From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/windowscodecs/converter.c | 47 ++++++++++++++++++++++++++++ dlls/windowscodecs/regsvr.c | 1 + dlls/windowscodecs/tests/converter.c | 14 +++++++++ 3 files changed, 62 insertions(+)
diff --git a/dlls/windowscodecs/converter.c b/dlls/windowscodecs/converter.c index 3607ac25819..2c7ec0dff5f 100644 --- a/dlls/windowscodecs/converter.c +++ b/dlls/windowscodecs/converter.c @@ -44,6 +44,7 @@ enum pixelformat { format_4bppGray, format_8bppGray, format_16bppGray, + format_16bppGrayHalf, format_16bppBGR555, format_16bppBGR565, format_16bppBGRA5551, @@ -2091,6 +2092,51 @@ static HRESULT copypixels_to_128bppRGBFloat(struct FormatConverter *This, const free(srcdata); return S_OK; } + case format_16bppGrayHalf: + { + UINT srcstride, srcdatasize; + const USHORT *srcpixel; + const BYTE *srcrow; + float *dstpixel; + BYTE *srcdata; + BYTE *dstrow; + INT x, y; + + if (!prc) + return S_OK; + + srcstride = 2 * 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 = (USHORT *)srcrow; + dstpixel= (float *)dstrow; + for (x = 0; x < prc->Width; x++) + { + float f32 = float_16_to_32(*srcpixel++); + + *dstpixel++ = f32; + *dstpixel++ = f32; + *dstpixel++ = f32; + *dstpixel++ = 1.0f; + } + srcrow += srcstride; + dstrow += cbStride; + } + } + + free(srcdata); + return S_OK; + }
default: FIXME("Unimplemented conversion path %d.\n", source_format); @@ -2108,6 +2154,7 @@ static const struct pixelformatinfo supported_formats[] = { {format_4bppGray, &GUID_WICPixelFormat4bppGray, NULL}, {format_8bppGray, &GUID_WICPixelFormat8bppGray, copypixels_to_8bppGray}, {format_16bppGray, &GUID_WICPixelFormat16bppGray, NULL}, + {format_16bppGrayHalf, &GUID_WICPixelFormat16bppGrayHalf}, {format_16bppBGR555, &GUID_WICPixelFormat16bppBGR555, NULL}, {format_16bppBGR565, &GUID_WICPixelFormat16bppBGR565, NULL}, {format_16bppBGRA5551, &GUID_WICPixelFormat16bppBGRA5551, copypixels_to_16bppBGRA5551}, diff --git a/dlls/windowscodecs/regsvr.c b/dlls/windowscodecs/regsvr.c index 191e1367c9c..d6c430e22ad 100644 --- a/dlls/windowscodecs/regsvr.c +++ b/dlls/windowscodecs/regsvr.c @@ -1668,6 +1668,7 @@ static GUID const * const converter_formats[] = { &GUID_WICPixelFormat4bppGray, &GUID_WICPixelFormat8bppGray, &GUID_WICPixelFormat16bppGray, + &GUID_WICPixelFormat16bppGrayHalf, &GUID_WICPixelFormat16bppBGR555, &GUID_WICPixelFormat16bppBGR565, &GUID_WICPixelFormat16bppBGRA5551, diff --git a/dlls/windowscodecs/tests/converter.c b/dlls/windowscodecs/tests/converter.c index a94ab9c0324..75fecfe1511 100644 --- a/dlls/windowscodecs/tests/converter.c +++ b/dlls/windowscodecs/tests/converter.c @@ -690,6 +690,12 @@ static const WORD bits_48bppRGBHalf[] = { static const struct bitmap_data testdata_48bppRGBHalf = { &GUID_WICPixelFormat48bppRGBHalf, 48, (const BYTE *)bits_48bppRGBHalf, 3, 2, 96.0, 96.0};
+static const WORD bits_16bppGrayHalf[] = { + 0, 0x3c00, 0x3290, + 0x3c00, 0x3290, 0 }; +static const struct bitmap_data testdata_16bppGrayHalf = { + &GUID_WICPixelFormat16bppGrayHalf, 16, (const BYTE *)bits_16bppGrayHalf, 3, 2, 96.0, 96.0}; + static const float bits_128bppRGBFloat[] = { 0.0f,0.0f,0.0f,1.0f, 0.0f,1.0f,0.0f,1.0f, 0.214039f,0.214053f,0.214039f,1.0f, 1.0f,1.0f,1.0f,1.0f, 0.000012f,0.000012f,0.000012f,1.0f, 0.0f,0.0f,0.000012f,1.0f,}; @@ -702,6 +708,12 @@ static const float bits_128bppRGBFloat_2[] = { static const struct bitmap_data testdata_128bppRGBFloat_2 = { &GUID_WICPixelFormat128bppRGBFloat, 128, (const BYTE *)bits_128bppRGBFloat_2, 3, 2, 96.0, 96.0};
+static const float bits_128bppRGBFloat_3[] = { + 0.0f,0.0f,0.0f,1.0f, 1.0f,1.0f,1.0f,1.0f, 0.205079f,0.205079f,0.205079f,1.0f, + 1.0f,1.0f,1.0f,1.0f, 0.205079f,0.205079f,0.205079f,1.0f, 0.0f,0.0f,0.0f,1.0f}; +static const struct bitmap_data testdata_128bppRGBFloat_3 = { + &GUID_WICPixelFormat128bppRGBFloat, 128, (const BYTE *)bits_128bppRGBFloat_3, 3, 2, 96.0, 96.0}; + static const BYTE bits_24bppBGR_2[] = { 0,0,0, 0,255,0, 0,0,255, 255,0,0, 0,125,0, 0,0,125}; @@ -2358,6 +2370,8 @@ 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_128bppRGBFloat_3, "16bppGrayHalf -> 128bppRGBFloat", FALSE); + test_invalid_conversion(); test_default_converter(); test_can_convert();