Bryon Roche : windowscodecs: Byte swap png read/write for 16-bpp data.

Alexandre Julliard julliard at winehq.org
Mon Nov 25 09:12:23 CST 2019


Module: wine
Branch: stable
Commit: 5afbcf16abc9b8a2aa5535522e1e7c3f2ffd8fb0
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=5afbcf16abc9b8a2aa5535522e1e7c3f2ffd8fb0

Author: Bryon Roche <kain at kain.org>
Date:   Thu May  9 15:30:42 2019 -0500

windowscodecs: Byte swap png read/write for 16-bpp data.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46558
Signed-off-by: Vincent Povirk <vincent at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit 0c0def962f2b86f44625f11d8d9d2013aaffa46a)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 dlls/windowscodecs/pngformat.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/dlls/windowscodecs/pngformat.c b/dlls/windowscodecs/pngformat.c
index faffeae6ae..023b331718 100644
--- a/dlls/windowscodecs/pngformat.c
+++ b/dlls/windowscodecs/pngformat.c
@@ -332,6 +332,7 @@ MAKE_FUNCPTR(png_set_strip_16);
 MAKE_FUNCPTR(png_set_tRNS);
 MAKE_FUNCPTR(png_set_tRNS_to_alpha);
 MAKE_FUNCPTR(png_set_write_fn);
+MAKE_FUNCPTR(png_set_swap);
 MAKE_FUNCPTR(png_read_end);
 MAKE_FUNCPTR(png_read_image);
 MAKE_FUNCPTR(png_read_info);
@@ -398,6 +399,7 @@ static void *load_libpng(void)
         LOAD_FUNCPTR(png_set_tRNS);
         LOAD_FUNCPTR(png_set_tRNS_to_alpha);
         LOAD_FUNCPTR(png_set_write_fn);
+        LOAD_FUNCPTR(png_set_swap);
         LOAD_FUNCPTR(png_read_end);
         LOAD_FUNCPTR(png_read_image);
         LOAD_FUNCPTR(png_read_info);
@@ -642,6 +644,10 @@ static HRESULT WINAPI PngDecoder_Initialize(IWICBitmapDecoder *iface, IStream *p
     color_type = ppng_get_color_type(This->png_ptr, This->info_ptr);
     bit_depth = ppng_get_bit_depth(This->png_ptr, This->info_ptr);
 
+    /* PNGs with bit-depth greater than 8 are network byte order. Windows does not expect this. */
+    if (bit_depth > 8)
+        ppng_set_swap(This->png_ptr);
+
     /* check for color-keyed alpha */
     transparency = ppng_get_tRNS(This->png_ptr, This->info_ptr, &trans, &num_trans, &trans_values);
 
@@ -1644,6 +1650,10 @@ static HRESULT WINAPI PngFrameEncode_WritePixels(IWICBitmapFrameEncode *iface,
             }
         }
 
+        /* Tell PNG we need to byte swap if writing a >8-bpp image */
+        if (This->format->bit_depth > 8)
+            ppng_set_swap(This->png_ptr);
+
         ppng_set_IHDR(This->png_ptr, This->info_ptr, This->width, This->height,
             This->format->bit_depth, This->format->color_type,
             This->interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE,




More information about the wine-cvs mailing list