gdiplus: Implement bitmap color keying.

This commit is contained in:
Vincent Povirk 2010-05-08 12:26:02 -05:00 committed by Alexandre Julliard
parent d2a01883fc
commit 15ebd84daf
2 changed files with 101 additions and 3 deletions

View File

@ -2083,9 +2083,36 @@ GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image
if (imageAttributes->colorkeys[ColorAdjustTypeBitmap].enabled ||
imageAttributes->colorkeys[ColorAdjustTypeDefault].enabled)
{
static int fixme;
if (!fixme++)
FIXME("Color keying not implemented\n");
const struct color_key *key;
BYTE min_blue, min_green, min_red;
BYTE max_blue, max_green, max_red;
if (imageAttributes->colorkeys[ColorAdjustTypeBitmap].enabled)
key = &imageAttributes->colorkeys[ColorAdjustTypeBitmap];
else
key = &imageAttributes->colorkeys[ColorAdjustTypeDefault];
min_blue = key->low&0xff;
min_green = (key->low>>8)&0xff;
min_red = (key->low>>16)&0xff;
max_blue = key->high&0xff;
max_green = (key->high>>8)&0xff;
max_red = (key->high>>16)&0xff;
for (x=dst_area.left; x<dst_area.right; x++)
for (y=dst_area.top; y<dst_area.bottom; y++)
{
ARGB *src_color;
BYTE blue, green, red;
src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
blue = *src_color&0xff;
green = (*src_color>>8)&0xff;
red = (*src_color>>16)&0xff;
if (blue >= min_blue && green >= min_green && red >= min_red &&
blue <= max_blue && green <= max_green && red <= max_red)
*src_color = 0x00000000;
}
}
if (imageAttributes->colorremaptables[ColorAdjustTypeBitmap].enabled ||

View File

@ -1999,6 +1999,76 @@ static void test_remaptable(void)
GdipFree(map);
}
static void test_colorkey(void)
{
GpStatus stat;
GpImageAttributes *imageattr;
GpBitmap *bitmap1, *bitmap2;
GpGraphics *graphics;
ARGB color;
stat = GdipSetImageAttributesColorKeys(NULL, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
expect(InvalidParameter, stat);
stat = GdipCreateImageAttributes(&imageattr);
expect(Ok, stat);
stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeCount, TRUE, 0xff405060, 0xff708090);
expect(InvalidParameter, stat);
stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeAny, TRUE, 0xff405060, 0xff708090);
expect(InvalidParameter, stat);
stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
expect(Ok, stat);
stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap1);
expect(Ok, stat);
stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap2);
expect(Ok, stat);
stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0x20405060);
expect(Ok, stat);
stat = GdipBitmapSetPixel(bitmap1, 0, 1, 0x40506070);
expect(Ok, stat);
stat = GdipBitmapSetPixel(bitmap1, 1, 0, 0x60708090);
expect(Ok, stat);
stat = GdipBitmapSetPixel(bitmap1, 1, 1, 0xffffffff);
expect(Ok, stat);
stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
expect(Ok, stat);
stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,2,2, 0,0,2,2,
UnitPixel, imageattr, NULL, NULL);
expect(Ok, stat);
stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
expect(Ok, stat);
ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
stat = GdipBitmapGetPixel(bitmap2, 0, 1, &color);
expect(Ok, stat);
ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
stat = GdipBitmapGetPixel(bitmap2, 1, 0, &color);
expect(Ok, stat);
ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
stat = GdipBitmapGetPixel(bitmap2, 1, 1, &color);
expect(Ok, stat);
ok(color_match(0xffffffff, color, 1), "Expected ffff00ff, got %.8x\n", color);
GdipDeleteGraphics(graphics);
GdipDisposeImage((GpImage*)bitmap1);
GdipDisposeImage((GpImage*)bitmap2);
GdipDisposeImageAttributes(imageattr);
}
START_TEST(image)
{
struct GdiplusStartupInput gdiplusStartupInput;
@ -2036,6 +2106,7 @@ START_TEST(image)
test_multiframegif();
test_rotateflip();
test_remaptable();
test_colorkey();
GdiplusShutdown(gdiplusToken);
}