Beispiel #1
0
LPBYTE DibGRAY2RGBHandle(LPBYTE lpGrayDib){
	LPBYTE lpRgbDib, lpSrc, lpDst;
	int cx, cy;

	if(!lpGrayDib || DIB_BPP(lpGrayDib) != 8)
		return NULL;

	cx = DIB_CX(lpGrayDib);
	cy = DIB_CY(lpGrayDib);
	if(!(lpRgbDib = DibCreateEmptyHandle(24, cx, cy)))
		return NULL;

	for(int y = 0; y < cy; y++){
		lpSrc = DIB_DATA8XY(lpGrayDib, 0, y);
		lpDst = DIB_DATA24XY(lpRgbDib, 0, y);
		for(int x = 0; x < cx; x++){
			*lpDst++ = *lpSrc;
			*lpDst++ = *lpSrc;
			*lpDst++ = *lpSrc;
			lpSrc++;
		}
	}

	return lpRgbDib;
}
Beispiel #2
0
LPBYTE	DibRGB2GRAYHandle( LPBYTE lpRgbDib )
{
	LPBYTE	lpGrayDib, lpSrc, lpDst;
	int		x, y, cx, cy;

	if ( !lpRgbDib || DIB_BPP( lpRgbDib ) != 24 )
		return NULL;

	cx = DIB_CX( lpRgbDib );
	cy = DIB_CY( lpRgbDib );
	if ( !(lpGrayDib = DibCreateEmptyHandle( 8, cx, cy )) )
		return NULL;

	for ( y = 0; y < cy; y++ )
	{
		lpSrc = DIB_DATA24XY( lpRgbDib, 0, y );
		lpDst = DIB_DATA8XY( lpGrayDib, 0, y );
		for ( x = 0; x < cx; x++ )
		{
			*lpDst++ = (*lpSrc + *(lpSrc+1) + *(lpSrc+2))/3;
			lpSrc += 3;
		}
	}

	return lpGrayDib;
}