Package: netpbm-free Version: 2:10.0-15.2 Severity: normal Tags: patch pending
[Replace XX with correct value] Dear maintainer, I've prepared an NMU for netpbm-free (versioned as 2:10.0-15.3) and uploaded it to DELAYED/XX. Please feel free to tell me if I should delay it longer. Regards. diff -u netpbm-free-10.0/debian/changelog netpbm-free-10.0/debian/changelog --- netpbm-free-10.0/debian/changelog +++ netpbm-free-10.0/debian/changelog @@ -1,3 +1,11 @@ +netpbm-free (2:10.0-15.3) unstable; urgency=medium + + * Non-maintainer upload. + * Fix FTBFS with libpng1.6 -- see 648131libpng16.patch (Closes: #648131) + * Change B-D to libpng-dev (Closes: #662444) + + -- Tobias Frost <t...@debian.org> Sat, 30 Jan 2016 16:51:10 +0100 + netpbm-free (2:10.0-15.2) unstable; urgency=medium * Non-maintainer upload. diff -u netpbm-free-10.0/debian/control netpbm-free-10.0/debian/control --- netpbm-free-10.0/debian/control +++ netpbm-free-10.0/debian/control @@ -4,7 +4,7 @@ Maintainer: Andreas Barth <a...@not.so.argh.org> Uploaders: Steve McIntyre <93...@debian.org> Standards-Version: 3.8.4 -Build-Depends: libtiff5-dev, libjpeg-dev, debhelper (>= 7), libpng12-dev, zlib1g-dev, flex, quilt +Build-Depends: libtiff5-dev, libjpeg-dev, debhelper (>= 7), libpng-dev, zlib1g-dev, flex, quilt Homepage: http://netpbm.alioth.debian.org Vcs-Browser: http://git.debian.org/?p=collab-maint/netpbm.git Vcs-Git: git://anonscm.debian.org/collab-maint/netpbm.git diff -u netpbm-free-10.0/debian/patches/bufferoverflow.patch netpbm-free-10.0/debian/patches/bufferoverflow.patch --- netpbm-free-10.0/debian/patches/bufferoverflow.patch +++ netpbm-free-10.0/debian/patches/bufferoverflow.patch @@ -11,0 +12 @@ + diff -u netpbm-free-10.0/debian/patches/series netpbm-free-10.0/debian/patches/series --- netpbm-free-10.0/debian/patches/series +++ netpbm-free-10.0/debian/patches/series @@ -18,0 +19,2 @@ +648131libpng16.patch + only in patch2: unchanged: --- netpbm-free-10.0.orig/debian/patches/648131libpng16.patch +++ netpbm-free-10.0/debian/patches/648131libpng16.patch @@ -0,0 +1,1044 @@ +--- a/pnm/pnmtopng.c ++++ b/pnm/pnmtopng.c +@@ -93,7 +93,8 @@ + + #include <string.h> /* strcat() */ + #include <limits.h> +-#include <png.h> /* includes zlib.h and setjmp.h */ ++#include <zlib.h> ++#include <png.h> /* includes no longer zlib.h and setjmp.h */ + #define VERSION "2.37.5 (24 October 2000) +netpbm" + #include "pnm.h" + +@@ -142,7 +143,7 @@ + + /* function prototypes */ + #ifdef __STDC__ +-static void read_text (png_info *info_ptr, FILE *tfp); ++static void read_text (png_struct *png_ptr, png_info *info_ptr, FILE *tfp); + static void pnmtopng_error_handler (png_structp png_ptr, png_const_charp msg); + static int convertpnm (FILE *ifp, FILE *afp, FILE *tfp); + int main (int argc, char *argv[]); +@@ -318,9 +319,10 @@ + + + #ifdef __STDC__ +-static void read_text (png_info *info_ptr, FILE *tfp) ++static void read_text (png_struct *png_ptr, png_info *info_ptr, FILE *tfp) + #else +-static void read_text (info_ptr, tfp) ++static void read_text (png_ptr, info_ptr, tfp) ++png_struct *png_ptr; + png_info *info_ptr; + FILE *tfp; + #endif +@@ -332,8 +334,8 @@ + char *cp; + + overflow2 (MAXCOMMENTS, (int)sizeof(png_text)); +- info_ptr->text = (png_text *)malloc2 (MAXCOMMENTS, sizeof (png_text)); +- if(info_ptr->text == NULL) ++ png_textp text = (png_text *)malloc2 (MAXCOMMENTS, sizeof (png_text)); ++ if(text == NULL) + pm_error("out of memory"); + j = 0; + textpos = 0; +@@ -351,11 +353,11 @@ + if ((textline[0] != ' ') && (textline[0] != '\t')) { + /* the following is a not that accurate check on Author or Title */ + if ((!ztxt) || (textline[0] == 'A') || (textline[0] == 'T')) +- info_ptr->text[j].compression = -1; ++ text[j].compression = -1; + else +- info_ptr->text[j].compression = 0; ++ text[j].compression = 0; + cp = malloc (textpos); +- info_ptr->text[j].key = cp; ++ text[j].key = cp; + i = 0; + if (textline[0] == '"') { + i++; +@@ -368,38 +370,39 @@ + } + *(cp++) = '\0'; + cp = malloc (textpos); +- info_ptr->text[j].text = cp; ++ text[j].text = cp; + while (textline[i] == ' ' || textline[i] == '\t') + i++; + strcpy (cp, &textline[i]); +- info_ptr->text[j].text_length = strlen (cp); ++ text[j].text_length = strlen (cp); + j++; + } else { + j--; +- if (info_ptr->text[j].text_length + textpos <= 0) { ++ if (text[j].text_length + textpos <= 0) { + /* malloc() would overflow: terminate now; lose comment */ + fprintf(stderr, "Invalid text line, aborting\n"); + fflush(stderr); + c = EOF; + break; + } +- overflow_add(info_ptr->text[j].text_length, textpos); +- cp = malloc (info_ptr->text[j].text_length + textpos); +- strcpy (cp, info_ptr->text[j].text); +- cp[ info_ptr->text[j].text_length ] = '\n'; ++ overflow_add(text[j].text_length, textpos); ++ cp = malloc (text[j].text_length + textpos); ++ strcpy (cp, text[j].text); ++ cp[ text[j].text_length ] = '\n'; + i = 0; + while (textline[i] == ' ' || textline[i] == '\t') + i++; +- strcpy (cp + info_ptr->text[j].text_length + 1, &textline[i]); +- free (info_ptr->text[j].text); /* FIXME: see realloc() comment above */ +- info_ptr->text[j].text = cp; +- info_ptr->text[j].text_length = strlen (cp); ++ strcpy (cp + text[j].text_length + 1, &textline[i]); ++ free (text[j].text); /* FIXME: see realloc() comment above */ ++ text[j].text = cp; ++ text[j].text_length = strlen (cp); + j++; + } + textpos = 0; + } + } while (c != EOF); +- info_ptr->num_text = j; ++ ++ png_set_text(png_ptr, info_ptr, text, j); + } + + #ifdef __STDC__ +@@ -1460,60 +1463,49 @@ + } + + png_init_io (png_ptr, stdout); +- info_ptr->width = cols; +- info_ptr->height = rows; +- info_ptr->bit_depth = depth; ++ ++ int color_type; + + if (colorMapped) +- info_ptr->color_type = PNG_COLOR_TYPE_PALETTE; ++ color_type = PNG_COLOR_TYPE_PALETTE; + else if (pnm_type == PPM_TYPE) +- info_ptr->color_type = PNG_COLOR_TYPE_RGB; ++ color_type = PNG_COLOR_TYPE_RGB; + else +- info_ptr->color_type = PNG_COLOR_TYPE_GRAY; ++ color_type = PNG_COLOR_TYPE_GRAY; + +- if (alpha && info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) +- info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; ++ if (alpha && color_type != PNG_COLOR_TYPE_PALETTE) ++ color_type |= PNG_COLOR_MASK_ALPHA; + +- info_ptr->interlace_type = interlace; ++ png_set_IHDR(png_ptr, info_ptr, cols, rows, depth, color_type, interlace, ++ PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + + /* gAMA chunk */ + if (gamma != -1.0) { +- info_ptr->valid |= PNG_INFO_gAMA; +- info_ptr->gamma = gamma; ++ png_set_gAMA(png_ptr, info_ptr, gamma); + } + + /* cHRM chunk */ + if (chroma_wx != -1.0) { +- info_ptr->valid |= PNG_INFO_cHRM; +- info_ptr->x_white = chroma_wx; +- info_ptr->y_white = chroma_wy; +- info_ptr->x_red = chroma_rx; +- info_ptr->y_red = chroma_ry; +- info_ptr->x_green = chroma_gx; +- info_ptr->y_green = chroma_gy; +- info_ptr->x_blue = chroma_bx; +- info_ptr->y_blue = chroma_by; ++ png_set_cHRM_fixed(png_ptr, info_ptr, ++ chroma_wx, chroma_wy, ++ chroma_rx, chroma_ry, ++ chroma_gx, chroma_gy, ++ chroma_bx, chroma_by); + } + + /* pHYS chunk */ + if (phys_unit != -1.0) { +- info_ptr->valid |= PNG_INFO_pHYs; +- info_ptr->x_pixels_per_unit = phys_x; +- info_ptr->y_pixels_per_unit = phys_y; +- info_ptr->phys_unit_type = phys_unit; ++ png_set_pHYs (png_ptr, info_ptr, phys_x, phys_y, phys_unit); + } + +- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { ++ if (color_type == PNG_COLOR_TYPE_PALETTE) { + createPngPalette(palette_pnm, palette_size, maxval, + trans_pnm, trans_size, alpha_maxval, + palette, trans); +- info_ptr->valid |= PNG_INFO_PLTE; +- info_ptr->palette = palette; +- info_ptr->num_palette = palette_size; ++ png_set_PLTE(png_ptr, info_ptr, palette, palette_size); ++ + if (trans_size > 0) { +- info_ptr->valid |= PNG_INFO_tRNS; +- info_ptr->trans = trans; +- info_ptr->num_trans = trans_size; /* omit opaque values */ ++ png_set_tRNS(png_ptr, info_ptr, trans, trans_size, NULL); + } + + /* creating hIST chunk */ +@@ -1527,18 +1519,19 @@ + + for (i = 0 ; i < MAXCOLORS ; i++) + histogram[i] = chv[i].value; +- info_ptr->valid |= PNG_INFO_hIST; +- info_ptr->hist = histogram; ++ ++ png_set_hIST(png_ptr, info_ptr, histogram); ++ + if (verbose) + pm_message ("histogram created"); + } + } else { /* color_type != PNG_COLOR_TYPE_PALETTE */ +- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY || +- info_ptr->color_type == PNG_COLOR_TYPE_RGB) { ++ png_color_16 trans_values; ++ if (color_type == PNG_COLOR_TYPE_GRAY || ++ color_type == PNG_COLOR_TYPE_RGB) { + if (transparent > 0) { +- info_ptr->valid |= PNG_INFO_tRNS; +- info_ptr->trans_values = +- xelToPngColor_16(transcolor, maxval, png_maxval); ++ trans_values = xelToPngColor_16(transcolor, maxval, png_maxval); ++ png_set_tRNS(png_ptr, info_ptr, NULL, 1, &trans_values); + } + + } else { +@@ -1547,32 +1540,36 @@ + */ + } + if (verbose) { +- if (info_ptr->valid && PNG_INFO_tRNS) ++ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { + pm_message("Transparent color {gray, red, green, blue} = " + "{%d, %d, %d, %d}", +- info_ptr->trans_values.gray, +- info_ptr->trans_values.red, +- info_ptr->trans_values.green, +- info_ptr->trans_values.blue); ++ trans_values.gray, ++ trans_values.red, ++ trans_values.green, ++ trans_values.blue); ++ } + else + pm_message("No transparent color"); + } + } + /* bKGD chunk */ + if (background > -1) { +- info_ptr->valid |= PNG_INFO_bKGD; +- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { +- info_ptr->background.index = background_index; ++ png_color_16 background_col; ++ if (color_type == PNG_COLOR_TYPE_PALETTE) { ++ background_col.index = background_index; ++ png_set_bKGD(png_ptr, info_ptr, &background_col); + } else { +- info_ptr->background = +- xelToPngColor_16(backcolor, maxval, png_maxval); +- if (verbose) ++ background_col = xelToPngColor_16(backcolor, maxval, png_maxval); ++ png_set_bKGD(png_ptr, info_ptr, &background_col); ++ ++ if (verbose) { + pm_message("Writing bKGD chunk with background color " + " {gray, red, green, blue} = {%d, %d, %d, %d}", +- info_ptr->background.gray, +- info_ptr->background.red, +- info_ptr->background.green, +- info_ptr->background.blue ); ++ background_col.gray, ++ background_col.red, ++ background_col.green, ++ background_col.blue ); ++ } + } + } + +@@ -1587,34 +1584,34 @@ + */ + /* sBIT chunk */ + int sbitval; +- +- info_ptr->valid |= PNG_INFO_sBIT; ++ png_color_8 sig_bit; + + sbitval = pm_maxvaltobits(maxval); + +- if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) { +- info_ptr->sig_bit.red = sbitval; +- info_ptr->sig_bit.green = sbitval; +- info_ptr->sig_bit.blue = sbitval; ++ if (color_type & PNG_COLOR_MASK_COLOR) { ++ sig_bit.red = sbitval; ++ sig_bit.green = sbitval; ++ sig_bit.blue = sbitval; + } else { +- info_ptr->sig_bit.gray = sbitval; ++ sig_bit.gray = sbitval; + } + if (verbose) + pm_message("Writing sBIT chunk with sbitval = %d", sbitval); + +- if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) { +- info_ptr->sig_bit.alpha = pm_maxvaltobits(alpha_maxval); ++ if (color_type & PNG_COLOR_MASK_ALPHA) { ++ sig_bit.alpha = pm_maxvaltobits(alpha_maxval); + } ++ ++ png_set_sBIT(png_ptr, info_ptr, &sig_bit); + } + + /* tEXT and zTXT chunks */ + if ((text) || (ztxt)) { +- read_text (info_ptr, tfp); ++ read_text (png_ptr, info_ptr, tfp); + } + + /* tIME chunk */ + if (mtime) { +- info_ptr->valid |= PNG_INFO_tIME; + sscanf (date_string, "%d-%d-%d", &time_struct.tm_year, + &time_struct.tm_mon, + &time_struct.tm_mday); +@@ -1624,7 +1621,10 @@ + sscanf (time_string, "%d:%d:%d", &time_struct.tm_hour, + &time_struct.tm_min, + &time_struct.tm_sec); +- png_convert_from_struct_tm (&info_ptr->mod_time, &time_struct); ++ ++ png_time modtime; ++ png_convert_from_struct_tm (&modtime, &time_struct); ++ png_set_tIME(png_ptr, info_ptr, &modtime); + } + + /* explicit filter-type (or none) required */ +@@ -1644,11 +1644,11 @@ + + if ((text) || (ztxt)) + /* prevent from being written twice with png_write_end */ +- info_ptr->num_text = 0; ++ png_set_text(png_ptr, info_ptr, NULL, 0); + + if (mtime) + /* prevent from being written twice with png_write_end */ +- info_ptr->valid &= ~PNG_INFO_tIME; ++ png_set_invalid(png_ptr, info_ptr, PNG_INFO_tIME); + + /* let libpng take care of, e.g., bit-depth conversions */ + png_set_packing (png_ptr); +@@ -1671,12 +1671,12 @@ + xel p_png; + xel const p = xelrow[x]; + PPM_DEPTH(p_png, p, maxval, png_maxval); +- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY || +- info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { ++ if (color_type == PNG_COLOR_TYPE_GRAY || ++ color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { + if (depth == 16) + *pp++ = PNM_GET1 (p_png) >> 8; + *pp++ = PNM_GET1 (p_png)&0xff; +- } else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { ++ } else if (color_type == PNG_COLOR_TYPE_PALETTE) { + unsigned int paletteIndex; + if (alpha) + paletteIndex = lookupColorAlpha(caht, &p, +@@ -1684,8 +1684,8 @@ + else + paletteIndex = ppm_lookupcolor(cht, &p); + *pp++ = paletteIndex; +- } else if (info_ptr->color_type == PNG_COLOR_TYPE_RGB || +- info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) { ++ } else if (color_type == PNG_COLOR_TYPE_RGB || ++ color_type == PNG_COLOR_TYPE_RGB_ALPHA) { + if (depth == 16) + *pp++ = PPM_GETR (p_png) >> 8; + *pp++ = PPM_GETR (p_png)&0xff; +@@ -1700,7 +1700,7 @@ + pm_closer (ifp); + pm_error (" (can't happen) undefined color_type"); + } +- if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) { ++ if (color_type & PNG_COLOR_MASK_ALPHA) { + int const png_alphaval = (int) + alpha_mask[y][x] * (float) png_maxval / maxval +0.5; + if (depth == 16) +--- a/pnm/pngtopnm.c ++++ b/pnm/pngtopnm.c +@@ -31,6 +31,8 @@ + * compiled with one size in libpng and another size here). */ + + #include <math.h> ++#include <string.h> ++#include <zlib.h> + #include <png.h> /* includes zlib.h and setjmp.h */ + #define VERSION "2.37.4 (5 December 1999) +netpbm" + +@@ -64,8 +66,8 @@ + static void store_pixel (xel *pix, png_uint_16 r, png_uint_16 g, png_uint_16 b, + png_uint_16 a); + static int iscolor (png_color c); +-static void save_text (png_info *info_ptr, FILE *tfp); +-static void show_time (png_info *info_ptr); ++static void save_text (png_struct *png_ptr, png_info *info_ptr, FILE *tfp); ++static void show_time (png_struct *png_ptr, png_info *info_ptr); + static void pngtopnm_error_handler (png_structp png_ptr, png_const_charp msg); + static void convertpng (FILE *ifp, FILE *tfp); + int main (int argc, char *argv[]); +@@ -87,7 +89,7 @@ + static int mtime = FALSE; + static jmpbuf_wrapper pngtopnm_jmpbuf_struct; + +-#define get_png_val(p) _get_png_val (&(p), info_ptr->bit_depth) ++#define get_png_val(p) _get_png_val (&(p), bit_depth) + + #ifdef __STDC__ + static png_uint_16 _get_png_val (png_byte **pp, int bit_depth) +@@ -156,33 +158,37 @@ + } + + #ifdef __STDC__ +-static void save_text (png_info *info_ptr, FILE *tfp) ++static void save_text (png_struct *png_ptr, png_info *info_ptr, FILE *tfp) + #else +-static void save_text (info_ptr, tfp) ++static void save_text (png_ptr, info_ptr, tfp) ++png_struct *png_ptr; + png_info *info_ptr; + FILE *tfp; + #endif + { + int i, j, k; ++ png_textp text; + +- for (i = 0 ; i < info_ptr->num_text ; i++) { ++ int num_text = png_get_text(png_ptr, info_ptr, &text, NULL); ++ ++ for (i = 0 ; i < num_text ; i++) { + j = 0; +- while (info_ptr->text[i].key[j] != '\0' && info_ptr->text[i].key[j] != ' ') ++ while (text[i].key[j] != '\0' && text[i].key[j] != ' ') + j++; +- if (info_ptr->text[i].key[j] != ' ') { +- fprintf (tfp, "%s", info_ptr->text[i].key); +- for (j = strlen (info_ptr->text[i].key) ; j < 15 ; j++) ++ if (text[i].key[j] != ' ') { ++ fprintf (tfp, "%s", text[i].key); ++ for (j = strlen (text[i].key) ; j < 15 ; j++) + putc (' ', tfp); + } else { +- fprintf (tfp, "\"%s\"", info_ptr->text[i].key); +- for (j = strlen (info_ptr->text[i].key) ; j < 13 ; j++) ++ fprintf (tfp, "\"%s\"", text[i].key); ++ for (j = strlen (text[i].key) ; j < 13 ; j++) + putc (' ', tfp); + } + putc (' ', tfp); /* at least one space between key and text */ + +- for (j = 0 ; j < info_ptr->text[i].text_length ; j++) { +- putc (info_ptr->text[i].text[j], tfp); +- if (info_ptr->text[i].text[j] == '\n') ++ for (j = 0 ; j < text[i].text_length ; j++) { ++ putc (text[i].text[j], tfp); ++ if (text[i].text[j] == '\n') + for (k = 0 ; k < 16 ; k++) + putc ((int)' ', tfp); + } +@@ -191,9 +197,10 @@ + } + + #ifdef __STDC__ +-static void show_time (png_info *info_ptr) ++static void show_time (png_struct *png_ptr, png_info *info_ptr) + #else +-static void show_time (info_ptr) ++static void show_time (png_struct *png_ptr, info_ptr) ++png_struct *png_ptr; + png_info *info_ptr; + #endif + { +@@ -201,11 +208,14 @@ + {"", "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December"}; + +- if (info_ptr->valid & PNG_INFO_tIME) { ++ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tIME)) { ++ png_timep mod_time; ++ png_get_tIME(png_ptr, info_ptr, &mod_time); ++ if (mod_time->month > 12) mod_time->month = 0; + pm_message ("modification time: %02d %s %d %02d:%02d:%02d", +- info_ptr->mod_time.day, month[info_ptr->mod_time.month], +- info_ptr->mod_time.year, info_ptr->mod_time.hour, +- info_ptr->mod_time.minute, info_ptr->mod_time.second); ++ mod_time->day, month[mod_time->month], ++ mod_time->year, mod_time->hour, ++ mod_time->minute, mod_time->second); + } + } + +@@ -310,8 +320,19 @@ + png_set_sig_bytes (png_ptr, SIG_CHECK_SIZE); + png_read_info (png_ptr, info_ptr); + ++ png_uint_32 width; ++ png_uint_32 height; ++ int bit_depth; ++ int color_type; ++ int interlace_type; ++ int compression_method; ++ int filter_method; ++ ++ png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, ++ &interlace_type, &compression_method, &filter_method); ++ + if (verbose) { +- switch (info_ptr->color_type) { ++ switch (color_type) { + case PNG_COLOR_TYPE_GRAY: + type_string = "gray"; + alpha_string = ""; +@@ -337,66 +358,70 @@ + alpha_string = "+alpha"; + break; + } +- if (info_ptr->valid & PNG_INFO_tRNS) { ++ if (png_get_valid(png_ptr, info_ptr,PNG_INFO_tRNS)) { + alpha_string = "+transparency"; + } + +- if (info_ptr->valid & PNG_INFO_gAMA) { +- sprintf (gamma_string, ", image gamma = %4.2f", info_ptr->gamma); ++ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA)) { ++ double gamma; ++ png_get_gAMA(png_ptr, info_ptr, &gamma); ++ sprintf (gamma_string, ", image gamma = %4.2f", gamma); + } else { + strcpy (gamma_string, ""); + } + + if (verbose) { +- pm_message ("reading a %ldw x %ldh image, %d bit%s %s%s%s%s", +- info_ptr->width, info_ptr->height, +- info_ptr->bit_depth, info_ptr->bit_depth > 1 ? "s" : "", ++ pm_message ("reading a %dw x %dh image, %d bit%s %s%s%s%s", ++ width, height, ++ bit_depth, bit_depth > 1 ? "s" : "", + type_string, alpha_string, gamma_string, +- info_ptr->interlace_type ? ", Adam7 interlaced" : ""); ++ interlace_type ? ", Adam7 interlaced" : ""); ++ png_color_16p background; ++ png_get_bKGD(png_ptr, info_ptr, &background); + pm_message ("background {index, gray, red, green, blue} = " + "{%d, %d, %d, %d, %d}", +- info_ptr->background.index, +- info_ptr->background.gray, +- info_ptr->background.red, +- info_ptr->background.green, +- info_ptr->background.blue); ++ background->index, ++ background->gray, ++ background->red, ++ background->green, ++ background->blue); + } + } + +- png_image = (png_byte **)malloc (info_ptr->height * sizeof (png_byte*)); ++ png_image = (png_byte **)malloc (height * sizeof (png_byte*)); + if (png_image == NULL) { + png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp)NULL); + pm_closer (ifp); + pm_error ("couldn't allocate space for image"); + } + +- if (info_ptr->bit_depth == 16) ++ if (bit_depth == 16) + { +- overflow2(2, info_ptr->width); +- linesize = 2 * info_ptr->width; ++ overflow2(2, width); ++ linesize = 2 * width; + } + else +- linesize = info_ptr->width; ++ linesize = width; + +- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ++ if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + linesize *= 2; + overflow2(2, linesize); + } + else +- if (info_ptr->color_type == PNG_COLOR_TYPE_RGB) ++ if (color_type == PNG_COLOR_TYPE_RGB) + { + overflow2(3, linesize); + linesize *= 3; + } + else +- if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) ++ if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + overflow2(4, linesize); + linesize *= 4; + } + +- for (y = 0 ; y < info_ptr->height ; y++) { ++ for (y = 0 ; y < height ; y++) { + png_image[y] = malloc (linesize); + if (png_image[y] == NULL) { + for (x = 0 ; x < y ; x++) +@@ -408,32 +433,38 @@ + } + } + +- if (info_ptr->bit_depth < 8) ++ if (bit_depth < 8) + png_set_packing (png_ptr); + +- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { ++ if (color_type == PNG_COLOR_TYPE_PALETTE) { + maxval = 255; + } else { +- maxval = (1l << info_ptr->bit_depth) - 1; ++ maxval = (1l << bit_depth) - 1; + } + + /* gamma-correction */ + if (displaygamma != -1.0) { +- if (info_ptr->valid & PNG_INFO_gAMA) { +- if (displaygamma != info_ptr->gamma) { +- png_set_gamma (png_ptr, displaygamma, info_ptr->gamma); +- totalgamma = (double) info_ptr->gamma * (double) displaygamma; ++ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA)) { ++ double gamma; ++ png_get_gAMA(png_ptr, info_ptr, &gamma); ++ ++ if (displaygamma != gamma) { ++ png_set_gamma (png_ptr, displaygamma, gamma); ++ totalgamma = (double) gamma * (double) displaygamma; + /* in case of gamma-corrections, sBIT's as in the PNG-file are not valid anymore */ +- info_ptr->valid &= ~PNG_INFO_sBIT; ++ png_set_invalid(png_ptr, info_ptr, PNG_INFO_sBIT); + if (verbose) + pm_message ("image gamma is %4.2f, converted for display gamma of %4.2f", +- info_ptr->gamma, displaygamma); ++ gamma, displaygamma); + } + } else { +- if (displaygamma != info_ptr->gamma) { ++ double gamma = -1.0; ++ // BUG? gAMA was found to be invalid in the if-path of this else. ++ png_get_gAMA(png_ptr, info_ptr, &gamma); ++ if (displaygamma != gamma) { + png_set_gamma (png_ptr, displaygamma, 1.0); + totalgamma = (double) displaygamma; +- info_ptr->valid &= ~PNG_INFO_sBIT; ++ png_set_invalid(png_ptr, info_ptr, PNG_INFO_sBIT); + if (verbose) + pm_message ("image gamma assumed 1.0, converted for display gamma of %4.2f", + displaygamma); +@@ -449,17 +480,21 @@ + so we will use the sBIT info only for transparency, if we know that only + solid and fully transparent is used */ + +- if (info_ptr->valid & PNG_INFO_sBIT) { ++ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT)) { + switch (alpha) { + case mix: +- if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || +- info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ++ if (color_type == PNG_COLOR_TYPE_RGB_ALPHA || ++ color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + break; +- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE && +- (info_ptr->valid & PNG_INFO_tRNS)) { ++ if (color_type == PNG_COLOR_TYPE_PALETTE && ++ png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { + trans_mix = TRUE; +- for (i = 0 ; i < info_ptr->num_trans ; i++) +- if (info_ptr->trans[i] != 0 && info_ptr->trans[i] != 255) { ++ png_bytep trans = NULL; ++ int num_trans = 0; ++ png_color_16p trans_values; ++ png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &trans_values); ++ for (i = 0 ; i < num_trans ; i++) ++ if (trans[i] != 0 && trans[i] != 255) { + trans_mix = FALSE; + break; + } +@@ -470,83 +505,103 @@ + /* else fall though to normal case */ + + case none: +- if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE || +- info_ptr->color_type == PNG_COLOR_TYPE_RGB || +- info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) && +- (info_ptr->sig_bit.red != info_ptr->sig_bit.green || +- info_ptr->sig_bit.red != info_ptr->sig_bit.blue) && ++ { ++ png_color_8p sig_bit; ++ png_get_sBIT(png_ptr, info_ptr, &sig_bit); ++ if ((color_type == PNG_COLOR_TYPE_PALETTE || ++ color_type == PNG_COLOR_TYPE_RGB || ++ color_type == PNG_COLOR_TYPE_RGB_ALPHA) && ++ (sig_bit->red != sig_bit->green || ++ sig_bit->red != sig_bit->blue) && + alpha == none) { + pm_message ("different bit depths for color channels not supported"); +- pm_message ("writing file with %d bit resolution", info_ptr->bit_depth); ++ pm_message ("writing file with %d bit resolution", bit_depth); + } else { +- if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) && +- (info_ptr->sig_bit.red < 255)) { +- for (i = 0 ; i < info_ptr->num_palette ; i++) { +- info_ptr->palette[i].red >>= (8 - info_ptr->sig_bit.red); +- info_ptr->palette[i].green >>= (8 - info_ptr->sig_bit.green); +- info_ptr->palette[i].blue >>= (8 - info_ptr->sig_bit.blue); ++ if ((color_type == PNG_COLOR_TYPE_PALETTE) && ++ (sig_bit->red < 255)) { ++ png_colorp palette; ++ int num_palette; ++ png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette); ++ ++ for (i = 0 ; i < num_palette ; i++) { ++ palette[i].red >>= (8 - sig_bit->red); ++ palette[i].green >>= (8 - sig_bit->green); ++ palette[i].blue >>= (8 - sig_bit->blue); + } +- maxval = (1l << info_ptr->sig_bit.red) - 1; ++ maxval = (1l << sig_bit->red) - 1; + if (verbose) + pm_message ("image has fewer significant bits, writing file with %d bits per channel", +- info_ptr->sig_bit.red); ++ sig_bit->red); + } else +- if ((info_ptr->color_type == PNG_COLOR_TYPE_RGB || +- info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) && +- (info_ptr->sig_bit.red < info_ptr->bit_depth)) { +- png_set_shift (png_ptr, &(info_ptr->sig_bit)); +- maxval = (1l << info_ptr->sig_bit.red) - 1; ++ if ((color_type == PNG_COLOR_TYPE_RGB || ++ color_type == PNG_COLOR_TYPE_RGB_ALPHA) && ++ (sig_bit->red < bit_depth)) { ++ png_set_shift (png_ptr, sig_bit); ++ maxval = (1l << sig_bit->red) - 1; + if (verbose) + pm_message ("image has fewer significant bits, writing file with %d bits per channel", +- info_ptr->sig_bit.red); ++ sig_bit->red); + } else +- if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY || +- info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) && +- (info_ptr->sig_bit.gray < info_ptr->bit_depth)) { +- png_set_shift (png_ptr, &(info_ptr->sig_bit)); +- maxval = (1l << info_ptr->sig_bit.gray) - 1; ++ if ((color_type == PNG_COLOR_TYPE_GRAY || ++ color_type == PNG_COLOR_TYPE_GRAY_ALPHA) && ++ (sig_bit->gray < bit_depth)) { ++ png_set_shift (png_ptr, sig_bit); ++ maxval = (1l << sig_bit->gray) - 1; + if (verbose) + pm_message ("image has fewer significant bits, writing file with %d bits", +- info_ptr->sig_bit.gray); ++ sig_bit->gray); + } + } + break; ++ } + +- case alpha_only: +- if ((info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || +- info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) && +- (info_ptr->sig_bit.gray < info_ptr->bit_depth)) { +- png_set_shift (png_ptr, &(info_ptr->sig_bit)); ++ case alpha_only: { ++ png_color_8p sig_bit; ++ png_get_sBIT(png_ptr, info_ptr, &sig_bit); ++ ++ if ((color_type == PNG_COLOR_TYPE_RGB_ALPHA || ++ color_type == PNG_COLOR_TYPE_GRAY_ALPHA) && ++ (sig_bit->gray < bit_depth)) { ++ png_set_shift (png_ptr, sig_bit); + if (verbose) + pm_message ("image has fewer significant bits, writing file with %d bits", +- info_ptr->sig_bit.alpha); +- maxval = (1l << info_ptr->sig_bit.alpha) - 1; ++ sig_bit->alpha); ++ maxval = (1l << sig_bit->alpha) - 1; + } + break; ++ } + + } + } +- + /* didn't manage to get libpng to work (bugs?) concerning background */ + /* processing, therefore we do our own using bgr, bgg and bgb */ +- if (info_ptr->valid & PNG_INFO_bKGD) +- switch (info_ptr->color_type) { ++ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD)) { ++ png_color_16p background; ++ png_get_bKGD(png_ptr, info_ptr, &background); ++ ++ switch (color_type) { + case PNG_COLOR_TYPE_GRAY: + case PNG_COLOR_TYPE_GRAY_ALPHA: +- bgr = bgg = bgb = gamma_correct (info_ptr->background.gray, totalgamma); ++ bgr = bgg = bgb = gamma_correct (background->gray, totalgamma); + break; +- case PNG_COLOR_TYPE_PALETTE: +- bgr = gamma_correct (info_ptr->palette[info_ptr->background.index].red, totalgamma); +- bgg = gamma_correct (info_ptr->palette[info_ptr->background.index].green, totalgamma); +- bgb = gamma_correct (info_ptr->palette[info_ptr->background.index].blue, totalgamma); ++ case PNG_COLOR_TYPE_PALETTE: { ++ png_colorp palette; ++ int num_palette; ++ png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette); ++ ++ bgr = gamma_correct (palette[background->index].red, totalgamma); ++ bgg = gamma_correct (palette[background->index].green, totalgamma); ++ bgb = gamma_correct (palette[background->index].blue, totalgamma); + break; ++ } + case PNG_COLOR_TYPE_RGB: + case PNG_COLOR_TYPE_RGB_ALPHA: +- bgr = gamma_correct (info_ptr->background.red, totalgamma); +- bgg = gamma_correct (info_ptr->background.green, totalgamma); +- bgb = gamma_correct (info_ptr->background.blue, totalgamma); ++ bgr = gamma_correct (background->red, totalgamma); ++ bgg = gamma_correct (background->green, totalgamma); ++ bgb = gamma_correct (background->blue, totalgamma); + break; + } ++ } + else + /* when no background given, we use white [from version 2.37] */ + bgr = bgg = bgb = maxval; +@@ -556,7 +611,7 @@ + if (background > -1) + { + backcolor = ppm_parsecolor (backstring, maxval); +- switch (info_ptr->color_type) { ++ switch (color_type) { + case PNG_COLOR_TYPE_GRAY: + case PNG_COLOR_TYPE_GRAY_ALPHA: + bgr = bgg = bgb = PNM_GET1 (backcolor); +@@ -575,13 +630,16 @@ + png_read_end (png_ptr, info_ptr); + + if (mtime) +- show_time (info_ptr); ++ show_time (png_ptr, info_ptr); + if (text) +- save_text (info_ptr, tfp); ++ save_text (png_ptr, info_ptr, tfp); + +- if (info_ptr->valid & PNG_INFO_pHYs) { ++ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_pHYs)) { + float r; +- r = (float)info_ptr->x_pixels_per_unit / info_ptr->y_pixels_per_unit; ++ png_uint_32 x_pixels_per_unit, y_pixels_per_unit; ++ int unit_type; ++ png_get_pHYs(png_ptr, info_ptr, &x_pixels_per_unit, &y_pixels_per_unit, &unit_type); ++ r = (float)x_pixels_per_unit / y_pixels_per_unit; + if (r != 1.0) { + pm_message ("warning - non-square pixels; to fix do a 'pnmscale -%cscale %g'", + r < 1.0 ? 'x' : 'y', +@@ -589,8 +647,8 @@ + } + } + +- if ((row = pnm_allocrow (info_ptr->width)) == NULL) { +- for (y = 0 ; y < info_ptr->height ; y++) ++ if ((row = pnm_allocrow (width)) == NULL) { ++ for (y = 0 ; y < height ; y++) + free (png_image[y]); + free (png_image); + png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp)NULL); +@@ -599,15 +657,20 @@ + } + + if (alpha == alpha_only) { +- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY || +- info_ptr->color_type == PNG_COLOR_TYPE_RGB) { ++ if (color_type == PNG_COLOR_TYPE_GRAY || ++ color_type == PNG_COLOR_TYPE_RGB) { + pnm_type = PBM_TYPE; + } else +- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { ++ if (color_type == PNG_COLOR_TYPE_PALETTE) { + pnm_type = PBM_TYPE; +- if (info_ptr->valid & PNG_INFO_tRNS) { +- for (i = 0 ; i < info_ptr->num_trans ; i++) { +- if (info_ptr->trans[i] != 0 && info_ptr->trans[i] != maxval) { ++ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { ++ png_bytep trans = NULL; ++ int num_trans = 0; ++ png_color_16p trans_values; ++ png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &trans_values); ++ ++ for (i = 0 ; i < num_trans ; i++) { ++ if (trans[i] != 0 && trans[i] != maxval) { + pnm_type = PGM_TYPE; + break; + } +@@ -620,18 +683,21 @@ + pnm_type = PGM_TYPE; + } + } else { +- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY || +- info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { +- if (info_ptr->bit_depth == 1) { ++ if (color_type == PNG_COLOR_TYPE_GRAY || ++ color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { ++ if (bit_depth == 1) { + pnm_type = PBM_TYPE; + } else { + pnm_type = PGM_TYPE; + } + } else +- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { ++ if (color_type == PNG_COLOR_TYPE_PALETTE) { + pnm_type = PGM_TYPE; +- for (i = 0 ; i < info_ptr->num_palette ; i++) { +- if (iscolor (info_ptr->palette[i])) { ++ png_colorp palette; ++ int num_palette; ++ png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette); ++ for (i = 0 ; i < num_palette ; i++) { ++ if (iscolor (palette[i])) { + pnm_type = PPM_TYPE; + break; + } +@@ -655,45 +721,72 @@ + "UNKNOWN!", + maxmaxval); + +- pnm_writepnminit (stdout, info_ptr->width, info_ptr->height, maxval, ++ pnm_writepnminit (stdout, width, height, maxval, + pnm_type, FALSE); + +- for (y = 0 ; y < info_ptr->height ; y++) { ++ for (y = 0 ; y < height ; y++) { ++ + png_pixel = png_image[y]; + pnm_pixel = row; +- for (x = 0 ; x < info_ptr->width ; x++) { ++ for (x = 0 ; x < width ; x++) { + c = get_png_val (png_pixel); +- switch (info_ptr->color_type) { +- case PNG_COLOR_TYPE_GRAY: ++ switch (color_type) { ++ case PNG_COLOR_TYPE_GRAY: { ++ png_bytep trans = NULL; ++ int num_trans = 0; ++ png_color_16p trans_values; ++ png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &trans_values); ++ + store_pixel (pnm_pixel, c, c, c, +- ((info_ptr->valid & PNG_INFO_tRNS) && +- (c == gamma_correct (info_ptr->trans_values.gray, totalgamma))) ? ++ ((png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) && ++ (c == gamma_correct (trans_values->gray, totalgamma))) ? + 0 : maxval); + break; ++ } + + case PNG_COLOR_TYPE_GRAY_ALPHA: + a = get_png_val (png_pixel); + store_pixel (pnm_pixel, c, c, c, a); + break; + +- case PNG_COLOR_TYPE_PALETTE: +- store_pixel (pnm_pixel, info_ptr->palette[c].red, +- info_ptr->palette[c].green, info_ptr->palette[c].blue, +- (info_ptr->valid & PNG_INFO_tRNS) && +- c<info_ptr->num_trans ? +- info_ptr->trans[c] : maxval); ++ case PNG_COLOR_TYPE_PALETTE: { ++ png_colorp palette; ++ int num_palette; ++ png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette); ++ ++ png_bytep trans = NULL; ++ int num_trans = 0; ++ png_color_16p trans_values; ++ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { ++ png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &trans_values); ++ } ++ ++ store_pixel (pnm_pixel, palette[c].red, ++ palette[c].green, palette[c].blue, ++ (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) && ++ c<num_trans ? ++ trans[c] : maxval); + break; ++ } ++ ++ case PNG_COLOR_TYPE_RGB: { ++ png_bytep trans = NULL; ++ int num_trans = 0; ++ png_color_16p trans_values; ++ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { ++ png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &trans_values); ++ } + +- case PNG_COLOR_TYPE_RGB: + c2 = get_png_val (png_pixel); + c3 = get_png_val (png_pixel); + store_pixel (pnm_pixel, c, c2, c3, +- ((info_ptr->valid & PNG_INFO_tRNS) && +- (c == gamma_correct (info_ptr->trans_values.red, totalgamma)) && +- (c2 == gamma_correct (info_ptr->trans_values.green, totalgamma)) && +- (c3 == gamma_correct (info_ptr->trans_values.blue, totalgamma))) ? ++ ((png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) && ++ (c == gamma_correct (trans_values->red, totalgamma)) && ++ (c2 == gamma_correct (trans_values->green, totalgamma)) && ++ (c3 == gamma_correct (trans_values->blue, totalgamma))) ? + 0 : maxval); + break; ++ } + + case PNG_COLOR_TYPE_RGB_ALPHA: + c2 = get_png_val (png_pixel); +@@ -704,7 +797,7 @@ + + default: + pnm_freerow (row); +- for (i = 0 ; i < info_ptr->height ; i++) ++ for (i = 0 ; i < height ; i++) + free (png_image[i]); + free (png_image); + png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp)NULL); +@@ -713,12 +806,12 @@ + } + pnm_pixel++; + } +- pnm_writepnmrow (stdout, row, info_ptr->width, maxval, pnm_type, FALSE); ++ pnm_writepnmrow (stdout, row, width, maxval, pnm_type, FALSE); + } + + fflush(stdout); + pnm_freerow (row); +- for (y = 0 ; y < info_ptr->height ; y++) ++ for (y = 0 ; y < height ; y++) + free (png_image[y]); + free (png_image); + png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp)NULL);