windowscodecs: Only copy the palette to new bitmaps if they might be indexed.

Vincent Povirk madewokherd at gmail.com
Mon Sep 10 17:13:02 CDT 2012


-------------- next part --------------
From 59fbab380869b2efdacdffe27fc1f6a3340b4a51 Mon Sep 17 00:00:00 2001
From: Vincent Povirk <vincent at codeweavers.com>
Date: Mon, 10 Sep 2012 15:23:43 -0500
Subject: [PATCH 1/2] windowscodecs: Only copy the palette to new bitmaps if
 they might be indexed.

---
 dlls/windowscodecs/imgfactory.c   |   23 +++++++++++++++-
 dlls/windowscodecs/tests/bitmap.c |   53 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/dlls/windowscodecs/imgfactory.c b/dlls/windowscodecs/imgfactory.c
index 01ce034..8ba0a1d 100644
--- a/dlls/windowscodecs/imgfactory.c
+++ b/dlls/windowscodecs/imgfactory.c
@@ -474,6 +474,9 @@ static HRESULT WINAPI ComponentFactory_CreateBitmapFromSource(IWICComponentFacto
     HRESULT hr;
     WICRect rc;
     double dpix, dpiy;
+    IWICComponentInfo *info;
+    IWICPixelFormatInfo2 *formatinfo;
+    WICPixelFormatNumericRepresentation format_type;
 
     TRACE("(%p,%p,%u,%p)\n", iface, piBitmapSource, option, ppIBitmap);
 
@@ -486,6 +489,23 @@ static HRESULT WINAPI ComponentFactory_CreateBitmapFromSource(IWICComponentFacto
         hr = IWICBitmapSource_GetPixelFormat(piBitmapSource, &pixelformat);
 
     if (SUCCEEDED(hr))
+        hr = CreateComponentInfo(&pixelformat, &info);
+
+    if (SUCCEEDED(hr))
+    {
+        hr = IWICComponentInfo_QueryInterface(info, &IID_IWICPixelFormatInfo2, (void**)&formatinfo);
+
+        if (SUCCEEDED(hr))
+        {
+            hr = IWICPixelFormatInfo2_GetNumericRepresentation(formatinfo, &format_type);
+
+            IWICPixelFormatInfo2_Release(formatinfo);
+        }
+
+        IWICComponentInfo_Release(info);
+    }
+
+    if (SUCCEEDED(hr))
         hr = BitmapImpl_Create(width, height, &pixelformat, option, &result);
 
     if (SUCCEEDED(hr))
@@ -514,7 +534,8 @@ static HRESULT WINAPI ComponentFactory_CreateBitmapFromSource(IWICComponentFacto
         if (SUCCEEDED(hr))
             hr = PaletteImpl_Create(&palette);
 
-        if (SUCCEEDED(hr))
+        if (SUCCEEDED(hr) && (format_type == WICPixelFormatNumericRepresentationUnspecified ||
+                              format_type == WICPixelFormatNumericRepresentationIndexed))
         {
             hr = IWICBitmapSource_CopyPalette(piBitmapSource, palette);
 
diff --git a/dlls/windowscodecs/tests/bitmap.c b/dlls/windowscodecs/tests/bitmap.c
index 91376ac..c2ce1aa 100644
--- a/dlls/windowscodecs/tests/bitmap.c
+++ b/dlls/windowscodecs/tests/bitmap.c
@@ -283,6 +283,8 @@ static void test_createbitmapfromsource(void)
     WICPixelFormatGUID pixelformat = {0};
     UINT width=0, height=0;
     double dpix=10.0, dpiy=10.0;
+    UINT count;
+    WICBitmapPaletteType palette_type;
 
     hr = IWICImagingFactory_CreateBitmap(factory, 3, 3, &GUID_WICPixelFormat24bppBGR,
         WICBitmapCacheOnLoad, &bitmap);
@@ -340,7 +342,7 @@ static void test_createbitmapfromsource(void)
 
     /* palette isn't copied for non-indexed formats? */
     hr = IWICBitmap_CopyPalette(bitmap2, palette);
-    todo_wine ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "IWICBitmap_CopyPalette failed hr=%x\n", hr);
+    ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "IWICBitmap_CopyPalette failed hr=%x\n", hr);
 
     IWICPalette_Release(palette);
 
@@ -365,6 +367,55 @@ static void test_createbitmapfromsource(void)
     ok(height == 3, "got %d, expected 3\n", height);
 
     IWICBitmap_Release(bitmap2);
+
+    /* Ensure palette is copied for indexed formats */
+    hr = IWICImagingFactory_CreateBitmap(factory, 3, 3, &GUID_WICPixelFormat4bppIndexed,
+        WICBitmapCacheOnLoad, &bitmap);
+    ok(hr == S_OK, "IWICImagingFactory_CreateBitmap failed hr=%x\n", hr);
+
+    hr = IWICImagingFactory_CreatePalette(factory, &palette);
+    ok(hr == S_OK, "IWICImagingFactory_CreatePalette failed hr=%x\n", hr);
+
+    hr = IWICPalette_InitializePredefined(palette, WICBitmapPaletteTypeFixedGray256, FALSE);
+    ok(hr == S_OK, "IWICPalette_InitializePredefined failed hr=%x\n", hr);
+
+    hr = IWICBitmap_SetPalette(bitmap, palette);
+    ok(hr == S_OK, "IWICBitmap_SetPalette failed hr=%x\n", hr);
+
+    IWICPalette_Release(palette);
+
+    hr = IWICImagingFactory_CreateBitmapFromSource(factory, (IWICBitmapSource*)bitmap,
+        WICBitmapCacheOnLoad, &bitmap2);
+    ok(hr == S_OK, "IWICImagingFactory_CreateBitmapFromSource failed hr=%x\n", hr);
+
+    IWICBitmap_Release(bitmap);
+
+    hr = IWICImagingFactory_CreatePalette(factory, &palette);
+    ok(hr == S_OK, "IWICImagingFactory_CreatePalette failed hr=%x\n", hr);
+
+    hr = IWICBitmap_CopyPalette(bitmap2, palette);
+    ok(hr == S_OK, "IWICBitmap_CopyPalette failed hr=%x\n", hr);
+
+    hr = IWICPalette_GetColorCount(palette, &count);
+    ok(hr == S_OK, "IWICPalette_GetColorCount failed hr=%x\n", hr);
+    ok(count == 256, "unexpected count %d\n", count);
+
+    hr = IWICPalette_GetType(palette, &palette_type);
+    ok(hr == S_OK, "IWICPalette_GetType failed hr=%x\n", hr);
+    ok(palette_type == WICBitmapPaletteTypeFixedGray256, "unexpected palette type %d\n", palette_type);
+
+    IWICPalette_Release(palette);
+
+    hr = IWICBitmap_GetPixelFormat(bitmap2, &pixelformat);
+    ok(hr == S_OK, "IWICBitmap_GetPixelFormat failed hr=%x\n", hr);
+    ok(IsEqualGUID(&pixelformat, &GUID_WICPixelFormat4bppIndexed), "unexpected pixel format\n");
+
+    hr = IWICBitmap_GetSize(bitmap2, &width, &height);
+    ok(hr == S_OK, "IWICBitmap_GetSize failed hr=%x\n", hr);
+    ok(width == 3, "got %d, expected 3\n", width);
+    ok(height == 3, "got %d, expected 3\n", height);
+
+    IWICBitmap_Release(bitmap2);
 }
 
 START_TEST(bitmap)
-- 
1.7.9.5


More information about the wine-patches mailing list