summaryrefslogtreecommitdiff
path: root/graphics/netpbm/patches/patch-ac
blob: 18aa0f883f0a94c8b00c73d205511adeb74084c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
$NetBSD: patch-ac,v 1.20 2011/01/14 21:51:59 tron Exp $

Fix build with png-1.5.

--- converter/other/pnmtopng.c.orig	2010-07-10 02:38:01.000000000 +0100
+++ converter/other/pnmtopng.c	2011-01-14 21:49:17.000000000 +0000
@@ -61,7 +61,8 @@
 #include <assert.h>
 #include <string.h> /* strcat() */
 #include <limits.h>
-#include <png.h>    /* includes zlib.h and setjmp.h */
+#include <png.h>    /* includes setjmp.h */
+#include <zlib.h>
 #include "pnm.h"
 #include "pngtxt.h"
 #include "shhopt.h"
@@ -69,11 +70,6 @@
 #include "nstring.h"
 #include "version.h"
 
-#if PNG_LIBPNG_VER >= 10400
-#error Your PNG library (<png.h>) is incompatible with this Netpbm source code.
-#error You need either an older PNG library (older than 1.4)
-#error newer Netpbm source code (at least 10.48)
-#endif
 
 
 struct zlibCompression {
@@ -2079,6 +2075,7 @@
             gray *               const alpha_mask,
             colorhash_table      const cht,
             coloralphahash_table const caht,
+            png_struct *         const png_ptr,
             png_info *           const info_ptr,
             xelval               const png_maxval,
             unsigned int         const depth) {
@@ -2091,20 +2088,20 @@
         xel p_png;
         xel const p = xelrow[col];
         PPM_DEPTH(p_png, p, maxval, png_maxval);
-        if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
-            info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
+        if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY ||
+            png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY_ALPHA) {
             if (depth == 16)
                 *pp++ = PNM_GET1(p_png) >> 8;
             *pp++ = PNM_GET1(p_png) & 0xff;
-        } else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
+        } else if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
             unsigned int paletteIndex;
             if (alpha)
                 paletteIndex = lookupColorAlpha(caht, &p, &alpha_mask[col]);
             else
                 paletteIndex = ppm_lookupcolor(cht, &p);
             *pp++ = paletteIndex;
-        } else if (info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
-                   info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
+        } else if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB ||
+                   png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA) {
             if (depth == 16)
                 *pp++ = PPM_GETR(p_png) >> 8;
             *pp++ = PPM_GETR(p_png) & 0xff;
@@ -2117,7 +2114,7 @@
         } else
             pm_error("INTERNAL ERROR: undefined color_type");
                 
-        if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) {
+        if (png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_ALPHA) {
             int const png_alphaval = (int)
                 alpha_mask[col] * (float) png_maxval / maxval + 0.5;
             if (depth == 16)
@@ -2174,7 +2171,7 @@
             
             makePngLine(line, xelrow, cols, maxval,
                         alpha, alpha ? alpha_mask[row] : NULL,
-                        cht, caht, info_ptr, png_maxval, depth);
+                        cht, caht, png_ptr, info_ptr, png_maxval, depth);
 
             png_write_row(png_ptr, line);
         }
@@ -2186,12 +2183,12 @@
 
 static void
 doGamaChunk(struct cmdlineInfo const cmdline,
+            png_struct *       const png_ptr,
             png_info *         const info_ptr) {
             
     if (cmdline.gammaSpec) {
         /* gAMA chunk */
-        info_ptr->valid |= PNG_INFO_gAMA;
-        info_ptr->gamma = cmdline.gamma;
+        png_set_gAMA(png_ptr, info_ptr, cmdline.gamma);
     }
 }
 
@@ -2199,20 +2196,15 @@
 
 static void
 doChrmChunk(struct cmdlineInfo const cmdline,
+            png_struct *       const png_ptr,
             png_info *         const info_ptr) {
 
     if (cmdline.rgbSpec) {
         /* cHRM chunk */
-        info_ptr->valid |= PNG_INFO_cHRM;
-
-        info_ptr->x_white = cmdline.rgb.wx;
-        info_ptr->y_white = cmdline.rgb.wy;
-        info_ptr->x_red   = cmdline.rgb.rx;
-        info_ptr->y_red   = cmdline.rgb.ry;
-        info_ptr->x_green = cmdline.rgb.gx;
-        info_ptr->y_green = cmdline.rgb.gy;
-        info_ptr->x_blue  = cmdline.rgb.bx;
-        info_ptr->y_blue  = cmdline.rgb.by;
+	
+        png_set_cHRM (png_ptr, info_ptr, cmdline.rgb.wx, cmdline.rgb.wy,
+                      cmdline.rgb.rx, cmdline.rgb.ry, cmdline.rgb.gx,
+                      cmdline.rgb.gy, cmdline.rgb.bx, cmdline.rgb.by);
     }
 }
 
@@ -2220,15 +2212,12 @@
 
 static void
 doPhysChunk(struct cmdlineInfo const cmdline,
+            png_struct *       const png_ptr,
             png_info *         const info_ptr) {
 
     if (cmdline.sizeSpec) {
         /* pHYS chunk */
-        info_ptr->valid |= PNG_INFO_pHYs;
-
-        info_ptr->x_pixels_per_unit = cmdline.size.x;
-        info_ptr->y_pixels_per_unit = cmdline.size.y;
-        info_ptr->phys_unit_type    = cmdline.size.unit;
+        png_set_pHYs(png_ptr, info_ptr, cmdline.size.x, cmdline.size.y, cmdline.size.unit);
     }
 }
 
@@ -2237,26 +2226,28 @@
 
 static void
 doTimeChunk(struct cmdlineInfo const cmdline,
+            png_struct *       const png_ptr,
             png_info *         const info_ptr) {
 
     if (cmdline.modtimeSpec) {
         /* tIME chunk */
-        info_ptr->valid |= PNG_INFO_tIME;
-
-        png_convert_from_time_t(&info_ptr->mod_time, cmdline.modtime);
+        png_timep ptime;
+        png_convert_from_time_t(ptime, cmdline.modtime);
+        png_set_tIME(png_ptr, info_ptr, ptime);
     }
 }
 
 
 
 static void
-doSbitChunk(png_info * const pngInfoP,
+doSbitChunk(png_struct * const pngP,
+            png_info * const pngInfoP,
             xelval     const pngMaxval,
             xelval     const maxval,
             bool       const alpha,
             xelval     const alphaMaxval) {
 
-    if (pngInfoP->color_type != PNG_COLOR_TYPE_PALETTE &&
+    if (png_get_color_type(pngP, pngInfoP) != PNG_COLOR_TYPE_PALETTE &&
         (pngMaxval > maxval || (alpha && pngMaxval > alphaMaxval))) {
 
         /* We're writing in a bit depth that doesn't match the maxval
@@ -2275,26 +2266,28 @@
            sBIT chunk.
         */
 
-        pngInfoP->valid |= PNG_INFO_sBIT;
-
         {
             int const sbitval = pm_maxvaltobits(MIN(maxval, pngMaxval));
+            png_color_8 sbit;
 
-            if (pngInfoP->color_type & PNG_COLOR_MASK_COLOR) {
-                pngInfoP->sig_bit.red   = sbitval;
-                pngInfoP->sig_bit.green = sbitval;
-                pngInfoP->sig_bit.blue  = sbitval;
+            (void)memset(&sbit, 0, sizeof(sbit));
+            if (png_get_color_type(pngP, pngInfoP) & PNG_COLOR_MASK_COLOR) {
+                sbit.red   = sbitval;
+                sbit.green = sbitval;
+                sbit.blue  = sbitval;
             } else
-                pngInfoP->sig_bit.gray = sbitval;
+                sbit.gray = sbitval;
             
             if (verbose)
                 pm_message("Writing sBIT chunk with bits = %d", sbitval);
-        }
-        if (pngInfoP->color_type & PNG_COLOR_MASK_ALPHA) {
-            pngInfoP->sig_bit.alpha =
-                pm_maxvaltobits(MIN(alphaMaxval, pngMaxval));
-            if (verbose)
-                pm_message("  alpha bits = %d", pngInfoP->sig_bit.alpha);
+
+            if (png_get_color_type(pngP, pngInfoP) & PNG_COLOR_MASK_ALPHA) {
+                sbit.alpha =
+                    pm_maxvaltobits(MIN(alphaMaxval, pngMaxval));
+                if (verbose)
+                    pm_message("  alpha bits = %d", sbit.alpha);
+            }
+            png_set_sBIT(pngP, pngInfoP, &sbit);
         }
     }
 }
@@ -2391,6 +2384,8 @@
   xelval maxmaxval;
   gray ** alpha_mask;
 
+  int color_type;
+
   /* these guys are initialized to quiet compiler warnings: */
   maxmaxval = 255;
   alpha_mask = NULL;
@@ -2576,43 +2571,42 @@
     pm_error ("setjmp returns error condition (2)");
   }
 
-  png_init_io (png_ptr, stdout);
-  info_ptr->width = cols;
-  info_ptr->height = rows;
-  info_ptr->bit_depth = depth;
-
   if (colorMapped)
-    info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
-  else if (pnm_type == PPM_TYPE)
-    info_ptr->color_type = PNG_COLOR_TYPE_RGB;
-  else
-    info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
+    color_type = PNG_COLOR_TYPE_PALETTE;
+  else if (pnm_type == PPM_TYPE) {
+    if (alpha)
+      color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+    else
+      color_type = PNG_COLOR_TYPE_RGB;
+  } else {
+    if (alpha)
+      color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
+    else
+      color_type = PNG_COLOR_TYPE_GRAY;
+  }
 
-  if (alpha && info_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
-    info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
+  png_set_IHDR(png_ptr, info_ptr, cols, rows, depth, PNG_COLOR_TYPE_PALETTE, 0, 0, 0);
+  png_init_io (png_ptr, stdout);
 
-  info_ptr->interlace_type = cmdline.interlace;
+  if (cmdline.interlace)
+    png_set_interlace_handling(png_ptr);
 
-  doGamaChunk(cmdline, info_ptr);
+  doGamaChunk(cmdline, png_ptr, info_ptr);
 
-  doChrmChunk(cmdline, info_ptr);
+  doChrmChunk(cmdline, png_ptr, info_ptr);
 
-  doPhysChunk(cmdline, info_ptr);
+  doPhysChunk(cmdline, png_ptr, info_ptr);
 
-  if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
+  if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
 
     /* creating PNG palette  (PLTE and tRNS chunks) */
 
     createPngPalette(palette_pnm, palette_size, maxval,
                      trans_pnm, trans_size, alpha_maxval, 
                      palette, trans);
-    info_ptr->valid |= PNG_INFO_PLTE;
-    info_ptr->palette = palette;
-    info_ptr->num_palette = palette_size;
+    png_set_PLTE(png_ptr, info_ptr, palette, palette_size);
     if (trans_size > 0) {
-        info_ptr->valid |= PNG_INFO_tRNS;
-        info_ptr->trans = trans;
-        info_ptr->num_trans = trans_size;   /* omit opaque values */
+        png_set_tRNS(png_ptr, info_ptr, trans, trans_size, NULL);
     }
     /* creating hIST chunk */
     if (cmdline.hist) {
@@ -2638,18 +2632,17 @@
 
         ppm_freecolorhash(cht);
 
-        info_ptr->valid |= PNG_INFO_hIST;
-        info_ptr->hist = histogram;
+        png_set_hIST(png_ptr, info_ptr, histogram);
         if (verbose)
             pm_message("histogram created");
     }
   } else { /* color_type != PNG_COLOR_TYPE_PALETTE */
-    if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
-        info_ptr->color_type == PNG_COLOR_TYPE_RGB) {
+    if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY ||
+        png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB) {
         if (transparent > 0) {
-            info_ptr->valid |= PNG_INFO_tRNS;
-            info_ptr->trans_values = 
-                xelToPngColor_16(transcolor, maxval, png_maxval);
+            png_color_16 trans_color = xelToPngColor_16(transcolor, maxval, png_maxval);
+            png_set_tRNS(png_ptr, info_ptr, NULL, 0, &trans_color);
+                
         }
     } else {
         /* This is PNG_COLOR_MASK_ALPHA.  Transparency will be handled
@@ -2657,43 +2650,43 @@
         */
     }
     if (verbose) {
-        if (info_ptr->valid && PNG_INFO_tRNS) 
+        if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
+            png_color_16p trans_color;
+
+            png_get_tRNS(png_ptr, info_ptr, NULL, NULL, &trans_color);
             pm_message("Transparent color {gray, red, green, blue} = "
                        "{%d, %d, %d, %d}",
-                       info_ptr->trans_values.gray,
-                       info_ptr->trans_values.red,
-                       info_ptr->trans_values.green,
-                       info_ptr->trans_values.blue);
-        else
+                       trans_color->gray,
+                       trans_color->red,
+                       trans_color->green,
+                       trans_color->blue);
+        } else
             pm_message("No transparent color");
     }
   }
 
   /* bKGD chunk */
   if (cmdline.background) {
-      info_ptr->valid |= PNG_INFO_bKGD;
-      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
-          info_ptr->background.index = background_index;
-      } else {
-          info_ptr->background = 
-              xelToPngColor_16(backcolor, maxval, png_maxval);
+      if (png_get_color_type(png_ptr, info_ptr) != PNG_COLOR_TYPE_PALETTE) {
+          png_color_16 background = xelToPngColor_16(backcolor, maxval, png_maxval);
+          png_set_bKGD(png_ptr, info_ptr, &background);
           if (verbose)
               pm_message("Writing bKGD chunk with background color "
                          " {gray, red, green, blue} = {%d, %d, %d, %d}",
-                         info_ptr->background.gray, 
-                         info_ptr->background.red, 
-                         info_ptr->background.green, 
-                         info_ptr->background.blue ); 
+                         background.gray, 
+                         background.red, 
+                         background.green, 
+                         background.blue ); 
       }
   }
 
-  doSbitChunk(info_ptr, png_maxval, maxval, alpha, alpha_maxval);
+  doSbitChunk(png_ptr, info_ptr, png_maxval, maxval, alpha, alpha_maxval);
 
   /* tEXT and zTXT chunks */
   if (cmdline.text || cmdline.ztxt)
-      pnmpng_read_text(info_ptr, tfp, !!cmdline.ztxt, cmdline.verbose);
+      pnmpng_read_text(png_ptr, info_ptr, tfp, !!cmdline.ztxt, cmdline.verbose);
 
-  doTimeChunk(cmdline, info_ptr);
+  doTimeChunk(cmdline, png_ptr, info_ptr);
 
   if (cmdline.filterSet != 0)
       png_set_filter(png_ptr, 0, cmdline.filterSet);
@@ -2703,6 +2696,7 @@
   /* write the png-info struct */
   png_write_info(png_ptr, info_ptr);
 
+#if 0
   if (cmdline.text || cmdline.ztxt)
       /* prevent from being written twice with png_write_end */
       info_ptr->num_text = 0;
@@ -2710,6 +2704,7 @@
   if (cmdline.modtime)
       /* prevent from being written twice with png_write_end */
       info_ptr->valid &= ~PNG_INFO_tIME;
+#endif
 
   /* let libpng take care of, e.g., bit-depth conversions */
   png_set_packing (png_ptr);