Commit 37b56554 authored by Alexandre Julliard's avatar Alexandre Julliard

gdi32: Add support for pattern brushes in the DIB driver.

parent 457c9650
......@@ -161,25 +161,18 @@ BOOL init_dib_info(dib_info *dib, const BITMAPINFOHEADER *bi, const DWORD *bit_f
return TRUE;
}
BOOL init_dib_info_from_packed(dib_info *dib, const BITMAPINFOHEADER *bi, WORD usage, HPALETTE palette)
BOOL init_dib_info_from_brush(dib_info *dib, const BITMAPINFO *bi, void *bits, UINT usage, HPALETTE palette)
{
DWORD *masks = NULL;
DWORD *masks = (bi->bmiHeader.biCompression == BI_BITFIELDS) ? (DWORD *)bi->bmiColors : NULL;
RGBQUAD *color_table = NULL, pal_table[256];
BYTE *ptr = (BYTE*)bi + bi->biSize;
int num_colors = get_dib_num_of_colors( (const BITMAPINFO *)bi );
if(bi->biCompression == BI_BITFIELDS)
{
masks = (DWORD *)ptr;
ptr += 3 * sizeof(DWORD);
}
int num_colors = get_dib_num_of_colors( bi );
if(num_colors)
{
if(usage == DIB_PAL_COLORS)
{
PALETTEENTRY entries[256];
const WORD *index = (const WORD*) ptr;
const WORD *index = (const WORD *)bi->bmiColors;
UINT i, count = GetPaletteEntries( palette, 0, num_colors, entries );
for (i = 0; i < num_colors; i++, index++)
{
......@@ -190,16 +183,10 @@ BOOL init_dib_info_from_packed(dib_info *dib, const BITMAPINFOHEADER *bi, WORD u
pal_table[i].rgbReserved = 0;
}
color_table = pal_table;
ptr += num_colors * sizeof(WORD);
}
else
{
color_table = (RGBQUAD*)ptr;
ptr += num_colors * sizeof(*color_table);
}
else color_table = (RGBQUAD *)bi->bmiColors;
}
return init_dib_info(dib, bi, masks, color_table, num_colors, ptr, private_color_table);
return init_dib_info(dib, &bi->bmiHeader, masks, color_table, num_colors, bits, private_color_table);
}
BOOL init_dib_info_from_bitmapinfo(dib_info *dib, const BITMAPINFO *info, void *bits, enum dib_info_flags flags)
......
......@@ -195,7 +195,7 @@ extern void reset_dash_origin(dibdrv_physdev *pdev) DECLSPEC_HIDDEN;
extern BOOL init_dib_info(dib_info *dib, const BITMAPINFOHEADER *bi, const DWORD *bit_fields,
RGBQUAD *color_table, int color_table_size, void *bits,
enum dib_info_flags flags) DECLSPEC_HIDDEN;
extern BOOL init_dib_info_from_packed(dib_info *dib, const BITMAPINFOHEADER *bi, WORD usage, HPALETTE pal) DECLSPEC_HIDDEN;
extern BOOL init_dib_info_from_brush(dib_info *dib, const BITMAPINFO *bi, void *bits, UINT usage, HPALETTE pal) DECLSPEC_HIDDEN;
extern BOOL init_dib_info_from_bitmapinfo(dib_info *dib, const BITMAPINFO *info, void *bits,
enum dib_info_flags flags) DECLSPEC_HIDDEN;
extern BOOL init_dib_info_from_bitmapobj(dib_info *dib, BITMAPOBJ *bmp, enum dib_info_flags flags) DECLSPEC_HIDDEN;
......
......@@ -1345,6 +1345,53 @@ HBRUSH dibdrv_SelectBrush( PHYSDEV dev, HBRUSH hbrush, HBITMAP bitmap,
TRACE("(%p, %p)\n", dev, hbrush);
if (bitmap || info) /* pattern brush */
{
dib_info orig_dib;
HPALETTE pal = (usage == DIB_PAL_COLORS) ? GetCurrentObject(dev->hdc, OBJ_PAL) : NULL;
RECT rect;
BOOL ret;
if (!info)
{
BITMAPOBJ *bmp = GDI_GetObjPtr( bitmap, OBJ_BITMAP );
if (!bmp) return 0;
ret = init_dib_info_from_bitmapobj( &orig_dib, bmp, 0 );
GDI_ReleaseObj( bitmap );
}
else ret = init_dib_info_from_brush( &orig_dib, info, bits, usage, pal );
if (!ret) return 0;
if (usage == DIB_PAL_COLORS) FIXME( "DIB_PAL_COLORS brush not handled correctly\n");
free_pattern_brush( pdev );
copy_dib_color_info(&pdev->brush_dib, &pdev->dib);
pdev->brush_dib.height = orig_dib.height;
pdev->brush_dib.width = orig_dib.width;
pdev->brush_dib.stride = get_dib_stride( pdev->brush_dib.width, pdev->brush_dib.bit_count );
pdev->brush_dib.bits.param = NULL;
pdev->brush_dib.bits.ptr = HeapAlloc( GetProcessHeap(), 0,
pdev->brush_dib.height * pdev->brush_dib.stride );
pdev->brush_dib.bits.is_copy = TRUE;
pdev->brush_dib.bits.free = free_heap_bits;
rect.left = rect.top = 0;
rect.right = orig_dib.width;
rect.bottom = orig_dib.height;
pdev->brush_dib.funcs->convert_to(&pdev->brush_dib, &orig_dib, &rect);
pdev->brush_rects = pattern_brush;
pdev->brush_style = BS_DIBPATTERN;
pdev->defer &= ~DEFER_BRUSH;
free_dib_info(&orig_dib);
return next->funcs->pSelectBrush( next, hbrush, bitmap, info, bits, usage );
}
if (!GetObjectW( hbrush, sizeof(logbrush), &logbrush )) return 0;
if (hbrush == GetStockObject( DC_BRUSH ))
......@@ -1371,42 +1418,7 @@ HBRUSH dibdrv_SelectBrush( PHYSDEV dev, HBRUSH hbrush, HBITMAP bitmap,
pdev->defer &= ~DEFER_BRUSH;
break;
case BS_DIBPATTERN:
{
BITMAPINFOHEADER *bi = (BITMAPINFOHEADER *)logbrush.lbHatch;
dib_info orig_dib;
WORD usage = LOWORD(logbrush.lbColor);
HPALETTE pal = (usage == DIB_PAL_COLORS) ? GetCurrentObject(dev->hdc, OBJ_PAL) : NULL;
RECT rect;
if(init_dib_info_from_packed(&orig_dib, bi, usage, pal))
{
copy_dib_color_info(&pdev->brush_dib, &pdev->dib);
pdev->brush_dib.height = orig_dib.height;
pdev->brush_dib.width = orig_dib.width;
pdev->brush_dib.stride = get_dib_stride( pdev->brush_dib.width, pdev->brush_dib.bit_count );
pdev->brush_dib.bits.param = NULL;
pdev->brush_dib.bits.ptr = HeapAlloc( GetProcessHeap(), 0,
pdev->brush_dib.height * pdev->brush_dib.stride );
pdev->brush_dib.bits.is_copy = TRUE;
pdev->brush_dib.bits.free = free_heap_bits;
rect.left = rect.top = 0;
rect.right = orig_dib.width;
rect.bottom = orig_dib.height;
pdev->brush_dib.funcs->convert_to(&pdev->brush_dib, &orig_dib, &rect);
pdev->brush_rects = pattern_brush;
pdev->defer &= ~DEFER_BRUSH;
free_dib_info(&orig_dib);
}
break;
}
case BS_HATCHED:
{
if(logbrush.lbHatch > HS_DIAGCROSS) return 0;
pdev->brush_hatch = logbrush.lbHatch;
pdev->brush_colorref = logbrush.lbColor;
......@@ -1415,10 +1427,9 @@ HBRUSH dibdrv_SelectBrush( PHYSDEV dev, HBRUSH hbrush, HBITMAP bitmap,
pdev->brush_rects = pattern_brush;
pdev->defer &= ~DEFER_BRUSH;
break;
}
default:
break;
return 0;
}
return next->funcs->pSelectBrush( next, hbrush, bitmap, info, bits, usage );
......
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