Skip to content

Instantly share code, notes, and snippets.

@balr0g
Created June 27, 2012 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balr0g/3004353 to your computer and use it in GitHub Desktop.
Save balr0g/3004353 to your computer and use it in GitHub Desktop.
Exact-Image patch for libpng-1.5 or later
--- exactimage-orig/codecs/png.cc 2012-06-27 09:59:02.000000000 -0400
+++ exactimage/codecs/png.cc 2012-06-27 10:03:30.000000000 -0400
@@ -17,6 +17,7 @@
#include <stdlib.h>
#include <png.h>
+#include <zlib.h>
#include <iostream>
@@ -71,7 +72,7 @@
/* Allocate/initialize the memory for image information. REQUIRED. */
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
- png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
+ png_destroy_read_struct(&png_ptr, NULL, NULL);
return 0;
}
@@ -82,7 +83,7 @@
if (setjmp(png_jmpbuf(png_ptr))) {
/* Free all of the memory associated with the png_ptr and info_ptr */
- png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
/* If we get here, we had a problem reading the file */
return 0;
}
@@ -99,12 +100,12 @@
png_read_info (png_ptr, info_ptr);
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
- &interlace_type, int_p_NULL, int_p_NULL);
+ &interlace_type, NULL, NULL);
image.w = width;
image.h = height;
image.bps = bit_depth;
- image.spp = info_ptr->channels;
+ image.spp = png_get_channels(png_ptr, info_ptr);
png_uint_32 res_x, res_y;
res_x = png_get_x_pixels_per_meter(png_ptr, info_ptr);
@@ -123,7 +124,13 @@
if (color_type == PNG_COLOR_TYPE_PALETTE) {
png_set_palette_to_rgb(png_ptr);
image.bps = 8;
- if (info_ptr->num_trans)
+
+ png_bytep trans_alpha;
+ int num_trans;
+ png_color_16p trans_color;
+ png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color);
+
+ if (num_trans)
image.spp = 4;
else
image.spp = 3;
@@ -196,11 +203,11 @@
for (int pass = 0; pass < number_passes; ++pass)
for (unsigned int y = 0; y < height; ++y) {
row_pointers[0] = image.getRawData() + y * stride;
- png_read_rows(png_ptr, row_pointers, png_bytepp_NULL, 1);
+ png_read_rows(png_ptr, row_pointers, NULL, 1);
}
/* clean up after the read, and free any memory allocated - REQUIRED */
- png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
/* that's it */
return true;
@@ -224,7 +231,7 @@
/* Allocate/initialize the memory for image information. REQUIRED. */
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
- png_destroy_write_struct(&png_ptr, png_infopp_NULL);
+ png_destroy_write_struct(&png_ptr, NULL);
return false;
}
@@ -244,8 +251,6 @@
else if (quality > Z_BEST_COMPRESSION) quality = Z_BEST_COMPRESSION;
png_set_compression_level(png_ptr, quality);
- png_info_init (info_ptr);
-
/* Set up our STL stream output control */
png_set_write_fn (png_ptr, stream, &stdstream_write_data, &stdstream_flush_data);
@sdyroff
Copy link

sdyroff commented Oct 14, 2012

I try to package exactimage for fedora. May I use your patch? I would like to give you attribution, please contact me via email (sdyroff[at]fedoraproject[dot]org).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment