From 17b2bcd7928d78f1e164276a9ca100e4cabb082b Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Sat, 30 Jan 2010 19:01:52 -0600 Subject: [PATCH 3/3] gdiplus: Implement GetPixel for indexed color bitmaps. --- dlls/gdiplus/image.c | 33 ++++++++++++++++++++++++++++++++- dlls/gdiplus/tests/image.c | 12 ++++++------ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index 4d6448e..4fd593f 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -94,6 +94,24 @@ GpStatus WINGDIPAPI GdipBitmapCreateApplyEffect(GpBitmap** inputBitmaps, return NotImplemented; } +static inline void getpixel_1bppIndexed(BYTE *index, const BYTE *row, UINT x) +{ + *index = (row[x/8]>>(7-x%8)) & 1; +} + +static inline void getpixel_4bppIndexed(BYTE *index, const BYTE *row, UINT x) +{ + if (x & 1) + *index = row[x/2]&0xf; + else + *index = row[x/2]>>4; +} + +static inline void getpixel_8bppIndexed(BYTE *index, const BYTE *row, UINT x) +{ + *index = row[x]; +} + static inline void getpixel_16bppGrayScale(BYTE *r, BYTE *g, BYTE *b, BYTE *a, const BYTE *row, UINT x) { @@ -211,6 +229,7 @@ GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y, ARGB *color) { BYTE r, g, b, a; + BYTE index; BYTE *row; TRACE("%p %d %d %p\n", bitmap, x, y, color); @@ -222,6 +241,15 @@ GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y, switch (bitmap->format) { + case PixelFormat1bppIndexed: + getpixel_1bppIndexed(&index,row,x); + break; + case PixelFormat4bppIndexed: + getpixel_4bppIndexed(&index,row,x); + break; + case PixelFormat8bppIndexed: + getpixel_8bppIndexed(&index,row,x); + break; case PixelFormat16bppGrayScale: getpixel_16bppGrayScale(&r,&g,&b,&a,row,x); break; @@ -260,7 +288,10 @@ GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y, return NotImplemented; } - *color = a<<24|r<<16|g<<8|b; + if (bitmap->format & PixelFormatIndexed) + *color = bitmap->image.palette_entries[index]; + else + *color = a<<24|r<<16|g<<8|b; return Ok; } diff --git a/dlls/gdiplus/tests/image.c b/dlls/gdiplus/tests/image.c index 53d66e0..10dc21e 100644 --- a/dlls/gdiplus/tests/image.c +++ b/dlls/gdiplus/tests/image.c @@ -1181,8 +1181,8 @@ static void test_palette(void) /* test getting/setting pixels */ stat = GdipBitmapGetPixel(bitmap, 0, 0, &color); - todo_wine expect(Ok, stat); - todo_wine expect(0xff000000, color); + expect(Ok, stat); + expect(0xff000000, color); stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff); todo_wine ok((stat == Ok) || @@ -1214,8 +1214,8 @@ static void test_palette(void) /* test getting/setting pixels */ stat = GdipBitmapGetPixel(bitmap, 0, 0, &color); - todo_wine expect(Ok, stat); - todo_wine expect(0xff000000, color); + expect(Ok, stat); + expect(0xff000000, color); stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff); todo_wine ok((stat == Ok) || @@ -1247,8 +1247,8 @@ static void test_palette(void) /* test getting/setting pixels */ stat = GdipBitmapGetPixel(bitmap, 0, 0, &color); - todo_wine expect(Ok, stat); - todo_wine expect(0xff000000, color); + expect(Ok, stat); + expect(0xff000000, color); stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc); todo_wine ok((stat == Ok) || -- 1.6.3.3