gdiplus: Fix calculation for 32-bit PARGB to ARGB conversion.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Vincent Povirk <vincent@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jeff Smith 2020-02-10 17:32:51 -06:00 committed by Alexandre Julliard
parent 884f31b5c1
commit 06bf4283fb
2 changed files with 43 additions and 4 deletions

View File

@ -239,12 +239,17 @@ static inline void getpixel_32bppPARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
{
*a = row[x*4+3];
if (*a == 0)
*r = *g = *b = 0;
{
*r = row[x*4+2];
*g = row[x*4+1];
*b = row[x*4];
}
else
{
*r = row[x*4+2] * 255 / *a;
*g = row[x*4+1] * 255 / *a;
*b = row[x*4] * 255 / *a;
DWORD scaled_q = (255 << 15) / *a;
*r = (row[x*4+2] > *a) ? 0xff : (row[x*4+2] * scaled_q) >> 15;
*g = (row[x*4+1] > *a) ? 0xff : (row[x*4+1] * scaled_q) >> 15;
*b = (row[x*4] > *a) ? 0xff : (row[x*4] * scaled_q) >> 15;
}
}

View File

@ -4806,6 +4806,39 @@ static void test_ARGB_conversion(void)
GdipDisposeImage((GpImage *)bitmap);
}
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 *bits;
GpBitmap *bitmap;
BitmapData data;
GpStatus status;
int match;
status = GdipCreateBitmapFromScan0(2, 1, 8, PixelFormat32bppPARGB, pargb, &bitmap);
expect(Ok, status);
status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat32bppARGB, &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 == PixelFormat32bppARGB, "expected PixelFormat32bppARGB, got %d\n", data.PixelFormat);
match = !memcmp(data.Scan0, argb, sizeof(argb));
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", PixelFormat32bppARGB,
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);
}
static void test_CloneBitmapArea(void)
{
@ -5626,6 +5659,7 @@ START_TEST(image)
test_supported_encoders();
test_CloneBitmapArea();
test_ARGB_conversion();
test_PARGB_conversion();
test_DrawImage_scale();
test_image_format();
test_DrawImage();