Make it possible to define a destination colour palette when using convert_pixels(), so converting a bitmap from a non indexed format to an indexed format does not produce an empty image. --- This happens if you e.g. clone an RGB bitmap area to indexed. Most times the cloned image is just a plain black or white image.
v2: Use correct palette param in GdipBitmapUnlockBits.
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/gdiplus/gdiplus_private.h | 4 ++-- dlls/gdiplus/graphics.c | 2 +- dlls/gdiplus/image.c | 22 ++++++++++++---------- 3 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h index 22213e9f278..7ae8cc564c9 100644 --- a/dlls/gdiplus/gdiplus_private.h +++ b/dlls/gdiplus/gdiplus_private.h @@ -207,8 +207,8 @@ extern void convert_32bppARGB_to_32bppPARGB(UINT width, UINT height, BYTE *dst_bits, INT dst_stride, const BYTE *src_bits, INT src_stride) DECLSPEC_HIDDEN;
extern GpStatus convert_pixels(INT width, INT height, - INT dst_stride, BYTE *dst_bits, PixelFormat dst_format, - INT src_stride, const BYTE *src_bits, PixelFormat src_format, ColorPalette *palette) DECLSPEC_HIDDEN; + INT dst_stride, BYTE *dst_bits, PixelFormat dst_format, ColorPalette *dst_palette, + INT src_stride, const BYTE *src_bits, PixelFormat src_format, ColorPalette *src_palette) DECLSPEC_HIDDEN;
extern PixelFormat apply_image_attributes(const GpImageAttributes *attributes, LPBYTE data, UINT width, UINT height, INT stride, ColorAdjustType type, PixelFormat fmt) DECLSPEC_HIDDEN; diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c index 4a428c49869..65cdf96510d 100644 --- a/dlls/gdiplus/graphics.c +++ b/dlls/gdiplus/graphics.c @@ -3350,7 +3350,7 @@ GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image dst_format = PixelFormat32bppRGB;
convert_pixels(bitmap->width, bitmap->height, - bitmap->width*4, temp_bits, dst_format, + bitmap->width*4, temp_bits, dst_format, bitmap->image.palette, bitmap->stride, bitmap->bits, bitmap->format, bitmap->image.palette); } diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index 862f7fea111..0abb6aef72f 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -590,9 +590,10 @@ GpStatus WINGDIPAPI GdipBitmapSetPixel(GpBitmap* bitmap, INT x, INT y, }
GpStatus convert_pixels(INT width, INT height, - INT dst_stride, BYTE *dst_bits, PixelFormat dst_format, + INT dst_stride, BYTE *dst_bits, PixelFormat dst_format, + ColorPalette *dst_palette, INT src_stride, const BYTE *src_bits, PixelFormat src_format, - ColorPalette *palette) + ColorPalette *src_palette) { INT x, y;
@@ -612,7 +613,7 @@ GpStatus convert_pixels(INT width, INT height, ARGB argb; \ BYTE *color = (BYTE *)&argb; \ getpixel_function(&index, src_bits+src_stride*y, x); \ - argb = (palette && index < palette->Count) ? palette->Entries[index] : 0; \ + argb = (src_palette && index < src_palette->Count) ? src_palette->Entries[index] : 0; \ setpixel_function(color[2], color[1], color[0], color[3], dst_bits+dst_stride*y, x); \ } \ return Ok; \ @@ -633,7 +634,7 @@ GpStatus convert_pixels(INT width, INT height, for (x=0; x<width; x++) { \ BYTE r, g, b, a; \ getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \ - setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x, palette); \ + setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x, dst_palette); \ } \ return Ok; \ } while (0); @@ -1137,7 +1138,7 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect, /* Make sure we can convert to the requested format. */ if (flags & ImageLockModeRead) { - stat = convert_pixels(0, 0, 0, NULL, format, 0, NULL, bitmap->format, NULL); + stat = convert_pixels(0, 0, 0, NULL, format, NULL, 0, NULL, bitmap->format, NULL); if (stat == NotImplemented) { FIXME("cannot read bitmap from %x to %x\n", bitmap->format, format); @@ -1150,7 +1151,7 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect, * the original format. */ if (flags & ImageLockModeWrite) { - stat = convert_pixels(0, 0, 0, NULL, bitmap->format, 0, NULL, format, NULL); + stat = convert_pixels(0, 0, 0, NULL, bitmap->format, NULL, 0, NULL, format, NULL); if (stat == NotImplemented) { FIXME("cannot write bitmap from %x to %x\n", format, bitmap->format); @@ -1190,7 +1191,7 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect, }
stat = convert_pixels(act_rect.Width, act_rect.Height, - lockeddata->Stride, lockeddata->Scan0, format, + lockeddata->Stride, lockeddata->Scan0, format, bitmap->image.palette, bitmap->stride, bitmap->bits + bitmap->stride * act_rect.Y + PIXELFORMATBPP(bitmap->format) * act_rect.X / 8, bitmap->format, bitmap->image.palette); @@ -1267,10 +1268,11 @@ GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap, fixme = TRUE; }
+ /* FIXME: Pass src_palette generated from lockeddata->PixelFormat. */ stat = convert_pixels(lockeddata->Width, lockeddata->Height, bitmap->stride, bitmap->bits + bitmap->stride * bitmap->locky + PIXELFORMATBPP(bitmap->format) * bitmap->lockx / 8, - bitmap->format, + bitmap->format, bitmap->image.palette, lockeddata->Stride, lockeddata->Scan0, lockeddata->PixelFormat, NULL);
if (stat != Ok) @@ -1314,7 +1316,7 @@ GpStatus WINGDIPAPI GdipCloneBitmapArea(REAL x, REAL y, REAL width, REAL height, if (stat == Ok) { stat = convert_pixels(area.Width, area.Height, (*dstBitmap)->stride, (*dstBitmap)->bits, (*dstBitmap)->format, - srcBitmap->stride, + (*dstBitmap)->image.palette, srcBitmap->stride, srcBitmap->bits + srcBitmap->stride * area.Y + PIXELFORMATBPP(srcBitmap->format) * area.X / 8, srcBitmap->format, srcBitmap->image.palette);
@@ -1545,7 +1547,7 @@ GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap, }
stat = convert_pixels(width, height, -width*4, - bits + (width * 4 * (height - 1)), PixelFormat32bppPARGB, + bits + (width * 4 * (height - 1)), PixelFormat32bppPARGB, bitmap->image.palette, bitmap->stride, bitmap->bits, bitmap->format, bitmap->image.palette); if (stat != Ok) {