PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Bug Report, v3.60: AlphaBlt() with GDALPHABLT_MIRRORLEFTRIGH

Hello,

I use my Tile set to draw background. Some tiles are expected to be drawn horizontally flipped. I use AlphaBlt as follows:

CGlobalVariables::pBackBuffer->AlphaBlt(&rectDest;, strCurrentLayer->pTileSetRGB, &rectSource;, strCurrentLayer->pTileSetAlpha, &rectSource;, GDALPHABLT_MIRRORLEFTRIGHT, NULL );

I double checked everything, and it gets drawn fine anywhere in the display but left edge clipping causes problems.

As my tile gets partilally before and partially after the left edge, drawing the tile misbehaves. The tile starts drawing always from display's X[0], although it should start from negative value, where the remainder of the tile would be seen. In this case, always the origin of the tile is seen, if the tile is left-clipped.

an example: a horizontally flipped tile(48x48 pixels) is placed on -20 X position. Although the tile would be expected to draw from that position, where only remaining 28 pixels would be seen on the display, when using GDALPHABLT_MIRRORLEFTRIGHT, the tile starts drawing always from 0 X screen position. It means that the leftmost part of the tile, that should be behind the left display edge and hidden, is always visible on the screen.

As I removed GDALPHABLT_MIRRORLEFTRIGHT, the bug dissapeared. However, how to draw XFlipped ties then. I tried Blt() with GDALPHABLT_MIRRORLEFTRIGHT as well, but nothing helps.

Please, is this really a bug, and is here any chance, it gets fixed soon? Thank you an with regards,
Rene.
InexorableTash · 23 Feb 2007, 05:07 UTC
I encountered this bug as well. Here's the function I use as a workaround:

Code:


// Work around a bug in clipped mirrored blting
//----------------------------------------------------------------------
HRESULT AlphaClipBlt( CGapiSurface* dst, const RECT* prcDst, CGapiRGBASurface* src, DWORD dwFlags, GDALPHABLTFX* pABFX )
//----------------------------------------------------------------------
{
if( dst == NULL || src == NULL || prcDst == NULL )
return E_INVALIDARG;

RECT rcDst = *prcDst;

int cxDst = dst->GetWidth();
int cyDst = dst->GetHeight();

if( rcDst.left > cxDst || rcDst.top > cyDst || rcDst.right < 0 || rcDst.bottom < 0 )
return S_FALSE;

int cxSrc = src->GetWidth();
int cySrc = src->GetHeight();

int cxBlt = rcDst.right - rcDst.left;
int cyBlt = rcDst.bottom - rcDst.top;


RECT rcSrc = { 0, 0, cxSrc, cySrc };

int delta;

delta = 0 - rcDst.left;
if( delta > 0 )
{
rcSrc.left += delta * cxSrc / cxBlt;
rcDst.left = 0;
}

delta = 0 - rcDst.top;
if( delta > 0 )
{
rcSrc.top += delta * cySrc / cyBlt;
rcDst.top = 0;
}

delta = rcDst.right - cxDst;
if( delta > 0 )
{
rcSrc.right -= delta * cxSrc / cxBlt;
rcDst.right = cxDst;
}

delta = rcDst.bottom - cyDst;
if( delta > 0 )
{
rcSrc.bottom -= delta * cySrc / cyBlt;
rcDst.bottom = cyDst;
}

if( rcSrc.right <= rcSrc.left || rcSrc.bottom <= rcSrc.top )
return S_FALSE;

// Work around the actual bug
if( dwFlags & GDALPHABLT_MIRRORLEFTRIGHT )
{
::OffsetRect( &rcSrc, cxSrc-rcSrc.right-rcSrc.left, 0 );
}

if( dwFlags & GDALPHABLT_MIRRORUPDOWN )
{
::OffsetRect( &rcSrc, 0, cySrc-rcSrc.bottom-rcSrc.top );
}

return dst->AlphaBlt( &rcDst, src, &rcSrc, dwFlags, pABFX );


} // AlphaClipBlt

Hello Ineroxable,

Thank you for your solution. Yesterday I already solved it using this very simple way:

// calculate source tile to be drawn
RECT rectSource;
rectSource.left = usSourceTileXCoordinate;
rectSource.top = usSourceTileYCoordinate;
rectSource.right = usSourceTileXCoordinate + strCurrentLayer->ucSingleTileWidth;
rectSource.bottom = usSourceTileYCoordinate + strCurrentLayer->ucSingleTileHeight;

// draw the tile
//if (*p_usTileToDraw != 0) CGraphics::DrawSolid((const char *)strCurrentLayer->pTilesSourceFile, usSourceTileXCoordinate, usSourceTileYCoordinate, 0, 0, strCurrentLayer->ucSingleTileWidth, strCurrentLayer->ucSingleTileHeight, ssScreenTileXPositionOffset, ssScreenTileYPositionOffset, 0);
if(usTileToDraw != 0)
{
if(bXFlippedTile == false)
CGlobalVariables::pBackBuffer->AlphaBltFast(ssScreenTileXPositionOffset, ssScreenTileYPositionOffset, strCurrentLayer->pTileSetRGB, &rectSource, strCurrentLayer->pTileSetAlpha, &rectSource, NULL, NULL );
else
{
RECT rectDest;
if(ssScreenTileXPositionOffset < 0)
{
rectDest.left = 0;
rectDest.top = ssScreenTileYPositionOffset;
rectDest.right = ssScreenTileXPositionOffset + strCurrentLayer->ucSingleTileWidth;
rectDest.bottom = rectDest.top + strCurrentLayer->ucSingleTileHeight;

rectSource.right += ssScreenTileXPositionOffset;
}
else
{
rectDest.left = ssScreenTileXPositionOffset;
rectDest.top = ssScreenTileYPositionOffset;
rectDest.right = rectDest.left + strCurrentLayer->ucSingleTileWidth;
rectDest.bottom = rectDest.top + strCurrentLayer->ucSingleTileHeight;
}



CGlobalVariables::pBackBuffer->AlphaBlt(&rectDest, strCurrentLayer->pTileSetRGB, &rectSource, strCurrentLayer->pTileSetAlpha, &rectSource, GDALPHABLT_MIRRORLEFTRIGHT, NULL );

}



However, am I correct, that you pointed at this problem about 1.5 years ago, and it was not resloved? I found the Bug Report you wrote in 2005 i think..

http://www.pocketmatrix.com/forums/view ... bug+report
InexorableTash · 24 Feb 2007, 05:10 UTC
Bunkai wrote:However, am I correct, that you pointed at this problem about 1.5 years ago, and it was not resloved? I found the Bug Report you wrote in 2005 i think..

http://www.pocketmatrix.com/forums/view ... bug+report


Yes, that is correct. I can't believe that was over a year ago. But then again, I'm just using GapiDraw for a hobby project, not anything shipping commercially, so I'm not doing very heavy development.