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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
diff -Naur gimp-2.6.11/plug-ins/common/file-mng.c gimp-2.6.11-libpng//plug-ins/common/file-mng.c
--- gimp-2.6.11/plug-ins/common/file-mng.c 2010-07-03 00:51:56.000000000 +0200
+++ gimp-2.6.11-libpng//plug-ins/common/file-mng.c 2011-02-16 11:59:21.238641008 +0100
@@ -799,6 +799,13 @@
png_infop png_info_ptr;
FILE *infile, *outfile;
int num_passes;
+ int color_type;
+ png_colorp palette;
+ int num_palette;
+ int bit_depth;
+ png_bytep trans_alpha;
+ int num_trans;
+ png_color_16p trans_color;
int tile_height;
guchar **layer_pixels, *layer_pixel;
int pass, j, k, begin, end, num;
@@ -969,7 +976,7 @@
goto err3;
}
- if (setjmp (png_ptr->jmpbuf) != 0)
+ if (setjmp (png_jmpbuf(png_ptr)) != 0)
{
g_warning ("HRM saving PNG in mng_save_image()");
png_destroy_write_struct (&png_ptr, &png_info_ptr);
@@ -981,34 +988,27 @@
png_init_io (png_ptr, outfile);
png_set_compression_level (png_ptr, mng_data.compression_level);
- png_info_ptr->width = layer_cols;
- png_info_ptr->height = layer_rows;
- png_info_ptr->interlace_type = (mng_data.interlaced == 0 ? 0 : 1);
- png_info_ptr->bit_depth = 8;
-
switch (layer_drawable_type)
{
case GIMP_RGB_IMAGE:
- png_info_ptr->color_type = PNG_COLOR_TYPE_RGB;
+ color_type = PNG_COLOR_TYPE_RGB;
break;
case GIMP_RGBA_IMAGE:
- png_info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+ color_type = PNG_COLOR_TYPE_RGB_ALPHA;
break;
case GIMP_GRAY_IMAGE:
- png_info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
+ color_type = PNG_COLOR_TYPE_GRAY;
break;
case GIMP_GRAYA_IMAGE:
- png_info_ptr->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
+ color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
break;
case GIMP_INDEXED_IMAGE:
- png_info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
- png_info_ptr->valid |= PNG_INFO_PLTE;
- png_info_ptr->palette =
- (png_colorp) gimp_image_get_colormap (image_id, &num_colors);
- png_info_ptr->num_palette = num_colors;
+ color_type = PNG_COLOR_TYPE_PALETTE;
+
+ png_set_PLTE(png_ptr, png_info_ptr, (png_colorp) gimp_image_get_colormap (image_id, &num_colors), num_colors);
break;
case GIMP_INDEXEDA_IMAGE:
- png_info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
+ color_type = PNG_COLOR_TYPE_PALETTE;
layer_has_unique_palette =
respin_cmap (png_ptr, png_info_ptr, layer_remap,
image_id, layer_drawable);
@@ -1021,15 +1021,17 @@
goto err3;
}
- if ((png_info_ptr->valid & PNG_INFO_PLTE) == PNG_INFO_PLTE)
+ bit_depth = 8;
+ if (png_get_PLTE(png_ptr, png_info_ptr, &palette, &num_palette) != 0)
{
- if (png_info_ptr->num_palette <= 2)
- png_info_ptr->bit_depth = 1;
- else if (png_info_ptr->num_palette <= 4)
- png_info_ptr->bit_depth = 2;
- else if (png_info_ptr->num_palette <= 16)
- png_info_ptr->bit_depth = 4;
+ if (num_palette <= 2)
+ bit_depth = 1;
+ else if (num_palette <= 4)
+ bit_depth = 2;
+ else if (num_palette <= 16)
+ bit_depth = 4;
}
+ png_set_IHDR(png_ptr, png_info_ptr, layer_cols, layer_rows, bit_depth, color_type, (mng_data.interlaced == 0 ? PNG_INTERLACE_NONE : PNG_INTERLACE_ADAM7), PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_write_info (png_ptr, png_info_ptr);
@@ -1038,8 +1040,8 @@
else
num_passes = 1;
- if ((png_info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) &&
- (png_info_ptr->bit_depth < 8))
+ if ((png_get_color_type(png_ptr, png_info_ptr) == PNG_COLOR_TYPE_PALETTE) &&
+ (png_get_bit_depth(png_ptr, png_info_ptr) < 8))
png_set_packing (png_ptr);
tile_height = gimp_tile_height ();
@@ -1065,7 +1067,7 @@
gimp_pixel_rgn_get_rect (&layer_pixel_rgn, layer_pixel, 0,
begin, layer_cols, num);
- if ((png_info_ptr->valid & PNG_INFO_tRNS) == PNG_INFO_tRNS)
+ if (png_get_tRNS(png_ptr, png_info_ptr, &trans_alpha, &num_trans, &trans_color) != 0)
{
for (j = 0; j < num; j++)
{
@@ -1077,7 +1079,7 @@
}
}
else
- if (((png_info_ptr->valid & PNG_INFO_PLTE) == PNG_INFO_PLTE)
+ if ((png_get_PLTE(png_ptr, png_info_ptr, &palette, &num_palette) != 0)
&& (layer_bpp == 2))
{
for (j = 0; j < num; j++)
diff -Naur gimp-2.6.11/plug-ins/common/file-png.c gimp-2.6.11-libpng//plug-ins/common/file-png.c
--- gimp-2.6.11/plug-ins/common/file-png.c 2010-07-13 22:22:27.000000000 +0200
+++ gimp-2.6.11-libpng//plug-ins/common/file-png.c 2011-02-16 11:59:13.465685257 +0100
@@ -653,7 +653,11 @@
error_data->drawable->width, num);
}
+#if (PNG_LIBPNG_VER < 10500)
longjmp (png_ptr->jmpbuf, 1);
+#else
+ png_longjmp (png_ptr, 1);
+#endif
}
/*
@@ -697,7 +701,7 @@
pp = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
info = png_create_info_struct (pp);
- if (setjmp (pp->jmpbuf))
+ if (setjmp (png_jmpbuf(pp)))
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Error while reading '%s'. File corrupted?"),
@@ -738,17 +742,19 @@
* Latest attempt, this should be my best yet :)
*/
- if (info->bit_depth == 16)
+ if (png_get_bit_depth(pp, info) == 16)
{
png_set_strip_16 (pp);
}
- if (info->color_type == PNG_COLOR_TYPE_GRAY && info->bit_depth < 8)
+ if (png_get_color_type(pp, info) == PNG_COLOR_TYPE_GRAY &&
+ png_get_bit_depth(pp, info) < 8)
{
png_set_expand (pp);
}
- if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8)
+ if (png_get_color_type(pp, info) == PNG_COLOR_TYPE_PALETTE &&
+ png_get_bit_depth(pp, info) < 8)
{
png_set_packing (pp);
}
@@ -757,8 +763,8 @@
* Expand G+tRNS to GA, RGB+tRNS to RGBA
*/
- if (info->color_type != PNG_COLOR_TYPE_PALETTE &&
- (info->valid & PNG_INFO_tRNS))
+ if (png_get_color_type(pp, info) != PNG_COLOR_TYPE_PALETTE &&
+ png_get_valid(pp, info, PNG_INFO_tRNS) != 0)
{
png_set_expand (pp);
}
@@ -775,7 +781,7 @@
*/
if (png_get_valid (pp, info, PNG_INFO_tRNS) &&
- info->color_type == PNG_COLOR_TYPE_PALETTE)
+ png_get_color_type(pp, info) == PNG_COLOR_TYPE_PALETTE)
{
png_get_tRNS (pp, info, &alpha_ptr, &num, NULL);
/* Copy the existing alpha values from the tRNS chunk */
@@ -797,7 +803,7 @@
png_read_update_info (pp, info);
- switch (info->color_type)
+ switch (png_get_color_type(pp, info))
{
case PNG_COLOR_TYPE_RGB: /* RGB */
bpp = 3;
@@ -836,7 +842,9 @@
return -1;
}
- image = gimp_image_new (info->width, info->height, image_type);
+ image = gimp_image_new (png_get_image_width(pp, info),
+ png_get_image_height(pp, info),
+ image_type);
if (image == -1)
{
g_set_error (error, 0, 0,
@@ -849,7 +857,9 @@
* Create the "background" layer to hold the image...
*/
- layer = gimp_layer_new (image, _("Background"), info->width, info->height,
+ layer = gimp_layer_new (image, _("Background"),
+ png_get_image_width(pp, info),
+ png_get_image_height(pp, info),
layer_type, 100, GIMP_NORMAL_MODE);
gimp_image_add_layer (image, layer, 0);
@@ -883,7 +893,8 @@
gimp_layer_set_offsets (layer, offset_x, offset_y);
- if ((abs (offset_x) > info->width) || (abs (offset_y) > info->height))
+ if ((abs (offset_x) > png_get_image_width(pp, info)) ||
+ (abs (offset_y) > png_get_image_height(pp, info)))
{
if (interactive)
g_message (_("The PNG file specifies an offset that caused "
@@ -938,23 +949,27 @@
empty = 0; /* by default assume no full transparent palette entries */
- if (info->color_type & PNG_COLOR_MASK_PALETTE)
+ if (png_get_color_type(pp, info) & PNG_COLOR_MASK_PALETTE)
{
+ png_colorp palette;
+ int num_palette;
+ png_get_PLTE(pp, info, &palette, &num_palette);
+
if (png_get_valid (pp, info, PNG_INFO_tRNS))
{
for (empty = 0; empty < 256 && alpha[empty] == 0; ++empty)
/* Calculates number of fully transparent "empty" entries */;
/* keep at least one entry */
- empty = MIN (empty, info->num_palette - 1);
+ empty = MIN (empty, num_palette - 1);
- gimp_image_set_colormap (image, (guchar *) (info->palette + empty),
- info->num_palette - empty);
+ gimp_image_set_colormap (image, (guchar *) (palette + empty),
+ num_palette - empty);
}
else
{
- gimp_image_set_colormap (image, (guchar *) info->palette,
- info->num_palette);
+ gimp_image_set_colormap (image, (guchar *) palette,
+ num_palette);
}
}
@@ -972,18 +987,20 @@
*/
tile_height = gimp_tile_height ();
- pixel = g_new0 (guchar, tile_height * info->width * bpp);
+ pixel = g_new0 (guchar, tile_height * png_get_image_width(pp, info) * bpp);
pixels = g_new (guchar *, tile_height);
for (i = 0; i < tile_height; i++)
- pixels[i] = pixel + info->width * info->channels * i;
+ pixels[i] = pixel + (png_get_image_width(pp, info) *
+ png_get_channels(pp, info) *
+ i);
/* Install our own error handler to handle incomplete PNG files better */
error_data.drawable = drawable;
error_data.pixel = pixel;
error_data.tile_height = tile_height;
- error_data.width = info->width;
- error_data.height = info->height;
+ error_data.width = png_get_image_width(pp, info);
+ error_data.height = png_get_image_height(pp, info);
error_data.bpp = bpp;
error_data.pixel_rgn = &pixel_rgn;
@@ -996,10 +1013,11 @@
*/
for (begin = 0, end = tile_height;
- begin < info->height; begin += tile_height, end += tile_height)
+ begin < png_get_image_height(pp, info);
+ begin += tile_height, end += tile_height)
{
- if (end > info->height)
- end = info->height;
+ if (end > png_get_image_height(pp, info))
+ end = png_get_image_height(pp, info);
num = end - begin;
@@ -1016,10 +1034,11 @@
gimp_pixel_rgn_set_rect (&pixel_rgn, pixel, 0, begin,
drawable->width, num);
- memset (pixel, 0, tile_height * info->width * bpp);
+ memset (pixel, 0, tile_height * png_get_image_width(pp, info) * bpp);
gimp_progress_update (((gdouble) pass +
- (gdouble) end / (gdouble) info->height) /
+ (gdouble) end /
+ (gdouble) png_get_image_height(pp, info)) /
(gdouble) num_passes);
}
}
@@ -1072,7 +1091,8 @@
{
png_uint_32 proflen;
- png_charp profname, profile;
+ png_charp profname;
+ png_bytep profile;
int profcomp;
if (png_get_iCCP (pp, info, &profname, &profcomp, &profile, &proflen))
@@ -1200,6 +1220,8 @@
guchar red, green, blue; /* Used for palette background */
time_t cutime; /* Time since epoch */
struct tm *gmt; /* GMT broken down */
+ int color_type; /* type of colors in image */
+ int bit_depth; /* width of colors in bit */
guchar remap[256]; /* Re-mapping for the palette */
@@ -1208,7 +1230,9 @@
if (pngvals.comment)
{
GimpParasite *parasite;
+#ifndef PNG_iTXt_SUPPORTED
gsize text_length = 0;
+#endif
parasite = gimp_image_parasite_find (orig_image_ID, "gimp-comment");
if (parasite)
@@ -1249,7 +1273,7 @@
pp = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
info = png_create_info_struct (pp);
- if (setjmp (pp->jmpbuf))
+ if (setjmp (png_jmpbuf(pp)))
{
g_set_error (error, 0, 0,
_("Error while saving '%s'. Could not save image."),
@@ -1291,11 +1315,6 @@
png_set_compression_level (pp, pngvals.compression_level);
- info->width = drawable->width;
- info->height = drawable->height;
- info->bit_depth = 8;
- info->interlace_type = pngvals.interlaced;
-
/*
* Initialise remap[]
*/
@@ -1309,37 +1328,36 @@
switch (type)
{
case GIMP_RGB_IMAGE:
- info->color_type = PNG_COLOR_TYPE_RGB;
+ color_type = PNG_COLOR_TYPE_RGB;
bpp = 3;
break;
case GIMP_RGBA_IMAGE:
- info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+ color_type = PNG_COLOR_TYPE_RGB_ALPHA;
bpp = 4;
break;
case GIMP_GRAY_IMAGE:
- info->color_type = PNG_COLOR_TYPE_GRAY;
+ color_type = PNG_COLOR_TYPE_GRAY;
bpp = 1;
break;
case GIMP_GRAYA_IMAGE:
- info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
+ color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
bpp = 2;
break;
case GIMP_INDEXED_IMAGE:
bpp = 1;
- info->color_type = PNG_COLOR_TYPE_PALETTE;
- info->valid |= PNG_INFO_PLTE;
- info->palette =
- (png_colorp) gimp_image_get_colormap (image_ID, &num_colors);
- info->num_palette = num_colors;
+ color_type = PNG_COLOR_TYPE_PALETTE;
+ png_set_PLTE(pp, info,
+ (png_colorp) gimp_image_get_colormap (image_ID, &num_colors),
+ num_colors);
break;
case GIMP_INDEXEDA_IMAGE:
bpp = 2;
- info->color_type = PNG_COLOR_TYPE_PALETTE;
+ color_type = PNG_COLOR_TYPE_PALETTE;
/* fix up transparency */
respin_cmap (pp, info, remap, image_ID, drawable);
break;
@@ -1353,17 +1371,28 @@
* Fix bit depths for (possibly) smaller colormap images
*/
- if (info->valid & PNG_INFO_PLTE)
+ bit_depth = 8;
+
+ if (png_get_valid(pp, info, PNG_INFO_PLTE))
{
- if (info->num_palette <= 2)
- info->bit_depth = 1;
- else if (info->num_palette <= 4)
- info->bit_depth = 2;
- else if (info->num_palette <= 16)
- info->bit_depth = 4;
+ png_colorp palette;
+ int num_palette;
+ png_get_PLTE(pp, info, &palette, &num_palette);
+
+ if (num_palette <= 2)
+ bit_depth = 1;
+ else if (num_palette <= 4)
+ bit_depth = 2;
+ else if (num_palette <= 16)
+ bit_depth = 4;
/* otherwise the default is fine */
}
+ png_set_IHDR(pp, info,
+ drawable->width, drawable->height, bit_depth, color_type,
+ pngvals.interlaced ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+
/* All this stuff is optional extras, if the user is aiming for smallest
possible file size she can turn them all off */
@@ -1477,7 +1506,8 @@
* Convert unpacked pixels to packed if necessary
*/
- if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8)
+ if (png_get_color_type(pp, info) ==
+ PNG_COLOR_TYPE_PALETTE && png_get_bit_depth(pp, info) < 8)
png_set_packing (pp);
/*
@@ -1529,7 +1559,7 @@
/* If we're dealing with a paletted image with
* transparency set, write out the remapped palette */
- if (info->valid & PNG_INFO_tRNS)
+ if (png_get_valid(pp, info, PNG_INFO_tRNS))
{
guchar inverse_remap[256];
@@ -1549,7 +1579,7 @@
}
/* Otherwise if we have a paletted image and transparency
* couldn't be set, we ignore the alpha channel */
- else if (info->valid & PNG_INFO_PLTE && bpp == 2)
+ else if (png_get_valid(pp, info, PNG_INFO_PLTE) && bpp == 2)
{
for (i = 0; i < num; ++i)
{
@@ -1564,7 +1594,7 @@
png_write_rows (pp, pixels, num);
gimp_progress_update (((double) pass + (double) end /
- (double) info->height) /
+ (double) png_get_image_height(pp, info)) /
(double) num_passes);
}
}
|