Skip to content

Commit

Permalink
Fixed bug Bug 3214 - SDL_image causes "libpng warning: Interlace hand…
Browse files Browse the repository at this point in the history
…ling 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.
  • Loading branch information
slouken committed Feb 7, 2018
1 parent 9387acb commit e63624f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions IMG_png.c
Expand Up @@ -104,6 +104,7 @@ static struct {
void (*png_set_packing) (png_structrp png_ptr);
void (*png_set_read_fn) (png_structrp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn);
void (*png_set_strip_16) (png_structrp png_ptr);
int (*png_set_interlace_handling) (png_structrp png_ptr);
int (*png_sig_cmp) (png_const_bytep sig, png_size_t start, png_size_t num_to_check);
#ifndef LIBPNG_VERSION_12
jmp_buf* (*png_set_longjmp_fn) (png_structrp, png_longjmp_ptr, size_t);
Expand Down Expand Up @@ -153,6 +154,7 @@ int IMG_InitPNG()
FUNCTION_LOADER(png_set_packing, void (*) (png_structrp png_ptr))
FUNCTION_LOADER(png_set_read_fn, void (*) (png_structrp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn))
FUNCTION_LOADER(png_set_strip_16, void (*) (png_structrp png_ptr))
FUNCTION_LOADER(png_set_interlace_handling, int (*) (png_structrp png_ptr))
FUNCTION_LOADER(png_sig_cmp, int (*) (png_const_bytep sig, png_size_t start, png_size_t num_to_check))
#ifndef LIBPNG_VERSION_12
FUNCTION_LOADER(png_set_longjmp_fn, jmp_buf* (*) (png_structrp, png_longjmp_ptr, size_t))
Expand Down Expand Up @@ -287,7 +289,10 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
&color_type, &interlace_type, NULL, NULL);

/* tell libpng to strip 16 bit/color files down to 8 bits/color */
lib.png_set_strip_16(png_ptr) ;
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).
Expand Down Expand Up @@ -607,8 +612,8 @@ static int IMG_SavePNG_RW_libpng(SDL_Surface *surface, SDL_RWops *dst, int freed
#define MINIZ_SDL_MALLOC
#define MZ_ASSERT(x) SDL_assert(x)
#undef memset
#define memset SDL_memset
#define strlen SDL_strlen
#define memset SDL_memset
#define strlen SDL_strlen

#include "miniz.h"

Expand Down

0 comments on commit e63624f

Please sign in to comment.