]>
Commit | Line | Data |
---|---|---|
1 | from: http://www.openbsd.org/cgi-bin/cvsweb/ports/graphics/GraphicsMagick/patches/patch-coders_png_c | |
2 | ||
3 | $OpenBSD: patch-coders_png_c,v 1.6 2011/07/08 20:36:09 naddy Exp $ | |
4 | ||
5 | png.c taken from 1.4.020110207 for compatibility with png 1.5. | |
6 | ||
7 | --- coders/png.c.orig Wed Mar 3 13:26:23 2010 | |
8 | +++ coders/png.c Tue Jul 5 12:18:20 2011 | |
9 | @@ -88,27 +88,8 @@ | |
10 | #include "zlib.h" | |
11 | \f | |
12 | ||
13 | +#if PNG_LIBPNG_VER > 10011 | |
14 | /* | |
15 | - * TO DO: rewrite using png_get_tRNS() instead of direct access to the | |
16 | - * ping and ping_info structs. | |
17 | - */ | |
18 | -#if PNG_LIBPNG_VER < 10400 | |
19 | -# define trans_color trans_values /* Changed at libpng-1.4.0beta35 */ | |
20 | -# define trans_alpha trans /* Changed at libpng-1.4.0beta74 */ | |
21 | -#else | |
22 | - /* We could parse PNG_LIBPNG_VER_STRING here but it's too much bother.. | |
23 | - * Just don't use libpng-1.4.0beta32-34 or beta67-73 | |
24 | - */ | |
25 | -# ifndef PNG_USER_CHUNK_CACHE_MAX /* Added at libpng-1.4.0beta32 */ | |
26 | -# define trans_color trans_values /* Changed at libpng-1.4.0beta35 */ | |
27 | -# endif | |
28 | -# ifndef PNG_TRANSFORM_GRAY_TO_RGB /* Added at libpng-1.4.0beta67 */ | |
29 | -# define trans_alpha trans /* Changed at libpng-1.4.0beta74 */ | |
30 | -# endif | |
31 | -#endif | |
32 | - | |
33 | -#if PNG_LIBPNG_VER > 95 | |
34 | -/* | |
35 | Optional declarations. Define or undefine them as you like. | |
36 | */ | |
37 | /* #define PNG_DEBUG -- turning this on breaks VisualC compiling */ | |
38 | @@ -164,10 +145,6 @@ static SemaphoreInfo | |
39 | PNG_MNG_FEATURES_SUPPORTED is disabled by default in libpng-1.0.9 and | |
40 | will be enabled by default in libpng-1.2.0. | |
41 | */ | |
42 | -#if (PNG_LIBPNG_VER == 10009) /* work around libpng-1.0.9 bug */ | |
43 | -# undef PNG_READ_EMPTY_PLTE_SUPPORTED | |
44 | -# undef PNG_WRITE_EMPTY_PLTE_SUPPORTED | |
45 | -#endif | |
46 | #ifdef PNG_MNG_FEATURES_SUPPORTED | |
47 | # ifndef PNG_READ_EMPTY_PLTE_SUPPORTED | |
48 | # define PNG_READ_EMPTY_PLTE_SUPPORTED | |
49 | @@ -244,6 +221,16 @@ static png_byte FARDATA mng_tIME[5]={116, 73, 77, 6 | |
50 | static png_byte FARDATA mng_zTXt[5]={122, 84, 88, 116, '\0'}; | |
51 | */ | |
52 | ||
53 | +typedef struct _UShortPixelPacket | |
54 | +{ | |
55 | + unsigned short | |
56 | + red, | |
57 | + green, | |
58 | + blue, | |
59 | + opacity, | |
60 | + index; | |
61 | +} UShortPixelPacket; | |
62 | + | |
63 | typedef struct _MngBox | |
64 | { | |
65 | long | |
66 | @@ -492,7 +479,6 @@ static const char* PngColorTypeToString(const unsigned | |
67 | return result; | |
68 | } | |
69 | \f | |
70 | -#if PNG_LIBPNG_VER > 95 | |
71 | #if defined(PNG_SORT_PALETTE) | |
72 | /* | |
73 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
74 | @@ -785,7 +771,6 @@ static MagickPassFail CompressColormapTransFirst(Image | |
75 | return(MagickPass); | |
76 | } | |
77 | #endif | |
78 | -#endif /* PNG_LIBPNG_VER > 95 */ | |
79 | #endif /* HasPNG */ | |
80 | \f | |
81 | /* | |
82 | @@ -907,7 +892,7 @@ static MagickPassFail IsPNG(const unsigned char *magic | |
83 | extern "C" { | |
84 | #endif | |
85 | ||
86 | -#if (PNG_LIBPNG_VER > 95) | |
87 | +#if (PNG_LIBPNG_VER > 10011) | |
88 | static size_t WriteBlobMSBULong(Image *image,const unsigned long value) | |
89 | { | |
90 | unsigned char | |
91 | @@ -956,13 +941,13 @@ static void LogPNGChunk(int logging, png_bytep type, u | |
92 | " Writing %c%c%c%c chunk, length: %lu", | |
93 | type[0],type[1],type[2],type[3],length); | |
94 | } | |
95 | -#endif /* PNG_LIBPNG_VER > 95 */ | |
96 | +#endif /* PNG_LIBPNG_VER > 10011 */ | |
97 | ||
98 | #if defined(__cplusplus) || defined(c_plusplus) | |
99 | } | |
100 | #endif | |
101 | ||
102 | -#if PNG_LIBPNG_VER > 95 | |
103 | +#if PNG_LIBPNG_VER > 10011 | |
104 | /* | |
105 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
106 | % % | |
107 | @@ -1351,7 +1336,11 @@ static void PNGErrorHandler(png_struct *ping,png_const | |
108 | " libpng-%.1024s error: %.1024s", | |
109 | PNG_LIBPNG_VER_STRING, message); | |
110 | (void) ThrowException2(&image->exception,CoderError,message,image->filename); | |
111 | +#if (PNG_LIBPNG_VER < 10500) | |
112 | longjmp(ping->jmpbuf,1); | |
113 | +#else | |
114 | + png_longjmp(ping,1); | |
115 | +#endif | |
116 | } | |
117 | ||
118 | static void PNGWarningHandler(png_struct *ping,png_const_charp message) | |
119 | @@ -1372,19 +1361,8 @@ static void PNGWarningHandler(png_struct *ping,png_con | |
120 | #ifdef PNG_USER_MEM_SUPPORTED | |
121 | static png_voidp png_IM_malloc(png_structp png_ptr,png_uint_32 size) | |
122 | { | |
123 | -#if (PNG_LIBPNG_VER < 10011) | |
124 | - png_voidp | |
125 | - ret; | |
126 | - | |
127 | png_ptr=png_ptr; | |
128 | - ret=MagickAllocateMemory(png_voidp,(size_t) size); | |
129 | - if (ret == NULL) | |
130 | - png_error("Insufficient memory."); | |
131 | - return (ret); | |
132 | -#else | |
133 | - png_ptr=png_ptr; | |
134 | return MagickAllocateMemory(png_voidp,(size_t) size); | |
135 | -#endif | |
136 | } | |
137 | ||
138 | /* | |
139 | @@ -1560,11 +1538,24 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
140 | logging, | |
141 | num_text, | |
142 | num_passes, | |
143 | - pass; | |
144 | + pass, | |
145 | + ping_bit_depth, | |
146 | + ping_colortype, | |
147 | + ping_interlace_method, | |
148 | + ping_compression_method, | |
149 | + ping_filter_method, | |
150 | + ping_num_trans; | |
151 | ||
152 | - PixelPacket | |
153 | + UShortPixelPacket | |
154 | transparent_color; | |
155 | ||
156 | + png_bytep | |
157 | + ping_trans_alpha; | |
158 | + | |
159 | + png_color_16p | |
160 | + ping_background, | |
161 | + ping_trans_color; | |
162 | + | |
163 | png_info | |
164 | *end_info, | |
165 | *ping_info; | |
166 | @@ -1572,6 +1563,11 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
167 | png_struct | |
168 | *ping; | |
169 | ||
170 | + png_uint_32 | |
171 | + ping_rowbytes, | |
172 | + ping_width, | |
173 | + ping_height; | |
174 | + | |
175 | png_textp | |
176 | text; | |
177 | ||
178 | @@ -1619,23 +1615,12 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
179 | LockSemaphoreInfo(png_semaphore); | |
180 | #endif | |
181 | ||
182 | -#if (PNG_LIBPNG_VER < 10007) | |
183 | +#if (PNG_LIBPNG_VER < 10012) | |
184 | if (image_info->verbose) | |
185 | printf("Your PNG library (libpng-%s) is rather old.\n", | |
186 | PNG_LIBPNG_VER_STRING); | |
187 | #endif | |
188 | ||
189 | -#if (PNG_LIBPNG_VER >= 10400) | |
190 | -# ifndef PNG_TRANSFORM_GRAY_TO_RGB /* Added at libpng-1.4.0beta67 */ | |
191 | - if (image_info->verbose) | |
192 | - { | |
193 | - printf("Your PNG library (libpng-%s) is an old beta version.\n", | |
194 | - PNG_LIBPNG_VER_STRING); | |
195 | - printf("Please update it.\n"); | |
196 | - } | |
197 | -# endif | |
198 | -#endif | |
199 | - | |
200 | image=mng_info->image; | |
201 | ||
202 | /* | |
203 | @@ -1665,7 +1650,7 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
204 | ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image); | |
205 | } | |
206 | png_pixels=(unsigned char *) NULL; | |
207 | - if (setjmp(ping->jmpbuf)) | |
208 | + if (setjmp(png_jmpbuf(ping))) | |
209 | { | |
210 | /* | |
211 | PNG image is corrupt. | |
212 | @@ -1740,18 +1725,32 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
213 | ||
214 | png_read_info(ping,ping_info); | |
215 | ||
216 | + (void) png_get_IHDR(ping,ping_info, | |
217 | + &ping_width, | |
218 | + &ping_height, | |
219 | + &ping_bit_depth, | |
220 | + &ping_colortype, | |
221 | + &ping_interlace_method, | |
222 | + &ping_compression_method, | |
223 | + &ping_filter_method); | |
224 | + | |
225 | + (void) png_get_tRNS(ping, ping_info, &ping_trans_alpha, &ping_num_trans, | |
226 | + &ping_trans_color); | |
227 | + | |
228 | + (void) png_get_bKGD(ping, ping_info, &ping_background); | |
229 | + | |
230 | #if (QuantumDepth == 8) | |
231 | image->depth=8; | |
232 | #else | |
233 | - if (ping_info->bit_depth > 8) | |
234 | + if (ping_bit_depth > 8) | |
235 | image->depth=16; | |
236 | else | |
237 | image->depth=8; | |
238 | #endif | |
239 | ||
240 | - if (ping_info->bit_depth < 8) | |
241 | + if (ping_bit_depth < 8) | |
242 | { | |
243 | - if ((ping_info->color_type == PNG_COLOR_TYPE_PALETTE)) | |
244 | + if (ping_colortype == PNG_COLOR_TYPE_PALETTE) | |
245 | { | |
246 | png_set_packing(ping); | |
247 | image->depth=8; | |
248 | @@ -1761,21 +1760,22 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
249 | { | |
250 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
251 | " PNG width: %lu, height: %lu", | |
252 | - (unsigned long)ping_info->width, | |
253 | - (unsigned long)ping_info->height); | |
254 | + (unsigned long)ping_width, | |
255 | + (unsigned long)ping_height); | |
256 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
257 | " PNG color_type: %d, bit_depth: %d", | |
258 | - ping_info->color_type, ping_info->bit_depth); | |
259 | + ping_colortype, ping_bit_depth); | |
260 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
261 | " PNG compression_method: %d", | |
262 | - ping_info->compression_type); | |
263 | + ping_compression_method); | |
264 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
265 | " PNG interlace_method: %d, filter_method: %d", | |
266 | - ping_info->interlace_type,ping_info->filter_type); | |
267 | + ping_interlace_method, | |
268 | + ping_filter_method); | |
269 | } | |
270 | ||
271 | -#if (PNG_LIBPNG_VER > 10008) && defined(PNG_READ_iCCP_SUPPORTED) | |
272 | - if (ping_info->valid & PNG_INFO_iCCP) | |
273 | +#if defined(PNG_READ_iCCP_SUPPORTED) | |
274 | + if (png_get_valid(ping, ping_info, PNG_INFO_iCCP)) | |
275 | { | |
276 | int | |
277 | compression; | |
278 | @@ -1803,15 +1803,19 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
279 | } | |
280 | } | |
281 | } | |
282 | -#endif /* #if (PNG_LIBPNG_VER > 10008) && defined(PNG_READ_iCCP_SUPPORTED) */ | |
283 | +#endif /* #if defined(PNG_READ_iCCP_SUPPORTED) */ | |
284 | #if defined(PNG_READ_sRGB_SUPPORTED) | |
285 | { | |
286 | int | |
287 | intent; | |
288 | ||
289 | - if (mng_info->have_global_srgb) | |
290 | - image->rendering_intent=(RenderingIntent) | |
291 | - (mng_info->global_srgb_intent+1); | |
292 | + if (!png_get_sRGB(ping,ping_info,&intent)) | |
293 | + { | |
294 | + if (mng_info->have_global_srgb) | |
295 | + { | |
296 | + png_set_sRGB(ping,ping_info,(mng_info->global_srgb_intent+1)); | |
297 | + } | |
298 | + } | |
299 | if (png_get_sRGB(ping,ping_info,&intent)) | |
300 | { | |
301 | image->rendering_intent=(RenderingIntent) (intent+1); | |
302 | @@ -1827,8 +1831,11 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
303 | double | |
304 | file_gamma; | |
305 | ||
306 | - if (mng_info->have_global_gama) | |
307 | - image->gamma=mng_info->global_gamma; | |
308 | + if (!png_get_gAMA(ping,ping_info,&file_gamma)) | |
309 | + { | |
310 | + if (mng_info->have_global_gama) | |
311 | + png_set_gAMA(ping,ping_info,mng_info->global_gamma); | |
312 | + } | |
313 | if (png_get_gAMA(ping,ping_info,&file_gamma)) | |
314 | { | |
315 | image->gamma=(float) file_gamma; | |
316 | @@ -1838,10 +1845,21 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
317 | file_gamma); | |
318 | } | |
319 | } | |
320 | - if (mng_info->have_global_chrm) | |
321 | - image->chromaticity=mng_info->global_chrm; | |
322 | - if (ping_info->valid & PNG_INFO_cHRM) | |
323 | + if (!png_get_valid(ping, ping_info, PNG_INFO_cHRM)) | |
324 | { | |
325 | + if (mng_info->have_global_chrm) | |
326 | + (void) png_set_cHRM(ping,ping_info, | |
327 | + mng_info->global_chrm.white_point.x, | |
328 | + mng_info->global_chrm.white_point.y, | |
329 | + mng_info->global_chrm.red_primary.x, | |
330 | + mng_info->global_chrm.red_primary.y, | |
331 | + mng_info->global_chrm.green_primary.x, | |
332 | + mng_info->global_chrm.green_primary.y, | |
333 | + mng_info->global_chrm.blue_primary.x, | |
334 | + mng_info->global_chrm.blue_primary.y); | |
335 | + } | |
336 | + if (png_get_valid(ping, ping_info, PNG_INFO_cHRM)) | |
337 | + { | |
338 | (void) png_get_cHRM(ping,ping_info, | |
339 | &image->chromaticity.white_point.x, | |
340 | &image->chromaticity.white_point.y, | |
341 | @@ -1867,12 +1885,9 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
342 | image->chromaticity.white_point.x=0.3127f; | |
343 | image->chromaticity.white_point.y=0.3290f; | |
344 | } | |
345 | - if (mng_info->have_global_gama || image->rendering_intent) | |
346 | - ping_info->valid|=PNG_INFO_gAMA; | |
347 | - if (mng_info->have_global_chrm || image->rendering_intent) | |
348 | - ping_info->valid|=PNG_INFO_cHRM; | |
349 | #if defined(PNG_oFFs_SUPPORTED) | |
350 | - if (mng_info->mng_type == 0 && (ping_info->valid & PNG_INFO_oFFs)) | |
351 | + if (mng_info->mng_type == 0 && (png_get_valid(ping, ping_info, | |
352 | + PNG_INFO_oFFs))) | |
353 | { | |
354 | image->page.x=png_get_x_offset_pixels(ping, ping_info); | |
355 | image->page.y=png_get_y_offset_pixels(ping, ping_info); | |
356 | @@ -1885,8 +1900,18 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
357 | } | |
358 | #endif | |
359 | #if defined(PNG_pHYs_SUPPORTED) | |
360 | - if (ping_info->valid & PNG_INFO_pHYs) | |
361 | + if (!png_get_valid(ping, ping_info, PNG_INFO_pHYs)) | |
362 | { | |
363 | + if (mng_info->have_global_phys) | |
364 | + { | |
365 | + png_set_pHYs(ping,ping_info, | |
366 | + mng_info->global_x_pixels_per_unit, | |
367 | + mng_info->global_y_pixels_per_unit, | |
368 | + mng_info->global_phys_unit_type); | |
369 | + } | |
370 | + } | |
371 | + if (png_get_valid(ping, ping_info, PNG_INFO_pHYs)) | |
372 | + { | |
373 | int | |
374 | unit_type; | |
375 | ||
376 | @@ -1915,25 +1940,8 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
377 | (unsigned long)y_resolution, | |
378 | unit_type); | |
379 | } | |
380 | - else | |
381 | - { | |
382 | - if (mng_info->have_global_phys) | |
383 | - { | |
384 | - image->x_resolution=(float) mng_info->global_x_pixels_per_unit; | |
385 | - image->y_resolution=(float) mng_info->global_y_pixels_per_unit; | |
386 | - if (mng_info->global_phys_unit_type == PNG_RESOLUTION_METER) | |
387 | - { | |
388 | - image->units=PixelsPerCentimeterResolution; | |
389 | - image->x_resolution=(double) | |
390 | - mng_info->global_x_pixels_per_unit/100.0; | |
391 | - image->y_resolution=(double) | |
392 | - mng_info->global_y_pixels_per_unit/100.0; | |
393 | - } | |
394 | - ping_info->valid|=PNG_INFO_pHYs; | |
395 | - } | |
396 | - } | |
397 | #endif | |
398 | - if (ping_info->valid & PNG_INFO_PLTE) | |
399 | + if (png_get_valid(ping, ping_info, PNG_INFO_PLTE)) | |
400 | { | |
401 | int | |
402 | number_colors; | |
403 | @@ -1942,14 +1950,14 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
404 | palette; | |
405 | ||
406 | (void) png_get_PLTE(ping,ping_info,&palette,&number_colors); | |
407 | - if (number_colors == 0 && ping_info->color_type == | |
408 | + if (number_colors == 0 && ping_colortype == | |
409 | PNG_COLOR_TYPE_PALETTE) | |
410 | { | |
411 | if (mng_info->global_plte_length) | |
412 | { | |
413 | png_set_PLTE(ping,ping_info,mng_info->global_plte, | |
414 | (int) mng_info->global_plte_length); | |
415 | - if (!(ping_info->valid & PNG_INFO_tRNS)) | |
416 | + if (!(png_get_valid(ping, ping_info, PNG_INFO_tRNS))) | |
417 | if (mng_info->global_trns_length) | |
418 | { | |
419 | if (mng_info->global_trns_length > | |
420 | @@ -1966,7 +1974,7 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
421 | #ifndef PNG_READ_EMPTY_PLTE_SUPPORTED | |
422 | mng_info->have_saved_bkgd_index || | |
423 | #endif | |
424 | - ping_info->valid & PNG_INFO_bKGD) | |
425 | + png_get_valid(ping, ping_info, PNG_INFO_bKGD)) | |
426 | { | |
427 | png_color_16 | |
428 | background; | |
429 | @@ -1974,9 +1982,9 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
430 | #ifndef PNG_READ_EMPTY_PLTE_SUPPORTED | |
431 | if (mng_info->have_saved_bkgd_index) | |
432 | background.index=mng_info->saved_bkgd_index; | |
433 | - else | |
434 | #endif | |
435 | - background.index=ping_info->background.index; | |
436 | + if (png_get_valid(ping, ping_info, PNG_INFO_bKGD)) | |
437 | + background.index=ping_background->index; | |
438 | background.red=(png_uint_16) | |
439 | mng_info->global_plte[background.index].red; | |
440 | background.green=(png_uint_16) | |
441 | @@ -1995,34 +2003,76 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
442 | } | |
443 | ||
444 | #if defined(PNG_READ_bKGD_SUPPORTED) | |
445 | - if (mng_info->have_global_bkgd && !(ping_info->valid & PNG_INFO_bKGD)) | |
446 | + if (mng_info->have_global_bkgd && | |
447 | + !(png_get_valid(ping,ping_info, PNG_INFO_bKGD))) | |
448 | image->background_color=mng_info->mng_global_bkgd; | |
449 | - if (ping_info->valid & PNG_INFO_bKGD) | |
450 | + if (png_get_valid(ping, ping_info, PNG_INFO_bKGD)) | |
451 | { | |
452 | /* | |
453 | Set image background color. | |
454 | */ | |
455 | + | |
456 | if (logging) | |
457 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
458 | " Reading PNG bKGD chunk."); | |
459 | - if (ping_info->bit_depth <= QuantumDepth) | |
460 | + | |
461 | + if (ping_bit_depth == QuantumDepth) | |
462 | { | |
463 | - image->background_color.red=ping_info->background.red; | |
464 | - image->background_color.green=ping_info->background.green; | |
465 | - image->background_color.blue=ping_info->background.blue; | |
466 | + image->background_color.red = ping_background->red; | |
467 | + image->background_color.green= ping_background->green; | |
468 | + image->background_color.blue = ping_background->blue; | |
469 | } | |
470 | - else | |
471 | + else /* Scale background components to 16-bit */ | |
472 | { | |
473 | + unsigned int | |
474 | + bkgd_scale; | |
475 | + | |
476 | + if (logging != MagickFalse) | |
477 | + (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
478 | + " raw ping_background=(%d,%d,%d).",ping_background->red, | |
479 | + ping_background->green,ping_background->blue); | |
480 | + | |
481 | + bkgd_scale = 1; | |
482 | + if (ping_bit_depth == 1) | |
483 | + bkgd_scale = 255; | |
484 | + else if (ping_bit_depth == 2) | |
485 | + bkgd_scale = 85; | |
486 | + else if (ping_bit_depth == 4) | |
487 | + bkgd_scale = 17; | |
488 | + if (ping_bit_depth <= 8) | |
489 | + bkgd_scale *= 257; | |
490 | + | |
491 | + ping_background->red *= bkgd_scale; | |
492 | + ping_background->green *= bkgd_scale; | |
493 | + ping_background->blue *= bkgd_scale; | |
494 | + | |
495 | + if (logging != MagickFalse) | |
496 | + { | |
497 | + (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
498 | + " bkgd_scale=%d.",bkgd_scale); | |
499 | + (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
500 | + " ping_background=(%d,%d,%d).",ping_background->red, | |
501 | + ping_background->green,ping_background->blue); | |
502 | + } | |
503 | + | |
504 | image->background_color.red= | |
505 | - ScaleShortToQuantum(ping_info->background.red); | |
506 | + ScaleShortToQuantum(ping_background->red); | |
507 | image->background_color.green= | |
508 | - ScaleShortToQuantum(ping_info->background.green); | |
509 | + ScaleShortToQuantum(ping_background->green); | |
510 | image->background_color.blue= | |
511 | - ScaleShortToQuantum(ping_info->background.blue); | |
512 | + ScaleShortToQuantum(ping_background->blue); | |
513 | + image->background_color.opacity=OpaqueOpacity; | |
514 | + | |
515 | + if (logging != MagickFalse) | |
516 | + (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
517 | + " image->background_color=(%d,%d,%d).", | |
518 | + image->background_color.red, | |
519 | + image->background_color.green,image->background_color.blue); | |
520 | } | |
521 | } | |
522 | #endif | |
523 | - if (ping_info->valid & PNG_INFO_tRNS) | |
524 | + | |
525 | + if (png_get_valid(ping, ping_info, PNG_INFO_tRNS)) | |
526 | { | |
527 | int | |
528 | bit_mask; | |
529 | @@ -2031,49 +2081,70 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
530 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
531 | " Reading PNG tRNS chunk."); | |
532 | ||
533 | - bit_mask = (1 << ping_info->bit_depth) - 1; | |
534 | + bit_mask = (1 << ping_bit_depth) - 1; | |
535 | ||
536 | /* | |
537 | Image has a transparent background. | |
538 | */ | |
539 | + | |
540 | transparent_color.red= | |
541 | - (Quantum)(ping_info->trans_color.red & bit_mask); | |
542 | + (unsigned short)(ping_trans_color->red & bit_mask); | |
543 | transparent_color.green= | |
544 | - (Quantum) (ping_info->trans_color.green & bit_mask); | |
545 | + (unsigned short) (ping_trans_color->green & bit_mask); | |
546 | transparent_color.blue= | |
547 | - (Quantum) (ping_info->trans_color.blue & bit_mask); | |
548 | + (unsigned short) (ping_trans_color->blue & bit_mask); | |
549 | transparent_color.opacity= | |
550 | - (Quantum) (ping_info->trans_color.gray & bit_mask); | |
551 | - if (ping_info->color_type == PNG_COLOR_TYPE_GRAY) | |
552 | + (unsigned short) (ping_trans_color->gray & bit_mask); | |
553 | + | |
554 | + if (ping_colortype == PNG_COLOR_TYPE_GRAY) | |
555 | { | |
556 | +#if (Quantum_depth == 8) | |
557 | + if (ping_bit_depth < Quantum_depth) | |
558 | +#endif | |
559 | + transparent_color.opacity=(unsigned short) ( | |
560 | + ping_trans_color->gray * | |
561 | + (65535L/((1UL << ping_bit_depth)-1))); | |
562 | + | |
563 | +#if (Quantum_depth == 8) | |
564 | + else | |
565 | + transparent_color.opacity=(unsigned short) ( | |
566 | + (ping_trans_color->gray * 65535L)/ | |
567 | + ((1UL << ping_bit_depth)-1)); | |
568 | +#endif | |
569 | + if (logging != MagickFalse) | |
570 | + { | |
571 | + (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
572 | + " Raw tRNS graylevel is %d.",ping_trans_color->gray); | |
573 | + (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
574 | + " scaled graylevel is %d.",transparent_color.opacity); | |
575 | + } | |
576 | transparent_color.red=transparent_color.opacity; | |
577 | transparent_color.green=transparent_color.opacity; | |
578 | transparent_color.blue=transparent_color.opacity; | |
579 | } | |
580 | } | |
581 | #if defined(PNG_READ_sBIT_SUPPORTED) | |
582 | - if (mng_info->have_global_sbit) | |
583 | - { | |
584 | - int | |
585 | - not_valid; | |
586 | - not_valid=!ping_info->valid; | |
587 | - if (not_valid & PNG_INFO_sBIT) | |
588 | + if (!png_get_valid(ping, ping_info, PNG_INFO_sBIT)) | |
589 | + if (mng_info->have_global_sbit) | |
590 | png_set_sBIT(ping,ping_info,&mng_info->global_sbit); | |
591 | - } | |
592 | #endif | |
593 | num_passes=png_set_interlace_handling(ping); | |
594 | + | |
595 | png_read_update_info(ping,ping_info); | |
596 | + | |
597 | + ping_rowbytes=png_get_rowbytes(ping,ping_info); | |
598 | + | |
599 | /* | |
600 | Initialize image structure. | |
601 | */ | |
602 | mng_info->image_box.left=0; | |
603 | - mng_info->image_box.right=(long) ping_info->width; | |
604 | + mng_info->image_box.right=(long) ping_width; | |
605 | mng_info->image_box.top=0; | |
606 | - mng_info->image_box.bottom=(long) ping_info->height; | |
607 | + mng_info->image_box.bottom=(long) ping_height; | |
608 | if (mng_info->mng_type == 0) | |
609 | { | |
610 | - mng_info->mng_width=ping_info->width; | |
611 | - mng_info->mng_height=ping_info->height; | |
612 | + mng_info->mng_width=ping_width; | |
613 | + mng_info->mng_height=ping_height; | |
614 | mng_info->frame=mng_info->image_box; | |
615 | mng_info->clip=mng_info->image_box; | |
616 | } | |
617 | @@ -2082,14 +2153,14 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
618 | image->page.y=mng_info->y_off[mng_info->object_id]; | |
619 | } | |
620 | image->compression=ZipCompression; | |
621 | - image->columns=ping_info->width; | |
622 | - image->rows=ping_info->height; | |
623 | - if ((ping_info->color_type == PNG_COLOR_TYPE_PALETTE) || | |
624 | - (ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) || | |
625 | - (ping_info->color_type == PNG_COLOR_TYPE_GRAY)) | |
626 | + image->columns=ping_width; | |
627 | + image->rows=ping_height; | |
628 | + if ((ping_colortype == PNG_COLOR_TYPE_PALETTE) || | |
629 | + (ping_colortype == PNG_COLOR_TYPE_GRAY_ALPHA) || | |
630 | + (ping_colortype == PNG_COLOR_TYPE_GRAY)) | |
631 | { | |
632 | image->storage_class=PseudoClass; | |
633 | - image->colors=1 << ping_info->bit_depth; | |
634 | + image->colors=1 << ping_bit_depth; | |
635 | #if (QuantumDepth == 8) | |
636 | if (image->colors > 256) | |
637 | image->colors=256; | |
638 | @@ -2097,7 +2168,7 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
639 | if (image->colors > 65536L) | |
640 | image->colors=65536L; | |
641 | #endif | |
642 | - if (ping_info->color_type == PNG_COLOR_TYPE_PALETTE) | |
643 | + if (ping_colortype == PNG_COLOR_TYPE_PALETTE) | |
644 | { | |
645 | int | |
646 | number_colors; | |
647 | @@ -2121,7 +2192,7 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
648 | */ | |
649 | if (!AllocateImageColormap(image,image->colors)) | |
650 | ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image); | |
651 | - if (ping_info->color_type == PNG_COLOR_TYPE_PALETTE) | |
652 | + if (ping_colortype == PNG_COLOR_TYPE_PALETTE) | |
653 | { | |
654 | int | |
655 | number_colors; | |
656 | @@ -2142,7 +2213,7 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
657 | unsigned long | |
658 | scale; | |
659 | ||
660 | - scale=(MaxRGB/((1 << ping_info->bit_depth)-1)); | |
661 | + scale=(MaxRGB/((1 << ping_bit_depth)-1)); | |
662 | if (scale < 1) | |
663 | scale=1; | |
664 | for (i=0; i < (long) image->colors; i++) | |
665 | @@ -2182,10 +2253,9 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
666 | " Reading PNG IDAT chunk(s)"); | |
667 | if (num_passes > 1) | |
668 | png_pixels=MagickAllocateMemory(unsigned char *, | |
669 | - ping_info->rowbytes*image->rows); | |
670 | + ping_rowbytes*image->rows); | |
671 | else | |
672 | - png_pixels=MagickAllocateMemory(unsigned char *, | |
673 | - ping_info->rowbytes); | |
674 | + png_pixels=MagickAllocateMemory(unsigned char *, ping_rowbytes); | |
675 | if (png_pixels == (unsigned char *) NULL) | |
676 | ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image); | |
677 | ||
678 | @@ -2205,20 +2275,20 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
679 | int | |
680 | depth; | |
681 | ||
682 | - depth=(long) ping_info->bit_depth; | |
683 | + depth=(long) ping_bit_depth; | |
684 | #endif | |
685 | - image->matte=((ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) || | |
686 | - (ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) || | |
687 | - (ping_info->valid & PNG_INFO_tRNS)); | |
688 | + image->matte=((ping_colortype == PNG_COLOR_TYPE_RGB_ALPHA) || | |
689 | + (ping_colortype == PNG_COLOR_TYPE_GRAY_ALPHA) || | |
690 | + (png_get_valid(ping, ping_info, PNG_INFO_tRNS))); | |
691 | ||
692 | for (y=0; y < (long) image->rows; y++) | |
693 | { | |
694 | if (num_passes > 1) | |
695 | - row_offset=ping_info->rowbytes*y; | |
696 | + row_offset=ping_rowbytes*y; | |
697 | else | |
698 | row_offset=0; | |
699 | png_read_row(ping,png_pixels+row_offset,NULL); | |
700 | - if (!SetImagePixels(image,0,y,image->columns,1)) /* Was GetImagePixels() */ | |
701 | + if (!SetImagePixels(image,0,y,image->columns,1)) | |
702 | break; | |
703 | #if (QuantumDepth == 8) | |
704 | if (depth == 16) | |
705 | @@ -2229,13 +2299,13 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
706 | ||
707 | r=png_pixels+row_offset; | |
708 | p=r; | |
709 | - if (ping_info->color_type == PNG_COLOR_TYPE_GRAY) | |
710 | + if (ping_colortype == PNG_COLOR_TYPE_GRAY) | |
711 | { | |
712 | for (x=(long) image->columns; x > 0; x--) | |
713 | { | |
714 | *r++=*p++; | |
715 | p++; | |
716 | - if ((ping_info->valid & PNG_INFO_tRNS) && | |
717 | + if ((png_get_valid(ping, ping_info, PNG_INFO_tRNS)) && | |
718 | (((*(p-2) << 8)|*(p-1)) | |
719 | == transparent_color.opacity)) | |
720 | { | |
721 | @@ -2246,9 +2316,9 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
722 | *r++=OpaqueOpacity; | |
723 | } | |
724 | } | |
725 | - else if (ping_info->color_type == PNG_COLOR_TYPE_RGB) | |
726 | + else if (ping_colortype == PNG_COLOR_TYPE_RGB) | |
727 | { | |
728 | - if (ping_info->valid & PNG_INFO_tRNS) | |
729 | + if (png_get_valid(ping, ping_info, PNG_INFO_tRNS)) | |
730 | for (x=(long) image->columns; x > 0; x--) | |
731 | { | |
732 | *r++=*p++; | |
733 | @@ -2282,25 +2352,25 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
734 | *r++=OpaqueOpacity; | |
735 | } | |
736 | } | |
737 | - else if (ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) | |
738 | + else if (ping_colortype == PNG_COLOR_TYPE_RGB_ALPHA) | |
739 | for (x=(long) (4*image->columns); x > 0; x--) | |
740 | { | |
741 | *r++=*p++; | |
742 | p++; | |
743 | } | |
744 | - else if (ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) | |
745 | + else if (ping_colortype == PNG_COLOR_TYPE_GRAY_ALPHA) | |
746 | for (x=(long) (2*image->columns); x > 0; x--) | |
747 | { | |
748 | *r++=*p++; | |
749 | p++; | |
750 | } | |
751 | } | |
752 | - if (depth == 8 && ping_info->color_type == PNG_COLOR_TYPE_GRAY) | |
753 | + if (depth == 8 && ping_colortype == PNG_COLOR_TYPE_GRAY) | |
754 | (void) ImportImagePixelArea(image,(QuantumType) GrayQuantum, | |
755 | image->depth,png_pixels+ | |
756 | row_offset,0,0); | |
757 | - if (ping_info->color_type == PNG_COLOR_TYPE_GRAY || | |
758 | - ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) | |
759 | + if (ping_colortype == PNG_COLOR_TYPE_GRAY || | |
760 | + ping_colortype == PNG_COLOR_TYPE_GRAY_ALPHA) | |
761 | { | |
762 | image->depth=8; | |
763 | (void) ImportImagePixelArea(image, | |
764 | @@ -2309,12 +2379,12 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
765 | row_offset,0,0); | |
766 | image->depth=depth; | |
767 | } | |
768 | - else if (depth == 8 && ping_info->color_type == PNG_COLOR_TYPE_RGB) | |
769 | + else if (depth == 8 && ping_colortype == PNG_COLOR_TYPE_RGB) | |
770 | (void) ImportImagePixelArea(image,(QuantumType) RGBQuantum, | |
771 | image->depth,png_pixels+ | |
772 | row_offset,0,0); | |
773 | - else if (ping_info->color_type == PNG_COLOR_TYPE_RGB || | |
774 | - ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) | |
775 | + else if (ping_colortype == PNG_COLOR_TYPE_RGB || | |
776 | + ping_colortype == PNG_COLOR_TYPE_RGB_ALPHA) | |
777 | { | |
778 | image->depth=8; | |
779 | (void) ImportImagePixelArea(image,(QuantumType) RGBAQuantum, | |
780 | @@ -2322,28 +2392,28 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
781 | row_offset,0,0); | |
782 | image->depth=depth; | |
783 | } | |
784 | - else if (ping_info->color_type == PNG_COLOR_TYPE_PALETTE) | |
785 | + else if (ping_colortype == PNG_COLOR_TYPE_PALETTE) | |
786 | (void) ImportImagePixelArea(image,(QuantumType) IndexQuantum, | |
787 | - ping_info->bit_depth,png_pixels+ | |
788 | + ping_bit_depth,png_pixels+ | |
789 | row_offset,0,0); | |
790 | /* FIXME, sample size ??? */ | |
791 | #else /* (QuantumDepth != 8) */ | |
792 | ||
793 | - if (ping_info->color_type == PNG_COLOR_TYPE_GRAY) | |
794 | + if (ping_colortype == PNG_COLOR_TYPE_GRAY) | |
795 | (void) ImportImagePixelArea(image,(QuantumType) GrayQuantum, | |
796 | image->depth,png_pixels+ | |
797 | row_offset,0,0); | |
798 | - else if (ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) | |
799 | + else if (ping_colortype == PNG_COLOR_TYPE_GRAY_ALPHA) | |
800 | (void) ImportImagePixelArea(image,(QuantumType) GrayAlphaQuantum, | |
801 | image->depth,png_pixels+ | |
802 | row_offset,0,0); | |
803 | - else if (ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) | |
804 | + else if (ping_colortype == PNG_COLOR_TYPE_RGB_ALPHA) | |
805 | (void) ImportImagePixelArea(image,(QuantumType) RGBAQuantum, | |
806 | image->depth,png_pixels+ | |
807 | row_offset,0,0); | |
808 | - else if (ping_info->color_type == PNG_COLOR_TYPE_PALETTE) | |
809 | + else if (ping_colortype == PNG_COLOR_TYPE_PALETTE) | |
810 | (void) ImportImagePixelArea(image,(QuantumType) IndexQuantum, | |
811 | - ping_info->bit_depth,png_pixels+ | |
812 | + ping_bit_depth,png_pixels+ | |
813 | row_offset,0,0); | |
814 | /* FIXME, sample size ??? */ | |
815 | else | |
816 | @@ -2372,7 +2442,7 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
817 | /* | |
818 | Convert grayscale image to PseudoClass pixel packets. | |
819 | */ | |
820 | - image->matte=ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA; | |
821 | + image->matte=ping_colortype == PNG_COLOR_TYPE_GRAY_ALPHA; | |
822 | quantum_scanline=MagickAllocateMemory(Quantum *, | |
823 | (image->matte ? 2 : 1) * | |
824 | image->columns*sizeof(Quantum)); | |
825 | @@ -2385,7 +2455,7 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
826 | *p; | |
827 | ||
828 | if (num_passes > 1) | |
829 | - row_offset=ping_info->rowbytes*y; | |
830 | + row_offset=ping_rowbytes*y; | |
831 | else | |
832 | row_offset=0; | |
833 | png_read_row(ping,png_pixels+row_offset,NULL); | |
834 | @@ -2395,7 +2465,7 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
835 | indexes=AccessMutableIndexes(image); | |
836 | p=png_pixels+row_offset; | |
837 | r=quantum_scanline; | |
838 | - switch (ping_info->bit_depth) | |
839 | + switch (ping_bit_depth) | |
840 | { | |
841 | case 1: | |
842 | { | |
843 | @@ -2445,7 +2515,7 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
844 | } | |
845 | case 8: | |
846 | { | |
847 | - if (ping_info->color_type == 4) | |
848 | + if (ping_colortype == 4) | |
849 | for (x=(long) image->columns; x > 0; x--) | |
850 | { | |
851 | *r++=*p++; | |
852 | @@ -2473,7 +2543,7 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
853 | *r=0; | |
854 | *r|=(*p++); | |
855 | r++; | |
856 | - if (ping_info->color_type == 4) | |
857 | + if (ping_colortype == 4) | |
858 | { | |
859 | q->opacity=((*p++) << 8); | |
860 | q->opacity|=(*p++); | |
861 | @@ -2488,7 +2558,7 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
862 | *r=0; | |
863 | *r|=(*p++); | |
864 | r++; | |
865 | - if (ping_info->color_type == 4) | |
866 | + if (ping_colortype == 4) | |
867 | { | |
868 | q->opacity=((*p++) << 8); | |
869 | q->opacity|=(*p++); | |
870 | @@ -2499,7 +2569,7 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
871 | #else /* QuantumDepth == 8 */ | |
872 | *r++=(*p++); | |
873 | p++; /* strip low byte */ | |
874 | - if (ping_info->color_type == 4) | |
875 | + if (ping_colortype == 4) | |
876 | { | |
877 | q->opacity=(Quantum) (MaxRGB-(*p++)); | |
878 | p++; | |
879 | @@ -2549,7 +2619,7 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
880 | " exit ReadOnePNGImage()."); | |
881 | return (image); | |
882 | } | |
883 | - if (ping_info->valid & PNG_INFO_tRNS) | |
884 | + if (png_get_valid(ping, ping_info, PNG_INFO_tRNS)) | |
885 | { | |
886 | ClassType | |
887 | storage_class; | |
888 | @@ -2572,25 +2642,26 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
889 | IndexPacket | |
890 | index; | |
891 | ||
892 | - if (ping_info->color_type == PNG_COLOR_TYPE_PALETTE) | |
893 | + if (ping_colortype == PNG_COLOR_TYPE_PALETTE) | |
894 | for (x=0; x < (long) image->columns; x++) | |
895 | { | |
896 | index=indexes[x]; | |
897 | - if (index < ping_info->num_trans) | |
898 | + if (index < ping_num_trans) | |
899 | q->opacity= | |
900 | - ScaleCharToQuantum(255-ping_info->trans_alpha[index]); | |
901 | + ScaleCharToQuantum(255-ping_trans_alpha[index]); | |
902 | else | |
903 | q->opacity=OpaqueOpacity; | |
904 | q++; | |
905 | } | |
906 | - else if (ping_info->color_type == PNG_COLOR_TYPE_GRAY) | |
907 | + else if (ping_colortype == PNG_COLOR_TYPE_GRAY) | |
908 | for (x=0; x < (long) image->columns; x++) | |
909 | { | |
910 | index=indexes[x]; | |
911 | q->red=image->colormap[index].red; | |
912 | q->green=image->colormap[index].green; | |
913 | q->blue=image->colormap[index].blue; | |
914 | - if (q->red == transparent_color.opacity) | |
915 | + if (ScaleQuantumToShort(q->red) == | |
916 | + transparent_color.opacity) | |
917 | q->opacity=TransparentOpacity; | |
918 | else | |
919 | q->opacity=OpaqueOpacity; | |
920 | @@ -2600,9 +2671,9 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
921 | else | |
922 | for (x=(long) image->columns; x > 0; x--) | |
923 | { | |
924 | - if (q->red == transparent_color.red && | |
925 | - q->green == transparent_color.green && | |
926 | - q->blue == transparent_color.blue) | |
927 | + if (ScaleQuantumToShort(q->red) == transparent_color.red && | |
928 | + ScaleQuantumToShort(q->green) == transparent_color.green && | |
929 | + ScaleQuantumToShort(q->blue) == transparent_color.blue) | |
930 | q->opacity=TransparentOpacity; | |
931 | else | |
932 | q->opacity=OpaqueOpacity; | |
933 | @@ -2714,7 +2785,7 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, | |
934 | mng_info->ob[object_id]->interlace_method=interlace_method; | |
935 | mng_info->ob[object_id]->compression_method=compression_method; | |
936 | mng_info->ob[object_id]->filter_method=filter_method; | |
937 | - if (ping_info->valid & PNG_INFO_PLTE) | |
938 | + if (png_get_valid(ping, ping_info, PNG_INFO_PLTE)) | |
939 | { | |
940 | int | |
941 | number_colors; | |
942 | @@ -5734,7 +5805,7 @@ static Image *ReadMNGImage(const ImageInfo *image_info | |
943 | (void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit ReadMNGImage()"); | |
944 | return(image); | |
945 | } | |
946 | -#else /* PNG_LIBPNG_VER > 95 */ | |
947 | +#else /* PNG_LIBPNG_VER > 10011 */ | |
948 | static Image *ReadPNGImage(const ImageInfo *image_info, | |
949 | ExceptionInfo *exception) | |
950 | { | |
951 | @@ -5749,7 +5820,7 @@ static Image *ReadMNGImage(const ImageInfo *image_info | |
952 | { | |
953 | return (ReadPNGImage(image_info,exception)); | |
954 | } | |
955 | -#endif /* PNG_LIBPNG_VER > 95 */ | |
956 | +#endif /* PNG_LIBPNG_VER > 10011 */ | |
957 | #endif | |
958 | \f | |
959 | /* | |
960 | @@ -5960,7 +6031,7 @@ ModuleExport void UnregisterPNGImage(void) | |
961 | } | |
962 | \f | |
963 | #if defined(HasPNG) | |
964 | -#if PNG_LIBPNG_VER > 95 | |
965 | +#if PNG_LIBPNG_VER > 10011 | |
966 | /* | |
967 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
968 | % % | |
969 | @@ -6043,28 +6114,13 @@ ModuleExport void UnregisterPNGImage(void) | |
970 | */ | |
971 | ||
972 | ||
973 | -#if (PNG_LIBPNG_VER > 99 && PNG_LIBPNG_VER < 10007) | |
974 | -/* This function became available in libpng version 1.0.6g. */ | |
975 | static void | |
976 | -png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size) | |
977 | -{ | |
978 | - if (png_ptr->zbuf) | |
979 | - png_free(png_ptr, png_ptr->zbuf); png_ptr->zbuf=NULL; | |
980 | - png_ptr->zbuf_size=(png_size_t) size; | |
981 | - png_ptr->zbuf=(png_bytep) png_malloc(png_ptr, size); | |
982 | - if (!png_ptr->zbuf) | |
983 | - png_error(png_ptr,"Unable to allocate zbuf"); | |
984 | -} | |
985 | -#endif | |
986 | - | |
987 | -static void | |
988 | png_write_raw_profile(const ImageInfo *image_info,png_struct *ping, | |
989 | png_info *ping_info, const char *profile_type, | |
990 | const char *profile_description, | |
991 | const unsigned char *profile_data, | |
992 | png_uint_32 length) | |
993 | { | |
994 | -#if (PNG_LIBPNG_VER > 10005) | |
995 | png_textp | |
996 | text; | |
997 | ||
998 | @@ -6083,25 +6139,12 @@ png_write_raw_profile(const ImageInfo *image_info,png_ | |
999 | ||
1000 | unsigned char | |
1001 | hex[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; | |
1002 | -#endif | |
1003 | ||
1004 | -#if (PNG_LIBPNG_VER <= 10005) | |
1005 | if (image_info->verbose) | |
1006 | - (void) printf("Not "); | |
1007 | - (void) image_info; | |
1008 | - (void) ping; | |
1009 | - (void) ping_info; | |
1010 | - (void) profile_type; | |
1011 | - (void) profile_description; | |
1012 | - (void) profile_data; | |
1013 | - (void) length; | |
1014 | -#endif | |
1015 | - if (image_info->verbose) | |
1016 | { | |
1017 | (void) printf("writing raw profile: type=%.1024s, length=%lu\n", | |
1018 | profile_type, (unsigned long)length); | |
1019 | } | |
1020 | -#if (PNG_LIBPNG_VER > 10005) | |
1021 | text=(png_textp) png_malloc(ping,(png_uint_32) sizeof(png_text)); | |
1022 | description_length=strlen((const char *) profile_description); | |
1023 | allocated_length=(png_uint_32) (length*2 + (length >> 5) + 20 | |
1024 | @@ -6137,7 +6180,6 @@ png_write_raw_profile(const ImageInfo *image_info,png_ | |
1025 | png_free(ping,text[0].text); | |
1026 | png_free(ping,text[0].key); | |
1027 | png_free(ping,text); | |
1028 | -#endif | |
1029 | } | |
1030 | ||
1031 | static MagickPassFail WriteOnePNGImage(MngInfo *mng_info, | |
1032 | @@ -6152,17 +6194,34 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1033 | ||
1034 | int | |
1035 | num_passes, | |
1036 | - pass; | |
1037 | + pass, | |
1038 | + ping_bit_depth = 0, | |
1039 | + ping_colortype = 0, | |
1040 | + ping_interlace_method = 0, | |
1041 | + ping_compression_method = 0, | |
1042 | + ping_filter_method = 0, | |
1043 | + ping_num_trans = 0; | |
1044 | ||
1045 | + png_bytep | |
1046 | + ping_trans_alpha = NULL; | |
1047 | + | |
1048 | png_colorp | |
1049 | palette; | |
1050 | ||
1051 | + png_color_16 | |
1052 | + ping_background, | |
1053 | + ping_trans_color; | |
1054 | + | |
1055 | png_info | |
1056 | *ping_info; | |
1057 | ||
1058 | png_struct | |
1059 | *ping; | |
1060 | ||
1061 | + png_uint_32 | |
1062 | + ping_width, | |
1063 | + ping_height; | |
1064 | + | |
1065 | long | |
1066 | y; | |
1067 | ||
1068 | @@ -6181,8 +6240,7 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1069 | image_depth, | |
1070 | image_matte, | |
1071 | logging, | |
1072 | - matte, | |
1073 | - not_valid; | |
1074 | + matte; | |
1075 | ||
1076 | unsigned long | |
1077 | quantum_size, /* depth for ExportImage */ | |
1078 | @@ -6211,6 +6269,18 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1079 | return MagickFail; | |
1080 | } | |
1081 | ||
1082 | + /* Initialize some stuff */ | |
1083 | + ping_background.red = 0; | |
1084 | + ping_background.green = 0; | |
1085 | + ping_background.blue = 0; | |
1086 | + ping_background.gray = 0; | |
1087 | + ping_background.index = 0; | |
1088 | + | |
1089 | + ping_trans_color.red=0; | |
1090 | + ping_trans_color.green=0; | |
1091 | + ping_trans_color.blue=0; | |
1092 | + ping_trans_color.gray=0; | |
1093 | + | |
1094 | image_colors=image->colors; | |
1095 | image_depth=image->depth; | |
1096 | image_matte=image->matte; | |
1097 | @@ -6259,7 +6329,7 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1098 | LockSemaphoreInfo(png_semaphore); | |
1099 | #endif | |
1100 | ||
1101 | - if (setjmp(ping->jmpbuf)) | |
1102 | + if (setjmp(png_jmpbuf(ping))) | |
1103 | { | |
1104 | /* | |
1105 | PNG write failed. | |
1106 | @@ -6288,16 +6358,16 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1107 | # endif | |
1108 | #endif | |
1109 | x=0; | |
1110 | - ping_info->width=image->columns; | |
1111 | - ping_info->height=image->rows; | |
1112 | + ping_width=image->columns; | |
1113 | + ping_height=image->rows; | |
1114 | if (logging) | |
1115 | { | |
1116 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1117 | " width=%lu", | |
1118 | - (unsigned long)ping_info->width); | |
1119 | + (unsigned long)ping_width); | |
1120 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1121 | " height=%lu", | |
1122 | - (unsigned long)ping_info->height); | |
1123 | + (unsigned long)ping_height); | |
1124 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1125 | " image->depth=%u",image_depth); | |
1126 | } | |
1127 | @@ -6306,12 +6376,12 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1128 | quantum_size=(image_depth > 8) ? 16:8; | |
1129 | ||
1130 | save_image_depth=image_depth; | |
1131 | - ping_info->bit_depth=(png_byte) save_image_depth; | |
1132 | + ping_bit_depth=(png_byte) save_image_depth; | |
1133 | if (logging) | |
1134 | { | |
1135 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1136 | - " ping_info->bit_depth=%u", | |
1137 | - ping_info->bit_depth); | |
1138 | + " ping_bit_depth=%u", | |
1139 | + ping_bit_depth); | |
1140 | } | |
1141 | #if defined(PNG_pHYs_SUPPORTED) | |
1142 | if ((image->x_resolution != 0) && (image->y_resolution != 0) && | |
1143 | @@ -6398,8 +6468,8 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1144 | matte=image_matte; | |
1145 | if (mng_info->write_png8) | |
1146 | { | |
1147 | - ping_info->color_type=PNG_COLOR_TYPE_PALETTE; | |
1148 | - ping_info->bit_depth=8; | |
1149 | + ping_colortype=PNG_COLOR_TYPE_PALETTE; | |
1150 | + ping_bit_depth=8; | |
1151 | { | |
1152 | /* TO DO: make this a function cause it's used twice, except | |
1153 | for reducing the sample depth from 8. */ | |
1154 | @@ -6424,13 +6494,13 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1155 | " Colors quantized to %ld", | |
1156 | number_colors); | |
1157 | } | |
1158 | - if (matte) | |
1159 | - ping_info->valid|=PNG_INFO_tRNS; | |
1160 | + | |
1161 | /* | |
1162 | Set image palette. | |
1163 | */ | |
1164 | - ping_info->color_type=PNG_COLOR_TYPE_PALETTE; | |
1165 | - ping_info->valid|=PNG_INFO_PLTE; | |
1166 | + | |
1167 | + ping_colortype=PNG_COLOR_TYPE_PALETTE; | |
1168 | + | |
1169 | #if defined(PNG_SORT_PALETTE) | |
1170 | save_number_colors=image_colors; | |
1171 | if (CompressColormapTransFirst(image) == MagickFail) | |
1172 | @@ -6465,20 +6535,17 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1173 | ||
1174 | } | |
1175 | png_set_PLTE(ping,ping_info,palette,(int) number_colors); | |
1176 | -#if (PNG_LIBPNG_VER > 10008) | |
1177 | MagickFreeMemory(palette); | |
1178 | -#endif | |
1179 | /* | |
1180 | Identify which colormap entry is transparent. | |
1181 | */ | |
1182 | - ping_info->trans_alpha=MagickAllocateMemory(unsigned char *, | |
1183 | - number_colors); | |
1184 | - if (ping_info->trans_alpha == (unsigned char *) NULL) | |
1185 | + ping_trans_alpha=MagickAllocateMemory(unsigned char *, number_colors); | |
1186 | + if (ping_trans_alpha == (unsigned char *) NULL) | |
1187 | ThrowWriterException(ResourceLimitError,MemoryAllocationFailed, | |
1188 | image); | |
1189 | assert(number_colors <= 256); | |
1190 | for (i=0; i < (long) number_colors; i++) | |
1191 | - ping_info->trans_alpha[i]=255; | |
1192 | + ping_trans_alpha[i]=255; | |
1193 | for (y=0; y < (long) image->rows; y++) | |
1194 | { | |
1195 | register const PixelPacket | |
1196 | @@ -6498,29 +6565,29 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1197 | ||
1198 | index=indexes[x]; | |
1199 | assert((unsigned long) index < number_colors); | |
1200 | - ping_info->trans_alpha[index]=(png_byte) (255- | |
1201 | + ping_trans_alpha[index]=(png_byte) (255- | |
1202 | ScaleQuantumToChar(p->opacity)); | |
1203 | } | |
1204 | p++; | |
1205 | } | |
1206 | } | |
1207 | - ping_info->num_trans=0; | |
1208 | + ping_num_trans=0; | |
1209 | for (i=0; i < (long) number_colors; i++) | |
1210 | - if (ping_info->trans_alpha[i] != 255) | |
1211 | - ping_info->num_trans=(unsigned short) (i+1); | |
1212 | - if (ping_info->num_trans == 0) | |
1213 | - ping_info->valid&=(~PNG_INFO_tRNS); | |
1214 | - if (!(ping_info->valid & PNG_INFO_tRNS)) | |
1215 | - ping_info->num_trans=0; | |
1216 | - if (ping_info->num_trans == 0) | |
1217 | - MagickFreeMemory(ping_info->trans_alpha); | |
1218 | + if (ping_trans_alpha[i] != 255) | |
1219 | + ping_num_trans=(unsigned short) (i+1); | |
1220 | + if (ping_num_trans == 0) | |
1221 | + png_set_invalid(ping,ping_info,PNG_INFO_tRNS); | |
1222 | + if (!(png_get_valid(ping,ping_info,PNG_INFO_tRNS))) | |
1223 | + ping_num_trans=0; | |
1224 | + if (ping_num_trans == 0) | |
1225 | + MagickFreeMemory(ping_trans_alpha); | |
1226 | /* | |
1227 | Identify which colormap entry is the background color. | |
1228 | */ | |
1229 | for (i=0; i < (long) Max(number_colors-1,1); i++) | |
1230 | - if (RGBColorMatchExact(ping_info->background,image->colormap[i])) | |
1231 | + if (RGBColorMatchExact(ping_background,image->colormap[i])) | |
1232 | break; | |
1233 | - ping_info->background.index=(png_uint_16) i; | |
1234 | + ping_background.index=(png_uint_16) i; | |
1235 | } | |
1236 | if (image_matte) | |
1237 | { | |
1238 | @@ -6530,79 +6597,79 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1239 | else if (mng_info->write_png24) | |
1240 | { | |
1241 | image_matte=MagickFalse; | |
1242 | - ping_info->color_type=PNG_COLOR_TYPE_RGB; | |
1243 | + ping_colortype=PNG_COLOR_TYPE_RGB; | |
1244 | } | |
1245 | else if (mng_info->write_png32) | |
1246 | { | |
1247 | image_matte=MagickTrue; | |
1248 | - ping_info->color_type=PNG_COLOR_TYPE_RGB_ALPHA; | |
1249 | + ping_colortype=PNG_COLOR_TYPE_RGB_ALPHA; | |
1250 | } | |
1251 | else | |
1252 | { | |
1253 | - if (ping_info->bit_depth < 8) | |
1254 | - ping_info->bit_depth=8; | |
1255 | + if (ping_bit_depth < 8) | |
1256 | + ping_bit_depth=8; | |
1257 | ||
1258 | - ping_info->color_type=PNG_COLOR_TYPE_RGB; | |
1259 | + ping_colortype=PNG_COLOR_TYPE_RGB; | |
1260 | if (characteristics.monochrome) | |
1261 | { | |
1262 | if (characteristics.opaque) | |
1263 | { | |
1264 | - ping_info->color_type=PNG_COLOR_TYPE_GRAY; | |
1265 | - ping_info->bit_depth=1; | |
1266 | + ping_colortype=PNG_COLOR_TYPE_GRAY; | |
1267 | + ping_bit_depth=1; | |
1268 | } | |
1269 | else | |
1270 | { | |
1271 | - ping_info->color_type=PNG_COLOR_TYPE_GRAY_ALPHA; | |
1272 | + ping_colortype=PNG_COLOR_TYPE_GRAY_ALPHA; | |
1273 | } | |
1274 | } | |
1275 | else if (characteristics.grayscale) | |
1276 | { | |
1277 | if (characteristics.opaque) | |
1278 | - ping_info->color_type=PNG_COLOR_TYPE_GRAY; | |
1279 | + ping_colortype=PNG_COLOR_TYPE_GRAY; | |
1280 | else | |
1281 | - ping_info->color_type=PNG_COLOR_TYPE_GRAY_ALPHA; | |
1282 | + ping_colortype=PNG_COLOR_TYPE_GRAY_ALPHA; | |
1283 | } | |
1284 | else if (characteristics.palette && image_colors <= 256) | |
1285 | { | |
1286 | - ping_info->color_type=PNG_COLOR_TYPE_PALETTE; | |
1287 | - ping_info->bit_depth=8; | |
1288 | + ping_colortype=PNG_COLOR_TYPE_PALETTE; | |
1289 | + ping_bit_depth=8; | |
1290 | mng_info->IsPalette=MagickTrue; | |
1291 | } | |
1292 | else | |
1293 | { | |
1294 | if (characteristics.opaque) | |
1295 | - ping_info->color_type=PNG_COLOR_TYPE_RGB; | |
1296 | + ping_colortype=PNG_COLOR_TYPE_RGB; | |
1297 | else | |
1298 | - ping_info->color_type=PNG_COLOR_TYPE_RGB_ALPHA; | |
1299 | + ping_colortype=PNG_COLOR_TYPE_RGB_ALPHA; | |
1300 | } | |
1301 | if (image_info->type == BilevelType) | |
1302 | { | |
1303 | if (characteristics.monochrome) | |
1304 | { | |
1305 | if (!image_matte) | |
1306 | - ping_info->bit_depth=1; | |
1307 | + ping_bit_depth=1; | |
1308 | } | |
1309 | } | |
1310 | if (image_info->type == GrayscaleType) | |
1311 | - ping_info->color_type=PNG_COLOR_TYPE_GRAY; | |
1312 | + ping_colortype=PNG_COLOR_TYPE_GRAY; | |
1313 | if (image_info->type == GrayscaleMatteType) | |
1314 | - ping_info->color_type=PNG_COLOR_TYPE_GRAY_ALPHA; | |
1315 | + ping_colortype=PNG_COLOR_TYPE_GRAY_ALPHA; | |
1316 | /* if (!mng_info->optimize && matte) */ | |
1317 | - /* ping_info->color_type=PNG_COLOR_TYPE_RGB_ALPHA; */ | |
1318 | + /* ping_colortype=PNG_COLOR_TYPE_RGB_ALPHA; */ | |
1319 | ||
1320 | if (logging) | |
1321 | { | |
1322 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1323 | " Tentative PNG color type: %s (%d)", | |
1324 | - PngColorTypeToString(ping_info->color_type), | |
1325 | - ping_info->color_type); | |
1326 | + PngColorTypeToString(ping_colortype), | |
1327 | + ping_colortype); | |
1328 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1329 | " image_info->type: %d",image_info->type); | |
1330 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1331 | " image->depth: %u",image_depth); | |
1332 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1333 | - " ping_info->bit_depth: %d", | |
1334 | - ping_info->bit_depth); | |
1335 | + " ping_bit_depth: %d", | |
1336 | + ping_bit_depth); | |
1337 | } | |
1338 | ||
1339 | if (matte && (mng_info->optimize || mng_info->IsPalette)) | |
1340 | @@ -6614,10 +6681,10 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1341 | { | |
1342 | /* | |
1343 | No transparent pixels are present. Change 4 or 6 to 0 or 2, | |
1344 | - and do not set the PNG_INFO_tRNS flag in ping_info->valid. | |
1345 | + and do not set the PNG_INFO_tRNS flag. | |
1346 | */ | |
1347 | image_matte=MagickFalse; | |
1348 | - ping_info->color_type&=0x03; | |
1349 | + ping_colortype&=0x03; | |
1350 | } | |
1351 | else | |
1352 | { | |
1353 | @@ -6625,13 +6692,13 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1354 | mask; | |
1355 | ||
1356 | mask=0xffff; | |
1357 | - if (ping_info->bit_depth == 8) | |
1358 | + if (ping_bit_depth == 8) | |
1359 | mask=0x00ff; | |
1360 | - if (ping_info->bit_depth == 4) | |
1361 | + if (ping_bit_depth == 4) | |
1362 | mask=0x000f; | |
1363 | - if (ping_info->bit_depth == 2) | |
1364 | + if (ping_bit_depth == 2) | |
1365 | mask=0x0003; | |
1366 | - if (ping_info->bit_depth == 1) | |
1367 | + if (ping_bit_depth == 1) | |
1368 | mask=0x0001; | |
1369 | ||
1370 | /* | |
1371 | @@ -6655,19 +6722,20 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1372 | if ((p != (const PixelPacket *) NULL) && | |
1373 | (p->opacity != OpaqueOpacity)) | |
1374 | { | |
1375 | - ping_info->valid|=PNG_INFO_tRNS; | |
1376 | - ping_info->trans_color.red=ScaleQuantumToShort(p->red)&mask; | |
1377 | - ping_info->trans_color.green=ScaleQuantumToShort(p->green) | |
1378 | + ping_trans_color.red=ScaleQuantumToShort(p->red)&mask; | |
1379 | + ping_trans_color.green=ScaleQuantumToShort(p->green) | |
1380 | &mask; | |
1381 | - ping_info->trans_color.blue=ScaleQuantumToShort(p->blue) | |
1382 | + ping_trans_color.blue=ScaleQuantumToShort(p->blue) | |
1383 | &mask; | |
1384 | - ping_info->trans_color.gray= | |
1385 | + ping_trans_color.gray= | |
1386 | (png_uint_16) ScaleQuantumToShort(PixelIntensity(p))&mask; | |
1387 | - ping_info->trans_color.index=(unsigned char) | |
1388 | + ping_trans_color.index=(unsigned char) | |
1389 | (ScaleQuantumToChar(MaxRGB-p->opacity)); | |
1390 | + (void) png_set_tRNS(ping, ping_info, NULL, 0, | |
1391 | + &ping_trans_color); | |
1392 | } | |
1393 | } | |
1394 | - if (ping_info->valid & PNG_INFO_tRNS) | |
1395 | + if (png_get_valid(ping, ping_info, PNG_INFO_tRNS)) | |
1396 | { | |
1397 | /* | |
1398 | Determine if there is one and only one transparent color | |
1399 | @@ -6684,7 +6752,7 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1400 | { | |
1401 | if (p->opacity != OpaqueOpacity) | |
1402 | { | |
1403 | - if (!RGBColorMatchExact(ping_info->trans_color,*p)) | |
1404 | + if (!RGBColorMatchExact(ping_trans_color,*p)) | |
1405 | { | |
1406 | break; /* Can't use RGB + tRNS for multiple | |
1407 | transparent colors. */ | |
1408 | @@ -6697,7 +6765,7 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1409 | } | |
1410 | else | |
1411 | { | |
1412 | - if (RGBColorMatchExact(ping_info->trans_color,*p)) | |
1413 | + if (RGBColorMatchExact(ping_trans_color,*p)) | |
1414 | break; /* Can't use RGB + tRNS when another pixel | |
1415 | having the same RGB samples is | |
1416 | transparent. */ | |
1417 | @@ -6708,50 +6776,50 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1418 | break; | |
1419 | } | |
1420 | if (x != 0) | |
1421 | - ping_info->valid&=(~PNG_INFO_tRNS); | |
1422 | + png_set_invalid(ping, ping_info, PNG_INFO_tRNS); | |
1423 | } | |
1424 | - if (ping_info->valid & PNG_INFO_tRNS) | |
1425 | + if (png_get_valid(ping, ping_info, PNG_INFO_tRNS)) | |
1426 | { | |
1427 | - ping_info->color_type &= 0x03; /* changes 4 or 6 to 0 or 2 */ | |
1428 | + ping_colortype &= 0x03; /* changes 4 or 6 to 0 or 2 */ | |
1429 | if (image_depth == 8) | |
1430 | { | |
1431 | - ping_info->trans_color.red&=0xff; | |
1432 | - ping_info->trans_color.green&=0xff; | |
1433 | - ping_info->trans_color.blue&=0xff; | |
1434 | - ping_info->trans_color.gray&=0xff; | |
1435 | + ping_trans_color.red&=0xff; | |
1436 | + ping_trans_color.green&=0xff; | |
1437 | + ping_trans_color.blue&=0xff; | |
1438 | + ping_trans_color.gray&=0xff; | |
1439 | } | |
1440 | } | |
1441 | } | |
1442 | matte=image_matte; | |
1443 | - if (ping_info->valid & PNG_INFO_tRNS) | |
1444 | + if (png_get_valid(ping, ping_info, PNG_INFO_tRNS)) | |
1445 | image_matte=MagickFalse; | |
1446 | if ((mng_info->optimize || mng_info->IsPalette) && | |
1447 | characteristics.grayscale && (!image_matte || image_depth >= 8)) | |
1448 | { | |
1449 | if (image_matte) | |
1450 | - ping_info->color_type=PNG_COLOR_TYPE_GRAY_ALPHA; | |
1451 | + ping_colortype=PNG_COLOR_TYPE_GRAY_ALPHA; | |
1452 | else | |
1453 | { | |
1454 | - ping_info->color_type=PNG_COLOR_TYPE_GRAY; | |
1455 | + ping_colortype=PNG_COLOR_TYPE_GRAY; | |
1456 | if (save_image_depth == 16 && image_depth == 8) | |
1457 | - ping_info->trans_color.gray*=0x0101; | |
1458 | + ping_trans_color.gray*=0x0101; | |
1459 | } | |
1460 | if (image_depth > QuantumDepth) | |
1461 | image_depth=QuantumDepth; | |
1462 | if (image_colors == 0 || image_colors-1 > MaxRGB) | |
1463 | image_colors=1 << image_depth; | |
1464 | if (image_depth > 8) | |
1465 | - ping_info->bit_depth=16; | |
1466 | + ping_bit_depth=16; | |
1467 | else | |
1468 | { | |
1469 | - if (ping_info->color_type == PNG_COLOR_TYPE_PALETTE) | |
1470 | + if (ping_colortype == PNG_COLOR_TYPE_PALETTE) | |
1471 | { | |
1472 | - ping_info->bit_depth=1; | |
1473 | - while ((int) (1 << ping_info->bit_depth) < | |
1474 | + ping_bit_depth=1; | |
1475 | + while ((int) (1 << ping_bit_depth) < | |
1476 | (long) image_colors) | |
1477 | - ping_info->bit_depth <<= 1; | |
1478 | + ping_bit_depth <<= 1; | |
1479 | } | |
1480 | - else if (mng_info->optimize && ping_info->color_type == | |
1481 | + else if (mng_info->optimize && ping_colortype == | |
1482 | PNG_COLOR_TYPE_GRAY && image_colors < 17 && | |
1483 | mng_info->IsPalette) | |
1484 | { | |
1485 | @@ -6779,11 +6847,11 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1486 | depth_1_ok=MagickFalse; | |
1487 | } | |
1488 | if (depth_1_ok) | |
1489 | - ping_info->bit_depth=1; | |
1490 | + ping_bit_depth=1; | |
1491 | else if (depth_2_ok) | |
1492 | - ping_info->bit_depth=2; | |
1493 | + ping_bit_depth=2; | |
1494 | else if (depth_4_ok) | |
1495 | - ping_info->bit_depth=4; | |
1496 | + ping_bit_depth=4; | |
1497 | } | |
1498 | } | |
1499 | } | |
1500 | @@ -6796,13 +6864,10 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1501 | number_colors; | |
1502 | ||
1503 | number_colors=image_colors; | |
1504 | - if (matte) | |
1505 | - ping_info->valid|=PNG_INFO_tRNS; | |
1506 | /* | |
1507 | Set image palette. | |
1508 | */ | |
1509 | - ping_info->color_type=PNG_COLOR_TYPE_PALETTE; | |
1510 | - ping_info->valid|=PNG_INFO_PLTE; | |
1511 | + ping_colortype=PNG_COLOR_TYPE_PALETTE; | |
1512 | if (mng_info->have_write_global_plte && !matte) | |
1513 | { | |
1514 | png_set_PLTE(ping,ping_info,NULL,0); | |
1515 | @@ -6847,14 +6912,12 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1516 | " Setting up PLTE chunk with %d colors", | |
1517 | (int) number_colors); | |
1518 | png_set_PLTE(ping,ping_info,palette,(int) number_colors); | |
1519 | -#if (PNG_LIBPNG_VER > 10008) | |
1520 | MagickFreeMemory(palette); | |
1521 | -#endif | |
1522 | } | |
1523 | - ping_info->bit_depth=1; | |
1524 | - while ((1UL << ping_info->bit_depth) < number_colors) | |
1525 | - ping_info->bit_depth <<= 1; | |
1526 | - ping_info->num_trans=0; | |
1527 | + ping_bit_depth=1; | |
1528 | + while ((1UL << ping_bit_depth) < number_colors) | |
1529 | + ping_bit_depth <<= 1; | |
1530 | + ping_num_trans=0; | |
1531 | if (matte) | |
1532 | { | |
1533 | int | |
1534 | @@ -6890,7 +6953,7 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1535 | if (trans_alpha[index] != (png_byte) (255- | |
1536 | ScaleQuantumToChar(p->opacity))) | |
1537 | { | |
1538 | - ping_info->color_type= | |
1539 | + ping_colortype= | |
1540 | PNG_COLOR_TYPE_RGB_ALPHA; | |
1541 | break; | |
1542 | } | |
1543 | @@ -6900,11 +6963,11 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1544 | } | |
1545 | p++; | |
1546 | } | |
1547 | - if (ping_info->color_type==PNG_COLOR_TYPE_RGB_ALPHA) | |
1548 | + if (ping_colortype==PNG_COLOR_TYPE_RGB_ALPHA) | |
1549 | { | |
1550 | - ping_info->num_trans=0; | |
1551 | - ping_info->valid&=(~PNG_INFO_tRNS); | |
1552 | - ping_info->valid&=(~PNG_INFO_PLTE); | |
1553 | + ping_num_trans=0; | |
1554 | + png_set_invalid(ping, ping_info, PNG_INFO_tRNS); | |
1555 | + png_set_invalid(ping, ping_info, PNG_INFO_PLTE); | |
1556 | mng_info->IsPalette=MagickFalse; | |
1557 | (void) SyncImage(image); | |
1558 | if (logging) | |
1559 | @@ -6916,40 +6979,41 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1560 | break; | |
1561 | } | |
1562 | } | |
1563 | - if ((ping_info->valid & PNG_INFO_tRNS)) | |
1564 | + if (png_get_valid(ping, ping_info, PNG_INFO_tRNS)) | |
1565 | { | |
1566 | for (i=0; i < (long) number_colors; i++) | |
1567 | { | |
1568 | if (trans_alpha[i] == 256) | |
1569 | trans_alpha[i]=255; | |
1570 | if (trans_alpha[i] != 255) | |
1571 | - ping_info->num_trans=(unsigned short) (i+1); | |
1572 | + ping_num_trans=(unsigned short) (i+1); | |
1573 | } | |
1574 | } | |
1575 | - if (ping_info->num_trans == 0) | |
1576 | - ping_info->valid&=(~PNG_INFO_tRNS); | |
1577 | - if (!(ping_info->valid & PNG_INFO_tRNS)) | |
1578 | - ping_info->num_trans=0; | |
1579 | - if (ping_info->num_trans != 0) | |
1580 | + if (ping_num_trans == 0) | |
1581 | + png_set_invalid(ping, ping_info, PNG_INFO_tRNS); | |
1582 | + if (!png_get_valid(ping, ping_info, PNG_INFO_tRNS)) | |
1583 | + ping_num_trans=0; | |
1584 | + | |
1585 | + if (ping_num_trans != 0) | |
1586 | { | |
1587 | - ping_info->trans_alpha=MagickAllocateMemory( | |
1588 | - unsigned char *, number_colors); | |
1589 | - if (ping_info->trans_alpha == (unsigned char *) NULL) | |
1590 | - ThrowWriterException(ResourceLimitError, | |
1591 | - MemoryAllocationFailed,image); | |
1592 | - for (i=0; i < (long) number_colors; i++) | |
1593 | - ping_info->trans_alpha[i]=(png_byte) trans_alpha[i]; | |
1594 | + for (i=0; i<256; i++) | |
1595 | + ping_trans_alpha[i]=(png_byte) trans_alpha[i]; | |
1596 | } | |
1597 | + | |
1598 | + (void) png_set_tRNS(ping, ping_info, | |
1599 | + ping_trans_alpha, | |
1600 | + ping_num_trans, | |
1601 | + &ping_trans_color); | |
1602 | } | |
1603 | ||
1604 | /* | |
1605 | Identify which colormap entry is the background color. | |
1606 | */ | |
1607 | for (i=0; i < (long) Max(number_colors-1,1); i++) | |
1608 | - if (RGBColorMatchExact(ping_info->background, | |
1609 | + if (RGBColorMatchExact(ping_background, | |
1610 | image->colormap[i])) | |
1611 | break; | |
1612 | - ping_info->background.index=(png_uint_16) i; | |
1613 | + ping_background.index=(png_uint_16) i; | |
1614 | } | |
1615 | } | |
1616 | else | |
1617 | @@ -6958,10 +7022,10 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1618 | image_depth=8; | |
1619 | if ((save_image_depth == 16) && (image_depth == 8)) | |
1620 | { | |
1621 | - ping_info->trans_color.red*=0x0101; | |
1622 | - ping_info->trans_color.green*=0x0101; | |
1623 | - ping_info->trans_color.blue*=0x0101; | |
1624 | - ping_info->trans_color.gray*=0x0101; | |
1625 | + ping_trans_color.red*=0x0101; | |
1626 | + ping_trans_color.green*=0x0101; | |
1627 | + ping_trans_color.blue*=0x0101; | |
1628 | + ping_trans_color.gray*=0x0101; | |
1629 | } | |
1630 | } | |
1631 | ||
1632 | @@ -6969,7 +7033,7 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1633 | Adjust background and transparency samples in sub-8-bit | |
1634 | grayscale files. | |
1635 | */ | |
1636 | - if (ping_info->bit_depth < 8 && ping_info->color_type == | |
1637 | + if (ping_bit_depth < 8 && ping_colortype == | |
1638 | PNG_COLOR_TYPE_GRAY) | |
1639 | { | |
1640 | png_uint_16 | |
1641 | @@ -6978,7 +7042,7 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1642 | png_color_16 | |
1643 | background; | |
1644 | ||
1645 | - maxval=(1 << ping_info->bit_depth)-1; | |
1646 | + maxval=(1 << ping_bit_depth)-1; | |
1647 | ||
1648 | ||
1649 | background.gray=(png_uint_16) | |
1650 | @@ -6989,28 +7053,26 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1651 | " Setting up bKGD chunk"); | |
1652 | png_set_bKGD(ping,ping_info,&background); | |
1653 | ||
1654 | - ping_info->trans_color.gray=(png_uint_16)(maxval* | |
1655 | - ping_info->trans_color.gray/ | |
1656 | - MaxRGB); | |
1657 | + ping_trans_color.gray=(png_uint_16)(maxval* | |
1658 | + ping_trans_color.gray/ | |
1659 | + MaxRGB); | |
1660 | } | |
1661 | } | |
1662 | if (logging) | |
1663 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1664 | " PNG color type: %s (%d)", | |
1665 | - PngColorTypeToString(ping_info->color_type), | |
1666 | - ping_info->color_type); | |
1667 | + PngColorTypeToString(ping_colortype), | |
1668 | + ping_colortype); | |
1669 | /* | |
1670 | Initialize compression level and filtering. | |
1671 | */ | |
1672 | if (logging) | |
1673 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1674 | " Setting up deflate compression"); | |
1675 | -#if (PNG_LIBPNG_VER > 99) | |
1676 | if (logging) | |
1677 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1678 | " Compression buffer size: 32768"); | |
1679 | png_set_compression_buffer_size(ping,32768L); | |
1680 | -#endif | |
1681 | if (logging) | |
1682 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1683 | " Compression mem level: 9"); | |
1684 | @@ -7044,7 +7106,7 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1685 | if (logging) | |
1686 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1687 | " Filter_type: PNG_INTRAPIXEL_DIFFERENCING"); | |
1688 | - ping_info->filter_type=PNG_INTRAPIXEL_DIFFERENCING; | |
1689 | + ping_filter_method=PNG_INTRAPIXEL_DIFFERENCING; | |
1690 | } | |
1691 | else | |
1692 | if (logging) | |
1693 | @@ -7061,8 +7123,8 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1694 | if ((image_info->quality % 10) != 5) | |
1695 | base_filter=(int) image_info->quality % 10; | |
1696 | else | |
1697 | - if ((ping_info->color_type == PNG_COLOR_TYPE_GRAY) || | |
1698 | - (ping_info->color_type == PNG_COLOR_TYPE_PALETTE) || | |
1699 | + if ((ping_colortype == PNG_COLOR_TYPE_GRAY) || | |
1700 | + (ping_colortype == PNG_COLOR_TYPE_PALETTE) || | |
1701 | (image_info->quality < 50)) | |
1702 | base_filter=PNG_NO_FILTERS; | |
1703 | else | |
1704 | @@ -7099,7 +7161,7 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1705 | { | |
1706 | if (LocaleCompare(profile_name,"ICM") == 0) | |
1707 | { | |
1708 | -#if (PNG_LIBPNG_VER > 10008) && defined(PNG_WRITE_iCCP_SUPPORTED) | |
1709 | +#if defined(PNG_WRITE_iCCP_SUPPORTED) | |
1710 | { | |
1711 | if (logging) | |
1712 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1713 | @@ -7170,8 +7232,8 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1714 | (void) png_set_sRGB(ping,ping_info,PerceptualIntent); | |
1715 | png_set_gAMA(ping,ping_info,0.45455); | |
1716 | } | |
1717 | - not_valid=(!ping_info->valid); | |
1718 | - if ((!mng_info->write_mng) || not_valid & PNG_INFO_sRGB) | |
1719 | + if ((!mng_info->write_mng) || | |
1720 | + !png_get_valid(ping, ping_info, PNG_INFO_sRGB)) | |
1721 | #endif | |
1722 | { | |
1723 | if (!mng_info->have_write_global_gama && (image->gamma != 0.0)) | |
1724 | @@ -7210,7 +7272,7 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1725 | bp.x,bp.y); | |
1726 | } | |
1727 | } | |
1728 | - ping_info->interlace_type=(image_info->interlace == LineInterlace); | |
1729 | + ping_interlace_method=(image_info->interlace == LineInterlace); | |
1730 | ||
1731 | if (mng_info->write_mng) | |
1732 | png_set_sig_bytes(ping,8); | |
1733 | @@ -7219,6 +7281,15 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1734 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1735 | " Writing PNG header chunks"); | |
1736 | ||
1737 | + png_set_IHDR(ping,ping_info, | |
1738 | + ping_width, | |
1739 | + ping_height, | |
1740 | + ping_bit_depth, | |
1741 | + ping_colortype, | |
1742 | + ping_interlace_method, | |
1743 | + ping_compression_method, | |
1744 | + ping_filter_method); | |
1745 | + | |
1746 | png_write_info(ping,ping_info); | |
1747 | ||
1748 | #if (PNG_LIBPNG_VER == 10206) | |
1749 | @@ -7313,7 +7384,7 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1750 | { | |
1751 | if ((!mng_info->write_png8 && !mng_info->write_png24 && | |
1752 | !mng_info->write_png32) && | |
1753 | - (!image_matte || (ping_info->bit_depth >= QuantumDepth)) && | |
1754 | + (!image_matte || (ping_bit_depth >= QuantumDepth)) && | |
1755 | (mng_info->optimize || mng_info->IsPalette) && | |
1756 | IsGrayImage(image,&image->exception)) | |
1757 | { | |
1758 | @@ -7325,7 +7396,7 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1759 | if (!AcquireImagePixels(image,0,y,image->columns,1, | |
1760 | &image->exception)) | |
1761 | break; | |
1762 | - if (ping_info->color_type == PNG_COLOR_TYPE_GRAY) | |
1763 | + if (ping_colortype == PNG_COLOR_TYPE_GRAY) | |
1764 | { | |
1765 | if (mng_info->IsPalette) | |
1766 | (void) ExportImagePixelArea(image, | |
1767 | @@ -7368,14 +7439,14 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1768 | " pass %d, Image Is RGB," | |
1769 | " PNG colortype is %s (%d)",pass, | |
1770 | PngColorTypeToString( | |
1771 | - ping_info->color_type), | |
1772 | - ping_info->color_type); | |
1773 | + ping_colortype), | |
1774 | + ping_colortype); | |
1775 | for (y=0; y < (long) image->rows; y++) | |
1776 | { | |
1777 | if (!AcquireImagePixels(image,0,y,image->columns,1, | |
1778 | &image->exception)) | |
1779 | break; | |
1780 | - if (ping_info->color_type == PNG_COLOR_TYPE_GRAY) | |
1781 | + if (ping_colortype == PNG_COLOR_TYPE_GRAY) | |
1782 | { | |
1783 | if (image->storage_class == DirectClass) | |
1784 | (void) ExportImagePixelArea(image,(QuantumType) | |
1785 | @@ -7388,7 +7459,7 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1786 | quantum_size, | |
1787 | png_pixels,0,0); | |
1788 | } | |
1789 | - else if (ping_info->color_type == | |
1790 | + else if (ping_colortype == | |
1791 | PNG_COLOR_TYPE_GRAY_ALPHA) | |
1792 | (void) ExportImagePixelArea(image,(QuantumType) | |
1793 | GrayAlphaQuantum, | |
1794 | @@ -7433,12 +7504,12 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1795 | if (!AcquireImagePixels(image,0,y,image->columns,1, | |
1796 | &image->exception)) | |
1797 | break; | |
1798 | - if (ping_info->color_type == PNG_COLOR_TYPE_GRAY) | |
1799 | + if (ping_colortype == PNG_COLOR_TYPE_GRAY) | |
1800 | (void) ExportImagePixelArea(image,(QuantumType) | |
1801 | GrayQuantum, | |
1802 | quantum_size, | |
1803 | png_pixels,0,0); | |
1804 | - else if (ping_info->color_type == | |
1805 | + else if (ping_colortype == | |
1806 | PNG_COLOR_TYPE_GRAY_ALPHA) | |
1807 | (void) ExportImagePixelArea(image,(QuantumType) | |
1808 | GrayAlphaQuantum, | |
1809 | @@ -7471,38 +7542,32 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1810 | " Writing PNG image data"); | |
1811 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1812 | " Width: %lu", | |
1813 | - (unsigned long)ping_info->width); | |
1814 | + (unsigned long)ping_width); | |
1815 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1816 | " Height: %lu", | |
1817 | - (unsigned long)ping_info->height); | |
1818 | + (unsigned long)ping_height); | |
1819 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1820 | - " PNG sample depth: %d",ping_info->bit_depth); | |
1821 | + " PNG sample depth: %d",ping_bit_depth); | |
1822 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1823 | " PNG color type: %s (%d)", | |
1824 | - PngColorTypeToString(ping_info->color_type), | |
1825 | - ping_info->color_type); | |
1826 | + PngColorTypeToString(ping_colortype), | |
1827 | + ping_colortype); | |
1828 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1829 | " PNG Interlace method: %d", | |
1830 | - ping_info->interlace_type); | |
1831 | + ping_interlace_method); | |
1832 | } | |
1833 | /* | |
1834 | Generate text chunks. | |
1835 | */ | |
1836 | -#if (PNG_LIBPNG_VER <= 10005) | |
1837 | - ping_info->num_text=0; | |
1838 | -#endif | |
1839 | attribute=GetImageAttribute(image,(char *) NULL); | |
1840 | for ( ; attribute != (const ImageAttribute *) NULL; | |
1841 | attribute=attribute->next) | |
1842 | { | |
1843 | -#if (PNG_LIBPNG_VER > 10005) | |
1844 | png_textp | |
1845 | text; | |
1846 | -#endif | |
1847 | ||
1848 | if (*attribute->key == '[') | |
1849 | continue; | |
1850 | -#if (PNG_LIBPNG_VER > 10005) | |
1851 | text=(png_textp) png_malloc(ping,(png_uint_32) sizeof(png_text)); | |
1852 | text[0].key=attribute->key; | |
1853 | text[0].text=attribute->value; | |
1854 | @@ -7519,40 +7584,6 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1855 | } | |
1856 | png_set_text(ping,ping_info,text,1); | |
1857 | png_free(ping,text); | |
1858 | -#else | |
1859 | - /* Work directly with ping_info struct; | |
1860 | - * png_set_text before libpng version | |
1861 | - * 1.0.5a is leaky */ | |
1862 | - if (ping_info->num_text == 0) | |
1863 | - { | |
1864 | - ping_info->text=MagickAllocateMemory(png_text *, | |
1865 | - 256*sizeof(png_text)); | |
1866 | - if (ping_info->text == (png_text *) NULL) | |
1867 | - (void) ThrowException(&image->exception,(ExceptionType) | |
1868 | - ResourceLimitError,MemoryAllocationFailed, | |
1869 | - image->filename); | |
1870 | - } | |
1871 | - i=ping_info->num_text++; | |
1872 | - if (i > 255) | |
1873 | - (void) ThrowException(&image->exception,(ExceptionType) | |
1874 | - ResourceLimitError, | |
1875 | - "Cannot write more than 256 PNG text chunks", | |
1876 | - image->filename); | |
1877 | - ping_info->text[i].key=attribute->key; | |
1878 | - ping_info->text[i].text=attribute->value; | |
1879 | - ping_info->text[i].text_length=strlen(attribute->value); | |
1880 | - ping_info->text[i].compression= | |
1881 | - image_info->compression == NoCompression || | |
1882 | - (image_info->compression == UndefinedCompression && | |
1883 | - ping_info->text[i].text_length < 128) ? -1 : 0; | |
1884 | - if (logging) | |
1885 | - { | |
1886 | - (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1887 | - " Setting up text chunk"); | |
1888 | - (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1889 | - " keyword: %s",ping_info->text[i].key); | |
1890 | - } | |
1891 | -#endif | |
1892 | } | |
1893 | if (logging) | |
1894 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), | |
1895 | @@ -7560,9 +7591,9 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1896 | png_write_end(ping,ping_info); | |
1897 | if (mng_info->need_fram && (int) image->dispose == BackgroundDispose) | |
1898 | { | |
1899 | - if (mng_info->page.x || mng_info->page.y || (ping_info->width != | |
1900 | + if (mng_info->page.x || mng_info->page.y || (ping_width != | |
1901 | mng_info->page.width) || | |
1902 | - (ping_info->height != mng_info->page.height)) | |
1903 | + (ping_height != mng_info->page.height)) | |
1904 | { | |
1905 | unsigned char | |
1906 | chunk[32]; | |
1907 | @@ -7583,10 +7614,10 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1908 | chunk[14]=0; /* clipping boundaries delta type */ | |
1909 | PNGLong(chunk+15,(png_uint_32) (mng_info->page.x)); /* left cb */ | |
1910 | PNGLong(chunk+19,(png_uint_32) (mng_info->page.x + | |
1911 | - ping_info->width)); | |
1912 | + ping_width)); | |
1913 | PNGLong(chunk+23,(png_uint_32) (mng_info->page.y)); /* top cb */ | |
1914 | PNGLong(chunk+27,(png_uint_32) (mng_info->page.y + | |
1915 | - ping_info->height)); | |
1916 | + ping_height)); | |
1917 | (void) WriteBlob(image,31,(char *) chunk); | |
1918 | (void) WriteBlobMSBULong(image,crc32(0,chunk,31)); | |
1919 | mng_info->old_framing_mode=4; | |
1920 | @@ -7605,7 +7636,7 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1921 | ||
1922 | /* Save depth actually written */ | |
1923 | ||
1924 | - s[0]=(char) ping_info->bit_depth; | |
1925 | + s[0]=(char) ping_bit_depth; | |
1926 | s[1]='\0'; | |
1927 | ||
1928 | (void) SetImageAttribute(image,"[png:bit-depth-written]",s); | |
1929 | @@ -7613,18 +7644,6 @@ static MagickPassFail WriteOnePNGImage(MngInfo *mng_in | |
1930 | /* | |
1931 | Free PNG resources. | |
1932 | */ | |
1933 | -#if (PNG_LIBPNG_VER < 10007) | |
1934 | - if (ping_info->valid & PNG_INFO_PLTE) | |
1935 | - { | |
1936 | - MagickFreeMemory(ping_info->palette); | |
1937 | - ping_info->valid&=(~PNG_INFO_PLTE); | |
1938 | - } | |
1939 | -#endif | |
1940 | - if (ping_info->valid & PNG_INFO_tRNS) | |
1941 | - { | |
1942 | - MagickFreeMemory(ping_info->trans_alpha); | |
1943 | - ping_info->valid&=(~PNG_INFO_tRNS); | |
1944 | - } | |
1945 | png_destroy_write_struct(&ping,&ping_info); | |
1946 | ||
1947 | MagickFreeMemory(png_pixels); | |
1948 | @@ -8365,23 +8384,12 @@ static unsigned int WriteMNGImage(const ImageInfo *ima | |
1949 | final_delay=0, | |
1950 | initial_delay; | |
1951 | ||
1952 | -#if (PNG_LIBPNG_VER < 10007) | |
1953 | +#if (PNG_LIBPNG_VER < 10200) | |
1954 | if (image_info->verbose) | |
1955 | printf("Your PNG library (libpng-%s) is rather old.\n", | |
1956 | PNG_LIBPNG_VER_STRING); | |
1957 | #endif | |
1958 | ||
1959 | -#if (PNG_LIBPNG_VER >= 10400) | |
1960 | -# ifndef PNG_TRANSFORM_GRAY_TO_RGB /* Added at libpng-1.4.0beta67 */ | |
1961 | - if (image_info->verbose) | |
1962 | - { | |
1963 | - printf("Your PNG library (libpng-%s) is an old beta version.\n", | |
1964 | - PNG_LIBPNG_VER_STRING); | |
1965 | - printf("Please update it.\n"); | |
1966 | - } | |
1967 | -# endif | |
1968 | -#endif | |
1969 | - | |
1970 | /* | |
1971 | Open image file. | |
1972 | */ | |
1973 | @@ -9196,7 +9204,7 @@ static unsigned int WriteMNGImage(const ImageInfo *ima | |
1974 | (void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit WriteMNGImage()"); | |
1975 | return(MagickPass); | |
1976 | } | |
1977 | -#else /* PNG_LIBPNG_VER > 95 */ | |
1978 | +#else /* PNG_LIBPNG_VER > 10011 */ | |
1979 | static unsigned int WritePNGImage(const ImageInfo *image_info,Image *image) | |
1980 | { | |
1981 | image=image; | |
1982 | @@ -9208,5 +9216,5 @@ static unsigned int WriteMNGImage(const ImageInfo *ima | |
1983 | { | |
1984 | return (WritePNGImage(image_info,image)); | |
1985 | } | |
1986 | -#endif /* PNG_LIBPNG_VER > 95 */ | |
1987 | +#endif /* PNG_LIBPNG_VER > 10011 */ | |
1988 | #endif |