src/Helpers.c
bool BitmapMergeAlpha(HBITMAP hbmp,COLORREF crDest)
{
  BITMAP bmp;
  if (GetObject(hbmp,sizeof(BITMAP),&bmp)) {
    if (bmp.bmBitsPixel == 32) {
      RGBQUAD *prgba = bmp.bmBits;
      if (prgba) {
        for (int y = 0; y < bmp.bmHeight; y++) {
          for (int x = 0; x < bmp.bmWidth; x++) {
            BYTE alpha = prgba[x].rgbReserved;
            prgba[x].rgbRed = ((prgba[x].rgbRed * alpha) + (GetRValue(crDest) * (255 - alpha))) >> 8;
            prgba[x].rgbGreen = ((prgba[x].rgbGreen * alpha) + (GetGValue(crDest) * (255 - alpha))) >> 8;
            prgba[x].rgbBlue = ((prgba[x].rgbBlue * alpha) + (GetBValue(crDest) * (255 - alpha))) >> 8;
            prgba[x].rgbReserved = 0xFF;
          }
          prgba = (RGBQUAD*)((LPBYTE)prgba + bmp.bmWidthBytes);
        }
        return true;
      }
    }
  }
  return false;
}
//=============================================================================
//
//  BitmapMergeAlpha()
//  Merge alpha channel into color channel
//
BitmapMergeAlpha()
Merge alpha channel into color channel
BitmapMergeAlpha () Merge alpha channel into color channel
bool BitmapMergeAlpha(HBITMAP hbmp,COLORREF crDest)
{
  BITMAP bmp;
  if (GetObject(hbmp,sizeof(BITMAP),&bmp)) {
    if (bmp.bmBitsPixel == 32) {
      RGBQUAD *prgba = bmp.bmBits;
      if (prgba) {
        for (int y = 0; y < bmp.bmHeight; y++) {
          for (int x = 0; x < bmp.bmWidth; x++) {
            BYTE alpha = prgba[x].rgbReserved;
            prgba[x].rgbRed = ((prgba[x].rgbRed * alpha) + (GetRValue(crDest) * (255 - alpha))) >> 8;
            prgba[x].rgbGreen = ((prgba[x].rgbGreen * alpha) + (GetGValue(crDest) * (255 - alpha))) >> 8;
            prgba[x].rgbBlue = ((prgba[x].rgbBlue * alpha) + (GetBValue(crDest) * (255 - alpha))) >> 8;
            prgba[x].rgbReserved = 0xFF;
          }
          prgba = (RGBQUAD*)((LPBYTE)prgba + bmp.bmWidthBytes);
        }
        return true;
      }
    }
  }
  return false;
}
bool BitmapMergeAlpha ( HBITMAP hbmp , COLORREF crDest ) { BITMAP bmp ; if ( GetObject ( hbmp , sizeof ( BITMAP ) , & bmp ) ) { if ( bmp . bmBitsPixel == 32 ) { RGBQUAD * prgba = bmp . bmBits ; if ( prgba ) { for ( int y = 0 ; y < bmp . bmHeight ; y ++ ) { for ( int x = 0 ; x < bmp . bmWidth ; x ++ ) { BYTE alpha = prgba [ x ] . rgbReserved ; prgba [ x ] . rgbRed = ( ( prgba [ x ] . rgbRed * alpha ) + ( GetRValue ( crDest ) * ( 255 - alpha ) ) ) >> 8 ; prgba [ x ] . rgbGreen = ( ( prgba [ x ] . rgbGreen * alpha ) + ( GetGValue ( crDest ) * ( 255 - alpha ) ) ) >> 8 ; prgba [ x ] . rgbBlue = ( ( prgba [ x ] . rgbBlue * alpha ) + ( GetBValue ( crDest ) * ( 255 - alpha ) ) ) >> 8 ; prgba [ x ] . rgbReserved = 0xFF ; } prgba = ( RGBQUAD * ) ( ( LPBYTE ) prgba + bmp . bmWidthBytes ) ; } return true ; } } } return false ; }
BitmapMergeAlpha()
Merge alpha channel into color channel
BitmapMergeAlpha () Merge alpha channel into color channel