gdi32: Use GetImage to retrieve the brush bits in enhanced metafiles.

This commit is contained in:
Alexandre Julliard 2011-08-03 13:08:34 +02:00
parent 91976a5b74
commit 1aa35bea9a

View File

@ -105,36 +105,6 @@ HBITMAP EMFDRV_SelectBitmap( PHYSDEV dev, HBITMAP hbitmap )
} }
/* Internal helper for EMFDRV_CreateBrushIndirect():
* Change the padding of a bitmap from 16 (BMP) to 32 (DIB) bits.
*/
static inline void EMFDRV_PadTo32(LPBYTE lpRows, int height, int width)
{
int bytes16 = 2 * ((width + 15) / 16);
int bytes32 = 4 * ((width + 31) / 32);
LPBYTE lpSrc, lpDst;
int i;
if (!height)
return;
height = abs(height) - 1;
lpSrc = lpRows + height * bytes16;
lpDst = lpRows + height * bytes32;
/* Note that we work backwards so we can re-pad in place */
while (height >= 0)
{
for (i = bytes32; i > bytes16; i--)
lpDst[i - 1] = 0; /* Zero the padding bytes */
for (; i > 0; i--)
lpDst[i - 1] = lpSrc[i - 1]; /* Move image bytes into alignment */
lpSrc -= bytes16;
lpDst -= bytes32;
height--;
}
}
/*********************************************************************** /***********************************************************************
* EMFDRV_CreateBrushIndirect * EMFDRV_CreateBrushIndirect
*/ */
@ -197,46 +167,36 @@ DWORD EMFDRV_CreateBrushIndirect( PHYSDEV dev, HBRUSH hBrush )
case BS_PATTERN: case BS_PATTERN:
{ {
EMRCREATEDIBPATTERNBRUSHPT *emr; EMRCREATEDIBPATTERNBRUSHPT *emr;
BITMAPINFOHEADER *info; char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
BITMAP bm; BITMAPINFO *dst_info, *src_info = (BITMAPINFO *)buffer;
DWORD bmSize, biSize, size; struct gdi_image_bits bits;
DWORD size;
GetObjectA((HANDLE)logbrush.lbHatch, sizeof(bm), &bm); if (!get_bitmap_image( (HANDLE)logbrush.lbHatch, src_info, &bits )) break;
if (src_info->bmiHeader.biBitCount != 1)
if (bm.bmBitsPixel != 1 || bm.bmPlanes != 1)
{ {
FIXME("Trying to create a color pattern brush\n"); FIXME("Trying to create a color pattern brush\n");
if (bits.free) bits.free( &bits );
break; break;
} }
/* BMP will be aligned to 32 bits, not 16 */
bmSize = get_dib_stride(bm.bmWidth, bm.bmBitsPixel) * bm.bmHeight;
biSize = sizeof(BITMAPINFOHEADER);
/* FIXME: There is an extra DWORD written by native before the BMI. /* FIXME: There is an extra DWORD written by native before the BMI.
* Not sure what its meant to contain. * Not sure what its meant to contain.
*/ */
size = sizeof(EMRCREATEDIBPATTERNBRUSHPT) + biSize + bmSize + sizeof(DWORD); size = sizeof(EMRCREATEDIBPATTERNBRUSHPT) + sizeof(DWORD) +
sizeof(BITMAPINFOHEADER) + src_info->bmiHeader.biSizeImage;
emr = HeapAlloc( GetProcessHeap(), 0, size ); emr = HeapAlloc( GetProcessHeap(), 0, size );
if(!emr) if(!emr)
break; {
if (bits.free) bits.free( &bits );
break;
}
info = (BITMAPINFOHEADER *)((LPBYTE)emr + dst_info = (BITMAPINFO *)((LPBYTE)(emr + 1) + sizeof(DWORD));
sizeof(EMRCREATEDIBPATTERNBRUSHPT) + sizeof(DWORD)); dst_info->bmiHeader = src_info->bmiHeader;
info->biSize = sizeof(BITMAPINFOHEADER); memcpy( &dst_info->bmiHeader + 1, bits.ptr, dst_info->bmiHeader.biSizeImage );
info->biWidth = bm.bmWidth; if (bits.free) bits.free( &bits );
info->biHeight = bm.bmHeight;
info->biPlanes = bm.bmPlanes;
info->biBitCount = bm.bmBitsPixel;
info->biSizeImage = bmSize;
GetBitmapBits((HANDLE)logbrush.lbHatch,
bm.bmHeight * get_bitmap_stride(bm.bmWidth, bm.bmBitsPixel),
(LPBYTE)info + sizeof(BITMAPINFOHEADER));
/* Change the padding to be DIB compatible if needed */
if (bm.bmWidth & 31)
EMFDRV_PadTo32((LPBYTE)info + sizeof(BITMAPINFOHEADER), bm.bmWidth, bm.bmHeight);
emr->emr.iType = EMR_CREATEMONOBRUSH; emr->emr.iType = EMR_CREATEMONOBRUSH;
emr->emr.nSize = size; emr->emr.nSize = size;
@ -249,10 +209,10 @@ DWORD EMFDRV_CreateBrushIndirect( PHYSDEV dev, HBRUSH hBrush )
* FIXME: It may be that the DIB functions themselves accept this value. * FIXME: It may be that the DIB functions themselves accept this value.
*/ */
emr->iUsage = DIB_PAL_MONO; emr->iUsage = DIB_PAL_MONO;
emr->offBmi = (LPBYTE)info - (LPBYTE)emr; emr->offBmi = (LPBYTE)dst_info - (LPBYTE)emr;
emr->cbBmi = biSize; emr->cbBmi = sizeof( BITMAPINFOHEADER );
emr->offBits = emr->offBmi + biSize; emr->offBits = emr->offBmi + emr->cbBmi;
emr->cbBits = bmSize; emr->cbBits = dst_info->bmiHeader.biSizeImage;
if(!EMFDRV_WriteRecord( dev, &emr->emr )) if(!EMFDRV_WriteRecord( dev, &emr->emr ))
index = 0; index = 0;