gdi32: Simplify creation of hatch masks and avoid endianness issues.

This commit is contained in:
Alexandre Julliard 2012-05-23 11:24:18 +02:00
parent 574a07e4c9
commit b8e4cd81ab
3 changed files with 90 additions and 126 deletions

View File

@ -191,7 +191,7 @@ typedef struct primitive_funcs
DWORD (* colorref_to_pixel)(const dib_info *dib, COLORREF color);
COLORREF (* pixel_to_colorref)(const dib_info *dib, DWORD pixel);
void (* convert_to)(dib_info *dst, const dib_info *src, const RECT *src_rect, BOOL dither);
BOOL (* create_rop_masks)(const dib_info *dib, const dib_info *hatch,
void (* create_rop_masks)(const dib_info *dib, const BYTE *hatch_ptr,
const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits);
void (* stretch_row)(const dib_info *dst_dib, const POINT *dst_start,
const dib_info *src_dib, const POINT *src_start,

View File

@ -1777,7 +1777,7 @@ static BOOL create_pattern_brush_bits( dib_brush *brush )
return TRUE;
}
static const DWORD hatches[6][8] =
static const BYTE hatches[6][8] =
{
{ 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HS_HORIZONTAL */
{ 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HS_VERTICAL */
@ -1789,9 +1789,7 @@ static const DWORD hatches[6][8] =
static BOOL create_hatch_brush_bits(dibdrv_physdev *pdev, dib_brush *brush, BOOL *needs_reselect)
{
dib_info hatch;
rop_mask fg_mask, bg_mask;
BOOL ret;
/* Just initialise brush dib with the color / sizing info. We don't
need the bits as we'll calculate the rop masks straight from
@ -1808,17 +1806,6 @@ static BOOL create_hatch_brush_bits(dibdrv_physdev *pdev, dib_brush *brush, BOOL
if (!alloc_brush_mask_bits( brush )) return FALSE;
hatch.bit_count = 1;
hatch.height = hatch.width = 8;
hatch.stride = 4;
hatch.bits.ptr = (void *) hatches[brush->hatch];
hatch.bits.free = hatch.bits.param = NULL;
hatch.bits.is_copy = FALSE;
hatch.rect.left = 0;
hatch.rect.top = 0;
hatch.rect.right = 8;
hatch.rect.bottom = 8;
get_color_masks( pdev, brush->rop, brush->colorref, GetBkMode(pdev->dev.hdc),
&fg_mask, &bg_mask );
@ -1827,10 +1814,9 @@ static BOOL create_hatch_brush_bits(dibdrv_physdev *pdev, dib_brush *brush, BOOL
if (GetBkMode(pdev->dev.hdc) != TRANSPARENT && (GetBkColor(pdev->dev.hdc) & (1 << 24)))
*needs_reselect = TRUE;
ret = brush->dib.funcs->create_rop_masks( &brush->dib, &hatch, &fg_mask, &bg_mask, &brush->masks );
if(!ret) free_brush_mask_bits( brush );
return ret;
brush->dib.funcs->create_rop_masks( &brush->dib, hatches[brush->hatch],
&fg_mask, &bg_mask, &brush->masks );
return TRUE;
}
static BOOL matching_pattern_format( dib_info *dib, dib_info *pattern )

View File

@ -4803,53 +4803,53 @@ static void draw_glyph_null( const dib_info *dib, const RECT *rect, const dib_in
return;
}
static BOOL create_rop_masks_32(const dib_info *dib, const dib_info *hatch, const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits)
static void create_rop_masks_32(const dib_info *dib, const BYTE *hatch_ptr,
const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits)
{
BYTE *hatch_start = get_pixel_ptr_1(hatch, 0, 0), *hatch_ptr;
DWORD mask_start = 0, mask_offset;
DWORD *and_bits = bits->and, *xor_bits = bits->xor;
int x, y;
for(y = 0; y < hatch->height; y++)
/* masks are always 8x8 */
assert( dib->width == 8 );
assert( dib->height == 8 );
for(y = 0; y < 8; y++, hatch_ptr++)
{
hatch_ptr = hatch_start;
mask_offset = mask_start;
for(x = 0; x < hatch->width; x++)
for(x = 0; x < 8; x++)
{
if(*hatch_ptr & pixel_masks_1[x % 8])
if(*hatch_ptr & pixel_masks_1[x])
{
and_bits[mask_offset] = fg->and;
xor_bits[mask_offset] = fg->xor;
and_bits[x] = fg->and;
xor_bits[x] = fg->xor;
}
else
{
and_bits[mask_offset] = bg->and;
xor_bits[mask_offset] = bg->xor;
and_bits[x] = bg->and;
xor_bits[x] = bg->xor;
}
if(x % 8 == 7) hatch_ptr++;
mask_offset++;
}
hatch_start += hatch->stride;
mask_start += dib->stride / 4;
and_bits += dib->stride / 4;
xor_bits += dib->stride / 4;
}
return TRUE;
}
static BOOL create_rop_masks_24(const dib_info *dib, const dib_info *hatch, const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits)
static void create_rop_masks_24(const dib_info *dib, const BYTE *hatch_ptr,
const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits)
{
BYTE *hatch_start = get_pixel_ptr_1(hatch, 0, 0), *hatch_ptr;
DWORD mask_start = 0, mask_offset;
BYTE *and_bits = bits->and, *xor_bits = bits->xor;
int x, y;
for(y = 0; y < hatch->height; y++)
/* masks are always 8x8 */
assert( dib->width == 8 );
assert( dib->height == 8 );
for(y = 0; y < 8; y++, hatch_ptr++)
{
hatch_ptr = hatch_start;
mask_offset = mask_start;
for(x = 0; x < hatch->width; x++)
for(x = 0; x < 8; x++)
{
if(*hatch_ptr & pixel_masks_1[x % 8])
if(*hatch_ptr & pixel_masks_1[x])
{
and_bits[mask_offset] = fg->and & 0xff;
xor_bits[mask_offset++] = fg->xor & 0xff;
@ -4867,104 +4867,96 @@ static BOOL create_rop_masks_24(const dib_info *dib, const dib_info *hatch, cons
and_bits[mask_offset] = (bg->and >> 16) & 0xff;
xor_bits[mask_offset++] = (bg->xor >> 16) & 0xff;
}
if(x % 8 == 7) hatch_ptr++;
}
hatch_start += hatch->stride;
mask_start += dib->stride;
}
return TRUE;
}
static BOOL create_rop_masks_16(const dib_info *dib, const dib_info *hatch, const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits)
static void create_rop_masks_16(const dib_info *dib, const BYTE *hatch_ptr,
const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits)
{
BYTE *hatch_start = get_pixel_ptr_1(hatch, 0, 0), *hatch_ptr;
DWORD mask_start = 0, mask_offset;
WORD *and_bits = bits->and, *xor_bits = bits->xor;
int x, y;
for(y = 0; y < hatch->height; y++)
/* masks are always 8x8 */
assert( dib->width == 8 );
assert( dib->height == 8 );
for(y = 0; y < 8; y++, hatch_ptr++)
{
hatch_ptr = hatch_start;
mask_offset = mask_start;
for(x = 0; x < hatch->width; x++)
for(x = 0; x < 8; x++)
{
if(*hatch_ptr & pixel_masks_1[x % 8])
if(*hatch_ptr & pixel_masks_1[x])
{
and_bits[mask_offset] = fg->and;
xor_bits[mask_offset] = fg->xor;
and_bits[x] = fg->and;
xor_bits[x] = fg->xor;
}
else
{
and_bits[mask_offset] = bg->and;
xor_bits[mask_offset] = bg->xor;
and_bits[x] = bg->and;
xor_bits[x] = bg->xor;
}
if(x % 8 == 7) hatch_ptr++;
mask_offset++;
}
hatch_start += hatch->stride;
mask_start += dib->stride / 2;
and_bits += dib->stride / 2;
xor_bits += dib->stride / 2;
}
return TRUE;
}
static BOOL create_rop_masks_8(const dib_info *dib, const dib_info *hatch, const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits)
static void create_rop_masks_8(const dib_info *dib, const BYTE *hatch_ptr,
const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits)
{
BYTE *hatch_start = get_pixel_ptr_1(hatch, 0, 0), *hatch_ptr;
DWORD mask_start = 0, mask_offset;
BYTE *and_bits = bits->and, *xor_bits = bits->xor;
int x, y;
for(y = 0; y < hatch->height; y++)
/* masks are always 8x8 */
assert( dib->width == 8 );
assert( dib->height == 8 );
for(y = 0; y < 8; y++, hatch_ptr++)
{
hatch_ptr = hatch_start;
mask_offset = mask_start;
for(x = 0; x < hatch->width; x++)
for(x = 0; x < 8; x++)
{
if(*hatch_ptr & pixel_masks_1[x % 8])
if(*hatch_ptr & pixel_masks_1[x])
{
and_bits[mask_offset] = fg->and;
xor_bits[mask_offset] = fg->xor;
and_bits[x] = fg->and;
xor_bits[x] = fg->xor;
}
else
{
and_bits[mask_offset] = bg->and;
xor_bits[mask_offset] = bg->xor;
and_bits[x] = bg->and;
xor_bits[x] = bg->xor;
}
if(x % 8 == 7) hatch_ptr++;
mask_offset++;
}
hatch_start += hatch->stride;
mask_start += dib->stride;
and_bits += dib->stride;
xor_bits += dib->stride;
}
return TRUE;
}
static BOOL create_rop_masks_4(const dib_info *dib, const dib_info *hatch, const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits)
static void create_rop_masks_4(const dib_info *dib, const BYTE *hatch_ptr,
const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits)
{
BYTE *hatch_start = get_pixel_ptr_1(hatch, 0, 0), *hatch_ptr;
DWORD mask_start = 0, mask_offset;
DWORD mask_offset;
BYTE *and_bits = bits->and, *xor_bits = bits->xor;
const rop_mask *rop_mask;
int x, y;
for(y = 0; y < hatch->height; y++)
/* masks are always 8x8 */
assert( dib->width == 8 );
assert( dib->height == 8 );
for(y = 0; y < 8; y++, hatch_ptr++)
{
hatch_ptr = hatch_start;
mask_offset = mask_start;
for(x = 0; x < hatch->width; x++)
for(x = mask_offset = 0; x < 8; x++)
{
if(*hatch_ptr & pixel_masks_1[x % 8])
if(*hatch_ptr & pixel_masks_1[x])
rop_mask = fg;
else
rop_mask = bg;
if(x & 1)
{
and_bits[mask_offset] = (rop_mask->and & 0x0f) | (and_bits[mask_offset] & 0xf0);
xor_bits[mask_offset] = (rop_mask->xor & 0x0f) | (xor_bits[mask_offset] & 0xf0);
and_bits[mask_offset] |= (rop_mask->and & 0x0f);
xor_bits[mask_offset] |= (rop_mask->xor & 0x0f);
mask_offset++;
}
else
@ -4972,31 +4964,29 @@ static BOOL create_rop_masks_4(const dib_info *dib, const dib_info *hatch, const
and_bits[mask_offset] = (rop_mask->and << 4) & 0xf0;
xor_bits[mask_offset] = (rop_mask->xor << 4) & 0xf0;
}
if(x % 8 == 7) hatch_ptr++;
}
hatch_start += hatch->stride;
mask_start += dib->stride;
and_bits += dib->stride;
xor_bits += dib->stride;
}
return TRUE;
}
static BOOL create_rop_masks_1(const dib_info *dib, const dib_info *hatch, const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits)
static void create_rop_masks_1(const dib_info *dib, const BYTE *hatch_ptr,
const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits)
{
BYTE *hatch_start = get_pixel_ptr_1(hatch, 0, 0), *hatch_ptr;
DWORD mask_start = 0, mask_offset;
BYTE *and_bits = bits->and, *xor_bits = bits->xor;
rop_mask rop_mask;
int x, y, bit_pos;
int x, y;
for(y = 0; y < hatch->height; y++)
/* masks are always 8x8 */
assert( dib->width == 8 );
assert( dib->height == 8 );
for(y = 0; y < 8; y++, hatch_ptr++)
{
hatch_ptr = hatch_start;
mask_offset = mask_start;
for(x = 0, bit_pos = 0; x < hatch->width; x++)
*and_bits = *xor_bits = 0;
for(x = 0; x < 8; x++)
{
if(*hatch_ptr & pixel_masks_1[x % 8])
if(*hatch_ptr & pixel_masks_1[x])
{
rop_mask.and = (fg->and & 1) ? 0xff : 0;
rop_mask.xor = (fg->xor & 1) ? 0xff : 0;
@ -5006,29 +4996,17 @@ static BOOL create_rop_masks_1(const dib_info *dib, const dib_info *hatch, const
rop_mask.and = (bg->and & 1) ? 0xff : 0;
rop_mask.xor = (bg->xor & 1) ? 0xff : 0;
}
if(bit_pos == 0) and_bits[mask_offset] = xor_bits[mask_offset] = 0;
and_bits[mask_offset] = (rop_mask.and & pixel_masks_1[bit_pos]) | (and_bits[mask_offset] & ~pixel_masks_1[bit_pos]);
xor_bits[mask_offset] = (rop_mask.xor & pixel_masks_1[bit_pos]) | (xor_bits[mask_offset] & ~pixel_masks_1[bit_pos]);
if(++bit_pos == 8)
{
mask_offset++;
hatch_ptr++;
bit_pos = 0;
}
*and_bits |= (rop_mask.and & pixel_masks_1[x]);
*xor_bits |= (rop_mask.xor & pixel_masks_1[x]);
}
hatch_start += hatch->stride;
mask_start += dib->stride;
and_bits += dib->stride;
xor_bits += dib->stride;
}
return TRUE;
}
static BOOL create_rop_masks_null(const dib_info *dib, const dib_info *hatch, const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits)
static void create_rop_masks_null(const dib_info *dib, const BYTE *hatch_ptr,
const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits)
{
return FALSE;
}
static inline void rop_codes_from_stretch_mode( int mode, struct rop_codes *codes )