From 9d1a9fec93feaaff1fa7bd6f60a1c5fce6eaf787 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Sat, 8 May 2010 12:26:02 -0500 Subject: [PATCH] gdiplus: Implement bitmap color keying. --- dlls/gdiplus/graphics.c | 33 ++++++++++++++++++-- dlls/gdiplus/tests/image.c | 71 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 3 deletions(-) diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c index eb24008..790e0fb 100644 --- a/dlls/gdiplus/graphics.c +++ b/dlls/gdiplus/graphics.c @@ -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>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 || diff --git a/dlls/gdiplus/tests/image.c b/dlls/gdiplus/tests/image.c index 09ba8f0..a981bbf 100644 --- a/dlls/gdiplus/tests/image.c +++ b/dlls/gdiplus/tests/image.c @@ -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); } -- 1.6.3.3