windowscodecs: Support InterlaceOption in PNG encoder.

Vincent Povirk madewokherd at gmail.com
Mon Jun 16 10:58:38 CDT 2014


For bug 34942.
-------------- next part --------------
From 0e86b3a305e0b4e0dd1f7dd6a9e0e7459cf440a1 Mon Sep 17 00:00:00 2001
From: Vincent Povirk <vincent at codeweavers.com>
Date: Wed, 28 May 2014 15:04:00 -0500
Subject: [PATCH] windowscodecs: Support InterlaceOption in PNG encoder.

---
 dlls/windowscodecs/pngformat.c | 40 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/dlls/windowscodecs/pngformat.c b/dlls/windowscodecs/pngformat.c
index 579989b..3e4ae58 100644
--- a/dlls/windowscodecs/pngformat.c
+++ b/dlls/windowscodecs/pngformat.c
@@ -41,6 +41,8 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
 
+static const WCHAR wszPngInterlaceOption[] = {'I','n','t','e','r','l','a','c','e','O','p','t','i','o','n',0};
+
 static HRESULT read_png_chunk(IStream *stream, BYTE *type, BYTE **data, ULONG *data_size)
 {
     BYTE header[8];
@@ -1060,6 +1062,7 @@ typedef struct PngEncoder {
     BOOL frame_committed;
     BOOL committed;
     CRITICAL_SECTION lock;
+    BOOL interlace;
 } PngEncoder;
 
 static inline PngEncoder *impl_from_IWICBitmapEncoder(IWICBitmapEncoder *iface)
@@ -1111,8 +1114,32 @@ static HRESULT WINAPI PngFrameEncode_Initialize(IWICBitmapFrameEncode *iface,
     IPropertyBag2 *pIEncoderOptions)
 {
     PngEncoder *This = impl_from_IWICBitmapFrameEncode(iface);
+    BOOL interlace;
+    PROPBAG2 opts[1]= {{0}};
+    VARIANT opt_values[1];
+    HRESULT opt_hres[1];
+    HRESULT hr;
+
     TRACE("(%p,%p)\n", iface, pIEncoderOptions);
 
+    opts[0].pstrName = (LPOLESTR)wszPngInterlaceOption;
+    opts[0].vt = VT_BOOL;
+
+    if (pIEncoderOptions)
+    {
+        hr = IPropertyBag2_Read(pIEncoderOptions, 1, opts, NULL, opt_values, opt_hres);
+
+        if (FAILED(hr))
+            return hr;
+    }
+    else
+        memset(opt_values, sizeof(opt_values), 0);
+
+    if (V_VT(&opt_values[0]) == VT_EMPTY)
+        interlace = FALSE;
+    else
+        interlace = (V_BOOL(&opt_values[0]) != 0);
+
     EnterCriticalSection(&This->lock);
 
     if (This->frame_initialized)
@@ -1121,6 +1148,8 @@ static HRESULT WINAPI PngFrameEncode_Initialize(IWICBitmapFrameEncode *iface,
         return WINCODEC_ERR_WRONGSTATE;
     }
 
+    This->interlace = interlace;
+
     This->frame_initialized = TRUE;
 
     LeaveCriticalSection(&This->lock);
@@ -1259,7 +1288,8 @@ static HRESULT WINAPI PngFrameEncode_WritePixels(IWICBitmapFrameEncode *iface,
     if (!This->info_written)
     {
         ppng_set_IHDR(This->png_ptr, This->info_ptr, This->width, This->height,
-            This->format->bit_depth, This->format->color_type, PNG_INTERLACE_NONE,
+            This->format->bit_depth, This->format->color_type,
+            This->interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE,
             PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
 
         if (This->xres != 0.0 && This->yres != 0.0)
@@ -1598,6 +1628,8 @@ static HRESULT WINAPI PngEncoder_CreateNewFrame(IWICBitmapEncoder *iface,
 {
     PngEncoder *This = impl_from_IWICBitmapEncoder(iface);
     HRESULT hr;
+    PROPBAG2 opts[1]= {{0}};
+
     TRACE("(%p,%p,%p)\n", iface, ppIFrameEncode, ppIEncoderOptions);
 
     EnterCriticalSection(&This->lock);
@@ -1614,7 +1646,11 @@ static HRESULT WINAPI PngEncoder_CreateNewFrame(IWICBitmapEncoder *iface,
         return WINCODEC_ERR_NOTINITIALIZED;
     }
 
-    hr = CreatePropertyBag2(NULL, 0, ppIEncoderOptions);
+    opts[0].pstrName = (LPOLESTR)wszPngInterlaceOption;
+    opts[0].vt = VT_BOOL;
+    opts[0].dwType = PROPBAG2_TYPE_DATA;
+
+    hr = CreatePropertyBag2(opts, 1, ppIEncoderOptions);
     if (FAILED(hr))
     {
         LeaveCriticalSection(&This->lock);
-- 
1.8.3.2



More information about the wine-patches mailing list