src/Helpers.c
bool BitmapGrayScale(HBITMAP hbmp)
{
  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++) {
            prgba[x].rgbRed = prgba[x].rgbGreen = prgba[x].rgbBlue =
              (((BYTE)((prgba[x].rgbRed * 38 + prgba[x].rgbGreen * 75 + prgba[x].rgbBlue * 15) >> 7) * 0x80) + (0xD0 * (255 - 0x80))) >> 8;
          }
          prgba = (RGBQUAD*)((LPBYTE)prgba + bmp.bmWidthBytes);
        }
        return true;
      }
    }
  }
  return false;
}
//=============================================================================
//
//  BitmapGrayScale()
//  Gray scale color channel only
//
BitmapGrayScale()
Gray scale color channel only
BitmapGrayScale () Gray scale color channel only
bool BitmapGrayScale(HBITMAP hbmp)
{
  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++) {
            prgba[x].rgbRed = prgba[x].rgbGreen = prgba[x].rgbBlue =
              (((BYTE)((prgba[x].rgbRed * 38 + prgba[x].rgbGreen * 75 + prgba[x].rgbBlue * 15) >> 7) * 0x80) + (0xD0 * (255 - 0x80))) >> 8;
          }
          prgba = (RGBQUAD*)((LPBYTE)prgba + bmp.bmWidthBytes);
        }
        return true;
      }
    }
  }
  return false;
}
bool BitmapGrayScale ( HBITMAP hbmp ) { 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 ++ ) { prgba [ x ] . rgbRed = prgba [ x ] . rgbGreen = prgba [ x ] . rgbBlue = ( ( ( BYTE ) ( ( prgba [ x ] . rgbRed * 38 + prgba [ x ] . rgbGreen * 75 + prgba [ x ] . rgbBlue * 15 ) >> 7 ) * 0x80 ) + ( 0xD0 * ( 255 - 0x80 ) ) ) >> 8 ; } prgba = ( RGBQUAD * ) ( ( LPBYTE ) prgba + bmp . bmWidthBytes ) ; } return true ; } } } return false ; }
BitmapGrayScale()
Gray scale color channel only
BitmapGrayScale () Gray scale color channel only