From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/windowscodecs/converter.c | 45 ++++++++++++++++++++++++++++ dlls/windowscodecs/tests/converter.c | 15 +++++++++- 2 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/dlls/windowscodecs/converter.c b/dlls/windowscodecs/converter.c index 65936e6b30a..c66329168ca 100644 --- a/dlls/windowscodecs/converter.c +++ b/dlls/windowscodecs/converter.c @@ -1740,6 +1740,51 @@ static HRESULT copypixels_to_128bppRGBAFloat(struct FormatConverter *This, const free(srcdata); return S_OK; } + case format_32bppBGRA: + { + UINT srcstride, srcdatasize; + const BYTE *srcpixel; + const BYTE *srcrow; + float *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= (float *)dstrow; + for (x = 0; x < prc->Width; x++) + { + dstpixel[2] = from_sRGB_component(*srcpixel++ / 255.0f); + dstpixel[1] = from_sRGB_component(*srcpixel++ / 255.0f); + dstpixel[0] = from_sRGB_component(*srcpixel++ / 255.0f); + dstpixel[3] = *srcpixel++ / 255.0f; + + dstpixel += 4; + } + srcrow += srcstride; + dstrow += cbStride; + } + } + + free(srcdata); + return S_OK; + } 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 8122ba51ff5..527d6938a50 100644 --- a/dlls/windowscodecs/tests/converter.c +++ b/dlls/windowscodecs/tests/converter.c @@ -678,12 +678,24 @@ static const BYTE bits_24bppBGR_2[] = { static const struct bitmap_data testdata_24bppBGR_2 = { &GUID_WICPixelFormat24bppBGR, 24, bits_24bppBGR_2, 3, 2, 96.0, 96.0};
+static const BYTE bits_32bppBGRA_2[] = { + 0,0,0,0, 0,255,0,128, 0,0,255,255, + 255,0,0,0, 0,125,0,255, 0,0,125,128}; +static const struct bitmap_data testdata_32bppBGRA_2 = { + &GUID_WICPixelFormat32bppBGRA, 32, bits_32bppBGRA_2, 3, 2, 96.0, 96.0}; + static const float bits_128bppRGBAFloat[] = { 0.0f,0.0f,0.0f,1.0f, 0.0f,1.0f,0.0f,1.0f, 1.0f,0.0f,0.0f,1.0f, 0.0f,0.0f,1.0f,1.0f, 0.0f,0.205079f,0.0f,1.0f, 0.205079f,0.0f,0.0f,1.0f}; static const struct bitmap_data testdata_128bppRGBAFloat = { &GUID_WICPixelFormat128bppRGBAFloat, 128, (const BYTE *)bits_128bppRGBAFloat, 3, 2, 96.0, 96.0};
+static const float bits_128bppRGBAFloat_2[] = { + 0.0f,0.0f,0.0f,0.0f, 0.0f,1.0f,0.0f,0.501961f, 1.0f,0.0f,0.0f,1.0f, + 0.0f,0.0f,1.0f,0.0f, 0.0f,0.205079f,0.0f,1.0f, 0.205079f,0.0f,0.0f,0.5019f}; +static const struct bitmap_data testdata_128bppRGBAFloat_2 = { + &GUID_WICPixelFormat128bppRGBAFloat, 128, (const BYTE *)bits_128bppRGBAFloat_2, 3, 2, 96.0, 96.0}; + static void test_conversion(const struct bitmap_data *src, const struct bitmap_data *dst, const char *name, BOOL todo) { BitmapTestSrc *src_obj; @@ -809,7 +821,7 @@ static void test_can_convert(void) {WIC_PIXEL_FORMAT(48bppBGRFixedPoint)}, {WIC_PIXEL_FORMAT(96bppRGBFixedPoint)}, {WIC_PIXEL_FORMAT(96bppRGBFloat), TRUE, TRUE, 35, TRUE}, - {WIC_PIXEL_FORMAT(128bppRGBAFloat), TRUE, TRUE, 34}, + {WIC_PIXEL_FORMAT(128bppRGBAFloat), TRUE, TRUE, 33}, {WIC_PIXEL_FORMAT(128bppPRGBAFloat), TRUE, TRUE, 35}, {WIC_PIXEL_FORMAT(128bppRGBFloat), TRUE, TRUE, 34},
@@ -2320,6 +2332,7 @@ START_TEST(converter)
test_conversion(&testdata_48bppRGB, &testdata_128bppRGBFloat, "48bppRGB -> 128bppRGBFloat", FALSE); test_conversion(&testdata_24bppBGR_2, &testdata_128bppRGBAFloat, "24bppBGR -> 128bppRGBAFloat", FALSE); + test_conversion(&testdata_32bppBGRA_2, &testdata_128bppRGBAFloat_2, "32bppBGRA -> 128bppRGBAFloat", FALSE);
test_invalid_conversion(); test_default_converter();