blob: 09ed6d2889f2d817bda2671b1e1daa096d5a2b7c [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-Pehrsond56aca72000-11-23 11:51:42 -06004 * libpng version 1.0.9beta3 - November 23, 2000
Glenn Randers-Pehrsonf5ed0e12000-11-18 18:19:14 -06005 * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
Glenn Randers-Pehrsond4366722000-06-04 14:29:29 -05006 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
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
13#include "png.h"
14
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -060015/* Generate a compiler error if there is an old png.h in the search path. */
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -060016typedef version_1_0_9beta3 Your_png_h_is_not_version_1_0_9beta3;
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -060017
Andreas Dilger47a0c421997-05-16 02:46:07 -050018/* Version information for C files. This had better match the version
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -060019 * string defined in png.h. */
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -060020
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -060021#ifdef PNG_USE_GLOBAL_ARRAYS
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -060022/* png_libpng_ver was changed to a function in version 1.0.5c */
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -060023const char png_libpng_ver[18] = "1.0.9beta3";
Guy Schalnat51f0eb41995-09-26 05:22:39 -050024
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -060025/* png_sig was changed to a function in version 1.0.5c */
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060026/* Place to hold the signature string for a PNG file. */
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060027const png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060028
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -060029/* Invoke global declarations for constant strings for known chunk types */
30PNG_IHDR;
31PNG_IDAT;
32PNG_IEND;
33PNG_PLTE;
34PNG_bKGD;
35PNG_cHRM;
36PNG_gAMA;
37PNG_hIST;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060038PNG_iCCP;
39PNG_iTXt;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -060040PNG_oFFs;
41PNG_pCAL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060042PNG_sCAL;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -060043PNG_pHYs;
44PNG_sBIT;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060045PNG_sPLT;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -060046PNG_sRGB;
47PNG_tEXt;
48PNG_tIME;
49PNG_tRNS;
50PNG_zTXt;
Guy Schalnat0d580581995-07-20 02:43:20 -050051
52/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
53
54/* start of interlace block */
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060055const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
Guy Schalnat0d580581995-07-20 02:43:20 -050056
57/* offset to next interlace block */
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060058const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
Guy Schalnat0d580581995-07-20 02:43:20 -050059
60/* start of interlace block in the y direction */
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060061const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
Guy Schalnat0d580581995-07-20 02:43:20 -050062
63/* offset to next interlace block in the y direction */
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060064const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
Guy Schalnat0d580581995-07-20 02:43:20 -050065
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060066/* width of interlace block (used in assembler routines only) */
67#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060068const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060069#endif
Guy Schalnat0d580581995-07-20 02:43:20 -050070
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060071/* Height of interlace block. This is not currently used - if you need
72 * it, uncomment it here and in png.h
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060073const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
Guy Schalnat0d580581995-07-20 02:43:20 -050074*/
75
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060076/* Mask to determine which pixels are valid in a pass */
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060077const int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
Guy Schalnat0d580581995-07-20 02:43:20 -050078
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060079/* Mask to determine which pixels to overwrite while displaying */
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060080const int FARDATA png_pass_dsp_mask[]
81 = {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-Pehrsona4d54bd2000-07-14 08:15:12 -0500144#ifndef PNG_NO_ZALLOC_ZERO
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500145 if (num_bytes > (png_uint_32)0x8000L)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600146 {
147 png_memset(ptr, 0, (png_size_t)0x8000L);
148 png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
149 (png_size_t)(num_bytes - (png_uint_32)0x8000L));
150 }
151 else
152 {
153 png_memset(ptr, 0, (png_size_t)num_bytes);
154 }
Glenn Randers-Pehrsona4d54bd2000-07-14 08:15:12 -0500155#endif
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600156 return ((voidpf)ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500157}
158
159/* function to free memory for zlib */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500160void PNGAPI
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500161png_zfree(voidpf png_ptr, voidpf ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500162{
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600163 png_free((png_structp)png_ptr, (png_voidp)ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500164}
165
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600166/* Reset the CRC variable to 32 bits of 1's. Care must be taken
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600167 * in case CRC is > 32 bits to leave the top bits 0.
168 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500169void /* PRIVATE */
Guy Schalnat6d764711995-12-19 03:22:19 -0600170png_reset_crc(png_structp png_ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500171{
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600172 png_ptr->crc = crc32(0, Z_NULL, 0);
Guy Schalnat0d580581995-07-20 02:43:20 -0500173}
174
Andreas Dilger47a0c421997-05-16 02:46:07 -0500175/* Calculate the CRC over a section of data. We can only pass as
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600176 * much data to this routine as the largest single buffer size. We
177 * also check that this data will actually be used before going to the
178 * trouble of calculating it.
179 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500180void /* PRIVATE */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500181png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
Guy Schalnat0d580581995-07-20 02:43:20 -0500182{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500183 int need_crc = 1;
184
185 if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
186 {
187 if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
188 (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
189 need_crc = 0;
190 }
191 else /* critical */
192 {
193 if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
194 need_crc = 0;
195 }
196
197 if (need_crc)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600198 png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
Guy Schalnat0d580581995-07-20 02:43:20 -0500199}
Guy Schalnate5a37791996-06-05 15:50:50 -0500200
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600201/* Allocate the memory for an info_struct for the application. We don't
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600202 * really need the png_ptr, but it could potentially be useful in the
203 * future. This should be used in favour of malloc(sizeof(png_info))
204 * and png_info_init() so that applications that want to use a shared
205 * libpng don't have to be recompiled if png_info changes size.
206 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500207png_infop PNGAPI
Guy Schalnate5a37791996-06-05 15:50:50 -0500208png_create_info_struct(png_structp png_ptr)
209{
210 png_infop info_ptr;
211
Andreas Dilger47a0c421997-05-16 02:46:07 -0500212 png_debug(1, "in png_create_info_struct\n");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600213 if(png_ptr == NULL) return (NULL);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500214#ifdef PNG_USER_MEM_SUPPORTED
215 if ((info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
216 png_ptr->malloc_fn)) != NULL)
217#else
Guy Schalnate5a37791996-06-05 15:50:50 -0500218 if ((info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO)) != NULL)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500219#endif
Guy Schalnate5a37791996-06-05 15:50:50 -0500220 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600221 png_info_init(info_ptr);
Guy Schalnate5a37791996-06-05 15:50:50 -0500222 }
223
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600224 return (info_ptr);
Guy Schalnate5a37791996-06-05 15:50:50 -0500225}
226
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600227/* This function frees the memory associated with a single info struct.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600228 * Normally, one would use either png_destroy_read_struct() or
229 * png_destroy_write_struct() to free an info struct, but this may be
230 * useful for some applications.
231 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500232void PNGAPI
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600233png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
234{
235 png_infop info_ptr = NULL;
236
Andreas Dilger47a0c421997-05-16 02:46:07 -0500237 png_debug(1, "in png_destroy_info_struct\n");
238 if (info_ptr_ptr != NULL)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600239 info_ptr = *info_ptr_ptr;
240
Andreas Dilger47a0c421997-05-16 02:46:07 -0500241 if (info_ptr != NULL)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600242 {
243 png_info_destroy(png_ptr, info_ptr);
244
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500245#ifdef PNG_USER_MEM_SUPPORTED
246 png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn);
247#else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600248 png_destroy_struct((png_voidp)info_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500249#endif
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600250 *info_ptr_ptr = (png_infop)NULL;
251 }
252}
253
254/* Initialize the info structure. This is now an internal function (0.89)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600255 * and applications using it are urged to use png_create_info_struct()
256 * instead.
257 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500258void PNGAPI
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600259png_info_init(png_infop info_ptr)
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500260{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500261 png_debug(1, "in png_info_init\n");
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500262 /* set everything to 0 */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600263 png_memset(info_ptr, 0, sizeof (png_info));
264}
265
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500266#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500267void PNGAPI
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500268png_data_freer(png_structp png_ptr, png_infop info_ptr,
269 int freer, png_uint_32 mask)
270{
271 png_debug(1, "in png_data_freer\n");
272 if (png_ptr == NULL || info_ptr == NULL)
273 return;
274 if(freer == PNG_DESTROY_WILL_FREE_DATA)
275 info_ptr->free_me |= mask;
276 else if(freer == PNG_USER_WILL_FREE_DATA)
277 info_ptr->free_me &= ~mask;
278 else
279 png_warning(png_ptr,
280 "Unknown freer parameter in png_data_freer.");
281}
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500282#endif
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500283
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500284void PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600285png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, int num)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600286{
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500287 png_debug(1, "in png_free_data\n");
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600288 if (png_ptr == NULL || info_ptr == NULL)
289 return;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600290
291#if defined(PNG_TEXT_SUPPORTED)
292/* free text item num or (if num == -1) all text items */
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500293#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500294if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500295#else
296if (mask & PNG_FREE_TEXT)
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500297#endif
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600298{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600299 if (num != -1)
300 {
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500301 if (info_ptr->text && info_ptr->text[num].key)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600302 {
303 png_free(png_ptr, info_ptr->text[num].key);
304 info_ptr->text[num].key = NULL;
305 }
306 }
Glenn Randers-Pehrsonec61c232000-05-16 06:17:36 -0500307 else
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600308 {
Glenn Randers-Pehrsonec61c232000-05-16 06:17:36 -0500309 int i;
310 for (i = 0; i < info_ptr->num_text; i++)
311 png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
312 png_free(png_ptr, info_ptr->text);
313 info_ptr->text = NULL;
314 info_ptr->num_text=0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600315 }
316}
317#endif
318
319#if defined(PNG_tRNS_SUPPORTED)
320/* free any tRNS entry */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500321#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500322if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500323#else
324if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
325#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600326{
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500327 png_free(png_ptr, info_ptr->trans);
328 info_ptr->valid &= ~PNG_INFO_tRNS;
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500329 info_ptr->trans = NULL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600330}
331#endif
332
333#if defined(PNG_sCAL_SUPPORTED)
334/* free any sCAL entry */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500335#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500336if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500337#else
338if (mask & PNG_FREE_SCAL)
339#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600340{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600341#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500342 png_free(png_ptr, info_ptr->scal_s_width);
343 png_free(png_ptr, info_ptr->scal_s_height);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500344 info_ptr->scal_s_width = NULL;
345 info_ptr->scal_s_height = NULL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600346#endif
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500347 info_ptr->valid &= ~PNG_INFO_sCAL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600348}
349#endif
350
351#if defined(PNG_pCAL_SUPPORTED)
352/* free any pCAL entry */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500353#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500354if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500355#else
356if (mask & PNG_FREE_PCAL)
357#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600358{
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500359 png_free(png_ptr, info_ptr->pcal_purpose);
360 png_free(png_ptr, info_ptr->pcal_units);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500361 info_ptr->pcal_purpose = NULL;
362 info_ptr->pcal_units = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500363 if (info_ptr->pcal_params != NULL)
364 {
365 int i;
366 for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500367 {
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500368 png_free(png_ptr, info_ptr->pcal_params[i]);
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500369 info_ptr->pcal_params[i]=NULL;
370 }
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500371 png_free(png_ptr, info_ptr->pcal_params);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500372 info_ptr->pcal_params = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500373 }
374 info_ptr->valid &= ~PNG_INFO_pCAL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600375}
376#endif
377
378#if defined(PNG_iCCP_SUPPORTED)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600379/* free any iCCP entry */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500380#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500381if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500382#else
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600383if (mask & PNG_FREE_ICCP)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500384#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600385{
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500386 png_free(png_ptr, info_ptr->iccp_name);
387 png_free(png_ptr, info_ptr->iccp_profile);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500388 info_ptr->iccp_name = NULL;
389 info_ptr->iccp_profile = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500390 info_ptr->valid &= ~PNG_INFO_iCCP;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600391}
392#endif
393
394#if defined(PNG_sPLT_SUPPORTED)
395/* free a given sPLT entry, or (if num == -1) all sPLT entries */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500396#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500397if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500398#else
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600399if (mask & PNG_FREE_SPLT)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500400#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600401{
402 if (num != -1)
403 {
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500404 if(info_ptr->splt_palettes)
405 {
406 png_free(png_ptr, info_ptr->splt_palettes[num].name);
407 png_free(png_ptr, info_ptr->splt_palettes[num].entries);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500408 info_ptr->splt_palettes[num].name = NULL;
409 info_ptr->splt_palettes[num].entries = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500410 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600411 }
412 else
413 {
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600414 if(info_ptr->splt_palettes_num)
415 {
416 int i;
417 for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
418 png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600419
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600420 png_free(png_ptr, info_ptr->splt_palettes);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500421 info_ptr->splt_palettes = NULL;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600422 info_ptr->splt_palettes_num = 0;
423 }
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500424 info_ptr->valid &= ~PNG_INFO_sPLT;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600425 }
426}
427#endif
428
429#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500430#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500431if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500432#else
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600433if (mask & PNG_FREE_UNKN)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500434#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600435{
436 if (num != -1)
437 {
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500438 if(info_ptr->unknown_chunks)
439 {
440 png_free(png_ptr, info_ptr->unknown_chunks[num].data);
441 info_ptr->unknown_chunks[num].data = NULL;
442 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600443 }
444 else
445 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600446 int i;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600447
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600448 if(info_ptr->unknown_chunks_num)
449 {
450 for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
451 png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600452
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600453 png_free(png_ptr, info_ptr->unknown_chunks);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500454 info_ptr->unknown_chunks = NULL;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600455 info_ptr->unknown_chunks_num = 0;
456 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600457 }
458}
459#endif
460
461#if defined(PNG_hIST_SUPPORTED)
462/* free any hIST entry */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500463#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500464if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500465#else
466if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
467#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600468{
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500469 png_free(png_ptr, info_ptr->hist);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500470 info_ptr->hist = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500471 info_ptr->valid &= ~PNG_INFO_hIST;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600472}
473#endif
474
475/* free any PLTE entry that was internally allocated */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500476#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500477if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500478#else
479if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
480#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600481{
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500482 png_zfree(png_ptr, info_ptr->palette);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500483 info_ptr->palette = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500484 info_ptr->valid &= ~PNG_INFO_PLTE;
485 info_ptr->num_palette = 0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600486}
487
488#if defined(PNG_INFO_IMAGE_SUPPORTED)
489/* free any image bits attached to the info structure */
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500490#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500491if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500492#else
493if (mask & PNG_FREE_ROWS)
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500494#endif
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500495{
496 if(info_ptr->row_pointers)
497 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600498 int row;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600499 for (row = 0; row < (int)info_ptr->height; row++)
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500500 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600501 png_free(png_ptr, info_ptr->row_pointers[row]);
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500502 info_ptr->row_pointers[row]=NULL;
503 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600504 png_free(png_ptr, info_ptr->row_pointers);
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500505 info_ptr->row_pointers=NULL;
506 }
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500507 info_ptr->valid &= ~PNG_INFO_IDAT;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600508}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600509#endif
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500510
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500511#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600512 if(num == -1)
513 info_ptr->free_me &= ~mask;
Glenn Randers-Pehrsonec61c232000-05-16 06:17:36 -0500514 else
515 info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500516#endif
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600517}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600518
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600519/* This is an internal routine to free any memory that the info struct is
Andreas Dilger47a0c421997-05-16 02:46:07 -0500520 * pointing to before re-using it or freeing the struct itself. Recall
521 * that png_free() checks for NULL pointers for us.
522 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500523void /* PRIVATE */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600524png_info_destroy(png_structp png_ptr, png_infop info_ptr)
525{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500526 png_debug(1, "in png_info_destroy\n");
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600527
528 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -0600529
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500530#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600531 if (png_ptr->num_chunk_list)
532 {
533 png_free(png_ptr, png_ptr->chunk_list);
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500534 png_ptr->chunk_list=NULL;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600535 png_ptr->num_chunk_list=0;
536 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600537#endif
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600538
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600539 png_info_init(info_ptr);
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500540}
Guy Schalnat0d580581995-07-20 02:43:20 -0500541
Guy Schalnate5a37791996-06-05 15:50:50 -0500542/* This function returns a pointer to the io_ptr associated with the user
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600543 * functions. The application should free any memory associated with this
544 * pointer before png_write_destroy() or png_read_destroy() are called.
545 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500546png_voidp PNGAPI
Guy Schalnate5a37791996-06-05 15:50:50 -0500547png_get_io_ptr(png_structp png_ptr)
548{
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600549 return (png_ptr->io_ptr);
Guy Schalnate5a37791996-06-05 15:50:50 -0500550}
Andreas Dilger47a0c421997-05-16 02:46:07 -0500551
552#if !defined(PNG_NO_STDIO)
553/* Initialize the default input/output functions for the PNG file. If you
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600554 * use your own read or write routines, you can call either png_set_read_fn()
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500555 * or png_set_write_fn() instead of png_init_io(). If you have defined
556 * PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't
557 * necessarily available.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600558 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500559void PNGAPI
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500560png_init_io(png_structp png_ptr, png_FILE_p fp)
Guy Schalnate5a37791996-06-05 15:50:50 -0500561{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500562 png_debug(1, "in png_init_io\n");
Guy Schalnate5a37791996-06-05 15:50:50 -0500563 png_ptr->io_ptr = (png_voidp)fp;
564}
Andreas Dilger47a0c421997-05-16 02:46:07 -0500565#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500566
567#if defined(PNG_TIME_RFC1123_SUPPORTED)
568/* Convert the supplied time into an RFC 1123 string suitable for use in
569 * a "Creation Time" or other text-based time string.
570 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500571png_charp PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500572png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
573{
574 static PNG_CONST char short_months[12][4] =
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600575 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
576 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500577
578 if (png_ptr->time_buffer == NULL)
579 {
580 png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
581 sizeof(char)));
582 }
583
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500584#if defined(_WIN32_WCE)
585 {
586 wchar_t time_buf[29];
587 wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
588 ptime->day % 32, short_months[(ptime->month - 1) % 12],
589 ptime->year, ptime->hour % 24, ptime->minute % 60,
590 ptime->second % 61);
591 WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
592 NULL, NULL);
593 }
594#else
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500595#ifdef USE_FAR_KEYWORD
596 {
597 char near_time_buf[29];
598 sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000",
599 ptime->day % 32, short_months[(ptime->month - 1) % 12],
600 ptime->year, ptime->hour % 24, ptime->minute % 60,
601 ptime->second % 61);
602 png_memcpy(png_ptr->time_buffer, near_time_buf,
603 29*sizeof(char));
604 }
605#else
606 sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
607 ptime->day % 32, short_months[(ptime->month - 1) % 12],
608 ptime->year, ptime->hour % 24, ptime->minute % 60,
609 ptime->second % 61);
610#endif
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500611#endif /* _WIN32_WCE */
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500612 return ((png_charp)png_ptr->time_buffer);
613}
614#endif /* PNG_TIME_RFC1123_SUPPORTED */
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600615
Glenn Randers-Pehrson81fdf8a2000-04-07 10:34:56 -0500616#if 0
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600617/* Signature string for a PNG file. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500618png_bytep PNGAPI
Glenn Randers-Pehrson81fdf8a2000-04-07 10:34:56 -0500619png_sig_bytes(void)
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600620{
Glenn Randers-Pehrson81fdf8a2000-04-07 10:34:56 -0500621 return ((png_bytep)"\211\120\116\107\015\012\032\012");
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600622}
Glenn Randers-Pehrson81fdf8a2000-04-07 10:34:56 -0500623#endif
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600624
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500625png_charp PNGAPI
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600626png_get_copyright(png_structp png_ptr)
627{
Glenn Randers-Pehrson860ab2b1999-10-14 07:43:10 -0500628 if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -0600629 return ((png_charp) "\n libpng version 1.0.9beta3 - November 23, 2000\n\
Glenn Randers-Pehrsonf5ed0e12000-11-18 18:19:14 -0600630 Copyright (c) 1998-2000 Glenn Randers-Pehrson\n\
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600631 Copyright (c) 1996, 1997 Andreas Dilger\n\
Glenn Randers-Pehrsond4366722000-06-04 14:29:29 -0500632 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n");
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500633 return ((png_charp) "");
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600634}
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500635
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600636/* The following return the library version as a short string in the
637 * format 1.0.0 through 99.99.99zz. To get the version of *.h files used
638 * with your application, print out PNG_LIBPNG_VER_STRING, which is defined
639 * in png.h.
640 */
641
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500642png_charp PNGAPI
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600643png_get_libpng_ver(png_structp png_ptr)
644{
645 /* Version of *.c files used when building libpng */
646 if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -0600647 return((png_charp) "1.0.9beta3");
648 return((png_charp) "1.0.9beta3");
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600649}
650
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500651png_charp PNGAPI
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600652png_get_header_ver(png_structp png_ptr)
653{
654 /* Version of *.h files used when building libpng */
655 if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500656 return((png_charp) PNG_LIBPNG_VER_STRING);
657 return((png_charp) PNG_LIBPNG_VER_STRING);
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600658}
659
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500660png_charp PNGAPI
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600661png_get_header_version(png_structp png_ptr)
662{
663 /* Returns longer string containing both version and date */
664 if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500665 return((png_charp) PNG_HEADER_VERSION_STRING);
666 return((png_charp) PNG_HEADER_VERSION_STRING);
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600667}
668
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600669#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500670int PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600671png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
672{
673 /* check chunk_name and return "keep" value if it's on the list, else 0 */
674 int i;
675 png_bytep p;
676 if((png_ptr == NULL && chunk_name == NULL) || png_ptr->num_chunk_list<=0)
677 return 0;
678 p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
679 for (i = png_ptr->num_chunk_list; i; i--, p-=5)
680 if (!png_memcmp(chunk_name, p, 4))
681 return ((int)*(p+4));
682 return 0;
683}
684#endif
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500685
686/* This function, added to libpng-1.0.6g, is untested. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500687int PNGAPI
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500688png_reset_zstream(png_structp png_ptr)
689{
690 return (inflateReset(&png_ptr->zstream));
691}
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500692
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600693/* This function was added to libpng-1.0.7 */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500694png_uint_32 PNGAPI
695png_access_version_number(void)
696{
697 /* Version of *.c files used when building libpng */
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600698 return((png_uint_32) 10009L);
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500699}