/[pcsx2_0.9.7]/trunk/3rdparty/wxWidgets/src/png/pngset.c
ViewVC logotype

Annotation of /trunk/3rdparty/wxWidgets/src/png/pngset.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (hide annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (10 years, 4 months ago) by william
File MIME type: text/plain
File size: 39328 byte(s)
committing r3113 initial commit again...
1 william 31
2     /* pngset.c - storage of image information into info struct
3     *
4     * Last changed in libpng 1.2.39 [August 13, 2009]
5     * Copyright (c) 1998-2009 Glenn Randers-Pehrson
6     * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7     * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8     *
9     * This code is released under the libpng license.
10     * For conditions of distribution and use, see the disclaimer
11     * and license in png.h
12     *
13     * The functions here are used during reads to store data from the file
14     * into the info struct, and during writes to store application data
15     * into the info struct for writing into the file. This abstracts the
16     * info struct and allows us to change the structure in the future.
17     */
18    
19     #define PNG_INTERNAL
20     #include "png.h"
21     #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
22    
23     #if defined(PNG_bKGD_SUPPORTED)
24     void PNGAPI
25     png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
26     {
27     png_debug1(1, "in %s storage function", "bKGD");
28     if (png_ptr == NULL || info_ptr == NULL)
29     return;
30    
31     png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
32     info_ptr->valid |= PNG_INFO_bKGD;
33     }
34     #endif
35    
36     #if defined(PNG_cHRM_SUPPORTED)
37     #ifdef PNG_FLOATING_POINT_SUPPORTED
38     void PNGAPI
39     png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
40     double white_x, double white_y, double red_x, double red_y,
41     double green_x, double green_y, double blue_x, double blue_y)
42     {
43     png_debug1(1, "in %s storage function", "cHRM");
44     if (png_ptr == NULL || info_ptr == NULL)
45     return;
46    
47     info_ptr->x_white = (float)white_x;
48     info_ptr->y_white = (float)white_y;
49     info_ptr->x_red = (float)red_x;
50     info_ptr->y_red = (float)red_y;
51     info_ptr->x_green = (float)green_x;
52     info_ptr->y_green = (float)green_y;
53     info_ptr->x_blue = (float)blue_x;
54     info_ptr->y_blue = (float)blue_y;
55     #ifdef PNG_FIXED_POINT_SUPPORTED
56     info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
57     info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
58     info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
59     info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
60     info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
61     info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
62     info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
63     info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
64     #endif
65     info_ptr->valid |= PNG_INFO_cHRM;
66     }
67     #endif /* PNG_FLOATING_POINT_SUPPORTED */
68    
69     #ifdef PNG_FIXED_POINT_SUPPORTED
70     void PNGAPI
71     png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
72     png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
73     png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
74     png_fixed_point blue_x, png_fixed_point blue_y)
75     {
76     png_debug1(1, "in %s storage function", "cHRM fixed");
77     if (png_ptr == NULL || info_ptr == NULL)
78     return;
79    
80     #if !defined(PNG_NO_CHECK_cHRM)
81     if (png_check_cHRM_fixed(png_ptr,
82     white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
83     #endif
84     {
85     info_ptr->int_x_white = white_x;
86     info_ptr->int_y_white = white_y;
87     info_ptr->int_x_red = red_x;
88     info_ptr->int_y_red = red_y;
89     info_ptr->int_x_green = green_x;
90     info_ptr->int_y_green = green_y;
91     info_ptr->int_x_blue = blue_x;
92     info_ptr->int_y_blue = blue_y;
93     #ifdef PNG_FLOATING_POINT_SUPPORTED
94     info_ptr->x_white = (float)(white_x/100000.);
95     info_ptr->y_white = (float)(white_y/100000.);
96     info_ptr->x_red = (float)( red_x/100000.);
97     info_ptr->y_red = (float)( red_y/100000.);
98     info_ptr->x_green = (float)(green_x/100000.);
99     info_ptr->y_green = (float)(green_y/100000.);
100     info_ptr->x_blue = (float)( blue_x/100000.);
101     info_ptr->y_blue = (float)( blue_y/100000.);
102     #endif
103     info_ptr->valid |= PNG_INFO_cHRM;
104     }
105     }
106     #endif /* PNG_FIXED_POINT_SUPPORTED */
107     #endif /* PNG_cHRM_SUPPORTED */
108    
109     #if defined(PNG_gAMA_SUPPORTED)
110     #ifdef PNG_FLOATING_POINT_SUPPORTED
111     void PNGAPI
112     png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
113     {
114     double png_gamma;
115     png_debug1(1, "in %s storage function", "gAMA");
116     if (png_ptr == NULL || info_ptr == NULL)
117     return;
118    
119     /* Check for overflow */
120     if (file_gamma > 21474.83)
121     {
122     png_warning(png_ptr, "Limiting gamma to 21474.83");
123     png_gamma=21474.83;
124     }
125     else
126     png_gamma = file_gamma;
127     info_ptr->gamma = (float)png_gamma;
128     #ifdef PNG_FIXED_POINT_SUPPORTED
129     info_ptr->int_gamma = (int)(png_gamma*100000.+.5);
130     #endif
131     info_ptr->valid |= PNG_INFO_gAMA;
132     if (png_gamma == 0.0)
133     png_warning(png_ptr, "Setting gamma=0");
134     }
135     #endif
136     void PNGAPI
137     png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
138     int_gamma)
139     {
140     png_fixed_point png_gamma;
141    
142     png_debug1(1, "in %s storage function", "gAMA");
143     if (png_ptr == NULL || info_ptr == NULL)
144     return;
145    
146     if (int_gamma > (png_fixed_point)PNG_UINT_31_MAX)
147     {
148     png_warning(png_ptr, "Limiting gamma to 21474.83");
149     png_gamma=PNG_UINT_31_MAX;
150     }
151     else
152     {
153     if (int_gamma < 0)
154     {
155     png_warning(png_ptr, "Setting negative gamma to zero");
156     png_gamma = 0;
157     }
158     else
159     png_gamma = int_gamma;
160     }
161     #ifdef PNG_FLOATING_POINT_SUPPORTED
162     info_ptr->gamma = (float)(png_gamma/100000.);
163     #endif
164     #ifdef PNG_FIXED_POINT_SUPPORTED
165     info_ptr->int_gamma = png_gamma;
166     #endif
167     info_ptr->valid |= PNG_INFO_gAMA;
168     if (png_gamma == 0)
169     png_warning(png_ptr, "Setting gamma=0");
170     }
171     #endif
172    
173     #if defined(PNG_hIST_SUPPORTED)
174     void PNGAPI
175     png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
176     {
177     int i;
178    
179     png_debug1(1, "in %s storage function", "hIST");
180     if (png_ptr == NULL || info_ptr == NULL)
181     return;
182     if (info_ptr->num_palette == 0 || info_ptr->num_palette
183     > PNG_MAX_PALETTE_LENGTH)
184     {
185     png_warning(png_ptr,
186     "Invalid palette size, hIST allocation skipped.");
187     return;
188     }
189    
190     #ifdef PNG_FREE_ME_SUPPORTED
191     png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
192     #endif
193     /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in
194     * version 1.2.1
195     */
196     png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
197     (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16)));
198     if (png_ptr->hist == NULL)
199     {
200     png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
201     return;
202     }
203    
204     for (i = 0; i < info_ptr->num_palette; i++)
205     png_ptr->hist[i] = hist[i];
206     info_ptr->hist = png_ptr->hist;
207     info_ptr->valid |= PNG_INFO_hIST;
208    
209     #ifdef PNG_FREE_ME_SUPPORTED
210     info_ptr->free_me |= PNG_FREE_HIST;
211     #else
212     png_ptr->flags |= PNG_FLAG_FREE_HIST;
213     #endif
214     }
215     #endif
216    
217     void PNGAPI
218     png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
219     png_uint_32 width, png_uint_32 height, int bit_depth,
220     int color_type, int interlace_type, int compression_type,
221     int filter_type)
222     {
223     png_debug1(1, "in %s storage function", "IHDR");
224     if (png_ptr == NULL || info_ptr == NULL)
225     return;
226    
227     /* Check for width and height valid values */
228     if (width == 0 || height == 0)
229     png_error(png_ptr, "Image width or height is zero in IHDR");
230     #ifdef PNG_SET_USER_LIMITS_SUPPORTED
231     if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
232     png_error(png_ptr, "image size exceeds user limits in IHDR");
233     #else
234     if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
235     png_error(png_ptr, "image size exceeds user limits in IHDR");
236     #endif
237     if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
238     png_error(png_ptr, "Invalid image size in IHDR");
239     if ( width > (PNG_UINT_32_MAX
240     >> 3) /* 8-byte RGBA pixels */
241     - 64 /* bigrowbuf hack */
242     - 1 /* filter byte */
243     - 7*8 /* rounding of width to multiple of 8 pixels */
244     - 8) /* extra max_pixel_depth pad */
245     png_warning(png_ptr, "Width is too large for libpng to process pixels");
246    
247     /* Check other values */
248     if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
249     bit_depth != 8 && bit_depth != 16)
250     png_error(png_ptr, "Invalid bit depth in IHDR");
251    
252     if (color_type < 0 || color_type == 1 ||
253     color_type == 5 || color_type > 6)
254     png_error(png_ptr, "Invalid color type in IHDR");
255    
256     if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
257     ((color_type == PNG_COLOR_TYPE_RGB ||
258     color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
259     color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
260     png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
261    
262     if (interlace_type >= PNG_INTERLACE_LAST)
263     png_error(png_ptr, "Unknown interlace method in IHDR");
264    
265     if (compression_type != PNG_COMPRESSION_TYPE_BASE)
266     png_error(png_ptr, "Unknown compression method in IHDR");
267    
268     #if defined(PNG_MNG_FEATURES_SUPPORTED)
269     /* Accept filter_method 64 (intrapixel differencing) only if
270     * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
271     * 2. Libpng did not read a PNG signature (this filter_method is only
272     * used in PNG datastreams that are embedded in MNG datastreams) and
273     * 3. The application called png_permit_mng_features with a mask that
274     * included PNG_FLAG_MNG_FILTER_64 and
275     * 4. The filter_method is 64 and
276     * 5. The color_type is RGB or RGBA
277     */
278     if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
279     png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
280     if (filter_type != PNG_FILTER_TYPE_BASE)
281     {
282     if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
283     (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
284     ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
285     (color_type == PNG_COLOR_TYPE_RGB ||
286     color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
287     png_error(png_ptr, "Unknown filter method in IHDR");
288     if (png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
289     png_warning(png_ptr, "Invalid filter method in IHDR");
290     }
291     #else
292     if (filter_type != PNG_FILTER_TYPE_BASE)
293     png_error(png_ptr, "Unknown filter method in IHDR");
294     #endif
295    
296     info_ptr->width = width;
297     info_ptr->height = height;
298     info_ptr->bit_depth = (png_byte)bit_depth;
299     info_ptr->color_type =(png_byte) color_type;
300     info_ptr->compression_type = (png_byte)compression_type;
301     info_ptr->filter_type = (png_byte)filter_type;
302     info_ptr->interlace_type = (png_byte)interlace_type;
303     if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
304     info_ptr->channels = 1;
305     else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
306     info_ptr->channels = 3;
307     else
308     info_ptr->channels = 1;
309     if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
310     info_ptr->channels++;
311     info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
312    
313     /* Check for potential overflow */
314     if (width > (PNG_UINT_32_MAX
315     >> 3) /* 8-byte RGBA pixels */
316     - 64 /* bigrowbuf hack */
317     - 1 /* filter byte */
318     - 7*8 /* rounding of width to multiple of 8 pixels */
319     - 8) /* extra max_pixel_depth pad */
320     info_ptr->rowbytes = (png_size_t)0;
321     else
322     info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
323     }
324    
325     #if defined(PNG_oFFs_SUPPORTED)
326     void PNGAPI
327     png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
328     png_int_32 offset_x, png_int_32 offset_y, int unit_type)
329     {
330     png_debug1(1, "in %s storage function", "oFFs");
331     if (png_ptr == NULL || info_ptr == NULL)
332     return;
333    
334     info_ptr->x_offset = offset_x;
335     info_ptr->y_offset = offset_y;
336     info_ptr->offset_unit_type = (png_byte)unit_type;
337     info_ptr->valid |= PNG_INFO_oFFs;
338     }
339     #endif
340    
341     #if defined(PNG_pCAL_SUPPORTED)
342     void PNGAPI
343     png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
344     png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
345     png_charp units, png_charpp params)
346     {
347     png_uint_32 length;
348     int i;
349    
350     png_debug1(1, "in %s storage function", "pCAL");
351     if (png_ptr == NULL || info_ptr == NULL)
352     return;
353    
354     length = png_strlen(purpose) + 1;
355     png_debug1(3, "allocating purpose for info (%lu bytes)",
356     (unsigned long)length);
357     info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
358     if (info_ptr->pcal_purpose == NULL)
359     {
360     png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
361     return;
362     }
363     png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
364    
365     png_debug(3, "storing X0, X1, type, and nparams in info");
366     info_ptr->pcal_X0 = X0;
367     info_ptr->pcal_X1 = X1;
368     info_ptr->pcal_type = (png_byte)type;
369     info_ptr->pcal_nparams = (png_byte)nparams;
370    
371     length = png_strlen(units) + 1;
372     png_debug1(3, "allocating units for info (%lu bytes)",
373     (unsigned long)length);
374     info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
375     if (info_ptr->pcal_units == NULL)
376     {
377     png_warning(png_ptr, "Insufficient memory for pCAL units.");
378     return;
379     }
380     png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
381    
382     info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
383     (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
384     if (info_ptr->pcal_params == NULL)
385     {
386     png_warning(png_ptr, "Insufficient memory for pCAL params.");
387     return;
388     }
389    
390     png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp));
391    
392     for (i = 0; i < nparams; i++)
393     {
394     length = png_strlen(params[i]) + 1;
395     png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
396     (unsigned long)length);
397     info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
398     if (info_ptr->pcal_params[i] == NULL)
399     {
400     png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
401     return;
402     }
403     png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
404     }
405    
406     info_ptr->valid |= PNG_INFO_pCAL;
407     #ifdef PNG_FREE_ME_SUPPORTED
408     info_ptr->free_me |= PNG_FREE_PCAL;
409     #endif
410     }
411     #endif
412    
413     #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
414     #ifdef PNG_FLOATING_POINT_SUPPORTED
415     void PNGAPI
416     png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
417     int unit, double width, double height)
418     {
419     png_debug1(1, "in %s storage function", "sCAL");
420     if (png_ptr == NULL || info_ptr == NULL)
421     return;
422    
423     info_ptr->scal_unit = (png_byte)unit;
424     info_ptr->scal_pixel_width = width;
425     info_ptr->scal_pixel_height = height;
426    
427     info_ptr->valid |= PNG_INFO_sCAL;
428     }
429     #else
430     #ifdef PNG_FIXED_POINT_SUPPORTED
431     void PNGAPI
432     png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
433     int unit, png_charp swidth, png_charp sheight)
434     {
435     png_uint_32 length;
436    
437     png_debug1(1, "in %s storage function", "sCAL");
438     if (png_ptr == NULL || info_ptr == NULL)
439     return;
440    
441     info_ptr->scal_unit = (png_byte)unit;
442    
443     length = png_strlen(swidth) + 1;
444     png_debug1(3, "allocating unit for info (%u bytes)",
445     (unsigned int)length);
446     info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
447     if (info_ptr->scal_s_width == NULL)
448     {
449     png_warning(png_ptr,
450     "Memory allocation failed while processing sCAL.");
451     return;
452     }
453     png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
454    
455     length = png_strlen(sheight) + 1;
456     png_debug1(3, "allocating unit for info (%u bytes)",
457     (unsigned int)length);
458     info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
459     if (info_ptr->scal_s_height == NULL)
460     {
461     png_free (png_ptr, info_ptr->scal_s_width);
462     info_ptr->scal_s_width = NULL;
463     png_warning(png_ptr,
464     "Memory allocation failed while processing sCAL.");
465     return;
466     }
467     png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
468     info_ptr->valid |= PNG_INFO_sCAL;
469     #ifdef PNG_FREE_ME_SUPPORTED
470     info_ptr->free_me |= PNG_FREE_SCAL;
471     #endif
472     }
473     #endif
474     #endif
475     #endif
476    
477     #if defined(PNG_pHYs_SUPPORTED)
478     void PNGAPI
479     png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
480     png_uint_32 res_x, png_uint_32 res_y, int unit_type)
481     {
482     png_debug1(1, "in %s storage function", "pHYs");
483     if (png_ptr == NULL || info_ptr == NULL)
484     return;
485    
486     info_ptr->x_pixels_per_unit = res_x;
487     info_ptr->y_pixels_per_unit = res_y;
488     info_ptr->phys_unit_type = (png_byte)unit_type;
489     info_ptr->valid |= PNG_INFO_pHYs;
490     }
491     #endif
492    
493     void PNGAPI
494     png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
495     png_colorp palette, int num_palette)
496     {
497    
498     png_debug1(1, "in %s storage function", "PLTE");
499     if (png_ptr == NULL || info_ptr == NULL)
500     return;
501    
502     if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
503     {
504     if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
505     png_error(png_ptr, "Invalid palette length");
506     else
507     {
508     png_warning(png_ptr, "Invalid palette length");
509     return;
510     }
511     }
512    
513     /*
514     * It may not actually be necessary to set png_ptr->palette here;
515     * we do it for backward compatibility with the way the png_handle_tRNS
516     * function used to do the allocation.
517     */
518     #ifdef PNG_FREE_ME_SUPPORTED
519     png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
520     #endif
521    
522     /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
523     * of num_palette entries, in case of an invalid PNG file that has
524     * too-large sample values.
525     */
526     png_ptr->palette = (png_colorp)png_malloc(png_ptr,
527     PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
528     png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
529     png_sizeof(png_color));
530     png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
531     info_ptr->palette = png_ptr->palette;
532     info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
533    
534     #ifdef PNG_FREE_ME_SUPPORTED
535     info_ptr->free_me |= PNG_FREE_PLTE;
536     #else
537     png_ptr->flags |= PNG_FLAG_FREE_PLTE;
538     #endif
539    
540     info_ptr->valid |= PNG_INFO_PLTE;
541     }
542    
543     #if defined(PNG_sBIT_SUPPORTED)
544     void PNGAPI
545     png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
546     png_color_8p sig_bit)
547     {
548     png_debug1(1, "in %s storage function", "sBIT");
549     if (png_ptr == NULL || info_ptr == NULL)
550     return;
551    
552     png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8));
553     info_ptr->valid |= PNG_INFO_sBIT;
554     }
555     #endif
556    
557     #if defined(PNG_sRGB_SUPPORTED)
558     void PNGAPI
559     png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
560     {
561     png_debug1(1, "in %s storage function", "sRGB");
562     if (png_ptr == NULL || info_ptr == NULL)
563     return;
564    
565     info_ptr->srgb_intent = (png_byte)intent;
566     info_ptr->valid |= PNG_INFO_sRGB;
567     }
568    
569     void PNGAPI
570     png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
571     int intent)
572     {
573     #if defined(PNG_gAMA_SUPPORTED)
574     #ifdef PNG_FLOATING_POINT_SUPPORTED
575     float file_gamma;
576     #endif
577     #ifdef PNG_FIXED_POINT_SUPPORTED
578     png_fixed_point int_file_gamma;
579     #endif
580     #endif
581     #if defined(PNG_cHRM_SUPPORTED)
582     #ifdef PNG_FLOATING_POINT_SUPPORTED
583     float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
584     #endif
585     png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
586     int_green_y, int_blue_x, int_blue_y;
587     #endif
588     png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM");
589     if (png_ptr == NULL || info_ptr == NULL)
590     return;
591    
592     png_set_sRGB(png_ptr, info_ptr, intent);
593    
594     #if defined(PNG_gAMA_SUPPORTED)
595     #ifdef PNG_FLOATING_POINT_SUPPORTED
596     file_gamma = (float).45455;
597     png_set_gAMA(png_ptr, info_ptr, file_gamma);
598     #endif
599     #ifdef PNG_FIXED_POINT_SUPPORTED
600     int_file_gamma = 45455L;
601     png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
602     #endif
603     #endif
604    
605     #if defined(PNG_cHRM_SUPPORTED)
606     int_white_x = 31270L;
607     int_white_y = 32900L;
608     int_red_x = 64000L;
609     int_red_y = 33000L;
610     int_green_x = 30000L;
611     int_green_y = 60000L;
612     int_blue_x = 15000L;
613     int_blue_y = 6000L;
614    
615     #ifdef PNG_FLOATING_POINT_SUPPORTED
616     white_x = (float).3127;
617     white_y = (float).3290;
618     red_x = (float).64;
619     red_y = (float).33;
620     green_x = (float).30;
621     green_y = (float).60;
622     blue_x = (float).15;
623     blue_y = (float).06;
624     #endif
625    
626     #if !defined(PNG_NO_CHECK_cHRM)
627     if (png_check_cHRM_fixed(png_ptr,
628     int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
629     int_green_y, int_blue_x, int_blue_y))
630     #endif
631     {
632     #ifdef PNG_FIXED_POINT_SUPPORTED
633     png_set_cHRM_fixed(png_ptr, info_ptr,
634     int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
635     int_green_y, int_blue_x, int_blue_y);
636     #endif
637     #ifdef PNG_FLOATING_POINT_SUPPORTED
638     png_set_cHRM(png_ptr, info_ptr,
639     white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
640     #endif
641     }
642     #endif /* cHRM */
643     }
644     #endif /* sRGB */
645    
646    
647     #if defined(PNG_iCCP_SUPPORTED)
648     void PNGAPI
649     png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
650     png_charp name, int compression_type,
651     png_charp profile, png_uint_32 proflen)
652     {
653     png_charp new_iccp_name;
654     png_charp new_iccp_profile;
655     png_uint_32 length;
656    
657     png_debug1(1, "in %s storage function", "iCCP");
658     if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
659     return;
660    
661     length = png_strlen(name)+1;
662     new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
663     if (new_iccp_name == NULL)
664     {
665     png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
666     return;
667     }
668     png_memcpy(new_iccp_name, name, length);
669     new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
670     if (new_iccp_profile == NULL)
671     {
672     png_free (png_ptr, new_iccp_name);
673     png_warning(png_ptr,
674     "Insufficient memory to process iCCP profile.");
675     return;
676     }
677     png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
678    
679     png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
680    
681     info_ptr->iccp_proflen = proflen;
682     info_ptr->iccp_name = new_iccp_name;
683     info_ptr->iccp_profile = new_iccp_profile;
684     /* Compression is always zero but is here so the API and info structure
685     * does not have to change if we introduce multiple compression types */
686     info_ptr->iccp_compression = (png_byte)compression_type;
687     #ifdef PNG_FREE_ME_SUPPORTED
688     info_ptr->free_me |= PNG_FREE_ICCP;
689     #endif
690     info_ptr->valid |= PNG_INFO_iCCP;
691     }
692     #endif
693    
694     #if defined(PNG_TEXT_SUPPORTED)
695     void PNGAPI
696     png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
697     int num_text)
698     {
699     int ret;
700     ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
701     if (ret)
702     png_error(png_ptr, "Insufficient memory to store text");
703     }
704    
705     int /* PRIVATE */
706     png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
707     int num_text)
708     {
709     int i;
710    
711     png_debug1(1, "in %s storage function", ((png_ptr == NULL ||
712     png_ptr->chunk_name[0] == '\0') ?
713     "text" : (png_const_charp)png_ptr->chunk_name));
714    
715     if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
716     return(0);
717    
718     /* Make sure we have enough space in the "text" array in info_struct
719     * to hold all of the incoming text_ptr objects.
720     */
721     if (info_ptr->num_text + num_text > info_ptr->max_text)
722     {
723     if (info_ptr->text != NULL)
724     {
725     png_textp old_text;
726     int old_max;
727    
728     old_max = info_ptr->max_text;
729     info_ptr->max_text = info_ptr->num_text + num_text + 8;
730     old_text = info_ptr->text;
731     info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
732     (png_uint_32)(info_ptr->max_text * png_sizeof(png_text)));
733     if (info_ptr->text == NULL)
734     {
735     png_free(png_ptr, old_text);
736     return(1);
737     }
738     png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
739     png_sizeof(png_text)));
740     png_free(png_ptr, old_text);
741     }
742     else
743     {
744     info_ptr->max_text = num_text + 8;
745     info_ptr->num_text = 0;
746     info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
747     (png_uint_32)(info_ptr->max_text * png_sizeof(png_text)));
748     if (info_ptr->text == NULL)
749     return(1);
750     #ifdef PNG_FREE_ME_SUPPORTED
751     info_ptr->free_me |= PNG_FREE_TEXT;
752     #endif
753     }
754     png_debug1(3, "allocated %d entries for info_ptr->text",
755     info_ptr->max_text);
756     }
757     for (i = 0; i < num_text; i++)
758     {
759     png_size_t text_length, key_len;
760     png_size_t lang_len, lang_key_len;
761     png_textp textp = &(info_ptr->text[info_ptr->num_text]);
762    
763     if (text_ptr[i].key == NULL)
764     continue;
765    
766     key_len = png_strlen(text_ptr[i].key);
767    
768     if (text_ptr[i].compression <= 0)
769     {
770     lang_len = 0;
771     lang_key_len = 0;
772     }
773     else
774     #ifdef PNG_iTXt_SUPPORTED
775     {
776     /* Set iTXt data */
777     if (text_ptr[i].lang != NULL)
778     lang_len = png_strlen(text_ptr[i].lang);
779     else
780     lang_len = 0;
781     if (text_ptr[i].lang_key != NULL)
782     lang_key_len = png_strlen(text_ptr[i].lang_key);
783     else
784     lang_key_len = 0;
785     }
786     #else
787     {
788     png_warning(png_ptr, "iTXt chunk not supported.");
789     continue;
790     }
791     #endif
792    
793     if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
794     {
795     text_length = 0;
796     #ifdef PNG_iTXt_SUPPORTED
797     if (text_ptr[i].compression > 0)
798     textp->compression = PNG_ITXT_COMPRESSION_NONE;
799     else
800     #endif
801     textp->compression = PNG_TEXT_COMPRESSION_NONE;
802     }
803     else
804     {
805     text_length = png_strlen(text_ptr[i].text);
806     textp->compression = text_ptr[i].compression;
807     }
808    
809     textp->key = (png_charp)png_malloc_warn(png_ptr,
810     (png_uint_32)
811     (key_len + text_length + lang_len + lang_key_len + 4));
812     if (textp->key == NULL)
813     return(1);
814     png_debug2(2, "Allocated %lu bytes at %x in png_set_text",
815     (png_uint_32)
816     (key_len + lang_len + lang_key_len + text_length + 4),
817     (int)textp->key);
818    
819     png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len));
820     *(textp->key + key_len) = '\0';
821     #ifdef PNG_iTXt_SUPPORTED
822     if (text_ptr[i].compression > 0)
823     {
824     textp->lang = textp->key + key_len + 1;
825     png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
826     *(textp->lang + lang_len) = '\0';
827     textp->lang_key = textp->lang + lang_len + 1;
828     png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
829     *(textp->lang_key + lang_key_len) = '\0';
830     textp->text = textp->lang_key + lang_key_len + 1;
831     }
832     else
833     #endif
834     {
835     #ifdef PNG_iTXt_SUPPORTED
836     textp->lang=NULL;
837     textp->lang_key=NULL;
838     #endif
839     textp->text = textp->key + key_len + 1;
840     }
841     if (text_length)
842     png_memcpy(textp->text, text_ptr[i].text,
843     (png_size_t)(text_length));
844     *(textp->text + text_length) = '\0';
845    
846     #ifdef PNG_iTXt_SUPPORTED
847     if (textp->compression > 0)
848     {
849     textp->text_length = 0;
850     textp->itxt_length = text_length;
851     }
852     else
853     #endif
854     {
855     textp->text_length = text_length;
856     #ifdef PNG_iTXt_SUPPORTED
857     textp->itxt_length = 0;
858     #endif
859     }
860     info_ptr->num_text++;
861     png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
862     }
863     return(0);
864     }
865     #endif
866    
867     #if defined(PNG_tIME_SUPPORTED)
868     void PNGAPI
869     png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
870     {
871     png_debug1(1, "in %s storage function", "tIME");
872     if (png_ptr == NULL || info_ptr == NULL ||
873     (png_ptr->mode & PNG_WROTE_tIME))
874     return;
875    
876     png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));
877     info_ptr->valid |= PNG_INFO_tIME;
878     }
879     #endif
880    
881     #if defined(PNG_tRNS_SUPPORTED)
882     void PNGAPI
883     png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
884     png_bytep trans, int num_trans, png_color_16p trans_values)
885     {
886     png_debug1(1, "in %s storage function", "tRNS");
887     if (png_ptr == NULL || info_ptr == NULL)
888     return;
889    
890     if (trans != NULL)
891     {
892     /*
893     * It may not actually be necessary to set png_ptr->trans here;
894     * we do it for backward compatibility with the way the png_handle_tRNS
895     * function used to do the allocation.
896     */
897    
898     #ifdef PNG_FREE_ME_SUPPORTED
899     png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
900     #endif
901    
902     /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
903     png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
904     (png_uint_32)PNG_MAX_PALETTE_LENGTH);
905     if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
906     png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
907     }
908    
909     if (trans_values != NULL)
910     {
911     int sample_max = (1 << info_ptr->bit_depth);
912     if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
913     (int)trans_values->gray > sample_max) ||
914     (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
915     ((int)trans_values->red > sample_max ||
916     (int)trans_values->green > sample_max ||
917     (int)trans_values->blue > sample_max)))
918     png_warning(png_ptr,
919     "tRNS chunk has out-of-range samples for bit_depth");
920     png_memcpy(&(info_ptr->trans_values), trans_values,
921     png_sizeof(png_color_16));
922     if (num_trans == 0)
923     num_trans = 1;
924     }
925    
926     info_ptr->num_trans = (png_uint_16)num_trans;
927     if (num_trans != 0)
928     {
929     info_ptr->valid |= PNG_INFO_tRNS;
930     #ifdef PNG_FREE_ME_SUPPORTED
931     info_ptr->free_me |= PNG_FREE_TRNS;
932     #else
933     png_ptr->flags |= PNG_FLAG_FREE_TRNS;
934     #endif
935     }
936     }
937     #endif
938    
939     #if defined(PNG_sPLT_SUPPORTED)
940     void PNGAPI
941     png_set_sPLT(png_structp png_ptr,
942     png_infop info_ptr, png_sPLT_tp entries, int nentries)
943     /*
944     * entries - array of png_sPLT_t structures
945     * to be added to the list of palettes
946     * in the info structure.
947     * nentries - number of palette structures to be
948     * added.
949     */
950     {
951     png_sPLT_tp np;
952     int i;
953    
954     if (png_ptr == NULL || info_ptr == NULL)
955     return;
956    
957     np = (png_sPLT_tp)png_malloc_warn(png_ptr,
958     (info_ptr->splt_palettes_num + nentries) *
959     (png_uint_32)png_sizeof(png_sPLT_t));
960     if (np == NULL)
961     {
962     png_warning(png_ptr, "No memory for sPLT palettes.");
963     return;
964     }
965    
966     png_memcpy(np, info_ptr->splt_palettes,
967     info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
968     png_free(png_ptr, info_ptr->splt_palettes);
969     info_ptr->splt_palettes=NULL;
970    
971     for (i = 0; i < nentries; i++)
972     {
973     png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
974     png_sPLT_tp from = entries + i;
975     png_uint_32 length;
976    
977     length = png_strlen(from->name) + 1;
978     to->name = (png_charp)png_malloc_warn(png_ptr, length);
979     if (to->name == NULL)
980     {
981     png_warning(png_ptr,
982     "Out of memory while processing sPLT chunk");
983     continue;
984     }
985     png_memcpy(to->name, from->name, length);
986     to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
987     (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry)));
988     if (to->entries == NULL)
989     {
990     png_warning(png_ptr,
991     "Out of memory while processing sPLT chunk");
992     png_free(png_ptr, to->name);
993     to->name = NULL;
994     continue;
995     }
996     png_memcpy(to->entries, from->entries,
997     from->nentries * png_sizeof(png_sPLT_entry));
998     to->nentries = from->nentries;
999     to->depth = from->depth;
1000     }
1001    
1002     info_ptr->splt_palettes = np;
1003     info_ptr->splt_palettes_num += nentries;
1004     info_ptr->valid |= PNG_INFO_sPLT;
1005     #ifdef PNG_FREE_ME_SUPPORTED
1006     info_ptr->free_me |= PNG_FREE_SPLT;
1007     #endif
1008     }
1009     #endif /* PNG_sPLT_SUPPORTED */
1010    
1011     #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1012     void PNGAPI
1013     png_set_unknown_chunks(png_structp png_ptr,
1014     png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
1015     {
1016     png_unknown_chunkp np;
1017     int i;
1018    
1019     if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
1020     return;
1021    
1022     np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
1023     (png_uint_32)((info_ptr->unknown_chunks_num + num_unknowns) *
1024     png_sizeof(png_unknown_chunk)));
1025     if (np == NULL)
1026     {
1027     png_warning(png_ptr,
1028     "Out of memory while processing unknown chunk.");
1029     return;
1030     }
1031    
1032     png_memcpy(np, info_ptr->unknown_chunks,
1033     info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
1034     png_free(png_ptr, info_ptr->unknown_chunks);
1035     info_ptr->unknown_chunks=NULL;
1036    
1037     for (i = 0; i < num_unknowns; i++)
1038     {
1039     png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
1040     png_unknown_chunkp from = unknowns + i;
1041    
1042     png_memcpy((png_charp)to->name,
1043     (png_charp)from->name,
1044     png_sizeof(from->name));
1045     to->name[png_sizeof(to->name)-1] = '\0';
1046     to->size = from->size;
1047     /* Note our location in the read or write sequence */
1048     to->location = (png_byte)(png_ptr->mode & 0xff);
1049    
1050     if (from->size == 0)
1051     to->data=NULL;
1052     else
1053     {
1054     to->data = (png_bytep)png_malloc_warn(png_ptr,
1055     (png_uint_32)from->size);
1056     if (to->data == NULL)
1057     {
1058     png_warning(png_ptr,
1059     "Out of memory while processing unknown chunk.");
1060     to->size = 0;
1061     }
1062     else
1063     png_memcpy(to->data, from->data, from->size);
1064     }
1065     }
1066    
1067     info_ptr->unknown_chunks = np;
1068     info_ptr->unknown_chunks_num += num_unknowns;
1069     #ifdef PNG_FREE_ME_SUPPORTED
1070     info_ptr->free_me |= PNG_FREE_UNKN;
1071     #endif
1072     }
1073     void PNGAPI
1074     png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
1075     int chunk, int location)
1076     {
1077     if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
1078     (int)info_ptr->unknown_chunks_num)
1079     info_ptr->unknown_chunks[chunk].location = (png_byte)location;
1080     }
1081     #endif
1082    
1083     #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
1084     #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
1085     defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
1086     void PNGAPI
1087     png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
1088     {
1089     /* This function is deprecated in favor of png_permit_mng_features()
1090     and will be removed from libpng-1.3.0 */
1091     png_debug(1, "in png_permit_empty_plte, DEPRECATED.");
1092     if (png_ptr == NULL)
1093     return;
1094     png_ptr->mng_features_permitted = (png_byte)
1095     ((png_ptr->mng_features_permitted & (~PNG_FLAG_MNG_EMPTY_PLTE)) |
1096     ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
1097     }
1098     #endif
1099     #endif
1100    
1101     #if defined(PNG_MNG_FEATURES_SUPPORTED)
1102     png_uint_32 PNGAPI
1103     png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
1104     {
1105     png_debug(1, "in png_permit_mng_features");
1106     if (png_ptr == NULL)
1107     return (png_uint_32)0;
1108     png_ptr->mng_features_permitted =
1109     (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
1110     return (png_uint_32)png_ptr->mng_features_permitted;
1111     }
1112     #endif
1113    
1114     #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1115     void PNGAPI
1116     png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
1117     chunk_list, int num_chunks)
1118     {
1119     png_bytep new_list, p;
1120     int i, old_num_chunks;
1121     if (png_ptr == NULL)
1122     return;
1123     if (num_chunks == 0)
1124     {
1125     if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
1126     png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
1127     else
1128     png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
1129    
1130     if (keep == PNG_HANDLE_CHUNK_ALWAYS)
1131     png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
1132     else
1133     png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
1134     return;
1135     }
1136     if (chunk_list == NULL)
1137     return;
1138     old_num_chunks = png_ptr->num_chunk_list;
1139     new_list=(png_bytep)png_malloc(png_ptr,
1140     (png_uint_32)
1141     (5*(num_chunks + old_num_chunks)));
1142     if (png_ptr->chunk_list != NULL)
1143     {
1144     png_memcpy(new_list, png_ptr->chunk_list,
1145     (png_size_t)(5*old_num_chunks));
1146     png_free(png_ptr, png_ptr->chunk_list);
1147     png_ptr->chunk_list=NULL;
1148     }
1149     png_memcpy(new_list + 5*old_num_chunks, chunk_list,
1150     (png_size_t)(5*num_chunks));
1151     for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
1152     *p=(png_byte)keep;
1153     png_ptr->num_chunk_list = old_num_chunks + num_chunks;
1154     png_ptr->chunk_list = new_list;
1155     #ifdef PNG_FREE_ME_SUPPORTED
1156     png_ptr->free_me |= PNG_FREE_LIST;
1157     #endif
1158     }
1159     #endif
1160    
1161     #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
1162     void PNGAPI
1163     png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
1164     png_user_chunk_ptr read_user_chunk_fn)
1165     {
1166     png_debug(1, "in png_set_read_user_chunk_fn");
1167     if (png_ptr == NULL)
1168     return;
1169     png_ptr->read_user_chunk_fn = read_user_chunk_fn;
1170     png_ptr->user_chunk_ptr = user_chunk_ptr;
1171     }
1172     #endif
1173    
1174     #if defined(PNG_INFO_IMAGE_SUPPORTED)
1175     void PNGAPI
1176     png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
1177     {
1178     png_debug1(1, "in %s storage function", "rows");
1179    
1180     if (png_ptr == NULL || info_ptr == NULL)
1181     return;
1182    
1183     if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
1184     png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
1185     info_ptr->row_pointers = row_pointers;
1186     if (row_pointers)
1187     info_ptr->valid |= PNG_INFO_IDAT;
1188     }
1189     #endif
1190    
1191     #ifdef PNG_WRITE_SUPPORTED
1192     void PNGAPI
1193     png_set_compression_buffer_size(png_structp png_ptr,
1194     png_uint_32 size)
1195     {
1196     if (png_ptr == NULL)
1197     return;
1198     png_free(png_ptr, png_ptr->zbuf);
1199     png_ptr->zbuf_size = (png_size_t)size;
1200     png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
1201     png_ptr->zstream.next_out = png_ptr->zbuf;
1202     png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
1203     }
1204     #endif
1205    
1206     void PNGAPI
1207     png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
1208     {
1209     if (png_ptr && info_ptr)
1210     info_ptr->valid &= ~mask;
1211     }
1212    
1213    
1214     #ifndef PNG_1_0_X
1215     #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
1216     /* Function was added to libpng 1.2.0 and should always exist by default */
1217     void PNGAPI
1218     png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
1219     {
1220     /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */
1221     if (png_ptr != NULL)
1222     png_ptr->asm_flags = 0;
1223     asm_flags = asm_flags; /* Quiet the compiler */
1224     }
1225    
1226     /* This function was added to libpng 1.2.0 */
1227     void PNGAPI
1228     png_set_mmx_thresholds (png_structp png_ptr,
1229     png_byte mmx_bitdepth_threshold,
1230     png_uint_32 mmx_rowbytes_threshold)
1231     {
1232     /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */
1233     if (png_ptr == NULL)
1234     return;
1235     /* Quiet the compiler */
1236     mmx_bitdepth_threshold = mmx_bitdepth_threshold;
1237     mmx_rowbytes_threshold = mmx_rowbytes_threshold;
1238     }
1239     #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
1240    
1241     #ifdef PNG_SET_USER_LIMITS_SUPPORTED
1242     /* This function was added to libpng 1.2.6 */
1243     void PNGAPI
1244     png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
1245     png_uint_32 user_height_max)
1246     {
1247     /* Images with dimensions larger than these limits will be
1248     * rejected by png_set_IHDR(). To accept any PNG datastream
1249     * regardless of dimensions, set both limits to 0x7ffffffL.
1250     */
1251     if (png_ptr == NULL)
1252     return;
1253     png_ptr->user_width_max = user_width_max;
1254     png_ptr->user_height_max = user_height_max;
1255     }
1256     #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1257    
1258     #endif /* ?PNG_1_0_X */
1259     #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */

  ViewVC Help
Powered by ViewVC 1.1.22