Commit b28c79aa authored by Walt Ogburn's avatar Walt Ogburn Committed by Alexandre Julliard

Fix BS_PATTERN brushes in mfdrv. Un-comment the corresponding test.

parent 6847d595
......@@ -126,6 +126,68 @@ HBITMAP MFDRV_SelectBitmap( PHYSDEV dev, HBITMAP hbitmap )
return 0;
}
/***********************************************************************
* Internal helper for MFDRV_CreateBrushIndirect():
* Change the padding of a bitmap from 16 (BMP) to 32 (DIB) bits.
*/
static inline void MFDRV_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--;
}
}
/***********************************************************************
* Internal helper for MFDRV_CreateBrushIndirect():
* Reverse order of bitmap rows in going from BMP to DIB.
*/
static inline void MFDRV_Reverse(LPBYTE lpRows, int height, int width)
{
int bytes = 4 * ((width + 31) / 32);
LPBYTE lpSrc, lpDst;
BYTE temp;
int i;
if (!height)
return;
lpSrc = lpRows;
lpDst = lpRows + (height-1) * bytes;
height = height/2;
while (height > 0)
{
for (i = 0; i < bytes; i++)
{
temp = lpDst[i];
lpDst[i] = lpSrc[i];
lpSrc[i] = temp;
}
lpSrc += bytes;
lpDst -= bytes;
height--;
}
}
/******************************************************************
* MFDRV_CreateBrushIndirect
......@@ -162,9 +224,9 @@ INT16 MFDRV_CreateBrushIndirect(PHYSDEV dev, HBRUSH hBrush )
case BS_PATTERN:
{
BITMAP bm;
BYTE *bits;
BITMAPINFO *info;
DWORD bmSize;
COLORREF cref;
GetObjectA((HANDLE)logbrush.lbHatch, sizeof(bm), &bm);
if(bm.bmBitsPixel != 1 || bm.bmPlanes != 1) {
......@@ -190,12 +252,30 @@ INT16 MFDRV_CreateBrushIndirect(PHYSDEV dev, HBRUSH hBrush )
info->bmiHeader.biHeight = bm.bmHeight;
info->bmiHeader.biPlanes = 1;
info->bmiHeader.biBitCount = 1;
bits = ((BYTE *)info) + sizeof(BITMAPINFO) + sizeof(RGBQUAD);
GetDIBits(physDev->hdc, (HANDLE)logbrush.lbHatch, 0, bm.bmHeight,
bits, info, DIB_RGB_COLORS);
*(DWORD *)info->bmiColors = 0;
*(DWORD *)(info->bmiColors + 1) = 0xffffff;
info->bmiHeader.biSizeImage = bmSize;
GetBitmapBits((HANDLE)logbrush.lbHatch,
bm.bmHeight * BITMAP_GetWidthBytes (bm.bmWidth, bm.bmBitsPixel),
(LPBYTE)info + sizeof(BITMAPINFO) + sizeof(RGBQUAD));
/* Change the padding to be DIB compatible if needed */
if(bm.bmWidth & 31)
MFDRV_PadTo32((LPBYTE)info + sizeof(BITMAPINFO) + sizeof(RGBQUAD),
bm.bmWidth, bm.bmHeight);
/* BMP and DIB have opposite row order conventions */
MFDRV_Reverse((LPBYTE)info + sizeof(BITMAPINFO) + sizeof(RGBQUAD),
bm.bmWidth, bm.bmHeight);
cref = GetTextColor(physDev->hdc);
info->bmiColors[0].rgbRed = GetRValue(cref);
info->bmiColors[0].rgbGreen = GetGValue(cref);
info->bmiColors[0].rgbBlue = GetBValue(cref);
info->bmiColors[0].rgbReserved = 0;
cref = GetBkColor(physDev->hdc);
info->bmiColors[1].rgbRed = GetRValue(cref);
info->bmiColors[1].rgbGreen = GetGValue(cref);
info->bmiColors[1].rgbBlue = GetBValue(cref);
info->bmiColors[1].rgbReserved = 0;
break;
}
......
......@@ -442,8 +442,5 @@ START_TEST(metafile)
/* For win-format metafiles (mfdrv) */
test_mf_Blank();
test_mf_Graphics();
/* Crashes under wine: */
/* test_mf_PatternBrush(); */
test_mf_PatternBrush();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment