Rebase against 6b76648a8b773838ecde00719ca54a433edf5ce6

This commit is contained in:
Alistair Leslie-Hughes
2019-02-06 14:27:30 +11:00
parent 1edb7d5bc5
commit 3dab9e5e6b
7 changed files with 11 additions and 893 deletions

View File

@@ -1,28 +0,0 @@
From 8d2a6325a891a2fab8bf7c091cb8fb73468ae1ea Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Thu, 20 Oct 2016 16:57:51 +0800
Subject: windowscodecs: WICConvertBitmapSource should ask
IWICFormatConverter::Initialize to use an optimized palette.
This matches Windows' behaviour, and makes a simple test application that converts
any WIC compatible RGB(A) source image to 8bppIndexed format (GIF for instance) work.
---
dlls/windowscodecs/info.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/windowscodecs/info.c b/dlls/windowscodecs/info.c
index 1a93491..c1e8a66 100644
--- a/dlls/windowscodecs/info.c
+++ b/dlls/windowscodecs/info.c
@@ -2336,7 +2336,7 @@ HRESULT WINAPI WICConvertBitmapSource(REFWICPixelFormatGUID dstFormat, IWICBitma
if (SUCCEEDED(res) && canconvert)
res = IWICFormatConverter_Initialize(converter, pISrc, dstFormat, WICBitmapDitherTypeNone,
- NULL, 0.0, WICBitmapPaletteTypeCustom);
+ NULL, 0.0, WICBitmapPaletteTypeMedianCut);
if (FAILED(res) || !canconvert)
{
--
2.9.0

View File

@@ -1,100 +0,0 @@
From 9ddafc9d2cd0fc899e513807a34ef4e875851fca Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Thu, 27 Oct 2016 14:55:03 +0800
Subject: windowscodecs: Fix behaviour of format converter for indexed formats
when NULL or empty palette has been provided.
---
dlls/windowscodecs/converter.c | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/dlls/windowscodecs/converter.c b/dlls/windowscodecs/converter.c
index c6a2514..4ee980e 100644
--- a/dlls/windowscodecs/converter.c
+++ b/dlls/windowscodecs/converter.c
@@ -1240,7 +1240,6 @@ static HRESULT copypixels_to_8bppIndexed(struct FormatConverter *This, const WIC
hr = IWICPalette_GetColors(This->palette, 256, colors, &count);
if (hr != S_OK) return hr;
- if (!count) return WINCODEC_ERR_WRONGSTATE;
srcstride = 3 * prc->Width;
srcdatasize = srcstride * prc->Height;
@@ -1409,7 +1408,18 @@ static HRESULT WINAPI FormatConverter_CopyPalette(IWICFormatConverter *iface,
TRACE("(%p,%p)\n", iface, palette);
if (!palette) return E_INVALIDARG;
- if (!This->palette) return WINCODEC_ERR_WRONGSTATE;
+ if (!This->source) return WINCODEC_ERR_WRONGSTATE;
+
+ if (!This->palette)
+ {
+ HRESULT hr;
+ UINT bpp;
+
+ hr = get_pixelformat_bpp(This->dst_format->guid, &bpp);
+ if (hr != S_OK) return hr;
+ if (bpp <= 8) return WINCODEC_ERR_WRONGSTATE;
+ return IWICBitmapSource_CopyPalette(This->source, palette);
+ }
return IWICPalette_InitializeFromPalette(palette, This->palette);
}
@@ -1440,7 +1450,7 @@ static HRESULT WINAPI FormatConverter_CopyPixels(IWICFormatConverter *iface,
pbBuffer, This->src_format->format);
}
else
- return WINCODEC_ERR_NOTINITIALIZED;
+ return WINCODEC_ERR_WRONGSTATE;
}
static HRESULT WINAPI FormatConverter_Initialize(IWICFormatConverter *iface,
@@ -1457,6 +1467,10 @@ static HRESULT WINAPI FormatConverter_Initialize(IWICFormatConverter *iface,
if (!palette)
{
+ UINT bpp;
+ res = get_pixelformat_bpp(dstFormat, &bpp);
+ if (res != S_OK) return res;
+
res = PaletteImpl_Create(&palette);
if (res != S_OK) return res;
@@ -1465,20 +1479,19 @@ static HRESULT WINAPI FormatConverter_Initialize(IWICFormatConverter *iface,
case WICBitmapPaletteTypeCustom:
IWICPalette_Release(palette);
palette = NULL;
- res = S_OK;
+ if (bpp <= 8) return E_INVALIDARG;
break;
case WICBitmapPaletteTypeMedianCut:
{
- UINT bpp;
- res = get_pixelformat_bpp(dstFormat, &bpp);
- if (res == S_OK && bpp <= 8)
+ if (bpp <= 8)
res = IWICPalette_InitializeFromBitmap(palette, source, 1 << bpp, FALSE);
break;
}
default:
- res = IWICPalette_InitializePredefined(palette, palette_type, FALSE);
+ if (bpp <= 8)
+ res = IWICPalette_InitializePredefined(palette, palette_type, FALSE);
break;
}
@@ -1538,6 +1551,9 @@ end:
LeaveCriticalSection(&This->lock);
+ if (res != S_OK && palette)
+ IWICPalette_Release(palette);
+
return res;
}
--
2.9.0

View File

@@ -1,189 +0,0 @@
From e27b9d2889f424ecffabc57e449e995fab80274f Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Thu, 27 Oct 2016 15:13:24 +0800
Subject: [PATCH] windowscodecs/tests: Add some tests for converting
24bppBGR to 8bppIndexed format.
---
dlls/windowscodecs/tests/converter.c | 158 +++++++++++++++++++++++++++++++++++
1 file changed, 158 insertions(+)
diff --git a/dlls/windowscodecs/tests/converter.c b/dlls/windowscodecs/tests/converter.c
index 4eea13b..089926b 100644
--- a/dlls/windowscodecs/tests/converter.c
+++ b/dlls/windowscodecs/tests/converter.c
@@ -1468,6 +1468,163 @@ static const struct setting png_interlace_settings[] = {
{NULL}
};
+static void test_converter_8bppIndexed(void)
+{
+ HRESULT hr;
+ BitmapTestSrc *src_obj;
+ IWICFormatConverter *converter;
+ IWICPalette *palette;
+ UINT count, i;
+ BYTE buf[32 * 2 * 3]; /* enough to hold 32x2 24bppBGR data */
+
+ CreateTestBitmap(&testdata_24bppBGR, &src_obj);
+
+ hr = IWICImagingFactory_CreatePalette(factory, &palette);
+ ok(hr == S_OK, "CreatePalette error %#x\n", hr);
+ count = 0xdeadbeef;
+ hr = IWICPalette_GetColorCount(palette, &count);
+ ok(hr == S_OK, "GetColorCount error %#x\n", hr);
+ ok(count == 0, "expected 0, got %u\n", count);
+
+ /* NULL palette + Custom type*/
+ hr = IWICImagingFactory_CreateFormatConverter(factory, &converter);
+ ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr);
+ hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface,
+ &GUID_WICPixelFormat24bppBGR, WICBitmapDitherTypeNone,
+ NULL, 0.0, WICBitmapPaletteTypeCustom);
+ ok(hr == S_OK, "Initialize error %#x\n", hr);
+ hr = IWICFormatConverter_CopyPalette(converter, palette);
+ ok(hr == 0xdeadbeef, "unexpected error %#x\n", hr);
+ hr = IWICFormatConverter_CopyPixels(converter, NULL, 32 * 3, sizeof(buf), buf);
+ ok(hr == S_OK, "CopyPixels error %#x\n", hr);
+ IWICFormatConverter_Release(converter);
+
+ /* NULL palette + Custom type*/
+ hr = IWICImagingFactory_CreateFormatConverter(factory, &converter);
+ ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr);
+ hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface,
+ &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone,
+ NULL, 0.0, WICBitmapPaletteTypeCustom);
+ ok(hr == E_INVALIDARG, "unexpected error %#x\n", hr);
+ hr = IWICFormatConverter_CopyPalette(converter, palette);
+ ok(hr == WINCODEC_ERR_WRONGSTATE, "unexpected error %#x\n", hr);
+ hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf);
+ ok(hr == WINCODEC_ERR_WRONGSTATE, "unexpected error %#x\n", hr);
+ IWICFormatConverter_Release(converter);
+
+ /* empty palette + Custom type*/
+ hr = IWICImagingFactory_CreateFormatConverter(factory, &converter);
+ ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr);
+ hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface,
+ &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone,
+ palette, 0.0, WICBitmapPaletteTypeCustom);
+ ok(hr == S_OK, "Initialize error %#x\n", hr);
+ hr = IWICFormatConverter_CopyPalette(converter, palette);
+ ok(hr == S_OK, "CopyPalette error %#x\n", hr);
+ count = 0xdeadbeef;
+ hr = IWICPalette_GetColorCount(palette, &count);
+ ok(hr == S_OK, "GetColorCount error %#x\n", hr);
+ ok(count == 0, "expected 0, got %u\n", count);
+ memset(buf, 0xaa, sizeof(buf));
+ hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf);
+ ok(hr == S_OK, "CopyPixels error %#x\n", hr);
+ count = 0;
+ for (i = 0; i < 32 * 2; i++)
+ if (buf[i] != 0) count++;
+ ok(count == 0, "expected 0\n");
+ IWICFormatConverter_Release(converter);
+
+ /* NULL palette + Predefined type*/
+ hr = IWICImagingFactory_CreateFormatConverter(factory, &converter);
+ ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr);
+ hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface,
+ &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone,
+ NULL, 0.0, WICBitmapPaletteTypeFixedGray16);
+ ok(hr == S_OK, "Initialize error %#x\n", hr);
+ hr = IWICFormatConverter_CopyPalette(converter, palette);
+ ok(hr == S_OK, "CopyPalette error %#x\n", hr);
+ count = 0xdeadbeef;
+ hr = IWICPalette_GetColorCount(palette, &count);
+ ok(hr == S_OK, "GetColorCount error %#x\n", hr);
+ ok(count == 16, "expected 16, got %u\n", count);
+ hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf);
+ ok(hr == S_OK, "CopyPixels error %#x\n", hr);
+ count = 0;
+ for (i = 0; i < 32 * 2; i++)
+ if (buf[i] != 0) count++;
+ ok(count != 0, "expected != 0\n");
+ IWICFormatConverter_Release(converter);
+
+ /* not empty palette + Predefined type*/
+ hr = IWICImagingFactory_CreateFormatConverter(factory, &converter);
+ ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr);
+ hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface,
+ &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone,
+ palette, 0.0, WICBitmapPaletteTypeFixedHalftone64);
+ ok(hr == S_OK, "Initialize error %#x\n", hr);
+ hr = IWICFormatConverter_CopyPalette(converter, palette);
+ ok(hr == S_OK, "CopyPalette error %#x\n", hr);
+ count = 0xdeadbeef;
+ hr = IWICPalette_GetColorCount(palette, &count);
+ ok(hr == S_OK, "GetColorCount error %#x\n", hr);
+ ok(count == 16, "expected 16, got %u\n", count);
+ hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf);
+ ok(hr == S_OK, "CopyPixels error %#x\n", hr);
+ count = 0;
+ for (i = 0; i < 32 * 2; i++)
+ if (buf[i] != 0) count++;
+ ok(count != 0, "expected != 0\n");
+ IWICFormatConverter_Release(converter);
+
+ /* not empty palette + MedianCut type*/
+ hr = IWICImagingFactory_CreateFormatConverter(factory, &converter);
+ ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr);
+ hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface,
+ &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone,
+ palette, 0.0, WICBitmapPaletteTypeMedianCut);
+ ok(hr == S_OK, "Initialize error %#x\n", hr);
+ hr = IWICFormatConverter_CopyPalette(converter, palette);
+ ok(hr == S_OK, "CopyPalette error %#x\n", hr);
+ count = 0xdeadbeef;
+ hr = IWICPalette_GetColorCount(palette, &count);
+ ok(hr == S_OK, "GetColorCount error %#x\n", hr);
+ ok(count == 16, "expected 16, got %u\n", count);
+ hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf);
+ ok(hr == S_OK, "CopyPixels error %#x\n", hr);
+ count = 0;
+ for (i = 0; i < 32 * 2; i++)
+ if (buf[i] != 0) count++;
+ ok(count != 0, "expected != 0\n");
+ IWICFormatConverter_Release(converter);
+
+ /* NULL palette + MedianCut type*/
+ hr = IWICImagingFactory_CreateFormatConverter(factory, &converter);
+ ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr);
+ hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface,
+ &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone,
+ NULL, 0.0, WICBitmapPaletteTypeMedianCut);
+ ok(hr == S_OK || broken(hr == E_INVALIDARG) /* XP */, "Initialize error %#x\n", hr);
+ if (hr == S_OK)
+ {
+ hr = IWICFormatConverter_CopyPalette(converter, palette);
+ ok(hr == S_OK, "CopyPalette error %#x\n", hr);
+ count = 0xdeadbeef;
+ hr = IWICPalette_GetColorCount(palette, &count);
+ ok(hr == S_OK, "GetColorCount error %#x\n", hr);
+ ok(count == 8, "expected 8, got %u\n", count);
+ hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf);
+ ok(hr == S_OK, "CopyPixels error %#x\n", hr);
+ count = 0;
+ for (i = 0; i < 32 * 2; i++)
+ if (buf[i] != 0) count++;
+ ok(count != 0, "expected != 0\n");
+ }
+ IWICFormatConverter_Release(converter);
+
+ IWICPalette_Release(palette);
+ DeleteTestBitmap(src_obj);
+}
+
START_TEST(converter)
{
HRESULT hr;
@@ -1502,6 +1659,7 @@ START_TEST(converter)
test_invalid_conversion();
test_default_converter();
+ test_converter_8bppIndexed();
test_encoder(&testdata_BlackWhite, &CLSID_WICPngEncoder,
&testdata_BlackWhite, &CLSID_WICPngDecoder, "PNG encoder BlackWhite");
--
1.9.1

View File

@@ -1,25 +0,0 @@
From 18eb6add9eac40d84a809d75d340600e44cc1dae Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Sun, 6 Nov 2016 16:25:12 +0800
Subject: windowscodecs/tests: Add a missing check for
IWICBitmapFrameDecode::GetPixelFormat return value.
---
dlls/windowscodecs/tests/converter.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/dlls/windowscodecs/tests/converter.c b/dlls/windowscodecs/tests/converter.c
index 430c0ed..6d782f3 100644
--- a/dlls/windowscodecs/tests/converter.c
+++ b/dlls/windowscodecs/tests/converter.c
@@ -1311,6 +1311,7 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls
if (SUCCEEDED(hr))
{
hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &pixelformat);
+ ok(hr == S_OK, "GetPixelFormat) failed, hr=%x (%s)\n", hr, name);
if (IsEqualGUID(&pixelformat, dsts[i]->format))
compare_bitmap_data(srcs[i], dsts[i], (IWICBitmapSource*)framedecode, name);
--
2.9.0