]> git.imager.perl.org - imager.git/blobdiff - PNG/impng.c
add missing va_end() in bmp.c's write_packed()
[imager.git] / PNG / impng.c
index dcc852421da0335366ad1bcc713a77da7d7ad86b..c7a7b8e4ce68aafe1b34fc0e1df0dddd07369a66 100644 (file)
@@ -2,6 +2,7 @@
 #include "png.h"
 #include <stdlib.h>
 #include <string.h>
+#include <zlib.h>
 
 /* this is a way to get number of channels from color space 
  * Color code to channel number */
@@ -48,6 +49,35 @@ i_png_lib_version(void) {
   return png_access_version_number();
 }
 
+static char const * const
+features[] =
+  {
+#ifdef PNG_BENIGN_ERRORS_SUPPORTED
+    "benign-errors",
+#endif
+#ifdef PNG_READ_SUPPORTED
+    "read",
+#endif
+#ifdef PNG_WRITE_SUPPORTED
+    "write",
+#endif
+#ifdef PNG_MNG_FEATURES_SUPPORTED
+    "mng-features",
+#endif
+#ifdef PNG_CHECK_cHRM_SUPPORTED
+    "check-cHRM",
+#endif
+#ifdef PNG_SET_USER_LIMITS_SUPPORTED
+    "user-limits",
+#endif
+    NULL
+  };
+
+const char * const *
+i_png_features(void) {
+  return features;
+}
+
 static void
 wiol_read_data(png_structp png_ptr, png_bytep data, png_size_t length) {
   io_glue *ig = png_get_io_ptr(png_ptr);
@@ -295,8 +325,14 @@ i_readpng_wiol(io_glue *ig, int flags) {
   }
   png_set_read_fn(png_ptr, (png_voidp) (ig), wiol_read_data);
 
-#if PNG_LIBPNG_VER >= 10400
+#if defined(PNG_BENIGN_ERRORS_SUPPORTED)
   png_set_benign_errors(png_ptr, (flags & IMPNG_READ_IGNORE_BENIGN_ERRORS) ? 1 : 0);
+#elif PNG_LIBPNG_VER >= 10400
+  if (flags & IMPNG_READ_IGNORE_BENIGN_ERRORS) {
+    i_push_error(0, "libpng not configured to ignore benign errors");
+    png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
+    return NULL;
+  }
 #else
   if (flags & IMPNG_READ_IGNORE_BENIGN_ERRORS) {
     i_push_error(0, "libpng too old to ignore benign errors");
@@ -1102,6 +1138,19 @@ set_png_tags(i_img *im, png_structp png_ptr, png_infop info_ptr) {
     }
   }
 
+  {
+    int level;
+    if (i_tags_get_int(&im->tags, "png_compression_level", 0, &level)) {
+      if (level >= Z_NO_COMPRESSION && level <= Z_BEST_COMPRESSION) 
+       png_set_compression_level(png_ptr, level);
+      else {
+       i_push_errorf(0, "png_compression_level must be between %d and %d",
+                     Z_NO_COMPRESSION, Z_BEST_COMPRESSION);
+       return 0;
+      }
+    }
+  }
+
   {
     /* no bKGD support yet, maybe later
        it may be simpler to do it in the individual writers