]> git.pld-linux.org Git - packages/netpbm.git/blob - netpbm-build.patch
3f5865f8f9101110d15b6169a295e57cd581f28e
[packages/netpbm.git] / netpbm-build.patch
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
3 @@ -59,7 +59,8 @@
4  #include <assert.h>
5  #include <string.h> /* strcat() */
6  #include <limits.h>
7 -#include <png.h>    /* includes zlib.h and setjmp.h */
8 +#include <png.h>    /* includes setjmp.h */
9 +#include <zlib.h>
10  
11  #include "pm_c_util.h"
12  #include "pnm.h"
13 @@ -69,20 +70,6 @@
14  #include "nstring.h"
15  #include "version.h"
16  
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)
21 -#endif
22 -
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
27 -#else
28 -#define TRANS_ALPHA trans
29 -#endif
30 -
31  
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) {
44          xel p_png;
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) {
52              if (depth == 16)
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;
58              if (alpha)
59                  paletteIndex = lookupColorAlpha(caht, &p, &alpha_mask[col]);
60              else
61                  paletteIndex = ppm_lookupcolor(cht, &p);
62              *pp++ = paletteIndex;
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) {
67              if (depth == 16)
68                  *pp++ = PPM_GETR(p_png) >> 8;
69              *pp++ = PPM_GETR(p_png) & 0xff;
70 @@ -2169,7 +2158,7 @@ makePngLine(png_byte *           const l
71          } else
72              pm_error("INTERNAL ERROR: undefined color_type");
73                  
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;
78              if (depth == 16)
79 @@ -2226,7 +2215,7 @@ writeRaster(png_struct *         const p
80              
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);
85  
86              png_write_row(png_ptr, line);
87          }
88 @@ -2238,12 +2227,12 @@ writeRaster(png_struct *         const p
89  
90  static void
91  doGamaChunk(struct cmdlineInfo const cmdline,
92 +            png_struct *       const png_ptr,
93              png_info *         const info_ptr) {
94              
95      if (cmdline.gammaSpec) {
96          /* gAMA chunk */
97 -        info_ptr->valid |= PNG_INFO_gAMA;
98 -        info_ptr->gamma = cmdline.gamma;
99 +        png_set_gAMA(png_ptr, info_ptr, cmdline.gamma);           
100      }
101  }
102  
103 @@ -2251,20 +2240,16 @@ doGamaChunk(struct cmdlineInfo const cmd
104  
105  static void
106  doChrmChunk(struct cmdlineInfo const cmdline,
107 +            png_struct *       const png_ptr,
108              png_info *         const info_ptr) {
109  
110      if (cmdline.rgbSpec) {
111          /* cHRM chunk */
112 -        info_ptr->valid |= PNG_INFO_cHRM;
113 -
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);
127      }
128  }
129  
130 @@ -2272,15 +2257,13 @@ doChrmChunk(struct cmdlineInfo const cmd
131  
132  static void
133  doPhysChunk(struct cmdlineInfo const cmdline,
134 +            png_struct *       const png_ptr,
135              png_info *         const info_ptr) {
136  
137      if (cmdline.sizeSpec) {
138          /* pHYS chunk */
139 -        info_ptr->valid |= PNG_INFO_pHYs;
140 -
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);
146      }
147  }
148  
149 @@ -2289,26 +2272,29 @@ doPhysChunk(struct cmdlineInfo const cmd
150  
151  static void
152  doTimeChunk(struct cmdlineInfo const cmdline,
153 +            png_struct *       const png_ptr,
154              png_info *         const info_ptr) {
155  
156      if (cmdline.modtimeSpec) {
157          /* tIME chunk */
158 -        info_ptr->valid |= PNG_INFO_tIME;
159 -
160 -        png_convert_from_time_t(&info_ptr->mod_time, cmdline.modtime);
161 +        png_time ptime;
162 +        png_convert_from_time_t(&ptime, cmdline.modtime);
163 +        png_set_tIME(png_ptr, info_ptr, &ptime);
164      }
165  }
166  
167  
168  
169  static void
170 -doSbitChunk(png_info * const pngInfoP,
171 +doSbitChunk(png_struct * const png_ptr,
172 +            png_info * const pngInfoP,
173              xelval     const pngMaxval,
174              xelval     const maxval,
175              bool       const alpha,
176              xelval     const alphaMaxval) {
177  
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))) {
182  
183          /* We're writing in a bit depth that doesn't match the maxval
184 @@ -2327,27 +2313,27 @@ doSbitChunk(png_info * const pngInfoP,
185             sBIT chunk.
186          */
187  
188 -        pngInfoP->valid |= PNG_INFO_sBIT;
189 -
190 +        png_color_8 sbit;
191          {
192              int const sbitval = pm_maxvaltobits(MIN(maxval, pngMaxval));
193  
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;
202              } else
203 -                pngInfoP->sig_bit.gray = sbitval;
204 +                sbit.gray = sbitval;
205              
206              if (verbose)
207                  pm_message("Writing sBIT chunk with bits = %d", sbitval);
208          }
209 -        if (pngInfoP->color_type & PNG_COLOR_MASK_ALPHA) {
210 -            pngInfoP->sig_bit.alpha =
211 +        if (color_type & PNG_COLOR_MASK_ALPHA) {
212 +            sbit.alpha =
213                  pm_maxvaltobits(MIN(alphaMaxval, pngMaxval));
214              if (verbose)
215 -                pm_message("  alpha bits = %d", pngInfoP->sig_bit.alpha);
216 +                pm_message("  alpha bits = %d", sbit.alpha);
217          }
218 +        png_set_sBIT(png_ptr, pngInfoP, &sbit);
219      }
220  }
221  
222 @@ -2628,43 +2614,40 @@ convertpnm(struct cmdlineInfo const cmdl
223      pm_error ("setjmp returns error condition (2)");
224    }
225  
226 -  png_init_io (png_ptr, stdout);
227 -  info_ptr->width = cols;
228 -  info_ptr->height = rows;
229 -  info_ptr->bit_depth = depth;
230 -
231 +  {
232 +  int color_type;
233    if (colorMapped)
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;
239    else
240 -    info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
241 +    color_type = PNG_COLOR_TYPE_GRAY;
242 +
243 +  if (alpha && color_type != PNG_COLOR_TYPE_PALETTE)
244 +    color_type |= PNG_COLOR_MASK_ALPHA;
245  
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);
249 +  }
250  
251 -  info_ptr->interlace_type = cmdline.interlace;
252 +  if (cmdline.interlace)
253 +    png_set_interlace_handling(png_ptr);
254  
255 -  doGamaChunk(cmdline, info_ptr);
256 +  doGamaChunk(cmdline, png_ptr, info_ptr);
257  
258 -  doChrmChunk(cmdline, info_ptr);
259 +  doChrmChunk(cmdline, png_ptr, info_ptr);
260  
261 -  doPhysChunk(cmdline, info_ptr);
262 +  doPhysChunk(cmdline, png_ptr, info_ptr);
263  
264 -  if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
265 +  if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
266  
267      /* creating PNG palette  (PLTE and tRNS chunks) */
268  
269      createPngPalette(palette_pnm, palette_size, maxval,
270                       trans_pnm, trans_size, alpha_maxval, 
271                       palette, trans);
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);
281      }
282      /* creating hIST chunk */
283      if (cmdline.hist) {
284 @@ -2690,18 +2673,17 @@ convertpnm(struct cmdlineInfo const cmdl
285  
286          ppm_freecolorhash(cht);
287  
288 -        info_ptr->valid |= PNG_INFO_hIST;
289 -        info_ptr->hist = histogram;
290 +        png_set_hIST(png_ptr, info_ptr, histogram);
291          if (verbose)
292              pm_message("histogram created");
293      }
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);
306          }
307      } else {
308          /* This is PNG_COLOR_MASK_ALPHA.  Transparency will be handled
309 @@ -2709,13 +2691,17 @@ convertpnm(struct cmdlineInfo const cmdl
310          */
311      }
312      if (verbose) {
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);
317 +        }
318 +        if(trans_colorp != NULL)
319              pm_message("Transparent color {gray, red, green, blue} = "
320                         "{%d, %d, %d, %d}",
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,
326 +                       trans_colorp->red,
327 +                       trans_colorp->green,
328 +                       trans_colorp->blue);
329          else
330              pm_message("No transparent color");
331      }
332 @@ -2723,29 +2709,29 @@ convertpnm(struct cmdlineInfo const cmdl
333  
334    /* bKGD chunk */
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;
339 +      png_color_16 bkgd;
340 +      if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
341 +          bkgd.index = background_index;
342        } else {
343 -          info_ptr->background = 
344 -              xelToPngColor_16(backcolor, maxval, png_maxval);
345 +          bkgd = xelToPngColor_16(backcolor, maxval, png_maxval);
346            if (verbose)
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 ); 
353 +                         bkgd.gray, 
354 +                         bkgd.red, 
355 +                         bkgd.green, 
356 +                         bkgd.blue ); 
357        }
358 +      png_set_bKGD(png_ptr, info_ptr, &bkgd);
359    }
360  
361 -  doSbitChunk(info_ptr, png_maxval, maxval, alpha, alpha_maxval);
362 +  doSbitChunk(png_ptr, info_ptr, png_maxval, maxval, alpha, alpha_maxval);
363  
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);
368  
369 -  doTimeChunk(cmdline, info_ptr);
370 +  doTimeChunk(cmdline, png_ptr, info_ptr);
371  
372    if (cmdline.filterSetSpec)
373        png_set_filter(png_ptr, 0, cmdline.filterSet);
374 @@ -2755,17 +2741,11 @@ convertpnm(struct cmdlineInfo const cmdl
375  
376    setZlibCompression(png_ptr, cmdline.zlibCompression);
377  
378 +  png_init_io (png_ptr, stdout);
379 +
380    /* write the png-info struct */
381    png_write_info(png_ptr, info_ptr);
382  
383 -  if (cmdline.text || cmdline.ztxt)
384 -      /* prevent from being written twice with png_write_end */
385 -      info_ptr->num_text = 0;
386 -
387 -  if (cmdline.modtime)
388 -      /* prevent from being written twice with png_write_end */
389 -      info_ptr->valid &= ~PNG_INFO_tIME;
390 -
391    /* let libpng take care of, e.g., bit-depth conversions */
392    png_set_packing (png_ptr);
393  
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
396 @@ -32,19 +32,6 @@
397  #include "shhopt.h"
398  #include "pnm.h"
399  
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)
404 -#endif
405 -
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
409 -#else
410 -#define TRANS_ALPHA trans
411 -#endif
412 -
413  
414  enum alpha_handling {ALPHA_NONE, ALPHA_ONLY, ALPHA_MIX};
415  
416 @@ -269,23 +256,25 @@ verifyFileIsPng(FILE *   const ifP,
417  static unsigned int
418  computePngLineSize(struct pngx * const pngxP) {
419  
420 -    unsigned int const bytesPerSample =
421 -        pngxP->info_ptr->bit_depth == 16 ? 2 : 1;
422 -
423 +    png_uint_32 width;
424 +    int bit_depth, color_type;
425 +    unsigned int bytesPerSample;
426      unsigned int samplesPerPixel;
427  
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;
436      }
437  
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);
443         
444 -    return pngxP->info_ptr->width * bytesPerSample * samplesPerPixel;
445 +    return width * bytesPerSample * samplesPerPixel;
446  }
447  
448  
449 @@ -297,15 +286,16 @@ allocPngRaster(struct pngx * const pngxP
450      unsigned int const lineSize = computePngLineSize(pngxP);
451  
452      png_byte ** pngImage;
453 +    png_uint_32 height = png_get_image_height(pngxP->png_ptr, pngxP->info_ptr);
454      unsigned int row;
455  
456 -    MALLOCARRAY(pngImage, pngxP->info_ptr->height);
457 +    MALLOCARRAY(pngImage, height);
458  
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);
463  
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
470  
471      unsigned int row;
472  
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]);
476  
477      free(pngRaster);
478 @@ -349,7 +339,7 @@ readPng(struct pngx * const pngxP,
479  
480      allocPngRaster(pngxP, &pngRaster);
481  
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);
485  
486      png_read_image(pngxP->png_ptr, pngRaster);
487 @@ -445,31 +435,34 @@ saveText(struct pngx * const pngxP,
488           FILE *        const tfP) {
489  
490      png_info * const info_ptr = pngxP->info_ptr;
491 -
492 +    png_text *text;
493 +    int num_text;
494      unsigned int i;
495  
496 -    for (i = 0 ; i < info_ptr->num_text; ++i) {
497 +    png_get_text(pngxP->png_ptr, info_ptr, &text, &num_text);
498 +
499 +    for (i = 0 ; i < num_text; ++i) {
500          unsigned int j;
501          j = 0;
502  
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] != ' ')
507              ++j;    
508  
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)
515                  putc(' ', tfP);
516          } else {
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)
521                  putc(' ', tfP);
522          }
523          putc(' ', tfP); /* at least one space between key and text */
524      
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') {
531                  unsigned int k;
532                  for (k = 0; k < 16; ++k)
533                      putc(' ', tfP);
534 @@ -489,21 +482,23 @@ showTime(struct pngx * const pngxP) {
535          "July", "August", "September", "October", "November", "December"
536      };
537  
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);
551        } else
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);
559 +                   mod_timep->day,
560 +                   month[mod_timep->month],
561 +                   mod_timep->year,
562 +                   mod_timep->hour,
563 +                   mod_timep->minute,
564 +                   mod_timep->second);
565      }
566  }
567  
568 @@ -516,7 +511,7 @@ dumpPngInfo(struct pngx * const pngxP) {
569      const char *type_string;
570      const char *filter_string;
571  
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";
576          break;
577 @@ -538,90 +533,106 @@ dumpPngInfo(struct pngx * const pngxP) {
578          break;
579      }
580  
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");
585          break;
586      default:
587          asprintfN(&filter_string, "unknown filter type %d", 
588 -                  info_ptr->filter_type);
589 +                  png_get_filter_type(pngxP->png_ptr, info_ptr));
590      }
591  
592 +    {
593 +    png_uint_32 width, height;
594 +    int bit_depth;
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" : "");
601 +    }
602      pm_message("%s, %s, %s",
603                 type_string,
604 -               info_ptr->interlace_type ? 
605 +               png_get_interlace_type(pngxP->png_ptr, info_ptr) ? 
606                 "Adam7 interlaced" : "not interlaced",
607                 filter_string);
608 +    {
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);
618 +               bkgp->index,
619 +               bkgp->gray,
620 +               bkgp->red,
621 +               bkgp->green,
622 +               bkgp->blue);
623 +    }
624  
625      strfree(filter_string);
626  
627 -    if (info_ptr->valid & PNG_INFO_tRNS)
628 +    if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_tRNS)) {
629 +        int num_trans;
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);
633 -    else
634 +                   num_trans);
635 +    } else
636          pm_message("tRNS chunk (transparency): not present");
637  
638 -    if (info_ptr->valid & PNG_INFO_gAMA)
639 -        pm_message("gAMA chunk (image gamma): gamma = %4.2f", info_ptr->gamma);
640 -    else
641 +    if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_gAMA)) {
642 +        double gamma;
643 +        png_get_gAMA(pngxP->png_ptr, info_ptr, &gamma);
644 +        pm_message("gAMA chunk (image gamma): gamma = %4.2f", gamma);
645 +    } else
646          pm_message("gAMA chunk (image gamma): not present");
647  
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");
651      else
652          pm_message("sBIT chunk: not present");
653  
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");
657      else
658          pm_message("cHRM chunk: not present");
659  
660 -    if (info_ptr->valid & PNG_INFO_PLTE)
661 -        pm_message("PLTE chunk: %d entries", info_ptr->num_palette);
662 -    else
663 +    if (png_get_valid(pngxP->png_ptr, info_ptr, PNG_INFO_PLTE)) {
664 +        png_colorp palette;
665 +        int num_palette;
666 +        png_get_PLTE(pngxP->png_ptr, info_ptr, &palette, &num_palette);
667 +        pm_message("PLTE chunk: %d entries", num_palette);
668 +    } else
669          pm_message("PLTE chunk: not present");
670  
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");
674      else
675          pm_message("bKGD chunk: not present");
676  
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");
680      else
681          pm_message("hIST chunk: not present");
682  
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");
686      else
687          pm_message("pHYs chunk: not present");
688  
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");
692      else
693          pm_message("oFFs chunk: not present");
694  
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");
698      else
699          pm_message("tIME chunk: not present");
700  
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");
704      else
705          pm_message("pCAL chunk: not present");
706  
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");
710      else
711          pm_message("sRGB chunk: not present");
712 @@ -675,7 +686,7 @@ isTransparentColor(pngcolor      const c
713             pixels, and just do it ourselves.
714          */
715      
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);
720              break;
721 @@ -702,9 +713,11 @@ setupGammaCorrection(struct pngx * const
722          *totalgammaP = -1.0;
723      else {
724          float imageGamma;
725 -        if (pngxP->info_ptr->valid & PNG_INFO_gAMA)
726 -            imageGamma = pngxP->info_ptr->gamma;
727 -        else {
728 +        if (png_get_valid(pngxP->png_ptr, pngxP->info_ptr, PNG_INFO_gAMA)) {
729 +            double gamma;
730 +            png_get_gAMA(pngxP->png_ptr, pngxP->info_ptr, &gamma);
731 +            imageGamma = gamma;
732 +       } else {
733              if (verbose)
734                  pm_message("PNG doesn't specify image gamma.  Assuming 1.0");
735              imageGamma = 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 
739              */
740 -            pngxP->info_ptr->valid &= ~PNG_INFO_sBIT;
741 +            png_set_invalid(pngxP->png_ptr, pngxP->info_ptr, PNG_INFO_sBIT);
742              if (verbose)
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
746  
747  
748  static bool
749 -paletteHasPartialTransparency(png_info * const info_ptr) {
750 +paletteHasPartialTransparency(png_struct * const png_ptr, png_info * const info_ptr) {
751  
752      bool retval;
753  
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)) {
758              bool foundGray;
759              unsigned int i;
760 +            int num_trans;
761 +            png_bytep trans_alpha;
762 +            png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, NULL);
763              
764              for (i = 0, foundGray = FALSE;
765 -                 i < info_ptr->num_trans && !foundGray;
766 +                 i < num_trans && !foundGray;
767                   ++i) {
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) {
772                      foundGray = TRUE;
773                  }
774              }
775 @@ -777,13 +793,14 @@ setupSignificantBits(struct pngx *
776      png_info * const info_ptr = pngxP->info_ptr;
777  
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 */
788                  *maxvalP = 1;
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*/
792                  *maxvalP = 255;
793              else
794 @@ -793,7 +810,7 @@ setupSignificantBits(struct pngx *
795              /* Use same maxval as PNG palette for simplicity */
796              *maxvalP = 255;
797      } else {
798 -        *maxvalP = (1l << info_ptr->bit_depth) - 1;
799 +        *maxvalP = (1l << png_get_bit_depth(pngxP->png_ptr, info_ptr)) - 1;
800      }
801  
802      /* sBIT handling is very tricky. If we are extracting only the
803 @@ -806,20 +823,25 @@ setupSignificantBits(struct pngx *
804         is used 
805      */
806      
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);
811          switch (alpha) {
812          case ALPHA_MIX:
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)
817                  break;
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))) {
822  
823 +                png_bytep trans_alpha;
824 +                int num_trans;
825                  bool trans_mix;
826                  unsigned int i;
827                  trans_mix = TRUE;
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) {
833                          trans_mix = FALSE;
834                          break;
835                      }
836 @@ -830,70 +852,73 @@ setupSignificantBits(struct pngx *
837              /* else fall though to normal case */
838  
839          case ALPHA_NONE:
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;
857              } else {
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)) {
862                      unsigned int i;
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;
871 +                    int num_palette;
872 +                    png_get_PLTE(pngxP->png_ptr, info_ptr, &palette, &num_palette);
873 +                    for (i = 0; i < num_palette; ++i) {
874 +                        palette[i].red   >>=
875 +                            (8 - sig_bit->red);
876 +                        palette[i].green >>=
877 +                            (8 - sig_bit->green);
878 +                        palette[i].blue  >>=
879 +                            (8 - sig_bit->blue);
880                      }
881 -                    *maxvalP = (1l << info_ptr->sig_bit.red) - 1;
882 +                    *maxvalP = (1l << sig_bit->red) - 1;
883                      if (verbose)
884                          pm_message ("image has fewer significant bits, "
885                                      "writing file with %d bits per channel", 
886 -                                    info_ptr->sig_bit.red);
887 +                                    sig_bit->red);
888                  } else
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;
899                          if (verbose)
900                              pm_message("image has fewer significant bits, "
901                                         "writing file with %d "
902                                         "bits per channel", 
903 -                                       info_ptr->sig_bit.red);
904 +                                       sig_bit->red);
905                      } else 
906 -                        if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
907 -                             info_ptr->color_type ==
908 +                        if ((color_type == PNG_COLOR_TYPE_GRAY ||
909 +                             color_type ==
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;
917                              if (verbose)
918                                  pm_message("image has fewer significant bits, "
919                                             "writing file with %d bits",
920 -                                           info_ptr->sig_bit.gray);
921 +                                           sig_bit->gray);
922                          }
923              }
924              break;
925  
926          case ALPHA_ONLY:
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);
935                  if (verbose)
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;
940 +                                sig_bit->alpha);
941 +                *maxvalP = (1l << sig_bit->alpha) - 1;
942              }
943              break;
944  
945 @@ -908,18 +933,23 @@ imageHasColor(struct pngx * const pngxP)
946  
947      bool retval;
948  
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)
954  
955          retval = FALSE;
956 -    else if (pngxP->info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
957 +    else if (color_type == PNG_COLOR_TYPE_PALETTE) {
958          bool foundColor;
959          unsigned int i;
960 +        png_colorp palette;
961 +        int num_palette;
962 +
963 +        png_get_PLTE(pngxP->png_ptr, pngxP->info_ptr, &palette, &num_palette);
964              
965          for (i = 0, foundColor = FALSE;
966 -             i < pngxP->info_ptr->num_palette && !foundColor;
967 +             i < num_palette && !foundColor;
968               ++i) {
969 -            if (iscolor(pngxP->info_ptr->palette[i]))
970 +            if (iscolor(palette[i]))
971                  foundColor = TRUE;
972          }
973          retval = foundColor;
974 @@ -974,19 +1004,24 @@ getBackgroundColor(struct pngx * const p
975          bgColorP->g = PPM_GETG(backcolor);
976          bgColorP->b = PPM_GETB(backcolor);
977  
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.
984          */
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);
992              break;
993          case PNG_COLOR_TYPE_PALETTE: {
994 +            png_colorp palette;
995 +            int num_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
1004          break;
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;
1009              
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) {
1015  
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);
1020          float const r =
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;
1025  
1026          if (r != 1.0) {
1027              pm_message ("warning - non-square pixels; "
1028 @@ -1030,7 +1067,7 @@ warnNonsquarePixels(struct pngx * const
1029  
1030  
1031  
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))
1034  
1035  
1036  
1037 @@ -1048,8 +1085,8 @@ makeXelRow(xel *               const xel
1038      unsigned int col;
1039  
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: {
1046              pngcolor fgColor;
1047              fgColor.r = fgColor.g = fgColor.b = GET_PNG_VAL(pngPixelP);
1048 @@ -1071,7 +1108,15 @@ makeXelRow(xel *               const xel
1049  
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);
1059 +           if (trans_valid)
1060 +               png_get_tRNS(pngxP->png_ptr, pngxP->info_ptr, &trans_alpha, &num_trans, NULL);
1061 +            paletteColor = palette[index];
1062  
1063              pngcolor fgColor;
1064  
1065 @@ -1080,9 +1125,9 @@ makeXelRow(xel *               const xel
1066              fgColor.b = paletteColor.blue;
1067  
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);
1072 +                   trans_valid &&
1073 +                   index < num_trans ?
1074 +                   trans_alpha[index] : maxval);
1075          }
1076          break;
1077                  
1078 @@ -1112,13 +1157,20 @@ makeXelRow(xel *               const xel
1079  
1080          default:
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));
1084          }
1085      }
1086  }
1087  
1088  
1089  
1090 +static png_bytep get_png_trans_alpha(struct pngx * const pngxP)
1091 +{
1092 +    png_bytep trans_alpha;
1093 +    png_get_tRNS(pngxP->png_ptr, pngxP->info_ptr, &trans_alpha, NULL, NULL);
1094 +    return trans_alpha;
1095 +}
1096
1097  static void
1098  writePnm(FILE *              const ofP,
1099           xelval              const maxval,
1100 @@ -1142,6 +1194,8 @@ writePnm(FILE *              const ofP,
1101  
1102      xel * xelrow;
1103      unsigned int row;
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);
1106  
1107      if (verbose)
1108          pm_message("writing a %s file (maxval=%u)",
1109 @@ -1151,17 +1205,17 @@ writePnm(FILE *              const ofP,
1110                     "UNKNOWN!", 
1111                     maxval);
1112      
1113 -    xelrow = pnm_allocrow(pngxP->info_ptr->width);
1114 +    xelrow = pnm_allocrow(width);
1115  
1116      pnm_writepnminit(stdout,
1117 -                     pngxP->info_ptr->width, pngxP->info_ptr->height, maxval,
1118 +                     width, height, maxval,
1119                       pnmType, plainFalse);
1120  
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);
1125  
1126 -        pnm_writepnmrow(ofP, xelrow, pngxP->info_ptr->width, maxval,
1127 +        pnm_writepnmrow(ofP, xelrow, width, maxval,
1128                          pnmType, plainFalse);
1129      }
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
1133 @@ -240,7 +240,8 @@
1134  
1135  
1136  void 
1137 -pnmpng_read_text (png_info * const info_ptr, 
1138 +pnmpng_read_text (png_struct * const png_ptr,
1139 +                  png_info * const info_ptr, 
1140                    FILE *     const tfp, 
1141                    bool       const ztxt,
1142                    bool       const verbose) {
1143 @@ -250,15 +251,16 @@
1144      unsigned int commentIdx;
1145      bool noCommentsYet;
1146      bool eof;
1147 +    png_textp text;
1148      unsigned int allocatedComments;
1149 -        /* Number of entries currently allocated for the info_ptr->text
1150 +        /* Number of entries currently allocated for the text
1151             array 
1152          */
1153  
1154      allocatedComments = 256;  /* initial value */
1155  
1156 -    MALLOCARRAY(info_ptr->text, allocatedComments);
1157 -    if (info_ptr->text == NULL) 
1158 +    MALLOCARRAY(text, allocatedComments);
1159 +    if (text == NULL) 
1160          pm_error("unable to allocate memory for comment array");
1161  
1162      commentIdx = 0;
1163 @@ -273,7 +275,7 @@
1164              if (lineLength == 0) {
1165                  /* skip this empty line */
1166              } else {
1167 -                handleArrayAllocation(&info_ptr->text, &allocatedComments,
1168 +                handleArrayAllocation(&text, &allocatedComments,
1169                                        commentIdx);
1170                  if ((textline[0] != ' ') && (textline[0] != '\t')) {
1171                      /* Line doesn't start with white space, which
1172 @@ -285,7 +287,7 @@
1173                          ++commentIdx;
1174                      noCommentsYet = FALSE;
1175  
1176 -                    startComment(&info_ptr->text[commentIdx], 
1177 +                    startComment(&text[commentIdx], 
1178                                   textline, lineLength, ztxt);
1179                  } else {
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);
1188                  }
1189              }
1190              strfree(textline);
1191          }
1192      } 
1193 -    if (noCommentsYet)
1194 -        info_ptr->num_text = 0;
1195 -    else
1196 -        info_ptr->num_text = commentIdx + 1;
1197 +    if (!noCommentsYet)
1198 +        png_set_text(png_ptr, info_ptr, text, commentIdx + 1);
1199  
1200      if (verbose)
1201 -        pm_message("%d comments placed in text chunk", info_ptr->num_text);
1202 +        pm_message("%d comments placed in text chunk", commentIdx + 1);
1203 +
1204 +    free(text);
1205  }
1206  
1207  
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
1210 @@ -5,7 +5,8 @@
1211  #include <png.h>
1212  
1213  void 
1214 -pnmpng_read_text (png_info * const info_ptr, 
1215 +pnmpng_read_text (png_struct * const png_ptr,
1216 +                  png_info * const info_ptr, 
1217                    FILE *     const tfp, 
1218                    bool const ztxt,
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 @@
1223      if (!infoP)
1224          pm_error("Could not allocate PNG info structure");
1225      else {
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);
1233          
1234          png_init_io(pngP, ofP);
1235  
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 @@
1239                  
1240                  ok = TIFFRGBAImageBegin(&img, tif, stopOnErrorFalse, emsg) ;
1241                  if (!ok) {
1242 -                    pm_message(emsg);
1243 +                    pm_message("%s", emsg);
1244                      *statusP = CONV_FAILED;
1245                  } else {
1246                      int ok;
1247                      ok = TIFFRGBAImageGet(&img, raster, cols, rows);
1248                      TIFFRGBAImageEnd(&img) ;
1249                      if (!ok) {
1250 -                        pm_message(emsg);
1251 +                        pm_message("%s", emsg);
1252                          *statusP = CONV_FAILED;
1253                      } else {
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
1257 @@ -882,7 +882,7 @@
1258          int ok;
1259          ok = TIFFRGBAImageOK(tif, emsg);
1260          if (!ok) {
1261 -            pm_message(emsg);
1262 +            pm_message("%s", emsg);
1263              *statusP = CONV_UNABLE;
1264          } else {
1265              uint32* raster ;
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
1268 @@ -176,7 +176,7 @@
1269        return 0;
1270     else
1271     {
1272 -      fprintf (stderr, fiasco_get_error_message ());
1273 +      fprintf (stderr, "%s", fiasco_get_error_message ());
1274        fprintf (stderr, "\n");
1275        return 1;
1276     }
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
1279 @@ -652,7 +652,7 @@
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
1290 @@ -39,20 +39,20 @@
1291  
1292      rc = pm_readbiglong(ifP, &l);
1293      if (rc == -1 )
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);
1299      if (rc == -1)
1300 -        pm_error(initReadError);
1301 +        pm_error("%s", initReadError);
1302      *colsP = l;
1303      rc = pm_readbiglong(ifP, &l);
1304      if (rc == -1 )
1305 -        pm_error(initReadError);
1306 +        pm_error("%s", initReadError);
1307      *rowsP = l;
1308      rc = pm_readbigshort(ifP, &s);
1309      if (rc == -1)
1310 -        pm_error(initReadError);
1311 +        pm_error("%s", initReadError);
1312      *depthP = s;
1313  }
1314  
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
1317 @@ -31,16 +31,16 @@
1318  
1319      rc = pm_writebiglong(stdout, CMUWM_MAGIC);
1320      if (rc == -1)
1321 -        pm_error(initWriteError);
1322 +        pm_error("%s", initWriteError);
1323      rc = pm_writebiglong(stdout, cols);
1324      if (rc == -1)
1325 -        pm_error(initWriteError);
1326 +        pm_error("%s", initWriteError);
1327      rc = pm_writebiglong(stdout, rows);
1328      if (rc == -1)
1329 -        pm_error(initWriteError);
1330 +        pm_error("%s", initWriteError);
1331      rc = pm_writebigshort(stdout, (short) 1);
1332      if (rc == -1)
1333 -        pm_error(initWriteError);
1334 +        pm_error("%s", initWriteError);
1335  }
1336  
1337  
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
1340 @@ -30,14 +30,6 @@
1341  #include "shhopt.h"
1342  #include "pam.h"
1343  
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
1348 -#else
1349 -#define TRANS_ALPHA trans
1350 -#endif
1351 -
1352  typedef struct _jmpbuf_wrapper {
1353    jmp_buf jmpbuf;
1354  } jmpbuf_wrapper;
1355 @@ -268,28 +260,31 @@ static int iscolor (png_color c)
1356    return c.red != c.green || c.green != c.blue;
1357  }
1358  
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)
1361  {
1362    int i, j, k;
1363 +  png_text *text;
1364 +  int num_text;
1365  
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++) {
1369      j = 0;
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] != ' ')
1372        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++)
1379          putc (' ', tfp);
1380      } else {
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++)
1385          putc (' ', tfp);
1386      }
1387      putc (' ', tfp); /* at least one space between key and text */
1388      
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);
1397      }
1398 @@ -297,25 +292,28 @@ static void save_text (png_info *info_pt
1399    }
1400  }
1401  
1402 -static void show_time (png_info *info_ptr)
1403 +static void show_time (png_struct *png_ptr, png_info *info_ptr)
1404  {
1405      static const char * const month[] = {
1406          "", "January", "February", "March", "April", "May", "June",
1407          "July", "August", "September", "October", "November", "December"
1408      };
1409  
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;
1415 +
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);
1424      } else
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);
1432    }
1433  }
1434  
1435 @@ -346,12 +344,12 @@ static void pngtopnm_error_handler (png_
1436  
1437  
1438  static void
1439 -dump_png_info(png_info *info_ptr) {
1440 +dump_png_info(png_struct *png_ptr, png_info *info_ptr) {
1441  
1442      const char *type_string;
1443      const char *filter_string;
1444  
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";
1449          break;
1450 @@ -373,90 +371,106 @@ dump_png_info(png_info *info_ptr) {
1451          break;
1452      }
1453  
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");
1458          break;
1459      default:
1460          asprintfN(&filter_string, "unknown filter type %d", 
1461 -                  info_ptr->filter_type);
1462 +                  png_get_filter_type(png_ptr, info_ptr));
1463      }
1464  
1465 +    {
1466 +    png_uint_32 width, height;
1467 +    int bit_depth;
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" : "");
1474 +    }
1475      pm_message("%s, %s, %s",
1476                 type_string,
1477 -               info_ptr->interlace_type ? 
1478 +               png_get_interlace_type(png_ptr, info_ptr) ? 
1479                 "Adam7 interlaced" : "not interlaced",
1480                 filter_string);
1481 +    {
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);
1491 +               bkgp->index,
1492 +               bkgp->gray,
1493 +               bkgp->red,
1494 +               bkgp->green,
1495 +               bkgp->blue);
1496 +    }
1497  
1498      strfree(filter_string);
1499  
1500 -    if (info_ptr->valid & PNG_INFO_tRNS)
1501 +    if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
1502 +        int num_trans;
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);
1506 -    else
1507 +                   num_trans);
1508 +    } else
1509          pm_message("tRNS chunk (transparency): not present");
1510  
1511 -    if (info_ptr->valid & PNG_INFO_gAMA)
1512 -        pm_message("gAMA chunk (image gamma): gamma = %4.2f", info_ptr->gamma);
1513 -    else
1514 +    if (png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA)) {
1515 +        double gamma;
1516 +        png_get_gAMA(png_ptr, info_ptr, &gamma);
1517 +        pm_message("gAMA chunk (image gamma): gamma = %4.2f", gamma);
1518 +    } else
1519          pm_message("gAMA chunk (image gamma): not present");
1520  
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");
1524      else
1525          pm_message("sBIT chunk: not present");
1526  
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");
1530      else
1531          pm_message("cHRM chunk: not present");
1532  
1533 -    if (info_ptr->valid & PNG_INFO_PLTE)
1534 -        pm_message("PLTE chunk: %d entries", info_ptr->num_palette);
1535 -    else
1536 +    if (png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE)) {
1537 +        png_colorp palette;
1538 +        int num_palette;
1539 +        png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
1540 +        pm_message("PLTE chunk: %d entries", num_palette);
1541 +    } else
1542          pm_message("PLTE chunk: not present");
1543  
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");
1547      else
1548          pm_message("bKGD chunk: not present");
1549  
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");
1553      else
1554          pm_message("hIST chunk: not present");
1555  
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");
1559      else
1560          pm_message("pHYs chunk: not present");
1561  
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");
1565      else
1566          pm_message("oFFs chunk: not present");
1567  
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");
1571      else
1572          pm_message("tIME chunk: not present");
1573  
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");
1577      else
1578          pm_message("pCAL chunk: not present");
1579  
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");
1583      else
1584          pm_message("sRGB chunk: not present");
1585 @@ -465,44 +479,50 @@ dump_png_info(png_info *info_ptr) {
1586  
1587  
1588  static unsigned int
1589 -computePngLineSize(png_info * const pngInfoP) {
1590 -
1591 -    unsigned int const bytesPerSample = pngInfoP->bit_depth == 16 ? 2 : 1;
1592 +computePngLineSize(png_struct * const pngP, png_info * const pngInfoP) {
1593  
1594 +    png_uint_32 width;
1595 +    int bit_depth, color_type;
1596 +    unsigned int bytesPerSample;
1597      unsigned int samplesPerPixel;
1598  
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;
1602 +
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;
1608      }
1609  
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);
1615         
1616 -    return pngInfoP->width * bytesPerSample * samplesPerPixel;
1617 +    return width * bytesPerSample * samplesPerPixel;
1618  }
1619  
1620  
1621  
1622  static void
1623 -allocPngRaster(png_info *   const pngInfoP,
1624 +allocPngRaster(png_struct * const pngP,
1625 +               png_info *   const pngInfoP,
1626                 png_byte *** const pngImageP) {
1627  
1628 -    unsigned int const lineSize = computePngLineSize(pngInfoP);
1629 +    unsigned int const lineSize = computePngLineSize(pngP, pngInfoP);
1630  
1631      png_byte ** pngImage;
1632 +    png_uint_32 height = png_get_image_height(pngP, pngInfoP);
1633      unsigned int row;
1634  
1635 -    MALLOCARRAY(pngImage, pngInfoP->height);
1636 +    MALLOCARRAY(pngImage, height);
1637  
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);
1642  
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
1649  
1650  static void
1651  freePngRaster(png_byte ** const pngRaster,
1652 +              png_struct* const pngP,
1653                png_info *  const pngInfoP) {
1654  
1655      unsigned int row;
1656  
1657 -    for (row = 0; row < pngInfoP->height; ++row)
1658 +    for (row = 0; row < png_get_image_height(pngP, pngInfoP); ++row)
1659          free(pngRaster[row]);
1660  
1661      free(pngRaster);
1662 @@ -529,6 +550,7 @@ freePngRaster(png_byte ** const pngRaste
1663  
1664  static bool
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  -----------------------------------------------------------------------------*/
1672      bool retval;
1673  
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);
1679  
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.
1684          */
1685      
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);
1690              break;
1691 @@ -603,9 +626,11 @@ setupGammaCorrection(png_struct * const
1692          *totalgammaP = -1.0;
1693      else {
1694          float imageGamma;
1695 -        if (info_ptr->valid & PNG_INFO_gAMA)
1696 -            imageGamma = info_ptr->gamma;
1697 -        else {
1698 +        if (png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA)) {
1699 +            double gamma;
1700 +            png_get_gAMA(png_ptr, info_ptr, &gamma);
1701 +            imageGamma = gamma;
1702 +       } else {
1703              if (verbose)
1704                  pm_message("PNG doesn't specify image gamma.  Assuming 1.0");
1705              imageGamma = 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 
1709              */
1710 -            info_ptr->valid &= ~PNG_INFO_sBIT;
1711 +            png_set_invalid(png_ptr, info_ptr, PNG_INFO_sBIT);
1712              if (verbose)
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
1716  
1717  
1718  static bool
1719 -paletteHasPartialTransparency(png_info * const info_ptr) {
1720 +paletteHasPartialTransparency(png_struct * const png_ptr, png_info * const info_ptr) {
1721  
1722      bool retval;
1723  
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)) {
1728              bool foundGray;
1729              unsigned int i;
1730 +            int num_trans;
1731 +            png_bytep trans_alpha;
1732 +            png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, NULL);
1733              
1734              for (i = 0, foundGray = FALSE;
1735 -                 i < info_ptr->num_trans && !foundGray;
1736 +                 i < num_trans && !foundGray;
1737                   ++i) {
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) {
1742                      foundGray = TRUE;
1743                  }
1744              }
1745 @@ -664,34 +692,44 @@ paletteHasPartialTransparency(png_info *
1746  
1747  
1748  static void
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) {
1754  
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);
1763 +
1764 +    if (color_type == PNG_COLOR_TYPE_RGB ||
1765 +        color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
1766 +        color_type == PNG_COLOR_TYPE_PALETTE) {
1767 +
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;
1773          } else
1774              *notUniformP = true;
1775      } else {
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;
1780      }
1781  }
1782  
1783  
1784  
1785  static void
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) {
1792  
1793 +    png_color_8p sig_bit;
1794 +    png_get_sBIT(pngP, pngInfoP, &sig_bit);
1795 +
1796      switch (alphaHandling) {
1797  
1798      case ALPHA_ONLY:
1799 @@ -699,26 +737,26 @@ getComponentSbit(png_info *          con
1800             the alpha Sbit
1801          */
1802          *notUniformP = false;
1803 -        *componentSbitP = pngInfoP->sig_bit.alpha;
1804 +        *componentSbitP = sig_bit->alpha;
1805          break;
1806      case ALPHA_NONE:
1807      case ALPHA_MIX:
1808          /* We aren't going to produce an alpha channel, so we care only
1809             about the uniformity of the foreground channels.
1810          */
1811 -        getComponentSbitFg(pngInfoP, componentSbitP, notUniformP);
1812 +        getComponentSbitFg(pngP, pngInfoP, componentSbitP, notUniformP);
1813          break;
1814      case ALPHA_IN: {
1815          /* We care about both the foreground and the alpha */
1816          bool fgNotUniform;
1817          png_byte fgSbit;
1818          
1819 -        getComponentSbitFg(pngInfoP, &fgSbit, &fgNotUniform);
1820 +        getComponentSbitFg(pngP, pngInfoP, &fgSbit, &fgNotUniform);
1821  
1822          if (fgNotUniform)
1823              *notUniformP = true;
1824          else {
1825 -            if (fgSbit == pngInfoP->sig_bit.alpha) {
1826 +            if (fgSbit == sig_bit->alpha) {
1827                  *notUniformP    = false;
1828                  *componentSbitP = fgSbit;
1829              } else
1830 @@ -731,7 +769,8 @@ getComponentSbit(png_info *          con
1831                   
1832  
1833  static void
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
1841                   shift);
1842      else {
1843          unsigned int i;
1844 -        
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);
1849 +        int num_palette;
1850 +        png_colorp palette;
1851 +        png_get_PLTE(pngP, pngInfoP, &palette, &num_palette);
1852 +
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);
1857          }
1858      }
1859  }
1860 @@ -782,12 +824,12 @@ computeMaxvalFromSbit(png_struct *
1861             Meaningless if they aren't all the same (i.e. 'notUniform')
1862          */
1863  
1864 -    getComponentSbit(pngInfoP, alphaHandling, &componentSigBit, &notUniform);
1865 +    getComponentSbit(pngP, pngInfoP, alphaHandling, &componentSigBit, &notUniform);
1866  
1867      if (notUniform) {
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;
1878      } else {
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;
1888          else {
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;
1894                  *succeededP = true;
1895  
1896 -                if (pngInfoP->color_type == PNG_COLOR_TYPE_PALETTE)
1897 -                    shiftPalette(pngInfoP, componentSigBit);
1898 -                else
1899 -                    png_set_shift(pngP, &pngInfoP->sig_bit);
1900 +                if (color_type == PNG_COLOR_TYPE_PALETTE)
1901 +                    shiftPalette(pngP, pngInfoP, componentSigBit);
1902 +                else {
1903 +                    png_color_8p sig_bit;
1904 +                   png_get_sBIT(pngP, pngInfoP, &sig_bit);
1905 +                    png_set_shift(pngP, sig_bit);
1906 +               }
1907              } else
1908                  *succeededP = false;
1909          }
1910 @@ -838,22 +884,23 @@ setupSignificantBits(png_struct *
1911  -----------------------------------------------------------------------------*/
1912      bool gotItFromSbit;
1913      
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);
1918      else
1919          gotItFromSbit = false;
1920  
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
1931                         is plenty
1932                      */
1933                      *maxvalP = 1;
1934 -                else if (paletteHasPartialTransparency(pngInfoP))
1935 +                else if (paletteHasPartialTransparency(pngP, pngInfoP))
1936                      /* Use same maxval as PNG transparency palette for
1937                         simplicity
1938                      */
1939 @@ -865,7 +912,7 @@ setupSignificantBits(png_struct *
1940                  /* Use same maxval as PNG palette for simplicity */
1941                  *maxvalP = 255;
1942          } else {
1943 -            *maxvalP = (1l << pngInfoP->bit_depth) - 1;
1944 +            *maxvalP = (1l << png_get_bit_depth(pngP, pngInfoP)) - 1;
1945          }
1946      }
1947  }
1948 @@ -873,22 +920,27 @@ setupSignificantBits(png_struct *
1949  
1950  
1951  static bool
1952 -imageHasColor(png_info * const info_ptr) {
1953 +imageHasColor(png_struct * const png_ptr, png_info * const info_ptr) {
1954  
1955      bool retval;
1956 +    int color_type = png_get_color_type(png_ptr, info_ptr);
1957  
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)
1962  
1963          retval = FALSE;
1964 -    else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
1965 +    else if (color_type == PNG_COLOR_TYPE_PALETTE) {
1966          bool foundColor;
1967          unsigned int i;
1968 +        int num_palette;
1969 +        png_colorp palette;
1970 +
1971 +        png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
1972              
1973          for (i = 0, foundColor = FALSE;
1974 -             i < info_ptr->num_palette && !foundColor;
1975 +             i < num_palette && !foundColor;
1976               ++i) {
1977 -            if (iscolor(info_ptr->palette[i]))
1978 +            if (iscolor(palette[i]))
1979                  foundColor = TRUE;
1980          }
1981          retval = foundColor;
1982 @@ -901,7 +953,8 @@ imageHasColor(png_info * const info_ptr)
1983  
1984  
1985  static void
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 *
1993      } else {            
1994          /* The output is a normal Netpbm image */
1995          bool const outputIsColor =
1996 -            imageHasColor(pngInfoP) || !isGrayscale(bgColor);
1997 +            imageHasColor(pngP, pngInfoP) || !isGrayscale(bgColor);
1998  
1999          if (alphaHandling == ALPHA_IN) {
2000              *formatP = PAM_FORMAT;
2001 @@ -942,7 +995,8 @@ determineOutputType(png_info *
2002  
2003  
2004  static void
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);
2014  
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.
2021          */
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);
2029              break;
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;
2035 +            int num_palette;
2036 +
2037 +            png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
2038 +            rawBgcolor = 
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
2044          break;
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;
2049              
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
2053  
2054  
2055  
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))
2058  
2059  
2060  
2061  static void
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
2069      unsigned int col;
2070  
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: {
2077              pngcolor fgColor;
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) ?
2082                     0 : maxval);
2083          }
2084          break;
2085 @@ -1040,18 +1102,26 @@ makeTupleRow(const struct pam *  const p
2086  
2087          case PNG_COLOR_TYPE_PALETTE: {
2088              png_uint_16 const index        = GET_PNG_VAL(pngPixelP);
2089 -            png_color   const paletteColor = pngInfoP->palette[index];
2090 -
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;
2096              pngcolor fgColor;
2097  
2098 +            png_get_PLTE(pngP, pngInfoP, &palette, &num_palette);
2099 +           paletteColor = palette[index];
2100 +
2101              fgColor.r = paletteColor.red;
2102              fgColor.g = paletteColor.green;
2103              fgColor.b = paletteColor.blue;
2104  
2105 +           if (transValid)
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);
2111 +                     transValid &&
2112 +                     index < num_trans ?
2113 +                     trans_alpha[index] : maxval);
2114          }
2115          break;
2116                  
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) ?
2123                       0 : maxval);
2124          }
2125          break;
2126 @@ -1081,7 +1151,7 @@ makeTupleRow(const struct pam *  const p
2127          break;
2128  
2129          default:
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));
2132          }
2133      }
2134  }
2135 @@ -1115,6 +1185,7 @@ reportOutputFormat(const struct pam * co
2136  
2137  static void
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
2144  
2145      tuplerow = pnm_allocpamrow(pamP);
2146  
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);
2152  
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);
2157  
2158 -    allocPngRaster(info_ptr, &png_image);
2159 +    allocPngRaster(png_ptr, info_ptr, &png_image);
2160  
2161 -    if (info_ptr->bit_depth < 8)
2162 +    if (png_get_bit_depth(png_ptr, info_ptr) < 8)
2163          png_set_packing (png_ptr);
2164  
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);
2169  
2170 -    getBackgroundColor(info_ptr, cmdline.background, totalgamma, maxval,
2171 +    getBackgroundColor(png_ptr, info_ptr, cmdline.background, totalgamma, maxval,
2172                         &bgColor);
2173  
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
2177             end of the stream.
2178          */
2179 -        dump_png_info(info_ptr);
2180 +        dump_png_info(png_ptr, info_ptr);
2181  
2182      if (cmdline.time)
2183 -        show_time(info_ptr);
2184 +        show_time(png_ptr, info_ptr);
2185      if (tfp)
2186 -        save_text(info_ptr, tfp);
2187 +        save_text(png_ptr, info_ptr, tfp);
2188 +
2189 +    if (png_get_valid(png_ptr, info_ptr, PNG_INFO_pHYs)) {
2190 +        float r;
2191 +        png_uint_32 x_pixels_per_unit, y_pixels_per_unit;
2192  
2193 -    if (info_ptr->valid & PNG_INFO_pHYs) {
2194 -        float const r =
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;
2198          if (r != 1.0) {
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);
2203      pam.file        = stdout;
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;
2210  
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);
2214  
2215 -    writeNetpbm(&pam, info_ptr, png_image, bgColor, cmdline.alpha, totalgamma);
2216 +    writeNetpbm(&pam, png_ptr, info_ptr, png_image, bgColor, cmdline.alpha, totalgamma);
2217  
2218      fflush(stdout);
2219  
2220 -    freePngRaster(png_image, info_ptr);
2221 +    freePngRaster(png_image, png_ptr, info_ptr);
2222  
2223      png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
2224  }
This page took 0.24881 seconds and 2 git commands to generate.