From 7f0520ee3747f572e53fd641c1fde8c93a92257b Mon Sep 17 00:00:00 2001 From: Martin Petricek Date: Wed, 12 Jan 2011 04:34:47 +0100 Subject: gdiplus: Support for indexed formats in GdipBitmapSetPixel Add support for indexed formats (PixelFormat1bppIndexed, PixelFormat4bppIndexed, PixelFormat8bppIndexed) to GdipBitmapSetPixel. --- dlls/gdiplus/image.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ dlls/gdiplus/tests/image.c | 6 ++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index 69f5865..a69046d 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -296,6 +296,53 @@ GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y, return Ok; } +static inline UINT get_palette_index(BYTE r, BYTE g, BYTE b, BYTE a, GpBitmap* bitmap) { + BYTE index = 0; + int best_distance = 0x7fff; + int distance; + int i; + /* This algorithm scans entire pallete, + computes difference from desired color (all color components have equal weight) + and returns the index of color with least difference. + + Note: Maybe it could be replaced with a better algorithm for better image quality + and performance, though better algorithm would probably need some pre-built lookup + tables and thus may actually be slower if this method is called only few times per + every image. + */ + for(i=0;iimage.palette_size;i++) { + ARGB color=bitmap->image.palette_entries[i]; + distance=abs(b-(color & 0xff)) + abs(g-(color>>8 & 0xff)) + abs(r-(color>>16 & 0xff)) + abs(a-(color>>24 & 0xff)); + if (distanceformat); return NotImplemented; diff --git a/dlls/gdiplus/tests/image.c b/dlls/gdiplus/tests/image.c index b2b1a0f..989e0bb 100644 --- a/dlls/gdiplus/tests/image.c +++ b/dlls/gdiplus/tests/image.c @@ -1568,7 +1568,7 @@ static void test_palette(void) expect(0xff000000, color); stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff); - todo_wine ok((stat == Ok) || + ok((stat == Ok) || broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat); if (stat == Ok) @@ -1601,7 +1601,7 @@ static void test_palette(void) expect(0xff000000, color); stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff); - todo_wine ok((stat == Ok) || + ok((stat == Ok) || broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat); if (stat == Ok) @@ -1634,7 +1634,7 @@ static void test_palette(void) expect(0xff000000, color); stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc); - todo_wine ok((stat == Ok) || + ok((stat == Ok) || broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat); if (stat == Ok) -- 1.7.2.3