blob: 29fbb11984dd9817569d21a9f918b9a0f47a79c2 [file] [log] [blame]
Guy Schalnat0d580581995-07-20 02:43:20 -05001
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06002/* png.c - location for general purpose libpng functions
3 *
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05004 * libpng version 1.0.7beta15 - May 29, 2000
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06005 * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
6 * Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06007 * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06008 *
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06009 */
Guy Schalnat0d580581995-07-20 02:43:20 -050010
11#define PNG_INTERNAL
12#define PNG_NO_EXTERN
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060013#include <assert.h>
Guy Schalnat0d580581995-07-20 02:43:20 -050014#include "png.h"
15
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -060016/* Generate a compiler error if there is an old png.h in the search path. */
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -050017typedef version_1_0_7beta15 Your_png_h_is_not_version_1_0_7beta15;
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -060018
Andreas Dilger47a0c421997-05-16 02:46:07 -050019/* Version information for C files. This had better match the version
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -060020 * string defined in png.h. */
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -060021
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -060022#ifdef PNG_USE_GLOBAL_ARRAYS
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -060023/* png_libpng_ver was changed to a function in version 1.0.5c */
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -050024char png_libpng_ver[12] = "1.0.7beta15";
Guy Schalnat51f0eb41995-09-26 05:22:39 -050025
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -060026/* png_sig was changed to a function in version 1.0.5c */
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060027/* Place to hold the signature string for a PNG file. */
Guy Schalnat6d764711995-12-19 03:22:19 -060028png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060029
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -060030/* Invoke global declarations for constant strings for known chunk types */
31PNG_IHDR;
32PNG_IDAT;
33PNG_IEND;
34PNG_PLTE;
35PNG_bKGD;
36PNG_cHRM;
37PNG_gAMA;
38PNG_hIST;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060039PNG_iCCP;
40PNG_iTXt;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -060041PNG_oFFs;
42PNG_pCAL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060043PNG_sCAL;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -060044PNG_pHYs;
45PNG_sBIT;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060046PNG_sPLT;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -060047PNG_sRGB;
48PNG_tEXt;
49PNG_tIME;
50PNG_tRNS;
51PNG_zTXt;
Guy Schalnat0d580581995-07-20 02:43:20 -050052
53/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
54
55/* start of interlace block */
Guy Schalnat6d764711995-12-19 03:22:19 -060056int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
Guy Schalnat0d580581995-07-20 02:43:20 -050057
58/* offset to next interlace block */
Guy Schalnat6d764711995-12-19 03:22:19 -060059int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
Guy Schalnat0d580581995-07-20 02:43:20 -050060
61/* start of interlace block in the y direction */
Guy Schalnat6d764711995-12-19 03:22:19 -060062int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
Guy Schalnat0d580581995-07-20 02:43:20 -050063
64/* offset to next interlace block in the y direction */
Guy Schalnat6d764711995-12-19 03:22:19 -060065int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
Guy Schalnat0d580581995-07-20 02:43:20 -050066
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060067/* width of interlace block (used in assembler routines only) */
68#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
Guy Schalnat6d764711995-12-19 03:22:19 -060069int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060070#endif
Guy Schalnat0d580581995-07-20 02:43:20 -050071
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060072/* Height of interlace block. This is not currently used - if you need
73 * it, uncomment it here and in png.h
Guy Schalnat6d764711995-12-19 03:22:19 -060074int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
Guy Schalnat0d580581995-07-20 02:43:20 -050075*/
76
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060077/* Mask to determine which pixels are valid in a pass */
Guy Schalnat6d764711995-12-19 03:22:19 -060078int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
Guy Schalnat0d580581995-07-20 02:43:20 -050079
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060080/* Mask to determine which pixels to overwrite while displaying */
Guy Schalnat6d764711995-12-19 03:22:19 -060081int FARDATA png_pass_dsp_mask[] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
Guy Schalnat0d580581995-07-20 02:43:20 -050082
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -060083#endif
84
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060085/* Tells libpng that we have already handled the first "num_bytes" bytes
86 * of the PNG file signature. If the PNG data is embedded into another
87 * stream we can set num_bytes = 8 so that libpng will not attempt to read
88 * or write any of the magic bytes before it starts on the IHDR.
89 */
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -050090
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050091void PNGAPI
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060092png_set_sig_bytes(png_structp png_ptr, int num_bytes)
93{
Andreas Dilger47a0c421997-05-16 02:46:07 -050094 png_debug(1, "in png_set_sig_bytes\n");
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060095 if (num_bytes > 8)
96 png_error(png_ptr, "Too many bytes for PNG signature.");
97
Glenn Randers-Pehrson860ab2b1999-10-14 07:43:10 -050098 png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060099}
100
101/* Checks whether the supplied bytes match the PNG signature. We allow
102 * checking less than the full 8-byte signature so that those apps that
103 * already read the first few bytes of a file to determine the file type
104 * can simply check the remaining bytes for extra assurance. Returns
105 * an integer less than, equal to, or greater than zero if sig is found,
106 * respectively, to be less than, to match, or be greater than the correct
107 * PNG signature (this is the same behaviour as strcmp, memcmp, etc).
108 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500109int PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500110png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600111{
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600112 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600113 if (num_to_check > 8)
114 num_to_check = 8;
115 else if (num_to_check < 1)
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600116 return (0);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600117
Andreas Dilger47a0c421997-05-16 02:46:07 -0500118 if (start > 7)
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600119 return (0);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600120
121 if (start + num_to_check > 8)
122 num_to_check = 8 - start;
123
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600124 return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600125}
126
127/* (Obsolete) function to check signature bytes. It does not allow one
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -0600128 * to check a partial signature. This function might be removed in the
129 * future - use png_sig_cmp(). Returns true (nonzero) if the file is a PNG.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600130 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500131int PNGAPI
Guy Schalnat6d764711995-12-19 03:22:19 -0600132png_check_sig(png_bytep sig, int num)
Guy Schalnat0d580581995-07-20 02:43:20 -0500133{
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600134 return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
Guy Schalnat0d580581995-07-20 02:43:20 -0500135}
136
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500137/* Function to allocate memory for zlib and clear it to 0. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500138voidpf PNGAPI
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500139png_zalloc(voidpf png_ptr, uInt items, uInt size)
Guy Schalnat0d580581995-07-20 02:43:20 -0500140{
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500141 png_uint_32 num_bytes = (png_uint_32)items * size;
142 png_voidp ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
Guy Schalnat6d764711995-12-19 03:22:19 -0600143
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500144 if (num_bytes > (png_uint_32)0x8000L)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600145 {
146 png_memset(ptr, 0, (png_size_t)0x8000L);
147 png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
148 (png_size_t)(num_bytes - (png_uint_32)0x8000L));
149 }
150 else
151 {
152 png_memset(ptr, 0, (png_size_t)num_bytes);
153 }
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600154 return ((voidpf)ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500155}
156
157/* function to free memory for zlib */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500158void PNGAPI
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500159png_zfree(voidpf png_ptr, voidpf ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500160{
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600161 png_free((png_structp)png_ptr, (png_voidp)ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500162}
163
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600164/* Reset the CRC variable to 32 bits of 1's. Care must be taken
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600165 * in case CRC is > 32 bits to leave the top bits 0.
166 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500167void /* PRIVATE */
Guy Schalnat6d764711995-12-19 03:22:19 -0600168png_reset_crc(png_structp png_ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500169{
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600170 png_ptr->crc = crc32(0, Z_NULL, 0);
Guy Schalnat0d580581995-07-20 02:43:20 -0500171}
172
Andreas Dilger47a0c421997-05-16 02:46:07 -0500173/* Calculate the CRC over a section of data. We can only pass as
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600174 * much data to this routine as the largest single buffer size. We
175 * also check that this data will actually be used before going to the
176 * trouble of calculating it.
177 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500178void /* PRIVATE */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500179png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
Guy Schalnat0d580581995-07-20 02:43:20 -0500180{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500181 int need_crc = 1;
182
183 if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
184 {
185 if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
186 (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
187 need_crc = 0;
188 }
189 else /* critical */
190 {
191 if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
192 need_crc = 0;
193 }
194
195 if (need_crc)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600196 png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
Guy Schalnat0d580581995-07-20 02:43:20 -0500197}
Guy Schalnate5a37791996-06-05 15:50:50 -0500198
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600199/* Allocate the memory for an info_struct for the application. We don't
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600200 * really need the png_ptr, but it could potentially be useful in the
201 * future. This should be used in favour of malloc(sizeof(png_info))
202 * and png_info_init() so that applications that want to use a shared
203 * libpng don't have to be recompiled if png_info changes size.
204 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500205png_infop PNGAPI
Guy Schalnate5a37791996-06-05 15:50:50 -0500206png_create_info_struct(png_structp png_ptr)
207{
208 png_infop info_ptr;
209
Andreas Dilger47a0c421997-05-16 02:46:07 -0500210 png_debug(1, "in png_create_info_struct\n");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600211 if(png_ptr == NULL) return (NULL);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500212#ifdef PNG_USER_MEM_SUPPORTED
213 if ((info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
214 png_ptr->malloc_fn)) != NULL)
215#else
Guy Schalnate5a37791996-06-05 15:50:50 -0500216 if ((info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO)) != NULL)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500217#endif
Guy Schalnate5a37791996-06-05 15:50:50 -0500218 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600219 png_info_init(info_ptr);
Guy Schalnate5a37791996-06-05 15:50:50 -0500220 }
221
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600222 return (info_ptr);
Guy Schalnate5a37791996-06-05 15:50:50 -0500223}
224
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600225/* This function frees the memory associated with a single info struct.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600226 * Normally, one would use either png_destroy_read_struct() or
227 * png_destroy_write_struct() to free an info struct, but this may be
228 * useful for some applications.
229 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500230void PNGAPI
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600231png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
232{
233 png_infop info_ptr = NULL;
234
Andreas Dilger47a0c421997-05-16 02:46:07 -0500235 png_debug(1, "in png_destroy_info_struct\n");
236 if (info_ptr_ptr != NULL)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600237 info_ptr = *info_ptr_ptr;
238
Andreas Dilger47a0c421997-05-16 02:46:07 -0500239 if (info_ptr != NULL)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600240 {
241 png_info_destroy(png_ptr, info_ptr);
242
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500243#ifdef PNG_USER_MEM_SUPPORTED
244 png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn);
245#else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600246 png_destroy_struct((png_voidp)info_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500247#endif
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600248 *info_ptr_ptr = (png_infop)NULL;
249 }
250}
251
252/* Initialize the info structure. This is now an internal function (0.89)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600253 * and applications using it are urged to use png_create_info_struct()
254 * instead.
255 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500256void PNGAPI
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600257png_info_init(png_infop info_ptr)
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500258{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500259 png_debug(1, "in png_info_init\n");
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500260 /* set everything to 0 */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600261 png_memset(info_ptr, 0, sizeof (png_info));
262}
263
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500264#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500265void PNGAPI
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500266png_data_freer(png_structp png_ptr, png_infop info_ptr,
267 int freer, png_uint_32 mask)
268{
269 png_debug(1, "in png_data_freer\n");
270 if (png_ptr == NULL || info_ptr == NULL)
271 return;
272 if(freer == PNG_DESTROY_WILL_FREE_DATA)
273 info_ptr->free_me |= mask;
274 else if(freer == PNG_USER_WILL_FREE_DATA)
275 info_ptr->free_me &= ~mask;
276 else
277 png_warning(png_ptr,
278 "Unknown freer parameter in png_data_freer.");
279}
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500280#endif
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500281
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500282void PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600283png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, int num)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600284{
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500285 png_debug(1, "in png_free_data\n");
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600286 if (png_ptr == NULL || info_ptr == NULL)
287 return;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600288
289#if defined(PNG_TEXT_SUPPORTED)
290/* free text item num or (if num == -1) all text items */
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500291#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500292if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500293#else
294if (mask & PNG_FREE_TEXT)
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500295#endif
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600296{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600297 if (num != -1)
298 {
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500299 if (info_ptr->text && info_ptr->text[num].key)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600300 {
301 png_free(png_ptr, info_ptr->text[num].key);
302 info_ptr->text[num].key = NULL;
303 }
304 }
Glenn Randers-Pehrsonec61c232000-05-16 06:17:36 -0500305 else
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600306 {
Glenn Randers-Pehrsonec61c232000-05-16 06:17:36 -0500307 int i;
308 for (i = 0; i < info_ptr->num_text; i++)
309 png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
310 png_free(png_ptr, info_ptr->text);
311 info_ptr->text = NULL;
312 info_ptr->num_text=0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600313 }
314}
315#endif
316
317#if defined(PNG_tRNS_SUPPORTED)
318/* free any tRNS entry */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500319#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500320if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500321#else
322if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
323#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600324{
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500325 png_free(png_ptr, info_ptr->trans);
326 info_ptr->valid &= ~PNG_INFO_tRNS;
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500327 info_ptr->trans = NULL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600328}
329#endif
330
331#if defined(PNG_sCAL_SUPPORTED)
332/* free any sCAL entry */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500333#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500334if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500335#else
336if (mask & PNG_FREE_SCAL)
337#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600338{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600339#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500340 png_free(png_ptr, info_ptr->scal_s_width);
341 png_free(png_ptr, info_ptr->scal_s_height);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500342 info_ptr->scal_s_width = NULL;
343 info_ptr->scal_s_height = NULL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600344#endif
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500345 info_ptr->valid &= ~PNG_INFO_sCAL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600346}
347#endif
348
349#if defined(PNG_pCAL_SUPPORTED)
350/* free any pCAL entry */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500351#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500352if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500353#else
354if (mask & PNG_FREE_PCAL)
355#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600356{
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500357 png_free(png_ptr, info_ptr->pcal_purpose);
358 png_free(png_ptr, info_ptr->pcal_units);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500359 info_ptr->pcal_purpose = NULL;
360 info_ptr->pcal_units = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500361 if (info_ptr->pcal_params != NULL)
362 {
363 int i;
364 for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
365 png_free(png_ptr, info_ptr->pcal_params[i]);
366 png_free(png_ptr, info_ptr->pcal_params);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500367 info_ptr->pcal_params = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500368 }
369 info_ptr->valid &= ~PNG_INFO_pCAL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600370}
371#endif
372
373#if defined(PNG_iCCP_SUPPORTED)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600374/* free any iCCP entry */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500375#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500376if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500377#else
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600378if (mask & PNG_FREE_ICCP)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500379#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600380{
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500381 png_free(png_ptr, info_ptr->iccp_name);
382 png_free(png_ptr, info_ptr->iccp_profile);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500383 info_ptr->iccp_name = NULL;
384 info_ptr->iccp_profile = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500385 info_ptr->valid &= ~PNG_INFO_iCCP;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600386}
387#endif
388
389#if defined(PNG_sPLT_SUPPORTED)
390/* free a given sPLT entry, or (if num == -1) all sPLT entries */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500391#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500392if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500393#else
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600394if (mask & PNG_FREE_SPLT)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500395#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600396{
397 if (num != -1)
398 {
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500399 if(info_ptr->splt_palettes)
400 {
401 png_free(png_ptr, info_ptr->splt_palettes[num].name);
402 png_free(png_ptr, info_ptr->splt_palettes[num].entries);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500403 info_ptr->splt_palettes[num].name = NULL;
404 info_ptr->splt_palettes[num].entries = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500405 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600406 }
407 else
408 {
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600409 if(info_ptr->splt_palettes_num)
410 {
411 int i;
412 for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
413 png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600414
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600415 png_free(png_ptr, info_ptr->splt_palettes);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500416 info_ptr->splt_palettes = NULL;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600417 info_ptr->splt_palettes_num = 0;
418 }
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500419 info_ptr->valid &= ~PNG_INFO_sPLT;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600420 }
421}
422#endif
423
424#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500425#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500426if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500427#else
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600428if (mask & PNG_FREE_UNKN)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500429#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600430{
431 if (num != -1)
432 {
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500433 if(info_ptr->unknown_chunks)
434 {
435 png_free(png_ptr, info_ptr->unknown_chunks[num].data);
436 info_ptr->unknown_chunks[num].data = NULL;
437 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600438 }
439 else
440 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600441 int i;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600442
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600443 if(info_ptr->unknown_chunks_num)
444 {
445 for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
446 png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600447
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600448 png_free(png_ptr, info_ptr->unknown_chunks);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500449 info_ptr->unknown_chunks = NULL;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600450 info_ptr->unknown_chunks_num = 0;
451 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600452 }
453}
454#endif
455
456#if defined(PNG_hIST_SUPPORTED)
457/* free any hIST entry */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500458#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500459if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500460#else
461if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
462#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600463{
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500464 png_free(png_ptr, info_ptr->hist);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500465 info_ptr->hist = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500466 info_ptr->valid &= ~PNG_INFO_hIST;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600467}
468#endif
469
470/* free any PLTE entry that was internally allocated */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500471#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500472if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500473#else
474if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
475#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600476{
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500477 png_zfree(png_ptr, info_ptr->palette);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500478 info_ptr->palette = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500479 info_ptr->valid &= ~PNG_INFO_PLTE;
480 info_ptr->num_palette = 0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600481}
482
483#if defined(PNG_INFO_IMAGE_SUPPORTED)
484/* free any image bits attached to the info structure */
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500485#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500486if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500487#else
488if (mask & PNG_FREE_ROWS)
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500489#endif
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500490{
491 if(info_ptr->row_pointers)
492 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600493 int row;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600494 for (row = 0; row < (int)info_ptr->height; row++)
495 png_free(png_ptr, info_ptr->row_pointers[row]);
496 png_free(png_ptr, info_ptr->row_pointers);
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500497 info_ptr->row_pointers=NULL;
498 }
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500499 info_ptr->valid &= ~PNG_INFO_IDAT;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600500}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600501#endif
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500502
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500503#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600504 if(num == -1)
505 info_ptr->free_me &= ~mask;
Glenn Randers-Pehrsonec61c232000-05-16 06:17:36 -0500506 else
507 info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500508#endif
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600509}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600510
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600511/* This is an internal routine to free any memory that the info struct is
Andreas Dilger47a0c421997-05-16 02:46:07 -0500512 * pointing to before re-using it or freeing the struct itself. Recall
513 * that png_free() checks for NULL pointers for us.
514 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500515void /* PRIVATE */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600516png_info_destroy(png_structp png_ptr, png_infop info_ptr)
517{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500518 png_debug(1, "in png_info_destroy\n");
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600519
520 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
521
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500522#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600523 if (png_ptr->num_chunk_list)
524 {
525 png_free(png_ptr, png_ptr->chunk_list);
526 png_ptr->num_chunk_list=0;
527 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600528#endif
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600529
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600530 png_info_init(info_ptr);
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500531}
Guy Schalnat0d580581995-07-20 02:43:20 -0500532
Guy Schalnate5a37791996-06-05 15:50:50 -0500533/* This function returns a pointer to the io_ptr associated with the user
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600534 * functions. The application should free any memory associated with this
535 * pointer before png_write_destroy() or png_read_destroy() are called.
536 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500537png_voidp PNGAPI
Guy Schalnate5a37791996-06-05 15:50:50 -0500538png_get_io_ptr(png_structp png_ptr)
539{
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600540 return (png_ptr->io_ptr);
Guy Schalnate5a37791996-06-05 15:50:50 -0500541}
Andreas Dilger47a0c421997-05-16 02:46:07 -0500542
543#if !defined(PNG_NO_STDIO)
544/* Initialize the default input/output functions for the PNG file. If you
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600545 * use your own read or write routines, you can call either png_set_read_fn()
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500546 * or png_set_write_fn() instead of png_init_io(). If you have defined
547 * PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't
548 * necessarily available.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600549 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500550void PNGAPI
Guy Schalnate5a37791996-06-05 15:50:50 -0500551png_init_io(png_structp png_ptr, FILE *fp)
552{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500553 png_debug(1, "in png_init_io\n");
Guy Schalnate5a37791996-06-05 15:50:50 -0500554 png_ptr->io_ptr = (png_voidp)fp;
555}
Andreas Dilger47a0c421997-05-16 02:46:07 -0500556#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500557
558#if defined(PNG_TIME_RFC1123_SUPPORTED)
559/* Convert the supplied time into an RFC 1123 string suitable for use in
560 * a "Creation Time" or other text-based time string.
561 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500562png_charp PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500563png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
564{
565 static PNG_CONST char short_months[12][4] =
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600566 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
567 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500568
569 if (png_ptr->time_buffer == NULL)
570 {
571 png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
572 sizeof(char)));
573 }
574
575#ifdef USE_FAR_KEYWORD
576 {
577 char near_time_buf[29];
578 sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000",
579 ptime->day % 32, short_months[(ptime->month - 1) % 12],
580 ptime->year, ptime->hour % 24, ptime->minute % 60,
581 ptime->second % 61);
582 png_memcpy(png_ptr->time_buffer, near_time_buf,
583 29*sizeof(char));
584 }
585#else
586 sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
587 ptime->day % 32, short_months[(ptime->month - 1) % 12],
588 ptime->year, ptime->hour % 24, ptime->minute % 60,
589 ptime->second % 61);
590#endif
591 return ((png_charp)png_ptr->time_buffer);
592}
593#endif /* PNG_TIME_RFC1123_SUPPORTED */
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600594
Glenn Randers-Pehrson81fdf8a2000-04-07 10:34:56 -0500595#if 0
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600596/* Signature string for a PNG file. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500597png_bytep PNGAPI
Glenn Randers-Pehrson81fdf8a2000-04-07 10:34:56 -0500598png_sig_bytes(void)
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600599{
Glenn Randers-Pehrson81fdf8a2000-04-07 10:34:56 -0500600 return ((png_bytep)"\211\120\116\107\015\012\032\012");
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600601}
Glenn Randers-Pehrson81fdf8a2000-04-07 10:34:56 -0500602#endif
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600603
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500604png_charp PNGAPI
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600605png_get_copyright(png_structp png_ptr)
606{
Glenn Randers-Pehrson860ab2b1999-10-14 07:43:10 -0500607 if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500608 return ("\n libpng version 1.0.7beta15 - May 29, 2000\n\
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600609 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n\
610 Copyright (c) 1996, 1997 Andreas Dilger\n\
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600611 Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson\n");
Glenn Randers-Pehrson860ab2b1999-10-14 07:43:10 -0500612 return ("");
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600613}
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500614
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600615/* The following return the library version as a short string in the
616 * format 1.0.0 through 99.99.99zz. To get the version of *.h files used
617 * with your application, print out PNG_LIBPNG_VER_STRING, which is defined
618 * in png.h.
619 */
620
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500621png_charp PNGAPI
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600622png_get_libpng_ver(png_structp png_ptr)
623{
624 /* Version of *.c files used when building libpng */
625 if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500626 return("1.0.7beta15");
627 return("1.0.7beta15");
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600628}
629
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500630png_charp PNGAPI
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600631png_get_header_ver(png_structp png_ptr)
632{
633 /* Version of *.h files used when building libpng */
634 if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
635 return(PNG_LIBPNG_VER_STRING);
636 return(PNG_LIBPNG_VER_STRING);
637}
638
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500639png_charp PNGAPI
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600640png_get_header_version(png_structp png_ptr)
641{
642 /* Returns longer string containing both version and date */
643 if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
644 return(PNG_HEADER_VERSION_STRING);
645 return(PNG_HEADER_VERSION_STRING);
646}
647
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600648#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500649int PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600650png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
651{
652 /* check chunk_name and return "keep" value if it's on the list, else 0 */
653 int i;
654 png_bytep p;
655 if((png_ptr == NULL && chunk_name == NULL) || png_ptr->num_chunk_list<=0)
656 return 0;
657 p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
658 for (i = png_ptr->num_chunk_list; i; i--, p-=5)
659 if (!png_memcmp(chunk_name, p, 4))
660 return ((int)*(p+4));
661 return 0;
662}
663#endif
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500664
665/* This function, added to libpng-1.0.6g, is untested. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500666int PNGAPI
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500667png_reset_zstream(png_structp png_ptr)
668{
669 return (inflateReset(&png_ptr->zstream));
670}
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500671
672png_uint_32 PNGAPI
673png_access_version_number(void)
674{
675 /* Version of *.c files used when building libpng */
676 return((png_uint_32) 10007L);
677}