windowscodecs: Implement IWICPalette_InitializeFromPalette.
Dmitry Timoshkov
dmitry at baikal.ru
Sun Jul 29 22:31:01 CDT 2012
---
dlls/windowscodecs/palette.c | 31 ++++++++++++++++++--
dlls/windowscodecs/tests/palette.c | 60 +++++++++++++++++++++++++++++++++++++-
2 files changed, 87 insertions(+), 4 deletions(-)
diff --git a/dlls/windowscodecs/palette.c b/dlls/windowscodecs/palette.c
index f989c97..1ea909c 100644
--- a/dlls/windowscodecs/palette.c
+++ b/dlls/windowscodecs/palette.c
@@ -455,10 +455,35 @@ static HRESULT WINAPI PaletteImpl_InitializeFromBitmap(IWICPalette *iface,
}
static HRESULT WINAPI PaletteImpl_InitializeFromPalette(IWICPalette *iface,
- IWICPalette *pIPalette)
+ IWICPalette *source)
{
- FIXME("(%p,%p): stub\n", iface, pIPalette);
- return E_NOTIMPL;
+ PaletteImpl *This = impl_from_IWICPalette(iface);
+ UINT count;
+ WICColor *colors = NULL;
+ WICBitmapPaletteType type;
+ HRESULT hr;
+
+ TRACE("(%p,%p)\n", iface, source);
+
+ hr = IWICPalette_GetType(source, &type);
+ if (hr != S_OK) return hr;
+ hr = IWICPalette_GetColorCount(source, &count);
+ if (hr != S_OK) return hr;
+ if (count)
+ {
+ colors = HeapAlloc(GetProcessHeap(), 0, sizeof(WICColor) * count);
+ if (!colors) return E_OUTOFMEMORY;
+ hr = IWICPalette_GetColors(source, count, colors, &count);
+ if (hr != S_OK) return hr;
+ }
+
+ EnterCriticalSection(&This->lock);
+ This->colors = colors;
+ This->count = count;
+ This->type = type;
+ LeaveCriticalSection(&This->lock);
+
+ return S_OK;
}
static HRESULT WINAPI PaletteImpl_GetType(IWICPalette *iface,
diff --git a/dlls/windowscodecs/tests/palette.c b/dlls/windowscodecs/tests/palette.c
index 499d59d..ff5dc23 100644
--- a/dlls/windowscodecs/tests/palette.c
+++ b/dlls/windowscodecs/tests/palette.c
@@ -30,7 +30,7 @@
static void test_custom_palette(void)
{
IWICImagingFactory *factory;
- IWICPalette *palette;
+ IWICPalette *palette, *palette2;
HRESULT hr;
WICBitmapPaletteType type=0xffffffff;
UINT count=1;
@@ -106,6 +106,29 @@ static void test_custom_palette(void)
ok(SUCCEEDED(hr), "IsGrayscale failed, hr=%x\n", hr);
ok(!boolresult, "expected FALSE, got TRUE\n");
+ hr = IWICImagingFactory_CreatePalette(factory, &palette2);
+ ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
+
+ hr = IWICPalette_InitializeFromPalette(palette2, palette);
+ ok(SUCCEEDED(hr), "InitializeFromPalette failed, hr=%x\n", hr);
+
+ type = 0xdeadbeef;
+ hr = IWICPalette_GetType(palette2, &type);
+ ok(SUCCEEDED(hr), "GetType failed, hr=%x\n", hr);
+ ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %x\n", type);
+
+ count = 0xdeadbeef;
+ hr = IWICPalette_GetColorCount(palette2, &count);
+ ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
+ ok(count == 4, "expected 4, got %u\n", count);
+
+ memset(colors, 0, sizeof(colors));
+ count = 0xdeadbeef;
+ hr = IWICPalette_GetColors(palette2, 4, colors, &count);
+ ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr);
+ ok(count == 4, "expected 4, got %u\n", count);
+ ok(!memcmp(colors, initcolors, sizeof(colors)), "got unexpected palette data\n");
+
/* try a palette with some alpha in it */
colors[2] = 0x80ffffff;
hr = IWICPalette_InitializeCustom(palette, colors, 4);
@@ -119,6 +142,40 @@ static void test_custom_palette(void)
hr = IWICPalette_InitializeCustom(palette, NULL, 0);
ok(SUCCEEDED(hr), "InitializeCustom failed, hr=%x\n", hr);
+ type = 0xdeadbeef;
+ hr = IWICPalette_GetType(palette, &type);
+ ok(SUCCEEDED(hr), "GetType failed, hr=%x\n", hr);
+ ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %x\n", type);
+
+ count = 0xdeadbeef;
+ hr = IWICPalette_GetColorCount(palette, &count);
+ ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
+ ok(count == 0, "expected 0, got %u\n", count);
+
+ count = 0xdeadbeef;
+ hr = IWICPalette_GetColors(palette, 4, colors, &count);
+ ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr);
+ ok(count == 0, "expected 0, got %u\n", count);
+
+ hr = IWICPalette_InitializeFromPalette(palette2, palette);
+ ok(SUCCEEDED(hr), "InitializeFromPalette failed, hr=%x\n", hr);
+
+ type = 0xdeadbeef;
+ hr = IWICPalette_GetType(palette2, &type);
+ ok(SUCCEEDED(hr), "GetType failed, hr=%x\n", hr);
+ ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %x\n", type);
+
+ count = 0xdeadbeef;
+ hr = IWICPalette_GetColorCount(palette2, &count);
+ ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
+ ok(count == 0, "expected 0, got %u\n", count);
+
+ memset(colors, 0, sizeof(colors));
+ count = 0xdeadbeef;
+ hr = IWICPalette_GetColors(palette2, 4, colors, &count);
+ ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr);
+ ok(count == 0, "expected 0, got %u\n", count);
+
/* IWICPalette is paranoid about NULL pointers */
hr = IWICPalette_GetType(palette, NULL);
ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
@@ -144,6 +201,7 @@ static void test_custom_palette(void)
hr = IWICPalette_IsGrayscale(palette, NULL);
ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
+ IWICPalette_Release(palette2);
IWICPalette_Release(palette);
}
--
1.7.11.2
More information about the wine-patches
mailing list