============================================================================= BitmapAlphaBlend() Perform alpha blending to color channel only
| 274 | // Perform alpha blending to color channel only |
| 275 | // |
| 276 | BOOL BitmapAlphaBlend ( HBITMAP hbmp, COLORREF crDest, BYTE alpha ) |
| 277 | { |
| 278 | BITMAP bmp; |
| 279 | if ( GetObject ( hbmp, sizeof ( BITMAP ), &bmp ) ) { |
| 280 | if ( bmp.bmBitsPixel == 32 ) { |
| 281 | int x, y; |
| 282 | RGBQUAD *prgba = bmp.bmBits; |
| 283 | for ( y = 0; y < bmp.bmHeight; y++ ) { |
| 284 | for ( x = 0; x < bmp.bmWidth; x++ ) { |
| 285 | prgba[x].rgbRed = ( ( prgba[x].rgbRed * alpha ) + ( GetRValue ( crDest ) * ( 255 - alpha ) ) ) >> 8; |
| 286 | prgba[x].rgbGreen = ( ( prgba[x].rgbGreen * alpha ) + ( GetGValue ( crDest ) * ( 255 - alpha ) ) ) >> 8; |
| 287 | prgba[x].rgbBlue = ( ( prgba[x].rgbBlue * alpha ) + ( GetBValue ( crDest ) * ( 255 - alpha ) ) ) >> 8; |
| 288 | } |
| 289 | prgba = ( RGBQUAD * ) ( ( LPBYTE ) prgba + bmp.bmWidthBytes ); |
| 290 | } |
| 291 | return TRUE; |
| 292 | } |
| 293 | } |
| 294 | return FALSE; |
| 295 | } |
| 296 | |
| 297 | |
| 298 | //============================================================================= |