Blob Blame History Raw
From: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
Subject: Some changes to cooperate with libpng 1.5.

--- a/f_readpng.c
+++ b/f_readpng.c
@@ -43,7 +43,7 @@
     char	   *ptr;
     int		    num_palette;
     png_colorp	    palette;
-    png_color_16    background;
+    png_color_16    background, *image_background;
 
     /* make scale factor smaller for metric */
     float scale = (appres.INCHES ?
@@ -73,7 +73,7 @@
     }
 
     /* set long jump recovery here */
-    if (setjmp(png_ptr->jmpbuf)) {
+    if (setjmp(png_jmpbuf((png_ptr)))) {
 	/* if we get here there was a problem reading the file */
 	png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
 	close_picfile(file,filetype);
@@ -90,14 +90,18 @@
     png_get_IHDR(png_ptr, info_ptr, &w, &h, &bit_depth, &color_type,
 	&interlace_type, &compression_type, &filter_type);
 
-    if (info_ptr->valid & PNG_INFO_gAMA)
-	png_set_gamma(png_ptr, 2.2, info_ptr->gamma);
-    else
+    if (png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA)) {
+	double gamma;
+	png_get_gAMA(png_ptr, info_ptr, &gamma);
+	png_set_gamma(png_ptr, 2.2, gamma);
+	} else {
 	png_set_gamma(png_ptr, 2.2, 0.45);
+	}
 
-    if (info_ptr->valid & PNG_INFO_bKGD)
+    if (png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD) &&
+        png_get_bKGD(png_ptr, info_ptr, &image_background))
 	/* set the background to the one supplied */
-	png_set_background(png_ptr, &info_ptr->background,
+	png_set_background(png_ptr, image_background,
 		PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
     else {
 	/* blend the canvas background using the alpha channel */
@@ -136,7 +140,11 @@
 
 	if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette)) {
 	    png_get_hIST(png_ptr, info_ptr, &histogram);
+#ifdef PNG_READ_QUANTIZE_SUPPORTED
+	    png_set_quantize(png_ptr, palette, num_palette, 256, histogram, 0);
+#else
 	    png_set_dither(png_ptr, palette, num_palette, 256, histogram, 0);
+#endif
 	}
     }
     if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
--- a/f_wrpng.c
+++ b/f_wrpng.c
@@ -20,6 +20,7 @@
 #include "w_msgpanel.h"
 #include "w_setup.h"
 #include <png.h>
+#include <zlib.h>
 
 /*
  * Write PNG file from rgb data
@@ -59,7 +60,7 @@
     }
 
     /* set long jump recovery here */
-    if (setjmp(png_ptr->jmpbuf)) {
+    if (setjmp(png_jmpbuf((png_ptr)))) {
 	/* if we get here there was a problem reading the file */
 	png_destroy_write_struct(&png_ptr, &info_ptr);
 	return False;