1 --- netpbm-10.47.73/converter/other/pnmtopng.c.orig 2019-06-28 23:02:17.000000000 +0200
2 +++ netpbm-10.47.73/converter/other/pnmtopng.c 2019-07-27 10:44:23.878530313 +0200
5 #include <string.h> /* strcat() */
7 -#include <png.h> /* includes zlib.h and setjmp.h */
8 +#include <png.h> /* includes setjmp.h */
11 #include "pm_c_util.h"
17 -#if PNG_LIBPNG_VER >= 10500
18 -#error Your PNG library (<png.h>) is incompatible with this Netpbm source code.
19 -#error You need either an older PNG library (older than 1.5) or
20 -#error newer Netpbm source code (at least 10.55)
23 -/* A hack until we can remove direct access to png_info from the program */
24 -#if PNG_LIBPNG_VER >= 10400
25 -#define trans_values trans_color
26 -#define TRANS_ALPHA trans_alpha
28 -#define TRANS_ALPHA trans
32 struct zlibCompression {
33 /* These are parameters that describe a form of zlib compression.
34 @@ -2131,6 +2118,7 @@ makePngLine(png_byte * const l
35 gray * const alpha_mask,
36 colorhash_table const cht,
37 coloralphahash_table const caht,
38 + png_struct * const png_ptr,
39 png_info * const info_ptr,
40 xelval const png_maxval,
41 unsigned int const depth) {
42 @@ -2142,21 +2130,22 @@ makePngLine(png_byte * const l
43 for (col = 0; col < cols; ++col) {
45 xel const p = xelrow[col];
46 + png_byte color_type = png_get_color_type(png_ptr, info_ptr);
47 PPM_DEPTH(p_png, p, maxval, png_maxval);
48 - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
49 - info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
50 + if (color_type == PNG_COLOR_TYPE_GRAY ||
51 + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
53 *pp++ = PNM_GET1(p_png) >> 8;
54 *pp++ = PNM_GET1(p_png) & 0xff;
55 - } else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
56 + } else if (color_type == PNG_COLOR_TYPE_PALETTE) {
57 unsigned int paletteIndex;
59 paletteIndex = lookupColorAlpha(caht, &p, &alpha_mask[col]);
61 paletteIndex = ppm_lookupcolor(cht, &p);
63 - } else if (info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
64 - info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
65 + } else if (color_type == PNG_COLOR_TYPE_RGB ||
66 + color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
68 *pp++ = PPM_GETR(p_png) >> 8;
69 *pp++ = PPM_GETR(p_png) & 0xff;
70 @@ -2169,7 +2158,7 @@ makePngLine(png_byte * const l
72 pm_error("INTERNAL ERROR: undefined color_type");
74 - if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) {
75 + if (color_type & PNG_COLOR_MASK_ALPHA) {
76 int const png_alphaval = (int)
77 alpha_mask[col] * (float) png_maxval / maxval + 0.5;
79 @@ -2226,7 +2215,7 @@ writeRaster(png_struct * const p
81 makePngLine(line, xelrow, cols, maxval,
82 alpha, alpha ? alpha_mask[row] : NULL,
83 - cht, caht, info_ptr, png_maxval, depth);
84 + cht, caht, png_ptr, info_ptr, png_maxval, depth);
86 png_write_row(png_ptr, line);
88 @@ -2238,12 +2227,12 @@ writeRaster(png_struct * const p
91 doGamaChunk(struct cmdlineInfo const cmdline,
92 + png_struct * const png_ptr,
93 png_info * const info_ptr) {
95 if (cmdline.gammaSpec) {
97 - info_ptr->valid |= PNG_INFO_gAMA;
98 - info_ptr->gamma = cmdline.gamma;
99 + png_set_gAMA(png_ptr, info_ptr, cmdline.gamma);
103 @@ -2251,20 +2240,16 @@ doGamaChunk(struct cmdlineInfo const cmd
106 doChrmChunk(struct cmdlineInfo const cmdline,
107 + png_struct * const png_ptr,
108 png_info * const info_ptr) {
110 if (cmdline.rgbSpec) {
112 - info_ptr->valid |= PNG_INFO_cHRM;
114 - info_ptr->x_white = cmdline.rgb.wx;
115 - info_ptr->y_white = cmdline.rgb.wy;
116 - info_ptr->x_red = cmdline.rgb.rx;
117 - info_ptr->y_red = cmdline.rgb.ry;
118 - info_ptr->x_green = cmdline.rgb.gx;
119 - info_ptr->y_green = cmdline.rgb.gy;
120 - info_ptr->x_blue = cmdline.rgb.bx;
121 - info_ptr->y_blue = cmdline.rgb.by;
122 + png_set_cHRM(png_ptr, info_ptr,
123 + cmdline.rgb.wx, cmdline.rgb.wy,
124 + cmdline.rgb.rx, cmdline.rgb.ry,
125 + cmdline.rgb.gx, cmdline.rgb.gy,
126 + cmdline.rgb.bx, cmdline.rgb.by);
130 @@ -2272,15 +2257,13 @@ doChrmChunk(struct cmdlineInfo const cmd
133 doPhysChunk(struct cmdlineInfo const cmdline,
134 + png_struct * const png_ptr,
135 png_info * const info_ptr) {
137 if (cmdline.sizeSpec) {
139 - info_ptr->valid |= PNG_INFO_pHYs;
141 - info_ptr->x_pixels_per_unit = cmdline.size.x;
142 - info_ptr->y_pixels_per_unit = cmdline.size.y;
143 - info_ptr->phys_unit_type = cmdline.size.unit;
144 + png_set_pHYs(png_ptr, info_ptr,
145 + cmdline.size.x, cmdline.size.y, cmdline.size.unit);
149 @@ -2289,26 +2272,29 @@ doPhysChunk(struct cmdlineInfo const cmd
152 doTimeChunk(struct cmdlineInfo const cmdline,
153 + png_struct * const png_ptr,
154 png_info * const info_ptr) {
156 if (cmdline.modtimeSpec) {
158 - info_ptr->valid |= PNG_INFO_tIME;
160 - png_convert_from_time_t(&info_ptr->mod_time, cmdline.modtime);
162 + png_convert_from_time_t(&ptime, cmdline.modtime);
163 + png_set_tIME(png_ptr, info_ptr, &ptime);
170 -doSbitChunk(png_info * const pngInfoP,
171 +doSbitChunk(png_struct * const png_ptr,
172 + png_info * const pngInfoP,
173 xelval const pngMaxval,
176 xelval const alphaMaxval) {
178 - if (pngInfoP->color_type != PNG_COLOR_TYPE_PALETTE &&
179 + png_byte color_type = png_get_color_type(png_ptr, pngInfoP);
180 + if (color_type != PNG_COLOR_TYPE_PALETTE &&
181 (pngMaxval > maxval || (alpha && pngMaxval > alphaMaxval))) {
183 /* We're writing in a bit depth that doesn't match the maxval
184 @@ -2327,27 +2313,27 @@ doSbitChunk(png_info * const pngInfoP,
188 - pngInfoP->valid |= PNG_INFO_sBIT;
192 int const sbitval = pm_maxvaltobits(MIN(maxval, pngMaxval));
194 - if (pngInfoP->color_type & PNG_COLOR_MASK_COLOR) {
195 - pngInfoP->sig_bit.red = sbitval;
196 - pngInfoP->sig_bit.green = sbitval;
197 - pngInfoP->sig_bit.blue = sbitval;
198 + if (color_type & PNG_COLOR_MASK_COLOR) {
199 + sbit.red = sbitval;
200 + sbit.green = sbitval;
201 + sbit.blue = sbitval;
203 - pngInfoP->sig_bit.gray = sbitval;
204 + sbit.gray = sbitval;
207 pm_message("Writing sBIT chunk with bits = %d", sbitval);
209 - if (pngInfoP->color_type & PNG_COLOR_MASK_ALPHA) {
210 - pngInfoP->sig_bit.alpha =
211 + if (color_type & PNG_COLOR_MASK_ALPHA) {
213 pm_maxvaltobits(MIN(alphaMaxval, pngMaxval));
215 - pm_message(" alpha bits = %d", pngInfoP->sig_bit.alpha);
216 + pm_message(" alpha bits = %d", sbit.alpha);
218 + png_set_sBIT(png_ptr, pngInfoP, &sbit);
222 @@ -2628,43 +2614,40 @@ convertpnm(struct cmdlineInfo const cmdl
223 pm_error ("setjmp returns error condition (2)");
226 - png_init_io (png_ptr, stdout);
227 - info_ptr->width = cols;
228 - info_ptr->height = rows;
229 - info_ptr->bit_depth = depth;
234 - info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
235 + color_type = PNG_COLOR_TYPE_PALETTE;
236 else if (pnm_type == PPM_TYPE)
237 - info_ptr->color_type = PNG_COLOR_TYPE_RGB;
238 + color_type = PNG_COLOR_TYPE_RGB;
240 - info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
241 + color_type = PNG_COLOR_TYPE_GRAY;
243 + if (alpha && color_type != PNG_COLOR_TYPE_PALETTE)
244 + color_type |= PNG_COLOR_MASK_ALPHA;
246 - if (alpha && info_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
247 - info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
248 + png_set_IHDR(png_ptr, info_ptr, cols, rows, depth, color_type, cmdline.interlace, 0, 0);
251 - info_ptr->interlace_type = cmdline.interlace;
252 + if (cmdline.interlace)
253 + png_set_interlace_handling(png_ptr);
255 - doGamaChunk(cmdline, info_ptr);
256 + doGamaChunk(cmdline, png_ptr, info_ptr);
258 - doChrmChunk(cmdline, info_ptr);
259 + doChrmChunk(cmdline, png_ptr, info_ptr);
261 - doPhysChunk(cmdline, info_ptr);
262 + doPhysChunk(cmdline, png_ptr, info_ptr);
264 - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
265 + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
267 /* creating PNG palette (PLTE and tRNS chunks) */
269 createPngPalette(palette_pnm, palette_size, maxval,
270 trans_pnm, trans_size, alpha_maxval,
272 - info_ptr->valid |= PNG_INFO_PLTE;
273 - info_ptr->palette = palette;
274 - info_ptr->num_palette = palette_size;
275 + png_set_PLTE(png_ptr, info_ptr, palette, palette_size);
276 if (trans_size > 0) {
277 - info_ptr->valid |= PNG_INFO_tRNS;
278 - info_ptr->TRANS_ALPHA = trans;
279 - info_ptr->num_trans = trans_size; /* omit opaque values */
280 + png_set_tRNS(png_ptr, info_ptr, trans, trans_size, NULL);
282 /* creating hIST chunk */
284 @@ -2690,18 +2673,17 @@ convertpnm(struct cmdlineInfo const cmdl
286 ppm_freecolorhash(cht);
288 - info_ptr->valid |= PNG_INFO_hIST;
289 - info_ptr->hist = histogram;
290 + png_set_hIST(png_ptr, info_ptr, histogram);
292 pm_message("histogram created");
294 } else { /* color_type != PNG_COLOR_TYPE_PALETTE */
295 - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
296 - info_ptr->color_type == PNG_COLOR_TYPE_RGB) {
297 + png_byte color_type = png_get_color_type(png_ptr, info_ptr);
298 + if (color_type == PNG_COLOR_TYPE_GRAY ||
299 + color_type == PNG_COLOR_TYPE_RGB) {
300 if (transparent > 0) {
301 - info_ptr->valid |= PNG_INFO_tRNS;
302 - info_ptr->trans_values =
303 - xelToPngColor_16(transcolor, maxval, png_maxval);
304 + png_color_16 c = xelToPngColor_16(transcolor, maxval, png_maxval);
305 + png_set_tRNS(png_ptr, info_ptr, NULL, 0, &c);
308 /* This is PNG_COLOR_MASK_ALPHA. Transparency will be handled
309 @@ -2709,13 +2691,17 @@ convertpnm(struct cmdlineInfo const cmdl
313 - if (info_ptr->valid && PNG_INFO_tRNS)
314 + png_color_16p trans_colorp = NULL;
315 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
316 + png_get_tRNS(png_ptr, info_ptr, NULL, NULL, &trans_colorp);
318 + if(trans_colorp != NULL)
319 pm_message("Transparent color {gray, red, green, blue} = "
321 - info_ptr->trans_values.gray,
322 - info_ptr->trans_values.red,
323 - info_ptr->trans_values.green,
324 - info_ptr->trans_values.blue);
325 + trans_colorp->gray,
327 + trans_colorp->green,
328 + trans_colorp->blue);
330 pm_message("No transparent color");
332 @@ -2723,29 +2709,29 @@ convertpnm(struct cmdlineInfo const cmdl
335 if (cmdline.background) {
336 - info_ptr->valid |= PNG_INFO_bKGD;
337 - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
338 - info_ptr->background.index = background_index;
340 + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
341 + bkgd.index = background_index;
343 - info_ptr->background =
344 - xelToPngColor_16(backcolor, maxval, png_maxval);
345 + bkgd = xelToPngColor_16(backcolor, maxval, png_maxval);
347 pm_message("Writing bKGD chunk with background color "
348 " {gray, red, green, blue} = {%d, %d, %d, %d}",
349 - info_ptr->background.gray,
350 - info_ptr->background.red,
351 - info_ptr->background.green,
352 - info_ptr->background.blue );
358 + png_set_bKGD(png_ptr, info_ptr, &bkgd);
361 - doSbitChunk(info_ptr, png_maxval, maxval, alpha, alpha_maxval);
362 + doSbitChunk(png_ptr, info_ptr, png_maxval, maxval, alpha, alpha_maxval);
364 /* tEXT and zTXT chunks */
365 if (cmdline.text || cmdline.ztxt)
366 - pnmpng_read_text(info_ptr, tfp, !!cmdline.ztxt, cmdline.verbose);
367 + pnmpng_read_text(png_ptr, info_ptr, tfp, !!cmdline.ztxt, cmdline.verbose);
369 - doTimeChunk(cmdline, info_ptr);
370 + doTimeChunk(cmdline, png_ptr, info_ptr);
372 if (cmdline.filterSetSpec)
373 png_set_filter(png_ptr, 0, cmdline.filterSet);
374 @@ -2755,17 +2741,11 @@ convertpnm(struct cmdlineInfo const cmdl
376 setZlibCompression(png_ptr, cmdline.zlibCompression);
378 + png_init_io (png_ptr, stdout);
380 /* write the png-info struct */
381 png_write_info(png_ptr, info_ptr);
383 - if (cmdline.text || cmdline.ztxt)
384 - /* prevent from being written twice with png_write_end */
385 - info_ptr->num_text = 0;
387 - if (cmdline.modtime)
388 - /* prevent from being written twice with png_write_end */
389 - info_ptr->valid &= ~PNG_INFO_tIME;
391 /* let libpng take care of, e.g., bit-depth conversions */
392 png_set_packing (png_ptr);
394 --- netpbm-10.47.63/converter/other/pngtopnm.c.orig 2016-09-26 18:44:20.000000000 +0200
395 +++ netpbm-10.47.63/converter/other/pngtopnm.c 2016-10-26 20:40:14.913792290 +0200
400 -#if PNG_LIBPNG_VER >= 10500
401 -#error Your PNG library (<png.h>) is incompatible with this Netpbm source code.
402 -#error You need either an older PNG library (older than 1.5) or
403 -#error newer Netpbm source code (at least 10.55)
406 -/* A hack until we can remove direct access to png_info from the program */
407 -#if PNG_LIBPNG_VER >= 10400
408 -#define TRANS_ALPHA trans_alpha
410 -#define TRANS_ALPHA trans
414 enum alpha_handling {ALPHA_NONE, ALPHA_ONLY, ALPHA_MIX};
416 @@ -269,23 +256,25 @@ verifyFileIsPng(FILE * const ifP,
418 computePngLineSize(struct pngx * const pngxP) {
420 - unsigned int const bytesPerSample =
421 - pngxP->info_ptr->bit_depth == 16 ? 2 : 1;
424 + int bit_depth, color_type;
425 + unsigned int bytesPerSample;
426 unsigned int samplesPerPixel;
428 - switch (pngxP->info_ptr->color_type) {
429 + png_get_IHDR(pngxP->png_ptr, pngxP->info_ptr, &width, NULL, &bit_depth, &color_type, NULL, NULL, NULL);
430 + bytesPerSample = (bit_depth == 16) ? 2 : 1;
431 + switch (color_type) {
432 case PNG_COLOR_TYPE_GRAY_ALPHA: samplesPerPixel = 2; break;
433 case PNG_COLOR_TYPE_RGB: samplesPerPixel = 3; break;
434 case PNG_COLOR_TYPE_RGB_ALPHA: samplesPerPixel = 4; break;
435 default: samplesPerPixel = 1;
438 - if (UINT_MAX / bytesPerSample / samplesPerPixel < pngxP->info_ptr->width)
439 + if (UINT_MAX / bytesPerSample / samplesPerPixel < width)
440 pm_error("Width %u of PNG is uncomputably large",
441 - (unsigned int)pngxP->info_ptr->width);
442 + (unsigned int)width);
444 - return pngxP->info_ptr->width * bytesPerSample * samplesPerPixel;
445 + return width * bytesPerSample * samplesPerPixel;
449 @@ -297,15 +286,16 @@ allocPngRaster(struct pngx * const pngxP
450 unsigned int const lineSize = computePngLineSize(pngxP);
452 png_byte ** pngImage;
453 + png_uint_32 height = png_get_image_height(pngxP->png_ptr, pngxP->info_ptr);
456 - MALLOCARRAY(pngImage, pngxP->info_ptr->height);
457 + MALLOCARRAY(pngImage, height);
459 if (pngImage == NULL)
460 pm_error("couldn't allocate space for %u PNG raster rows",
461 - (unsigned int)pngxP->info_ptr->height);
462 + (unsigned int)height);
464 - for (row = 0; row < pngxP->info_ptr->height; ++row) {
465 + for (row = 0; row < height; ++row) {
466 MALLOCARRAY(pngImage[row], lineSize);
467 if (pngImage[row] == NULL)
468 pm_error("couldn't allocate space for %uth row of PNG raster",
469 @@ -322,7 +312,7 @@ freePngRaster(png_byte ** const pngRas
473 - for (row = 0; row < pngxP->info_ptr->height; ++row)
474 + for (row = 0; row < png_get_image_height(pngxP->png_ptr, pngxP->info_ptr); ++row)
475 free(pngRaster[row]);
478 @@ -349,7 +339,7 @@ readPng(struct pngx * const pngxP,
480 allocPngRaster(pngxP, &pngRaster);
482 - if (pngxP->info_ptr->bit_depth < 8)
483 + if (png_get_bit_depth(pngxP->png_ptr, pngxP->info_ptr) < 8)
484 png_set_packing(pngxP->png_ptr);
486 png_read_image(pngxP->png_ptr, pngRaster);
487 @@ -445,31 +435,34 @@ saveText(struct pngx * const pngxP,
490 png_info * const info_ptr = pngxP->info_ptr;
496 - for (i = 0 ; i < info_ptr->num_text; ++i) {
497 + png_get_text(pngxP->png_ptr, info_ptr, &text, &num_text);
499 + for (i = 0 ; i < num_text; ++i) {
503 - while (info_ptr->text[i].key[j] != '\0' &&
504 - info_ptr->text[i].key[j] != ' ')
505 + while (text[i].key[j] != '\0' &&
506 + text[i].key[j] != ' ')
509 - if (info_ptr->text[i].key[j] != ' ') {
510 - fprintf(tfP, "%s", info_ptr->text[i].key);
511 - for (j = strlen (info_ptr->text[i].key); j < 15; ++j)
512 + if (text[i].key[j] != ' ') {
513 + fprintf(tfP, "%s", text[i].key);
514 + for (j = strlen (text[i].key); j < 15; ++j)
517 - fprintf(tfP, "\"%s\"", info_ptr->text[i].key);
518 - for (j = strlen (info_ptr->text[i].key); j < 13; ++j)
519 + fprintf(tfP, "\"%s\"", text[i].key);
520 + for (j = strlen (text[i].key); j < 13; ++j)
523 putc(' ', tfP); /* at least one space between key and text */
525 - for (j = 0; j < info_ptr->text[i].text_length; ++j) {
526 - putc(info_ptr->text[i].text[j], tfP);
527 - if (info_ptr->text[i].text[j] == '\n') {
528 + for (j = 0; j < text[i].text_length; ++j) {
529 + putc(text[i].text[j], tfP);
530 + if (text[i].text[j] == '\n') {
532 for (k = 0; k < 16; ++k)
534 @@ -489,21 +482,23 @@ showTime(struct pngx * const pngxP) {
535 "July", "August", "September", "October", "November", "December"
538 - if (pngxP->info_ptr->valid & PNG_INFO_tIME) {
539 - if (pngxP->info_ptr->mod_time.month < 1 ||
540 - pngxP->info_ptr->mod_time.month >= ARRAY_SIZE(month)) {
541 + if (png_get_valid(pngxP->png_ptr, pngxP->info_ptr, PNG_INFO_tIME)) {
542 + png_timep mod_timep;
543 + png_get_tIME(pngxP->png_ptr, pngxP->info_ptr, &mod_timep);
544 + if (mod_timep->month < 1 ||
545 + mod_timep->month >= ARRAY_SIZE(month)) {
546 pm_message("tIME chunk in PNG input is invalid; "
547 "modification time of image is unknown. "
548 "The month value, which should be in the range "
549 - "1-12, is %u", pngxP->info_ptr->mod_time.month);
550 + "1-12, is %u", mod_timep->month);
552 pm_message("modification time: %02d %s %d %02d:%02d:%02d",
553 - pngxP->info_ptr->mod_time.day,
554 - month[pngxP->info_ptr->mod_time.month],
555 - pngxP->info_ptr->mod_time.year,
556 - pngxP->info_ptr->mod_time.hour,
557 - pngxP->info_ptr->mod_time.minute,
558 - pngxP->info_ptr->mod_time.second);
560 + month[mod_timep->month],
564 + mod_timep->second);
568 @@ -516,7 +511,7 @@ dumpPngInfo(struct pngx * const pngxP) {
569 const char *type_string;
570 const char *filter_string;
572 - switch (info_ptr->color_type) {
573 + switch (png_get_color_type(pngxP->png_ptr, info_ptr)) {
574 case PNG_COLOR_TYPE_GRAY:
575 type_string = "gray";
577 @@ -538,90 +533,106 @@ dumpPngInfo(struct pngx * const pngxP) {
581 - switch (info_ptr->filter_type) {
582 + switch (png_get_filter_type(pngxP->png_ptr, info_ptr)) {
583 case PNG_FILTER_TYPE_BASE:
584 asprintfN(&filter_string, "base filter");
587 asprintfN(&filter_string, "unknown filter type %d",
588 - info_ptr->filter_type);
589 + png_get_filter_type(pngxP->png_ptr, info_ptr));
593 + png_uint_32 width, height;
595 + png_get_IHDR(pngxP->png_ptr, pngxP->info_ptr, &width, &height, &bit_depth, NULL, NULL, NULL, NULL);
596 pm_message("reading a %ldw x %ldh image, %d bit%s",
597 - info_ptr->width, info_ptr->height,
598 - info_ptr->bit_depth, info_ptr->bit_depth > 1 ? "s" : "");
599 + (long)width, (long)height,
600 + bit_depth, bit_depth > 1 ? "s" : "");
602 pm_message("%s, %s, %s",
604 - info_ptr->interlace_type ?
605 + png_get_interlace_type(pngxP->png_ptr, info_ptr) ?
606 "Adam7 interlaced" : "not interlaced",
609 + png_color_16p bkgp;
610 + if(png_get_bKGD(pngxP->png_ptr, info_ptr, &bkgp) && (bkgp != NULL))
611 pm_message("background {index, gray, red, green, blue} = "
612 "{%d, %d, %d, %d, %d}",
613 - info_ptr->background.index,
614 - info_ptr->background.gray,
615 - info_ptr->background.red,
616 - info_ptr->background.green,
617 - info_ptr->background.blue);
625 strfree(filter_string);
627 - if (info_ptr->valid & PNG_INFO_tRNS)
628 + if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_tRNS)) {
630 + png_get_tRNS(pngxP->png_ptr, info_ptr, NULL, &num_trans, NULL);
631 pm_message("tRNS chunk (transparency): %u entries",
632 - info_ptr->num_trans);
636 pm_message("tRNS chunk (transparency): not present");
638 - if (info_ptr->valid & PNG_INFO_gAMA)
639 - pm_message("gAMA chunk (image gamma): gamma = %4.2f", info_ptr->gamma);
641 + if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_gAMA)) {
643 + png_get_gAMA(pngxP->png_ptr, info_ptr, &gamma);
644 + pm_message("gAMA chunk (image gamma): gamma = %4.2f", gamma);
646 pm_message("gAMA chunk (image gamma): not present");
648 - if (info_ptr->valid & PNG_INFO_sBIT)
649 + if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_sBIT))
650 pm_message("sBIT chunk: present");
652 pm_message("sBIT chunk: not present");
654 - if (info_ptr->valid & PNG_INFO_cHRM)
655 + if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_cHRM))
656 pm_message("cHRM chunk: present");
658 pm_message("cHRM chunk: not present");
660 - if (info_ptr->valid & PNG_INFO_PLTE)
661 - pm_message("PLTE chunk: %d entries", info_ptr->num_palette);
663 + if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_PLTE)) {
664 + png_colorp palette;
666 + png_get_PLTE(pngxP->png_ptr, info_ptr, &palette, &num_palette);
667 + pm_message("PLTE chunk: %d entries", num_palette);
669 pm_message("PLTE chunk: not present");
671 - if (info_ptr->valid & PNG_INFO_bKGD)
672 + if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_bKGD))
673 pm_message("bKGD chunk: present");
675 pm_message("bKGD chunk: not present");
677 - if (info_ptr->valid & PNG_INFO_PLTE)
678 + if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_hIST))
679 pm_message("hIST chunk: present");
681 pm_message("hIST chunk: not present");
683 - if (info_ptr->valid & PNG_INFO_pHYs)
684 + if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_pHYs))
685 pm_message("pHYs chunk: present");
687 pm_message("pHYs chunk: not present");
689 - if (info_ptr->valid & PNG_INFO_oFFs)
690 + if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_oFFs))
691 pm_message("oFFs chunk: present");
693 pm_message("oFFs chunk: not present");
695 - if (info_ptr->valid & PNG_INFO_tIME)
696 + if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_tIME))
697 pm_message("tIME chunk: present");
699 pm_message("tIME chunk: not present");
701 - if (info_ptr->valid & PNG_INFO_pCAL)
702 + if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_pCAL))
703 pm_message("pCAL chunk: present");
705 pm_message("pCAL chunk: not present");
707 - if (info_ptr->valid & PNG_INFO_sRGB)
708 + if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_sRGB))
709 pm_message("sRGB chunk: present");
711 pm_message("sRGB chunk: not present");
712 @@ -675,7 +686,7 @@ isTransparentColor(pngcolor const c
713 pixels, and just do it ourselves.
716 - switch (pngxP->info_ptr->color_type) {
717 + switch (png_get_color_type(pngxP->png_ptr, pngxP->info_ptr)) {
718 case PNG_COLOR_TYPE_GRAY:
719 retval = color.r == gamma_correct(transColorP->gray, totalgamma);
721 @@ -702,9 +713,11 @@ setupGammaCorrection(struct pngx * const
725 - if (pngxP->info_ptr->valid & PNG_INFO_gAMA)
726 - imageGamma = pngxP->info_ptr->gamma;
728 + if (png_get_valid(pngxP->png_ptr, pngxP->info_ptr, PNG_INFO_gAMA)) {
730 + png_get_gAMA(pngxP->png_ptr, pngxP->info_ptr, &gamma);
731 + imageGamma = gamma;
734 pm_message("PNG doesn't specify image gamma. Assuming 1.0");
736 @@ -722,7 +735,7 @@ setupGammaCorrection(struct pngx * const
737 /* in case of gamma-corrections, sBIT's as in the
738 PNG-file are not valid anymore
740 - pngxP->info_ptr->valid &= ~PNG_INFO_sBIT;
741 + png_set_invalid(pngxP->png_ptr, pngxP->info_ptr, PNG_INFO_sBIT);
743 pm_message("image gamma is %4.2f, "
744 "converted for display gamma of %4.2f",
745 @@ -734,20 +747,23 @@ setupGammaCorrection(struct pngx * const
749 -paletteHasPartialTransparency(png_info * const info_ptr) {
750 +paletteHasPartialTransparency(png_struct * const png_ptr, png_info * const info_ptr) {
754 - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
755 - if (info_ptr->valid & PNG_INFO_tRNS) {
756 + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
757 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
761 + png_bytep trans_alpha;
762 + png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, NULL);
764 for (i = 0, foundGray = FALSE;
765 - i < info_ptr->num_trans && !foundGray;
766 + i < num_trans && !foundGray;
768 - if (info_ptr->TRANS_ALPHA[i] != 0 &&
769 - info_ptr->TRANS_ALPHA[i] != maxval) {
770 + if (trans_alpha[i] != 0 &&
771 + trans_alpha[i] != maxval) {
775 @@ -777,13 +793,14 @@ setupSignificantBits(struct pngx *
776 png_info * const info_ptr = pngxP->info_ptr;
778 /* Initial assumption of maxval */
779 - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
780 + png_byte color_type = png_get_color_type(pngxP->png_ptr, info_ptr);
781 + if (color_type == PNG_COLOR_TYPE_PALETTE) {
782 if (alpha == ALPHA_ONLY) {
783 - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
784 - info_ptr->color_type == PNG_COLOR_TYPE_RGB)
785 + if (color_type == PNG_COLOR_TYPE_GRAY ||
786 + color_type == PNG_COLOR_TYPE_RGB)
787 /* The alpha mask will be all opaque, so maxval 1 is plenty */
789 - else if (paletteHasPartialTransparency(info_ptr))
790 + else if (paletteHasPartialTransparency(pngxP->png_ptr, info_ptr))
791 /* Use same maxval as PNG transparency palette for simplicity*/
794 @@ -793,7 +810,7 @@ setupSignificantBits(struct pngx *
795 /* Use same maxval as PNG palette for simplicity */
798 - *maxvalP = (1l << info_ptr->bit_depth) - 1;
799 + *maxvalP = (1l << png_get_bit_depth(pngxP->png_ptr, info_ptr)) - 1;
802 /* sBIT handling is very tricky. If we are extracting only the
803 @@ -806,20 +823,25 @@ setupSignificantBits(struct pngx *
807 - if (info_ptr->valid & PNG_INFO_sBIT) {
808 + if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_sBIT)) {
809 + png_color_8p sig_bit;
810 + png_get_sBIT(pngxP->png_ptr, info_ptr, &sig_bit);
813 - if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
814 - info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
815 + if (color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
816 + color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
818 - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
819 - (info_ptr->valid & PNG_INFO_tRNS)) {
820 + if (color_type == PNG_COLOR_TYPE_PALETTE &&
821 + (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_tRNS))) {
823 + png_bytep trans_alpha;
828 - for (i = 0; i < info_ptr->num_trans; ++i)
829 - if (info_ptr->TRANS_ALPHA[i] != 0 && info_ptr->TRANS_ALPHA[i] != 255) {
830 + png_get_tRNS(pngxP->png_ptr, info_ptr, &trans_alpha, &num_trans, NULL);
831 + for (i = 0; i < num_trans; ++i)
832 + if (trans_alpha[i] != 0 && trans_alpha[i] != 255) {
836 @@ -830,70 +852,73 @@ setupSignificantBits(struct pngx *
837 /* else fall though to normal case */
840 - if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
841 - info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
842 - info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
843 - (info_ptr->sig_bit.red != info_ptr->sig_bit.green ||
844 - info_ptr->sig_bit.red != info_ptr->sig_bit.blue) &&
845 + if ((color_type == PNG_COLOR_TYPE_PALETTE ||
846 + color_type == PNG_COLOR_TYPE_RGB ||
847 + color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
848 + (sig_bit->red != sig_bit->green ||
849 + sig_bit->red != sig_bit->blue) &&
850 alpha == ALPHA_NONE) {
851 pm_message("This program cannot handle "
852 "different bit depths for color channels");
853 pm_message("writing file with %d bit resolution",
854 - info_ptr->bit_depth);
855 + png_get_bit_depth(pngxP->png_ptr, info_ptr));
856 *errorLevelP = PNMTOPNG_WARNING_LEVEL;
858 - if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) &&
859 - (info_ptr->sig_bit.red < 255)) {
860 + if ((color_type == PNG_COLOR_TYPE_PALETTE) &&
861 + (sig_bit->red < 255)) {
863 - for (i = 0; i < info_ptr->num_palette; ++i) {
864 - info_ptr->palette[i].red >>=
865 - (8 - info_ptr->sig_bit.red);
866 - info_ptr->palette[i].green >>=
867 - (8 - info_ptr->sig_bit.green);
868 - info_ptr->palette[i].blue >>=
869 - (8 - info_ptr->sig_bit.blue);
870 + png_colorp palette;
872 + png_get_PLTE(pngxP->png_ptr, info_ptr, &palette, &num_palette);
873 + for (i = 0; i < num_palette; ++i) {
875 + (8 - sig_bit->red);
876 + palette[i].green >>=
877 + (8 - sig_bit->green);
878 + palette[i].blue >>=
879 + (8 - sig_bit->blue);
881 - *maxvalP = (1l << info_ptr->sig_bit.red) - 1;
882 + *maxvalP = (1l << sig_bit->red) - 1;
884 pm_message ("image has fewer significant bits, "
885 "writing file with %d bits per channel",
886 - info_ptr->sig_bit.red);
889 - if ((info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
890 - info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
891 - (info_ptr->sig_bit.red < info_ptr->bit_depth)) {
892 - png_set_shift(pngxP->png_ptr, &(info_ptr->sig_bit));
893 - *maxvalP = (1l << info_ptr->sig_bit.red) - 1;
894 + if ((color_type == PNG_COLOR_TYPE_RGB ||
895 + color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
896 + (sig_bit->red < png_get_bit_depth(pngxP->png_ptr, info_ptr))) {
897 + png_set_shift(pngxP->png_ptr, sig_bit);
898 + *maxvalP = (1l << sig_bit->red) - 1;
900 pm_message("image has fewer significant bits, "
901 "writing file with %d "
903 - info_ptr->sig_bit.red);
906 - if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
907 - info_ptr->color_type ==
908 + if ((color_type == PNG_COLOR_TYPE_GRAY ||
910 PNG_COLOR_TYPE_GRAY_ALPHA) &&
911 - (info_ptr->sig_bit.gray < info_ptr->bit_depth)) {
912 - png_set_shift(pngxP->png_ptr, &info_ptr->sig_bit);
913 - *maxvalP = (1l << info_ptr->sig_bit.gray) - 1;
914 + (sig_bit->gray < png_get_bit_depth(pngxP->png_ptr, info_ptr))) {
915 + png_set_shift(pngxP->png_ptr, sig_bit);
916 + *maxvalP = (1l << sig_bit->gray) - 1;
918 pm_message("image has fewer significant bits, "
919 "writing file with %d bits",
920 - info_ptr->sig_bit.gray);
927 - if ((info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
928 - info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) &&
929 - (info_ptr->sig_bit.gray < info_ptr->bit_depth)) {
930 - png_set_shift(pngxP->png_ptr, &info_ptr->sig_bit);
931 + if ((color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
932 + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) &&
933 + (sig_bit->gray < png_get_bit_depth(pngxP->png_ptr, info_ptr))) {
934 + png_set_shift(pngxP->png_ptr, sig_bit);
936 pm_message ("image has fewer significant bits, "
937 "writing file with %d bits",
938 - info_ptr->sig_bit.alpha);
939 - *maxvalP = (1l << info_ptr->sig_bit.alpha) - 1;
941 + *maxvalP = (1l << sig_bit->alpha) - 1;
945 @@ -908,18 +933,23 @@ imageHasColor(struct pngx * const pngxP)
949 - if (pngxP->info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
950 - pngxP->info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
951 + png_byte color_type = png_get_color_type(pngxP->png_ptr, pngxP->info_ptr);
952 + if (color_type == PNG_COLOR_TYPE_GRAY ||
953 + color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
956 - else if (pngxP->info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
957 + else if (color_type == PNG_COLOR_TYPE_PALETTE) {
960 + png_colorp palette;
963 + png_get_PLTE(pngxP->png_ptr, pngxP->info_ptr, &palette, &num_palette);
965 for (i = 0, foundColor = FALSE;
966 - i < pngxP->info_ptr->num_palette && !foundColor;
967 + i < num_palette && !foundColor;
969 - if (iscolor(pngxP->info_ptr->palette[i]))
970 + if (iscolor(palette[i]))
974 @@ -974,19 +1004,24 @@ getBackgroundColor(struct pngx * const p
975 bgColorP->g = PPM_GETG(backcolor);
976 bgColorP->b = PPM_GETB(backcolor);
978 - } else if (pngxP->info_ptr->valid & PNG_INFO_bKGD) {
979 + } else if (png_get_valid(pngxP->png_ptr, pngxP->info_ptr, PNG_INFO_bKGD)) {
980 + png_color_16p background;
981 + png_get_bKGD(pngxP->png_ptr, pngxP->info_ptr, &background);
982 /* didn't manage to get libpng to work (bugs?) concerning background
983 processing, therefore we do our own.
985 - switch (pngxP->info_ptr->color_type) {
986 + switch (png_get_color_type(pngxP->png_ptr, pngxP->info_ptr)) {
987 case PNG_COLOR_TYPE_GRAY:
988 case PNG_COLOR_TYPE_GRAY_ALPHA:
989 bgColorP->r = bgColorP->g = bgColorP->b =
990 - gamma_correct(pngxP->info_ptr->background.gray, totalgamma);
991 + gamma_correct(background->gray, totalgamma);
993 case PNG_COLOR_TYPE_PALETTE: {
994 + png_colorp palette;
996 + png_get_PLTE(pngxP->png_ptr, pngxP->info_ptr, &palette, &num_palette);
997 png_color const rawBgcolor =
998 - pngxP->info_ptr->palette[pngxP->info_ptr->background.index];
999 + palette[background->index];
1000 bgColorP->r = gamma_correct(rawBgcolor.red, totalgamma);
1001 bgColorP->g = gamma_correct(rawBgcolor.green, totalgamma);
1002 bgColorP->b = gamma_correct(rawBgcolor.blue, totalgamma);
1003 @@ -994,7 +1029,7 @@ getBackgroundColor(struct pngx * const p
1005 case PNG_COLOR_TYPE_RGB:
1006 case PNG_COLOR_TYPE_RGB_ALPHA: {
1007 - png_color_16 const rawBgcolor = pngxP->info_ptr->background;
1008 + png_color_16 const rawBgcolor = *background;
1010 bgColorP->r = gamma_correct(rawBgcolor.red, totalgamma);
1011 bgColorP->g = gamma_correct(rawBgcolor.green, totalgamma);
1012 @@ -1013,10 +1048,12 @@ static void
1013 warnNonsquarePixels(struct pngx * const pngxP,
1014 int * const errorLevelP) {
1016 - if (pngxP->info_ptr->valid & PNG_INFO_pHYs) {
1017 + if (png_get_valid(pngxP->png_ptr, pngxP->info_ptr, PNG_INFO_pHYs)) {
1018 + png_uint_32 x_pixels_per_unit, y_pixels_per_unit;
1019 + png_get_pHYs(pngxP->png_ptr, pngxP->info_ptr, &x_pixels_per_unit, &y_pixels_per_unit, NULL);
1021 - (float)pngxP->info_ptr->x_pixels_per_unit /
1022 - pngxP->info_ptr->y_pixels_per_unit;
1023 + (float)x_pixels_per_unit /
1024 + y_pixels_per_unit;
1027 pm_message ("warning - non-square pixels; "
1028 @@ -1030,7 +1067,7 @@ warnNonsquarePixels(struct pngx * const
1032 -#define GET_PNG_VAL(p) get_png_val(&(p), pngxP->info_ptr->bit_depth)
1033 +#define GET_PNG_VAL(p) get_png_val(&(p), png_get_bit_depth(pngxP->png_ptr, pngxP->info_ptr))
1037 @@ -1048,8 +1085,8 @@ makeXelRow(xel * const xel
1040 pngPixelP = &pngRasterRow[0]; /* initial value */
1041 - for (col = 0; col < pngxP->info_ptr->width; ++col) {
1042 - switch (pngxP->info_ptr->color_type) {
1043 + for (col = 0; col < png_get_image_width(pngxP->png_ptr, pngxP->info_ptr); ++col) {
1044 + switch (png_get_color_type(pngxP->png_ptr, pngxP->info_ptr)) {
1045 case PNG_COLOR_TYPE_GRAY: {
1047 fgColor.r = fgColor.g = fgColor.b = GET_PNG_VAL(pngPixelP);
1048 @@ -1071,7 +1108,15 @@ makeXelRow(xel * const xel
1050 case PNG_COLOR_TYPE_PALETTE: {
1051 png_uint_16 const index = GET_PNG_VAL(pngPixelP);
1052 - png_color const paletteColor = pngxP->info_ptr->palette[index];
1053 + png_color paletteColor;
1054 + png_colorp palette;
1055 + png_bytep trans_alpha;
1056 + int num_palette, num_trans;
1057 + bool trans_valid = png_get_valid(pngxP->png_ptr, pngxP->info_ptr, PNG_INFO_tRNS);
1058 + png_get_PLTE(pngxP->png_ptr, pngxP->info_ptr, &palette, &num_palette);
1060 + png_get_tRNS(pngxP->png_ptr, pngxP->info_ptr, &trans_alpha, &num_trans, NULL);
1061 + paletteColor = palette[index];
1065 @@ -1080,9 +1125,9 @@ makeXelRow(xel * const xel
1066 fgColor.b = paletteColor.blue;
1068 setXel(&xelrow[col], fgColor, bgColor, alphaHandling,
1069 - (pngxP->info_ptr->valid & PNG_INFO_tRNS) &&
1070 - index < pngxP->info_ptr->num_trans ?
1071 - pngxP->info_ptr->TRANS_ALPHA[index] : maxval);
1073 + index < num_trans ?
1074 + trans_alpha[index] : maxval);
1078 @@ -1112,13 +1157,20 @@ makeXelRow(xel * const xel
1081 pm_error("unknown PNG color type: %d",
1082 - pngxP->info_ptr->color_type);
1083 + png_get_color_type(pngxP->png_ptr, pngxP->info_ptr));
1090 +static png_bytep get_png_trans_alpha(struct pngx * const pngxP)
1092 + png_bytep trans_alpha;
1093 + png_get_tRNS(pngxP->png_ptr, pngxP->info_ptr, &trans_alpha, NULL, NULL);
1094 + return trans_alpha;
1098 writePnm(FILE * const ofP,
1099 xelval const maxval,
1100 @@ -1142,6 +1194,8 @@ writePnm(FILE * const ofP,
1104 + png_uint_32 width = png_get_image_width(pngxP->png_ptr, pngxP->info_ptr),
1105 + height = png_get_image_height(pngxP->png_ptr, pngxP->info_ptr);
1108 pm_message("writing a %s file (maxval=%u)",
1109 @@ -1151,17 +1205,17 @@ writePnm(FILE * const ofP,
1113 - xelrow = pnm_allocrow(pngxP->info_ptr->width);
1114 + xelrow = pnm_allocrow(width);
1116 pnm_writepnminit(stdout,
1117 - pngxP->info_ptr->width, pngxP->info_ptr->height, maxval,
1118 + width, height, maxval,
1119 pnmType, plainFalse);
1121 - for (row = 0; row < pngxP->info_ptr->height; ++row) {
1122 + for (row = 0; row < height; ++row) {
1123 makeXelRow(xelrow, maxval, pnmType, pngxP, pngRaster[row], bgColor,
1124 alphaHandling, totalgamma);
1126 - pnm_writepnmrow(ofP, xelrow, pngxP->info_ptr->width, maxval,
1127 + pnm_writepnmrow(ofP, xelrow, width, maxval,
1128 pnmType, plainFalse);
1130 pnm_freerow (xelrow);
1131 --- netpbm-10.35.83/converter/other/pngtxt.c.orig 2006-08-19 05:12:28.000000000 +0200
1132 +++ netpbm-10.35.83/converter/other/pngtxt.c 2012-01-29 09:59:22.463431985 +0100
1137 -pnmpng_read_text (png_info * const info_ptr,
1138 +pnmpng_read_text (png_struct * const png_ptr,
1139 + png_info * const info_ptr,
1142 bool const verbose) {
1143 @@ -250,15 +251,16 @@
1144 unsigned int commentIdx;
1148 unsigned int allocatedComments;
1149 - /* Number of entries currently allocated for the info_ptr->text
1150 + /* Number of entries currently allocated for the text
1154 allocatedComments = 256; /* initial value */
1156 - MALLOCARRAY(info_ptr->text, allocatedComments);
1157 - if (info_ptr->text == NULL)
1158 + MALLOCARRAY(text, allocatedComments);
1160 pm_error("unable to allocate memory for comment array");
1164 if (lineLength == 0) {
1165 /* skip this empty line */
1167 - handleArrayAllocation(&info_ptr->text, &allocatedComments,
1168 + handleArrayAllocation(&text, &allocatedComments,
1170 if ((textline[0] != ' ') && (textline[0] != '\t')) {
1171 /* Line doesn't start with white space, which
1174 noCommentsYet = FALSE;
1176 - startComment(&info_ptr->text[commentIdx],
1177 + startComment(&text[commentIdx],
1178 textline, lineLength, ztxt);
1180 /* Line starts with whitespace, which means it is
1181 @@ -295,20 +297,20 @@
1182 pm_error("Invalid comment file format: "
1183 "first line is a continuation line! "
1184 "(It starts with whitespace)");
1185 - continueComment(&info_ptr->text[commentIdx],
1186 + continueComment(&text[commentIdx],
1187 textline, lineLength);
1193 - if (noCommentsYet)
1194 - info_ptr->num_text = 0;
1196 - info_ptr->num_text = commentIdx + 1;
1197 + if (!noCommentsYet)
1198 + png_set_text(png_ptr, info_ptr, text, commentIdx + 1);
1201 - pm_message("%d comments placed in text chunk", info_ptr->num_text);
1202 + pm_message("%d comments placed in text chunk", commentIdx + 1);
1208 --- netpbm-10.35.83/converter/other/pngtxt.h.orig 2006-08-19 05:12:28.000000000 +0200
1209 +++ netpbm-10.35.83/converter/other/pngtxt.h 2012-01-29 09:59:59.566766561 +0100
1214 -pnmpng_read_text (png_info * const info_ptr,
1215 +pnmpng_read_text (png_struct * const png_ptr,
1216 + png_info * const info_ptr,
1219 bool const verbose);
1220 --- netpbm-10.35.83/converter/other/pamrgbatopng.c.orig 2006-08-19 05:12:28.000000000 +0200
1221 +++ netpbm-10.35.83/converter/other/pamrgbatopng.c 2012-01-29 14:02:47.790587693 +0100
1222 @@ -101,10 +101,9 @@
1224 pm_error("Could not allocate PNG info structure");
1226 - infoP->width = pamP->width;
1227 - infoP->height = pamP->height;
1228 - infoP->bit_depth = 8;
1229 - infoP->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
1230 + png_set_IHDR(pngP, infoP,
1231 + pamP->width, pamP->height,
1232 + 8, PNG_COLOR_TYPE_RGB_ALPHA, 0, 0, 0);
1234 png_init_io(pngP, ofP);
1236 --- netpbm-10.35.90/converter/other/tifftopnm.c~ 2006-08-19 05:12:28.000000000 +0200
1237 +++ netpbm-10.35.90/converter/other/tifftopnm.c 2013-10-31 17:58:49.296479893 +0100
1238 @@ -902,14 +902,14 @@
1240 ok = TIFFRGBAImageBegin(&img, tif, stopOnErrorFalse, emsg) ;
1243 + pm_message("%s", emsg);
1244 *statusP = CONV_FAILED;
1247 ok = TIFFRGBAImageGet(&img, raster, cols, rows);
1248 TIFFRGBAImageEnd(&img) ;
1251 + pm_message("%s", emsg);
1252 *statusP = CONV_FAILED;
1254 *statusP = CONV_DONE;
1255 --- netpbm-10.35.90/converter/other/tifftopnm.c~ 2013-10-31 17:59:04.000000000 +0100
1256 +++ netpbm-10.35.90/converter/other/tifftopnm.c 2013-10-31 18:00:05.761780998 +0100
1259 ok = TIFFRGBAImageOK(tif, emsg);
1262 + pm_message("%s", emsg);
1263 *statusP = CONV_UNABLE;
1266 --- netpbm-10.35.90/converter/other/fiasco/pnmtofiasco.c~ 2006-08-19 05:12:28.000000000 +0200
1267 +++ netpbm-10.35.90/converter/other/fiasco/pnmtofiasco.c 2013-10-31 18:02:13.731936837 +0100
1272 - fprintf (stderr, fiasco_get_error_message ());
1273 + fprintf (stderr, "%s", fiasco_get_error_message ());
1274 fprintf (stderr, "\n");
1277 --- netpbm-10.35.90/converter/other/fiasco/params.c~ 2006-08-19 05:12:28.000000000 +0200
1278 +++ netpbm-10.35.90/converter/other/fiasco/params.c 2013-10-31 18:05:00.869560937 +0100
1280 fprintf (stderr, "Usage: %s [OPTION]...%s\n", progname,
1281 non_opt_string ? non_opt_string : " ");
1282 if (synopsis != NULL)
1283 - fprintf (stderr, synopsis);
1284 + fprintf (stderr, "%s", synopsis);
1285 fprintf (stderr, "\n\n");
1286 fprintf (stderr, "Mandatory or optional arguments to long options "
1287 "are mandatory or optional\nfor short options too. "
1288 --- netpbm-10.47.61/converter/pbm/cmuwmtopbm.c.orig 2016-03-27 03:38:28.000000000 +0200
1289 +++ netpbm-10.47.61/converter/pbm/cmuwmtopbm.c 2016-06-08 20:43:31.277330446 +0200
1292 rc = pm_readbiglong(ifP, &l);
1294 - pm_error(initReadError);
1295 + pm_error("%s", initReadError);
1296 if ((uint32_t)l != CMUWM_MAGIC)
1297 pm_error("bad magic number in CMU window manager file");
1298 rc = pm_readbiglong(ifP, &l);
1300 - pm_error(initReadError);
1301 + pm_error("%s", initReadError);
1303 rc = pm_readbiglong(ifP, &l);
1305 - pm_error(initReadError);
1306 + pm_error("%s", initReadError);
1308 rc = pm_readbigshort(ifP, &s);
1310 - pm_error(initReadError);
1311 + pm_error("%s", initReadError);
1315 --- netpbm-10.47.61/converter/pbm/pbmtocmuwm.c.orig 2016-03-27 03:38:28.000000000 +0200
1316 +++ netpbm-10.47.61/converter/pbm/pbmtocmuwm.c 2016-06-08 20:48:55.797316874 +0200
1319 rc = pm_writebiglong(stdout, CMUWM_MAGIC);
1321 - pm_error(initWriteError);
1322 + pm_error("%s", initWriteError);
1323 rc = pm_writebiglong(stdout, cols);
1325 - pm_error(initWriteError);
1326 + pm_error("%s", initWriteError);
1327 rc = pm_writebiglong(stdout, rows);
1329 - pm_error(initWriteError);
1330 + pm_error("%s", initWriteError);
1331 rc = pm_writebigshort(stdout, (short) 1);
1333 - pm_error(initWriteError);
1334 + pm_error("%s", initWriteError);
1338 --- netpbm-10.47.61/converter/other/pngtopam.c.orig 2016-03-27 03:38:28.000000000 +0200
1339 +++ netpbm-10.47.61/converter/other/pngtopam.c 2016-06-10 21:50:14.703243717 +0200
1344 -/* A hack until we can remove direct access to png_info from the program */
1345 -#if PNG_LIBPNG_VER >= 10400
1346 -#define trans_values trans_color
1347 -#define TRANS_ALPHA trans_alpha
1349 -#define TRANS_ALPHA trans
1352 typedef struct _jmpbuf_wrapper {
1355 @@ -268,28 +260,31 @@ static int iscolor (png_color c)
1356 return c.red != c.green || c.green != c.blue;
1359 -static void save_text (png_info *info_ptr, FILE *tfp)
1360 +static void save_text (png_struct *png_ptr, png_info *info_ptr, FILE *tfp)
1366 - for (i = 0 ; i < info_ptr->num_text ; i++) {
1367 + png_get_text(png_ptr, info_ptr, &text, &num_text);
1368 + for (i = 0 ; i < num_text ; i++) {
1370 - while (info_ptr->text[i].key[j] != '\0' && info_ptr->text[i].key[j] != ' ')
1371 + while (text[i].key[j] != '\0' && text[i].key[j] != ' ')
1373 - if (info_ptr->text[i].key[j] != ' ') {
1374 - fprintf (tfp, "%s", info_ptr->text[i].key);
1375 - for (j = strlen (info_ptr->text[i].key) ; j < 15 ; j++)
1376 + if (text[i].key[j] != ' ') {
1377 + fprintf (tfp, "%s", text[i].key);
1378 + for (j = strlen (text[i].key) ; j < 15 ; j++)
1381 - fprintf (tfp, "\"%s\"", info_ptr->text[i].key);
1382 - for (j = strlen (info_ptr->text[i].key) ; j < 13 ; j++)
1383 + fprintf (tfp, "\"%s\"", text[i].key);
1384 + for (j = strlen (text[i].key) ; j < 13 ; j++)
1387 putc (' ', tfp); /* at least one space between key and text */
1389 - for (j = 0 ; j < info_ptr->text[i].text_length ; j++) {
1390 - putc (info_ptr->text[i].text[j], tfp);
1391 - if (info_ptr->text[i].text[j] == '\n')
1392 + for (j = 0 ; j < text[i].text_length ; j++) {
1393 + putc (text[i].text[j], tfp);
1394 + if (text[i].text[j] == '\n')
1395 for (k = 0 ; k < 16 ; k++)
1396 putc ((int)' ', tfp);
1398 @@ -297,25 +292,28 @@ static void save_text (png_info *info_pt
1402 -static void show_time (png_info *info_ptr)
1403 +static void show_time (png_struct *png_ptr, png_info *info_ptr)
1405 static const char * const month[] = {
1406 "", "January", "February", "March", "April", "May", "June",
1407 "July", "August", "September", "October", "November", "December"
1410 - if (info_ptr->valid & PNG_INFO_tIME) {
1411 - if (info_ptr->mod_time.month < 1 ||
1412 - info_ptr->mod_time.month >= ARRAY_SIZE(month)) {
1413 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tIME)) {
1414 + png_timep mod_timep;
1416 + png_get_tIME(png_ptr, info_ptr, &mod_timep);
1417 + if (mod_timep->month < 1 ||
1418 + mod_timep->month >= ARRAY_SIZE(month)) {
1419 pm_message("tIME chunk in PNG input is invalid; "
1420 "modification time of image is unknown. "
1421 "The month value, which should be in the range "
1422 - "1-12, is %u", info_ptr->mod_time.month);
1423 + "1-12, is %u", mod_timep->month);
1425 pm_message ("modification time: %02d %s %d %02d:%02d:%02d",
1426 - info_ptr->mod_time.day, month[info_ptr->mod_time.month],
1427 - info_ptr->mod_time.year, info_ptr->mod_time.hour,
1428 - info_ptr->mod_time.minute, info_ptr->mod_time.second);
1429 + mod_timep->day, month[mod_timep->month],
1430 + mod_timep->year, mod_timep->hour,
1431 + mod_timep->minute, mod_timep->second);
1435 @@ -346,12 +344,12 @@ static void pngtopnm_error_handler (png_
1439 -dump_png_info(png_info *info_ptr) {
1440 +dump_png_info(png_struct *png_ptr, png_info *info_ptr) {
1442 const char *type_string;
1443 const char *filter_string;
1445 - switch (info_ptr->color_type) {
1446 + switch (png_get_color_type(png_ptr, info_ptr)) {
1447 case PNG_COLOR_TYPE_GRAY:
1448 type_string = "gray";
1450 @@ -373,90 +371,106 @@ dump_png_info(png_info *info_ptr) {
1454 - switch (info_ptr->filter_type) {
1455 + switch (png_get_filter_type(png_ptr, info_ptr)) {
1456 case PNG_FILTER_TYPE_BASE:
1457 asprintfN(&filter_string, "base filter");
1460 asprintfN(&filter_string, "unknown filter type %d",
1461 - info_ptr->filter_type);
1462 + png_get_filter_type(png_ptr, info_ptr));
1466 + png_uint_32 width, height;
1468 + png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, NULL, NULL, NULL, NULL);
1469 pm_message("reading a %ldw x %ldh image, %d bit%s",
1470 - info_ptr->width, info_ptr->height,
1471 - info_ptr->bit_depth, info_ptr->bit_depth > 1 ? "s" : "");
1472 + (long)width, (long)height,
1473 + bit_depth, bit_depth > 1 ? "s" : "");
1475 pm_message("%s, %s, %s",
1477 - info_ptr->interlace_type ?
1478 + png_get_interlace_type(png_ptr, info_ptr) ?
1479 "Adam7 interlaced" : "not interlaced",
1482 + png_color_16p bkgp;
1483 + if(png_get_bKGD(png_ptr, info_ptr, &bkgp) && (bkgp != NULL))
1484 pm_message("background {index, gray, red, green, blue} = "
1485 "{%d, %d, %d, %d, %d}",
1486 - info_ptr->background.index,
1487 - info_ptr->background.gray,
1488 - info_ptr->background.red,
1489 - info_ptr->background.green,
1490 - info_ptr->background.blue);
1498 strfree(filter_string);
1500 - if (info_ptr->valid & PNG_INFO_tRNS)
1501 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
1503 + png_get_tRNS(png_ptr, info_ptr, NULL, &num_trans, NULL);
1504 pm_message("tRNS chunk (transparency): %u entries",
1505 - info_ptr->num_trans);
1509 pm_message("tRNS chunk (transparency): not present");
1511 - if (info_ptr->valid & PNG_INFO_gAMA)
1512 - pm_message("gAMA chunk (image gamma): gamma = %4.2f", info_ptr->gamma);
1514 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA)) {
1516 + png_get_gAMA(png_ptr, info_ptr, &gamma);
1517 + pm_message("gAMA chunk (image gamma): gamma = %4.2f", gamma);
1519 pm_message("gAMA chunk (image gamma): not present");
1521 - if (info_ptr->valid & PNG_INFO_sBIT)
1522 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
1523 pm_message("sBIT chunk: present");
1525 pm_message("sBIT chunk: not present");
1527 - if (info_ptr->valid & PNG_INFO_cHRM)
1528 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_cHRM))
1529 pm_message("cHRM chunk: present");
1531 pm_message("cHRM chunk: not present");
1533 - if (info_ptr->valid & PNG_INFO_PLTE)
1534 - pm_message("PLTE chunk: %d entries", info_ptr->num_palette);
1536 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE)) {
1537 + png_colorp palette;
1539 + png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
1540 + pm_message("PLTE chunk: %d entries", num_palette);
1542 pm_message("PLTE chunk: not present");
1544 - if (info_ptr->valid & PNG_INFO_bKGD)
1545 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))
1546 pm_message("bKGD chunk: present");
1548 pm_message("bKGD chunk: not present");
1550 - if (info_ptr->valid & PNG_INFO_hIST)
1551 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_hIST))
1552 pm_message("hIST chunk: present");
1554 pm_message("hIST chunk: not present");
1556 - if (info_ptr->valid & PNG_INFO_pHYs)
1557 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_pHYs))
1558 pm_message("pHYs chunk: present");
1560 pm_message("pHYs chunk: not present");
1562 - if (info_ptr->valid & PNG_INFO_oFFs)
1563 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_oFFs))
1564 pm_message("oFFs chunk: present");
1566 pm_message("oFFs chunk: not present");
1568 - if (info_ptr->valid & PNG_INFO_tIME)
1569 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tIME))
1570 pm_message("tIME chunk: present");
1572 pm_message("tIME chunk: not present");
1574 - if (info_ptr->valid & PNG_INFO_pCAL)
1575 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_pCAL))
1576 pm_message("pCAL chunk: present");
1578 pm_message("pCAL chunk: not present");
1580 - if (info_ptr->valid & PNG_INFO_sRGB)
1581 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sRGB))
1582 pm_message("sRGB chunk: present");
1584 pm_message("sRGB chunk: not present");
1585 @@ -465,44 +479,50 @@ dump_png_info(png_info *info_ptr) {
1589 -computePngLineSize(png_info * const pngInfoP) {
1591 - unsigned int const bytesPerSample = pngInfoP->bit_depth == 16 ? 2 : 1;
1592 +computePngLineSize(png_struct * const pngP, png_info * const pngInfoP) {
1594 + png_uint_32 width;
1595 + int bit_depth, color_type;
1596 + unsigned int bytesPerSample;
1597 unsigned int samplesPerPixel;
1599 - switch (pngInfoP->color_type) {
1600 + png_get_IHDR(pngP, pngInfoP, &width, NULL, &bit_depth, &color_type, NULL, NULL, NULL);
1601 + bytesPerSample = (bit_depth == 16) ? 2 : 1;
1603 + switch (color_type) {
1604 case PNG_COLOR_TYPE_GRAY_ALPHA: samplesPerPixel = 2; break;
1605 case PNG_COLOR_TYPE_RGB: samplesPerPixel = 3; break;
1606 case PNG_COLOR_TYPE_RGB_ALPHA: samplesPerPixel = 4; break;
1607 default: samplesPerPixel = 1;
1610 - if (UINT_MAX / bytesPerSample / samplesPerPixel < pngInfoP->width)
1611 + if (UINT_MAX / bytesPerSample / samplesPerPixel < width)
1612 pm_error("Width %u of PNG is uncomputably large",
1613 - (unsigned int)pngInfoP->width);
1614 + (unsigned int)width);
1616 - return pngInfoP->width * bytesPerSample * samplesPerPixel;
1617 + return width * bytesPerSample * samplesPerPixel;
1623 -allocPngRaster(png_info * const pngInfoP,
1624 +allocPngRaster(png_struct * const pngP,
1625 + png_info * const pngInfoP,
1626 png_byte *** const pngImageP) {
1628 - unsigned int const lineSize = computePngLineSize(pngInfoP);
1629 + unsigned int const lineSize = computePngLineSize(pngP, pngInfoP);
1631 png_byte ** pngImage;
1632 + png_uint_32 height = png_get_image_height(pngP, pngInfoP);
1635 - MALLOCARRAY(pngImage, pngInfoP->height);
1636 + MALLOCARRAY(pngImage, height);
1638 if (pngImage == NULL)
1639 pm_error("couldn't allocate space for %u PNG raster rows",
1640 - (unsigned int)pngInfoP->height);
1641 + (unsigned int)height);
1643 - for (row = 0; row < pngInfoP->height; ++row) {
1644 + for (row = 0; row < height; ++row) {
1645 MALLOCARRAY(pngImage[row], lineSize);
1646 if (pngImage[row] == NULL)
1647 pm_error("couldn't allocate space for %uth row of PNG raster",
1648 @@ -515,11 +535,12 @@ allocPngRaster(png_info * const pngInf
1651 freePngRaster(png_byte ** const pngRaster,
1652 + png_struct* const pngP,
1653 png_info * const pngInfoP) {
1657 - for (row = 0; row < pngInfoP->height; ++row)
1658 + for (row = 0; row < png_get_image_height(pngP, pngInfoP); ++row)
1659 free(pngRaster[row]);
1662 @@ -529,6 +550,7 @@ freePngRaster(png_byte ** const pngRaste
1665 isTransparentColor(pngcolor const color,
1666 + png_struct * const pngP,
1667 png_info * const pngInfoP,
1668 double const totalgamma) {
1669 /*----------------------------------------------------------------------------
1670 @@ -539,8 +561,9 @@ isTransparentColor(pngcolor const colo
1671 -----------------------------------------------------------------------------*/
1674 - if (pngInfoP->valid & PNG_INFO_tRNS) {
1675 - const png_color_16 * const transColorP = &pngInfoP->trans_values;
1676 + if (png_get_valid(pngP, pngInfoP, PNG_INFO_tRNS)) {
1677 + png_color_16 * transColorP;
1678 + png_get_tRNS(pngP, pngInfoP, NULL, NULL, &transColorP);
1680 /* It seems odd that libpng lets you get gamma-corrected pixel
1681 values, but not gamma-corrected transparency or background
1682 @@ -556,7 +579,7 @@ isTransparentColor(pngcolor const colo
1683 pixels, and just do it ourselves.
1686 - switch (pngInfoP->color_type) {
1687 + switch (png_get_color_type(pngP, pngInfoP)) {
1688 case PNG_COLOR_TYPE_GRAY:
1689 retval = color.r == gamma_correct(transColorP->gray, totalgamma);
1691 @@ -603,9 +626,11 @@ setupGammaCorrection(png_struct * const
1692 *totalgammaP = -1.0;
1695 - if (info_ptr->valid & PNG_INFO_gAMA)
1696 - imageGamma = info_ptr->gamma;
1698 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA)) {
1700 + png_get_gAMA(png_ptr, info_ptr, &gamma);
1701 + imageGamma = gamma;
1704 pm_message("PNG doesn't specify image gamma. Assuming 1.0");
1706 @@ -623,7 +648,7 @@ setupGammaCorrection(png_struct * const
1707 /* in case of gamma-corrections, sBIT's as in the
1708 PNG-file are not valid anymore
1710 - info_ptr->valid &= ~PNG_INFO_sBIT;
1711 + png_set_invalid(png_ptr, info_ptr, PNG_INFO_sBIT);
1713 pm_message("image gamma is %4.2f, "
1714 "converted for display gamma of %4.2f",
1715 @@ -635,20 +660,23 @@ setupGammaCorrection(png_struct * const
1719 -paletteHasPartialTransparency(png_info * const info_ptr) {
1720 +paletteHasPartialTransparency(png_struct * const png_ptr, png_info * const info_ptr) {
1724 - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
1725 - if (info_ptr->valid & PNG_INFO_tRNS) {
1726 + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
1727 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
1731 + png_bytep trans_alpha;
1732 + png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, NULL);
1734 for (i = 0, foundGray = FALSE;
1735 - i < info_ptr->num_trans && !foundGray;
1736 + i < num_trans && !foundGray;
1738 - if (info_ptr->TRANS_ALPHA[i] != 0 &&
1739 - info_ptr->TRANS_ALPHA[i] != maxval) {
1740 + if (trans_alpha[i] != 0 &&
1741 + trans_alpha[i] != maxval) {
1745 @@ -664,34 +692,44 @@ paletteHasPartialTransparency(png_info *
1749 -getComponentSbitFg(png_info * const pngInfoP,
1750 +getComponentSbitFg(png_struct * const pngP,
1751 + png_info * const pngInfoP,
1752 png_byte * const fgSbitP,
1753 bool * const notUniformP) {
1755 - if (pngInfoP->color_type == PNG_COLOR_TYPE_RGB ||
1756 - pngInfoP->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
1757 - pngInfoP->color_type == PNG_COLOR_TYPE_PALETTE) {
1758 - if (pngInfoP->sig_bit.red == pngInfoP->sig_bit.blue &&
1759 - pngInfoP->sig_bit.red == pngInfoP->sig_bit.green) {
1760 + int color_type = png_get_color_type(pngP, pngInfoP);
1761 + png_color_8p sig_bit;
1762 + png_get_sBIT(pngP, pngInfoP, &sig_bit);
1764 + if (color_type == PNG_COLOR_TYPE_RGB ||
1765 + color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
1766 + color_type == PNG_COLOR_TYPE_PALETTE) {
1768 + if (sig_bit->red == sig_bit->blue &&
1769 + sig_bit->red == sig_bit->green) {
1770 *notUniformP = false;
1771 - *fgSbitP = pngInfoP->sig_bit.red;
1772 + *fgSbitP = sig_bit->red;
1774 *notUniformP = true;
1776 /* It has only a gray channel so it's obviously uniform */
1777 *notUniformP = false;
1778 - *fgSbitP = pngInfoP->sig_bit.gray;
1779 + *fgSbitP = sig_bit->gray;
1786 -getComponentSbit(png_info * const pngInfoP,
1787 +getComponentSbit(png_struct * const pngP,
1788 + png_info * const pngInfoP,
1789 enum alpha_handling const alphaHandling,
1790 png_byte * const componentSbitP,
1791 bool * const notUniformP) {
1793 + png_color_8p sig_bit;
1794 + png_get_sBIT(pngP, pngInfoP, &sig_bit);
1796 switch (alphaHandling) {
1799 @@ -699,26 +737,26 @@ getComponentSbit(png_info * con
1802 *notUniformP = false;
1803 - *componentSbitP = pngInfoP->sig_bit.alpha;
1804 + *componentSbitP = sig_bit->alpha;
1808 /* We aren't going to produce an alpha channel, so we care only
1809 about the uniformity of the foreground channels.
1811 - getComponentSbitFg(pngInfoP, componentSbitP, notUniformP);
1812 + getComponentSbitFg(pngP, pngInfoP, componentSbitP, notUniformP);
1815 /* We care about both the foreground and the alpha */
1819 - getComponentSbitFg(pngInfoP, &fgSbit, &fgNotUniform);
1820 + getComponentSbitFg(pngP, pngInfoP, &fgSbit, &fgNotUniform);
1823 *notUniformP = true;
1825 - if (fgSbit == pngInfoP->sig_bit.alpha) {
1826 + if (fgSbit == sig_bit->alpha) {
1827 *notUniformP = false;
1828 *componentSbitP = fgSbit;
1830 @@ -731,7 +769,8 @@ getComponentSbit(png_info * con
1834 -shiftPalette(png_info * const pngInfoP,
1835 +shiftPalette(png_struct * const pngP,
1836 + png_info * const pngInfoP,
1837 unsigned int const shift) {
1838 /*----------------------------------------------------------------------------
1839 Shift every component of every color in the PNG palette right by
1840 @@ -744,11 +783,14 @@ shiftPalette(png_info * const pngInfoP
1845 - for (i = 0; i < pngInfoP->num_palette; ++i) {
1846 - pngInfoP->palette[i].red >>= (8 - shift);
1847 - pngInfoP->palette[i].green >>= (8 - shift);
1848 - pngInfoP->palette[i].blue >>= (8 - shift);
1850 + png_colorp palette;
1851 + png_get_PLTE(pngP, pngInfoP, &palette, &num_palette);
1853 + for (i = 0; i < num_palette; ++i) {
1854 + palette[i].red >>= (8 - shift);
1855 + palette[i].green >>= (8 - shift);
1856 + palette[i].blue >>= (8 - shift);
1860 @@ -782,12 +824,12 @@ computeMaxvalFromSbit(png_struct *
1861 Meaningless if they aren't all the same (i.e. 'notUniform')
1864 - getComponentSbit(pngInfoP, alphaHandling, &componentSigBit, ¬Uniform);
1865 + getComponentSbit(pngP, pngInfoP, alphaHandling, &componentSigBit, ¬Uniform);
1868 pm_message("This program cannot handle "
1869 "different bit depths for color channels");
1870 - pm_message("writing file with %u bit resolution", pngInfoP->bit_depth);
1871 + pm_message("writing file with %u bit resolution", png_get_bit_depth(pngP, pngInfoP));
1872 *succeededP = false;
1873 *errorlevelP = PNMTOPNG_WARNING_LEVEL;
1874 } else if (componentSigBit > 15) {
1875 @@ -797,22 +839,26 @@ computeMaxvalFromSbit(png_struct *
1876 *succeededP = false;
1877 *errorlevelP = PNMTOPNG_WARNING_LEVEL;
1879 + int color_type = png_get_color_type(pngP, pngInfoP);
1880 if (alphaHandling == ALPHA_MIX &&
1881 - (pngInfoP->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
1882 - pngInfoP->color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
1883 - paletteHasPartialTransparency(pngInfoP)))
1884 + (color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
1885 + color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
1886 + paletteHasPartialTransparency(pngP, pngInfoP)))
1887 *succeededP = false;
1889 - if (componentSigBit < pngInfoP->bit_depth) {
1890 + if (componentSigBit < png_get_bit_depth(pngP, pngInfoP)) {
1891 pm_message("Image has fewer significant bits, "
1892 "writing file with %u bits", componentSigBit);
1893 *maxvalP = (1l << componentSigBit) - 1;
1896 - if (pngInfoP->color_type == PNG_COLOR_TYPE_PALETTE)
1897 - shiftPalette(pngInfoP, componentSigBit);
1899 - png_set_shift(pngP, &pngInfoP->sig_bit);
1900 + if (color_type == PNG_COLOR_TYPE_PALETTE)
1901 + shiftPalette(pngP, pngInfoP, componentSigBit);
1903 + png_color_8p sig_bit;
1904 + png_get_sBIT(pngP, pngInfoP, &sig_bit);
1905 + png_set_shift(pngP, sig_bit);
1908 *succeededP = false;
1910 @@ -838,22 +884,23 @@ setupSignificantBits(png_struct *
1911 -----------------------------------------------------------------------------*/
1914 - if (pngInfoP->valid & PNG_INFO_sBIT)
1915 + if (png_get_valid(pngP, pngInfoP, PNG_INFO_sBIT))
1916 computeMaxvalFromSbit(pngP, pngInfoP, alphaHandling,
1917 maxvalP, &gotItFromSbit, errorlevelP);
1919 gotItFromSbit = false;
1921 if (!gotItFromSbit) {
1922 - if (pngInfoP->color_type == PNG_COLOR_TYPE_PALETTE) {
1923 + int color_type = png_get_color_type(pngP, pngInfoP);
1924 + if (color_type == PNG_COLOR_TYPE_PALETTE) {
1925 if (alphaHandling == ALPHA_ONLY) {
1926 - if (pngInfoP->color_type == PNG_COLOR_TYPE_GRAY ||
1927 - pngInfoP->color_type == PNG_COLOR_TYPE_RGB)
1928 + if (color_type == PNG_COLOR_TYPE_GRAY ||
1929 + color_type == PNG_COLOR_TYPE_RGB)
1930 /* The alpha mask will be all opaque, so maxval 1
1934 - else if (paletteHasPartialTransparency(pngInfoP))
1935 + else if (paletteHasPartialTransparency(pngP, pngInfoP))
1936 /* Use same maxval as PNG transparency palette for
1939 @@ -865,7 +912,7 @@ setupSignificantBits(png_struct *
1940 /* Use same maxval as PNG palette for simplicity */
1943 - *maxvalP = (1l << pngInfoP->bit_depth) - 1;
1944 + *maxvalP = (1l << png_get_bit_depth(pngP, pngInfoP)) - 1;
1948 @@ -873,22 +920,27 @@ setupSignificantBits(png_struct *
1952 -imageHasColor(png_info * const info_ptr) {
1953 +imageHasColor(png_struct * const png_ptr, png_info * const info_ptr) {
1956 + int color_type = png_get_color_type(png_ptr, info_ptr);
1958 - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
1959 - info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
1960 + if (color_type == PNG_COLOR_TYPE_GRAY ||
1961 + color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
1964 - else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
1965 + else if (color_type == PNG_COLOR_TYPE_PALETTE) {
1969 + png_colorp palette;
1971 + png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
1973 for (i = 0, foundColor = FALSE;
1974 - i < info_ptr->num_palette && !foundColor;
1975 + i < num_palette && !foundColor;
1977 - if (iscolor(info_ptr->palette[i]))
1978 + if (iscolor(palette[i]))
1981 retval = foundColor;
1982 @@ -901,7 +953,8 @@ imageHasColor(png_info * const info_ptr)
1986 -determineOutputType(png_info * const pngInfoP,
1987 +determineOutputType(png_struct * const pngP,
1988 + png_info * const pngInfoP,
1989 enum alpha_handling const alphaHandling,
1990 pngcolor const bgColor,
1991 xelval const maxval,
1992 @@ -916,7 +969,7 @@ determineOutputType(png_info *
1994 /* The output is a normal Netpbm image */
1995 bool const outputIsColor =
1996 - imageHasColor(pngInfoP) || !isGrayscale(bgColor);
1997 + imageHasColor(pngP, pngInfoP) || !isGrayscale(bgColor);
1999 if (alphaHandling == ALPHA_IN) {
2000 *formatP = PAM_FORMAT;
2001 @@ -942,7 +995,8 @@ determineOutputType(png_info *
2005 -getBackgroundColor(png_info * const info_ptr,
2006 +getBackgroundColor(png_struct * const png_ptr,
2007 + png_info * const info_ptr,
2008 const char * const requestedColor,
2009 float const totalgamma,
2010 xelval const maxval,
2011 @@ -964,19 +1018,26 @@ getBackgroundColor(png_info * const in
2012 bgColorP->g = PPM_GETG(backcolor);
2013 bgColorP->b = PPM_GETB(backcolor);
2015 - } else if (info_ptr->valid & PNG_INFO_bKGD) {
2016 + } else if (png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD)) {
2017 + png_color_16p background;
2018 + png_get_bKGD(png_ptr, info_ptr, &background);
2019 /* didn't manage to get libpng to work (bugs?) concerning background
2020 processing, therefore we do our own.
2022 - switch (info_ptr->color_type) {
2023 + switch (png_get_color_type(png_ptr, info_ptr)) {
2024 case PNG_COLOR_TYPE_GRAY:
2025 case PNG_COLOR_TYPE_GRAY_ALPHA:
2026 bgColorP->r = bgColorP->g = bgColorP->b =
2027 - gamma_correct(info_ptr->background.gray, totalgamma);
2028 + gamma_correct(background->gray, totalgamma);
2030 case PNG_COLOR_TYPE_PALETTE: {
2031 - png_color const rawBgcolor =
2032 - info_ptr->palette[info_ptr->background.index];
2033 + png_color rawBgcolor;
2034 + png_colorp palette;
2037 + png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
2039 + palette[background->index];
2040 bgColorP->r = gamma_correct(rawBgcolor.red, totalgamma);
2041 bgColorP->g = gamma_correct(rawBgcolor.green, totalgamma);
2042 bgColorP->b = gamma_correct(rawBgcolor.blue, totalgamma);
2043 @@ -984,7 +1045,7 @@ getBackgroundColor(png_info * const in
2045 case PNG_COLOR_TYPE_RGB:
2046 case PNG_COLOR_TYPE_RGB_ALPHA: {
2047 - png_color_16 const rawBgcolor = info_ptr->background;
2048 + png_color_16 const rawBgcolor = *background;
2050 bgColorP->r = gamma_correct(rawBgcolor.red, totalgamma);
2051 bgColorP->g = gamma_correct(rawBgcolor.green, totalgamma);
2052 @@ -999,13 +1060,14 @@ getBackgroundColor(png_info * const in
2056 -#define GET_PNG_VAL(p) get_png_val(&(p), pngInfoP->bit_depth)
2057 +#define GET_PNG_VAL(p) get_png_val(&(p), png_get_bit_depth(pngP, pngInfoP))
2062 makeTupleRow(const struct pam * const pamP,
2063 const tuple * const tuplerow,
2064 + png_struct * const pngP,
2065 png_info * const pngInfoP,
2066 const png_byte * const pngRasterRow,
2067 pngcolor const bgColor,
2068 @@ -1016,13 +1078,13 @@ makeTupleRow(const struct pam * const p
2071 pngPixelP = &pngRasterRow[0]; /* initial value */
2072 - for (col = 0; col < pngInfoP->width; ++col) {
2073 - switch (pngInfoP->color_type) {
2074 + for (col = 0; col < png_get_image_width(pngP, pngInfoP); ++col) {
2075 + switch (png_get_color_type(pngP, pngInfoP)) {
2076 case PNG_COLOR_TYPE_GRAY: {
2078 fgColor.r = fgColor.g = fgColor.b = GET_PNG_VAL(pngPixelP);
2079 setTuple(pamP, tuplerow[col], fgColor, bgColor, alphaHandling,
2080 - isTransparentColor(fgColor, pngInfoP, totalgamma) ?
2081 + isTransparentColor(fgColor, pngP, pngInfoP, totalgamma) ?
2085 @@ -1040,18 +1102,26 @@ makeTupleRow(const struct pam * const p
2087 case PNG_COLOR_TYPE_PALETTE: {
2088 png_uint_16 const index = GET_PNG_VAL(pngPixelP);
2089 - png_color const paletteColor = pngInfoP->palette[index];
2091 + png_color paletteColor;
2092 + bool transValid = png_get_valid(pngP, pngInfoP, PNG_INFO_tRNS);
2093 + png_bytep trans_alpha;
2094 + int num_trans, num_palette;
2095 + png_colorp palette;
2098 + png_get_PLTE(pngP, pngInfoP, &palette, &num_palette);
2099 + paletteColor = palette[index];
2101 fgColor.r = paletteColor.red;
2102 fgColor.g = paletteColor.green;
2103 fgColor.b = paletteColor.blue;
2106 + png_get_tRNS(pngP, pngInfoP, &trans_alpha, &num_trans, NULL);
2107 setTuple(pamP, tuplerow[col], fgColor, bgColor, alphaHandling,
2108 - (pngInfoP->valid & PNG_INFO_tRNS) &&
2109 - index < pngInfoP->num_trans ?
2110 - pngInfoP->TRANS_ALPHA[index] : maxval);
2112 + index < num_trans ?
2113 + trans_alpha[index] : maxval);
2117 @@ -1062,7 +1132,7 @@ makeTupleRow(const struct pam * const p
2118 fgColor.g = GET_PNG_VAL(pngPixelP);
2119 fgColor.b = GET_PNG_VAL(pngPixelP);
2120 setTuple(pamP, tuplerow[col], fgColor, bgColor, alphaHandling,
2121 - isTransparentColor(fgColor, pngInfoP, totalgamma) ?
2122 + isTransparentColor(fgColor, pngP, pngInfoP, totalgamma) ?
2126 @@ -1081,7 +1151,7 @@ makeTupleRow(const struct pam * const p
2130 - pm_error("unknown PNG color type: %d", pngInfoP->color_type);
2131 + pm_error("unknown PNG color type: %d", png_get_color_type(pngP, pngInfoP));
2135 @@ -1115,6 +1185,7 @@ reportOutputFormat(const struct pam * co
2138 writeNetpbm(struct pam * const pamP,
2139 + png_struct * const pngP,
2140 png_info * const pngInfoP,
2141 png_byte ** const pngRaster,
2142 pngcolor const bgColor,
2143 @@ -1141,8 +1212,8 @@ writeNetpbm(struct pam * const pa
2145 tuplerow = pnm_allocpamrow(pamP);
2147 - for (row = 0; row < pngInfoP->height; ++row) {
2148 - makeTupleRow(pamP, tuplerow, pngInfoP, pngRaster[row], bgColor,
2149 + for (row = 0; row < png_get_image_height(pngP, pngInfoP); ++row) {
2150 + makeTupleRow(pamP, tuplerow, pngP, pngInfoP, pngRaster[row], bgColor,
2151 alphaHandling, totalgamma);
2153 pnm_writepamrow(pamP, tuplerow);
2154 @@ -1186,9 +1257,9 @@ convertpng(FILE * const ifp,
2155 png_set_sig_bytes (png_ptr, SIG_CHECK_SIZE);
2156 png_read_info (png_ptr, info_ptr);
2158 - allocPngRaster(info_ptr, &png_image);
2159 + allocPngRaster(png_ptr, info_ptr, &png_image);
2161 - if (info_ptr->bit_depth < 8)
2162 + if (png_get_bit_depth(png_ptr, info_ptr) < 8)
2163 png_set_packing (png_ptr);
2165 setupGammaCorrection(png_ptr, info_ptr, cmdline.gamma, &totalgamma);
2166 @@ -1196,7 +1267,7 @@ convertpng(FILE * const ifp,
2167 setupSignificantBits(png_ptr, info_ptr, cmdline.alpha,
2168 &maxval, errorlevelP);
2170 - getBackgroundColor(info_ptr, cmdline.background, totalgamma, maxval,
2171 + getBackgroundColor(png_ptr, info_ptr, cmdline.background, totalgamma, maxval,
2174 png_read_image(png_ptr, png_image);
2175 @@ -1207,16 +1278,19 @@ convertpng(FILE * const ifp,
2176 completes. That's because it comes from chunks that are at the
2179 - dump_png_info(info_ptr);
2180 + dump_png_info(png_ptr, info_ptr);
2183 - show_time(info_ptr);
2184 + show_time(png_ptr, info_ptr);
2186 - save_text(info_ptr, tfp);
2187 + save_text(png_ptr, info_ptr, tfp);
2189 + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_pHYs)) {
2191 + png_uint_32 x_pixels_per_unit, y_pixels_per_unit;
2193 - if (info_ptr->valid & PNG_INFO_pHYs) {
2195 - (float)info_ptr->x_pixels_per_unit / info_ptr->y_pixels_per_unit;
2196 + png_get_pHYs(png_ptr, info_ptr, &x_pixels_per_unit, &y_pixels_per_unit, NULL);
2197 + r = (float)x_pixels_per_unit / y_pixels_per_unit;
2199 pm_message ("warning - non-square pixels; "
2200 "to fix do a 'pamscale -%cscale %g'",
2201 @@ -1230,18 +1304,18 @@ convertpng(FILE * const ifp,
2202 pam.len = PAM_STRUCT_SIZE(tuple_type);
2204 pam.plainformat = 0;
2205 - pam.height = info_ptr->height;
2206 - pam.width = info_ptr->width;
2207 + pam.height = png_get_image_height(png_ptr, info_ptr);
2208 + pam.width = png_get_image_width(png_ptr, info_ptr);
2209 pam.maxval = maxval;
2211 - determineOutputType(info_ptr, cmdline.alpha, bgColor, maxval,
2212 + determineOutputType(png_ptr, info_ptr, cmdline.alpha, bgColor, maxval,
2213 &pam.format, &pam.depth, pam.tuple_type);
2215 - writeNetpbm(&pam, info_ptr, png_image, bgColor, cmdline.alpha, totalgamma);
2216 + writeNetpbm(&pam, png_ptr, info_ptr, png_image, bgColor, cmdline.alpha, totalgamma);
2220 - freePngRaster(png_image, info_ptr);
2221 + freePngRaster(png_image, png_ptr, info_ptr);
2223 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);