Vincent Povirk : gdiplus: Implement bitmap color keying.

Alexandre Julliard julliard at winehq.org
Mon May 10 11:59:10 CDT 2010


Module: wine
Branch: master
Commit: 15ebd84daf6d12afff78344a008d291420eb9450
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=15ebd84daf6d12afff78344a008d291420eb9450

Author: Vincent Povirk <vincent at codeweavers.com>
Date:   Sat May  8 12:26:02 2010 -0500

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<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 ||
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);
 }




More information about the wine-cvs mailing list