[1/5] windowscodecs: Add support for generating predefined black&white palette.

Dmitry Timoshkov dmitry at baikal.ru
Wed Jul 11 02:45:54 CDT 2012


---
 dlls/windowscodecs/palette.c       | 33 +++++++++++++++--
 dlls/windowscodecs/tests/palette.c | 73 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+), 3 deletions(-)

diff --git a/dlls/windowscodecs/palette.c b/dlls/windowscodecs/palette.c
index ec74d13..8941fb5 100644
--- a/dlls/windowscodecs/palette.c
+++ b/dlls/windowscodecs/palette.c
@@ -99,10 +99,37 @@ static ULONG WINAPI PaletteImpl_Release(IWICPalette *iface)
 }
 
 static HRESULT WINAPI PaletteImpl_InitializePredefined(IWICPalette *iface,
-    WICBitmapPaletteType ePaletteType, BOOL fAddTransparentColor)
+    WICBitmapPaletteType type, BOOL add_transparent)
 {
-    FIXME("(%p,%u,%i): stub\n", iface, ePaletteType, fAddTransparentColor);
-    return E_NOTIMPL;
+    PaletteImpl *This = impl_from_IWICPalette(iface);
+    WICColor *colors;
+    UINT count;
+
+    TRACE("(%p,%u,%d)\n", iface, type, add_transparent);
+
+    switch (type)
+    {
+    case WICBitmapPaletteTypeFixedBW:
+        count = 2;
+        colors = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WICColor));
+        if (!colors) return E_OUTOFMEMORY;
+        colors[0] = 0xff000000;
+        colors[1] = 0xffffffff;
+        break;
+
+    default:
+        FIXME("(%p,%u,%d): stub\n", iface, type, add_transparent);
+        return E_NOTIMPL;
+    }
+
+    EnterCriticalSection(&This->lock);
+    HeapFree(GetProcessHeap(), 0, This->colors);
+    This->colors = colors;
+    This->count = count;
+    This->type = type;
+    LeaveCriticalSection(&This->lock);
+
+    return S_OK;
 }
 
 static HRESULT WINAPI PaletteImpl_InitializeCustom(IWICPalette *iface,
diff --git a/dlls/windowscodecs/tests/palette.c b/dlls/windowscodecs/tests/palette.c
index ee9dfbc..abedc6f 100644
--- a/dlls/windowscodecs/tests/palette.c
+++ b/dlls/windowscodecs/tests/palette.c
@@ -148,11 +148,84 @@ static void test_custom_palette(void)
     IWICImagingFactory_Release(factory);
 }
 
+static void test_predefined_palette(void)
+{
+    static const struct test_data
+    {
+        WICBitmapPaletteType type;
+        BOOL is_bw, is_gray;
+        UINT count;
+        WICColor color[256];
+    } td[] =
+    {
+        { WICBitmapPaletteTypeFixedBW, 1, 1, 2, { 0xff000000, 0xffffffff } },
+    };
+    IWICImagingFactory *factory;
+    IWICPalette *palette;
+    HRESULT hr;
+    WICBitmapPaletteType type;
+    UINT count, i, ret;
+    BOOL bret;
+    WICColor color[256];
+
+    hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
+        &IID_IWICImagingFactory, (void**)&factory);
+    ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
+
+    for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
+    {
+        hr = IWICImagingFactory_CreatePalette(factory, &palette);
+        ok(hr == S_OK, "%u: CreatePalette error %#x\n", i, hr);
+
+        hr = IWICPalette_InitializePredefined(palette, td[i].type, FALSE);
+        ok(hr == S_OK, "%u: InitializePredefined error %#x\n", i, hr);
+
+        bret = -1;
+        hr = IWICPalette_IsBlackWhite(palette, &bret);
+        ok(hr == S_OK, "%u: IsBlackWhite error %#x\n", i, hr);
+        ok(bret == td[i].is_bw || broken(bret != td[i].is_bw), /* XP */
+           "%u: expected %d, got %d\n",i, td[i].is_bw, bret);
+
+        bret = -1;
+        hr = IWICPalette_IsGrayscale(palette, &bret);
+        ok(hr == S_OK, "%u: IsGrayscale error %#x\n", i, hr);
+        ok(bret == td[i].is_gray, "%u: expected %d, got %d\n", i, td[i].is_gray, bret);
+
+        type = -1;
+        hr = IWICPalette_GetType(palette, &type);
+        ok(hr == S_OK, "%u: GetType error %#x\n", i, hr);
+        ok(type == td[i].type, "%u: expected %#x, got %#x\n", i, td[i].type, type);
+
+        count = 0xdeadbeef;
+        hr = IWICPalette_GetColorCount(palette, &count);
+        ok(hr == S_OK, "%u: GetColorCount error %#x\n", i, hr);
+        ok(count == td[i].count, "%u: expected %u, got %u\n", i, td[i].count, count);
+
+        hr = IWICPalette_GetColors(palette, count, color, &ret);
+        ok(hr == S_OK, "%u: GetColors error %#x\n", i, hr);
+        ok(ret == count, "%u: expected %u, got %u\n", i, count, ret);
+        if (ret == td[i].count)
+        {
+            UINT j;
+            for (j = 0; j < count; j++)
+            {
+                ok(color[j] == td[i].color[j], "%u:[%u]: expected %#x, got %#x\n",
+                   i, j, td[i].color[j], color[j]);
+            }
+        }
+
+        IWICPalette_Release(palette);
+    }
+
+    IWICImagingFactory_Release(factory);
+}
+
 START_TEST(palette)
 {
     CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
 
     test_custom_palette();
+    test_predefined_palette();
 
     CoUninitialize();
 }
-- 
1.7.11.1




More information about the wine-patches mailing list