Magellan Linux

Annotation of /trunk/netpbm/patches/netpbm-10.35.81-libpng15.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1409 - (hide annotations) (download)
Tue Jul 12 20:29:57 2011 UTC (12 years, 10 months ago) by niro
File size: 54101 byte(s)
-added libpng-1.5 patch from netbsd
1 niro 1409 consolidated patches ac,af,aj,ak,al from netbsd
2    
3     ##
4    
5     $NetBSD: patch-ac,v 1.22 2011/01/15 18:37:46 tron Exp $
6    
7     Fix build with png-1.5.
8    
9     --- converter/other/pnmtopng.c.orig 2010-12-10 18:19:40.000000000 +0000
10     +++ converter/other/pnmtopng.c 2011-01-15 11:15:25.000000000 +0000
11     @@ -61,7 +61,8 @@
12     #include <assert.h>
13     #include <string.h> /* strcat() */
14     #include <limits.h>
15     -#include <png.h> /* includes zlib.h and setjmp.h */
16     +#include <png.h> /* includes setjmp.h */
17     +#include <zlib.h>
18     #include "pnm.h"
19     #include "pngtxt.h"
20     #include "shhopt.h"
21     @@ -69,13 +70,6 @@
22     #include "nstring.h"
23     #include "version.h"
24    
25     -#if PNG_LIBPNG_VER >= 10400
26     -#error Your PNG library (<png.h>) is incompatible with this Netpbm source code.
27     -#error You need either an older PNG library (older than 1.4)
28     -#error newer Netpbm source code (at least 10.47.04)
29     -#endif
30     -
31     -
32     struct zlibCompression {
33     /* These are parameters that describe a form of zlib compression.
34     Values have the same meaning as the similarly named arguments to
35     @@ -2079,6 +2073,7 @@
36     gray * const alpha_mask,
37     colorhash_table const cht,
38     coloralphahash_table const caht,
39     + png_struct * const png_ptr,
40     png_info * const info_ptr,
41     xelval const png_maxval,
42     unsigned int const depth) {
43     @@ -2091,20 +2086,20 @@
44     xel p_png;
45     xel const p = xelrow[col];
46     PPM_DEPTH(p_png, p, maxval, png_maxval);
47     - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
48     - info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
49     + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY ||
50     + png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY_ALPHA) {
51     if (depth == 16)
52     *pp++ = PNM_GET1(p_png) >> 8;
53     *pp++ = PNM_GET1(p_png) & 0xff;
54     - } else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
55     + } else if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
56     unsigned int paletteIndex;
57     if (alpha)
58     paletteIndex = lookupColorAlpha(caht, &p, &alpha_mask[col]);
59     else
60     paletteIndex = ppm_lookupcolor(cht, &p);
61     *pp++ = paletteIndex;
62     - } else if (info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
63     - info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
64     + } else if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB ||
65     + png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA) {
66     if (depth == 16)
67     *pp++ = PPM_GETR(p_png) >> 8;
68     *pp++ = PPM_GETR(p_png) & 0xff;
69     @@ -2117,7 +2112,7 @@
70     } else
71     pm_error("INTERNAL ERROR: undefined color_type");
72    
73     - if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) {
74     + if (png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_ALPHA) {
75     int const png_alphaval = (int)
76     alpha_mask[col] * (float) png_maxval / maxval + 0.5;
77     if (depth == 16)
78     @@ -2174,7 +2169,7 @@
79    
80     makePngLine(line, xelrow, cols, maxval,
81     alpha, alpha ? alpha_mask[row] : NULL,
82     - cht, caht, info_ptr, png_maxval, depth);
83     + cht, caht, png_ptr, info_ptr, png_maxval, depth);
84    
85     png_write_row(png_ptr, line);
86     }
87     @@ -2186,12 +2181,12 @@
88    
89     static void
90     doGamaChunk(struct cmdlineInfo const cmdline,
91     + png_struct * const png_ptr,
92     png_info * const info_ptr) {
93    
94     if (cmdline.gammaSpec) {
95     /* gAMA chunk */
96     - info_ptr->valid |= PNG_INFO_gAMA;
97     - info_ptr->gamma = cmdline.gamma;
98     + png_set_gAMA(png_ptr, info_ptr, cmdline.gamma);
99     }
100     }
101    
102     @@ -2199,20 +2194,15 @@
103    
104     static void
105     doChrmChunk(struct cmdlineInfo const cmdline,
106     + png_struct * const png_ptr,
107     png_info * const info_ptr) {
108    
109     if (cmdline.rgbSpec) {
110     /* cHRM chunk */
111     - info_ptr->valid |= PNG_INFO_cHRM;
112     -
113     - info_ptr->x_white = cmdline.rgb.wx;
114     - info_ptr->y_white = cmdline.rgb.wy;
115     - info_ptr->x_red = cmdline.rgb.rx;
116     - info_ptr->y_red = cmdline.rgb.ry;
117     - info_ptr->x_green = cmdline.rgb.gx;
118     - info_ptr->y_green = cmdline.rgb.gy;
119     - info_ptr->x_blue = cmdline.rgb.bx;
120     - info_ptr->y_blue = cmdline.rgb.by;
121     +
122     + png_set_cHRM (png_ptr, info_ptr, cmdline.rgb.wx, cmdline.rgb.wy,
123     + cmdline.rgb.rx, cmdline.rgb.ry, cmdline.rgb.gx,
124     + cmdline.rgb.gy, cmdline.rgb.bx, cmdline.rgb.by);
125     }
126     }
127    
128     @@ -2220,15 +2210,12 @@
129    
130     static void
131     doPhysChunk(struct cmdlineInfo const cmdline,
132     + png_struct * const png_ptr,
133     png_info * const info_ptr) {
134    
135     if (cmdline.sizeSpec) {
136     /* pHYS chunk */
137     - info_ptr->valid |= PNG_INFO_pHYs;
138     -
139     - info_ptr->x_pixels_per_unit = cmdline.size.x;
140     - info_ptr->y_pixels_per_unit = cmdline.size.y;
141     - info_ptr->phys_unit_type = cmdline.size.unit;
142     + png_set_pHYs(png_ptr, info_ptr, cmdline.size.x, cmdline.size.y, cmdline.size.unit);
143     }
144     }
145    
146     @@ -2237,26 +2224,28 @@
147    
148     static void
149     doTimeChunk(struct cmdlineInfo const cmdline,
150     + png_struct * const png_ptr,
151     png_info * const info_ptr) {
152    
153     if (cmdline.modtimeSpec) {
154     /* tIME chunk */
155     - info_ptr->valid |= PNG_INFO_tIME;
156     -
157     - png_convert_from_time_t(&info_ptr->mod_time, cmdline.modtime);
158     + png_timep ptime;
159     + png_convert_from_time_t(ptime, cmdline.modtime);
160     + png_set_tIME(png_ptr, info_ptr, ptime);
161     }
162     }
163    
164    
165    
166     static void
167     -doSbitChunk(png_info * const pngInfoP,
168     +doSbitChunk(png_struct * const pngP,
169     + png_info * const pngInfoP,
170     xelval const pngMaxval,
171     xelval const maxval,
172     bool const alpha,
173     xelval const alphaMaxval) {
174    
175     - if (pngInfoP->color_type != PNG_COLOR_TYPE_PALETTE &&
176     + if (png_get_color_type(pngP, pngInfoP) != PNG_COLOR_TYPE_PALETTE &&
177     (pngMaxval > maxval || (alpha && pngMaxval > alphaMaxval))) {
178    
179     /* We're writing in a bit depth that doesn't match the maxval
180     @@ -2275,26 +2264,28 @@
181     sBIT chunk.
182     */
183    
184     - pngInfoP->valid |= PNG_INFO_sBIT;
185     -
186     {
187     int const sbitval = pm_maxvaltobits(MIN(maxval, pngMaxval));
188     + png_color_8 sbit;
189    
190     - if (pngInfoP->color_type & PNG_COLOR_MASK_COLOR) {
191     - pngInfoP->sig_bit.red = sbitval;
192     - pngInfoP->sig_bit.green = sbitval;
193     - pngInfoP->sig_bit.blue = sbitval;
194     + (void)memset(&sbit, 0, sizeof(sbit));
195     + if (png_get_color_type(pngP, pngInfoP) & PNG_COLOR_MASK_COLOR) {
196     + sbit.red = sbitval;
197     + sbit.green = sbitval;
198     + sbit.blue = sbitval;
199     } else
200     - pngInfoP->sig_bit.gray = sbitval;
201     + sbit.gray = sbitval;
202    
203     if (verbose)
204     pm_message("Writing sBIT chunk with bits = %d", sbitval);
205     - }
206     - if (pngInfoP->color_type & PNG_COLOR_MASK_ALPHA) {
207     - pngInfoP->sig_bit.alpha =
208     - pm_maxvaltobits(MIN(alphaMaxval, pngMaxval));
209     - if (verbose)
210     - pm_message(" alpha bits = %d", pngInfoP->sig_bit.alpha);
211     +
212     + if (png_get_color_type(pngP, pngInfoP) & PNG_COLOR_MASK_ALPHA) {
213     + sbit.alpha =
214     + pm_maxvaltobits(MIN(alphaMaxval, pngMaxval));
215     + if (verbose)
216     + pm_message(" alpha bits = %d", sbit.alpha);
217     + }
218     + png_set_sBIT(pngP, pngInfoP, &sbit);
219     }
220     }
221     }
222     @@ -2391,6 +2382,8 @@
223     xelval maxmaxval;
224     gray ** alpha_mask;
225    
226     + int color_type;
227     +
228     /* these guys are initialized to quiet compiler warnings: */
229     maxmaxval = 255;
230     alpha_mask = NULL;
231     @@ -2576,43 +2569,42 @@
232     pm_error ("setjmp returns error condition (2)");
233     }
234    
235     - png_init_io (png_ptr, stdout);
236     - info_ptr->width = cols;
237     - info_ptr->height = rows;
238     - info_ptr->bit_depth = depth;
239     -
240     if (colorMapped)
241     - info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
242     - else if (pnm_type == PPM_TYPE)
243     - info_ptr->color_type = PNG_COLOR_TYPE_RGB;
244     - else
245     - info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
246     + color_type = PNG_COLOR_TYPE_PALETTE;
247     + else if (pnm_type == PPM_TYPE) {
248     + if (alpha)
249     + color_type = PNG_COLOR_TYPE_RGB_ALPHA;
250     + else
251     + color_type = PNG_COLOR_TYPE_RGB;
252     + } else {
253     + if (alpha)
254     + color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
255     + else
256     + color_type = PNG_COLOR_TYPE_GRAY;
257     + }
258    
259     - if (alpha && info_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
260     - info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
261     + png_set_IHDR(png_ptr, info_ptr, cols, rows, depth, color_type, 0, 0, 0);
262     + png_init_io (png_ptr, stdout);
263    
264     - info_ptr->interlace_type = cmdline.interlace;
265     + if (cmdline.interlace)
266     + png_set_interlace_handling(png_ptr);
267    
268     - doGamaChunk(cmdline, info_ptr);
269     + doGamaChunk(cmdline, png_ptr, info_ptr);
270    
271     - doChrmChunk(cmdline, info_ptr);
272     + doChrmChunk(cmdline, png_ptr, info_ptr);
273    
274     - doPhysChunk(cmdline, info_ptr);
275     + doPhysChunk(cmdline, png_ptr, info_ptr);
276    
277     - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
278     + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
279    
280     /* creating PNG palette (PLTE and tRNS chunks) */
281    
282     createPngPalette(palette_pnm, palette_size, maxval,
283     trans_pnm, trans_size, alpha_maxval,
284     palette, trans);
285     - info_ptr->valid |= PNG_INFO_PLTE;
286     - info_ptr->palette = palette;
287     - info_ptr->num_palette = palette_size;
288     + png_set_PLTE(png_ptr, info_ptr, palette, palette_size);
289     if (trans_size > 0) {
290     - info_ptr->valid |= PNG_INFO_tRNS;
291     - info_ptr->trans = trans;
292     - info_ptr->num_trans = trans_size; /* omit opaque values */
293     + png_set_tRNS(png_ptr, info_ptr, trans, trans_size, NULL);
294     }
295     /* creating hIST chunk */
296     if (cmdline.hist) {
297     @@ -2638,18 +2630,17 @@
298    
299     ppm_freecolorhash(cht);
300    
301     - info_ptr->valid |= PNG_INFO_hIST;
302     - info_ptr->hist = histogram;
303     + png_set_hIST(png_ptr, info_ptr, histogram);
304     if (verbose)
305     pm_message("histogram created");
306     }
307     } else { /* color_type != PNG_COLOR_TYPE_PALETTE */
308     - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
309     - info_ptr->color_type == PNG_COLOR_TYPE_RGB) {
310     + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY ||
311     + png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB) {
312     if (transparent > 0) {
313     - info_ptr->valid |= PNG_INFO_tRNS;
314     - info_ptr->trans_values =
315     - xelToPngColor_16(transcolor, maxval, png_maxval);
316     + png_color_16 trans_color = xelToPngColor_16(transcolor, maxval, png_maxval);
317     + png_set_tRNS(png_ptr, info_ptr, NULL, 0, &trans_color);
318     +
319     }
320     } else {
321     /* This is PNG_COLOR_MASK_ALPHA. Transparency will be handled
322     @@ -2657,43 +2648,49 @@
323     */
324     }
325     if (verbose) {
326     - if (info_ptr->valid && PNG_INFO_tRNS)
327     + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
328     + png_color_16p trans_color;
329     +
330     + png_get_tRNS(png_ptr, info_ptr, NULL, NULL, &trans_color);
331     pm_message("Transparent color {gray, red, green, blue} = "
332     "{%d, %d, %d, %d}",
333     - info_ptr->trans_values.gray,
334     - info_ptr->trans_values.red,
335     - info_ptr->trans_values.green,
336     - info_ptr->trans_values.blue);
337     - else
338     + trans_color->gray,
339     + trans_color->red,
340     + trans_color->green,
341     + trans_color->blue);
342     + } else
343     pm_message("No transparent color");
344     }
345     }
346    
347     /* bKGD chunk */
348     if (cmdline.background) {
349     - info_ptr->valid |= PNG_INFO_bKGD;
350     - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
351     - info_ptr->background.index = background_index;
352     + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
353     + png_color_16 background;
354     +
355     + (void)memset(&background, 0, sizeof(background));
356     + background.index = background_index;
357     + png_set_bKGD(png_ptr, info_ptr, &background);
358     } else {
359     - info_ptr->background =
360     - xelToPngColor_16(backcolor, maxval, png_maxval);
361     + png_color_16 background = xelToPngColor_16(backcolor, maxval, png_maxval);
362     + png_set_bKGD(png_ptr, info_ptr, &background);
363     if (verbose)
364     pm_message("Writing bKGD chunk with background color "
365     " {gray, red, green, blue} = {%d, %d, %d, %d}",
366     - info_ptr->background.gray,
367     - info_ptr->background.red,
368     - info_ptr->background.green,
369     - info_ptr->background.blue );
370     + background.gray,
371     + background.red,
372     + background.green,
373     + background.blue );
374     }
375     }
376    
377     - doSbitChunk(info_ptr, png_maxval, maxval, alpha, alpha_maxval);
378     + doSbitChunk(png_ptr, info_ptr, png_maxval, maxval, alpha, alpha_maxval);
379    
380     /* tEXT and zTXT chunks */
381     if (cmdline.text || cmdline.ztxt)
382     - pnmpng_read_text(info_ptr, tfp, !!cmdline.ztxt, cmdline.verbose);
383     + pnmpng_read_text(png_ptr, info_ptr, tfp, !!cmdline.ztxt, cmdline.verbose);
384    
385     - doTimeChunk(cmdline, info_ptr);
386     + doTimeChunk(cmdline, png_ptr, info_ptr);
387    
388     if (cmdline.filterSet != 0)
389     png_set_filter(png_ptr, 0, cmdline.filterSet);
390     @@ -2703,6 +2700,7 @@
391     /* write the png-info struct */
392     png_write_info(png_ptr, info_ptr);
393    
394     +#if 0
395     if (cmdline.text || cmdline.ztxt)
396     /* prevent from being written twice with png_write_end */
397     info_ptr->num_text = 0;
398     @@ -2710,6 +2708,7 @@
399     if (cmdline.modtime)
400     /* prevent from being written twice with png_write_end */
401     info_ptr->valid &= ~PNG_INFO_tIME;
402     +#endif
403    
404     /* let libpng take care of, e.g., bit-depth conversions */
405     png_set_packing (png_ptr);
406     $NetBSD: patch-af,v 1.16 2011/04/04 09:17:24 adam Exp $
407    
408     Fix build with png-1.5.
409    
410     --- converter/other/pngtopnm.c.orig 2009-09-03 16:34:36.000000000 +0100
411     +++ converter/other/pngtopnm.c 2011-01-15 18:19:09.000000000 +0000
412     @@ -44,12 +44,6 @@
413     #include "nstring.h"
414     #include "shhopt.h"
415    
416     -#if PNG_LIBPNG_VER >= 10400
417     -#error Your PNG library (<png.h>) is incompatible with this Netpbm source code.
418     -#error You need either an older PNG library (older than 1.4)
419     -#error newer Netpbm source code (at least 10.48)
420     -#endif
421     -
422     typedef struct _jmpbuf_wrapper {
423     jmp_buf jmpbuf;
424     } jmpbuf_wrapper;
425     @@ -187,7 +181,7 @@
426    
427    
428    
429     -#define get_png_val(p) _get_png_val (&(p), info_ptr->bit_depth)
430     +#define get_png_val(p) _get_png_val (&(p), png_get_bit_depth(png_ptr, info_ptr))
431    
432     static png_uint_16
433     _get_png_val (png_byte ** const pp,
434     @@ -266,33 +260,39 @@
435     }
436    
437     #ifdef __STDC__
438     -static void save_text (png_info *info_ptr, FILE *tfp)
439     +static void save_text (png_structp png_ptr, png_info *info_ptr, FILE *tfp)
440     #else
441     -static void save_text (info_ptr, tfp)
442     +static void save_text (png_ptr, info_ptr, tfp)
443     +png_structp png_ptr;
444     png_info *info_ptr;
445     FILE *tfp;
446     #endif
447     {
448     int i, j, k;
449     + png_textp text_ptr;
450     + int num_text;
451     +
452     + if (png_get_text(png_ptr, info_ptr, &text_ptr, &num_text) == 0)
453     + return;
454    
455     - for (i = 0 ; i < info_ptr->num_text ; i++) {
456     + for (i = 0 ; i < num_text ; i++) {
457     j = 0;
458     - while (info_ptr->text[i].key[j] != '\0' && info_ptr->text[i].key[j] != ' ')
459     + while (text_ptr[i].key[j] != '\0' && text_ptr[i].key[j] != ' ')
460     j++;
461     - if (info_ptr->text[i].key[j] != ' ') {
462     - fprintf (tfp, "%s", info_ptr->text[i].key);
463     - for (j = strlen (info_ptr->text[i].key) ; j < 15 ; j++)
464     + if (text_ptr[i].key[j] != ' ') {
465     + fprintf (tfp, "%s", text_ptr[i].key);
466     + for (j = strlen (text_ptr[i].key) ; j < 15 ; j++)
467     putc (' ', tfp);
468     } else {
469     - fprintf (tfp, "\"%s\"", info_ptr->text[i].key);
470     - for (j = strlen (info_ptr->text[i].key) ; j < 13 ; j++)
471     + fprintf (tfp, "\"%s\"", text_ptr[i].key);
472     + for (j = strlen (text_ptr[i].key) ; j < 13 ; j++)
473     putc (' ', tfp);
474     }
475     putc (' ', tfp); /* at least one space between key and text */
476    
477     - for (j = 0 ; j < info_ptr->text[i].text_length ; j++) {
478     - putc (info_ptr->text[i].text[j], tfp);
479     - if (info_ptr->text[i].text[j] == '\n')
480     + for (j = 0 ; j < text_ptr[i].text_length ; j++) {
481     + putc (text_ptr[i].text[j], tfp);
482     + if (text_ptr[i].text[j] == '\n')
483     for (k = 0 ; k < 16 ; k++)
484     putc ((int)' ', tfp);
485     }
486     @@ -301,9 +301,10 @@
487     }
488    
489     #ifdef __STDC__
490     -static void show_time (png_info *info_ptr)
491     +static void show_time (png_structp png_ptr, png_info *info_ptr)
492     #else
493     -static void show_time (info_ptr)
494     +static void show_time (png_ptr, info_ptr)
495     +png_structp png_ptr;
496     png_info *info_ptr;
497     #endif
498     {
499     @@ -311,12 +312,13 @@
500     "", "January", "February", "March", "April", "May", "June",
501     "July", "August", "September", "October", "November", "December"
502     };
503     + png_timep mod_time;
504    
505     - if (info_ptr->valid & PNG_INFO_tIME) {
506     + if (png_get_tIME(png_ptr, info_ptr, &mod_time) & PNG_INFO_tIME) {
507     pm_message ("modification time: %02d %s %d %02d:%02d:%02d",
508     - info_ptr->mod_time.day, month[info_ptr->mod_time.month],
509     - info_ptr->mod_time.year, info_ptr->mod_time.hour,
510     - info_ptr->mod_time.minute, info_ptr->mod_time.second);
511     + mod_time->day, month[mod_time->month],
512     + mod_time->year, mod_time->hour,
513     + mod_time->minute, mod_time->second);
514     }
515     }
516    
517     @@ -353,12 +355,28 @@
518    
519    
520     static void
521     -dump_png_info(png_info *info_ptr) {
522     +dump_png_info(png_structp png_ptr, png_info *info_ptr) {
523    
524     const char *type_string;
525     const char *filter_string;
526     + png_color_16p background;
527     + int num_trans;
528     + double gamma;
529     + png_color_8p sig_bit;
530     + png_colorp palette;
531     + int num_palette;
532     + png_uint_16p hist;
533     + int res_x, res_y, unit_type;
534     + png_int_32 offset_x, offset_y;
535     + png_timep mod_time;
536     + png_charp purpose;
537     + png_int_32 X0, X1;
538     + int type, nparams;
539     + png_charp units;
540     + png_charpp params;
541     + int file_srgb_intent;
542    
543     - switch (info_ptr->color_type) {
544     + switch (png_get_color_type(png_ptr, info_ptr)) {
545     case PNG_COLOR_TYPE_GRAY:
546     type_string = "gray";
547     break;
548     @@ -380,90 +398,101 @@
549     break;
550     }
551    
552     - switch (info_ptr->filter_type) {
553     + switch (png_get_filter_type(png_ptr, info_ptr)) {
554     case PNG_FILTER_TYPE_BASE:
555     asprintfN(&filter_string, "base filter");
556     break;
557     default:
558     asprintfN(&filter_string, "unknown filter type %d",
559     - info_ptr->filter_type);
560     + png_get_filter_type(png_ptr, info_ptr));
561     }
562    
563     - pm_message("reading a %ldw x %ldh image, %d bit%s",
564     - info_ptr->width, info_ptr->height,
565     - info_ptr->bit_depth, info_ptr->bit_depth > 1 ? "s" : "");
566     + pm_message("reading a %uw x %uh image, %d bit%s",
567     + png_get_image_width(png_ptr, info_ptr),
568     + png_get_image_height(png_ptr, info_ptr),
569     + png_get_bit_depth(png_ptr, info_ptr),
570     + png_get_bit_depth(png_ptr, info_ptr) > 1 ? "s" : "");
571     pm_message("%s, %s, %s",
572     type_string,
573     - info_ptr->interlace_type ?
574     + png_get_interlace_type(png_ptr, info_ptr) ?
575     "Adam7 interlaced" : "not interlaced",
576     filter_string);
577     - pm_message("background {index, gray, red, green, blue} = "
578     - "{%d, %d, %d, %d, %d}",
579     - info_ptr->background.index,
580     - info_ptr->background.gray,
581     - info_ptr->background.red,
582     - info_ptr->background.green,
583     - info_ptr->background.blue);
584     +
585     + if (png_get_bKGD(png_ptr, info_ptr, &background) & PNG_INFO_bKGD) {
586     + pm_message("background {index, gray, red, green, blue} = "
587     + "{%d, %d, %d, %d, %d}",
588     + background->index,
589     + background->gray,
590     + background->red,
591     + background->green,
592     + background->blue);
593     + }
594    
595     strfree(filter_string);
596    
597     - if (info_ptr->valid & PNG_INFO_tRNS)
598     + if (png_get_tRNS(png_ptr, info_ptr,
599     + NULL, &num_trans, NULL) & PNG_INFO_tRNS)
600     pm_message("tRNS chunk (transparency): %u entries",
601     - info_ptr->num_trans);
602     + num_trans);
603     else
604     pm_message("tRNS chunk (transparency): not present");
605    
606     - if (info_ptr->valid & PNG_INFO_gAMA)
607     - pm_message("gAMA chunk (image gamma): gamma = %4.2f", info_ptr->gamma);
608     + if (png_get_gAMA(png_ptr, info_ptr, &gamma) & PNG_INFO_gAMA)
609     + pm_message("gAMA chunk (image gamma): gamma = %4.2f", gamma);
610     else
611     pm_message("gAMA chunk (image gamma): not present");
612    
613     - if (info_ptr->valid & PNG_INFO_sBIT)
614     + if (png_get_sBIT(png_ptr, info_ptr, &sig_bit) & PNG_INFO_sBIT)
615     pm_message("sBIT chunk: present");
616     else
617     pm_message("sBIT chunk: not present");
618    
619     - if (info_ptr->valid & PNG_INFO_cHRM)
620     + if (png_get_cHRM(png_ptr, info_ptr,
621     + NULL, NULL, NULL, NULL,
622     + NULL, NULL, NULL, NULL) & PNG_INFO_cHRM)
623     pm_message("cHRM chunk: present");
624     else
625     pm_message("cHRM chunk: not present");
626    
627     - if (info_ptr->valid & PNG_INFO_PLTE)
628     - pm_message("PLTE chunk: %d entries", info_ptr->num_palette);
629     + if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette) & PNG_INFO_PLTE)
630     + pm_message("PLTE chunk: %d entries", num_palette);
631     else
632     pm_message("PLTE chunk: not present");
633    
634     - if (info_ptr->valid & PNG_INFO_bKGD)
635     + if (png_get_bKGD(png_ptr, info_ptr, &background) & PNG_INFO_bKGD)
636     pm_message("bKGD chunk: present");
637     else
638     pm_message("bKGD chunk: not present");
639    
640     - if (info_ptr->valid & PNG_INFO_hIST)
641     + if (png_get_hIST(png_ptr, info_ptr, &hist) & PNG_INFO_hIST)
642     pm_message("hIST chunk: present");
643     else
644     pm_message("hIST chunk: not present");
645    
646     - if (info_ptr->valid & PNG_INFO_pHYs)
647     + if (png_get_pHYs(png_ptr, info_ptr,
648     + &res_x, &res_y, &unit_type) & PNG_INFO_pHYs)
649     pm_message("pHYs chunk: present");
650     else
651     pm_message("pHYs chunk: not present");
652    
653     - if (info_ptr->valid & PNG_INFO_oFFs)
654     + if (png_get_oFFs(png_ptr, info_ptr,
655     + &offset_x, &offset_y, &unit_type) & PNG_INFO_oFFs)
656     pm_message("oFFs chunk: present");
657     else
658     pm_message("oFFs chunk: not present");
659    
660     - if (info_ptr->valid & PNG_INFO_tIME)
661     + if (png_get_tIME(png_ptr, info_ptr, &mod_time) & PNG_INFO_tIME)
662     pm_message("tIME chunk: present");
663     else
664     pm_message("tIME chunk: not present");
665    
666     - if (info_ptr->valid & PNG_INFO_pCAL)
667     + if (png_get_pCAL(png_ptr, info_ptr, &purpose, &X0, &X1,
668     + &type, &nparams, &units, &params) & PNG_INFO_pCAL)
669     pm_message("pCAL chunk: present");
670     else
671     pm_message("pCAL chunk: not present");
672    
673     - if (info_ptr->valid & PNG_INFO_sRGB)
674     + if (png_get_sRGB(png_ptr, info_ptr, &file_srgb_intent) & PNG_INFO_sRGB)
675     pm_message("sRGB chunk: present");
676     else
677     pm_message("sRGB chunk: not present");
678     @@ -472,19 +501,19 @@
679    
680    
681     static bool
682     -isTransparentColor(pngcolor const color,
683     - png_info * const info_ptr,
684     - double const totalgamma) {
685     +isTransparentColor(pngcolor const color,
686     + png_structp const png_ptr,
687     + png_info * const info_ptr,
688     + double const totalgamma) {
689     /*----------------------------------------------------------------------------
690     Return TRUE iff pixels of color 'color' are supposed to be transparent
691     everywhere they occur. Assume it's an RGB image.
692     -----------------------------------------------------------------------------*/
693     bool retval;
694     + png_color_16p transColorP;
695    
696     - if (info_ptr->valid & PNG_INFO_tRNS) {
697     - const png_color_16 * const transColorP = &info_ptr->trans_values;
698     -
699     -
700     + if (png_get_tRNS(png_ptr, info_ptr,
701     + NULL, NULL, &transColorP) & PNG_INFO_tRNS) {
702     /* There seems to be a problem here: you can't compare real
703     numbers for equality. Also, I'm not sure the gamma
704     corrected/uncorrected color spaces are right here.
705     @@ -530,9 +559,11 @@
706     if (displaygamma == -1.0)
707     *totalgammaP = -1.0;
708     else {
709     + double fileGamma;
710     float imageGamma;
711     - if (info_ptr->valid & PNG_INFO_gAMA)
712     - imageGamma = info_ptr->gamma;
713     +
714     + if (png_get_gAMA(png_ptr, info_ptr, &fileGamma) & PNG_INFO_gAMA)
715     + imageGamma = fileGamma;
716     else {
717     if (verbose)
718     pm_message("PNG doesn't specify image gamma. Assuming 1.0");
719     @@ -548,10 +579,14 @@
720     } else {
721     png_set_gamma(png_ptr, displaygamma, imageGamma);
722     *totalgammaP = imageGamma * displaygamma;
723     +#ifdef NOT_SUPPORTED_ANYMORE
724     + /* The API doesn't clearing PNG_INFO_sBIT. */
725     +
726     /* in case of gamma-corrections, sBIT's as in the
727     PNG-file are not valid anymore
728     */
729     info_ptr->valid &= ~PNG_INFO_sBIT;
730     +#endif
731     if (verbose)
732     pm_message("image gamma is %4.2f, "
733     "converted for display gamma of %4.2f",
734     @@ -563,20 +598,24 @@
735    
736    
737     static bool
738     -paletteHasPartialTransparency(png_info * const info_ptr) {
739     +paletteHasPartialTransparency(png_structp png_ptr, png_info * const info_ptr) {
740    
741     bool retval;
742    
743     - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
744     - if (info_ptr->valid & PNG_INFO_tRNS) {
745     + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
746     + png_bytep trans_alpha;
747     + int num_trans;
748     +
749     + if (png_get_tRNS(png_ptr, info_ptr,
750     + &trans_alpha, &num_trans, NULL) & PNG_INFO_tRNS) {
751     bool foundGray;
752     unsigned int i;
753    
754     for (i = 0, foundGray = FALSE;
755     - i < info_ptr->num_trans && !foundGray;
756     + i < num_trans && !foundGray;
757     ++i) {
758     - if (info_ptr->trans[i] != 0 &&
759     - info_ptr->trans[i] != maxval) {
760     + if (trans_alpha[i] != 0 &&
761     + trans_alpha[i] != maxval) {
762     foundGray = TRUE;
763     }
764     }
765     @@ -604,14 +643,16 @@
766    
767     Return the result as *maxvalP.
768     -----------------------------------------------------------------------------*/
769     + png_color_8p sig_bit;
770     +
771     /* Initial assumption of maxval */
772     - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
773     + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
774     if (alpha == ALPHA_ONLY) {
775     - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
776     - info_ptr->color_type == PNG_COLOR_TYPE_RGB)
777     + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY ||
778     + png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB)
779     /* The alpha mask will be all opaque, so maxval 1 is plenty */
780     *maxvalP = 1;
781     - else if (paletteHasPartialTransparency(info_ptr))
782     + else if (paletteHasPartialTransparency(png_ptr, info_ptr))
783     /* Use same maxval as PNG transparency palette for simplicity*/
784     *maxvalP = 255;
785     else
786     @@ -621,7 +662,7 @@
787     /* Use same maxval as PNG palette for simplicity */
788     *maxvalP = 255;
789     } else {
790     - *maxvalP = (1l << info_ptr->bit_depth) - 1;
791     + *maxvalP = (1l << png_get_bit_depth(png_ptr, info_ptr)) - 1;
792     }
793    
794     /* sBIT handling is very tricky. If we are extracting only the
795     @@ -634,20 +675,26 @@
796     is used
797     */
798    
799     - if (info_ptr->valid & PNG_INFO_sBIT) {
800     + if (png_get_sBIT(png_ptr, info_ptr, &sig_bit) & PNG_INFO_sBIT) {
801     + png_byte color_type;
802     + png_bytep trans_alpha;
803     + int num_trans;
804     +
805     + color_type = png_get_color_type(png_ptr, info_ptr);
806     switch (alpha) {
807     case ALPHA_MIX:
808     - if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
809     - info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
810     + if (color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
811     + color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
812     break;
813     - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
814     - (info_ptr->valid & PNG_INFO_tRNS)) {
815     + if (color_type == PNG_COLOR_TYPE_PALETTE &&
816     + png_get_tRNS(png_ptr, info_ptr,
817     + &trans_alpha, &num_trans, NULL) & PNG_INFO_tRNS) {
818    
819     bool trans_mix;
820     unsigned int i;
821     trans_mix = TRUE;
822     - for (i = 0; i < info_ptr->num_trans; ++i)
823     - if (info_ptr->trans[i] != 0 && info_ptr->trans[i] != 255) {
824     + for (i = 0; i < num_trans; ++i)
825     + if (trans_alpha[i] != 0 && trans_alpha[i] != 255) {
826     trans_mix = FALSE;
827     break;
828     }
829     @@ -658,70 +705,76 @@
830     /* else fall though to normal case */
831    
832     case ALPHA_NONE:
833     - if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
834     - info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
835     - info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
836     - (info_ptr->sig_bit.red != info_ptr->sig_bit.green ||
837     - info_ptr->sig_bit.red != info_ptr->sig_bit.blue) &&
838     + if ((color_type == PNG_COLOR_TYPE_PALETTE ||
839     + color_type == PNG_COLOR_TYPE_RGB ||
840     + color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
841     + (sig_bit->red != sig_bit->green ||
842     + sig_bit->red != sig_bit->blue) &&
843     alpha == ALPHA_NONE) {
844     pm_message("This program cannot handle "
845     "different bit depths for color channels");
846     pm_message("writing file with %d bit resolution",
847     - info_ptr->bit_depth);
848     + png_get_bit_depth(png_ptr, info_ptr));
849     *errorlevelP = PNMTOPNG_WARNING_LEVEL;
850     } else {
851     - if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) &&
852     - (info_ptr->sig_bit.red < 255)) {
853     + png_colorp palette;
854     + int num_palette;
855     +
856     + if ((color_type == PNG_COLOR_TYPE_PALETTE) &&
857     + (sig_bit->red < 255) &&
858     + png_get_PLTE(png_ptr, info_ptr,
859     + &palette, &num_palette) & PNG_INFO_PLTE) {
860     unsigned int i;
861     - for (i = 0; i < info_ptr->num_palette; ++i) {
862     - info_ptr->palette[i].red >>=
863     - (8 - info_ptr->sig_bit.red);
864     - info_ptr->palette[i].green >>=
865     - (8 - info_ptr->sig_bit.green);
866     - info_ptr->palette[i].blue >>=
867     - (8 - info_ptr->sig_bit.blue);
868     +
869     + for (i = 0; i < num_palette; ++i) {
870     + palette[i].red >>=
871     + (8 - sig_bit->red);
872     + palette[i].green >>=
873     + (8 - sig_bit->green);
874     + palette[i].blue >>=
875     + (8 - sig_bit->blue);
876     }
877     - *maxvalP = (1l << info_ptr->sig_bit.red) - 1;
878     + *maxvalP = (1l << sig_bit->red) - 1;
879     if (verbose)
880     pm_message ("image has fewer significant bits, "
881     "writing file with %d bits per channel",
882     - info_ptr->sig_bit.red);
883     + sig_bit->red);
884     } else
885     - if ((info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
886     - info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
887     - (info_ptr->sig_bit.red < info_ptr->bit_depth)) {
888     - png_set_shift (png_ptr, &(info_ptr->sig_bit));
889     - *maxvalP = (1l << info_ptr->sig_bit.red) - 1;
890     + if ((color_type == PNG_COLOR_TYPE_RGB ||
891     + color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
892     + (sig_bit->red < png_get_bit_depth(png_ptr, info_ptr))) {
893     + png_set_shift (png_ptr, sig_bit);
894     + *maxvalP = (1l << sig_bit->red) - 1;
895     if (verbose)
896     pm_message("image has fewer significant bits, "
897     "writing file with %d "
898     "bits per channel",
899     - info_ptr->sig_bit.red);
900     + sig_bit->red);
901     } else
902     - if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
903     - info_ptr->color_type ==
904     + if ((color_type == PNG_COLOR_TYPE_GRAY ||
905     + color_type ==
906     PNG_COLOR_TYPE_GRAY_ALPHA) &&
907     - (info_ptr->sig_bit.gray < info_ptr->bit_depth)) {
908     - png_set_shift (png_ptr, &(info_ptr->sig_bit));
909     - *maxvalP = (1l << info_ptr->sig_bit.gray) - 1;
910     + (sig_bit->gray < png_get_bit_depth(png_ptr, info_ptr))) {
911     + png_set_shift (png_ptr, sig_bit);
912     + *maxvalP = (1l << sig_bit->gray) - 1;
913     if (verbose)
914     pm_message("image has fewer significant bits, "
915     "writing file with %d bits",
916     - info_ptr->sig_bit.gray);
917     + sig_bit->gray);
918     }
919     }
920     break;
921    
922     case ALPHA_ONLY:
923     - if ((info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
924     - info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) &&
925     - (info_ptr->sig_bit.gray < info_ptr->bit_depth)) {
926     - png_set_shift (png_ptr, &(info_ptr->sig_bit));
927     + if ((color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
928     + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) &&
929     + (sig_bit->gray < png_get_bit_depth(png_ptr, info_ptr))) {
930     + png_set_shift (png_ptr, sig_bit);
931     if (verbose)
932     pm_message ("image has fewer significant bits, "
933     "writing file with %d bits",
934     - info_ptr->sig_bit.alpha);
935     - *maxvalP = (1l << info_ptr->sig_bit.alpha) - 1;
936     + sig_bit->alpha);
937     + *maxvalP = (1l << sig_bit->alpha) - 1;
938     }
939     break;
940    
941     @@ -732,22 +785,28 @@
942    
943    
944     static bool
945     -imageHasColor(png_info * const info_ptr) {
946     +imageHasColor(png_structp const png_ptr, png_info * const info_ptr) {
947    
948     bool retval;
949     -
950     - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
951     - info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
952     + png_byte color_type;
953     + png_colorp palette;
954     + int num_palette;
955     +
956     + color_type = png_get_color_type(png_ptr, info_ptr);
957     + if (color_type == PNG_COLOR_TYPE_GRAY ||
958     + color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
959    
960     retval = FALSE;
961     - else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
962     + else if (color_type == PNG_COLOR_TYPE_PALETTE &&
963     + png_get_PLTE(png_ptr, info_ptr,
964     + &palette, &num_palette) & PNG_INFO_PLTE) {
965     bool foundColor;
966     unsigned int i;
967    
968     for (i = 0, foundColor = FALSE;
969     - i < info_ptr->num_palette && !foundColor;
970     + i < num_palette && !foundColor;
971     ++i) {
972     - if (iscolor(info_ptr->palette[i]))
973     + if (iscolor(palette[i]))
974     foundColor = TRUE;
975     }
976     retval = foundColor;
977     @@ -760,14 +819,15 @@
978    
979    
980     static void
981     -determineOutputType(png_info * const info_ptr,
982     +determineOutputType(png_structp const png_ptr,
983     + png_info * const info_ptr,
984     enum alpha_handling const alphaHandling,
985     pngcolor const bgColor,
986     xelval const maxval,
987     int * const pnmTypeP) {
988    
989     if (alphaHandling != ALPHA_ONLY &&
990     - (imageHasColor(info_ptr) || !isGrayscale(bgColor)))
991     + (imageHasColor(png_ptr, info_ptr) || !isGrayscale(bgColor)))
992     *pnmTypeP = PPM_TYPE;
993     else {
994     if (maxval > 1)
995     @@ -780,7 +840,8 @@
996    
997    
998     static void
999     -getBackgroundColor(png_info * const info_ptr,
1000     +getBackgroundColor(png_structp const png_ptr,
1001     + png_info * const info_ptr,
1002     const char * const requestedColor,
1003     float const totalgamma,
1004     xelval const maxval,
1005     @@ -791,6 +852,8 @@
1006     Otherwise, if the PNG specifies a background color, that's the one.
1007     And otherwise, it's white.
1008     -----------------------------------------------------------------------------*/
1009     + png_color_16p background;
1010     +
1011     if (requestedColor) {
1012     /* Background was specified from the command-line; we always
1013     use that. I chose to do no gamma-correction in this case;
1014     @@ -802,27 +865,32 @@
1015     bgColorP->g = PPM_GETG(backcolor);
1016     bgColorP->b = PPM_GETB(backcolor);
1017    
1018     - } else if (info_ptr->valid & PNG_INFO_bKGD) {
1019     + } else if (png_get_bKGD(png_ptr, info_ptr, &background) & PNG_INFO_bKGD) {
1020     /* didn't manage to get libpng to work (bugs?) concerning background
1021     processing, therefore we do our own.
1022     */
1023     - switch (info_ptr->color_type) {
1024     + switch (png_get_color_type(png_ptr, info_ptr)) {
1025     case PNG_COLOR_TYPE_GRAY:
1026     case PNG_COLOR_TYPE_GRAY_ALPHA:
1027     bgColorP->r = bgColorP->g = bgColorP->b =
1028     - gamma_correct(info_ptr->background.gray, totalgamma);
1029     + gamma_correct(background->gray, totalgamma);
1030     break;
1031     case PNG_COLOR_TYPE_PALETTE: {
1032     - png_color const rawBgcolor =
1033     - info_ptr->palette[info_ptr->background.index];
1034     - bgColorP->r = gamma_correct(rawBgcolor.red, totalgamma);
1035     - bgColorP->g = gamma_correct(rawBgcolor.green, totalgamma);
1036     - bgColorP->b = gamma_correct(rawBgcolor.blue, totalgamma);
1037     + png_colorp palette;
1038     + int num_palette;
1039     +
1040     + if (png_get_PLTE(png_ptr, info_ptr,
1041     + &palette, &num_palette) & PNG_INFO_PLTE) {
1042     + png_color const rawBgcolor = palette[background->index];
1043     + bgColorP->r = gamma_correct(rawBgcolor.red, totalgamma);
1044     + bgColorP->g = gamma_correct(rawBgcolor.green, totalgamma);
1045     + bgColorP->b = gamma_correct(rawBgcolor.blue, totalgamma);
1046     + }
1047     }
1048     break;
1049     case PNG_COLOR_TYPE_RGB:
1050     case PNG_COLOR_TYPE_RGB_ALPHA: {
1051     - png_color_16 const rawBgcolor = info_ptr->background;
1052     + png_color_16 const rawBgcolor = *background;
1053    
1054     bgColorP->r = gamma_correct(rawBgcolor.red, totalgamma);
1055     bgColorP->g = gamma_correct(rawBgcolor.green, totalgamma);
1056     @@ -841,6 +909,7 @@
1057     writePnm(FILE * const ofP,
1058     xelval const maxval,
1059     int const pnm_type,
1060     + png_structp const png_ptr,
1061     png_info * const info_ptr,
1062     png_byte ** const png_image,
1063     pngcolor const bgColor,
1064     @@ -858,6 +927,7 @@
1065     -----------------------------------------------------------------------------*/
1066     xel * xelrow;
1067     unsigned int row;
1068     + png_uint_32 width, height;
1069    
1070     if (verbose)
1071     pm_message ("writing a %s file (maxval=%u)",
1072     @@ -867,27 +937,35 @@
1073     "UNKNOWN!",
1074     maxval);
1075    
1076     - xelrow = pnm_allocrow(info_ptr->width);
1077     + xelrow = pnm_allocrow(png_get_image_width(png_ptr, info_ptr));
1078    
1079     - pnm_writepnminit(stdout, info_ptr->width, info_ptr->height, maxval,
1080     - pnm_type, FALSE);
1081     + width = png_get_image_width(png_ptr, info_ptr);
1082     + height = png_get_image_height(png_ptr, info_ptr);
1083    
1084     - for (row = 0; row < info_ptr->height; ++row) {
1085     + pnm_writepnminit(stdout, width, height, maxval, pnm_type, FALSE);
1086     +
1087     + for (row = 0; row < height; ++row) {
1088     png_byte * png_pixelP;
1089     int col;
1090    
1091     png_pixelP = &png_image[row][0]; /* initial value */
1092     - for (col = 0; col < info_ptr->width; ++col) {
1093     - switch (info_ptr->color_type) {
1094     + for (col = 0; col < width; ++col) {
1095     + switch (png_get_color_type(png_ptr, info_ptr)) {
1096     case PNG_COLOR_TYPE_GRAY: {
1097     pngcolor fgColor;
1098     + png_color_16p trans_color;
1099     +
1100     fgColor.r = fgColor.g = fgColor.b = get_png_val(png_pixelP);
1101     - setXel(&xelrow[col], fgColor, bgColor, alpha_handling,
1102     - ((info_ptr->valid & PNG_INFO_tRNS) &&
1103     - (fgColor.r ==
1104     - gamma_correct(info_ptr->trans_values.gray,
1105     - totalgamma))) ?
1106     - 0 : maxval);
1107     +
1108     + if (png_get_tRNS(png_ptr, info_ptr,
1109     + NULL, NULL, &trans_color) & PNG_INFO_tRNS &&
1110     + (fgColor.r == gamma_correct(trans_color->gray,
1111     + totalgamma))) {
1112     + setXel(&xelrow[col], fgColor, bgColor, alpha_handling, 0);
1113     + } else {
1114     + setXel(&xelrow[col], fgColor, bgColor, alpha_handling,
1115     + maxval);
1116     + }
1117     }
1118     break;
1119    
1120     @@ -902,19 +980,31 @@
1121     break;
1122    
1123     case PNG_COLOR_TYPE_PALETTE: {
1124     - png_uint_16 const index = get_png_val(png_pixelP);
1125     - png_color const paletteColor = info_ptr->palette[index];
1126     -
1127     - pngcolor fgColor;
1128     -
1129     - fgColor.r = paletteColor.red;
1130     - fgColor.g = paletteColor.green;
1131     - fgColor.b = paletteColor.blue;
1132     -
1133     - setXel(&xelrow[col], fgColor, bgColor, alpha_handling,
1134     - (info_ptr->valid & PNG_INFO_tRNS) &&
1135     - index < info_ptr->num_trans ?
1136     - info_ptr->trans[index] : maxval);
1137     + png_uint_16 const index = get_png_val(png_pixelP);
1138     + png_colorp palette;
1139     + int num_palette;
1140     +
1141     + if (png_get_PLTE(png_ptr, info_ptr,
1142     + &palette, &num_palette) & PNG_INFO_PLTE) {
1143     + png_color const paletteColor = palette[index];
1144     + pngcolor fgColor;
1145     + png_bytep trans_alpha;
1146     + int num_trans;
1147     +
1148     + fgColor.r = paletteColor.red;
1149     + fgColor.g = paletteColor.green;
1150     + fgColor.b = paletteColor.blue;
1151     +
1152     + if (png_get_tRNS(png_ptr, info_ptr,
1153     + &trans_alpha,
1154     + &num_trans, NULL) & PNG_INFO_tRNS) {
1155     + setXel(&xelrow[col], fgColor, bgColor, alpha_handling,
1156     + index < num_trans ? trans_alpha[index] : maxval);
1157     + } else {
1158     + setXel(&xelrow[col], fgColor, bgColor, alpha_handling,
1159     + maxval);
1160     + }
1161     + }
1162     }
1163     break;
1164    
1165     @@ -925,8 +1015,8 @@
1166     fgColor.g = get_png_val(png_pixelP);
1167     fgColor.b = get_png_val(png_pixelP);
1168     setXel(&xelrow[col], fgColor, bgColor, alpha_handling,
1169     - isTransparentColor(fgColor, info_ptr, totalgamma) ?
1170     - 0 : maxval);
1171     + isTransparentColor(fgColor, png_ptr, info_ptr,
1172     + totalgamma) ? 0 : maxval);
1173     }
1174     break;
1175    
1176     @@ -943,10 +1033,10 @@
1177     break;
1178    
1179     default:
1180     - pm_error ("unknown PNG color type: %d", info_ptr->color_type);
1181     + pm_error ("unknown PNG color type: %d", png_get_color_type(png_ptr, info_ptr));
1182     }
1183     }
1184     - pnm_writepnmrow(ofP, xelrow, info_ptr->width, maxval, pnm_type, FALSE);
1185     + pnm_writepnmrow(ofP, xelrow, width, maxval, pnm_type, FALSE);
1186     }
1187     pnm_freerow (xelrow);
1188     }
1189     @@ -967,6 +1057,7 @@
1190     int pnm_type;
1191     pngcolor bgColor;
1192     float totalgamma;
1193     + int res_x, res_y, unit_type;
1194    
1195     *errorlevelP = 0;
1196    
1197     @@ -989,28 +1080,28 @@
1198     png_set_sig_bytes (png_ptr, SIG_CHECK_SIZE);
1199     png_read_info (png_ptr, info_ptr);
1200    
1201     - MALLOCARRAY(png_image, info_ptr->height);
1202     + MALLOCARRAY(png_image, png_get_image_height(png_ptr, info_ptr));
1203     if (png_image == NULL) {
1204     png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp)NULL);
1205     pm_closer (ifp);
1206     pm_error ("couldn't allocate space for image");
1207     }
1208    
1209     - if (info_ptr->bit_depth == 16)
1210     - linesize = 2 * info_ptr->width;
1211     + if (png_get_bit_depth(png_ptr, info_ptr) == 16)
1212     + linesize = 2 * png_get_image_width(png_ptr, info_ptr);
1213     else
1214     - linesize = info_ptr->width;
1215     + linesize = png_get_image_width(png_ptr, info_ptr);
1216    
1217     - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
1218     + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY_ALPHA)
1219     linesize *= 2;
1220     else
1221     - if (info_ptr->color_type == PNG_COLOR_TYPE_RGB)
1222     + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB)
1223     linesize *= 3;
1224     else
1225     - if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1226     + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA)
1227     linesize *= 4;
1228    
1229     - for (y = 0 ; y < info_ptr->height ; y++) {
1230     + for (y = 0 ; y < png_get_image_height(png_ptr, info_ptr) ; y++) {
1231     png_image[y] = malloc (linesize);
1232     if (png_image[y] == NULL) {
1233     for (x = 0 ; x < y ; x++)
1234     @@ -1022,7 +1113,7 @@
1235     }
1236     }
1237    
1238     - if (info_ptr->bit_depth < 8)
1239     + if (png_get_bit_depth(png_ptr, info_ptr) < 8)
1240     png_set_packing (png_ptr);
1241    
1242     setupGammaCorrection(png_ptr, info_ptr, cmdline.gamma, &totalgamma);
1243     @@ -1030,8 +1121,8 @@
1244     setupSignificantBits(png_ptr, info_ptr, cmdline.alpha,
1245     &maxval, errorlevelP);
1246    
1247     - getBackgroundColor(info_ptr, cmdline.background, totalgamma, maxval,
1248     - &bgColor);
1249     + getBackgroundColor(png_ptr, info_ptr, cmdline.background, totalgamma,
1250     + maxval, &bgColor);
1251    
1252     png_read_image (png_ptr, png_image);
1253     png_read_end (png_ptr, info_ptr);
1254     @@ -1041,16 +1132,17 @@
1255     completes. That's because it comes from chunks that are at the
1256     end of the stream.
1257     */
1258     - dump_png_info(info_ptr);
1259     + dump_png_info(png_ptr, info_ptr);
1260    
1261     if (mtime)
1262     - show_time (info_ptr);
1263     + show_time (png_ptr, info_ptr);
1264     if (tfp)
1265     - save_text (info_ptr, tfp);
1266     + save_text (png_ptr, info_ptr, tfp);
1267    
1268     - if (info_ptr->valid & PNG_INFO_pHYs) {
1269     + if (png_get_pHYs(png_ptr, info_ptr,
1270     + &res_x, &res_y, &unit_type) & PNG_INFO_pHYs) {
1271     float r;
1272     - r = (float)info_ptr->x_pixels_per_unit / info_ptr->y_pixels_per_unit;
1273     + r = (float)res_x / res_y;
1274     if (r != 1.0) {
1275     pm_message ("warning - non-square pixels; "
1276     "to fix do a 'pamscale -%cscale %g'",
1277     @@ -1060,13 +1152,13 @@
1278     }
1279     }
1280    
1281     - determineOutputType(info_ptr, cmdline.alpha, bgColor, maxval, &pnm_type);
1282     + determineOutputType(png_ptr, info_ptr, cmdline.alpha, bgColor, maxval, &pnm_type);
1283    
1284     - writePnm(stdout, maxval, pnm_type, info_ptr, png_image, bgColor,
1285     + writePnm(stdout, maxval, pnm_type, png_ptr, info_ptr, png_image, bgColor,
1286     cmdline.alpha, totalgamma);
1287    
1288     fflush(stdout);
1289     - for (y = 0 ; y < info_ptr->height ; y++)
1290     + for (y = 0 ; y < png_get_image_height(png_ptr, info_ptr) ; y++)
1291     free (png_image[y]);
1292     free (png_image);
1293     png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp)NULL);
1294     $NetBSD: patch-aj,v 1.13 2011/01/14 21:51:59 tron Exp $
1295    
1296     Fix build with png-1.5.
1297    
1298     --- converter/other/pngtxt.h.orig 2006-08-19 04:12:28.000000000 +0100
1299     +++ converter/other/pngtxt.h 2011-01-14 21:39:26.000000000 +0000
1300     @@ -5,7 +5,8 @@
1301     #include <png.h>
1302    
1303     void
1304     -pnmpng_read_text (png_info * const info_ptr,
1305     +pnmpng_read_text (png_struct * png_ptr,
1306     + png_info * const info_ptr,
1307     FILE * const tfp,
1308     bool const ztxt,
1309     bool const verbose);
1310     $NetBSD: patch-ak,v 1.9 2011/01/14 21:51:59 tron Exp $
1311    
1312     Fix build with png-1.5.
1313    
1314     --- converter/other/pngtxt.c.orig 2006-08-19 04:12:28.000000000 +0100
1315     +++ converter/other/pngtxt.c 2011-01-14 21:28:09.000000000 +0000
1316     @@ -240,7 +240,8 @@
1317    
1318    
1319     void
1320     -pnmpng_read_text (png_info * const info_ptr,
1321     +pnmpng_read_text (png_struct * png_ptr,
1322     + png_info * info_ptr,
1323     FILE * const tfp,
1324     bool const ztxt,
1325     bool const verbose) {
1326     @@ -250,6 +251,7 @@
1327     unsigned int commentIdx;
1328     bool noCommentsYet;
1329     bool eof;
1330     + png_textp text_ptr;
1331     unsigned int allocatedComments;
1332     /* Number of entries currently allocated for the info_ptr->text
1333     array
1334     @@ -257,8 +259,8 @@
1335    
1336     allocatedComments = 256; /* initial value */
1337    
1338     - MALLOCARRAY(info_ptr->text, allocatedComments);
1339     - if (info_ptr->text == NULL)
1340     + MALLOCARRAY(text_ptr, allocatedComments);
1341     + if (text_ptr == NULL)
1342     pm_error("unable to allocate memory for comment array");
1343    
1344     commentIdx = 0;
1345     @@ -273,7 +275,7 @@
1346     if (lineLength == 0) {
1347     /* skip this empty line */
1348     } else {
1349     - handleArrayAllocation(&info_ptr->text, &allocatedComments,
1350     + handleArrayAllocation(&text_ptr, &allocatedComments,
1351     commentIdx);
1352     if ((textline[0] != ' ') && (textline[0] != '\t')) {
1353     /* Line doesn't start with white space, which
1354     @@ -285,7 +287,7 @@
1355     ++commentIdx;
1356     noCommentsYet = FALSE;
1357    
1358     - startComment(&info_ptr->text[commentIdx],
1359     + startComment(&text_ptr[commentIdx],
1360     textline, lineLength, ztxt);
1361     } else {
1362     /* Line starts with whitespace, which means it is
1363     @@ -295,20 +297,20 @@
1364     pm_error("Invalid comment file format: "
1365     "first line is a continuation line! "
1366     "(It starts with whitespace)");
1367     - continueComment(&info_ptr->text[commentIdx],
1368     + continueComment(&text_ptr[commentIdx],
1369     textline, lineLength);
1370     }
1371     }
1372     strfree(textline);
1373     }
1374     }
1375     - if (noCommentsYet)
1376     - info_ptr->num_text = 0;
1377     - else
1378     - info_ptr->num_text = commentIdx + 1;
1379     + if (!noCommentsYet)
1380     + png_set_text(png_ptr, info_ptr, text_ptr, commentIdx + 1);
1381    
1382     if (verbose)
1383     - pm_message("%d comments placed in text chunk", info_ptr->num_text);
1384     + pm_message("%d comments placed in text chunk", commentIdx + 1);
1385     +
1386     + free(text_ptr);
1387     }
1388    
1389    
1390     $NetBSD: patch-al,v 1.5 2011/01/15 18:37:46 tron Exp $
1391    
1392     Fix build with png-1.5.
1393    
1394     --- converter/other/pamrgbatopng.c.orig 2006-08-19 04:12:28.000000000 +0100
1395     +++ converter/other/pamrgbatopng.c 2011-01-15 18:24:36.000000000 +0000
1396     @@ -101,10 +101,8 @@
1397     if (!infoP)
1398     pm_error("Could not allocate PNG info structure");
1399     else {
1400     - infoP->width = pamP->width;
1401     - infoP->height = pamP->height;
1402     - infoP->bit_depth = 8;
1403     - infoP->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
1404     + png_set_IHDR(pngP, infoP, pamP->width, pamP->height,
1405     + 8, PNG_COLOR_TYPE_RGB_ALPHA, 0, 0, 0);
1406    
1407     png_init_io(pngP, ofP);
1408