Fixed bug 4516 - [PATCH] more accuracy with macro SAVE_PNG and PNG_SETJMP_SUPPORTED
authorSam Lantinga <slouken@libsdl.org>
Sat, 16 Mar 2019 18:57:27 -0700
changeset 640db8eb5e7247c
parent 639 03bd33e8cb49
child 641 61f1bf992955
Fixed bug 4516 - [PATCH] more accuracy with macro SAVE_PNG and PNG_SETJMP_SUPPORTED

Dmitry Gapkalov

provide possibility to compile SDL_image without SAVE_PNG and PNG_SETJMP_SUPPORTED
IMG_png.c
     1.1 --- a/IMG_png.c	Sat Mar 16 18:34:22 2019 -0700
     1.2 +++ b/IMG_png.c	Sat Mar 16 18:57:27 2019 -0700
     1.3 @@ -23,6 +23,9 @@
     1.4  
     1.5  #include "SDL_image.h"
     1.6  
     1.7 +/* We'll always have PNG save support */
     1.8 +#define SAVE_PNG
     1.9 +
    1.10  #if !(defined(__APPLE__) || defined(SDL_IMAGE_USE_WIC_BACKEND)) || defined(SDL_IMAGE_USE_COMMON_BACKEND)
    1.11  
    1.12  #ifdef LOAD_PNG
    1.13 @@ -123,9 +126,12 @@
    1.14      void (*png_set_strip_16) (png_structrp png_ptr);
    1.15      int (*png_set_interlace_handling) (png_structrp png_ptr);
    1.16      int (*png_sig_cmp) (png_const_bytep sig, png_size_t start, png_size_t num_to_check);
    1.17 +#ifdef PNG_SETJMP_SUPPORTED
    1.18  #ifndef LIBPNG_VERSION_12
    1.19      jmp_buf* (*png_set_longjmp_fn) (png_structrp, png_longjmp_ptr, size_t);
    1.20  #endif
    1.21 +#endif
    1.22 +#ifdef SAVE_PNG
    1.23      png_structp (*png_create_write_struct) (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn);
    1.24      void (*png_destroy_write_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr);
    1.25      void (*png_set_write_fn) (png_structrp png_ptr, png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn);
    1.26 @@ -134,6 +140,7 @@
    1.27      void (*png_set_rows) (png_noconst15_structrp png_ptr, png_inforp info_ptr, png_bytepp row_pointers);
    1.28      void (*png_write_png) (png_structrp png_ptr, png_inforp info_ptr, int transforms, png_voidp params);
    1.29      void (*png_set_PLTE) (png_structrp png_ptr, png_inforp info_ptr, png_const_colorp palette, int num_palette);
    1.30 +#endif
    1.31  } lib;
    1.32  
    1.33  #ifdef LOAD_PNG_DYNAMIC
    1.34 @@ -173,9 +180,12 @@
    1.35          FUNCTION_LOADER(png_set_strip_16, void (*) (png_structrp png_ptr))
    1.36          FUNCTION_LOADER(png_set_interlace_handling, int (*) (png_structrp png_ptr))
    1.37          FUNCTION_LOADER(png_sig_cmp, int (*) (png_const_bytep sig, png_size_t start, png_size_t num_to_check))
    1.38 +#ifdef PNG_SETJMP_SUPPORTED
    1.39  #ifndef LIBPNG_VERSION_12
    1.40          FUNCTION_LOADER(png_set_longjmp_fn, jmp_buf* (*) (png_structrp, png_longjmp_ptr, size_t))
    1.41  #endif
    1.42 +#endif
    1.43 +#ifdef SAVE_PNG
    1.44          FUNCTION_LOADER(png_create_write_struct, png_structp (*) (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn))
    1.45          FUNCTION_LOADER(png_destroy_write_struct, void (*) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr))
    1.46          FUNCTION_LOADER(png_set_write_fn, void (*) (png_structrp png_ptr, png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn))
    1.47 @@ -184,6 +194,7 @@
    1.48          FUNCTION_LOADER(png_set_rows, void (*) (png_noconst15_structrp png_ptr, png_inforp info_ptr, png_bytepp row_pointers))
    1.49          FUNCTION_LOADER(png_write_png, void (*) (png_structrp png_ptr, png_inforp info_ptr, int transforms, png_voidp params))
    1.50          FUNCTION_LOADER(png_set_PLTE, void (*) (png_structrp png_ptr, png_inforp info_ptr, png_const_colorp palette, int num_palette))
    1.51 +#endif
    1.52      }
    1.53      ++lib.loaded;
    1.54  
    1.55 @@ -287,6 +298,8 @@
    1.56       * the normal method of doing things with libpng).  REQUIRED unless you
    1.57       * set up your own error handlers in png_create_read_struct() earlier.
    1.58       */
    1.59 +
    1.60 +#ifdef PNG_SETJMP_SUPPORTED
    1.61  #ifndef LIBPNG_VERSION_12
    1.62      if ( setjmp(*lib.png_set_longjmp_fn(png_ptr, longjmp, sizeof (jmp_buf))) )
    1.63  #else
    1.64 @@ -296,7 +309,7 @@
    1.65          error = "Error reading the PNG file.";
    1.66          goto done;
    1.67      }
    1.68 -
    1.69 +#endif
    1.70      /* Set up the input control */
    1.71      lib.png_set_read_fn(png_ptr, src, png_read_data);
    1.72  
    1.73 @@ -488,9 +501,6 @@
    1.74  
    1.75  #endif /* !defined(__APPLE__) || defined(SDL_IMAGE_USE_COMMON_BACKEND) */
    1.76  
    1.77 -/* We'll always have PNG save support */
    1.78 -#define SAVE_PNG
    1.79 -
    1.80  #ifdef SAVE_PNG
    1.81  
    1.82  int IMG_SavePNG(SDL_Surface *surface, const char *file)
    1.83 @@ -543,12 +553,13 @@
    1.84              SDL_SetError("Couldn't create image information for PNG file");
    1.85              return -1;
    1.86          }
    1.87 -
    1.88 +#ifdef PNG_SETJMP_SUPPORTED
    1.89  #ifndef LIBPNG_VERSION_12
    1.90          if (setjmp(*lib.png_set_longjmp_fn(png_ptr, longjmp, sizeof (jmp_buf))))
    1.91  #else
    1.92          if (setjmp(png_ptr->jmpbuf))
    1.93  #endif
    1.94 +#endif
    1.95          {
    1.96              lib.png_destroy_write_struct(&png_ptr, &info_ptr);
    1.97              SDL_SetError("Error writing the PNG file.");