From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/windowscodecs/converter.c | 43 ++++++++++++++++++++++++++++ dlls/windowscodecs/tests/converter.c | 7 +++++ 2 files changed, 50 insertions(+)
diff --git a/dlls/windowscodecs/converter.c b/dlls/windowscodecs/converter.c index 0bda7ab1ad0..eb45a8052c9 100644 --- a/dlls/windowscodecs/converter.c +++ b/dlls/windowscodecs/converter.c @@ -995,6 +995,49 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe return res; } return S_OK; + case format_16bppGrayHalf: + if (prc) + { + UINT srcstride, srcdatasize; + const USHORT *srcpixel; + const BYTE *srcrow; + DWORD *dstpixel; + BYTE *srcdata; + BYTE *dstrow; + HRESULT res; + INT x, y; + + srcstride = 2 * prc->Width; + srcdatasize = srcstride * prc->Height; + + srcdata = malloc(srcdatasize); + if (!srcdata) return E_OUTOFMEMORY; + + res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); + + if (SUCCEEDED(res)) + { + srcrow = srcdata; + dstrow = pbBuffer; + for (y = 0; y < prc->Height; y++) + { + srcpixel = (const USHORT *)srcrow; + dstpixel = (DWORD *)dstrow; + for (x = 0; x < prc->Width; x++) + { + BYTE comp = (BYTE)floorf(to_sRGB_component(float_16_to_32(*srcpixel++)) * 255.0f + 0.51f); + *dstpixel++ = 0xff000000 | comp << 16 | comp << 8 | comp; + } + srcrow += srcstride; + dstrow += cbStride; + } + } + + free(srcdata); + + return res; + } + return S_OK; case format_48bppRGBHalf: if (prc) { diff --git a/dlls/windowscodecs/tests/converter.c b/dlls/windowscodecs/tests/converter.c index 75fecfe1511..bce0cbb189b 100644 --- a/dlls/windowscodecs/tests/converter.c +++ b/dlls/windowscodecs/tests/converter.c @@ -684,6 +684,12 @@ static const BYTE bits_32bppBGRA_3[] = { static const struct bitmap_data testdata_32bppBGRA_3 = { &GUID_WICPixelFormat32bppBGRA, 32, bits_32bppBGRA_3, 3, 2, 96.0, 96.0};
+static const BYTE bits_32bppBGRA_4[] = { + 0,0,0,255, 255,255,255,255, 125,125,125,255, + 255,255,255,255, 125,125,125,255, 0,0,0,255}; +static const struct bitmap_data testdata_32bppBGRA_4 = { + &GUID_WICPixelFormat32bppBGRA, 32, bits_32bppBGRA_4, 3, 2, 96.0, 96.0}; + static const WORD bits_48bppRGBHalf[] = { 0,0,0, 0,0x3c00,0, 0x3c00,0,0, 0,0,0x3c00, 0,0x3290,0, 0x3290,0,0 }; @@ -2370,6 +2376,7 @@ START_TEST(converter) test_conversion(&testdata_48bppRGBHalf, &testdata_32bppBGRA_3, "48bppRGBHalf -> 32bppBGRA", FALSE); test_conversion(&testdata_48bppRGBHalf, &testdata_128bppRGBFloat_2, "48bppRGBHalf -> 128bppRGBFloat", FALSE);
+ test_conversion(&testdata_16bppGrayHalf, &testdata_32bppBGRA_4, "16bppGrayHalf -> 32bppBGRA", FALSE); test_conversion(&testdata_16bppGrayHalf, &testdata_128bppRGBFloat_3, "16bppGrayHalf -> 128bppRGBFloat", FALSE);
test_invalid_conversion();