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