From ec29292141ac39d2f7625ddae8e1547dd818eabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20K=C3=B6lbl?= Date: Mon, 29 Nov 2021 15:28:33 +0100 Subject: [PATCH] gdiplus: Introduce dst palette parameter to convert_pixels(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Signed-off-by: Bernhard Kölbl Signed-off-by: Esme Povirk Signed-off-by: Alexandre Julliard --- dlls/gdiplus/gdiplus_private.h | 4 ++-- dlls/gdiplus/graphics.c | 2 +- dlls/gdiplus/image.c | 20 +++++++++++--------- 3 files changed, 14 insertions(+), 12 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..518a9bf8689 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -591,8 +591,9 @@ 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, + 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; xformat, 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) {