]>
Commit | Line | Data |
---|---|---|
cbd6e183 JB |
1 | diff -Naur cinepaint1/plug-ins/png/png.c cinepaint/plug-ins/png/png.c |
2 | --- cinepaint1/plug-ins/png/png.c 2006-11-24 21:52:55.000000000 +0100 | |
3 | +++ cinepaint/plug-ins/png/png.c 2012-02-04 01:51:10.141016081 +0100 | |
4 | @@ -390,7 +390,16 @@ | |
5 | gchar *progress; /* Title for progress display... */ | |
6 | guchar alpha[256], /* Index -> Alpha */ | |
7 | *alpha_ptr; /* Temporary pointer */ | |
8 | - | |
9 | + png_byte color_type; | |
10 | + png_byte bit_depth; | |
11 | + png_colorp palette; | |
12 | + int num_palette; | |
13 | + png_charpp iccp_name; | |
14 | + int compression_type; | |
15 | + png_bytepp iccp_profile; | |
16 | + png_uint_32 iccp_proflen; | |
17 | + png_uint_32 width, height; | |
18 | + png_byte channels; | |
19 | /* | |
20 | * PNG 0.89 and newer have a sane, forwards compatible constructor. | |
21 | * Some SGI IRIX users will not have a new enough version though | |
22 | @@ -405,7 +414,7 @@ | |
23 | info = (png_infop)calloc(sizeof(png_info), 1); | |
24 | #endif /* PNG_LIBPNG_VER > 88 */ | |
25 | ||
26 | - if (setjmp (pp->jmpbuf)) | |
27 | + if (setjmp (png_jmpbuf(pp))) | |
28 | { | |
29 | g_message ("%s\nPNG error. File corrupted?", filename); | |
30 | return image; | |
31 | @@ -442,21 +451,23 @@ | |
32 | */ | |
33 | ||
34 | png_read_info(pp, info); | |
35 | - | |
36 | + color_type = png_get_color_type(pp, info); | |
37 | + width=png_get_image_width(pp, info); | |
38 | + height=png_get_image_height(pp, info); | |
39 | /* | |
40 | * Latest attempt, this should be my best yet :) | |
41 | */ | |
42 | - | |
43 | + bit_depth = png_get_bit_depth(pp, info); | |
44 | #ifndef WORDS_BIGENDIAN | |
45 | - if(info->bit_depth == 16) | |
46 | - png_set_swap(pp); | |
47 | + if(bit_depth == 16) | |
48 | + png_set_swap(pp); | |
49 | #endif | |
50 | ||
51 | - if (info->color_type == PNG_COLOR_TYPE_GRAY && info->bit_depth < 8) { | |
52 | + if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) { | |
53 | png_set_expand(pp); | |
54 | } | |
55 | ||
56 | - if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8) { | |
57 | + if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth < 8) { | |
58 | png_set_packing(pp); | |
59 | } | |
60 | ||
61 | @@ -464,8 +475,8 @@ | |
62 | * Expand G+tRNS to GA, RGB+tRNS to RGBA | |
63 | */ | |
64 | ||
65 | - if (info->color_type != PNG_COLOR_TYPE_PALETTE && | |
66 | - (info->valid & PNG_INFO_tRNS)) { | |
67 | + if (color_type != PNG_COLOR_TYPE_PALETTE && | |
68 | + (png_get_valid(pp, info, PNG_INFO_tRNS))) { | |
69 | png_set_expand(pp); | |
70 | } | |
71 | ||
72 | @@ -482,7 +493,7 @@ | |
73 | ||
74 | #if PNG_LIBPNG_VER > 99 | |
75 | if (png_get_valid(pp, info, PNG_INFO_tRNS) && | |
76 | - info->color_type == PNG_COLOR_TYPE_PALETTE) | |
77 | + color_type == PNG_COLOR_TYPE_PALETTE) | |
78 | { | |
79 | png_get_tRNS(pp, info, &alpha_ptr, &num, NULL); | |
80 | /* Copy the existing alpha values from the tRNS chunk */ | |
81 | @@ -505,12 +516,12 @@ | |
82 | ||
83 | png_read_update_info(pp, info); | |
84 | ||
85 | - if(info->bit_depth==16) | |
86 | + if(bit_depth==16) | |
87 | { | |
88 | - switch (info->color_type) | |
89 | + switch (color_type) | |
90 | { | |
91 | case PNG_COLOR_TYPE_RGB : /* RGB */ | |
92 | - bpp = 6; | |
93 | + bpp = 6; | |
94 | image_type = U16_RGB; | |
95 | layer_type = U16_RGB_IMAGE; | |
96 | break; | |
97 | @@ -545,10 +556,10 @@ | |
98 | } | |
99 | else | |
100 | { | |
101 | - switch (info->color_type) | |
102 | + switch (color_type) | |
103 | { | |
104 | case PNG_COLOR_TYPE_RGB : /* RGB */ | |
105 | - bpp = 3; | |
106 | + bpp = 3; | |
107 | image_type = RGB; | |
108 | layer_type = RGB_IMAGE; | |
109 | break; | |
110 | @@ -582,7 +593,7 @@ | |
111 | }; | |
112 | } | |
113 | ||
114 | - image = gimp_image_new(info->width, info->height, image_type); | |
115 | + image = gimp_image_new(width, height, image_type); | |
116 | if (image == -1) | |
117 | { | |
118 | g_message("Can't allocate new image\n%s", filename); | |
119 | @@ -595,7 +606,7 @@ | |
120 | * Create the "background" layer to hold the image... | |
121 | */ | |
122 | ||
123 | - layer = gimp_layer_new(image, _("Background"), info->width, info->height, | |
124 | + layer = gimp_layer_new(image, _("Background"), width, height, | |
125 | layer_type, 100, NORMAL_MODE); | |
126 | gimp_image_add_layer(image, layer, 0); | |
127 | ||
128 | @@ -627,20 +638,21 @@ | |
129 | ||
130 | empty= 0; /* by default assume no full transparent palette entries */ | |
131 | ||
132 | - if (info->color_type & PNG_COLOR_MASK_PALETTE) { | |
133 | + if (color_type & PNG_COLOR_MASK_PALETTE) { | |
134 | ||
135 | #if PNG_LIBPNG_VER > 99 | |
136 | + png_get_PLTE(pp, info, &palette, &num_palette); | |
137 | if (png_get_valid(pp, info, PNG_INFO_tRNS)) { | |
138 | for (empty= 0; empty < 256 && alpha[empty] == 0; ++empty); | |
139 | /* Calculates number of fully transparent "empty" entries */ | |
140 | ||
141 | - gimp_image_set_cmap(image, (guchar *) (info->palette + empty), | |
142 | - info->num_palette - empty); | |
143 | + gimp_image_set_cmap(image, (guchar *) (palette + empty), | |
144 | + num_palette - empty); | |
145 | } else { | |
146 | - gimp_image_set_cmap(image, (guchar *)info->palette, info->num_palette); | |
147 | + gimp_image_set_cmap(image, (guchar *)palette, num_palette); | |
148 | } | |
149 | #else | |
150 | - gimp_image_set_cmap(image, (guchar *)info->palette, info->num_palette); | |
151 | + gimp_image_set_cmap(image, (guchar *)palette, num_palette); | |
152 | #endif /* PNG_LIBPNG_VER > 99 */ | |
153 | ||
154 | } | |
155 | @@ -659,18 +671,19 @@ | |
156 | */ | |
157 | ||
158 | tile_height = gimp_tile_height (); | |
159 | - pixel = g_new(guchar, tile_height * info->width * bpp); | |
160 | + pixel = g_new(guchar, tile_height * width * bpp); | |
161 | pixels = g_new(guchar *, tile_height); | |
162 | + channels=png_get_channels(pp, info); | |
163 | ||
164 | - if(info->bit_depth==16) | |
165 | + if(bit_depth==16) | |
166 | { | |
167 | for (i = 0; i < tile_height; i ++) | |
168 | - pixels[i] = pixel + info->width * info->channels * i * 2; | |
169 | + pixels[i] = pixel + width * channels * i * 2; | |
170 | } | |
171 | else | |
172 | { | |
173 | for (i = 0; i < tile_height; i ++) | |
174 | - pixels[i] = pixel + info->width * info->channels * i; | |
175 | + pixels[i] = pixel + width * channels * i; | |
176 | } | |
177 | ||
178 | for (pass = 0; pass < num_passes; pass ++) | |
179 | @@ -680,11 +693,11 @@ | |
180 | */ | |
181 | ||
182 | for (begin = 0, end = tile_height; | |
183 | - begin < info->height; | |
184 | + begin < height; | |
185 | begin += tile_height, end += tile_height) | |
186 | { | |
187 | - if (end > info->height) | |
188 | - end = info->height; | |
189 | + if (end > height) | |
190 | + end = height; | |
191 | ||
192 | num = end - begin; | |
193 | ||
194 | @@ -697,20 +710,21 @@ | |
195 | gimp_pixel_rgn_set_rect(&pixel_rgn, pixel, 0, begin, | |
196 | drawable->width, num); | |
197 | ||
198 | - gimp_progress_update(((double)pass + (double)end / (double)info->height) / | |
199 | + gimp_progress_update(((double)pass + (double)end / (double)height) / | |
200 | (double)num_passes); | |
201 | }; | |
202 | }; | |
203 | ||
204 | #if defined(PNG_iCCP_SUPPORTED) | |
205 | /* set icc profile */ | |
206 | - if (info->iccp_proflen > 0) { | |
207 | - gimp_image_set_icc_profile_by_mem (image, info->iccp_proflen, | |
208 | - info->iccp_profile, | |
209 | - ICC_IMAGE_PROFILE); | |
210 | + png_get_iCCP(pp, info, (png_charpp)iccp_name, &compression_type, iccp_profile, &iccp_proflen); | |
211 | + if (iccp_proflen > 0) { | |
212 | + gimp_image_set_icc_profile_by_mem (image, iccp_proflen, | |
213 | + (gchar *)iccp_profile, | |
214 | + ICC_IMAGE_PROFILE); | |
215 | printf ("%s:%d %s() set embedded profile \"%s\"\n", | |
216 | __FILE__,__LINE__,__func__, | |
217 | - info->iccp_name); | |
218 | + (char *)iccp_name); | |
219 | } | |
220 | #endif | |
221 | ||
222 | @@ -809,6 +823,15 @@ | |
223 | time_t cutime; /* Time since epoch */ | |
224 | struct tm *gmt; /* GMT broken down */ | |
225 | ||
226 | + png_byte color_type; | |
227 | + png_byte bit_depth; | |
228 | + int filter_method=0; | |
229 | + png_colorp palette; | |
230 | + int num_palette; | |
231 | + png_charpp iccp_name; | |
232 | + png_uint_32 height; | |
233 | + int compression_type; | |
234 | + | |
235 | /* | |
236 | * PNG 0.89 and newer have a sane, forwards compatible constructor. | |
237 | * Some SGI IRIX users will not have a new enough version though | |
238 | @@ -824,7 +847,7 @@ | |
239 | info = (png_infop)calloc(sizeof(png_info), 1); | |
240 | #endif /* PNG_LIBPNG_VER > 88 */ | |
241 | ||
242 | - if (setjmp (pp->jmpbuf)) | |
243 | + if (setjmp (png_jmpbuf(pp))) | |
244 | { | |
245 | g_message ("%s\nPNG error. Couldn't save image", filename); | |
246 | return 0; | |
247 | @@ -858,87 +881,75 @@ | |
248 | type = gimp_drawable_type (drawable_ID); | |
249 | ||
250 | /* | |
251 | - * Set the image dimensions, bit depth, interlacing and compression | |
252 | - */ | |
253 | - | |
254 | - png_set_compression_level (pp, pngvals.compression_level); | |
255 | - | |
256 | - info->width = drawable->width; | |
257 | - info->height = drawable->height; | |
258 | - info->interlace_type = pngvals.interlaced; | |
259 | - | |
260 | - /* | |
261 | * Set color type and remember bytes per pixel count | |
262 | */ | |
263 | ||
264 | switch (type) | |
265 | { | |
266 | case RGB_IMAGE : | |
267 | - info->color_type = PNG_COLOR_TYPE_RGB; | |
268 | - info->bit_depth = 8; | |
269 | + color_type = PNG_COLOR_TYPE_RGB; | |
270 | + bit_depth = 8; | |
271 | bpp = 3; | |
272 | break; | |
273 | case RGBA_IMAGE : | |
274 | - info->color_type = PNG_COLOR_TYPE_RGB_ALPHA; | |
275 | - info->bit_depth = 8; | |
276 | + color_type = PNG_COLOR_TYPE_RGB_ALPHA; | |
277 | + bit_depth = 8; | |
278 | bpp = 4; | |
279 | break; | |
280 | case GRAY_IMAGE : | |
281 | - info->color_type = PNG_COLOR_TYPE_GRAY; | |
282 | - info->bit_depth = 8; | |
283 | + color_type = PNG_COLOR_TYPE_GRAY; | |
284 | + bit_depth = 8; | |
285 | bpp = 1; | |
286 | break; | |
287 | case GRAYA_IMAGE : | |
288 | - info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA; | |
289 | - info->bit_depth = 8; | |
290 | + color_type = PNG_COLOR_TYPE_GRAY_ALPHA; | |
291 | + bit_depth = 8; | |
292 | bpp = 2; | |
293 | break; | |
294 | case INDEXED_IMAGE : | |
295 | bpp = 1; | |
296 | - info->bit_depth = 8; | |
297 | - info->color_type = PNG_COLOR_TYPE_PALETTE; | |
298 | - info->valid |= PNG_INFO_PLTE; | |
299 | - info->palette= (png_colorp) gimp_image_get_cmap(image_ID, &num_colors); | |
300 | - info->num_palette= num_colors; | |
301 | + bit_depth = 8; | |
302 | + color_type = PNG_COLOR_TYPE_PALETTE; | |
303 | + png_get_valid(pp, info, PNG_INFO_PLTE); | |
304 | + png_set_PLTE(pp, info, (png_colorp) gimp_image_get_cmap(image_ID, &num_colors), num_colors); | |
305 | break; | |
306 | case INDEXEDA_IMAGE : | |
307 | bpp = 2; | |
308 | - info->bit_depth = 8; | |
309 | - info->color_type = PNG_COLOR_TYPE_PALETTE; | |
310 | + bit_depth = 8; | |
311 | + color_type = PNG_COLOR_TYPE_PALETTE; | |
312 | respin_cmap (pp, info, image_ID); /* fix up transparency */ | |
313 | break; | |
314 | case U16_RGB_IMAGE : | |
315 | - info->color_type = PNG_COLOR_TYPE_RGB; | |
316 | - info->bit_depth = 16; | |
317 | + color_type = PNG_COLOR_TYPE_RGB; | |
318 | + bit_depth = 16; | |
319 | bpp = 6; | |
320 | break; | |
321 | case U16_RGBA_IMAGE : | |
322 | - info->color_type = PNG_COLOR_TYPE_RGB_ALPHA; | |
323 | - info->bit_depth = 16; | |
324 | + color_type = PNG_COLOR_TYPE_RGB_ALPHA; | |
325 | + bit_depth = 16; | |
326 | bpp = 8; | |
327 | break; | |
328 | case U16_GRAY_IMAGE : | |
329 | - info->color_type = PNG_COLOR_TYPE_GRAY; | |
330 | - info->bit_depth = 16; | |
331 | + color_type = PNG_COLOR_TYPE_GRAY; | |
332 | + bit_depth = 16; | |
333 | bpp = 2; | |
334 | break; | |
335 | case U16_GRAYA_IMAGE : | |
336 | - info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA; | |
337 | - info->bit_depth = 16; | |
338 | + color_type = PNG_COLOR_TYPE_GRAY_ALPHA; | |
339 | + bit_depth = 16; | |
340 | bpp = 4; | |
341 | break; | |
342 | case U16_INDEXED_IMAGE : | |
343 | bpp = 2; | |
344 | - info->bit_depth = 16; | |
345 | - info->color_type = PNG_COLOR_TYPE_PALETTE; | |
346 | - info->valid |= PNG_INFO_PLTE; | |
347 | - info->palette= (png_colorp) gimp_image_get_cmap(image_ID, &num_colors); | |
348 | - info->num_palette= num_colors; | |
349 | + bit_depth = 16; | |
350 | + color_type = PNG_COLOR_TYPE_PALETTE; | |
351 | + png_get_valid(pp, info, PNG_INFO_PLTE); | |
352 | + png_set_PLTE(pp, info, (png_colorp) gimp_image_get_cmap(image_ID, &num_colors), num_colors); | |
353 | break; | |
354 | case U16_INDEXEDA_IMAGE : | |
355 | bpp = 4; | |
356 | - info->bit_depth = 16; | |
357 | - info->color_type = PNG_COLOR_TYPE_PALETTE; | |
358 | + bit_depth = 16; | |
359 | + color_type = PNG_COLOR_TYPE_PALETTE; | |
360 | respin_cmap (pp, info, image_ID); /* fix up transparency */ | |
361 | break; | |
362 | default: | |
363 | @@ -950,16 +961,21 @@ | |
364 | * Fix bit depths for (possibly) smaller colormap images | |
365 | */ | |
366 | ||
367 | - if (info->valid & PNG_INFO_PLTE) { | |
368 | - if (info->num_palette <= 2) | |
369 | - info->bit_depth= 1; | |
370 | - else if (info->num_palette <= 4) | |
371 | - info->bit_depth= 2; | |
372 | - else if (info->num_palette <= 16) | |
373 | - info->bit_depth= 4; | |
374 | + if (png_get_valid(pp, info, PNG_INFO_PLTE)) { | |
375 | + png_get_PLTE(pp, info, &palette, &num_palette); | |
376 | + if (num_palette <= 2) | |
377 | + bit_depth= 1; | |
378 | + else if (num_palette <= 4) | |
379 | + bit_depth= 2; | |
380 | + else if (num_palette <= 16) | |
381 | + bit_depth= 4; | |
382 | /* otherwise the default is fine */ | |
383 | } | |
384 | ||
385 | + png_set_compression_level (pp, pngvals.compression_level); | |
386 | + png_set_IHDR(pp, info, drawable->width, drawable->height, | |
387 | + bit_depth, color_type, pngvals.interlaced, compression_type, filter_method); | |
388 | + | |
389 | // write icc profile | |
390 | #if defined(PNG_iCCP_SUPPORTED) | |
391 | if (gimp_image_has_icc_profile (image_ID, ICC_IMAGE_PROFILE)) { | |
392 | @@ -970,10 +986,10 @@ | |
393 | ICC_IMAGE_PROFILE); | |
394 | png_set_iCCP (pp, info, | |
395 | gimp_image_get_icc_profile_description (image_ID, ICC_IMAGE_PROFILE), | |
396 | - 0, buffer, size); | |
397 | + 0, (png_const_bytep)buffer, size); | |
398 | printf ("%s:%d %s() embedd icc profile \"%s\"\n", | |
399 | __FILE__,__LINE__,__func__, | |
400 | - info->iccp_name); | |
401 | + (char *)iccp_name); | |
402 | } | |
403 | #endif | |
404 | ||
405 | @@ -1039,13 +1055,13 @@ | |
406 | * Convert unpacked pixels to packed if necessary | |
407 | */ | |
408 | ||
409 | - if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8) | |
410 | + if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth < 8) | |
411 | png_set_packing(pp); | |
412 | ||
413 | /* Set swapping for 16 bit per sample images */ | |
414 | ||
415 | #ifndef WORDS_BIGENDIAN | |
416 | - if (info->bit_depth == 16) | |
417 | + if (bit_depth == 16) | |
418 | png_set_swap(pp); | |
419 | #endif | |
420 | ||
421 | @@ -1063,6 +1079,7 @@ | |
422 | ||
423 | gimp_pixel_rgn_init(&pixel_rgn, drawable, 0, 0, drawable->width, | |
424 | drawable->height, FALSE, FALSE); | |
425 | + height=png_get_image_height(pp, info); | |
426 | ||
427 | for (pass = 0; pass < num_passes; pass ++) | |
428 | { | |
429 | @@ -1077,7 +1094,7 @@ | |
430 | num = end - begin; | |
431 | ||
432 | gimp_pixel_rgn_get_rect (&pixel_rgn, pixel, 0, begin, drawable->width, num); | |
433 | - if (info->valid & PNG_INFO_tRNS) { | |
434 | + if (png_get_valid(pp, info, PNG_INFO_tRNS)) { | |
435 | for (i = 0; i < num; ++i) { | |
436 | fixed= pixels[i]; | |
437 | for (k = 0; k < drawable->width; ++k) { | |
438 | @@ -1085,7 +1102,7 @@ | |
439 | } | |
440 | } | |
441 | /* Forgot this case before, what if there are too many colors? */ | |
442 | - } else if (info->valid & PNG_INFO_PLTE && bpp == 2) { | |
443 | + } else if (png_get_valid(pp, info, PNG_INFO_PLTE) && bpp == 2) { | |
444 | for (i = 0; i < num; ++i) { | |
445 | fixed= pixels[i]; | |
446 | for (k = 0; k < drawable->width; ++k) { | |
447 | @@ -1097,7 +1114,7 @@ | |
448 | png_write_rows (pp, pixels, num); | |
449 | ||
450 | gimp_progress_update (((double)pass + (double)end / | |
451 | - (double)info->height) / (double)num_passes); | |
452 | + (double)height) / (double)num_passes); | |
453 | }; | |
454 | }; | |
455 |