From 25e1e7344cdf4be584affde7ac71b41a12fa18de Mon Sep 17 00:00:00 2001 From: Martin Petricek Date: Tue, 11 Jan 2011 01:55:12 +0100 Subject: gdiplus: Support for indexed formats in GdipBitmapSetPixel Add support for indexed formats (PixelFormat1bppIndexed, PixelFormat4bppIndexed, PixelFormat8bppIndexed) to GdipBitmapSetPixel. --- dlls/gdiplus/image.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 56 insertions(+), 0 deletions(-) diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index 69f5865..df38fa5 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; -- 1.7.2.3