Dmitry Timoshkov : gdiplus: Retrieve image palette from WIC.
Alexandre Julliard
julliard at winehq.org
Wed Jul 25 16:06:54 CDT 2012
Module: wine
Branch: master
Commit: dce93479ea26c3317a362be93d9f523b9b563e83
URL: http://source.winehq.org/git/wine.git/?a=commit;h=dce93479ea26c3317a362be93d9f523b9b563e83
Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date: Wed Jul 18 17:24:58 2012 +0900
gdiplus: Retrieve image palette from WIC.
---
dlls/gdiplus/image.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c
index a5b560d..111bafd 100644
--- a/dlls/gdiplus/image.c
+++ b/dlls/gdiplus/image.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2007 Google (Evan Stade)
+ * Copyright (C) 2012 Dmitry Timoshkov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -41,6 +42,46 @@ WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
#define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
+static ColorPalette *get_palette(IWICBitmapFrameDecode *frame)
+{
+ HRESULT hr;
+ IWICImagingFactory *factory;
+ IWICPalette *wic_palette;
+ ColorPalette *palette = NULL;
+
+ hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
+ &IID_IWICImagingFactory, (void **)&factory);
+ if (hr != S_OK) return NULL;
+
+ hr = IWICImagingFactory_CreatePalette(factory, &wic_palette);
+ if (hr == S_OK)
+ {
+ hr = IWICBitmapFrameDecode_CopyPalette(frame, wic_palette);
+ if (hr == S_OK)
+ {
+ UINT count;
+ BOOL mono, gray;
+
+ IWICPalette_IsBlackWhite(wic_palette, &mono);
+ IWICPalette_IsGrayscale(wic_palette, &gray);
+
+ IWICPalette_GetColorCount(wic_palette, &count);
+ palette = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(UINT) + count * sizeof(ARGB));
+ IWICPalette_GetColors(wic_palette, count, palette->Entries, &palette->Count);
+
+ if (mono)
+ palette->Flags = 0;
+ else if (gray)
+ palette->Flags = PaletteFlagsGrayScale;
+ else
+ palette->Flags = PaletteFlagsHalftone;
+ }
+ IWICPalette_Release(wic_palette);
+ }
+ IWICImagingFactory_Release(factory);
+ return palette;
+}
+
static INT ipicture_pixel_height(IPicture *pic)
{
HDC hdcref;
@@ -2994,6 +3035,7 @@ static GpStatus decode_image_wic(IStream* stream, REFCLSID clsid, UINT active_fr
IWICMetadataBlockReader *block_reader;
WICPixelFormatGUID wic_format;
PixelFormat gdip_format=0;
+ ColorPalette *palette = NULL;
int i;
UINT width, height, frame_count;
BitmapData lockeddata;
@@ -3102,6 +3144,7 @@ static GpStatus decode_image_wic(IStream* stream, REFCLSID clsid, UINT active_fr
IWICMetadataBlockReader_Release(block_reader);
}
+ palette = get_palette(frame);
IWICBitmapFrameDecode_Release(frame);
}
@@ -3119,8 +3162,16 @@ end:
bitmap->image.frame_count = frame_count;
bitmap->image.current_frame = active_frame;
bitmap->image.stream = stream;
- if (IsEqualGUID(&wic_format, &GUID_WICPixelFormatBlackWhite))
- bitmap->image.palette->Flags = 0;
+ if (palette)
+ {
+ GdipFree(bitmap->image.palette);
+ bitmap->image.palette = palette;
+ }
+ else
+ {
+ if (IsEqualGUID(&wic_format, &GUID_WICPixelFormatBlackWhite))
+ bitmap->image.palette->Flags = 0;
+ }
/* Pin the source stream */
IStream_AddRef(stream);
}
More information about the wine-cvs
mailing list