Jeff Smith : gdiplus: Round up when converting from 32-bit ARGB to PARGB.

Alexandre Julliard julliard at winehq.org
Tue Feb 11 15:44:55 CST 2020


Module: wine
Branch: master
Commit: ddd88fe2f40299697208efc9f6b3842a4515054b
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=ddd88fe2f40299697208efc9f6b3842a4515054b

Author: Jeff Smith <whydoubt at gmail.com>
Date:   Mon Feb 10 17:32:52 2020 -0600

gdiplus: Round up when converting from 32-bit ARGB to PARGB.

Applies fix from d23bfd8dfc74a1955a0270feaf07ccd7a23a723a to
setpixel_32bppPARGB.

Signed-off-by: Jeff Smith <whydoubt at gmail.com>
Signed-off-by: Vincent Povirk <vincent at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/gdiplus/image.c       |  6 +++---
 dlls/gdiplus/tests/image.c | 23 +++++++++++++++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c
index 29fba1a9c1..dcdc49c6d6 100644
--- a/dlls/gdiplus/image.c
+++ b/dlls/gdiplus/image.c
@@ -459,9 +459,9 @@ static inline void setpixel_32bppARGB(BYTE r, BYTE g, BYTE b, BYTE a,
 static inline void setpixel_32bppPARGB(BYTE r, BYTE g, BYTE b, BYTE a,
     BYTE *row, UINT x)
 {
-    r = r * a / 255;
-    g = g * a / 255;
-    b = b * a / 255;
+    r = (r * a + 127) / 255;
+    g = (g * a + 127) / 255;
+    b = (b * a + 127) / 255;
     *((DWORD*)(row)+x) = (a<<24)|(r<<16)|(g<<8)|b;
 }
 
diff --git a/dlls/gdiplus/tests/image.c b/dlls/gdiplus/tests/image.c
index 8b9c44ef7b..d6f74050c0 100644
--- a/dlls/gdiplus/tests/image.c
+++ b/dlls/gdiplus/tests/image.c
@@ -4810,6 +4810,7 @@ static void test_PARGB_conversion(void)
 {
     BYTE pargb[8] = { 0x62,0x77,0x99,0x77, 0x62,0x77,0x99,0 };
     BYTE argb[8] = { 0xd1,0xfe,0xff,0x77, 0x62,0x77,0x99,0 };
+    BYTE pargb2[8] = { 0x01,0x01,0x00,0x01, 0xfe,0x7f,0x7f,0xfe };
     BYTE *bits;
     GpBitmap *bitmap;
     BitmapData data;
@@ -4836,6 +4837,28 @@ static void test_PARGB_conversion(void)
     status = GdipBitmapUnlockBits(bitmap, &data);
     expect(Ok, status);
 
+    /* Testing SetPixel 32-bit ARGB to PARGB */
+    status = GdipBitmapSetPixel(bitmap, 0, 0, 0x017f80ff);
+    expect(Ok, status);
+    status = GdipBitmapSetPixel(bitmap, 1, 0, 0xfe7f80ff);
+    expect(Ok, status);
+    status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat32bppPARGB, &data);
+    expect(Ok, status);
+    ok(data.Width == 2, "expected 2, got %d\n", data.Width);
+    ok(data.Height == 1, "expected 1, got %d\n", data.Height);
+    ok(data.Stride == 8, "expected 8, got %d\n", data.Stride);
+    ok(data.PixelFormat == PixelFormat32bppPARGB, "expected PixelFormat32bppPARGB, got %d\n", data.PixelFormat);
+    match = !memcmp(data.Scan0, pargb2, sizeof(pargb2));
+    ok(match, "bits don't match\n");
+    if (!match)
+    {
+        bits = data.Scan0;
+        trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat32bppPARGB,
+               bits[0], bits[1], bits[2], bits[3], bits[4], bits[5], bits[6], bits[7]);
+    }
+    status = GdipBitmapUnlockBits(bitmap, &data);
+    expect(Ok, status);
+
     GdipDisposeImage((GpImage *)bitmap);
 }
 




More information about the wine-cvs mailing list