diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index f9781ef07e3..d14fca00d79 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -297,11 +297,14 @@ 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) { +static inline UINT get_palette_index(BYTE r, BYTE g, BYTE b, BYTE a, ColorPalette *palette) +{ BYTE index = 0; int best_distance = 0x7fff; int distance; int i; + + if (!palette) return 0; /* This algorithm scans entire palette, computes difference from desired color (all color components have equal weight) and returns the index of color with least difference. @@ -311,8 +314,8 @@ static inline UINT get_palette_index(BYTE r, BYTE g, BYTE b, BYTE a, GpBitmap* b tables and thus may actually be slower if this method is called only few times per every image. */ - for(i=0;iimage.palette->Count;i++) { - ARGB color=bitmap->image.palette->Entries[i]; + for(i=0;iCount;i++) { + ARGB color=palette->Entries[i]; distance=abs(b-(color & 0xff)) + abs(g-(color>>8 & 0xff)) + abs(r-(color>>16 & 0xff)) + abs(a-(color>>24 & 0xff)); if (distanceimage.palette); break; case PixelFormat4bppIndexed: - setpixel_4bppIndexed(r,g,b,a,row,x,bitmap); + setpixel_4bppIndexed(r,g,b,a,row,x,bitmap->image.palette); break; case PixelFormat1bppIndexed: - setpixel_1bppIndexed(r,g,b,a,row,x,bitmap); + setpixel_1bppIndexed(r,g,b,a,row,x,bitmap->image.palette); break; default: FIXME("not implemented for format 0x%x\n", bitmap->format);