1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
From: Sam Lantinga <slouken@libsdl.org>
Date: Wed, 7 Feb 2018 14:21:26 -0800
Subject: Fixed bug Bug 3214 - SDL_image causes "libpng warning: Interlace
handling should be turned on when using png_read_image" when loading
interlaced images
Hans de Goede
When starting an app which uses SDL_image to load interlaced png-s with a recent libpng, the following message is printed to the terminal:
libpng warning: Interlace handling should be turned on when using png_read_image
Once per loaded png. The attached patch fixes this.
Origin: backport, 2.0.3, commit:e63624fb63e063be67c788c29a3616ae02c18e99
---
IMG_png.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/IMG_png.c b/IMG_png.c
index 5f91f15..613bf2c 100644
--- a/IMG_png.c
+++ b/IMG_png.c
@@ -95,6 +95,7 @@ static struct {
void (*png_set_packing) (png_structp png_ptr);
void (*png_set_read_fn) (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn);
void (*png_set_strip_16) (png_structp png_ptr);
+ int (*png_set_interlace_handling) (png_structp png_ptr);
int (*png_sig_cmp) (png_bytep sig, png_size_t start, png_size_t num_to_check);
#ifndef LIBPNG_VERSION_12
jmp_buf* (*png_set_longjmp_fn) (png_structp, png_longjmp_ptr, size_t);
@@ -228,6 +229,13 @@ int IMG_InitPNG()
SDL_UnloadObject(lib.handle);
return -1;
}
+ lib.png_set_interlace_handling =
+ (int (*) (png_structp))
+ SDL_LoadFunction(lib.handle, "png_set_interlace_handling");
+ if ( lib.png_set_interlace_handling == NULL ) {
+ SDL_UnloadObject(lib.handle);
+ return -1;
+ }
lib.png_sig_cmp =
(int (*) (png_bytep, png_size_t, png_size_t))
SDL_LoadFunction(lib.handle, "png_sig_cmp");
@@ -280,6 +288,7 @@ int IMG_InitPNG()
lib.png_set_packing = png_set_packing;
lib.png_set_read_fn = png_set_read_fn;
lib.png_set_strip_16 = png_set_strip_16;
+ lib.png_set_interlace_handling = png_set_interlace_handling;
lib.png_sig_cmp = png_sig_cmp;
#ifndef LIBPNG_VERSION_12
lib.png_set_longjmp_fn = png_set_longjmp_fn;
@@ -404,6 +413,9 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
lib.png_set_strip_16(png_ptr) ;
+ /* tell libpng to de-interlace (if the image is interlaced) */
+ lib.png_set_interlace_handling(png_ptr);
+
/* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
* byte into separate bytes (useful for paletted and grayscale images).
*/
|