From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/windowscodecs/converter.c | 60 ++++++++++++++++++++++++++++ dlls/windowscodecs/tests/converter.c | 22 ++++++++-- 2 files changed, 78 insertions(+), 4 deletions(-)
diff --git a/dlls/windowscodecs/converter.c b/dlls/windowscodecs/converter.c index b5e253c98ea..b32478d948a 100644 --- a/dlls/windowscodecs/converter.c +++ b/dlls/windowscodecs/converter.c @@ -1038,6 +1038,17 @@ static HRESULT copypixels_to_32bppPRGBA(struct FormatConverter *This, const WICR } }
+static void set_24bppbgr_pixel(BYTE **dstpixel, WICColor color) +{ + BYTE *dst = *dstpixel; + + *dst++ = color; + *dst++ = color >> 8; + *dst++ = color >> 16; + + *dstpixel += 3; +} + static HRESULT copypixels_to_24bppBGR(struct FormatConverter *This, const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer, enum pixelformat source_format) { @@ -1045,6 +1056,55 @@ static HRESULT copypixels_to_24bppBGR(struct FormatConverter *This, const WICRec
switch (source_format) { + case format_BlackWhite: + if (prc) + { + static const WICColor colors[2] = { 0, 0xffffff }; + BYTE *srcdata, *dstpixel, *dstrow; + UINT srcstride, srcdatasize; + const BYTE *srcbyte; + const BYTE *srcrow; + HRESULT res; + INT x, y; + + srcstride = (prc->Width+7)/8; + 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++) { + srcbyte = srcrow; + dstpixel= dstrow; + for (x=0; x<prc->Width; x+=8) { + BYTE srcval; + srcval=*srcbyte++; + + set_24bppbgr_pixel(&dstpixel, colors[srcval>>7&1]); + if (x+1 < prc->Width) set_24bppbgr_pixel(&dstpixel, colors[srcval>>6&1]); + if (x+2 < prc->Width) set_24bppbgr_pixel(&dstpixel, colors[srcval>>5&1]); + if (x+3 < prc->Width) set_24bppbgr_pixel(&dstpixel, colors[srcval>>4&1]); + if (x+4 < prc->Width) set_24bppbgr_pixel(&dstpixel, colors[srcval>>3&1]); + if (x+5 < prc->Width) set_24bppbgr_pixel(&dstpixel, colors[srcval>>2&1]); + if (x+6 < prc->Width) set_24bppbgr_pixel(&dstpixel, colors[srcval>>1&1]); + if (x+7 < prc->Width) set_24bppbgr_pixel(&dstpixel, colors[srcval>>0&1]); + } + srcrow += srcstride; + dstrow += cbStride; + } + } + + free(srcdata); + + return res; + } + return S_OK; case format_24bppBGR: case format_24bppRGB: if (prc) diff --git a/dlls/windowscodecs/tests/converter.c b/dlls/windowscodecs/tests/converter.c index 24cc5a9fb5d..bd9a18122d4 100644 --- a/dlls/windowscodecs/tests/converter.c +++ b/dlls/windowscodecs/tests/converter.c @@ -433,6 +433,19 @@ static const BYTE bits_24bppBGR[] = { static const struct bitmap_data testdata_24bppBGR = { &GUID_WICPixelFormat24bppBGR, 24, bits_24bppBGR, 32, 2, 96.0, 96.0};
+static const BYTE bits_24bppBGR_BW[] = { + 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, + 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, + 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, + 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, + + 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0, + 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0, + 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0, + 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0, 255,255,255, 0,0,0}; +static const struct bitmap_data testdata_24bppBGR_BW = { + &GUID_WICPixelFormat24bppBGR, 24, bits_24bppBGR_BW, 32, 2, 96.0, 96.0}; + static const BYTE bits_24bppRGB[] = { 0,0,255, 0,255,0, 255,0,0, 0,0,0, 0,0,255, 0,255,0, 255,0,0, 0,0,0, 0,0,255, 0,255,0, 255,0,0, 0,0,0, 0,0,255, 0,255,0, 255,0,0, 0,0,0, @@ -725,11 +738,11 @@ static void test_can_convert(void) {WIC_PIXEL_FORMAT(1bppIndexed), TRUE, TRUE, 35}, {WIC_PIXEL_FORMAT(2bppIndexed), TRUE, TRUE, 35}, {WIC_PIXEL_FORMAT(4bppIndexed), TRUE, TRUE, 35}, - {WIC_PIXEL_FORMAT(8bppIndexed), TRUE, TRUE, 27}, + {WIC_PIXEL_FORMAT(8bppIndexed), TRUE, TRUE, 26}, {WIC_PIXEL_FORMAT(BlackWhite), TRUE, TRUE, 35}, {WIC_PIXEL_FORMAT(2bppGray), TRUE, TRUE, 35}, {WIC_PIXEL_FORMAT(4bppGray), TRUE, TRUE, 35}, - {WIC_PIXEL_FORMAT(8bppGray), TRUE, TRUE, 27}, + {WIC_PIXEL_FORMAT(8bppGray), TRUE, TRUE, 26}, {WIC_PIXEL_FORMAT(16bppGray), TRUE, TRUE, 35},
{WIC_PIXEL_FORMAT(8bppAlpha), TRUE, TRUE, 35, TRUE}, @@ -737,7 +750,7 @@ static void test_can_convert(void) {WIC_PIXEL_FORMAT(16bppBGR555), TRUE, TRUE, 35}, {WIC_PIXEL_FORMAT(16bppBGR565), TRUE, TRUE, 35}, {WIC_PIXEL_FORMAT(16bppBGRA5551), TRUE, TRUE, 33, TRUE}, - {WIC_PIXEL_FORMAT(24bppBGR), TRUE, TRUE, 28}, + {WIC_PIXEL_FORMAT(24bppBGR), TRUE, TRUE, 27}, {WIC_PIXEL_FORMAT(24bppRGB), TRUE, TRUE, 30}, {WIC_PIXEL_FORMAT(32bppBGR), TRUE, TRUE, 15}, {WIC_PIXEL_FORMAT(32bppBGRA), TRUE, TRUE, 15}, @@ -2216,7 +2229,8 @@ START_TEST(converter) test_conversion(&testdata_24bppRGB, &testdata_4bppIndexed, "24bppRGB -> 4bppIndexed", TRUE); test_conversion(&testdata_24bppRGB, &testdata_8bppIndexed, "24bppRGB -> 8bppIndexed", FALSE);
- test_conversion(&testdata_BlackWhite, &testdata_8bppIndexed_BW, "BlackWhite -> 8bppIndexed", TRUE); + test_conversion(&testdata_BlackWhite, &testdata_8bppIndexed_BW, "BlackWhite -> 8bppIndexed", FALSE); + test_conversion(&testdata_BlackWhite, &testdata_24bppBGR_BW, "BlackWhite -> 24bppBGR", FALSE); test_conversion(&testdata_1bppIndexed, &testdata_8bppIndexed_BW, "1bppIndexed -> 8bppIndexed", TRUE); test_conversion(&testdata_2bppIndexed, &testdata_8bppIndexed_4colors, "2bppIndexed -> 8bppIndexed", TRUE); test_conversion(&testdata_4bppIndexed, &testdata_8bppIndexed, "4bppIndexed -> 8bppIndexed", TRUE);