📄 gperotate.cpp
字号:
{
ULONG * pMasks = pFormat->m_pPalette;
SrcRGBMask = pMasks[0] | pMasks[1] | pMasks[2];
}
else
{
SrcRGBMask = src.Mask;
}
}
else
{
SrcRGBMask = src.Mask;
}
#endif /* (_WINCEOSVER >= 500) */
}
DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("pDst depth: %d Bpp\r\n"), EGPEFormatToBpp[pParms->pDst->Format()] ) );
if( pParms->pBrush )
{
DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("pBrush depth: %d Bpp\r\n"), EGPEFormatToBpp[pParms->pBrush->Format()] ) );
brush.InitBrushPixelIterator( pParms->pBrush, pParms->xPositive, pParms->yPositive, &rclBrush );
}
if( ( maskedROP3 != unmaskedROP3 ) && !(pParms->pMask) )
{
DEBUGMSG(GPE_ZONE_ERROR,(TEXT("Rop4 = %04x but pMask is NULL\r\n"), pParms->rop4 ));
return E_INVALIDARG;
}
if( pParms->pMask )
mask.InitPixelIterator( pParms->pMask, pParms->xPositive, pParms->yPositive, pParms->prclMask,
srcXStartSkip, srcYStartSkip );
else
mask.RowIncrement = 0;
if( ( maskedROP3 != unmaskedROP3 ) && !(mask.RowPtr) )
{
DEBUGMSG(GPE_ZONE_ERROR,(TEXT("Rop4 = %04x but mask.RowPtr is NULL\r\n"), pParms->rop4 ));
return E_INVALIDARG;
}
if( (dst.Bpp = EGPEFormatToBpp[pParms->pDst->Format()]) >= 8 && (dst.IsRotate = pParms->pDst->IsRotate()) == FALSE)
{
quickWrite = 1;
if( !dstYPositive )
{
dst.RowIncrement = -pParms->pDst->Stride();
dst.RowPtr = (unsigned char *)pParms->pDst->Buffer() + pParms->pDst->Stride() * ( prclDst->bottom - 1 - dstYStartSkip);
}
else
{
dst.RowIncrement = pParms->pDst->Stride();
dst.RowPtr = (unsigned char *)pParms->pDst->Buffer() + pParms->pDst->Stride() * ( dstYStartSkip + prclDst->top );
}
if( !dstXPositive )
{
dst.BytesPerAccess = -dst.Bpp/8;
dst.RowPtr -= dst.BytesPerAccess * ( prclDst->right - 1 - dstXStartSkip );
}
else
{
dst.BytesPerAccess = dst.Bpp/8;
dst.RowPtr += dst.BytesPerAccess * ( dstXStartSkip + prclDst->left );
}
dst.Mask = (0xffffffff) >> (32 - dst.Bpp);
dst.CacheState=0; // so it is not marked as dirty
}
else
dst.InitPixelIterator((GPESurfRotate *)pParms->pDst, dstXPositive, dstYPositive,prclDst,
dstXStartSkip, dstYStartSkip);
if( yShrinkStretch )
{
// Back up the source and mask row increments because they will be altered dynamically
originalMaskRowInc = mask.RowIncrement;
originalSrcRowInc = src.RowIncrement;
DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("yStretch:%d yShrink:%d yDMinor:%d yDMajor:%d yAccum:%d\n"),
yStretch, yShrink, yDMinor, yDMajor, yAccum ));
}
if( pParms->rop4 == 0x0000 )
{
src.Value = 0;
}
else if( pParms->rop4 == 0xffff )
{
src.Value = dst.Mask;
}
else
{
src.Value = pParms->solidColor & dst.Mask;
if( ( maskedROP3 != unmaskedROP3 )
|| transparentBlt
#if defined (_WINCEOSVER) && (_WINCEOSVER >= 500)
|| alphaBlend
#endif
|| xShrinkStretch
|| ( rop3 != 0xCC && ( rop3 != 0xF0 || pParms->pBrush ) ) )
{
DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("Complex Blt!\r\n")));
DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("transparent:%d,masked:%2x,unmasked:%2x,rop3:%2x,mask.RowPtr:%08x\r\n"),
transparentBlt,maskedROP3, unmaskedROP3, rop3, mask.RowPtr ));
complexBlt = 1;
}
}
brush.Value = src.Value;
while( height-- )
{
// Handle y Shrinking or stretching
if( yShrinkStretch )
{
if( yShrink )
{
while( yAccum < 0 ) // skip source line(s) if shrinking
{
DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("yShrink - skip line\r\n")));
if (!src.IsRotate)
src.RowPtr += src.RowIncrement;
else
src.RowCoord.y += src.RowIncrement;
mask.RowPtr += mask.RowIncrement;
yAccum += yDMinor;
}
yAccum += yDMajor;
}
else
{
if( yAccum < 0 )
{
// repeat source line if stretching
yAccum += yDMinor; // yDMinor is a small +ve number
if( yStretch )
{
DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("yStretch - Repeat. Accum=%d\r\n"), yAccum));
src.RowIncrement = 0;
mask.RowIncrement = 0;
}
}
else
{
DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("yStretch - Switch to next after this Accum=%d\r\n"), yAccum));
// Switch to next source line (after this row)
yAccum += yDMajor; // yDMajor is a large -ve value (i.e. |yDMajor| > |yDMinor| )
src.RowIncrement = originalSrcRowInc;
mask.RowIncrement = originalMaskRowInc;
}
}
}
// Move all iterators to next line
if( src.RowPtr )
{
src.Ptr = src.RowPtr;
src.RowPtr += src.RowIncrement;
if( ! src.Is24Bit )
{
src.Cache = *(UNALIGNED unsigned long *)src.Ptr;
src.CacheState = src.CacheStateNewRow;
}
}
else if (src.OrigPtr)
{
src.CurrentCoord = src.RowCoord;
src.RowCoord.y += src.RowIncrement;
}
if( mask.RowPtr )
{
mask.Ptr = mask.RowPtr;
mask.RowPtr += mask.RowIncrement;
mask.Cache = *(UNALIGNED unsigned long *)mask.Ptr;
mask.CacheState = mask.CacheStateNewRow;
}
if( brush.RowPtr )
{
brush.Ptr = brush.RowPtr;
brush.LeftRowPtr = brush.Ptr - brush.LeftPixelOffset;
if( --brush.RowsRemaining )
brush.RowPtr += brush.RowIncrement;
else
{
brush.RowPtr = brush.FirstRowPtr;
brush.RowsRemaining = brush.Rows;
}
brush.Cache = *(unsigned long *)brush.Ptr;
brush.CacheState = brush.CacheStateNewRow;
brush.PixelsRemaining = brush.RowInitialPixelsRemaining;
}
if (dst.IsRotate)
{
dst.CurrentCoord = dst.RowCoord;
dst.RowCoord.y += dst.RowIncrement;
}
else
{
dst.Ptr = dst.RowPtr;
dst.RowPtr += dst.RowIncrement;
}
if( !quickWrite )
{
if (!dst.IsRotate)
{
dst.Cache = *(UNALIGNED unsigned long *)dst.Ptr;
}
dst.CacheState = dst.CacheStateNewRow;
}
if( xStretch )
{
prevMaskPtr = mask.Ptr;
prevMaskCache = mask.Cache;
prevMaskCacheState = mask.CacheState;
if (src.IsRotate)
prevSrcCoord = src.CurrentCoord;
else
{
prevSrcPtr = src.Ptr;
prevSrcCache = src.Cache;
prevSrcCacheState = src.CacheState;
}
}
xAccum = rowXAccum;
for( x=0; x<width; x++ )
{
if( src.Ptr || src.OrigPtr)
{
// Read the next pixel in and convert to same depth as destination
if (src.Ptr)
{
if( src.Is24Bit ) // Since 24-bit packed pixels cross dword boundaries:
{
src.Value = ( *src.Ptr ) + ( *(src.Ptr+1) << 8 ) + ( *(src.Ptr+2) << 16 );
src.Ptr += src.BytesPerAccess;
}
else
{
if( !(src.CacheState&0x00ff00) ) // Check bits remaining in src.Cache
{
src.Ptr += src.BytesPerAccess; // increment src.Ptr
src.CacheState = src.CacheStateNewDWord;
src.Cache = *(UNALIGNED unsigned long *)src.Ptr; // reload src.Cache
}
src.Value = src.Cache >> ( (src.CacheState >> 16) ^ src.MaskShiftXor );
src.CacheState += src.CacheStateIncrement;
}
}
else // src.origPtr, i.e. rotated surface
{
switch (src.Bpp)
{
case 8:
*(unsigned char *)&src.Value = *(unsigned char*)src.GetPtr();
break;
case 16:
*(unsigned short *)&src.Value = *(unsigned short *)src.GetPtr();
break;
case 32:
*(unsigned long *)&src.Value = *(unsigned long *)src.GetPtr();
break;
case 24:
{
unsigned char *ptr = src.GetPtr();
src.Value = ( *ptr ) + ( *(ptr+1) << 8 ) + ( *(ptr+2) << 16 );
break;
}
}
src.CurrentCoord.x += src.ColIncrement;
}
// Save the origianl source for transparency.
originalSrc = ( src.Value &= src.Mask );
#if defined (_WINCEOSVER) && (_WINCEOSVER >= 500)
originalSrc &= SrcRGBMask;
#endif
if( pParms->pLookup )
src.Value = (pParms->pLookup)[src.Value];
if( pParms->pConvert )
{
src.Value = (pParms->pColorConverter->*(pParms->pConvert))( src.Value );
}
// pParms->pConvert( pParms->pColorConverter, src.Value );
}
if( complexBlt ) // brushed, masked, transparent, unusual rop3 etc
{
if( brush.Ptr )
{
// Note that the brush will already have been converted to the same
// depth as the destination (if they weren't the same).
// The exception is if the dest is 24Bpp. In this case, the brush
// will have been converted to 32Bpp for simplicity.
// See DrvRealizeBrush for details
if( !(brush.PixelsRemaining--) ) // Check for wrapping off right edge of pattern
{
brush.Ptr = brush.LeftRowPtr;
brush.PixelsRemaining = brush.PixelsPerRow-1;
brush.CacheState = brush.CacheStateNewDWord;
brush.Cache = *(unsigned long *)brush.Ptr; // reload brush.Cache
}
else if( !(brush.CacheState&0x00ff00) ) // Check bits remaining in brush.Cache
{
brush.Ptr += brush.BytesPerAccess; // increment brush.Ptr
brush.CacheState = brush.CacheStateNewDWord;
brush.Cache = *(unsigned long *)brush.Ptr; // reload brush.Cache
}
brush.Value = brush.Cache >> ( (brush.CacheState >> 16) ^ brush.MaskShiftXor );
brush.CacheState += brush.CacheStateIncrement;
}
if( mask.Ptr ) // This selects between two rop3's
{
if( !(mask.CacheState&0x00ff00) ) // check bits remaining in mask cache
{
mask.Ptr += mask.BytesPerAccess; // == +/- 4
mask.CacheState = mask.CacheStateNewDWord;
mask.Cache = *(UNALIGNED unsigned long *)mask.Ptr;
}
rop3 = ( mask.Cache & ( 1 << ( (mask.CacheState >> 16) ^ mask.MaskShiftXor ) ) ) ? unmaskedROP3 : maskedROP3;
mask.CacheState += mask.CacheStateIncrement;
}
if( xShrinkStretch )
{
// Handle x Stretching
if( xStretch )
{
if( xAccum < 0 ) // Repeat this pixel
{
xAccum += xDMinor;
mask.Ptr = prevMaskPtr;
mask.Cache = prevMaskCache;
mask.CacheState = prevMaskCacheState;
if (src.IsRotate)
src.CurrentCoord = prevSrcCoord;
else
{
src.Ptr = prevSrcPtr;
src.Cache = prevSrcCache;
src.CacheState = prevSrcCacheState;
}
}
else // OK to move to next source pixel after this
{
xAccum += xDMajor;
prevMaskPtr = mask.Ptr;
prevMaskCache = mask.Cache;
prevMaskCacheState = mask.CacheState;
if (src.IsRotate)
prevSrcCoord = src.CurrentCoord;
else
{
prevSrcPtr = src.Ptr;
prevSrcCache = src.Cache;
prevSrcCacheState = src.CacheState;
}
}
}
else // xShrink
{
while( xAccum < 0 ) // Skip pixel(s)
{
// Move to next src pixel
if (src.IsRotate)
src.CurrentCoord.x += src.ColIncrement;
else {
if( src.Is24Bit ) // Since 24-bit packed pixels cross dword boundaries:
src.Ptr += src.BytesPerAccess;
else
{
if( !(src.CacheState&0x00ff00) ) // Check bits remaining in src.Cache
{
src.Ptr += src.BytesPerAccess; // increment src.Ptr
src.CacheState = src.CacheStateNewDWord;
if (x != width - 1 )
src.Cache = *(UNALIGNED unsigned long *)src.Ptr; // reload src.Cache
}
src.CacheState += src.CacheStateIncrement;
}
}
// Move to next mask pixel
if( pParms->pMask )
{
if( !(mask.CacheState&0x00ff00) ) // check bits remaining in mask cache
{
mask.Ptr += mask.BytesPerAccess; // == +/- 4
mask.CacheState = mask.CacheStateNewDWord;
mask.Cache = *(UNALIGNED unsigned long *)mask.Ptr;
}
mask.CacheState += mask.CacheStateIncrement;
}
xAccum += xDMinor;
}
xAccum += xDMajor;
}
}
if( dstMatters ) // The underlying rop4 utilizes the dst.
{
// We maintain dst.Cache valid at all times if not doing quickWrite
if (dst.IsRotate)
{
switch(dst.Bpp)
{
case 8:
*(unsigned char *)&dst.Value = *(unsigned char *)dst.GetPtr();
break;
case 16:
*(unsigned short *)&dst.Value = *(unsigned short *)dst.GetPtr();
break;
case 32:
*(unsigned long *)&dst.Value = *(unsigned long *)dst.GetPtr();
break;
case 24:
unsigned char *ptr = dst.GetPtr();
dst.Value = ( *ptr ) + ( *(ptr+1) << 8 ) + ( *(ptr+2) << 16 );
}
}
else
{
if( quickWrite )
{
switch(dst.Bpp)
{
case 8:
*(unsigned char *)&dst.Value = *(unsigned char *)dst.Ptr;
break;
case 16:
*(unsigned short *)&dst.Value = *(unsigned short *)dst.Ptr;
break;
case 32:
*(unsigned long *)&dst.Value = *(unsigned long *)dst.Ptr;
break;
case 24:
dst.Value = ( *dst.Ptr ) + ( *(dst.Ptr+1) << 8 ) + ( *(dst.Ptr+2) << 16 );
}
}
else
dst.Value = dst.Cache >> ( ( dst.CacheState >> 16 ) ^ dst.MaskShiftXor );
}
}
switch( rop3 )
{
// The compiler sorts these and creates a binary search set of tests to
// get to an entry quickly. Branch "prediction" helps this a lot.
// Remember that masked rop4s makes NOP and SRCCOPY quite a likely rop3
case 0xAA: break; // NOP
case 0xCC: break; // SRCCOPY
case 0x00: src.Value = 0; break; // BLACKNESS
case 0x22: src.Value = (~src.Value) & dst.Value; break; // no-name
case 0xB8: src.Value = (brush.Value & ~src.Value)|(src.Value & dst.Value); break; // no-name
case 0x11: src.Value = ~(src.Value | dst.Value); break; // NOTSRCERASE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -