ExtCmdIcon.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:243k
- //ASSERT( FALSE );
- ::DeleteDC( hSrcDC );
- return GDI_ERROR;
- }
- LONG nIconPixelCount = nDstWidth * nDstHeight;
- BITMAPINFOHEADER _bihSrc;
- ::memset( &_bihSrc, 0, sizeof( BITMAPINFOHEADER ) );
- _bihSrc.biSize = sizeof( BITMAPINFOHEADER );
- _bihSrc.biWidth = nDstWidth;
- _bihSrc.biHeight = nDstHeight;
- _bihSrc.biPlanes = 1;
- _bihSrc.biBitCount = 32;
- _bihSrc.biCompression = BI_RGB;
- _bihSrc.biSizeImage = nIconPixelCount;
- BITMAPINFOHEADER _bihDst;
- __EXT_MFC_MEMCPY(
- &_bihDst,
- sizeof( BITMAPINFOHEADER ),
- &_bihSrc,
- sizeof( BITMAPINFOHEADER )
- );
- COLORREF * pOutSurfaceSrc = NULL, * pOutSurfaceDst = NULL;
- HBITMAP hSrcDIB =
- ::CreateDIBSection(
- hDC,
- (LPBITMAPINFO)&_bihSrc,
- DIB_RGB_COLORS,
- (void**)&pOutSurfaceSrc,
- NULL,
- NULL
- );
- if( hSrcDIB == NULL )
- {
- //ASSERT( FALSE );
- ::DeleteDC( hSrcDC );
- ::DeleteDC( hDstDC );
- return GDI_ERROR;
- }
- ASSERT( pOutSurfaceSrc != NULL );
- HBITMAP hDstDIB =
- ::CreateDIBSection(
- hDC,
- (LPBITMAPINFO)&_bihDst,
- DIB_RGB_COLORS,
- (void**)&pOutSurfaceDst,
- NULL,
- NULL
- );
- if( hDstDIB == NULL )
- {
- //ASSERT( FALSE );
- ::DeleteDC( hSrcDC );
- ::DeleteDC( hDstDC );
- ::DeleteObject( hSrcDIB );
- return GDI_ERROR;
- }
- ASSERT( pOutSurfaceDst != NULL );
- CSize _size = GetSize();
- HGDIOBJ hBmpOldSrc = ::SelectObject( hSrcDC, hSrcDIB );
- HGDIOBJ hBmpOldDst = ::SelectObject( hDstDC, hDstDIB );
- int nOldStretchBltMode = ::GetStretchBltMode( hDC );
- ::SetStretchBltMode( hDC, COLORONCOLOR );
- int nOldStretchBltModeSrc = ::GetStretchBltMode( hSrcDC );
- ::SetStretchBltMode( hSrcDC, COLORONCOLOR );
- int nOldStretchBltModeDst = ::GetStretchBltMode( hDstDC );
- ::SetStretchBltMode( hDstDC, COLORONCOLOR );
- ::StretchBlt(
- hDstDC,
- 0,
- 0,
- nDstWidth,
- nDstHeight,
- hDC,
- nDstX,
- nDstY,
- nDstWidth,
- nDstHeight,
- SRCCOPY
- );
- Draw(
- hSrcDC,
- 0,
- 0,
- nDstWidth,
- nDstHeight,
- nSrcX,
- nSrcY,
- nSrcWidth,
- nSrcHeight
- );
- INT nX, nY;
- COLORREF * ptrSrcLine = pOutSurfaceSrc + nDstWidth * nDstHeight;
- COLORREF * ptrDstLine = pOutSurfaceDst + nDstWidth * nDstHeight;
- for( nY = 0; nY < nDstHeight; nY++ )
- {
- ptrSrcLine -= nDstWidth;
- ptrDstLine -= nDstWidth;
- COLORREF * ptrSrc = ptrSrcLine;
- COLORREF * ptrDst = ptrDstLine;
- for( nX = 0; nX < nDstWidth; nX++ )
- {
- BYTE nDstR = GetRValue( (*ptrDst) );
- BYTE nDstG = GetGValue( (*ptrDst) );
- BYTE nDstB = GetBValue( (*ptrDst) );
- BYTE nSrcR = GetRValue( (*ptrSrc) );
- BYTE nSrcG = GetGValue( (*ptrSrc) );
- BYTE nSrcB = GetBValue( (*ptrSrc) );
- BYTE nSrcA = __EXT_MFC_GetAValue( (*ptrSrc) );
- if( ! bPreMultiplied )
- {
- if( nSCA != 0x0FF )
- nSrcA = (BYTE) ::MulDiv( nSrcA, nSCA, 255 );
- nSrcR = (BYTE) ::MulDiv( nSrcR, nSrcA, 255 );
- nSrcG = (BYTE) ::MulDiv( nSrcG, nSrcA, 255 );
- nSrcB = (BYTE) ::MulDiv( nSrcB, nSrcA, 255 );
- }
- else if( nSCA != 0x0FF )
- {
- nSrcR = (BYTE) ::MulDiv( nSrcR, nSCA, 255 );
- nSrcG = (BYTE) ::MulDiv( nSrcG, nSCA, 255 );
- nSrcB = (BYTE) ::MulDiv( nSrcB, nSCA, 255 );
- nSrcA = (BYTE) ::MulDiv( nSrcA, nSCA, 255 );
- }
- BYTE _255_nSrcA = (BYTE) ( 255 - nSrcA );
- nDstR = (BYTE) ( nSrcR + ( (BYTE) ::MulDiv( _255_nSrcA, nDstR, 255 ) ) );
- nDstG = (BYTE) ( nSrcG + ( (BYTE) ::MulDiv( _255_nSrcA, nDstG, 255 ) ) );
- nDstB = (BYTE) ( nSrcB + ( (BYTE) ::MulDiv( _255_nSrcA, nDstB, 255 ) ) );
- (*ptrDst) = RGB( nDstR, nDstG, nDstB );
- ptrDst++;
- ptrSrc++;
- } // for( nX = 0; nX < nDstWidth; nX++ )
- } // for( nY = 0; nY < nDstHeight; nY++ )
- ::StretchBlt(
- hDC,
- nDstX,
- nDstY,
- nDstWidth,
- nDstHeight,
- hDstDC,
- 0,
- 0,
- nDstWidth,
- nDstHeight,
- SRCCOPY
- );
- ::SetStretchBltMode( hDC, nOldStretchBltMode );
- ::SetStretchBltMode( hSrcDC, nOldStretchBltModeSrc );
- ::SetStretchBltMode( hDstDC, nOldStretchBltModeDst );
-
- ::SelectObject( hSrcDC, hBmpOldSrc );
- ::SelectObject( hDstDC, hBmpOldDst );
- ::DeleteObject( hSrcDIB );
- ::DeleteObject( hDstDIB );
- ::DeleteDC( hSrcDC );
- ::DeleteDC( hDstDC );
- return 0;
- }
- int CExtBitmap::AlphaBlend(
- HDC hDC,
- int nDstX,
- int nDstY,
- int nDstWidth,
- int nDstHeight,
- BYTE nSCA // = 0xFF
- ) const
- {
- return
- AlphaBlend(
- hDC,
- nDstX,
- nDstY,
- nDstWidth,
- nDstHeight,
- 0,
- 0,
- GetSize().cx,
- GetSize().cy,
- nSCA
- );
- }
- bool CExtBitmap::AlphaBlendSkinParts(
- HDC hDC,
- const RECT & rcDstDraw,
- const RECT & rcSrcDraw,
- const RECT & rcPadding,
- e_DrawMethod_t eDM,
- bool bDrawMiddlePart, // = true
- bool bSmootherAsPossible, // = false
- BYTE nSCA // = 0xFF
- ) const
- {
- if( eDM == __EDM_HOLLOW )
- return true;
- ASSERT( hDC != NULL );
- ASSERT( rcPadding.left >= 0 );
- ASSERT( rcPadding.right >= 0 );
- ASSERT( rcPadding.top >= 0 );
- ASSERT( rcPadding.bottom >= 0 );
- if( IsEmpty() || hDC == NULL )
- return false;
- if( eDM == __EDM_CENTER )
- {
- //CSize _size = GetSize();
- CSize _size( rcSrcDraw.right - rcSrcDraw.left, rcSrcDraw.bottom - rcSrcDraw.top );
- CRect rcDst(
- CPoint(
- rcDstDraw.left + ( rcDstDraw.right - rcDstDraw.left - _size.cx ) / 2,
- rcDstDraw.top + ( rcDstDraw.bottom - rcDstDraw.top - _size.cy ) / 2
- ),
- _size
- );
- if( ::RectVisible( hDC, &rcDst ) )
- AlphaBlend(
- hDC,
- rcDst,
- rcSrcDraw,
- nSCA
- );
- return true;
- } // if( eDM == __EDM_CENTER )
- int nOldStretchBltMode = ::GetStretchBltMode( hDC );
- ::SetStretchBltMode(
- hDC,
- ( bSmootherAsPossible && g_PaintManager.m_bIsWinNT )
- ? HALFTONE
- : COLORONCOLOR
- );
- // left - top
- if( rcPadding.left > 0 && rcPadding.top > 0 )
- {
- CRect rcDst(
- rcDstDraw.left,
- rcDstDraw.top,
- rcDstDraw.left + rcPadding.left,
- rcDstDraw.top + rcPadding.top
- );
- if( ::RectVisible( hDC, &rcDst ) )
- {
- CRect rcSrc(
- rcSrcDraw.left,
- rcSrcDraw.top,
- rcSrcDraw.left + rcPadding.left,
- rcSrcDraw.top + rcPadding.top
- );
- AlphaBlend(
- hDC,
- rcDst,
- rcSrc,
- nSCA
- );
- } // if( ::RectVisible( hDC, &rcDst ) )
- } // if( rcPadding.left > 0 && rcPadding.top > 0 )
- // middle - top
- if( rcPadding.top > 0 )
- {
- CRect rcDst(
- rcDstDraw.left + rcPadding.left,
- rcDstDraw.top,
- rcDstDraw.right - rcPadding.right,
- rcDstDraw.top + rcPadding.top
- );
- if( ::RectVisible( hDC, &rcDst ) )
- {
- CRect rcSrc(
- rcSrcDraw.left + rcPadding.left,
- rcSrcDraw.top,
- rcSrcDraw.right - rcPadding.right,
- rcSrcDraw.top + rcPadding.top
- );
- if( eDM == __EDM_TILE_H || eDM == __EDM_TILE )
- {
- INT nSrcWidth = rcSrc.right - rcSrc.left;
- INT nSrcHeight = rcSrc.bottom - rcSrc.top;
- INT nDstWidth = rcDst.right - rcDst.left;
- INT nDstHeight = rcDst.bottom - rcDst.top;
- if( nSrcWidth != 0 && nSrcHeight != 0 && nDstWidth != 0 && nDstHeight != 0 )
- {
- INT nLastStepPx = nDstWidth % nSrcWidth;
- INT nLastStep = ( nLastStepPx != 0 ) ? 1 : 0;
- INT nStepCount = nDstWidth / nSrcWidth + nLastStep;
- INT nStepIndex;
- CRect rcDstStep(
- rcDst.left,
- rcDst.top,
- rcDst.left + nSrcWidth,
- rcDst.top + nSrcHeight
- );
- CRect rcSrcA = rcSrc;
- for( nStepIndex = 0; nStepIndex < nStepCount; nStepIndex ++ )
- {
- if( nLastStep != 0
- && nStepIndex == ( nStepCount - 1 )
- && rcDstStep.right > rcDst.right
- )
- {
- INT nDiff = rcDstStep.right - rcDst.right;
- rcDstStep.right -= nDiff;
- rcSrcA.right -= nDiff;
- }
- AlphaBlend(
- hDC,
- rcDstStep,
- rcSrcA,
- nSCA
- );
- rcDstStep.OffsetRect( nSrcWidth, 0 );
- } // for( nStepIndex = 0; nStepIndex < nStepCount; nStepIndex ++ )
- } // if( nSrcWidth != 0 && nSrcHeight != 0 && nDstWidth != 0 && nDstHeight != 0 )
- } // if( eDM == __EDM_TILE_H || eDM == __EDM_TILE )
- else
- AlphaBlend(
- hDC,
- rcDst,
- rcSrc,
- nSCA
- );
- } // if( ::RectVisible( hDC, &rcDst ) )
- } // if( rcPadding.top > 0 )
- // right - top
- if( rcPadding.right > 0 && rcPadding.top > 0 )
- {
- CRect rcDst(
- rcDstDraw.right - rcPadding.right,
- rcDstDraw.top,
- rcDstDraw.right,
- rcDstDraw.top + rcPadding.top
- );
- if( ::RectVisible( hDC, &rcDst ) )
- {
- CRect rcSrc(
- rcSrcDraw.right - rcPadding.right,
- rcSrcDraw.top,
- rcSrcDraw.right,
- rcSrcDraw.top + rcPadding.top
- );
- AlphaBlend(
- hDC,
- rcDst,
- rcSrc,
- nSCA
- );
- } // if( ::RectVisible( hDC, &rcDst ) )
- } // if( rcPadding.right > 0 && rcPadding.top > 0 )
- // left - middle
- if( rcPadding.left > 0 )
- {
- CRect rcDst(
- rcDstDraw.left,
- rcDstDraw.top + rcPadding.top,
- rcDstDraw.left + rcPadding.left,
- rcDstDraw.bottom - rcPadding.bottom
- );
- if( ::RectVisible( hDC, &rcDst ) )
- {
- CRect rcSrc(
- rcSrcDraw.left,
- rcSrcDraw.top + rcPadding.top,
- rcSrcDraw.left + rcPadding.left,
- rcSrcDraw.bottom - rcPadding.bottom
- );
- if( eDM == __EDM_TILE_V || eDM == __EDM_TILE )
- {
- INT nSrcWidth = rcSrc.right - rcSrc.left;
- INT nSrcHeight = rcSrc.bottom - rcSrc.top;
- INT nDstWidth = rcDst.right - rcDst.left;
- INT nDstHeight = rcDst.bottom - rcDst.top;
- if( nSrcWidth != 0 && nSrcHeight != 0 && nDstWidth != 0 && nDstHeight != 0 )
- {
- INT nLastStepPx = nDstHeight % nSrcHeight;
- INT nLastStep = ( nLastStepPx != 0 ) ? 1 : 0;
- INT nStepCount = nDstHeight / nSrcHeight + nLastStep;
- INT nStepIndex;
- CRect rcDstStep(
- rcDst.left,
- rcDst.top,
- rcDst.left + nSrcWidth,
- rcDst.top + nSrcHeight
- );
- CRect rcSrcA = rcSrc;
- for( nStepIndex = 0; nStepIndex < nStepCount; nStepIndex ++ )
- {
- if( nLastStep != 0
- && nStepIndex == ( nStepCount - 1 )
- && rcDstStep.bottom > rcDst.bottom
- )
- {
- INT nDiff = rcDstStep.bottom - rcDst.bottom;
- rcDstStep.bottom -= nDiff;
- rcSrcA.bottom -= nDiff;
- }
- AlphaBlend(
- hDC,
- rcDstStep,
- rcSrcA,
- nSCA
- );
- rcDstStep.OffsetRect( 0, nSrcHeight );
- } // for( nStepIndex = 0; nStepIndex < nStepCount; nStepIndex ++ )
- } // if( nSrcWidth != 0 && nSrcHeight != 0 && nDstWidth != 0 && nDstHeight != 0 )
- } // if( eDM == __EDM_TILE_V || eDM == __EDM_TILE )
- else
- AlphaBlend(
- hDC,
- rcDst,
- rcSrc,
- nSCA
- );
- } // if( ::RectVisible( hDC, &rcDst ) )
- } // if( rcPadding.left > 0 )
- // right - middle
- if( rcPadding.right > 0 )
- {
- CRect rcDst(
- rcDstDraw.right - rcPadding.right,
- rcDstDraw.top + rcPadding.top,
- rcDstDraw.right,
- rcDstDraw.bottom - rcPadding.bottom
- );
- if( ::RectVisible( hDC, &rcDst ) )
- {
- CRect rcSrc(
- rcSrcDraw.right - rcPadding.right,
- rcSrcDraw.top + rcPadding.top,
- rcSrcDraw.right,
- rcSrcDraw.bottom - rcPadding.bottom
- );
- if( eDM == __EDM_TILE_V || eDM == __EDM_TILE )
- {
- INT nSrcWidth = rcSrc.right - rcSrc.left;
- INT nSrcHeight = rcSrc.bottom - rcSrc.top;
- INT nDstWidth = rcDst.right - rcDst.left;
- INT nDstHeight = rcDst.bottom - rcDst.top;
- if( nSrcWidth != 0 && nSrcHeight != 0 && nDstWidth != 0 && nDstHeight != 0 )
- {
- INT nLastStepPx = nDstHeight % nSrcHeight;
- INT nLastStep = ( nLastStepPx != 0 ) ? 1 : 0;
- INT nStepCount = nDstHeight / nSrcHeight + nLastStep;
- INT nStepIndex;
- CRect rcDstStep(
- rcDst.left,
- rcDst.top,
- rcDst.left + nSrcWidth,
- rcDst.top + nSrcHeight
- );
- CRect rcSrcA = rcSrc;
- for( nStepIndex = 0; nStepIndex < nStepCount; nStepIndex ++ )
- {
- if( nLastStep != 0
- && nStepIndex == ( nStepCount - 1 )
- && rcDstStep.bottom > rcDst.bottom
- )
- {
- INT nDiff = rcDstStep.bottom - rcDst.bottom;
- rcDstStep.bottom -= nDiff;
- rcSrcA.bottom -= nDiff;
- }
- AlphaBlend(
- hDC,
- rcDstStep,
- rcSrcA,
- nSCA
- );
- rcDstStep.OffsetRect( 0, nSrcHeight );
- } // for( nStepIndex = 0; nStepIndex < nStepCount; nStepIndex ++ )
- } // if( nSrcWidth != 0 && nSrcHeight != 0 && nDstWidth != 0 && nDstHeight != 0 )
- } // if( eDM == __EDM_TILE_V || eDM == __EDM_TILE )
- else
- AlphaBlend(
- hDC,
- rcDst,
- rcSrc,
- nSCA
- );
- } // if( ::RectVisible( hDC, &rcDst ) )
- } // if( rcPadding.right > 0 )
- // left - bottom
- if( rcPadding.left > 0 && rcPadding.bottom > 0 )
- {
- CRect rcDst(
- rcDstDraw.left,
- rcDstDraw.bottom - rcPadding.bottom,
- rcDstDraw.left + rcPadding.left,
- rcDstDraw.bottom
- );
- if( ::RectVisible( hDC, &rcDst ) )
- {
- CRect rcSrc(
- rcSrcDraw.left,
- rcSrcDraw.bottom - rcPadding.bottom,
- rcSrcDraw.left + rcPadding.left,
- rcSrcDraw.bottom
- );
- AlphaBlend(
- hDC,
- rcDst,
- rcSrc,
- nSCA
- );
- } // if( ::RectVisible( hDC, &rcDst ) )
- } // if( rcPadding.left > 0 && rcPadding.bottom > 0 )
- // middle - bottom
- if( rcPadding.bottom > 0 )
- {
- CRect rcDst(
- rcDstDraw.left + rcPadding.left,
- rcDstDraw.bottom - rcPadding.bottom,
- rcDstDraw.right - rcPadding.right,
- rcDstDraw.bottom
- );
- if( ::RectVisible( hDC, &rcDst ) )
- {
- CRect rcSrc(
- rcSrcDraw.left + rcPadding.left,
- rcSrcDraw.bottom - rcPadding.bottom,
- rcSrcDraw.right - rcPadding.right,
- rcSrcDraw.bottom
- );
- if( eDM == __EDM_TILE_H || eDM == __EDM_TILE )
- {
- INT nSrcWidth = rcSrc.right - rcSrc.left;
- INT nSrcHeight = rcSrc.bottom - rcSrc.top;
- INT nDstWidth = rcDst.right - rcDst.left;
- INT nDstHeight = rcDst.bottom - rcDst.top;
- if( nSrcWidth != 0 && nSrcHeight != 0 && nDstWidth != 0 && nDstHeight != 0 )
- {
- INT nLastStepPx = nDstWidth % nSrcWidth;
- INT nLastStep = ( nLastStepPx != 0 ) ? 1 : 0;
- INT nStepCount = nDstWidth / nSrcWidth + nLastStep;
- INT nStepIndex;
- CRect rcDstStep(
- rcDst.left,
- rcDst.top,
- rcDst.left + nSrcWidth,
- rcDst.top + nSrcHeight
- );
- CRect rcSrcA = rcSrc;
- for( nStepIndex = 0; nStepIndex < nStepCount; nStepIndex ++ )
- {
- if( nLastStep != 0
- && nStepIndex == ( nStepCount - 1 )
- && rcDstStep.right > rcDst.right
- )
- {
- INT nDiff = rcDstStep.right - rcDst.right;
- rcDstStep.right -= nDiff;
- rcSrcA.right -= nDiff;
- }
- AlphaBlend(
- hDC,
- rcDstStep,
- rcSrcA,
- nSCA
- );
- rcDstStep.OffsetRect( nSrcWidth, 0 );
- } // for( nStepIndex = 0; nStepIndex < nStepCount; nStepIndex ++ )
- } // if( nSrcWidth != 0 && nSrcHeight != 0 && nDstWidth != 0 && nDstHeight != 0 )
- } // if( eDM == __EDM_TILE_H || eDM == __EDM_TILE )
- else
- AlphaBlend(
- hDC,
- rcDst,
- rcSrc,
- nSCA
- );
- } // if( ::RectVisible( hDC, &rcDst ) )
- } // if( rcPadding.bottom > 0 )
- // right - bottom
- if( rcPadding.right > 0 && rcPadding.bottom > 0 )
- {
- CRect rcDst(
- rcDstDraw.right - rcPadding.right,
- rcDstDraw.bottom - rcPadding.bottom,
- rcDstDraw.right,
- rcDstDraw.bottom
- );
- if( ::RectVisible( hDC, &rcDst ) )
- {
- CRect rcSrc(
- rcSrcDraw.right - rcPadding.right,
- rcSrcDraw.bottom - rcPadding.bottom,
- rcSrcDraw.right,
- rcSrcDraw.bottom
- );
- AlphaBlend(
- hDC,
- rcDst,
- rcSrc,
- nSCA
- );
- } // if( ::RectVisible( hDC, &rcDst ) )
- } // if( rcPadding.right > 0 && rcPadding.bottom > 0 )
- // central part
- if( bDrawMiddlePart )
- {
- CRect rcDst(
- rcDstDraw.left + rcPadding.left,
- rcDstDraw.top + rcPadding.top,
- rcDstDraw.right - rcPadding.right,
- rcDstDraw.bottom - rcPadding.bottom
- );
- if( ::RectVisible( hDC, &rcDst ) )
- {
- CRect rcSrc(
- rcSrcDraw.left + rcPadding.left,
- rcSrcDraw.top + rcPadding.top,
- rcSrcDraw.right - rcPadding.right,
- rcSrcDraw.bottom - rcPadding.bottom
- );
- if( eDM == __EDM_TILE_H )
- {
- INT nSrcWidth = rcSrc.right - rcSrc.left;
- INT nSrcHeight = rcSrc.bottom - rcSrc.top;
- INT nDstWidth = rcDst.right - rcDst.left;
- INT nDstHeight = rcDst.bottom - rcDst.top;
- if( nSrcWidth != 0 && nSrcHeight != 0 && nDstWidth != 0 && nDstHeight != 0 )
- {
- INT nLastStepPx = nDstWidth % nSrcWidth;
- INT nLastStep = ( nLastStepPx != 0 ) ? 1 : 0;
- INT nStepCount = nDstWidth / nSrcWidth + nLastStep;
- INT nStepIndex;
- CRect rcDstStep(
- rcDst.left,
- rcDst.top,
- rcDst.left + nSrcWidth,
- rcDst.top + nDstHeight
- );
- CRect rcSrcA = rcSrc;
- for( nStepIndex = 0; nStepIndex < nStepCount; nStepIndex ++ )
- {
- if( nLastStep != 0
- && nStepIndex == ( nStepCount - 1 )
- && rcDstStep.right > rcDst.right
- )
- {
- INT nDiff = rcDstStep.right - rcDst.right;
- rcDstStep.right -= nDiff;
- rcSrcA.right -= nDiff;
- }
- AlphaBlend(
- hDC,
- rcDstStep,
- rcSrcA,
- nSCA
- );
- rcDstStep.OffsetRect( nSrcWidth, 0 );
- } // for( nStepIndex = 0; nStepIndex < nStepCount; nStepIndex ++ )
- } // if( nSrcWidth != 0 && nSrcHeight != 0 && nDstWidth != 0 && nDstHeight != 0 )
- } // if( eDM == __EDM_TILE_H )
- else if( eDM == __EDM_TILE_V )
- {
- INT nSrcWidth = rcSrc.right - rcSrc.left;
- INT nSrcHeight = rcSrc.bottom - rcSrc.top;
- INT nDstWidth = rcDst.right - rcDst.left;
- INT nDstHeight = rcDst.bottom - rcDst.top;
- if( nSrcWidth != 0 && nSrcHeight != 0 && nDstWidth != 0 && nDstHeight != 0 )
- {
- INT nLastStepPx = nDstHeight % nSrcHeight;
- INT nLastStep = ( nLastStepPx != 0 ) ? 1 : 0;
- INT nStepCount = nDstHeight / nSrcHeight + nLastStep;
- INT nStepIndex;
- CRect rcDstStep(
- rcDst.left,
- rcDst.top,
- rcDst.left + nDstWidth,
- rcDst.top + nSrcHeight
- );
- CRect rcSrcA = rcSrc;
- for( nStepIndex = 0; nStepIndex < nStepCount; nStepIndex ++ )
- {
- if( nLastStep != 0
- && nStepIndex == ( nStepCount - 1 )
- && rcDstStep.bottom > rcDst.bottom
- )
- {
- INT nDiff = rcDstStep.bottom - rcDst.bottom;
- rcDstStep.bottom -= nDiff;
- rcSrcA.bottom -= nDiff;
- }
- AlphaBlend(
- hDC,
- rcDstStep,
- rcSrcA,
- nSCA
- );
- rcDstStep.OffsetRect( 0, nSrcHeight );
- } // for( nStepIndex = 0; nStepIndex < nStepCount; nStepIndex ++ )
- } // if( nSrcWidth != 0 && nSrcHeight != 0 && nDstWidth != 0 && nDstHeight != 0 )
- } // else if( eDM == __EDM_TILE_V )
- else if( eDM == __EDM_TILE )
- {
- INT nSrcWidth = rcSrc.right - rcSrc.left;
- INT nSrcHeight = rcSrc.bottom - rcSrc.top;
- INT nDstWidth = rcDst.right - rcDst.left;
- INT nDstHeight = rcDst.bottom - rcDst.top;
- if( nSrcWidth != 0 && nSrcHeight != 0 && nDstWidth != 0 && nDstHeight != 0 )
- {
- INT nLastStepPxH = nDstWidth % nSrcWidth;
- INT nLastStepPxV = nDstHeight % nSrcHeight;
- INT nLastStepH = ( nLastStepPxH != 0 ) ? 1 : 0;
- INT nLastStepV = ( nLastStepPxV != 0 ) ? 1 : 0;
- INT nStepCountH = nDstWidth / nSrcWidth + nLastStepH;
- INT nStepCountV = nDstHeight / nSrcHeight + nLastStepV;
- INT nStepIndexH, nStepIndexV;
- CRect rcDstStep(
- rcDst.left,
- rcDst.top,
- rcDst.left + nSrcWidth,
- rcDst.top + nSrcHeight
- );
- for( nStepIndexV = 0; nStepIndexV < nStepCountV; nStepIndexV ++ )
- {
- CRect rcDstStepA = rcDstStep;
- CRect rcSrcA = rcSrc;
- if( nLastStepV != 0
- && nStepIndexV == ( nStepCountV - 1 )
- && rcDstStepA.bottom > rcDst.bottom
- )
- {
- INT nDiff = rcDstStepA.bottom - rcDst.bottom;
- rcDstStepA.bottom -= nDiff;
- rcSrcA.bottom -= nDiff;
- }
- for( nStepIndexH = 0; nStepIndexH < nStepCountH; nStepIndexH ++ )
- {
- if( nLastStepH != 0
- && nStepIndexH == ( nStepCountH - 1 )
- && rcDstStepA.right > rcDst.right
- )
- {
- INT nDiff = rcDstStepA.right - rcDst.right;
- rcDstStepA.right -= nDiff;
- rcSrcA.right -= nDiff;
- }
- AlphaBlend(
- hDC,
- rcDstStepA,
- rcSrcA,
- nSCA
- );
- rcDstStepA.OffsetRect( nSrcWidth, 0 );
- } // for( nStepIndexH = 0; nStepIndexH < nStepCountH; nStepIndexH ++ )
- rcDstStep.OffsetRect( 0, nSrcHeight );
- } // for( nStepIndexV = 0; nStepIndexV < nStepCountV; nStepIndexV ++ )
- } // if( nSrcWidth != 0 && nSrcHeight != 0 && nDstWidth != 0 && nDstHeight != 0 )
- } // else if( eDM == __EDM_TILE )
- else
- AlphaBlend(
- hDC,
- rcDst,
- rcSrc,
- nSCA
- );
- } // if( ::RectVisible( hDC, &rcDst ) )
- } // if( bDrawMiddlePart )
- ::SetStretchBltMode(
- hDC,
- nOldStretchBltMode
- );
- return true;
- }
- bool CExtBitmap::AlphaBlendSkinParts(
- HDC hDC,
- const RECT & rcDstDraw,
- const RECT & rcPadding,
- e_DrawMethod_t eDM,
- bool bDrawMiddlePart, // = true
- bool bSmootherAsPossible, // = false
- BYTE nSCA // = 0xFF
- ) const
- {
- ASSERT( hDC != NULL );
- ASSERT( rcPadding.left >= 0 );
- ASSERT( rcPadding.right >= 0 );
- ASSERT( rcPadding.top >= 0 );
- ASSERT( rcPadding.bottom >= 0 );
- if( IsEmpty() || hDC == NULL )
- return false;
- CSize _size = GetSize();
- RECT rcSrcDraw = { 0, 0, _size.cx, _size.cy };
- return
- AlphaBlendSkinParts(
- hDC,
- rcDstDraw,
- rcSrcDraw,
- rcPadding,
- eDM,
- bDrawMiddlePart,
- bSmootherAsPossible,
- nSCA
- );
- }
- bool CExtBitmap::GetPixel(
- INT nX,
- INT nY,
- RGBQUAD & _pixel
- ) const
- {
- if( IsEmpty() )
- return false;
- if( nX < 0 || nY < 0 )
- return false;
- CSize _size = GetSize();
- if( nX >= _size.cx || nY >= _size.cy )
- return false;
- nY = _size.cy - nY - 1;
- ULONG nBPP = GetBPP();
- ULONG nScanLineSize = stat_RcScanLineSize( _size.cx, nBPP );
- LPBYTE pScanLine = stat_RcScanLine( m_pImageBuffer, ULONG(nY), nScanLineSize );
- switch( nBPP )
- {
- case 32:
- pScanLine += nX * 4;
- _pixel.rgbRed = pScanLine[2];
- _pixel.rgbGreen = pScanLine[1];
- _pixel.rgbBlue = pScanLine[0];
- _pixel.rgbReserved = pScanLine[3];
- if( PreMultipliedRGBChannelsGet() && _pixel.rgbReserved != 0 )
- {
- INT nRed = INT( _pixel.rgbRed * 255 / INT(_pixel.rgbReserved) );
- INT nGreen = INT( _pixel.rgbGreen * 255 / INT(_pixel.rgbReserved) );
- INT nBlue = INT( _pixel.rgbBlue * 255 / INT(_pixel.rgbReserved) );
- _pixel.rgbRed = BYTE( min( 255, nRed ) );
- _pixel.rgbGreen = BYTE( min( 255, nGreen ) );
- _pixel.rgbBlue = BYTE( min( 255, nBlue ) );
- }
- return true;
- case 24:
- pScanLine += nX * 3;
- _pixel.rgbRed = pScanLine[2];
- _pixel.rgbGreen = pScanLine[1];
- _pixel.rgbBlue = pScanLine[0];
- _pixel.rgbReserved = 0xFF;
- return true;
- case 16:
- case 15:
- pScanLine += nX * 2;
- WORD * pWordPixel16 = ( WORD * ) pScanLine;
- if( ( stat_MaskRed( m_pImageBuffer ) == 0xF800 )
- && ( stat_MaskGreen( m_pImageBuffer ) == 0x07E0 )
- && ( stat_MaskBlue( m_pImageBuffer ) == 0x001F )
- )
- {
- _pixel.rgbRed = BYTE( ( ( ( (*pWordPixel16) & 0xF800 ) >> 11 ) * 0xFF ) / 0x1F );
- _pixel.rgbGreen = BYTE( ( ( ( (*pWordPixel16) & 0x07E0 ) >> 5 ) * 0xFF ) / 0x3F );
- _pixel.rgbBlue = BYTE( ( ( (*pWordPixel16) & 0x001F ) * 0xFF ) / 0x1F );
- }
- else
- {
- _pixel.rgbRed = BYTE( ( ( ( (*pWordPixel16) & 0x7C00 ) >> 10 ) * 0xFF ) / 0x1F );
- _pixel.rgbGreen = BYTE( ( ( ( (*pWordPixel16) & 0x03E0 ) >> 5 ) * 0xFF ) / 0x1F );
- _pixel.rgbBlue = BYTE( ( ( (*pWordPixel16) & 0x001F ) * 0xFF) / 0x1F );
- }
- _pixel.rgbReserved = 0xFF;
- return true;
- } // switch( nBPP )
- return false;
- }
- COLORREF CExtBitmap::GetPixel(
- INT nX,
- INT nY,
- BYTE * p_nAlpha // = NULL
- ) const
- {
- if( IsEmpty() )
- return COLORREF(-1L);
- RGBQUAD _pixel;
- if( ! GetPixel( nX, nY, _pixel ) )
- return COLORREF(-1L);
- if( p_nAlpha != NULL )
- (*p_nAlpha) = _pixel.rgbReserved;
- return RGB( _pixel.rgbRed, _pixel.rgbGreen, _pixel.rgbBlue );
- }
- bool CExtBitmap::SetPixel(
- INT nX,
- INT nY,
- const RGBQUAD & _pixel,
- bool bSetRed, // = true
- bool bSetGreen, // = true
- bool bSetBlue, // = true
- bool bSetAlpha // = true
- )
- {
- if( IsEmpty() )
- return false;
- if( nX < 0 || nY < 0 )
- return false;
- CSize _size = GetSize();
- if( nX >= _size.cx || nY >= _size.cy )
- return false;
- nY = _size.cy - nY - 1;
- ULONG nBPP = GetBPP();
- ULONG nScanLineSize = stat_RcScanLineSize( _size.cx, nBPP );
- LPBYTE pScanLine = stat_RcScanLine( m_pImageBuffer, ULONG(nY), nScanLineSize );
- switch( nBPP )
- {
- case 32:
- pScanLine += nX * 4;
- if( bSetRed )
- pScanLine[2] = _pixel.rgbRed;
- if( bSetGreen )
- pScanLine[1] = _pixel.rgbGreen;
- if( bSetBlue )
- pScanLine[0] = _pixel.rgbBlue;
- if( bSetAlpha )
- {
- pScanLine[3] = _pixel.rgbReserved;
- if( PreMultipliedRGBChannelsGet() )
- {
- pScanLine[0] = BYTE( pScanLine[0] * _pixel.rgbReserved / 255 );
- pScanLine[1] = BYTE( pScanLine[1] * _pixel.rgbReserved / 255 );
- pScanLine[2] = BYTE( pScanLine[2] * _pixel.rgbReserved / 255 );
- }
- }
- OnContentChanged();
- return true;
- case 24:
- pScanLine += nX * 3;
- if( bSetRed )
- pScanLine[2] = _pixel.rgbRed;
- if( bSetGreen )
- pScanLine[1] = _pixel.rgbGreen;
- if( bSetBlue )
- pScanLine[0] = _pixel.rgbBlue;
- OnContentChanged();
- return true;
- case 16:
- case 15:
- {
- pScanLine += nX * 2;
- WORD * pWordPixel16 = ( WORD * ) pScanLine;
- if( stat_MaskRed( m_pImageBuffer ) == 0xF800
- && stat_MaskGreen( m_pImageBuffer ) == 0x07E0
- && stat_MaskBlue( m_pImageBuffer ) == 0x001F
- )
- {
- *pWordPixel16 =
- WORD(
- ( bSetRed ? ( ( _pixel.rgbRed >> 3 ) << 11 ) : 0 )
- | ( bSetGreen ? ( ( _pixel.rgbGreen >> 2 ) << 5 ) : 0 )
- | ( bSetBlue ? ( _pixel.rgbBlue >> 3 ) : 0 )
- );
- }
- else
- {
- *pWordPixel16 =
- WORD(
- ( bSetRed ? ( ( _pixel.rgbRed >> 3 ) << 10 ) : 0 )
- | ( bSetGreen ? ( ( _pixel.rgbGreen >> 3 ) << 5 ) : 0 )
- | ( bSetBlue ? ( _pixel.rgbBlue >> 3 ) : 0 )
- );
- }
- }
- OnContentChanged();
- return true;
- } // switch( nBPP )
- return false;
- }
- bool CExtBitmap::ColorizeMono(
- COLORREF clrTransparent,
- COLORREF clrTarget,
- LPCRECT pRect // = NULL
- )
- {
- if( IsEmpty() )
- return false;
- ULONG nBPP = GetBPP();
- if( nBPP < 15 )
- return false;
- if( PreMultipliedRGBChannelsGet() )
- {
- PreMultiplyRGBChannels( false );
- PreMultipliedRGBChannelsSet( false );
- }
- CSize _size = GetSize();
- CRect _rcFrame;
- if( pRect != NULL )
- {
- _rcFrame = (*pRect);
- if( _rcFrame.left < 0 )
- _rcFrame.left = 0;
- if( _rcFrame.top < 0 )
- _rcFrame.top = 0;
- if( _rcFrame.right > _size.cx )
- _rcFrame.right = _size.cx;
- if( _rcFrame.bottom > _size.cy )
- _rcFrame.bottom = _size.cy;
- }
- else
- _rcFrame.SetRect( 0, 0, _size.cx, _size.cy );
- if( _rcFrame.left >= _rcFrame.right
- || _rcFrame.top >= _rcFrame.bottom
- )
- return false;
- double dHTarget = 0.0, dSTarget = 0.0, dLTarget = 0.0;
- stat_RGBtoHSL( clrTarget, &dHTarget, &dSTarget, &dLTarget );
- INT nX, nY;
- for( nY = _rcFrame.top; nY < _rcFrame.bottom; nY++ )
- {
- for( nX = _rcFrame.left; nX < _rcFrame.right; nX++ )
- {
- RGBQUAD _pixel;
- VERIFY( GetPixel( nX, nY, _pixel ) );
- COLORREF clr =
- RGB(
- _pixel.rgbRed,
- _pixel.rgbGreen,
- _pixel.rgbBlue
- );
- if( clrTransparent != COLORREF(-1L) )
- {
- if( clr == clrTransparent )
- continue;
- } // if( clrTransparent != COLORREF(-1L) )
- double dHPixel = 0.0, dSPixel = 0.0, dLPixel = 0.0;
- stat_RGBtoHSL( clr, &dHPixel, &dSPixel, &dLPixel );
- clr = stat_HLStoRGB( dHTarget, dLPixel, dSTarget );
- _pixel.rgbRed = GetRValue( clr );
- _pixel.rgbGreen = GetGValue( clr );
- _pixel.rgbBlue = GetBValue( clr );
- VERIFY( SetPixel( nX, nY, _pixel ) );
- }
- }
- OnContentChanged();
- return true;
- }
- bool CExtBitmap::AdjustAlpha(
- double percentAlpha,
- LPCRECT pRect // = NULL
- )
- {
- if( IsEmpty() )
- return false;
- ULONG nBPP = GetBPP();
- if( nBPP < 15 )
- return false;
- if( percentAlpha == 0.0 )
- return true;
- if( PreMultipliedRGBChannelsGet() )
- {
- PreMultiplyRGBChannels( false );
- PreMultipliedRGBChannelsSet( false );
- }
- CSize _size = GetSize();
- CRect _rcFrame;
- if( pRect != NULL )
- {
- _rcFrame = (*pRect);
- if( _rcFrame.left < 0 )
- _rcFrame.left = 0;
- if( _rcFrame.top < 0 )
- _rcFrame.top = 0;
- if( _rcFrame.right > _size.cx )
- _rcFrame.right = _size.cx;
- if( _rcFrame.bottom > _size.cy )
- _rcFrame.bottom = _size.cy;
- }
- else
- _rcFrame.SetRect( 0, 0, _size.cx, _size.cy );
- if( _rcFrame.left >= _rcFrame.right
- || _rcFrame.top >= _rcFrame.bottom
- )
- return false;
- INT nX, nY;
- for( nY = _rcFrame.top; nY < _rcFrame.bottom; nY++ )
- {
- for( nX = _rcFrame.left; nX < _rcFrame.right; nX++ )
- {
- RGBQUAD _pixel;
- VERIFY( GetPixel( nX, nY, _pixel ) );
- if( _pixel.rgbReserved == 0 )
- continue;
- double A = double(_pixel.rgbReserved) / 255.0;
- if( percentAlpha > 0.0 )
- A =
- A +
- (1.0 - A) * percentAlpha
- ;
- else if ( percentAlpha < 0.0 )
- A =
- A * (1.0 + percentAlpha);
- if( A < 0.0 )
- A = 0.0;
- else if( A > 1.0 )
- A = 1.0;
- BYTE nA = BYTE(INT(A*255.0));
- if( _pixel.rgbReserved == nA )
- continue;
- _pixel.rgbReserved = nA;
- VERIFY( SetPixel( nX, nY, _pixel ) );
- }
- }
- OnContentChanged();
- return true;
- }
- bool CExtBitmap::AdjustHLS(
- COLORREF clrTransparent, // = RGB(0,0,0)
- COLORREF clrTolerance, // = RGB(0,0,0)
- double percentH, // = 0.0
- double percentL, // = 0.0
- double percentS, // = 0.0
- LPCRECT pRect // = NULL
- )
- {
- if( IsEmpty() )
- return false;
- ULONG nBPP = GetBPP();
- if( nBPP < 15 )
- return false;
- if( percentH == 0.0
- && percentL == 0.0
- && percentS == 0.0
- )
- return true;
- if( PreMultipliedRGBChannelsGet() )
- {
- PreMultiplyRGBChannels( false );
- PreMultipliedRGBChannelsSet( false );
- }
- CSize _size = GetSize();
- CRect _rcFrame;
- if( pRect != NULL )
- {
- _rcFrame = (*pRect);
- if( _rcFrame.left < 0 )
- _rcFrame.left = 0;
- if( _rcFrame.top < 0 )
- _rcFrame.top = 0;
- if( _rcFrame.right > _size.cx )
- _rcFrame.right = _size.cx;
- if( _rcFrame.bottom > _size.cy )
- _rcFrame.bottom = _size.cy;
- }
- else
- _rcFrame.SetRect( 0, 0, _size.cx, _size.cy );
- if( _rcFrame.left >= _rcFrame.right
- || _rcFrame.top >= _rcFrame.bottom
- )
- return false;
- BYTE nLowRed = GetRValue( clrTransparent );
- BYTE nLowGreen = GetGValue( clrTransparent );
- BYTE nLowBlue = GetBValue( clrTransparent );
- BYTE nHighRed = BYTE( min( 0xff, ( nLowRed + GetRValue(clrTolerance) ) ) );
- BYTE nHighGreen = BYTE( min( 0xff, ( nLowGreen + GetGValue(clrTolerance) ) ) );
- BYTE nHighBlue = BYTE( min( 0xff, ( nLowBlue + GetBValue(clrTolerance) ) ) );
- INT nX, nY;
- for( nY = _rcFrame.top; nY < _rcFrame.bottom; nY++ )
- {
- for( nX = _rcFrame.left; nX < _rcFrame.right; nX++ )
- {
- RGBQUAD _pixel;
- VERIFY( GetPixel( nX, nY, _pixel ) );
- if( clrTransparent != COLORREF(-1L) )
- {
- if( _pixel.rgbRed >= nLowRed && _pixel.rgbRed <= nHighRed )
- {
- if( _pixel.rgbGreen >= nLowGreen && _pixel.rgbGreen <= nHighGreen )
- {
- if( _pixel.rgbBlue >= nLowBlue && _pixel.rgbBlue <= nHighBlue )
- continue;
- } // if( nColorPart >= nLowGreen && nColorPart <= nHighGreen )
- } // if( nColorPart >= nLowRed && nColorPart <= nHighRed )
- } // if( clrTransparent != COLORREF(-1L) )
- COLORREF clr =
- RGB(
- _pixel.rgbRed,
- _pixel.rgbGreen,
- _pixel.rgbBlue
- );
- clr =
- CExtBitmap::stat_HLS_Adjust(
- clr,
- percentH,
- percentL,
- percentS
- );
- _pixel.rgbRed = GetRValue(clr);
- _pixel.rgbGreen = GetGValue(clr);
- _pixel.rgbBlue = GetBValue(clr);
- VERIFY( SetPixel( nX, nY, _pixel ) );
- }
- }
- OnContentChanged();
- return true;
- }
- HGLOBAL CExtBitmap::GenerateHGLOBAL(
- HPALETTE hPalDst // = NULL
- ) const
- {
- if( IsEmpty() )
- return NULL;
- HBITMAP hBitmap = CreateBitmap( false );
- if( hBitmap == NULL )
- return NULL;
- HGLOBAL hGlobal = stat_HBITMAPtoHGLOBAL( hBitmap, hPalDst );
- ::DeleteObject( hBitmap );
- return hGlobal;
- }
- HGLOBAL CExtBitmap::stat_HBITMAPtoHGLOBAL(
- HBITMAP hBmpSrc,
- HPALETTE hPalDst // = NULL
- )
- {
- if( hBmpSrc == NULL )
- {
- ASSERT( FALSE );
- return NULL;
- }
- if( hPalDst == NULL )
- hPalDst = (HPALETTE)::GetStockObject( DEFAULT_PALETTE );
- BITMAP bmpSrcDescription;
- ::memset( &bmpSrcDescription, 0, sizeof(BITMAP) );
- ::GetObject( hBmpSrc, sizeof(BITMAP), &bmpSrcDescription );
- ASSERT( bmpSrcDescription.bmWidth > 0 && bmpSrcDescription.bmHeight > 0 );
- BITMAPINFOHEADER bmpSrcInfoHdr;
- ::memset( &bmpSrcInfoHdr, 0, sizeof( BITMAPINFOHEADER ) );
- bmpSrcInfoHdr.biSize = sizeof( BITMAPINFOHEADER );
- bmpSrcInfoHdr.biWidth = bmpSrcDescription.bmWidth;
- bmpSrcInfoHdr.biHeight = bmpSrcDescription.bmHeight;
- bmpSrcInfoHdr.biPlanes = 1;
- bmpSrcInfoHdr.biBitCount = (WORD)
- ( bmpSrcDescription.bmPlanes * bmpSrcDescription.bmBitsPixel );
- bmpSrcInfoHdr.biCompression = BI_RGB;
- INT nColors =
- (bmpSrcInfoHdr.biBitCount > 8)
- ? 0
- : (1 << bmpSrcInfoHdr.biBitCount)
- ;
- DWORD dwLenAllocPart =
- bmpSrcInfoHdr.biSize
- + nColors * sizeof(RGBQUAD)
- ;
- HDC hDcSrc = ::CreateCompatibleDC( NULL );
- if( hDcSrc == NULL )
- {
- ASSERT( FALSE );
- return NULL;
- }
- hPalDst = ::SelectPalette( hDcSrc, hPalDst, FALSE );
- ::RealizePalette( hDcSrc );
- HGLOBAL hGlobalDst =
- ::GlobalAlloc(
- GMEM_FIXED,
- dwLenAllocPart
- );
- if( hGlobalDst == NULL )
- {
- ASSERT( FALSE );
- ::SelectPalette( hDcSrc, hPalDst, FALSE );
- ::DeleteDC( hDcSrc );
- return NULL;
- } // if( hBmpDst == NULL )
-
- LPBITMAPINFOHEADER lpBmpSrcInfoHdr =
- (LPBITMAPINFOHEADER)hGlobalDst;
- *lpBmpSrcInfoHdr = bmpSrcInfoHdr;
- ::GetDIBits(
- hDcSrc,
- hBmpSrc,
- 0L,
- (DWORD)bmpSrcInfoHdr.biHeight,
- (LPBYTE)NULL,
- (LPBITMAPINFO)lpBmpSrcInfoHdr,
- (DWORD)DIB_RGB_COLORS
- );
- bmpSrcInfoHdr = *lpBmpSrcInfoHdr;
- if( bmpSrcInfoHdr.biSizeImage == 0 )
- bmpSrcInfoHdr.biSizeImage =
- (
- (
- (
- (
- bmpSrcInfoHdr.biWidth
- * bmpSrcInfoHdr.biBitCount
- ) + 31
- ) & ~31
- ) / 8
- ) * bmpSrcInfoHdr.biHeight;
- dwLenAllocPart += bmpSrcInfoHdr.biSizeImage;
- HGLOBAL hGlobalTmp =
- ::GlobalReAlloc(
- hGlobalDst,
- dwLenAllocPart,
- GMEM_MOVEABLE
- );
- if( hGlobalTmp == NULL )
- {
- ASSERT( FALSE );
- ::GlobalFree( hGlobalDst ) ;
- ::SelectPalette( hDcSrc, hPalDst, FALSE );
- ::DeleteDC( hDcSrc );
- return NULL;
- } // if( bmpSrcInfoHdr.biSizeImage == 0 )
- hGlobalDst = hGlobalTmp;
- lpBmpSrcInfoHdr = (LPBITMAPINFOHEADER)hGlobalDst;
- if( ! (::GetDIBits(
- hDcSrc,
- hBmpSrc,
- 0L,
- (DWORD)bmpSrcInfoHdr.biHeight,
- (LPBYTE)lpBmpSrcInfoHdr + (bmpSrcInfoHdr.biSize + nColors * sizeof(RGBQUAD)),
- (LPBITMAPINFO)lpBmpSrcInfoHdr,
- (DWORD)DIB_RGB_COLORS
- )
- )
- )
- {
- ASSERT( FALSE );
- ::GlobalFree( hGlobalDst );
- hGlobalDst = NULL;
- }
- ::SelectPalette( hDcSrc, hPalDst, FALSE );
- ::DeleteDC( hDcSrc );
- return hGlobalDst;
- }
- HBITMAP CExtBitmap::stat_CloneBitmap(
- HBITMAP hBmpSrc,
- const RECT * pRcPart, // = NULL
- COLORREF ** ppSurface // = NULL // if not NULL - create 32 bit surface
- )
- {
- if( hBmpSrc == NULL )
- {
- ASSERT( FALSE );
- return NULL;
- }
- BITMAP _bmpInfo;
- ::memset( &_bmpInfo, 0, sizeof(BITMAP) );
- ::GetObject( hBmpSrc, sizeof(BITMAP), &_bmpInfo );
- #ifdef _DEBUG
- DWORD dwLastError = ::GetLastError();
- dwLastError;
- #endif // _DEBUG
- ASSERT( _bmpInfo.bmWidth > 0 && _bmpInfo.bmHeight > 0 );
- CPoint _ptSrc( 0, 0 );
- CSize _sizeDest( _bmpInfo.bmWidth, _bmpInfo.bmHeight );
- if( pRcPart != NULL )
- {
- ASSERT( pRcPart->left < pRcPart->right );
- ASSERT( pRcPart->top < pRcPart->bottom );
- ASSERT( 0 <= pRcPart->left && pRcPart->left <= _bmpInfo.bmWidth );
- ASSERT( 0 <= pRcPart->right && pRcPart->right <= _bmpInfo.bmWidth );
- ASSERT( 0 <= pRcPart->top && pRcPart->top <= _bmpInfo.bmHeight );
- ASSERT( 0 <= pRcPart->bottom && pRcPart->bottom <= _bmpInfo.bmHeight );
- _sizeDest.cx = pRcPart->right - pRcPart->left;
- _sizeDest.cy = pRcPart->bottom - pRcPart->top;
- ASSERT( _sizeDest.cx <= _bmpInfo.bmWidth );
- ASSERT( _sizeDest.cy <= _bmpInfo.bmHeight );
- _ptSrc.x = pRcPart->left;
- _ptSrc.y = pRcPart->top;
- } // if( pRcPart != NULL )
- HDC hSrcDC = ::CreateCompatibleDC( NULL );
- if( hSrcDC == NULL )
- {
- ASSERT( FALSE );
- return NULL;
- }
- HGDIOBJ hBmpSrcOld = ::SelectObject( hSrcDC, (HGDIOBJ)hBmpSrc );
- HBITMAP hBmpDst = NULL;
- if( ppSurface != NULL )
- {
- BITMAPINFOHEADER bih;
- ::memset( &bih, 0, sizeof( BITMAPINFOHEADER ) );
- bih.biSize = sizeof( BITMAPINFOHEADER );
- bih.biWidth = _sizeDest.cx;
- bih.biHeight = _sizeDest.cy;
- bih.biPlanes = 1;
- bih.biBitCount = 32;
- bih.biCompression = BI_RGB;
- bih.biSizeImage = _sizeDest.cx * _sizeDest.cy;
- hBmpDst =
- ::CreateDIBSection(
- hSrcDC,
- (LPBITMAPINFO)&bih,
- DIB_RGB_COLORS,
- (void **)ppSurface,
- NULL,
- NULL
- );
- ASSERT( hBmpDst != NULL );
- ASSERT( (*ppSurface) != NULL );
- } // if( ppSurface != NULL )
- else
- {
- hBmpDst =
- ::CreateCompatibleBitmap(
- hSrcDC,
- _sizeDest.cx,
- _sizeDest.cy
- );
- ASSERT( hBmpDst != NULL );
- } // else from if( ppSurface != NULL )
- if( hBmpDst == NULL )
- {
- ASSERT( FALSE );
- ::SelectObject( hSrcDC, (HGDIOBJ)hBmpSrcOld );
- ::DeleteDC( hSrcDC );
- return NULL;
- }
- HDC hDstDC = ::CreateCompatibleDC( NULL );
- if( hDstDC == NULL )
- {
- ASSERT( FALSE );
- ::DeleteObject( hBmpDst );
- ::SelectObject( hSrcDC, (HGDIOBJ)hBmpSrcOld );
- ::DeleteDC( hSrcDC );
- return NULL;
- }
- HGDIOBJ hBmpDstOld = ::SelectObject( hDstDC, (HGDIOBJ)hBmpDst );
- VERIFY(
- ::BitBlt(
- hDstDC,
- 0, 0, _sizeDest.cx, _sizeDest.cy,
- hSrcDC,
- _ptSrc.x, _ptSrc.y,
- SRCCOPY
- )
- );
- ::SelectObject( hDstDC, (HGDIOBJ)hBmpDstOld );
- ::DeleteDC( hDstDC );
- ::SelectObject( hSrcDC, (HGDIOBJ)hBmpSrcOld );
- ::DeleteDC( hSrcDC );
- return hBmpDst;
- }
- bool CExtBitmap::stat_CloneBitmap(
- CBitmap & bmpDst,
- const CBitmap & bmpSrc,
- const RECT * pRcPart, // = NULL
- COLORREF ** ppSurface // = NULL // if not NULL - create 32 bit surface
- )
- {
- if( bmpSrc.GetSafeHandle() == NULL )
- {
- ASSERT( FALSE );
- return false;
- }
- if( bmpDst.GetSafeHandle() != NULL )
- bmpDst.DeleteObject();
- HBITMAP hBmpDst =
- stat_CloneBitmap(
- (HBITMAP)bmpSrc.GetSafeHandle(),
- pRcPart,
- ppSurface
- );
- if( hBmpDst == NULL )
- {
- ASSERT( FALSE );
- return false;
- }
- bmpDst.Attach( hBmpDst );
- return true;
- }
- HRGN CExtBitmap::GenerateColorHRGN(
- bool bRTL,
- COLORREF clrTransparent,
- COLORREF clrTolerance // = RGB(0,0,0)
- ) const
- {
- if( IsEmpty() )
- {
- ASSERT( FALSE );
- return NULL;
- }
- ULONG nBPP = GetBPP();
- if( nBPP != 32 )
- {
- CExtBitmap other = (*this);
- other.Make32(false);
- return other.GenerateColorHRGN( bRTL, clrTransparent, clrTolerance );
- }
- CSize _sizeBitmap = GetSize();
- ULONG nScanLineSize = stat_RcScanLineSize( _sizeBitmap.cx, nBPP );
- LPBYTE p32bitColorSurface = stat_RcSurface( m_pImageBuffer );
- ASSERT( p32bitColorSurface != NULL );
- static DWORD g_nReallocSize = ( g_PaintManager.m_bIsWinNT4 ? 1 : 200 );
- DWORD nMaxParts = g_nReallocSize;
- HANDLE hGlobal = ::GlobalAlloc( GMEM_MOVEABLE, sizeof(RGNDATAHEADER) + ( sizeof(RECT) * nMaxParts ) );
- RGNDATA * pRgnData = (RGNDATA *) ::GlobalLock( hGlobal );
- ::memset( LPVOID(pRgnData), 0, sizeof(RGNDATAHEADER) + ( sizeof(RECT) * nMaxParts ) );
- pRgnData->rdh.dwSize = sizeof(RGNDATAHEADER);
- pRgnData->rdh.iType = RDH_RECTANGLES;
- pRgnData->rdh.nCount = pRgnData->rdh.nRgnSize = 0;
- ::SetRect( &pRgnData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0 );
- BYTE nLowRed = GetRValue( clrTransparent );
- BYTE nLowGreen = GetGValue( clrTransparent );
- BYTE nLowBlue = GetBValue( clrTransparent );
- BYTE nHighRed = BYTE( min( 0xff, ( nLowRed + GetRValue(clrTolerance) ) ) );
- BYTE nHighGreen = BYTE( min( 0xff, ( nLowGreen + GetGValue(clrTolerance) ) ) );
- BYTE nHighBlue = BYTE( min( 0xff, ( nLowBlue + GetBValue(clrTolerance) ) ) );
- HRGN hRgnResult = NULL;
- for( INT _nY = 0; _nY < _sizeBitmap.cy; _nY++ )
- {
- INT nY = _sizeBitmap.cy - _nY - 1;
- for( INT nX = 0; nX < _sizeBitmap.cx; nX++ )
- {
- LPLONG ptrLinePart = (LPLONG)p32bitColorSurface + nX;
- INT nSavedX = nX;
- for( ; nX < _sizeBitmap.cx; ptrLinePart++, nX++ )
- {
- BYTE nColorPart = GetRValue( (*ptrLinePart) );
- if( nColorPart >= nLowRed && nColorPart <= nHighRed )
- {
- nColorPart = GetGValue( (*ptrLinePart) );
- if( nColorPart >= nLowGreen && nColorPart <= nHighGreen )
- {
- nColorPart = GetBValue( (*ptrLinePart) );
- if( nColorPart >= nLowBlue && nColorPart <= nHighBlue )
- break;
- } // if( nColorPart >= nLowGreen && nColorPart <= nHighGreen )
- } // if( nColorPart >= nLowRed && nColorPart <= nHighRed )
- } // for( ; nX < _sizeBitmap.cx; ptrLinePart++, nX++ )
- if( nX > nSavedX )
- {
- if( pRgnData->rdh.nCount >= nMaxParts )
- {
- ::GlobalUnlock( hGlobal );
- DWORD dwPrevParts = nMaxParts;
- nMaxParts += g_nReallocSize;
- hGlobal = ::GlobalReAlloc( hGlobal, sizeof(RGNDATAHEADER) + (sizeof(RECT) * nMaxParts), GMEM_MOVEABLE );
- pRgnData = (RGNDATA *) ::GlobalLock( hGlobal );
- ::memset( LPVOID( LPBYTE(pRgnData) + sizeof(RGNDATAHEADER) + ( sizeof(RECT) * dwPrevParts ) ), 0, sizeof(RECT) * ( nMaxParts - dwPrevParts ) );
- } // if( pRgnData->rdh.nCount >= nMaxParts )
- LPRECT pRect = (LPRECT)&pRgnData->Buffer;
- ::SetRect( &pRect[pRgnData->rdh.nCount], nSavedX, nY, nX, nY + 1 );
- if( nSavedX < pRgnData->rdh.rcBound.left )
- pRgnData->rdh.rcBound.left = nSavedX;
- if( nY < pRgnData->rdh.rcBound.top )
- pRgnData->rdh.rcBound.top = nY;
- if( nX > pRgnData->rdh.rcBound.right )
- pRgnData->rdh.rcBound.right = nX;
- if( (nY + 1) > pRgnData->rdh.rcBound.bottom )
- pRgnData->rdh.rcBound.bottom = nY+1;
- pRgnData->rdh.nCount ++;
- if( pRgnData->rdh.nCount == DWORD( g_PaintManager.m_bIsWinNT4 ? 1 : 2000 ) )
- {
- if( bRTL )
- {
- INT nPart, nLeft, nRight, nCount = INT( pRgnData->rdh.nCount );
- LPRECT pRect = (LPRECT)&pRgnData->Buffer;
- for( nPart = 0; nPart < nCount; nPart ++, pRect ++ )
- {
- nLeft = _sizeBitmap.cx - pRect->left;
- nRight = _sizeBitmap.cx - pRect->right;
- pRect->right = nLeft;
- pRect->left = nRight;
- } // for( nPart = 0; nPart < nCount; nPart ++, pRect ++ )
- } // if( bRTL )
- HRGN hRgnPart = ::ExtCreateRegion( NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * nMaxParts), pRgnData );
- if( hRgnResult != NULL )
- {
- ::CombineRgn( hRgnResult, hRgnResult, hRgnPart, RGN_OR );
- ::DeleteObject( hRgnPart );
- } // if( hRgnResult != NULL )
- else
- hRgnResult = hRgnPart;
- pRgnData->rdh.nCount = 0;
- ::SetRect( &pRgnData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0 );
- } // if( pRgnData->rdh.nCount == ( g_PaintManager.m_bIsWinNT4 ? 1 : 2000 ) )
- } // if( nX > nSavedX )
- } // for( INT nX = 0; nX < _sizeBitmap.cx; nX++ )
- p32bitColorSurface += nScanLineSize;
- } // for( INT _nY = 0; _nY < _sizeBitmap.cy; _nY++ )
- if( bRTL )
- {
- INT nPart, nLeft, nRight, nCount = INT( pRgnData->rdh.nCount );
- LPRECT pRect = (LPRECT)&pRgnData->Buffer;
- for( nPart = 0; nPart < nCount; nPart ++, pRect ++ )
- {
- nLeft = _sizeBitmap.cx - pRect->left;
- nRight = _sizeBitmap.cx - pRect->right;
- pRect->right = nLeft;
- pRect->left = nRight;
- } // for( nPart = 0; nPart < nCount; nPart ++, pRect ++ )
- } // if( bRTL )
- HRGN hRgnPart = ::ExtCreateRegion( NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * nMaxParts), pRgnData );
- if( hRgnResult != NULL )
- {
- ::CombineRgn( hRgnResult, hRgnResult, hRgnPart, RGN_OR );
- ::DeleteObject( hRgnPart );
- } // if( hRgnResult != NULL )
- else
- hRgnResult = hRgnPart;
- ::GlobalFree( hGlobal );
- return hRgnResult;
- }
- bool CExtBitmap::SetPixel(
- INT nX,
- INT nY,
- COLORREF clr, // if COLORREF( -1L ) - do not set color
- INT nAlpha // = -1 // less than zero - do not set alpha
- )
- {
- if( IsEmpty() )
- return false;
- if( clr == COLORREF(-1L) && nAlpha < 0 )
- return false;
- bool bSetColor = false, bSetAlpha = false;
- RGBQUAD _pixel = { 0, 0, 0, 0 };
- if( clr != COLORREF(-1L) )
- {
- bSetColor = true;
- _pixel.rgbRed = GetRValue( clr );
- _pixel.rgbGreen = GetGValue( clr );
- _pixel.rgbBlue = GetBValue( clr );
- }
- if( nAlpha >= 0 )
- {
- bSetAlpha = true;
- if( nAlpha > 0x0FF )
- nAlpha = 0x0FF;
- _pixel.rgbReserved = BYTE( nAlpha );
- } // if( nAlpha >= 0 )
- return
- SetPixel(
- nX,
- nY,
- _pixel,
- bSetColor,
- bSetColor,
- bSetColor,
- bSetAlpha
- );
- }
- HRGN CExtBitmap::GenerateSkinPartColorRGN(
- bool bRTL,
- const RECT & rcDst,
- const RECT & rcSrc,
- const RECT & rcPadding,
- COLORREF clrTransparent,
- bool bLeft,
- bool bTop
- ) const
- {
- if( IsEmpty() )
- return NULL;
- CRect rcIn = rcSrc;
- CRect rcOut = rcDst;
- if( bLeft )
- {
- rcIn.right = rcIn.left + rcPadding.left;
- rcOut.right = rcOut.left + rcPadding.left;
- }
- else
- {
- rcIn.left = rcIn.right - rcPadding.right;
- rcOut.left = rcOut.right - rcPadding.right;
- }
- if( bTop )
- {
- rcIn.bottom = rcIn.top + rcPadding.top;
- rcOut.bottom = rcOut.top + rcPadding.top;
- }
- else
- {
- rcIn.top = rcIn.bottom - rcPadding.bottom;
- rcOut.top = rcOut.bottom - rcPadding.bottom;
- }
- INT xIn, yIn, xOut, yOut;
- CRgn _rgnRetVal;
- for( yIn = rcIn.top, yOut = rcOut.top; yIn < rcIn.bottom; yIn++, yOut++ )
- {
- for( xIn = rcIn.left, xOut = rcOut.left; xIn < rcIn.right; xIn++, xOut++ )
- {
- COLORREF clr = GetPixel( xIn, yIn );
- ASSERT( clr != COLORREF(-1L) );
- if( clr != clrTransparent )
- continue;
- CRgn _rgnPixel;
- if( bRTL )
- {
- if( ! _rgnPixel.CreateRectRgn(
- rcOut.right - 1 - xOut + rcOut.left,
- yOut,
- rcOut.right - xOut + rcOut.left,
- yOut + 1
- )
- )
- {
- ASSERT( FALSE );
- return NULL;
- }
- } // if( bRTL )
- else
- {
- if( ! _rgnPixel.CreateRectRgn(
- xOut,
- yOut,
- xOut + 1,
- yOut + 1
- )
- )
- {
- ASSERT( FALSE );
- return NULL;
- }
- } // else from if( bRTL )
- if( _rgnRetVal.GetSafeHandle() == NULL )
- {
- if( ! _rgnRetVal.CreateRectRgn( 0, 0, 0, 0 ) )
- {
- ASSERT( FALSE );
- return NULL;
- }
- }
- int nCombineRetVal =
- _rgnRetVal.CombineRgn( &_rgnRetVal, &_rgnPixel, RGN_OR );
- if( nCombineRetVal == RGN_ERROR )
- {
- ASSERT( FALSE );
- return NULL;
- }
- } // for( xIn = rcIn.left, xOut = rcOut.left; xIn < rcIn.right; xIn++, xOut++ )
- } // for( yIn = rcIn.top, yOut = rcOut.top; yIn < rcIn.bottom; yIn++, yOut++ )
- return ( ( _rgnRetVal.GetSafeHandle() != NULL ) ? ((HRGN)_rgnRetVal.Detach()) : NULL );
- }
- HRGN CExtBitmap::GenerateSkinPartColorRGN(
- bool bRTL,
- const RECT & rcDst,
- const RECT & rcPadding,
- COLORREF clrTransparent,
- bool bLeft,
- bool bTop
- ) const
- {
- if( IsEmpty() )
- return NULL;
- CSize _size = GetSize();
- RECT rcSrc = { 0, 0, _size.cx, _size.cy };
- return
- GenerateSkinPartColorRGN(
- bRTL,
- rcDst,
- rcSrc,
- rcPadding,
- clrTransparent,
- bLeft,
- bTop
- );
- }
- HRGN CExtBitmap::GenerateSkinFrameColorRGN(
- bool bRTL,
- const RECT & rcDst,
- const RECT & rcSrc,
- const RECT & rcPadding,
- COLORREF clrTransparent
- ) const
- {
- if( IsEmpty() )
- return NULL;
- rcDst;
- rcSrc;
- HRGN hRgnLT =
- GenerateSkinPartColorRGN(
- bRTL,
- rcDst,
- rcSrc,
- rcPadding,
- clrTransparent,
- true,
- true
- );
- HRGN hRgnLB =
- GenerateSkinPartColorRGN(
- bRTL,
- rcDst,
- rcSrc,
- rcPadding,
- clrTransparent,
- true,
- false
- );
- HRGN hRgnRT =
- GenerateSkinPartColorRGN(
- bRTL,
- rcDst,
- rcSrc,
- rcPadding,
- clrTransparent,
- false,
- true
- );
- HRGN hRgnRB =
- GenerateSkinPartColorRGN(
- bRTL,
- rcDst,
- rcSrc,
- rcPadding,
- clrTransparent,
- false,
- false
- );
- if( hRgnLT == NULL
- && hRgnLB == NULL
- && hRgnRT == NULL
- && hRgnRB == NULL
- )
- return NULL;
- HRGN hRgnRetVal =
- ::CreateRectRgnIndirect( &rcDst );
- if( hRgnRetVal != NULL )
- {
- if( hRgnLT != NULL )
- ::CombineRgn( hRgnRetVal, hRgnRetVal, hRgnLT, RGN_DIFF );
- if( hRgnLB != NULL )
- ::CombineRgn( hRgnRetVal, hRgnRetVal, hRgnLB, RGN_DIFF );
- if( hRgnRT != NULL )
- ::CombineRgn( hRgnRetVal, hRgnRetVal, hRgnRT, RGN_DIFF );
- if( hRgnRB != NULL )
- ::CombineRgn( hRgnRetVal, hRgnRetVal, hRgnRB, RGN_DIFF );
- } // if( hRgnRetVal != NULL )
- if( hRgnLT != NULL )
- DeleteObject( hRgnLT );
- if( hRgnLB != NULL )
- DeleteObject( hRgnLB );
- if( hRgnRT != NULL )
- DeleteObject( hRgnRT );
- if( hRgnRB != NULL )
- DeleteObject( hRgnRB );
- return hRgnRetVal; // NOT IMPL
- }
- HRGN CExtBitmap::GenerateSkinFrameColorRGN(
- bool bRTL,
- const RECT & rcDst,
- const RECT & rcPadding,
- COLORREF clrTransparent
- ) const
- {
- if( IsEmpty() )
- return NULL;
- CSize _size = GetSize();
- RECT rcSrc = { 0, 0, _size.cx, _size.cy };
- return
- GenerateSkinFrameColorRGN(
- bRTL,
- rcDst,
- rcSrc,
- rcPadding,
- clrTransparent
- );
- }
- HRGN CExtBitmap::GenerateSkinPartAlphaRGN(
- bool bRTL,
- const RECT & rcDst,
- const RECT & rcSrc,
- const RECT & rcPadding,
- bool bLeft,
- bool bTop,
- BYTE nAlphaMin, // = BYTE(0)
- BYTE nAlphaMax // = BYTE(0)
- ) const
- {
- if( IsEmpty() )
- return NULL;
- CRect rcIn = rcSrc;
- CRect rcOut = rcDst;
- if( bLeft )
- {
- rcIn.right = rcIn.left + rcPadding.left;
- rcOut.right = rcOut.left + rcPadding.left;
- }
- else
- {
- rcIn.left = rcIn.right - rcPadding.right;
- rcOut.left = rcOut.right - rcPadding.right;
- }
- if( bTop )
- {
- rcIn.bottom = rcIn.top + rcPadding.top;
- rcOut.bottom = rcOut.top + rcPadding.top;
- }
- else
- {
- rcIn.top = rcIn.bottom - rcPadding.bottom;
- rcOut.top = rcOut.bottom - rcPadding.bottom;
- }
- INT xIn, yIn, xOut, yOut;
- CRgn _rgnRetVal;
- for( yIn = rcIn.top, yOut = rcOut.top; yIn < rcIn.bottom; yIn++, yOut++ )
- {
- for( xIn = rcIn.left, xOut = rcOut.left; xIn < rcIn.right; xIn++, xOut++ )
- {
- RGBQUAD _pixel;
- VERIFY( GetPixel( xIn, yIn, _pixel ) );
- if( !( nAlphaMin <= _pixel.rgbReserved && _pixel.rgbReserved <= nAlphaMax ) )
- continue;
- CRgn _rgnPixel;
- if( bRTL )
- {
- if( ! _rgnPixel.CreateRectRgn(
- rcOut.right - 1 - xOut + rcOut.left,
- yOut,
- rcOut.right - xOut + rcOut.left,
- yOut + 1
- )
- )
- {
- ASSERT( FALSE );
- return NULL;
- }
- } // if( bRTL )
- else
- {
- if( ! _rgnPixel.CreateRectRgn(
- xOut,
- yOut,
- xOut + 1,
- yOut + 1
- )
- )
- {
- ASSERT( FALSE );
- return NULL;
- }
- } // else from if( bRTL )
- if( _rgnRetVal.GetSafeHandle() == NULL )
- {
- if( ! _rgnRetVal.CreateRectRgn( 0, 0, 0, 0 ) )
- {
- ASSERT( FALSE );
- return NULL;
- }
- }
- int nCombineRetVal =
- _rgnRetVal.CombineRgn( &_rgnRetVal, &_rgnPixel, RGN_OR );
- if( nCombineRetVal == RGN_ERROR )
- {
- ASSERT( FALSE );
- return NULL;
- }
- } // for( xIn = rcIn.left, xOut = rcOut.left; xIn < rcIn.right; xIn++, xOut++ )
- } // for( yIn = rcIn.top, yOut = rcOut.top; yIn < rcIn.bottom; yIn++, yOut++ )
- return ( ( _rgnRetVal.GetSafeHandle() != NULL ) ? ((HRGN)_rgnRetVal.Detach()) : NULL );
- }
- HRGN CExtBitmap::GenerateSkinPartAlphaRGN(
- bool bRTL,
- const RECT & rcDst,
- const RECT & rcPadding,
- bool bLeft,
- bool bTop,
- BYTE nAlphaMin, // = BYTE(0)
- BYTE nAlphaMax // = BYTE(0)
- ) const
- {
- if( IsEmpty() )
- return NULL;
- CSize _size = GetSize();
- RECT rcSrc = { 0, 0, _size.cx, _size.cy };
- return
- GenerateSkinPartAlphaRGN(
- bRTL,
- rcDst,
- rcSrc,
- rcPadding,
- bLeft,
- bTop,
- nAlphaMin,
- nAlphaMax
- );
- }
- HRGN CExtBitmap::GenerateSkinFrameAlphaRGN(
- bool bRTL,
- const RECT & rcDst,
- const RECT & rcSrc,
- const RECT & rcPadding,
- BYTE nAlphaMin, // = BYTE(0)
- BYTE nAlphaMax // = BYTE(0)
- ) const
- {
- if( IsEmpty() )
- return NULL;
- rcDst;
- rcSrc;
- HRGN hRgnLT =
- GenerateSkinPartAlphaRGN(
- bRTL,
- rcDst,
- rcSrc,
- rcPadding,
- true,
- true,
- nAlphaMin,
- nAlphaMax
- );
- HRGN hRgnLB =
- GenerateSkinPartAlphaRGN(
- bRTL,
- rcDst,
- rcSrc,
- rcPadding,
- true,
- false,
- nAlphaMin,
- nAlphaMax
- );
- HRGN hRgnRT =
- GenerateSkinPartAlphaRGN(
- bRTL,
- rcDst,
- rcSrc,
- rcPadding,
- false,
- true,
- nAlphaMin,
- nAlphaMax
- );
- HRGN hRgnRB =
- GenerateSkinPartAlphaRGN(
- bRTL,
- rcDst,
- rcSrc,
- rcPadding,
- false,
- false,
- nAlphaMin,
- nAlphaMax
- );
- if( hRgnLT == NULL
- && hRgnLB == NULL
- && hRgnRT == NULL
- && hRgnRB == NULL
- )
- return NULL;
- HRGN hRgnRetVal =
- ::CreateRectRgnIndirect( &rcDst );
- if( hRgnRetVal != NULL )
- {
- if( hRgnLT != NULL )
- ::CombineRgn( hRgnRetVal, hRgnRetVal, hRgnLT, RGN_DIFF );
- if( hRgnLB != NULL )
- ::CombineRgn( hRgnRetVal, hRgnRetVal, hRgnLB, RGN_DIFF );
- if( hRgnRT != NULL )
- ::CombineRgn( hRgnRetVal, hRgnRetVal, hRgnRT, RGN_DIFF );
- if( hRgnRB != NULL )
- ::CombineRgn( hRgnRetVal, hRgnRetVal, hRgnRB, RGN_DIFF );
- } // if( hRgnRetVal != NULL )
- if( hRgnLT != NULL )
- DeleteObject( hRgnLT );
- if( hRgnLB != NULL )
- DeleteObject( hRgnLB );
- if( hRgnRT != NULL )
- DeleteObject( hRgnRT );
- if( hRgnRB != NULL )
- DeleteObject( hRgnRB );
- return hRgnRetVal; // NOT IMPL
- }
- HRGN CExtBitmap::GenerateSkinFrameAlphaRGN(
- bool bRTL,
- const RECT & rcDst,
- const RECT & rcPadding,
- BYTE nAlphaMin, // = BYTE(0)
- BYTE nAlphaMax // = BYTE(0)
- ) const
- {
- if( IsEmpty() )
- return NULL;
- CSize _size = GetSize();
- RECT rcSrc = { 0, 0, _size.cx, _size.cy };
- return
- GenerateSkinFrameAlphaRGN(
- bRTL,
- rcDst,
- rcSrc,
- rcPadding,
- nAlphaMin,
- nAlphaMax
- );
- }
- CSize CExtBitmap::GetSize() const
- {
- if( IsEmpty() )
- return CSize( 0, 0 );
- LPBITMAPINFOHEADER pBIH = stat_RcInfoHeader( m_pImageBuffer );
- return CSize( pBIH->biWidth, pBIH->biHeight );
- }
- #pragma pack(push, 1)
- bool CExtBitmap::AssignFromHICON(
- HICON hIcon,
- bool bForceLowColorMode // = false
- )
- {
- // Empty();
- // if( hIcon == NULL )
- // return true;
- // ICONINFO _iconInfo;
- // ::memset( &_iconInfo, 0, sizeof(ICONINFO) );
- // if( ! ::GetIconInfo( hIcon, &_iconInfo ) )
- // return false;
- // ASSERT( _iconInfo.hbmColor != NULL || _iconInfo.hbmMask != NULL );
- // CSize _sizeIcon(
- // (INT)( (BYTE)(_iconInfo.xHotspot * 2 ) ),
- // (INT)( (BYTE)(_iconInfo.yHotspot * 2 ) )
- // );
- // if( _sizeIcon.cx == 0 || _sizeIcon.cy == 0 )
- // {
- // BITMAP _bmpInfo;
- // ::memset( &_bmpInfo, 0, sizeof(BITMAP) );
- // ::GetObject(
- // (_iconInfo.hbmColor != NULL) ? _iconInfo.hbmColor : _iconInfo.hbmMask,
- // sizeof(BITMAP),
- // &_bmpInfo
- // );
- // ASSERT( _bmpInfo.bmWidth > 0 && _bmpInfo.bmHeight > 0 );
- // _sizeIcon.cx = (INT)_bmpInfo.bmWidth;
- // _sizeIcon.cy = (INT)_bmpInfo.bmHeight;
- // } // if( m_sizeIcon.cx == 0 || m_sizeIcon.cy == 0 )
- // ASSERT( _sizeIcon.cx > 0 );
- // ASSERT( _sizeIcon.cy > 0 );
- // if( _iconInfo.hbmColor == NULL && _iconInfo.hbmMask != NULL )
- // {
- // CRect rc( 0, 0, _sizeIcon.cx, _sizeIcon.cy );
- // if( FromBitmap( _iconInfo.hbmMask, &rc, false, false ) )
- // {
- // } // if( FromBitmap ...
- // else
- // Empty();
- // } // if( _iconInfo.hbmColor == NULL && _iconInfo.hbmMask != NULL )
- // else if( _iconInfo.hbmColor != NULL )
- // {
- // if( FromBitmap( _iconInfo.hbmColor, false ) )
- // {
- // if( Make32( false ) )
- // {
- // if( _iconInfo.hbmMask != NULL )
- // {
- // CExtBitmap bmpMask;
- // if( bmpMask.FromBitmap( _iconInfo.hbmMask )
- // && bmpMask.Make32( false )
- // )
- // {
- // INT nX, nY;
- // for( nY = 0; nY < _sizeIcon.cy; nY ++ )
- // {
- // for( nX = 0; nX < _sizeIcon.cx; nX ++ )
- // {
- // RGBQUAD _pixel;
- // VERIFY( GetPixel( nX, nY, _pixel ) );
- // COLORREF clrMaskPixel = bmpMask.GetPixel( nX, nY );
- // if( clrMaskPixel == RGB(0,0,0) )
- // _pixel.rgbReserved = 0xFF;
- // else
- // _pixel.rgbReserved = 0x0;
- // VERIFY( SetPixel( nX, nY, _pixel ) );
- // } // for( nX = 0; nX < _sizeIcon.cx; nX ++ )
- // } // for( nY = 0; nY < _sizeIcon.cy; nY ++ )
- // } // if( bmpMask.FromBitmap( _iconInfo.hbmMask ...
- // else
- // Empty();
- // } // if( _iconInfo.hbmMask != NULL )
- // } // if( Make32( false ) )
- // else
- // Empty();
- // } // if( FromBitmap( _iconInfo.hbmColor, false ) )
- // } // else if( _iconInfo.hbmColor != NULL )
- // if( _iconInfo.hbmColor != NULL )
- // ::DeleteObject( _iconInfo.hbmColor );
- // if( _iconInfo.hbmMask != NULL )
- // ::DeleteObject( _iconInfo.hbmMask );
- // OnContentChanged();
- // bool bIsEmpty = IsEmpty();
- // return ( ! bIsEmpty );
- Empty();
- if( hIcon == NULL )
- return true;
- ICONINFO _iconInfo;
- ::memset( &_iconInfo, 0, sizeof(ICONINFO) );
- if( ! ::GetIconInfo( hIcon, &_iconInfo ) )
- return false;
- ASSERT( _iconInfo.hbmColor != NULL || _iconInfo.hbmMask != NULL );
- CSize _sizeIcon(
- (INT)( (BYTE)(_iconInfo.xHotspot * 2 ) ),
- (INT)( (BYTE)(_iconInfo.yHotspot * 2 ) )
- );
- BITMAP _bmpInfo;
- ::memset( &_bmpInfo, 0, sizeof(BITMAP) );
- ::GetObject(
- (_iconInfo.hbmColor != NULL) ? _iconInfo.hbmColor : _iconInfo.hbmMask,
- sizeof(BITMAP),
- &_bmpInfo
- );
- ASSERT( _bmpInfo.bmWidth > 0 && _bmpInfo.bmHeight > 0 );
- // if( _sizeIcon.cx == 0 || _sizeIcon.cy == 0 )
- if( _bmpInfo.bmWidth > 0 && _bmpInfo.bmHeight > 0 && _bmpInfo.bmBitsPixel > 1 )
- {
- _sizeIcon.cx = (INT)_bmpInfo.bmWidth;
- _sizeIcon.cy = (INT)_bmpInfo.bmHeight;
- } // if( m_sizeIcon.cx == 0 || m_sizeIcon.cy == 0 )
- //ASSERT( _sizeIcon.cx > 0 );
- //ASSERT( _sizeIcon.cy > 0 );
- if( (! bForceLowColorMode )
- /// && _bmpInfo.bmBitsPixel == 32
- //// && _iconInfo.hbmColor != NULL
- //// && _iconInfo.hbmMask == NULL
- // && g_PaintManager.m_bIsWinXPorLater
- // && CExtPaintManager::stat_GetBPP() >= 32
- )
- { // XP alpha icons under Windows XP or later + 32 bit desktop
- CExtImageList _il;
- if( _il.Create( _sizeIcon.cx, _sizeIcon.cy, ILC_COLOR32, 1, 1 ) )
- {
- if( _il.Add( hIcon ) >= 0 )
- // if( _il.Add(
- // CBitmap::FromHandle( _iconInfo.hbmColor ),
- // CBitmap::FromHandle( _iconInfo.hbmMask )
- // ) >= 0
- // )
- {
- IMAGEINFO _ii = { 0 };
- _il.GetImageInfo( 0, &_ii );
- ASSERT( _ii.hbmImage != NULL );
- ASSERT( _ii.hbmMask == NULL );
- if( ! FromBitmap(
- _ii.hbmImage,
- &_ii.rcImage,
- false,
- true
- )
- )
- Empty();
- else
- {
- bool bAssignedEmpty = true;
- for( INT nY = 0; nY < _sizeIcon.cy; nY++ )
- {
- for( INT nX = 0; nX < _sizeIcon.cx; nX++ )
- {
- RGBQUAD _pixel;
- VERIFY( GetPixel( nX, nY, _pixel ) );
- if( _pixel.rgbReserved != 0 )
- {
- bAssignedEmpty = false;
- break;
- }
- }
- if( ! bAssignedEmpty )
- break;
- }
- if( bAssignedEmpty )
- Empty();
- }
- ::DeleteObject( _ii.hbmImage );
- }
- _il.DeleteImageList();
- }
- //////////////::DestroyIcon( hIcon );
- } // XP alpha icons under Windows XP or later + 32 bit desktop
-
- if( IsEmpty() )
- { // old style icon
- if( _iconInfo.hbmColor == NULL && _iconInfo.hbmMask != NULL )
- {
- CRect rc( 0, 0, _sizeIcon.cx, _sizeIcon.cy );
- if( FromBitmap( _iconInfo.hbmMask, &rc, false, false ) )
- {
- } // if( FromBitmap ...
- else
- Empty();
- } // if( _iconInfo.hbmColor == NULL && _iconInfo.hbmMask != NULL )
- else if( _iconInfo.hbmColor != NULL )
- {
- if( FromBitmap( _iconInfo.hbmColor, false ) )
- {
- if( Make32( false ) )
- {
- if( _iconInfo.hbmMask != NULL )
- {
- CExtBitmap bmpMask;
- if( bmpMask.FromBitmap( _iconInfo.hbmMask )
- && bmpMask.Make32( false )
- )
- {
- INT nX, nY;
- for( nY = 0; nY < _sizeIcon.cy; nY ++ )
- {
- for( nX = 0; nX < _sizeIcon.cx; nX ++ )
- {
- RGBQUAD _pixel;
- VERIFY( GetPixel( nX, nY, _pixel ) );
- COLORREF clrMaskPixel = bmpMask.GetPixel( nX, nY );
- if( clrMaskPixel == RGB(0,0,0) )
- _pixel.rgbReserved = 0xFF;
- else
- _pixel.rgbReserved = 0x0;
- VERIFY( SetPixel( nX, nY, _pixel ) );
- } // for( nX = 0; nX < _sizeIcon.cx; nX ++ )
- } // for( nY = 0; nY < _sizeIcon.cy; nY ++ )
- } // if( bmpMask.FromBitmap( _iconInfo.hbmMask ...
- else
- Empty();
- } // if( _iconInfo.hbmMask != NULL )
- } // if( Make32( false ) )
- else
- Empty();
- } // if( FromBitmap( _iconInfo.hbmColor, false ) )
- } // else if( _iconInfo.hbmColor != NULL )
- } // old style icon
- if( _iconInfo.hbmColor != NULL )
- ::DeleteObject( _iconInfo.hbmColor );
- if( _iconInfo.hbmMask != NULL )
- ::DeleteObject( _iconInfo.hbmMask );
- bool bIsEmpty = IsEmpty();
- if( ! bIsEmpty )
- OnLoad();
- return ( ! bIsEmpty );
- }
- bool CExtBitmap::AssignFromOther(
- const CExtBitmap & other,
- bool bEnableThrowException // = false
- )
- {
- Empty();
- if( other.IsEmpty() )
- return true;
- CSize _size = other.GetSize();
- ULONG nBPP = other.GetBPP();
- m_pImageBuffer =
- stat_AllocHL(
- _size.cx,
- _size.cy,
- nBPP,
- stat_MaskRed( LPBYTE( other.m_pImageBuffer ) ),
- stat_MaskGreen( LPBYTE( other.m_pImageBuffer ) ),
- stat_MaskBlue( LPBYTE( other.m_pImageBuffer ) ),
- stat_MaskAlpha( LPBYTE( other.m_pImageBuffer ) ),
- stat_RunTimeFlagsGet( LPBYTE( other.m_pImageBuffer ) )
- );
- if( m_pImageBuffer == NULL )
- {
- if( bEnableThrowException )
- ::AfxThrowUserException();
- return false;
- }
- UINT nSizeInBytes =
- stat_RcImageBufferSize(
- _size.cx,
- _size.cy,
- nBPP
- ) - sizeof( BITMAPINFOHEADER );
- __EXT_MFC_MEMCPY(
- LPBYTE( stat_RcInfoHeader( m_pImageBuffer ) )
- + sizeof( BITMAPINFOHEADER ),
- nSizeInBytes,
- LPBYTE( stat_RcInfoHeader( LPBYTE( other.m_pImageBuffer ) ) )
- + sizeof( BITMAPINFOHEADER ),
- nSizeInBytes
- );
- OnLoad();
- return true;
- }
- ULONG CExtBitmap::GetBPP() const
- {
- if( IsEmpty() )
- return 0;
- LPBITMAPINFOHEADER pBIH = stat_RcInfoHeader( m_pImageBuffer );
- return pBIH->biBitCount;
- }
- ULONG CExtBitmap::stat_RcLine(
- ULONG nWidth,
- ULONG nBPP
- )
- {
- return ( ( nWidth * nBPP ) + 7 ) / 8;
- }
- ULONG CExtBitmap::stat_RcScanLineSize(
- ULONG nLineIndex
- )
- {
- return nLineIndex + 3 & (~3);
- }
- ULONG CExtBitmap::stat_RcScanLineSize(
- ULONG nWidth,
- ULONG nBPP
- )
- {
- return stat_RcScanLineSize( stat_RcLine( nWidth, nBPP ) );
- }
- ULONG CExtBitmap::stat_RcUPE( ULONG nBPP )
- {
- if( nBPP >= 1
- && nBPP <= 8
- )
- return ( 1 << nBPP );
- return 0;
- }
- LPBYTE CExtBitmap::stat_RcOffsetToScanLine(
- LPBYTE pBitsStart,
- ULONG nScanLineSize,
- ULONG nLineIndex
- )
- {
- return ( pBitsStart + ( nScanLineSize * nLineIndex ) );
- }
- ULONG CExtBitmap::stat_RcImageBufferSize(
- ULONG nWidth,
- ULONG hHeight,
- ULONG nBPP
- )
- {
- ULONG nImageBufferSize = sizeof( BITMAPINFOHEADER );
- ULONG nUPE = stat_RcUPE( nBPP );
- nImageBufferSize += sizeof( RGBQUAD ) * nUPE;
- if( ( nImageBufferSize % 16 ) != 0 )
- {
- ULONG nAlignmentRest =
- 16 - ( nImageBufferSize % 16 );
- nImageBufferSize += nAlignmentRest;
- }
- ULONG nScanLineSize = stat_RcScanLineSize( nWidth, nBPP );
- nImageBufferSize += nScanLineSize * hHeight;
- return nImageBufferSize;
- }
- LPBITMAPINFOHEADER CExtBitmap::stat_RcInfoHeader(
- LPBYTE pImageBuffer
- )
- {
- ASSERT( pImageBuffer != NULL );
- return ( (LPBITMAPINFOHEADER) pImageBuffer );
- }
- LPBITMAPINFO CExtBitmap::stat_RcInfo(
- LPBYTE pImageBuffer
- )
- {
- ASSERT( pImageBuffer != NULL );
- return ( (LPBITMAPINFO) pImageBuffer );
- }
- LPBYTE CExtBitmap::stat_RcScanLine(
- LPBYTE pImageBuffer,
- ULONG nLineIndex,
- ULONG nScanLineSize
- )
- {
- ASSERT( pImageBuffer != NULL );
- LPBITMAPINFOHEADER pBIH = stat_RcInfoHeader( pImageBuffer );
- ULONG nUPE = stat_RcUPE( pBIH->biBitCount );
- ULONG nOffset = sizeof( BITMAPINFOHEADER ) + sizeof( RGBQUAD ) * nUPE;
- if( ( nOffset % 16 ) != 0 )
- {
- ULONG nAlignmentRest =
- 16 - ( nOffset % 16 );
- nOffset += nAlignmentRest;
- }
- return
- stat_RcOffsetToScanLine(
- pImageBuffer,
- nScanLineSize,
- nLineIndex
- ) + nOffset;
- }
- LPBYTE CExtBitmap::stat_RcSurface(
- LPBYTE pImageBuffer
- )
- {
- ASSERT( pImageBuffer != NULL );
- LPBITMAPINFOHEADER pBIH = stat_RcInfoHeader( pImageBuffer );
- ULONG nUPE = stat_RcUPE( pBIH->biBitCount );
- ULONG nOffset = sizeof( BITMAPINFOHEADER ) + sizeof( RGBQUAD ) * nUPE;
- if( ( nOffset % 16 ) != 0 )
- {
- ULONG nAlignmentRest =
- 16 - ( nOffset % 16 );
- nOffset += nAlignmentRest;
- }
- return pImageBuffer + nOffset;
- }
- LPVOID CExtBitmap::stat_AllocLL(
- __EXT_MFC_ULONG_PTR amount,
- __EXT_MFC_ULONG_PTR alignment
- )
- {
- ASSERT( alignment >= sizeof(__EXT_MFC_ULONG_PTR) );
- LPBYTE mem_real = new BYTE[ amount + alignment * 2 ];
- LPBYTE mem_align = (LPBYTE)
- ( (__EXT_MFC_ULONG_PTR)
- ( alignment
- - ( (__EXT_MFC_ULONG_PTR)mem_real % (__EXT_MFC_ULONG_PTR)alignment )
- )
- + (__EXT_MFC_ULONG_PTR)mem_real
- );
- mem_align += alignment;
- *((__EXT_MFC_ULONG_PTR*)mem_align - 1) = (__EXT_MFC_ULONG_PTR)mem_real;
- return mem_align;
- }
- void CExtBitmap::stat_FreeLL( LPVOID pMemToFree )
- {
- pMemToFree = (LPVOID)*((__EXT_MFC_ULONG_PTR*)pMemToFree-1);
- LPBYTE pMemToDelete = (LPBYTE)pMemToFree;
- delete [] pMemToDelete;
- }
- LPBYTE CExtBitmap::stat_AllocHL(
- ULONG nWidth,
- ULONG hHeight,
- ULONG nBPP,
- ULONG nMaskRed,
- ULONG nMaskGreen,
- ULONG nMaskBlue,
- ULONG nMaskAlpha,
- ULONG nFlags
- )
- {
- if( nBPP != 1
- && nBPP != 4
- && nBPP != 8
- && nBPP != 16
- && nBPP != 24
- && nBPP != 32
- )
- nBPP = 8;
- ULONG nMaskBufferSize = max( sizeof(ULONG) * 5, 32 );
- ULONG nImageBufferSize = stat_RcImageBufferSize( nWidth, hHeight, nBPP );
- nImageBufferSize += nMaskBufferSize;
- LPBYTE pImageBuffer = (LPBYTE)
- stat_AllocLL(
- nImageBufferSize * sizeof( BYTE ),
- 16
- );
- ::memset( pImageBuffer, 0, nImageBufferSize );
- ULONG * pMaskBuffer = (ULONG *) pImageBuffer;
- pMaskBuffer[0] = nMaskRed;
- pMaskBuffer[1] = nMaskGreen;
- pMaskBuffer[2] = nMaskBlue;
- pMaskBuffer[3] = nMaskAlpha;
- pMaskBuffer[4] = nFlags;
- LPBITMAPINFOHEADER pBIH = (LPBITMAPINFOHEADER)( LPBYTE(pImageBuffer) + nMaskBufferSize );
- pBIH->biSize = sizeof( BITMAPINFOHEADER );
- pBIH->biWidth = nWidth;
- pBIH->biHeight = hHeight;
- pBIH->biPlanes = 1;
- pBIH->biCompression = 0;
- pBIH->biBitCount = (WORD)nBPP;
- pBIH->biClrUsed = stat_RcUPE( nBPP );
- pBIH->biClrImportant = pBIH->biClrUsed;
- return LPBYTE(pBIH);
- }
- void CExtBitmap::stat_FreeHL( LPVOID pMemToFree )
- {
- LPBYTE pMemToFreeReal = LPBYTE( pMemToFree );
- ULONG nMaskBufferSize = max( sizeof(ULONG) * 5, 32 );
- pMemToFreeReal -= nMaskBufferSize;
- stat_FreeLL( pMemToFreeReal );
- }
- LPBYTE CExtBitmap::stat_BmpLoad(
- CArchive & ar,
- bool bEnableThrowException,
- bool bResourceFormat
- )
- {
- ASSERT( ar.IsLoading() );
- LPBYTE pImageBuffer = NULL;
- try
- {
- if( ! bResourceFormat )
- {
- BITMAPFILEHEADER _BFH;
- ar.Read( &_BFH, sizeof( BITMAPFILEHEADER) );
- } // if( ! bResourceFormat )
- BITMAPINFOHEADER _BIH;
- ar.Read( &_BIH, sizeof( BITMAPINFOHEADER ) );
- int nWidth = _BIH.biWidth;
- int hHeight = _BIH.biHeight;
- int nBPP = _BIH.biBitCount;
- int nCompression = _BIH.biCompression;
- int nClrUsed = _BIH.biClrUsed;
- int nScanLineSize = stat_RcScanLineSize( nWidth, nBPP );
- ULONG nUPE = stat_RcUPE( nBPP );
- switch( nBPP )
- {
- case 32:
- if( _BIH.biCompression == BI_BITFIELDS )
- {
- int nSkipIndex;
- for( nSkipIndex = 0; nSkipIndex < 5; nSkipIndex++ )
- {
- BYTE _byte;
- ar.Read( &_byte, sizeof( BYTE ) );
- } // for( nSkipIndex = 0; nSkipIndex < 5; nSkipIndex++ )
- }
- // continue to 24
- case 24:
- {
- if( _BIH.biCompression == BI_BITFIELDS )
- {
- DWORD arrBitMaskDefinions[3];
- ar.Read(
- arrBitMaskDefinions,
- 3 * sizeof( DWORD )
- );
- pImageBuffer =
- stat_AllocHL(
- nWidth,
- hHeight,
- nBPP,
- arrBitMaskDefinions[0],
- arrBitMaskDefinions[1],
- arrBitMaskDefinions[2],
- 0,
- 0 // run-time flags
- );
- }
- else
- {
- if( nBPP == 32 )
- pImageBuffer =
- stat_AllocHL(
- nWidth,
- hHeight,
- nBPP,
- 0x00FF0000,
- 0x0000FF00,
- 0x000000FF,
- 0xFF000000,
- 0 // run-time flags
- );
- else
- pImageBuffer =
- stat_AllocHL(
- nWidth,
- hHeight,
- nBPP,
- 0x00FF0000,
- 0x0000FF00,
- 0x000000FF,
- 0,
- 0 // run-time flags
- );
- }
- LPBITMAPINFOHEADER pBIH = stat_RcInfoHeader( pImageBuffer );
- pBIH->biXPelsPerMeter = _BIH.biXPelsPerMeter;
- pBIH->biYPelsPerMeter = _BIH.biYPelsPerMeter;
- ar.Read(
- stat_RcSurface( pImageBuffer ),
- hHeight * nScanLineSize
- );
- } // 32, 24
- break;
- case 16:
- {
- if( _BIH.biCompression == BI_BITFIELDS )
- {
- int nSkipIndex;
- for( nSkipIndex = 0; nSkipIndex < 4; nSkipIndex++ )
- {
- BYTE _byte;
- ar.Read( &_byte, sizeof( BYTE ) );
- }
- DWORD arrBitMaskDefinions[3];
- ar.Read( arrBitMaskDefinions, 3 * sizeof( DWORD ) );
- pImageBuffer =
- stat_AllocHL(
- nWidth,
- hHeight,
- nBPP,
- arrBitMaskDefinions[0],
- arrBitMaskDefinions[1],
- arrBitMaskDefinions[2],
- 0,
- 0 // run-time flags
- );
- } // if( _BIH.biCompression == BI_BITFIELDS )
- else
- pImageBuffer =
- stat_AllocHL(
- nWidth,
- hHeight,
- nBPP,
- 0x7C00,
- 0x03E0,
- 0x001F,
- 0,
- 0 // run-time flags
- );
- LPBITMAPINFOHEADER pBIH = stat_RcInfoHeader( pImageBuffer );
- pBIH->biXPelsPerMeter = _BIH.biXPelsPerMeter;
- pBIH->biYPelsPerMeter = _BIH.biYPelsPerMeter;
- ar.Read(
- stat_RcSurface( pImageBuffer ),
- hHeight * nScanLineSize
- );
- } // 16
- break;
- case 8:
- case 4:
- case 1:
- {
- if( nClrUsed <= 0 // ( nClrUsed <= 0 && (!(nClrUsed==0 && nBPP==1)) )
- || nClrUsed > int(nUPE)
- )
- nClrUsed = int(nUPE);
- pImageBuffer =
- stat_AllocHL(
- nWidth,
- hHeight,
- nBPP,
- 0,
- 0,
- 0,
- 0,
- 0 // run-time flags
- );
- LPBITMAPINFOHEADER pBIH = stat_RcInfoHeader( pImageBuffer );
- pBIH->biXPelsPerMeter = _BIH.biXPelsPerMeter;
- pBIH->biYPelsPerMeter = _BIH.biYPelsPerMeter;
- RGBQUAD * pPalette = (RGBQUAD *)( pImageBuffer + sizeof( BITMAPINFOHEADER ) );
- ar.Read( pPalette, nClrUsed * sizeof( RGBQUAD ) );
- switch( nCompression )
- {
- case BI_RGB:
- if( hHeight > 0 )
- ar.Read(
- stat_RcSurface( pImageBuffer ),
- hHeight * nScanLineSize
- );
- else
- {
- int nLineIndex, nAbsHeight = abs( hHeight );
- for( nLineIndex = 0; nLineIndex < nAbsHeight; nLineIndex++ )
- {
- ar.Read(
- stat_RcScanLine(
- pImageBuffer,
- nAbsHeight - nLineIndex - 1,
- nScanLineSize
- ),
- nScanLineSize
- );
- } // for( nLineIndex = 0; nLineIndex < nAbsHeight; nLineIndex++ )
- }
- break;
- case BI_RLE4:
- {
- BYTE _byte0 = 0, _byte1 = 0;
- int nLineIndex = 0, nBitCount = 0, nAlignState = 0;
- bool bLowPartOfByte = false;
- for( ; true; )
- {
- ar.Read( &_byte0, sizeof( BYTE ) );
- switch( _byte0 )
- {
- case 0:
- ar.Read( &_byte0, sizeof( BYTE ) );
- switch( _byte0 )
- {
- case 0:
- nBitCount = 0;
- nLineIndex ++;
- bLowPartOfByte = false;
- break;
- case 1:
- return pImageBuffer;
- case 2:
- {
- BYTE nDX = 0, nDY = 0;
- ar.Read( &nDX, sizeof( BYTE ) );
- ar.Read( &nDY, sizeof( BYTE ) );
- nBitCount += nDX / 2;
- nLineIndex += nDY;
- }
- break;
- default:
- {
- ar.Read( &_byte1, sizeof( BYTE ) );
- LPBYTE pScanLine =
- stat_RcScanLine(
- pImageBuffer,
- nLineIndex,
- nScanLineSize
- );
- INT nLP;
- for( nLP = 0; nLP < _byte0; nLP++ )
- {
- if( bLowPartOfByte )
- {
- (*( pScanLine + nBitCount )) |= _byte1 & 0x0F;
- if( nLP != _byte0 - 1 )
- ar.Read( &_byte1, sizeof( BYTE ) );
- nBitCount++;
- } // if( bLowPartOfByte )
- else
- (*( pScanLine + nBitCount )) |= _byte1&0xF0;
- bLowPartOfByte = !bLowPartOfByte;
- } // for( nLP = 0; nLP < _byte0; nLP++ )
- nAlignState = _byte0 % 4;
- if( nAlignState == 1
- || nAlignState == 2
- )
- ar.Read( &_byte1, sizeof( BYTE ) );
- }
- break;
- }
- break;
- default:
- {
- LPBYTE pScanLine =
- stat_RcScanLine(
- pImageBuffer,
- nLineIndex,
- nScanLineSize
- );
- ar.Read( &_byte1, sizeof( BYTE ) );
- ULONG nLP;
- for( nLP = 0; nLP < _byte0; nLP++ )
- {
- if( bLowPartOfByte )
- {
- (*( pScanLine + nBitCount )) |= _byte1&0x0F;
- nBitCount++;
- } // if( bLowPartOfByte )
- else
- (*( pScanLine + nBitCount )) |= _byte1&0xF0;
- bLowPartOfByte = !bLowPartOfByte;
- } // for( nLP = 0; nLP < _byte0; nLP++ )
- }
- break;
- } // switch( _byte0 )
- } // for( ; true; )
- }
- break;
- case BI_RLE8:
- {
- BYTE _byte0 = 0, _byte1 = 0;
- int nLineIndex = 0, nBitCount = 0;
- for( ; true; )
- {
- ar.Read( &_byte0, sizeof( BYTE ) );
- switch( _byte0 )
- {
- case 0:
- ar.Read( &_byte0, sizeof( BYTE ) );
- switch( _byte0 )
- {
- case 0:
- nBitCount = 0;
- nLineIndex ++;
- break;
- case 1:
- return pImageBuffer;
- case 2:
- {
- BYTE nDX = 0, nDY = 0;
- ar.Read( &nDX, sizeof( BYTE ) );
- ar.Read( &nDY, sizeof( BYTE ) );
- nBitCount += nDX;
- nLineIndex += nDY;
- }
- break;
- default:
- {
- if( nLineIndex >= hHeight )
- return pImageBuffer;
- int nCount = min( (int)_byte0, (nWidth - nBitCount) );
- ar.Read(
- stat_RcScanLine(
- pImageBuffer,
- nLineIndex,
- nScanLineSize
- ) + nBitCount,
- sizeof( BYTE ) * nCount
- );
- if( ( _byte0 & 1 ) == 1)
- ar.Read( &_byte1, sizeof( BYTE ) );
- nBitCount += _byte0;
- break;
- }
- }
- break;
- default:
- {
- if( nLineIndex >= hHeight )
- return pImageBuffer;
- INT nCount = min( (int)_byte0, (nWidth - nBitCount) );
- LPBYTE pScanLine =
- stat_RcScanLine(
- pImageBuffer,
- nLineIndex,
- nScanLineSize
- );
- ar.Read( &_byte1, sizeof( BYTE ) );
- INT nIndex;
- for( nIndex = 0; nIndex < nCount; nIndex++ )
- {
- (*( pScanLine + nBitCount )) = _byte1;
- nBitCount++;
- } // for( nIndex = 0; nIndex < nCount; nIndex++ )
- break;
- }
- } // switch( _byte0 )
- } // for( ; true; )
- break;
- }
- // default:
- // #if _MFC_VER >= 0x0800
- // ::AfxThrowArchiveException( CArchiveException::genericException );
- // #else
- // ::AfxThrowArchiveException( CArchiveException::generic );
- // #endif
- // break;
- } // switch( nCompression )
- } // 8, 4, 1
- break;
- } // switch( nBPP )
- } // try
- catch( CException * pException )
- {
- if( pImageBuffer != NULL )
- {
- delete [] pImageBuffer;
- pImageBuffer = NULL;
- }
- if( bEnableThrowException )
- throw;
- pException->Delete();
- } // catch( CException * pException )
- catch( ... )
- {
- if( pImageBuffer != NULL )
- {
- delete [] pImageBuffer;
- pImageBuffer = NULL;
- }
- if( bEnableThrowException )
- throw;
- } // catch( ... )
- return pImageBuffer;
- }
- bool CExtBitmap::stat_BmpSave(
- LPBYTE pImageBuffer,
- CArchive & ar,
- bool bEnableThrowException,
- bool bUseIndexedRLE
- )
- {
- ASSERT( ar.IsStoring() );
- ASSERT( pImageBuffer != NULL );
- LPBYTE pBufferForRLE = NULL;
- try
- {
- LPBITMAPINFOHEADER pBIH = stat_RcInfoHeader( pImageBuffer );
- BITMAPFILEHEADER _BFH;
- _BFH.bfType = 0x4D42;
- _BFH.bfSize =
- sizeof( BITMAPFILEHEADER )
- + sizeof( BITMAPINFOHEADER )
- + pBIH->biWidth * pBIH->biHeight;
- _BFH.bfOffBits =
- sizeof( BITMAPFILEHEADER )
- + sizeof( BITMAPINFOHEADER )
- + pBIH->biClrUsed * sizeof( RGBQUAD );
- _BFH.bfReserved1 = 0;
- _BFH.bfReserved2 = 0;
- bool bSaveBitFields16 = ( pBIH->biBitCount == 16 ) ? true : false;
- if( bSaveBitFields16 )
- {
- _BFH.bfSize += 3 * sizeof( DWORD );
- _BFH.bfOffBits += 3 * sizeof( DWORD );
- }
- ar.Write( &_BFH, sizeof( BITMAPFILEHEADER ) );
- BITMAPINFOHEADER _BIH;
- __EXT_MFC_MEMCPY(
- &_BIH,
- sizeof( BITMAPINFOHEADER ),
- pBIH,
- sizeof( BITMAPINFOHEADER )
- );
- if( bSaveBitFields16 )
- _BIH.biCompression = BI_BITFIELDS;
- else if( _BIH.biBitCount == 8 && bUseIndexedRLE )
- _BIH.biCompression = BI_RLE8;
- else
- _BIH.biCompression = BI_RGB;
- ar.Write( &_BIH, sizeof( BITMAPINFOHEADER ) );
- if( bSaveBitFields16 )
- {
- DWORD dwVal;
- dwVal = (DWORD)stat_MaskRed( pImageBuffer );
- ar.Write( &dwVal, sizeof( DWORD ) );
- dwVal = (DWORD)stat_MaskGreen( pImageBuffer );
- ar.Write( &dwVal, sizeof( DWORD ) );
- dwVal = (DWORD)stat_MaskBlue( pImageBuffer );
- ar.Write( &dwVal, sizeof( DWORD ) );
- } // if( bSaveBitFields16 )
- if( pBIH->biBitCount < 16 )
- {
- RGBQUAD * pPalette = (RGBQUAD *)( pImageBuffer + sizeof( BITMAPINFOHEADER ) );
- typedef struct { BYTE m_nBlue, m_nGreen, m_nRed, m_nAlpha; } _BRGA;
- _BRGA _brga;
- DWORD dwClrIndex;
- for( dwClrIndex = 0; dwClrIndex < pBIH->biClrUsed; dwClrIndex++ )
- {
- _brga.m_nBlue = pPalette[dwClrIndex].rgbBlue;
- _brga.m_nGreen = pPalette[dwClrIndex].rgbGreen;
- _brga.m_nRed = pPalette[dwClrIndex].rgbRed;
- _brga.m_nAlpha = pPalette[dwClrIndex].rgbReserved;
- ar.Write( &_brga, sizeof( _BRGA ) );
- } // for( dwClrIndex = 0; dwClrIndex < pBIH->biClrUsed; dwClrIndex++ )
- } // if( pBIH->biBitCount < 16 )
- ULONG nScanLineSize = stat_RcScanLineSize( pBIH->biWidth, pBIH->biBitCount );
- if( pBIH->biBitCount == 8 && bUseIndexedRLE )
- {
- INT nSizeToEncode = stat_RcLine( pBIH->biWidth, pBIH->biBitCount );
- pBufferForRLE = new BYTE[ nScanLineSize * 2 ];
- LONG nLineIndex;
- for( nLineIndex = 0; nLineIndex < pBIH->biHeight; ++nLineIndex )
- {
- LPBYTE pScanPosDst = pBufferForRLE;
- LPBYTE pScanPosSrc = stat_RcScanLine( pImageBuffer, nLineIndex, nScanLineSize );
- BYTE arrLocalBuffer[256];
- INT nLocalBufferSize = 0, nProcessedPos = 0, nPackPos;
- for( nPackPos = 0; nPackPos < nSizeToEncode; ++nPackPos )
- {
- if( ( nPackPos < ( nSizeToEncode - 1) ) && ( pScanPosSrc[nPackPos] == pScanPosSrc[ nPackPos + 1 ] ) )
- {
- INT nSecondPos = nPackPos + 1;
- while( ( nSecondPos < ( nSizeToEncode - 1 ) ) && ( pScanPosSrc[ nSecondPos ] == pScanPosSrc[ nSecondPos + 1 ] ) )
- ++ nSecondPos;
- if( ( ( nSecondPos - nPackPos ) + 1 ) > 3 )
- {
- switch( nLocalBufferSize )
- {
- case 0:
- break;
- case 2:
- pScanPosDst[ nProcessedPos ++ ] = 1;
- pScanPosDst[ nProcessedPos ++ ] = arrLocalBuffer[0];
- pScanPosDst[ nProcessedPos ++ ] = 1;
- pScanPosDst[ nProcessedPos ++ ] = arrLocalBuffer[1];
- break;
- case 1:
- pScanPosDst[ nProcessedPos ++ ] = BYTE( nLocalBufferSize );
- pScanPosDst[ nProcessedPos ++ ] = arrLocalBuffer[0];
- break;
- default:
- pScanPosDst[ nProcessedPos ++ ] = 0;
- pScanPosDst[ nProcessedPos ++ ] = BYTE( nLocalBufferSize );
- __EXT_MFC_MEMCPY(
- pScanPosDst + nProcessedPos,
- nLocalBufferSize,
- arrLocalBuffer,
- nLocalBufferSize
- );
- nProcessedPos += nLocalBufferSize;
- if( ( nLocalBufferSize & 1 ) == 1 )
- nProcessedPos ++;
- break;
- } // switch( nLocalBufferSize )
- pScanPosDst[ nProcessedPos ++ ] = BYTE( (nSecondPos - nPackPos) + 1 );
- pScanPosDst[ nProcessedPos ++ ] = pScanPosSrc[nPackPos];
- nLocalBufferSize = 0;
- } // if( ( ( nSecondPos - nPackPos ) + 1 ) > 3 )
- else
- {
- INT nRestPos;
- for( nRestPos = 0; nRestPos < (nSecondPos - nPackPos) + 1; ++nRestPos)
- {
- arrLocalBuffer[ nLocalBufferSize ++ ] = pScanPosSrc[nPackPos + nRestPos];
- if( nLocalBufferSize == 254 )
- {
- pScanPosDst[ nProcessedPos ++ ] = 0;
- pScanPosDst[ nProcessedPos ++ ] = BYTE( nLocalBufferSize );
- __EXT_MFC_MEMCPY(
- pScanPosDst + nProcessedPos,
- nLocalBufferSize,
- arrLocalBuffer,
- nLocalBufferSize
- );
- nProcessedPos += nLocalBufferSize;
- nLocalBufferSize = 0;
- } // if( nLocalBufferSize == 254 )
- } // for( nRestPos = 0; nRestPos < (nSecondPos - nPackPos) + 1; ++nRestPos)
- } // else from if( ( ( nSecondPos - nPackPos ) + 1 ) > 3 )
- nPackPos = nSecondPos;
- } // if( ( nPackPos < ( nSizeToEncode - 1) ) && ( pScanPosSrc[nPackPos] == pScanPosSrc[ nPackPos + 1 ] ) )
- else
- arrLocalBuffer[ nLocalBufferSize ++ ] = pScanPosSrc[nPackPos];
- if( nLocalBufferSize == 254 )
- {
- pScanPosDst[ nProcessedPos ++ ] = 0;
- pScanPosDst[ nProcessedPos ++ ] = BYTE( nLocalBufferSize );
- __EXT_MFC_MEMCPY(
- pScanPosDst + nProcessedPos,
- nLocalBufferSize,
- arrLocalBuffer,
- nLocalBufferSize
- );
- nProcessedPos += nLocalBufferSize;
- nLocalBufferSize = 0;
- } // if( nLocalBufferSize == 254 )
- } // for( nPackPos = 0; nPackPos < nSizeToEncode; ++nPackPos )
- switch( nLocalBufferSize )
- {
- case 0:
- break;
- case 2:
- pScanPosDst[ nProcessedPos ++ ] = 1;
- pScanPosDst[ nProcessedPos ++ ] = arrLocalBuffer[0];
- pScanPosDst[ nProcessedPos ++ ] = 1;
- pScanPosDst[ nProcessedPos ++ ] = arrLocalBuffer[1];
- break;
- case 1:
- pScanPosDst[ nProcessedPos ++ ] = BYTE( nLocalBufferSize );
- pScanPosDst[ nProcessedPos ++ ] = arrLocalBuffer[0];
- break;
- default:
- pScanPosDst[ nProcessedPos ++ ] = 0;
- pScanPosDst[ nProcessedPos ++ ] = BYTE( nLocalBufferSize );
- __EXT_MFC_MEMCPY(
- pScanPosDst + nProcessedPos,
- nLocalBufferSize,
- arrLocalBuffer,
- nLocalBufferSize
- );
- nProcessedPos += nLocalBufferSize;
- if( (nLocalBufferSize & 1) == 1 )
- nProcessedPos ++;
- break;
- } // switch( nLocalBufferSize )
- pScanPosDst[ nProcessedPos ++ ] = 0;
- pScanPosDst[ nProcessedPos ++ ] = 0;
- ar.Write( pBufferForRLE, nProcessedPos );
- } // for( nLineIndex = 0; nLineIndex < pBIH->biHeight; ++nLineIndex )
- pBufferForRLE[0] = 0;
- pBufferForRLE[1] = 1;
- ar.Write( pBufferForRLE, 2 );
- delete [] pBufferForRLE;
- pBufferForRLE = NULL;
- } // if( pBIH->biBitCount == 8 && bUseIndexedRLE )
- else
- ar.Write(
- stat_RcSurface( pImageBuffer ),
- pBIH->biHeight * nScanLineSize
- );
- return true;
- } // try
- catch( CException * pException )
- {
- if( pBufferForRLE != NULL )
- delete [] pBufferForRLE;
- if( bEnableThrowException )
- throw;
- pException->Delete();
- } // catch( CException * pException )
- catch( ... )
- {
- if( pBufferForRLE != NULL )
- delete [] pBufferForRLE;
- if( bEnableThrowException )
- throw;
- } // catch( ... )
- return false;
- }
- ULONG CExtBitmap::stat_MaskRed( LPBYTE pImageBuffer )
- {
- ASSERT( pImageBuffer != NULL );
- ULONG nMaskBufferSize = max( sizeof(ULONG) * 5, 32 );
- pImageBuffer -= nMaskBufferSize;
- ULONG * pMaskBuffer = (ULONG *)pImageBuffer;
- return pMaskBuffer[0];
- }
- ULONG CExtBitmap::stat_MaskGreen( LPBYTE pImageBuffer )
- {
- ASSERT( pImageBuffer != NULL );
- ULONG nMaskBufferSize = max( sizeof(ULONG) * 5, 32 );
- pImageBuffer -= nMaskBufferSize;
- ULONG * pMaskBuffer = (ULONG *)pImageBuffer;
- return pMaskBuffer[1];
- }
- ULONG CExtBitmap::stat_MaskBlue( LPBYTE pImageBuffer )
- {
- ASSERT( pImageBuffer != NULL );
- ULONG nMaskBufferSize = max( sizeof(ULONG) * 5, 32 );
- pImageBuffer -= nMaskBufferSize;
- ULONG * pMaskBuffer = (ULONG *)pImageBuffer;
- return pMaskBuffer[2];
- }
- ULONG CExtBitmap::stat_MaskAlpha( LPBYTE pImageBuffer )
- {
- ASSERT( pImageBuffer != NULL );
- ULONG nMaskBufferSize = max( sizeof(ULONG) * 5, 32 );
- pImageBuffer -= nMaskBufferSize;
- ULONG * pMaskBuffer = (ULONG *)pImageBuffer;
- return pMaskBuffer[3];
- }
- ULONG CExtBitmap::stat_RunTimeFlagsGet( LPBYTE pImageBuffer )
- {
- ASSERT( pImageBuffer != NULL );
- ULONG nMaskBufferSize = max( sizeof(ULONG) * 5, 32 );
- pImageBuffer -= nMaskBufferSize;
- ULONG * pMaskBuffer = (ULONG *)pImageBuffer;
- return pMaskBuffer[4];
- }
- void CExtBitmap::stat_RunTimeFlagsSet( LPBYTE pImageBuffer, ULONG nFlags )
- {
- ASSERT( pImageBuffer != NULL );
- ULONG nMaskBufferSize = max( sizeof(ULONG) * 5, 32 );
- pImageBuffer -= nMaskBufferSize;
- ULONG * pMaskBuffer = (ULONG *)pImageBuffer;
- pMaskBuffer[4] = nFlags;
- }
- bool CExtBitmap::stat_PreMultipliedRGBChannelsGet( LPBYTE pImageBuffer )
- {
- ULONG nFlags = stat_RunTimeFlagsGet( pImageBuffer );
- if( ( nFlags & __EXT_BMP_FLAG_PREMULTIPLIED_RGB_CHANNELS ) != 0 )
- return true;
- else
- return false;
- }
- void CExtBitmap::stat_PreMultipliedRGBChannelsSet( LPBYTE pImageBuffer, bool bPreMultiplied )
- {
- ULONG nFlags = stat_RunTimeFlagsGet( pImageBuffer );
- if( bPreMultiplied )
- nFlags |= __EXT_BMP_FLAG_PREMULTIPLIED_RGB_CHANNELS;
- else
- nFlags &= ~(__EXT_BMP_FLAG_PREMULTIPLIED_RGB_CHANNELS);
- stat_RunTimeFlagsSet( pImageBuffer, nFlags );
- }
- LPBYTE CExtBitmap::stat_RcTo32(
- LPBYTE pImageBuffer,
- bool bEnableThrowException
- )
- {
- ASSERT( pImageBuffer != NULL );
- LPBITMAPINFOHEADER pBIH = (LPBITMAPINFOHEADER)pImageBuffer;
- ULONG nBPP = pBIH->biBitCount;
- ULONG nLineIndex, nX;
- ULONG nWidth = pBIH->biWidth;
- ULONG hHeight = pBIH->biHeight;
- ULONG nScanLineSizeSrc = stat_RcScanLineSize( nWidth, nBPP );
- ULONG nScanLineSizeDst = stat_RcScanLineSize( nWidth, 32 );
- LPBYTE pImageBufferNew = NULL;
- RGBQUAD * pPalette = (RGBQUAD *)( pImageBuffer + sizeof( BITMAPINFOHEADER ) );
- try
- {
- switch( nBPP )
- {
- case 24:
- pImageBufferNew =
- stat_AllocHL(
- nWidth,
- hHeight,
- 32,
- 0x00FF0000,
- 0x0000FF00,
- 0x000000FF,
- 0xFF000000,
- 0 // run-time flags
- );
- for( nLineIndex = 0; nLineIndex < hHeight; nLineIndex++ )
- {
- LPBYTE pScanLineDst = stat_RcScanLine( pImageBufferNew, nLineIndex, nScanLineSizeDst );
- LPBYTE pScanLineSrc = stat_RcScanLine( pImageBuffer, nLineIndex, nScanLineSizeSrc );
- for( nX = 0; nX < nWidth; nX++ )
- {
- pScanLineDst[2] = pScanLineSrc[2];
- pScanLineDst[1] = pScanLineSrc[1];
- pScanLineDst[0] = pScanLineSrc[0];
- pScanLineDst[3] = 0xFF;
- pScanLineDst += 4;
- pScanLineSrc += 3;
- } // for( nX = 0; nX < nWidth; nX++ )
- } // for( nLineIndex = 0; nLineIndex < hHeight; nLineIndex++ )
- break;
- case 16:
- {
- pImageBufferNew =
- stat_AllocHL(
- nWidth,
- hHeight,
- 32,
- 0x00FF0000,
- 0x0000FF00,
- 0x000000FF,
- 0xFF000000,
- 0 // run-time flags
- );
- bool b565 =
- ( ( stat_MaskRed( pImageBuffer ) == 0xF800 )
- && ( stat_MaskGreen( pImageBuffer ) == 0x07E0 )
- && ( stat_MaskBlue( pImageBuffer ) == 0x001F )
- ) ? true : false;
- for( nLineIndex = 0; nLineIndex < hHeight; nLineIndex++ )
- {
- LPBYTE pScanLineDst = stat_RcScanLine( pImageBufferNew, nLineIndex, nScanLineSizeDst );
- LPBYTE pScanLineSrc = stat_RcScanLine( pImageBuffer, nLineIndex, nScanLineSizeSrc );
- WORD * nBitCount = ( WORD * )pScanLineSrc;
- if( b565 )
- {
- for( nX = 0; nX < nWidth; nX++ )
- {
- pScanLineDst[2] = ( BYTE ) ( (((nBitCount[nX] & 0xF800) >> 11) * 0xFF) / 0x1F );
- pScanLineDst[1] = ( BYTE ) ( (((nBitCount[nX] & 0x07E0) >> 5) * 0xFF) / 0x3F );
- pScanLineDst[0] = ( BYTE ) ( ( (nBitCount[nX] & 0x001F) * 0xFF) / 0x1F );
- pScanLineDst[3] = ( BYTE ) ( 0xFF );
- pScanLineDst += 4;
- } // for( nX = 0; nX < nWidth; nX++ )
- } // if( b565 )
- else
- {
- for( nX = 0; nX < nWidth; nX++ )
- {
- pScanLineDst[2] = ( BYTE ) ( (((nBitCount[nX] & 0x7C00) >> 10) * 0xFF) / 0x1F );
- pScanLineDst[1] = ( BYTE ) ( (((nBitCount[nX] & 0x03E0) >> 5) * 0xFF) / 0x1F );
- pScanLineDst[0] = ( BYTE ) ( ( (nBitCount[nX] & 0x001F) * 0xFF) / 0x1F );
- pScanLineDst[3] = ( BYTE ) ( 0xFF );
- pScanLineDst += 4;
- } // for( nX = 0; nX < nWidth; nX++ )
- } // else from if( b565 )
- } // for( nLineIndex = 0; nLineIndex < hHeight; nLineIndex++ )
- }
- break;
- case 8:
- pImageBufferNew =
- stat_AllocHL(
- nWidth,
- hHeight,
- 32,
- 0x00FF0000,
- 0x0000FF00,
- 0x000000FF,
- 0xFF000000,
- 0 // run-time flags
- );
- for( nLineIndex = 0; nLineIndex < hHeight; nLineIndex++ )
- {
- LPBYTE pScanLineDst = stat_RcScanLine( pImageBufferNew, nLineIndex, nScanLineSizeDst );
- LPBYTE pScanLineSrc = stat_RcScanLine( pImageBuffer, nLineIndex, nScanLineSizeSrc );
- for( nX = 0; nX < nWidth; nX++ )
- {
- pScanLineDst[0] = pPalette[pScanLineSrc[nX]].rgbBlue;
- pScanLineDst[1] = pPalette[pScanLineSrc[nX]].rgbGreen;
- pScanLineDst[2] = pPalette[pScanLineSrc[nX]].rgbRed;
- pScanLineDst[3] = 0xFF;
- pScanLineDst += 4;
- } // for( nX = 0; nX < nWidth; nX++ )
- }
- break;
- case 4:
- pImageBufferNew =
- stat_AllocHL(
- nWidth,
- hHeight,
- 32,
- 0x00FF0000,
- 0x0000FF00,
- 0x000000FF,
- 0xFF000000,
- 0 // run-time flags
- );
- for( nLineIndex = 0; nLineIndex < hHeight; nLineIndex++ )
- {
- LPBYTE pScanLineDst = stat_RcScanLine( pImageBufferNew, nLineIndex, nScanLineSizeDst );
- LPBYTE pScanLineSrc = stat_RcScanLine( pImageBuffer, nLineIndex, nScanLineSizeSrc );
- bool bLowPartOfByte = false;
- ULONG nShiftX = 0;
- for( nX = 0; nX < nWidth ; ++nX )
- {
- if( bLowPartOfByte )
- {
- pScanLineDst[0] = pPalette[((pScanLineSrc[nShiftX])&0x0F)].rgbBlue;
- pScanLineDst[1] = pPalette[((pScanLineSrc[nShiftX])&0x0F)].rgbGreen;
- pScanLineDst[2] = pPalette[((pScanLineSrc[nShiftX])&0x0F)].rgbRed;
- nShiftX++;
- } // if( bLowPartOfByte )
- else
- {
- pScanLineDst[0] = pPalette[((pScanLineSrc[nShiftX])&0xF0) >> 4].rgbBlue;
- pScanLineDst[1] = pPalette[((pScanLineSrc[nShiftX])&0xF0) >> 4].rgbGreen;
- pScanLineDst[2] = pPalette[((pScanLineSrc[nShiftX])&0xF0) >> 4].rgbRed;
- } // else from if( bLowPartOfByte )
- bLowPartOfByte = !bLowPartOfByte;
- pScanLineDst[3] = 0xFF;
- pScanLineDst += 4;
- } // for( nX = 0; nX < nWidth ; ++nX )
- } // for( nLineIndex = 0; nLineIndex < hHeight; nLineIndex++ )
- break;
- case 1:
- pImageBufferNew =
- stat_AllocHL(
- nWidth,
- hHeight,
- 32,
- 0x00FF0000,
- 0x0000FF00,
- 0x000000FF,
- 0xFF000000,
- 0 // run-time flags
- );
- for( nLineIndex = 0; nLineIndex < hHeight; nLineIndex++ )
- {
- LPBYTE pScanLineDst = stat_RcScanLine( pImageBufferNew, nLineIndex, nScanLineSizeDst );
- LPBYTE pScanLineSrc = stat_RcScanLine( pImageBuffer, nLineIndex, nScanLineSizeSrc );
- for( nX = 0; nX < nWidth; nX++ )
- {
- ULONG nIndex = ( pScanLineSrc[nX>>3] & ( 0x80 >> ( nX & 0x07 ) ) ) != 0 ? 1 : 0;
- pScanLineDst[0] = pPalette[nIndex].rgbBlue;
- pScanLineDst[1] = pPalette[nIndex].rgbGreen;
- pScanLineDst[2] = pPalette[nIndex].rgbRed;
- pScanLineDst[3] = 0xFF;
- pScanLineDst += 4;
- } // for( nX = 0; nX < nWidth; nX++ )
- } // for( nLineIndex = 0; nLineIndex < hHeight; nLineIndex++ )
- break;
- } // switch( nBPP )
- } // try
- catch( CException * pException )
- {
- if( pImageBufferNew != NULL )
- {
- delete [] pImageBufferNew;
- pImageBufferNew = NULL;
- }
- if( bEnableThrowException )
- throw;
- pException->Delete();
- } // catch( CException * pException )
- catch( ... )
- {
- if( pImageBufferNew != NULL )
- {
- delete [] pImageBuffer;
- pImageBufferNew = NULL;
- }
- if( bEnableThrowException )
- throw;
- } // catch( ... )
- return pImageBufferNew;
- }
- #pragma pack(pop)
- const BYTE * CExtBitmap::GetBuffer() const
- {
- return m_pImageBuffer;
- }
- ULONG CExtBitmap::MaskRed() const
- {
- if( IsEmpty() )
- return 0;
- return stat_MaskRed( (LPBYTE)m_pImageBuffer );
- }
- ULONG CExtBitmap::MaskGreen() const
- {
- if( IsEmpty() )
- return 0;
- return stat_MaskGreen( (LPBYTE)m_pImageBuffer );
- }
- ULONG CExtBitmap::MaskBlue() const
- {
- if( IsEmpty() )
- return 0;
- return stat_MaskBlue( (LPBYTE)m_pImageBuffer );
- }
- ULONG CExtBitmap::MaskAlpha() const
- {
- if( IsEmpty() )
- return 0;
- return stat_MaskAlpha( (LPBYTE)m_pImageBuffer );
- }
- ULONG CExtBitmap::RunTimeFlagsGet() const
- {
- if( IsEmpty() )
- return 0;
- return stat_RunTimeFlagsGet( (LPBYTE)m_pImageBuffer );
- }
- void CExtBitmap::RunTimeFlagsSet( ULONG nFlags ) const
- {
- if( IsEmpty() )
- return;
- stat_RunTimeFlagsSet( (LPBYTE)m_pImageBuffer, nFlags );
- }
- void CExtBitmap::OnLoad()
- {
- ASSERT( ! IsEmpty() );
- OnContentChanged();
- }
- void CExtBitmap::OnContentChanged()
- {
- }
- __EXT_MFC_SAFE_LPCTSTR CExtBitmap::stat_GetDrawMethodName(
- CExtBitmap::e_DrawMethod_t eDM
- )
- {
- switch( eDM )
- {
- case __EDM_HOLLOW:
- return _T("Hollow");
- case __EDM_STRETCH:
- return _T("Stretch");
- case __EDM_CENTER:
- return _T("Center");
- case __EDM_TILE_H:
- return _T("TileH");
- case __EDM_TILE_V:
- return _T("TileV");
- case __EDM_TILE:
- return _T("Tile");
- } // switch( eDM )
- return _T("");
- }
- CExtBitmap::e_DrawMethod_t CExtBitmap::stat_GetDrawMethodFromString(
- __EXT_MFC_SAFE_LPCTSTR str
- )
- {
- CExtSafeString strDrawMethodString( str );
- if( strDrawMethodString.IsEmpty() )
- return __EDM_DEFAULT;
- int iDrawMethod;
- for( iDrawMethod = 0; iDrawMethod < (int)__EDM_COUNT; ++iDrawMethod )
- {
- USES_CONVERSION;
- if( ! strDrawMethodString.CompareNoCase(
- stat_GetDrawMethodName( (e_DrawMethod_t)iDrawMethod )
- )
- )
- return (e_DrawMethod_t)iDrawMethod;
- }
- return __EDM_DEFAULT;
- }
- INT CExtBitmap::GetBitmapColorMap( // returns bitmap's color bit count or zero if error
- CMap < COLORREF, COLORREF, DWORD, DWORD > & _map // key is color, value is count of color entries in bitmap
- ) const
- {
- _map.RemoveAll();
- if( IsEmpty() )
- return 0;
- INT nBPP = INT( GetBPP() );
- CSize _size = GetSize();
- INT nX, nY;
- for( nY = 0; nY < _size.cy; nY ++ )
- {
- for( nX = 0; nX < _size.cx; nX ++ )
- {
- COLORREF clr = GetPixel( nX, nY );
- DWORD dwEntries = 0;
- if( _map.Lookup( clr, dwEntries ) )
- {
- ASSERT( dwEntries > 0 );
- dwEntries++;
- _map.SetAt( clr, dwEntries );
- }
- else
- _map.SetAt( clr, 1 );
- }
- }
- return nBPP;
- }
- INT CExtBitmap::GetBitmapColorArray( // returns bitmap's color bit count or zero if error
- CArray < COLORREF, COLORREF > & arr
- ) const
- {
- arr.RemoveAll();
- CMap < COLORREF, COLORREF, DWORD, DWORD > _map;
- INT nBPP = GetBitmapColorMap( _map );
- if( nBPP == 0 )
- return 0;
- #ifdef _DEBUG
- INT nCount = (INT)_map.GetCount();
- #endif // _DEBUG
- ASSERT( nCount > 0 );
- POSITION pos = _map.GetStartPosition();
- ASSERT( pos != NULL );
- for( ; pos != NULL; )
- {
- COLORREF clrToInsert = RGB(0,0,0);
- DWORD dwEntries = 0;
- _map.GetNextAssoc( pos, clrToInsert, dwEntries );
- ASSERT( dwEntries > 0 );
- arr.Add( clrToInsert );
- } // for( ; pos != NULL; )
- ASSERT( nCount == arr.GetSize() );
- return nBPP;
- }
- COLORREF CExtBitmap::stat_RGBtoCMY( COLORREF clr )
- {
- int nR = GetRValue( clr );
- int nG = GetGValue( clr );
- int nB = GetBValue( clr );
- int nC = 255-nR;
- int nM = 255-nG;
- int nY = 255-nB;
- COLORREF clrCMY = RGB( nC, nM, nY );
- return clrCMY;
- }
- COLORREF CExtBitmap::stat_CMYtoRGB( COLORREF clr )
- {
- int nC = GetRValue( clr );
- int nM = GetGValue( clr );
- int nY = GetBValue( clr );
- int nR = 255 - nC;
- int nG = 255 - nM;
- int nB = 255 - nY;
- COLORREF clrRGB = RGB( nR, nG, nB );
- return clrRGB;
- }
- //----------------------------------------------------------------------
- // Conversion between the HSL (Hue, Saturation, and Luminosity)
- // and RBG color model.
- //----------------------------------------------------------------------
- // The conversion algorithms presented here come from the book by
- // Fundamentals of Interactive Computer Graphics by Foley and van Dam.
- // In the example code, HSL values are represented as floating point
- // number in the range 0 to 1. RGB tridrants use the Windows convention
- // of 0 to 255 of each element.
- //----------------------------------------------------------------------
- double CExtBitmap::stat_HuetoRGB(double m1, double m2, double h )
- {
- if( h < 0 ) h += 1.0;
- if( h > 1 ) h -= 1.0;
- if( 6.0*h < 1 )
- return (m1+(m2-m1)*h*6.0);
- if( 2.0*h < 1 )
- return m2;
- if( 3.0*h < 2.0 )
- return (m1+(m2-m1)*((2.0/3.0)-h)*6.0);
- return m1;
- }
- COLORREF CExtBitmap::stat_HLStoRGB( double H, double L, double S )
- {
- double r, g, b;
- double m1, m2;
- if( S==0 )
- {
- r = g = b = L;
- }
- else
- {
- if( L <= 0.5 )
- m2 = L*(1.0+S);
- else
- m2 = L+S-L*S;
- m1 = 2.0*L-m2;
- r = stat_HuetoRGB(m1,m2,H+1.0/3.0);
- g = stat_HuetoRGB(m1,m2,H);
- b = stat_HuetoRGB(m1,m2,H-1.0/3.0);
- }
- return RGB((BYTE)(r*255),(BYTE)(g*255),(BYTE)(b*255));
- }
- void CExtBitmap::stat_RGBtoHSL( COLORREF rgb, double *H, double *S, double *L )
- {
- // double delta;
- // double r = (double)GetRValue(rgb)/255;
- // double g = (double)GetGValue(rgb)/255;
- // double b = (double)GetBValue(rgb)/255;
- // double cmax = max(r,max(g,b));
- // double cmin = min(r,min(g,b));
- // *L = (cmax + cmin) / 2.0;
- //
- // if(cmax==cmin)
- // {
- // *S = 0;
- // *H = 0; // it's really undefined
- // }
- // else
- // {
- // if( *L < 0.5 )
- // *S = (cmax-cmin)/(cmax+cmin);
- // else
- // *S = (cmax-cmin)/(2.0-cmax-cmin);
- // delta = cmax - cmin;
- // if( r == cmax )
- // *H = (g-b)/delta;
- // else if( g == cmax )
- // *H = 2.0 +(b-r)/delta;
- // else
- // *H = 4.0 + (r-g)/delta;
- // *H /= 6.0;
- // if( *H < 0.0 )
- // *H += 1;
- // }
- INT nr = GetRValue( rgb );
- INT ng = GetGValue( rgb );
- INT nb = GetBValue( rgb );
- double delta;
- double r = double( nr ) / 255.0;
- double g = double( ng ) / 255.0;
- double b = double( nb ) / 255.0;
- INT ncmax = max( nr, max( ng, nb ) );
- INT ncmin = min( nr, min( ng, nb ) );
- double cmax = double( ncmax ) / 255.0;
- double cmin = double( ncmin ) / 255.0;
- *L = ( cmax + cmin ) / 2.0;
- if( ncmax == ncmin )
- {
- *S = 0;
- *H = 0; // undefined
- }
- else
- {
- if( *L < 0.5 )
- *S = ( cmax - cmin ) / ( cmax + cmin );
- else
- *S = ( cmax - cmin ) / ( 2.0 - cmax - cmin );
- delta = cmax - cmin;
- if( nr == ncmax )
- *H = ( g -b ) / delta;
- else if( ng == ncmax )
- *H = 2.0 +( b - r ) / delta;
- else
- *H = 4.0 + ( r - g) / delta;
- *H /= 6.0;
- if( *H < 0.0 )
- *H += 1;
- }
- }
- BYTE CExtBitmap::stat_GetRGBFromHue(float rm1, float rm2, float rh)
- {
- if (rh > 360.0f)
- rh -= 360.0f;
- else if (rh < 0.0f)
- rh += 360.0f;
- if (rh < 60.0f)
- rm1 = rm1 + (rm2 - rm1) * rh / 60.0f;
- else if (rh < 180.0f)
- rm1 = rm2;
- else if (rh < 240.0f)
- rm1 = rm1 + (rm2 - rm1) * (240.0f - rh) / 60.0f;
- return static_cast < BYTE > (rm1 * 255);
- }
- COLORREF CExtBitmap::stat_GetRGBFromHLSExtend( double H, double L, double S )
- {
- WORD R, G, B;
- if( S == 0.0 )
- {
- R = G = B = unsigned char(L * 255.0);
- }
- else
- {
- float rm1, rm2;
-
- if( L <= 0.5f )
- rm2 = (float)(L + L * S);
- else
- rm2 = (float)(L + S - L * S);
-
- rm1 = (float)(2.0f * L - rm2);
- R = stat_GetRGBFromHue(rm1, rm2, (float)(H + 120.0f));
- G = stat_GetRGBFromHue(rm1, rm2, (float)(H));
- B = stat_GetRGBFromHue(rm1, rm2, (float)(H - 120.0f));
- }
- return RGB(R, G, B);
- }
- COLORREF CExtBitmap::stat_HLS_Adjust(
- COLORREF clr,
- double percentH, // = 0.0
- double percentL, // = 0.0
- double percentS // = 0.0
- )
- {
- double H = 0.0, L = 0.0, S = 0.0;
- stat_RGBtoHSL( clr, &H, &S, &L );
- if( percentH > 0.0 )
- H =
- H +
- (1.0 - H) * percentH
- ;
- else if ( percentH < 0.0 )
- H =
- H * (1.0 + percentH);
- if( H < 0.0 )
- H = 0.0;
- else if( H > 1.0 )
- H = 1.0;
- if( percentL > 0.0 )
- L =
- L +
- (1.0 - L) * percentL
- ;
- else if ( percentL < 0.0 )
- L =
- L * (1.0 + percentL);
- if( L < 0.0 )
- L = 0.0;
- else if( L > 1.0 )
- L = 1.0;
- if ( percentS > 0.0 )
- S =
- S +
- (1.0 - S) * percentS
- ;
- else if ( percentS < 0.0 )
- S =
- S * (1.0 + percentS);
- if( S < 0.0 )
- S = 0.0;
- else if( S > 1.0 )
- S = 1.0;
- return stat_HLStoRGB( H, L, S );
- }
- COLORREF CExtBitmap::stat_RGB_Enlight(
- COLORREF clrLight,
- COLORREF clrDark,
- INT nEnlighten
- )
- {
- INT nInDarkRed = GetRValue( clrDark );
- INT nInLightRed = GetRValue( clrLight );
- INT nInDarkGreen = GetGValue( clrDark );
- INT nInLightGreen = GetGValue( clrLight );
- INT nInDarkBlue = GetBValue( clrDark );
- INT nInLightBlue = GetBValue( clrLight );
- INT nDivMixer = ( nEnlighten < 100 ) ? 100 : 1000;
- INT nDivAdjuster = nDivMixer / 2;
- INT nDarken = nDivMixer - nEnlighten;
- INT nEnlightenRed = nInLightRed * nEnlighten;
- INT nDarkenRed = nInDarkRed * nDarken;
- INT nEnlightenGreen = nInLightGreen * nEnlighten;
- INT nDarkenGreen = nInDarkGreen * nDarken;
- INT nEnlightenBlue = nInLightBlue * nEnlighten;
- INT nDarkenBlue = nInDarkBlue * nDarken;
- INT nOutRed =
- ( nDarkenRed + nDivAdjuster + nEnlightenRed )
- / nDivMixer;
- INT nOutGreen =
- ( nDarkenGreen + nDivAdjuster + nEnlightenGreen )
- / nDivMixer;
- INT nOutBlue =
- ( nDarkenBlue + nDivAdjuster + nEnlightenBlue )
- / nDivMixer;
- return ( RGB( nOutRed, nOutGreen, nOutBlue ) );
- }
- COLORREF CExtBitmap::stat_RGB_Blend(
- COLORREF clrFrom,
- COLORREF clrTo,
- INT nAlpha
- )
- {
- INT nOutRed =
- ( GetRValue( clrFrom ) * nAlpha + GetRValue( clrTo ) * ( 255 - nAlpha ) ) / 255;
- INT nOutGreen =
- ( GetGValue( clrFrom ) * nAlpha + GetGValue( clrTo ) * ( 255 - nAlpha ) ) / 255;
- INT nOutBlue =
- ( GetBValue( clrFrom ) * nAlpha + GetBValue( clrTo ) * ( 255 - nAlpha ) ) / 255;
- return RGB(
- nOutRed < 0 ? 0 : ( nOutRed > 255 ? 255 : nOutRed ),
- nOutGreen < 0 ? 0 : ( nOutGreen > 255 ? 255 : nOutGreen ),
- nOutBlue < 0 ? 0 : ( nOutBlue > 255 ? 255 : nOutBlue )
- );
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtBitmapCache
- CExtBitmapCache::CExtBitmapCache()
- : m_hBitmapCache( NULL )
- {
- }
- CExtBitmapCache::CExtBitmapCache(
- const CExtBitmap & other
- )
- : m_hBitmapCache( NULL )
- , CExtBitmap( other )
- {
- // _InitCache( *this );
- }
- CExtBitmapCache::~CExtBitmapCache()
- {
- Empty();
- }
- bool CExtBitmapCache::AssignFromOther(
- const CExtBitmap & other,
- bool bEnableThrowException // = false
- )
- {
- Empty();
- bool bRetVal =
- CExtBitmap::AssignFromOther(
- other,
- bEnableThrowException
- );
- // _InitCache( other );
- return bRetVal;
- }
- void CExtBitmapCache::_InitCache( const CExtBitmap & _bmp )
- {
- if( m_hBitmapCache != NULL )
- {
- ::DeleteObject( m_hBitmapCache );
- m_hBitmapCache = NULL;
- } // if( m_hBitmapCache != NULL )
- if( g_PaintManager.m_pfnMsImgAlphaBlend == NULL
- || _bmp.IsEmpty()
- || _bmp.GetBPP() != 32
- || _bmp.MaskAlpha() == 0
- )
- return;
- bool bPreMultiplied = PreMultipliedRGBChannelsGet();
- if( bPreMultiplied )
- {
- m_hBitmapCache = CreateBitmap( false );
- } // if( bPreMultiplied )
- else
- {
- bool bAutoPreMultiplyEnabled = IsAutoPreMultiplyRGBChannels();
- if( bAutoPreMultiplyEnabled )
- {
- PreMultipliedRGBChannelsSet( true );
- PreMultiplyRGBChannels();
- m_hBitmapCache = CreateBitmap( false );
- } // if( bAutoPreMultiplyEnabled )
- else
- {
- CExtBitmap _bmpCrt = _bmp;
- if( _bmpCrt.IsEmpty() )
- return;
- _bmpCrt.PreMultiplyRGBChannels();
- m_hBitmapCache = _bmpCrt.CreateBitmap( false );
- } // else from if( bAutoPreMultiplyEnabled )
- } // else from if( bPreMultiplied )
- }
- void CExtBitmapCache::Empty()
- {
- if( m_hBitmapCache != NULL )
- {
- ::DeleteObject( m_hBitmapCache );
- m_hBitmapCache = NULL;
- } // if( m_hBitmapCache != NULL )
- CExtBitmap::Empty();
- }
- bool CExtBitmapCache::IsEmpty() const
- {
- bool bRetVal = CExtBitmap::IsEmpty();
- return bRetVal;
- }
- int CExtBitmapCache::AlphaBlend(
- HDC hDC,
- int nDstX,
- int nDstY,
- int nDstWidth,
- int nDstHeight,
- int nSrcX,
- int nSrcY,
- int nSrcWidth,
- int nSrcHeight,
- BYTE nSCA // = 0xFF
- ) const
- {
- ASSERT( hDC != NULL );
- if( IsEmpty() || hDC == NULL )
- return GDI_ERROR;
- if( m_hBitmapCache == NULL )
- {
- ( const_cast < CExtBitmapCache * > ( this ) ) ->
- _InitCache( *this );
- }
- if( g_PaintManager.m_pfnMsImgAlphaBlend != NULL
- && m_hBitmapCache != NULL
- )
- {
- bool bRTL = false;
- if( CDC::FromHandle(hDC)->GetLayout() == LAYOUT_RTL )
- bRTL = true;
- if( ! bRTL )
- {
- int nRetVal = GDI_ERROR;
- HDC hSrcDC = ::CreateCompatibleDC( NULL );
- if( hSrcDC != NULL )
- {
- HGDIOBJ hOld = ::SelectObject( hSrcDC, m_hBitmapCache );
- CExtPaintManager::CExtPaintManagerAutoPtr::__EXT_MFC_BLENDFUNCTION
- _bf = { AC_SRC_OVER, 0, nSCA, __EXT_MFC_AC_SRC_ALPHA };
- if( g_PaintManager.m_pfnMsImgAlphaBlend(
- hDC,
- nDstX,
- nDstY,
- nDstWidth,
- nDstHeight,
- hSrcDC,
- nSrcX,
- nSrcY,
- nSrcWidth,
- nSrcHeight,
- _bf
- )
- )
- nRetVal = 0;
- ::SelectObject( hSrcDC, hOld );
- ::DeleteDC( hSrcDC );
- } // if( hSrcDC != NULL )
- if( nRetVal == 0 )
- return nRetVal;
- } // if( ! bRTL )
- } // if( g_PaintManager.m_pfnMsImgAlphaBlend != NULL . . .
- return
- CExtBitmap::AlphaBlend(
- hDC,
- nDstX,
- nDstY,
- nDstWidth,
- nDstHeight,
- nSrcX,
- nSrcY,
- nSrcWidth,
- nSrcHeight,
- nSCA
- );
- }
- void CExtBitmapCache::OnContentChanged()
- {
- CExtBitmap::OnContentChanged();
- if( m_hBitmapCache != NULL )
- {
- ::DeleteObject( m_hBitmapCache );
- m_hBitmapCache = NULL;
- } // if( m_hBitmapCache != NULL )
- // _InitCache( *this );
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtCmdIcon
- // command icon class
- CExtCmdIcon::CExtCmdIcon()
- : m_dwFlags( __EXT_ICON_FLAGS_DEFAULT )
- {
- }
- CExtCmdIcon::CExtCmdIcon( const CExtCmdIcon & other )
- : m_dwFlags( __EXT_ICON_FLAGS_DEFAULT )
- {
- (*this) = other;
- }
- // CExtCmdIcon::CExtCmdIcon(
- // HICON hIcon,
- // bool bCreateCopy // if false - delete hIcon
- // )
- // : m_dwFlags( __EXT_ICON_FLAGS_DEFAULT )
- // {
- // AssignFromHICON( hIcon, bCreateCopy );
- // }
- // CExtCmdIcon::CExtCmdIcon(
- // HBITMAP hBitmap,
- // COLORREF clrTransparent, // = RGB( 0, 0, 0 )
- // LPCRECT pRectBitmapSrc, // = NULL
- // bool bCloneBitmap // = true // if false - pRectBitmapSrc must be NULL and will delete hBitmap
- // )
- // : m_dwFlags( __EXT_ICON_FLAGS_DEFAULT )
- // {
- // AssignFromHBITMAP(
- // hBitmap,
- // clrTransparent,
- // pRectBitmapSrc,
- // bCloneBitmap
- // );
- // }
- CExtCmdIcon::~CExtCmdIcon()
- {
- Empty();
- }
- CExtCmdIcon & CExtCmdIcon :: operator = ( const CExtCmdIcon & other )
- {
- AssignFromOther( other );
- return (*this);
- }
- void CExtCmdIcon::AssignFromOther( const CExtCmdIcon & other )
- {
- Empty();
- m_dwFlags = other.m_dwFlags;
- m_bmpNormal = other.m_bmpNormal;
- if( (m_dwFlags&__EXT_ICON_PERSISTENT_BITMAP_DISABLED) != 0 )
- m_bmpDisabled = other.m_bmpDisabled;
- if( (m_dwFlags&__EXT_ICON_PERSISTENT_BITMAP_HOVER) != 0 )
- m_bmpHover = other.m_bmpHover;
- if( (m_dwFlags&__EXT_ICON_PERSISTENT_BITMAP_PRESSED) != 0 )
- m_bmpPressed = other.m_bmpPressed;
- OnContentChanged();
- }
- void CExtCmdIcon::AssignFromHICON(
- HICON hIcon,
- bool bCreateCopy, // if false - delete hIcon
- bool bForceLowColorMode // = false
- )
- {
- Empty();
- if( hIcon == NULL )
- return;
- m_bmpNormal.AssignFromHICON(
- hIcon,
- bForceLowColorMode
- );
- if( ! bCreateCopy )
- ::DestroyIcon( hIcon );
- OnContentChanged();
- }
- void CExtCmdIcon::AssignFromHBITMAP(
- HBITMAP hBitmap,
- COLORREF clrTransparent, // = COLORREF(-1L) // COLORREF(-1L) - no force transparent pixels
- LPCRECT pRectBitmapSrc, // = NULL
- bool bCloneBitmap // = true // if false - pRectBitmapSrc must be NULL and will delete hBitmap
- )
- {
- Empty();
- if( hBitmap == NULL )
- return;
- ASSERT( bCloneBitmap || pRectBitmapSrc == NULL );
- if( ! m_bmpNormal.FromBitmap( hBitmap, pRectBitmapSrc, false, false ) )
- return;
- if( clrTransparent != COLORREF(-1L)
- && m_bmpNormal.Make32( false )
- )
- m_bmpNormal.AlphaColor( clrTransparent, RGB(0,0,0), 0 );
- if( ! bCloneBitmap )
- ::DeleteObject( hBitmap );
- OnContentChanged();
- }
- bool CExtCmdIcon::IsEmpty() const
- {
- bool bIsEmpty = m_bmpNormal.IsEmpty();
- return bIsEmpty;
- }
- void CExtCmdIcon::Empty()
- {
- m_dwFlags = __EXT_ICON_FLAGS_DEFAULT;
- m_bmpNormal.Empty();
- m_bmpDisabled.Empty();
- m_bmpHover.Empty();
- m_bmpPressed.Empty();
- OnContentChanged();
- }
- void CExtCmdIcon::Serialize( CArchive & ar )
- {
- if( ar.IsStoring() )
- {
- ar << m_dwFlags;
- }
- else
- {
- Empty();
- ar >> m_dwFlags;
- }
- m_bmpNormal.SerializeUnpacked( ar );
- if( (m_dwFlags&__EXT_ICON_PERSISTENT_BITMAP_DISABLED) != 0 )
- m_bmpDisabled.SerializeUnpacked( ar );
- if( (m_dwFlags&__EXT_ICON_PERSISTENT_BITMAP_HOVER) != 0 )
- m_bmpHover.SerializeUnpacked( ar );
- if( (m_dwFlags&__EXT_ICON_PERSISTENT_BITMAP_PRESSED) != 0 )
- m_bmpPressed.SerializeUnpacked( ar );
- if( ! ar.IsStoring() )
- OnContentChanged();
- }
- CSize CExtCmdIcon::GetSize() const
- {
- return m_bmpNormal.GetSize();
- }
- CExtCmdIcon :: operator CSize () const
- {
- return GetSize();
- }
- void CExtCmdIcon::SyncSysColors(
- CExtPaintManager * pPM
- )
- {
- if( IsEmpty() )
- return;
-
- if( pPM == NULL
- && (m_dwFlags&__EXT_ICON_PERSISTENT_BITMAP_DISABLED) == 0
- )
- {
- m_bmpDisabled.Empty();
- m_bmpDisabled = m_bmpNormal;
- m_bmpDisabled.Make32();
- m_bmpDisabled.MakeMono( ::GetSysColor( COLOR_3DFACE ) );
- m_bmpDisabled.AdjustAlpha( -0.5 );
- OnContentChanged();
- return;
- }
- if( pPM->AdjustIcon( this ) )
- {
- OnContentChanged();
- return;
- }
- }
- void CExtCmdIcon::OnGlobalPaintManagerChanged()
- {
- OnEmptyGeneratedBitmaps();
- }
- void CExtCmdIcon::OnContentChanged()
- {
- }
- void CExtCmdIcon::OnEmptyGeneratedBitmaps()
- {
- if( (m_dwFlags&__EXT_ICON_PERSISTENT_BITMAP_DISABLED) == 0 )
- m_bmpDisabled.Empty();
- if( (m_dwFlags&__EXT_ICON_PERSISTENT_BITMAP_HOVER) == 0 )
- m_bmpHover.Empty();
- if( (m_dwFlags&__EXT_ICON_PERSISTENT_BITMAP_PRESSED) == 0 )
- m_bmpPressed.Empty();
- }
- void CExtCmdIcon::OnSysColorChange(
- CExtPaintManager * pPM
- )
- {
- OnEmptyGeneratedBitmaps();
- SyncSysColors( pPM );
- }
- void CExtCmdIcon::OnSettingChange(
- CExtPaintManager * pPM,
- UINT uFlags,
- __EXT_MFC_SAFE_LPCTSTR lpszSection
- )
- {
- uFlags;
- lpszSection;
- OnEmptyGeneratedBitmaps();
- SyncSysColors( pPM );
- }
- void CExtCmdIcon::OnDisplayChange(
- CExtPaintManager * pPM,
- INT nDepthBPP,
- CPoint ptSizes
- )
- {
- nDepthBPP;
- ptSizes;
- OnEmptyGeneratedBitmaps();
- SyncSysColors( pPM );
- }
- void CExtCmdIcon::OnThemeChanged(
- CExtPaintManager * pPM,
- WPARAM wParam,
- LPARAM lParam
- )
- {
- wParam;
- lParam;
- OnEmptyGeneratedBitmaps();
- SyncSysColors( pPM );
- }
- bool CExtCmdIcon::Scale(
- const SIZE & newSize
- )
- {
- if( IsEmpty()
- || newSize.cx <= 0
- || newSize.cy <= 0
- )
- {
- // ASSERT( FALSE );
- return false;
- }
- CSize _size = GetSize();
- if( _size.cx == newSize.cx && _size.cy == newSize.cy )
- return true;
- if( ( m_bmpNormal.IsEmpty() || m_bmpNormal.Scale( newSize.cx, newSize.cy ) )
- && ( m_bmpDisabled.IsEmpty() || m_bmpDisabled.Scale( newSize.cx, newSize.cy ) )
- && ( m_bmpHover.IsEmpty() || m_bmpHover.Scale( newSize.cx, newSize.cy ) )
- && ( m_bmpPressed.IsEmpty() || m_bmpPressed.Scale( newSize.cx, newSize.cy ) )
- )
- {
- OnContentChanged();
- return true;
- }
- return false;
- }
- bool CExtCmdIcon::CreateScaledCopy(
- const CExtCmdIcon & other,
- const SIZE & newSize
- )
- {
- if( other.IsEmpty()
- || newSize.cx <= 0
- || newSize.cy <= 0
- )
- {
- // ASSERT( FALSE );
- return false;
- }
- Empty();
- AssignFromOther( other );
- return Scale( newSize );
- }
- bool CExtCmdIcon::CreateCheckMarkIcon(
- CExtPaintManager * pPM,
- COLORREF clrMark, // = COLORREF(-1L)
- COLORREF clrTransparent, // = COLORREF(-1L)
- CSize sizeIcon // = CSize(16,16)
- )
- {
- if( sizeIcon.cx <= 0 || sizeIcon.cy <= 0 )
- {
- ASSERT( FALSE );
- return false;
- } // if( sizeIcon.cx <= 0 || sizeIcon.cy <= 0 )
- Empty();
- if( clrMark == COLORREF(-1L) )
- clrMark = pPM->GetColor( CExtPaintManager::CLR_TEXT_OUT, NULL );
- if( clrTransparent == COLORREF(-1L) )
- clrTransparent = (clrMark == RGB(255,0,255)) ? RGB(128,255,128) : RGB(255,0,255);
- HDC hDC = ::CreateCompatibleDC( NULL );
- if( hDC == NULL )
- {
- ASSERT( FALSE );
- return 0;
- }
- LONG nIconPixelCount = sizeIcon.cx * sizeIcon.cy;
- BITMAPINFOHEADER bih;
- ::memset( &bih, 0, sizeof( BITMAPINFOHEADER ) );
- bih.biSize = sizeof( BITMAPINFOHEADER );
- bih.biWidth = sizeIcon.cx;
- bih.biHeight = sizeIcon.cy;
- bih.biPlanes = 1;
- bih.biBitCount = 32;
- bih.biCompression = BI_RGB;
- bih.biSizeImage = nIconPixelCount;
- COLORREF * pOutSurface = NULL;
- HBITMAP hDIB =
- ::CreateDIBSection(
- hDC,
- (LPBITMAPINFO)&bih,
- DIB_RGB_COLORS,
- (void**)&pOutSurface,
- NULL,
- NULL
- );
- if( hDIB == NULL )
- {
- ASSERT( FALSE );
- ::DeleteDC( hDC );
- return false;
- }
- ASSERT( pOutSurface != NULL );
- HGDIOBJ hOldBitmap = ::SelectObject( hDC, hDIB );
- CDC dc;
- dc.Attach( hDC );
- dc.FillSolidRect( 0, 0, sizeIcon.cx, sizeIcon.cy, clrTransparent );
- CExtPaintManager::stat_PaintCheckMark( dc, sizeIcon.cx/2 - 3, sizeIcon.cy/2 - 3, clrMark );
- dc.Detach();
- ::SelectObject( hDC, hOldBitmap );
- ::DeleteDC( hDC );
- AssignFromHBITMAP( hDIB, clrTransparent, NULL, false );
- return true;
- }
- bool CExtCmdIcon::CreateIndeterminatedSquareIcon(
- CExtPaintManager * pPM,
- COLORREF clrMark, // = COLORREF(-1L)
- COLORREF clrTransparent, // = COLORREF(-1L)
- CSize sizeIcon // = CSize(16,16)
- )
- {
- if( sizeIcon.cx <= 0 || sizeIcon.cy <= 0 )
- {
- ASSERT( FALSE );
- return false;
- } // if( sizeIcon.cx <= 0 || sizeIcon.cy <= 0 )
- Empty();
- if( clrMark == COLORREF(-1L) )
- clrMark = pPM->GetColor( CExtPaintManager::CLR_TEXT_OUT, NULL );
- if( clrTransparent == COLORREF(-1L) )
- clrTransparent = (clrMark == RGB(255,0,255)) ? RGB(128,255,128) : RGB(255,0,255);
- HDC hDC = ::CreateCompatibleDC( NULL );
- if( hDC == NULL )
- {
- ASSERT( FALSE );
- return 0;
- }
- LONG nIconPixelCount = sizeIcon.cx * sizeIcon.cy;
- BITMAPINFOHEADER bih;
- ::memset( &bih, 0, sizeof( BITMAPINFOHEADER ) );
- bih.biSize = sizeof( BITMAPINFOHEADER );
- bih.biWidth = sizeIcon.cx;
- bih.biHeight = sizeIcon.cy;
- bih.biPlanes = 1;
- bih.biBitCount = 32;
- bih.biCompression = BI_RGB;
- bih.biSizeImage = nIconPixelCount;
- COLORREF * pOutSurface = NULL;
- HBITMAP hDIB =
- ::CreateDIBSection(
- hDC,
- (LPBITMAPINFO)&bih,
- DIB_RGB_COLORS,
- (void**)&pOutSurface,
- NULL,
- NULL
- );
- if( hDIB == NULL )
- {
- ASSERT( FALSE );
- ::DeleteDC( hDC );
- return false;
- }
- ASSERT( pOutSurface != NULL );
- HGDIOBJ hOldBitmap = ::SelectObject( hDC, hDIB );
- CDC dc;
- dc.Attach( hDC );
- dc.FillSolidRect( 0, 0, sizeIcon.cx, sizeIcon.cy, clrTransparent );
- CExtPaintManager::stat_PaintIndeterminatedSquare( dc, sizeIcon.cx/2 - 3, sizeIcon.cy/2 - 3, clrMark );
- dc.Detach();
- ::SelectObject( hDC, hOldBitmap );
- ::DeleteDC( hDC );
- AssignFromHBITMAP( hDIB, clrTransparent, NULL, false );
- return true;
- }
- bool CExtCmdIcon::CreateRadioMarkIcon(
- CExtPaintManager * pPM,
- COLORREF clrMark, // = COLORREF(-1L)
- COLORREF clrTransparent, // = COLORREF(-1L)
- CSize sizeIcon // = CSize(16,16)
- )
- {
- if( sizeIcon.cx <= 0 || sizeIcon.cy <= 0 )
- {
- ASSERT( FALSE );
- return false;
- } // if( sizeIcon.cx <= 0 || sizeIcon.cy <= 0 )
- Empty();
- if( clrMark == COLORREF(-1L) )
- clrMark = pPM->GetColor( CExtPaintManager::CLR_TEXT_OUT, NULL );
- if( clrTransparent == COLORREF(-1L) )
- clrTransparent = (clrMark == RGB(255,0,255)) ? RGB(128,255,128) : RGB(255,0,255);
- HDC hDC = ::CreateCompatibleDC( NULL );
- if( hDC == NULL )
- {
- ASSERT( FALSE );
- return 0;
- }
- LONG nIconPixelCount = sizeIcon.cx * sizeIcon.cy;
- BITMAPINFOHEADER bih;
- ::memset( &bih, 0, sizeof( BITMAPINFOHEADER ) );
- bih.biSize = sizeof( BITMAPINFOHEADER );
- bih.biWidth = sizeIcon.cx;
- bih.biHeight = sizeIcon.cy;
- bih.biPlanes = 1;
- bih.biBitCount = 32;
- bih.biCompression = BI_RGB;
- bih.biSizeImage = nIconPixelCount;
- COLORREF * pOutSurface = NULL;
- HBITMAP hDIB =
- ::CreateDIBSection(
- hDC,
- (LPBITMAPINFO)&bih,
- DIB_RGB_COLORS,
- (void**)&pOutSurface,
- NULL,
- NULL
- );
- if( hDIB == NULL )
- {
- ASSERT( FALSE );
- ::DeleteDC( hDC );
- return false;
- }
- ASSERT( pOutSurface != NULL );
- HGDIOBJ hOldBitmap = ::SelectObject( hDC, hDIB );
- CDC dc;
- dc.Attach( hDC );
- dc.FillSolidRect( 0, 0, sizeIcon.cx, sizeIcon.cy, clrTransparent );
- CExtPaintManager::stat_PaintRadioDot( dc, sizeIcon.cx/2 - 3, sizeIcon.cy/2 - 3, clrMark );
- dc.Detach();
- ::SelectObject( hDC, hOldBitmap );
- ::DeleteDC( hDC );
- AssignFromHBITMAP( hDIB, clrTransparent, NULL, false );
- return true;
- }
- bool CExtCmdIcon::CreateEmptyIcon(
- CExtPaintManager * pPM,
- COLORREF clrTransparent, // = COLORREF(-1L)
- CSize sizeIcon // = CSize(16,16)
- )
- {
- pPM;
- if( sizeIcon.cx <= 0 || sizeIcon.cy <= 0 )
- {
- ASSERT( FALSE );
- return false;
- } // if( sizeIcon.cx <= 0 || sizeIcon.cy <= 0 )
- Empty();
- if( clrTransparent == COLORREF(-1L) )
- clrTransparent = RGB(255,0,255);
- HDC hDC = ::CreateCompatibleDC( NULL );
- if( hDC == NULL )
- {
- ASSERT( FALSE );
- return 0;
- }
- LONG nIconPixelCount = sizeIcon.cx * sizeIcon.cy;
- BITMAPINFOHEADER bih;
- ::memset( &bih, 0, sizeof( BITMAPINFOHEADER ) );
- bih.biSize = sizeof( BITMAPINFOHEADER );
- bih.biWidth = sizeIcon.cx;
- bih.biHeight = sizeIcon.cy;
- bih.biPlanes = 1;
- bih.biBitCount = 32;
- bih.biCompression = BI_RGB;
- bih.biSizeImage = nIconPixelCount;
- COLORREF * pOutSurface = NULL;
- HBITMAP hDIB =
- ::CreateDIBSection(
- hDC,
- (LPBITMAPINFO)&bih,
- DIB_RGB_COLORS,
- (void**)&pOutSurface,
- NULL,
- NULL
- );
- if( hDIB == NULL )
- {
- ASSERT( FALSE );
- ::DeleteDC( hDC );
- return false;
- }
- ASSERT( pOutSurface != NULL );
- HGDIOBJ hOldBitmap = ::SelectObject( hDC, hDIB );
- CDC dc;
- dc.Attach( hDC );
- dc.FillSolidRect( 0, 0, sizeIcon.cx, sizeIcon.cy, clrTransparent );
- dc.Detach();
- ::SelectObject( hDC, hOldBitmap );
- ::DeleteDC( hDC );
- AssignFromHBITMAP( hDIB, clrTransparent, NULL, false );
- return true;
- }
- HICON CExtCmdIcon::ExtractHICON(
- bool bReplaceSysColors, // = true
- COLORREF clrTransparent // = COLORREF(-1L)
- ) const
- {
- if( IsEmpty() )
- return NULL;
- HICON hIcon =
- m_bmpNormal.CreateHICON(
- bReplaceSysColors,
- clrTransparent
- );
- return hIcon;
- }
- CExtBitmap & CExtCmdIcon::GetBitmap(
- CExtCmdIcon::e_paint_type_t ePT, // = __PAINT_NORMAL
- CExtPaintManager * pPM // = NULL
- )
- {
- CExtBitmap * pBitmap = &m_bmpNormal;
- switch( ePT )
- {
- case __PAINT_NORMAL:
- break;
- case __PAINT_DISABLED:
- if( m_bmpDisabled.IsEmpty()
- && ( ! m_bmpNormal.IsEmpty() )
- )
- SyncSysColors( pPM );
- if( ! m_bmpDisabled.IsEmpty() )
- pBitmap = &m_bmpDisabled;
- break;
- case __PAINT_HOVER:
- if( m_bmpHover.IsEmpty()
- && ( ! m_bmpNormal.IsEmpty() )
- )
- SyncSysColors( pPM );
- if( ! m_bmpHover.IsEmpty() )
- pBitmap = &m_bmpHover;
- break;
- case __PAINT_PRESSED:
- if( m_bmpPressed.IsEmpty()
- && ( ! m_bmpNormal.IsEmpty() )
- )
- SyncSysColors( pPM );
- if( ! m_bmpPressed.IsEmpty() )
- pBitmap = &m_bmpPressed;
- break;
- #ifdef _DEBUG
- default:
- ASSERT( FALSE );
- break;
- #endif // _DEBUG
- } // switch( ePT )
- return (*pBitmap);
- }
- const CExtBitmap & CExtCmdIcon::GetBitmap(
- CExtCmdIcon::e_paint_type_t ePT, // = __PAINT_NORMAL
- CExtPaintManager * pPM // = NULL
- ) const
- {
- return
- ( const_cast < CExtCmdIcon * > ( this ) )
- -> GetBitmap( ePT, pPM );
- }
- void CExtCmdIcon::Paint(
- CExtPaintManager * pPM,
- HDC hDC,
- const RECT & rc,
- e_paint_type_t ePT, // = __PAINT_NORMAL
- BYTE nSCA // = BYTE(255)
- ) const
- {
- Paint(
- pPM,
- hDC,
- rc.left,
- rc.top,
- rc.right - rc.left,
- rc.bottom - rc.top,
- ePT,
- nSCA
- );
- }
- void CExtCmdIcon::Paint(
- CExtPaintManager * pPM,
- HDC hDC,
- INT nX,
- INT nY,
- INT nDX, // = -1 // -1 use default size
- int nDY, // = -1 // -1 use default size
- e_paint_type_t ePT, // = CExtCmdIcon:: __PAINT_NORMAL
- BYTE nSCA // = BYTE(255)
- ) const
- {
- if( ePT == __PAINT_INVISIBLE )
- return;
- if( hDC == NULL || IsEmpty() )
- return;
- if( nDX == 0 || nDY == 0 )
- return;
- CSize _size = GetSize();
- if( nDX < 0 || nDY < 0 )
- {
- if( nDX < 0 )
- nDX = _size.cx;
- if( nDY < 0 )
- nDY = _size.cy;
- } // if( nDX < 0 || nDY < 0 )
- const CExtBitmap & _bmp = GetBitmap( ePT, pPM );
- if( ! _bmp.IsEmpty() )
- _bmp.AlphaBlend(
- hDC,
- nX,
- nY,
- nDX,
- nDY,
- 0,
- 0,
- _size.cx,
- _size.cy,
- nSCA
- );
- }
- void CExtCmdIcon::PaintAccentEmboss(
- CExtPaintManager * pPM,
- HDC hDC,
- COLORREF clrAccent,
- INT nX,
- INT nY,
- INT nDX, // = -1 // -1 use default size
- int nDY, // = -1 // -1 use default size
- BYTE nSCA // = BYTE(255)
- )
- {
- pPM;
- if( IsEmpty() )
- return;
- ASSERT( ! m_bmpNormal.IsEmpty() );
- if( nDX == 0 || nDY == 0 )
- return;
- CSize _size = GetSize();
- if( nDX < 0 || nDY < 0 )
- {
- if( nDX < 0 )
- nDX = _size.cx;
- if( nDY < 0 )
- nDY = _size.cy;
- } // if( nDX < 0 || nDY < 0 )
- clrAccent = ::GetNearestColor( hDC, clrAccent );
- CExtBitmap _bmpDisabled = m_bmpNormal;
- _bmpDisabled.AdjustHLS( COLORREF(-1L), 0, 0.0, -0.75, 0.0 );
- _bmpDisabled.AdjustHLS( COLORREF(-1L), 0, 0.0, 0.75, 0.0 );
- _bmpDisabled.MakeMono( clrAccent );
- CExtBitmap _bmpL = _bmpDisabled;
- _bmpL.AdjustHLS( COLORREF(-1L), 0, 0.0, 0.75, 0.0 );
- if( ! _bmpL.IsEmpty() )
- _bmpL.AlphaBlend(
- hDC,
- nX+1,
- nY+1,
- nDX,
- nDY,
- 0,
- 0,
- _size.cx,
- _size.cy,
- nSCA
- );
- if( ! _bmpDisabled.IsEmpty() )
- _bmpDisabled.AlphaBlend(
- hDC,
- nX,
- nY,
- nDX,
- nDY,
- 0,
- 0,
- _size.cx,
- _size.cy,
- nSCA
- );
- }
- void CExtCmdIcon::PaintAccentMono(
- CExtPaintManager * pPM,
- HDC hDC,
- COLORREF clrAccent,
- INT nX,
- INT nY,
- INT nDX, // = -1 // -1 use default size
- int nDY, // = -1 // -1 use default size
- BYTE nSCA // = BYTE(255)
- )
- {
- pPM;
- if( IsEmpty() )
- return;
- ASSERT( ! m_bmpNormal.IsEmpty() );
- if( nDX == 0 || nDY == 0 )
- return;
- CSize _size = GetSize();
- if( nDX < 0 || nDY < 0 )
- {
- if( nDX < 0 )
- nDX = _size.cx;
- if( nDY < 0 )
- nDY = _size.cy;
- } // if( nDX < 0 || nDY < 0 )
- CExtBitmap _bmp = m_bmpNormal;
- _bmp.Make32();
- double H = 0.0, S = 0.0, L = 0.0;
- CExtBitmap::stat_RGBtoHSL( clrAccent, &H, &S, &L );
- clrAccent = CExtBitmap::stat_HLStoRGB( H, L, S );
- _bmp.AdjustHLS( COLORREF(-1L), 0, 0.0, -1.0, -1.0 );
- _bmp.MakeMono( clrAccent );
- _bmp.AdjustHLS( COLORREF(-1L), 0, 0.0, 0.5, 0.0 );
- if( ! _bmp.IsEmpty() )
- _bmp.AlphaBlend(
- hDC,
- nX,
- nY,
- nDX,
- nDY,
- 0,
- 0,
- _size.cx,
- _size.cy,
- nSCA
- );
- }
- void CExtCmdIcon::PaintAccentColorized(
- CExtPaintManager * pPM,
- HDC hDC,
- COLORREF clrAccent,
- INT nX,
- INT nY,
- INT nDX, // = -1 // -1 use default size
- int nDY, // = -1 // -1 use default size
- BYTE nSCA // = BYTE(255)
- )
- {
- pPM;
- if( IsEmpty() )
- return;
- ASSERT( ! m_bmpNormal.IsEmpty() );
- if( nDX == 0 || nDY == 0 )
- return;
- CSize _size = GetSize();
- if( nDX < 0 || nDY < 0 )
- {
- if( nDX < 0 )
- nDX = _size.cx;
- if( nDY < 0 )
- nDY = _size.cy;
- } // if( nDX < 0 || nDY < 0 )
- CExtBitmap _bmp = m_bmpNormal;
- _bmp.Make32();
- double H = 0.0, S = 0.0, L = 0.0;
- CExtBitmap::stat_RGBtoHSL( clrAccent, &H, &S, &L );
- clrAccent = CExtBitmap::stat_HLStoRGB( H, L, S );
- _bmp.MakeMono( clrAccent );
- if( ! _bmp.IsEmpty() )
- _bmp.AlphaBlend(
- hDC,
- nX,
- nY,
- nDX,
- nDY,
- 0,
- 0,
- _size.cx,
- _size.cy,
- nSCA
- );
- }
- bool CExtCmdIcon::ExtractEditableBitmap(
- HBITMAP & hBitmap,
- COLORREF & clrTransparent,
- CArray <COLORREF,COLORREF> * pArr, // = NULL // recommended palette, item 0 is clrTransparent
- COLORREF ** ppClrSurface // = NULL // if not NULL - force 32 bit
- ) const
- {
- if( IsEmpty() )
- return false;
- return
- m_bmpNormal.ExtractEditableBitmap(
- hBitmap,
- clrTransparent,
- pArr,
- ppClrSurface
- );
- }