[PATCH 0/2] MR9803: windowscodecs: Add support for converting from 32bpp RGBA to 64bpp RGBA.
From: Dmitry Timoshkov <dmitry@baikal.ru> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=58757 Signed-off-by: Dmitry Timoshkov <dmitry@baikal.ru> --- dlls/windowscodecs/converter.c | 89 ++++++++++++++++++++++++++++ dlls/windowscodecs/tests/converter.c | 26 +++++++- 2 files changed, 113 insertions(+), 2 deletions(-) diff --git a/dlls/windowscodecs/converter.c b/dlls/windowscodecs/converter.c index d6be5920ea2..0801d583d96 100644 --- a/dlls/windowscodecs/converter.c +++ b/dlls/windowscodecs/converter.c @@ -1891,6 +1891,95 @@ static HRESULT copypixels_to_64bppRGBA(struct FormatConverter *This, const WICRe free(srcdata); return hr; } + + case format_32bppRGBA: + { + UINT srcstride, srcdatasize; + const BYTE *srcpixel; + const BYTE *srcrow; + WORD *dstpixel; + BYTE *srcdata; + BYTE *dstrow; + INT x, y; + + if (!prc) + return S_OK; + + srcstride = 4 * prc->Width; + srcdatasize = srcstride * prc->Height; + + srcdata = malloc(srcdatasize); + if (!srcdata) return E_OUTOFMEMORY; + + hr = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); + if (SUCCEEDED(hr)) + { + srcrow = srcdata; + dstrow = pbBuffer; + for (y = 0; y < prc->Height; y++) + { + srcpixel = srcrow; + dstpixel = (WORD *)dstrow; + for (x = 0; x < prc->Width; x++) + { + *dstpixel++ = srcpixel[0] * 257; + *dstpixel++ = srcpixel[1] * 257; + *dstpixel++ = srcpixel[2] * 257; + *dstpixel++ = srcpixel[3] * 257; + srcpixel += 4; + } + srcrow += srcstride; + dstrow += cbStride; + } + } + free(srcdata); + return hr; + } + + case format_32bppBGRA: + { + UINT srcstride, srcdatasize; + const BYTE *srcpixel; + const BYTE *srcrow; + WORD *dstpixel; + BYTE *srcdata; + BYTE *dstrow; + INT x, y; + + if (!prc) + return S_OK; + + srcstride = 4 * prc->Width; + srcdatasize = srcstride * prc->Height; + + srcdata = malloc(srcdatasize); + if (!srcdata) return E_OUTOFMEMORY; + + hr = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); + if (SUCCEEDED(hr)) + { + srcrow = srcdata; + dstrow = pbBuffer; + for (y = 0; y < prc->Height; y++) + { + srcpixel = srcrow; + dstpixel = (WORD *)dstrow; + for (x = 0; x < prc->Width; x++) + { + *dstpixel++ = srcpixel[2] * 257; + *dstpixel++ = srcpixel[1] * 257; + *dstpixel++ = srcpixel[0] * 257; + *dstpixel++ = srcpixel[3] * 257; + srcpixel += 4; + } + srcrow += srcstride; + dstrow += cbStride; + } + } + free(srcdata); + return hr; + } + default: FIXME("Unimplemented conversion path %d.\n", source_format); return WINCODEC_ERR_UNSUPPORTEDOPERATION; diff --git a/dlls/windowscodecs/tests/converter.c b/dlls/windowscodecs/tests/converter.c index bce0cbb189b..49d05e301ee 100644 --- a/dlls/windowscodecs/tests/converter.c +++ b/dlls/windowscodecs/tests/converter.c @@ -659,6 +659,26 @@ static const WORD bits_48bppRGB[] = { static const struct bitmap_data testdata_48bppRGB = { &GUID_WICPixelFormat48bppRGB, 48, (BYTE*)bits_48bppRGB, 3, 2, 96.0, 96.0}; +static const WORD bits_64bppRGBA_1[] = { + 0,0,0xffff,0xffff, 0,0xffff,0,0xffff, 0xffff,0,0,0xffff, 0,0,0,0xffff, + 0,0,0xffff,0xffff, 0,0xffff,0,0xffff, 0xffff,0,0,0xffff, 0,0,0,0xffff, + 0,0,0xffff,0xffff, 0,0xffff,0,0xffff, 0xffff,0,0,0xffff, 0,0,0,0xffff, + 0,0,0xffff,0xffff, 0,0xffff,0,0xffff, 0xffff,0,0,0xffff, 0,0,0,0xffff, + 0,0,0xffff,0xffff, 0,0xffff,0,0xffff, 0xffff,0,0,0xffff, 0,0,0,0xffff, + 0,0,0xffff,0xffff, 0,0xffff,0,0xffff, 0xffff,0,0,0xffff, 0,0,0,0xffff, + 0,0,0xffff,0xffff, 0,0xffff,0,0xffff, 0xffff,0,0,0xffff, 0,0,0,0xffff, + 0,0,0xffff,0xffff, 0,0xffff,0,0xffff, 0xffff,0,0,0xffff, 0,0,0,0xffff, + 0xffff,0xffff,0,0xffff, 0xffff,0,0xffff,0xffff, 0,0xffff,0xffff,0xffff, 0xffff,0xffff,0xffff,0xffff, + 0xffff,0xffff,0,0xffff, 0xffff,0,0xffff,0xffff, 0,0xffff,0xffff,0xffff, 0xffff,0xffff,0xffff,0xffff, + 0xffff,0xffff,0,0xffff, 0xffff,0,0xffff,0xffff, 0,0xffff,0xffff,0xffff, 0xffff,0xffff,0xffff,0xffff, + 0xffff,0xffff,0,0xffff, 0xffff,0,0xffff,0xffff, 0,0xffff,0xffff,0xffff, 0xffff,0xffff,0xffff,0xffff, + 0xffff,0xffff,0,0xffff, 0xffff,0,0xffff,0xffff, 0,0xffff,0xffff,0xffff, 0xffff,0xffff,0xffff,0xffff, + 0xffff,0xffff,0,0xffff, 0xffff,0,0xffff,0xffff, 0,0xffff,0xffff,0xffff, 0xffff,0xffff,0xffff,0xffff, + 0xffff,0xffff,0,0xffff, 0xffff,0,0xffff,0xffff, 0,0xffff,0xffff,0xffff, 0xffff,0xffff,0xffff,0xffff, + 0xffff,0xffff,0,0xffff, 0xffff,0,0xffff,0xffff, 0,0xffff,0xffff,0xffff, 0xffff,0xffff,0xffff,0xffff}; +static const struct bitmap_data testdata_64bppRGBA_1 = { + &GUID_WICPixelFormat64bppRGBA, 64, (BYTE*)bits_64bppRGBA_1, 32, 2, 96.0, 96.0}; + static const WORD bits_64bppRGBA_2[] = { 0,0,0,65535, 0,65535,0,65535, 32767,32768,32767,65535, 65535,65535,65535,65535, 10,10,10,65535, 0,0,10,65535,}; @@ -858,7 +878,7 @@ static void test_can_convert(void) {WIC_PIXEL_FORMAT(48bppRGB), TRUE, TRUE, 35}, {WIC_PIXEL_FORMAT(48bppBGR), TRUE, TRUE, 35, TRUE}, {WIC_PIXEL_FORMAT(64bppRGB), TRUE, TRUE, 35, TRUE}, - {WIC_PIXEL_FORMAT(64bppRGBA), TRUE, TRUE, 33}, + {WIC_PIXEL_FORMAT(64bppRGBA), TRUE, TRUE, 31}, {WIC_PIXEL_FORMAT(64bppBGRA), TRUE, TRUE, 35, TRUE}, {WIC_PIXEL_FORMAT(64bppPRGBA), TRUE, TRUE, 35}, {WIC_PIXEL_FORMAT(64bppPBGRA), TRUE, TRUE, 35, TRUE}, @@ -979,7 +999,7 @@ static void test_can_convert(void) } todo_wine_if (td[j].dst_todo_count == todo_count && todo_count != 0) - ok(todo_count == 0 || broken(todo_count == 35 || todo_count == 11 || todo_count == 4 || todo_count == 1), + ok(todo_count == 0 || broken(todo_count == 31 || todo_count == 11 || todo_count == 4 || todo_count == 1), "CanConvert missing %d expected source formats to destination format %s.\n", todo_count, td[j].name); } @@ -2349,6 +2369,7 @@ START_TEST(converter) test_conversion(&testdata_24bppRGB, &testdata_32bppBGR, "24bppRGB -> 32bppBGR", FALSE); test_conversion(&testdata_32bppBGRA, &testdata_24bppRGB, "32bppBGRA -> 24bppRGB", FALSE); test_conversion(&testdata_32bppRGBA, &testdata_24bppBGR, "32bppRGBA -> 24bppBGR", FALSE); + test_conversion(&testdata_32bppRGBA, &testdata_64bppRGBA_1, "32bppRGBA -> 64bppRGBA", FALSE); test_conversion(&testdata_32bppRGBA, &testdata_32bppBGRA, "32bppRGBA -> 32bppBGRA", FALSE); test_conversion(&testdata_32bppBGRA, &testdata_32bppRGBA, "32bppBGRA -> 32bppRGBA", FALSE); @@ -2364,6 +2385,7 @@ START_TEST(converter) test_conversion(&testdata_32bppGrayFloat, &testdata_24bppBGR_gray, "32bppGrayFloat -> 24bppBGR gray", FALSE); test_conversion(&testdata_32bppGrayFloat, &testdata_8bppGray, "32bppGrayFloat -> 8bppGray", FALSE); test_conversion(&testdata_32bppBGRA, &testdata_16bppBGRA5551, "32bppBGRA -> 16bppBGRA5551", FALSE); + test_conversion(&testdata_32bppBGRA, &testdata_64bppRGBA_1, "32bppBGRA -> 64bppRGBA", FALSE); test_conversion(&testdata_48bppRGB, &testdata_64bppRGBA_2, "48bppRGB -> 64bppRGBA", FALSE); test_conversion(&testdata_48bppRGB, &testdata_128bppRGBFloat, "48bppRGB -> 128bppRGBFloat", FALSE); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9803
From: Dmitry Timoshkov <dmitry@baikal.ru> Signed-off-by: Dmitry Timoshkov <dmitry@baikal.ru> --- dlls/windowscodecs/converter.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/dlls/windowscodecs/converter.c b/dlls/windowscodecs/converter.c index 0801d583d96..3ec4f6ef473 100644 --- a/dlls/windowscodecs/converter.c +++ b/dlls/windowscodecs/converter.c @@ -840,9 +840,9 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe BYTE *srcdata; UINT srcstride, srcdatasize; const BYTE *srcrow; - const BYTE *srcpixel; + const WORD *srcpixel; BYTE *dstrow; - DWORD *dstpixel; + BYTE *dstpixel; srcstride = 8 * prc->Width; srcdatasize = srcstride * prc->Height; @@ -857,15 +857,15 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe srcrow = srcdata; dstrow = pbBuffer; for (y=0; y<prc->Height; y++) { - srcpixel=srcrow; - dstpixel=(DWORD*)dstrow; + srcpixel=(const WORD *)srcrow; + dstpixel=dstrow; for (x=0; x<prc->Width; x++) { - BYTE red, green, blue, alpha; - srcpixel++; red = *srcpixel++; - srcpixel++; green = *srcpixel++; - srcpixel++; blue = *srcpixel++; - srcpixel++; alpha = *srcpixel++; - *dstpixel++=alpha<<24|red<<16|green<<8|blue; + dstpixel[2] = (srcpixel[0] + 127) / 257; + dstpixel[1] = (srcpixel[1] + 127) / 257; + dstpixel[0] = (srcpixel[2] + 127) / 257; + dstpixel[3] = (srcpixel[3] + 127) / 257; + srcpixel += 4; + dstpixel += 4; } srcrow += srcstride; dstrow += cbStride; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9803
This merge request was approved by Esme Povirk. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9803
participants (3)
-
Dmitry Timoshkov -
Dmitry Timoshkov (@dmitry) -
Esme Povirk (@madewokherd)