blob: 3cf55b2881fff207499c99e50cd0f931e349d69a [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-Pehrsonc1bfe682002-03-06 22:08:00 -06004 * libpng version 1.2.2beta3 - March 7, 2002
Glenn Randers-Pehrsonc6de22d2002-02-23 18:55:25 -06005 * Copyright (c) 1998-2002 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-Pehrsonc1bfe682002-03-06 22:08:00 -060016typedef version_1_2_2beta3 Your_png_h_is_not_version_1_2_2beta3;
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-Pehrsonc1bfe682002-03-06 22:08:00 -060023const char png_libpng_ver[18] = "1.2.2beta3";
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-Pehrsonc1bfe682002-03-06 22:08:00 -0600138voidpf 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;
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600142 png_voidp ptr;
143 png_structp p=png_ptr;
144 png_uint_32 save_flags=p->flags;
145
146 p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
147 ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
148 p->flags=save_flags;
Guy Schalnat6d764711995-12-19 03:22:19 -0600149
Glenn Randers-Pehrsona4d54bd2000-07-14 08:15:12 -0500150#ifndef PNG_NO_ZALLOC_ZERO
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -0500151 if (num_bytes > (png_uint_32)0x8000L)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600152 {
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -0500153 png_memset(ptr, 0, (png_size_t)0x8000L);
154 png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
155 (png_size_t)(num_bytes - (png_uint_32)0x8000L));
156 }
157 else
158 {
159 png_memset(ptr, 0, (png_size_t)num_bytes);
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600160 }
Glenn Randers-Pehrsona4d54bd2000-07-14 08:15:12 -0500161#endif
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600162 return ((voidpf)ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500163}
164
165/* function to free memory for zlib */
Glenn Randers-Pehrsonc1bfe682002-03-06 22:08:00 -0600166void PNGAPI
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500167png_zfree(voidpf png_ptr, voidpf ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500168{
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600169 png_free((png_structp)png_ptr, (png_voidp)ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500170}
171
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600172/* Reset the CRC variable to 32 bits of 1's. Care must be taken
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600173 * in case CRC is > 32 bits to leave the top bits 0.
174 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500175void /* PRIVATE */
Guy Schalnat6d764711995-12-19 03:22:19 -0600176png_reset_crc(png_structp png_ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500177{
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600178 png_ptr->crc = crc32(0, Z_NULL, 0);
Guy Schalnat0d580581995-07-20 02:43:20 -0500179}
180
Andreas Dilger47a0c421997-05-16 02:46:07 -0500181/* Calculate the CRC over a section of data. We can only pass as
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600182 * much data to this routine as the largest single buffer size. We
183 * also check that this data will actually be used before going to the
184 * trouble of calculating it.
185 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500186void /* PRIVATE */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500187png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
Guy Schalnat0d580581995-07-20 02:43:20 -0500188{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500189 int need_crc = 1;
190
191 if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
192 {
193 if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
194 (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
195 need_crc = 0;
196 }
197 else /* critical */
198 {
199 if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
200 need_crc = 0;
201 }
202
203 if (need_crc)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600204 png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
Guy Schalnat0d580581995-07-20 02:43:20 -0500205}
Guy Schalnate5a37791996-06-05 15:50:50 -0500206
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600207/* Allocate the memory for an info_struct for the application. We don't
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600208 * really need the png_ptr, but it could potentially be useful in the
209 * future. This should be used in favour of malloc(sizeof(png_info))
210 * and png_info_init() so that applications that want to use a shared
211 * libpng don't have to be recompiled if png_info changes size.
212 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500213png_infop PNGAPI
Guy Schalnate5a37791996-06-05 15:50:50 -0500214png_create_info_struct(png_structp png_ptr)
215{
216 png_infop info_ptr;
217
Andreas Dilger47a0c421997-05-16 02:46:07 -0500218 png_debug(1, "in png_create_info_struct\n");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600219 if(png_ptr == NULL) return (NULL);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500220#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson5cded0b2001-11-07 07:10:08 -0600221 info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
222 png_ptr->malloc_fn, png_ptr->mem_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500223#else
Glenn Randers-Pehrson5cded0b2001-11-07 07:10:08 -0600224 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500225#endif
Glenn Randers-Pehrson5cded0b2001-11-07 07:10:08 -0600226 if (info_ptr != NULL)
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500227 png_info_init_3(&info_ptr, sizeof(png_info));
Guy Schalnate5a37791996-06-05 15:50:50 -0500228
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600229 return (info_ptr);
Guy Schalnate5a37791996-06-05 15:50:50 -0500230}
231
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600232/* This function frees the memory associated with a single info struct.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600233 * Normally, one would use either png_destroy_read_struct() or
234 * png_destroy_write_struct() to free an info struct, but this may be
235 * useful for some applications.
236 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500237void PNGAPI
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600238png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
239{
240 png_infop info_ptr = NULL;
241
Andreas Dilger47a0c421997-05-16 02:46:07 -0500242 png_debug(1, "in png_destroy_info_struct\n");
243 if (info_ptr_ptr != NULL)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600244 info_ptr = *info_ptr_ptr;
245
Andreas Dilger47a0c421997-05-16 02:46:07 -0500246 if (info_ptr != NULL)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600247 {
248 png_info_destroy(png_ptr, info_ptr);
249
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500250#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500251 png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
252 png_ptr->mem_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500253#else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600254 png_destroy_struct((png_voidp)info_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500255#endif
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -0500256 *info_ptr_ptr = NULL;
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600257 }
258}
259
260/* Initialize the info structure. This is now an internal function (0.89)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600261 * and applications using it are urged to use png_create_info_struct()
262 * instead.
263 */
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500264#undef png_info_init
265void PNGAPI
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600266png_info_init(png_infop info_ptr)
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500267{
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500268 /* We only come here via pre-1.0.12-compiled applications */
269 png_info_init_3(&info_ptr, 0);
270}
271
272void PNGAPI
273png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
274{
275 png_infop info_ptr = *ptr_ptr;
276
277 png_debug(1, "in png_info_init_3\n");
278
279 if(sizeof(png_info) > png_info_struct_size)
280 {
281 png_destroy_struct(info_ptr);
282 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
283 *ptr_ptr = info_ptr;
284 }
285
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500286 /* set everything to 0 */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600287 png_memset(info_ptr, 0, sizeof (png_info));
288}
289
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500290#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500291void PNGAPI
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500292png_data_freer(png_structp png_ptr, png_infop info_ptr,
293 int freer, png_uint_32 mask)
294{
295 png_debug(1, "in png_data_freer\n");
296 if (png_ptr == NULL || info_ptr == NULL)
297 return;
298 if(freer == PNG_DESTROY_WILL_FREE_DATA)
299 info_ptr->free_me |= mask;
300 else if(freer == PNG_USER_WILL_FREE_DATA)
301 info_ptr->free_me &= ~mask;
302 else
303 png_warning(png_ptr,
304 "Unknown freer parameter in png_data_freer.");
305}
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500306#endif
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500307
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500308void PNGAPI
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -0500309png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
310 int num)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600311{
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500312 png_debug(1, "in png_free_data\n");
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600313 if (png_ptr == NULL || info_ptr == NULL)
314 return;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600315
316#if defined(PNG_TEXT_SUPPORTED)
317/* free text item num or (if num == -1) all text items */
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500318#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500319if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500320#else
321if (mask & PNG_FREE_TEXT)
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500322#endif
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600323{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600324 if (num != -1)
325 {
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500326 if (info_ptr->text && info_ptr->text[num].key)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600327 {
328 png_free(png_ptr, info_ptr->text[num].key);
329 info_ptr->text[num].key = NULL;
330 }
331 }
Glenn Randers-Pehrsonec61c232000-05-16 06:17:36 -0500332 else
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600333 {
Glenn Randers-Pehrsonec61c232000-05-16 06:17:36 -0500334 int i;
335 for (i = 0; i < info_ptr->num_text; i++)
336 png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
337 png_free(png_ptr, info_ptr->text);
338 info_ptr->text = NULL;
339 info_ptr->num_text=0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600340 }
341}
342#endif
343
344#if defined(PNG_tRNS_SUPPORTED)
345/* free any tRNS entry */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500346#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500347if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500348#else
349if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
350#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600351{
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500352 png_free(png_ptr, info_ptr->trans);
353 info_ptr->valid &= ~PNG_INFO_tRNS;
Glenn Randers-Pehrsonc1bfe682002-03-06 22:08:00 -0600354#ifndef PNG_FREE_ME_SUPPORTED
355 png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
356#endif
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500357 info_ptr->trans = NULL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600358}
359#endif
360
361#if defined(PNG_sCAL_SUPPORTED)
362/* free any sCAL entry */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500363#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500364if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500365#else
366if (mask & PNG_FREE_SCAL)
367#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600368{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600369#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500370 png_free(png_ptr, info_ptr->scal_s_width);
371 png_free(png_ptr, info_ptr->scal_s_height);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500372 info_ptr->scal_s_width = NULL;
373 info_ptr->scal_s_height = NULL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600374#endif
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500375 info_ptr->valid &= ~PNG_INFO_sCAL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600376}
377#endif
378
379#if defined(PNG_pCAL_SUPPORTED)
380/* free any pCAL entry */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500381#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500382if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500383#else
384if (mask & PNG_FREE_PCAL)
385#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600386{
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500387 png_free(png_ptr, info_ptr->pcal_purpose);
388 png_free(png_ptr, info_ptr->pcal_units);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500389 info_ptr->pcal_purpose = NULL;
390 info_ptr->pcal_units = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500391 if (info_ptr->pcal_params != NULL)
392 {
393 int i;
394 for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500395 {
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500396 png_free(png_ptr, info_ptr->pcal_params[i]);
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500397 info_ptr->pcal_params[i]=NULL;
398 }
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500399 png_free(png_ptr, info_ptr->pcal_params);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500400 info_ptr->pcal_params = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500401 }
402 info_ptr->valid &= ~PNG_INFO_pCAL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600403}
404#endif
405
406#if defined(PNG_iCCP_SUPPORTED)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600407/* free any iCCP entry */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500408#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500409if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500410#else
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600411if (mask & PNG_FREE_ICCP)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500412#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600413{
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500414 png_free(png_ptr, info_ptr->iccp_name);
415 png_free(png_ptr, info_ptr->iccp_profile);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500416 info_ptr->iccp_name = NULL;
417 info_ptr->iccp_profile = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500418 info_ptr->valid &= ~PNG_INFO_iCCP;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600419}
420#endif
421
422#if defined(PNG_sPLT_SUPPORTED)
423/* free a given sPLT entry, or (if num == -1) all sPLT entries */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500424#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500425if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500426#else
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600427if (mask & PNG_FREE_SPLT)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500428#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600429{
430 if (num != -1)
431 {
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500432 if(info_ptr->splt_palettes)
433 {
434 png_free(png_ptr, info_ptr->splt_palettes[num].name);
435 png_free(png_ptr, info_ptr->splt_palettes[num].entries);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500436 info_ptr->splt_palettes[num].name = NULL;
437 info_ptr->splt_palettes[num].entries = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500438 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600439 }
440 else
441 {
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600442 if(info_ptr->splt_palettes_num)
443 {
444 int i;
445 for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
446 png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600447
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600448 png_free(png_ptr, info_ptr->splt_palettes);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500449 info_ptr->splt_palettes = NULL;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600450 info_ptr->splt_palettes_num = 0;
451 }
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500452 info_ptr->valid &= ~PNG_INFO_sPLT;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600453 }
454}
455#endif
456
457#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
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_UNKN) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500460#else
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600461if (mask & PNG_FREE_UNKN)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500462#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600463{
464 if (num != -1)
465 {
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500466 if(info_ptr->unknown_chunks)
467 {
468 png_free(png_ptr, info_ptr->unknown_chunks[num].data);
469 info_ptr->unknown_chunks[num].data = NULL;
470 }
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600471 }
472 else
473 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600474 int i;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600475
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600476 if(info_ptr->unknown_chunks_num)
477 {
478 for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
479 png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600480
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600481 png_free(png_ptr, info_ptr->unknown_chunks);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500482 info_ptr->unknown_chunks = NULL;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600483 info_ptr->unknown_chunks_num = 0;
484 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600485 }
486}
487#endif
488
489#if defined(PNG_hIST_SUPPORTED)
490/* free any hIST entry */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500491#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500492if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500493#else
494if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
495#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600496{
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500497 png_free(png_ptr, info_ptr->hist);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500498 info_ptr->hist = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500499 info_ptr->valid &= ~PNG_INFO_hIST;
Glenn Randers-Pehrsonc1bfe682002-03-06 22:08:00 -0600500#ifndef PNG_FREE_ME_SUPPORTED
501 png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
502#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600503}
504#endif
505
506/* free any PLTE entry that was internally allocated */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500507#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500508if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500509#else
510if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
511#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600512{
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500513 png_zfree(png_ptr, info_ptr->palette);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500514 info_ptr->palette = NULL;
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500515 info_ptr->valid &= ~PNG_INFO_PLTE;
Glenn Randers-Pehrsonc1bfe682002-03-06 22:08:00 -0600516#ifndef PNG_FREE_ME_SUPPORTED
517 png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
518#endif
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500519 info_ptr->num_palette = 0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600520}
521
522#if defined(PNG_INFO_IMAGE_SUPPORTED)
523/* free any image bits attached to the info structure */
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500524#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500525if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500526#else
527if (mask & PNG_FREE_ROWS)
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500528#endif
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500529{
530 if(info_ptr->row_pointers)
531 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600532 int row;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600533 for (row = 0; row < (int)info_ptr->height; row++)
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500534 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600535 png_free(png_ptr, info_ptr->row_pointers[row]);
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500536 info_ptr->row_pointers[row]=NULL;
537 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600538 png_free(png_ptr, info_ptr->row_pointers);
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500539 info_ptr->row_pointers=NULL;
540 }
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500541 info_ptr->valid &= ~PNG_INFO_IDAT;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600542}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600543#endif
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500544
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500545#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600546 if(num == -1)
547 info_ptr->free_me &= ~mask;
Glenn Randers-Pehrsonec61c232000-05-16 06:17:36 -0500548 else
549 info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500550#endif
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600551}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600552
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600553/* This is an internal routine to free any memory that the info struct is
Andreas Dilger47a0c421997-05-16 02:46:07 -0500554 * pointing to before re-using it or freeing the struct itself. Recall
555 * that png_free() checks for NULL pointers for us.
556 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500557void /* PRIVATE */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600558png_info_destroy(png_structp png_ptr, png_infop info_ptr)
559{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500560 png_debug(1, "in png_info_destroy\n");
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600561
562 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -0600563
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500564#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600565 if (png_ptr->num_chunk_list)
566 {
567 png_free(png_ptr, png_ptr->chunk_list);
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -0500568 png_ptr->chunk_list=NULL;
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600569 png_ptr->num_chunk_list=0;
570 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600571#endif
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600572
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500573 png_info_init_3(&info_ptr, sizeof(png_info));
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500574}
Guy Schalnat0d580581995-07-20 02:43:20 -0500575
Guy Schalnate5a37791996-06-05 15:50:50 -0500576/* This function returns a pointer to the io_ptr associated with the user
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600577 * functions. The application should free any memory associated with this
578 * pointer before png_write_destroy() or png_read_destroy() are called.
579 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500580png_voidp PNGAPI
Guy Schalnate5a37791996-06-05 15:50:50 -0500581png_get_io_ptr(png_structp png_ptr)
582{
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600583 return (png_ptr->io_ptr);
Guy Schalnate5a37791996-06-05 15:50:50 -0500584}
Andreas Dilger47a0c421997-05-16 02:46:07 -0500585
586#if !defined(PNG_NO_STDIO)
587/* Initialize the default input/output functions for the PNG file. If you
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600588 * use your own read or write routines, you can call either png_set_read_fn()
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500589 * or png_set_write_fn() instead of png_init_io(). If you have defined
590 * PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't
591 * necessarily available.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600592 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500593void PNGAPI
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500594png_init_io(png_structp png_ptr, png_FILE_p fp)
Guy Schalnate5a37791996-06-05 15:50:50 -0500595{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500596 png_debug(1, "in png_init_io\n");
Guy Schalnate5a37791996-06-05 15:50:50 -0500597 png_ptr->io_ptr = (png_voidp)fp;
598}
Andreas Dilger47a0c421997-05-16 02:46:07 -0500599#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500600
601#if defined(PNG_TIME_RFC1123_SUPPORTED)
602/* Convert the supplied time into an RFC 1123 string suitable for use in
603 * a "Creation Time" or other text-based time string.
604 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500605png_charp PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500606png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
607{
608 static PNG_CONST char short_months[12][4] =
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600609 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
610 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500611
612 if (png_ptr->time_buffer == NULL)
613 {
614 png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
615 sizeof(char)));
616 }
617
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500618#if defined(_WIN32_WCE)
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -0500619 {
620 wchar_t time_buf[29];
621 wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
622 ptime->day % 32, short_months[(ptime->month - 1) % 12],
623 ptime->year, ptime->hour % 24, ptime->minute % 60,
624 ptime->second % 61);
625 WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
626 NULL, NULL);
627 }
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500628#else
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500629#ifdef USE_FAR_KEYWORD
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -0500630 {
631 char near_time_buf[29];
632 sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000",
633 ptime->day % 32, short_months[(ptime->month - 1) % 12],
634 ptime->year, ptime->hour % 24, ptime->minute % 60,
635 ptime->second % 61);
636 png_memcpy(png_ptr->time_buffer, near_time_buf,
637 29*sizeof(char));
638 }
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500639#else
640 sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
Glenn Randers-Pehrsone1eff582001-04-14 20:15:41 -0500641 ptime->day % 32, short_months[(ptime->month - 1) % 12],
642 ptime->year, ptime->hour % 24, ptime->minute % 60,
643 ptime->second % 61);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500644#endif
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500645#endif /* _WIN32_WCE */
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500646 return ((png_charp)png_ptr->time_buffer);
647}
648#endif /* PNG_TIME_RFC1123_SUPPORTED */
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600649
Glenn Randers-Pehrson81fdf8a2000-04-07 10:34:56 -0500650#if 0
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600651/* Signature string for a PNG file. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500652png_bytep PNGAPI
Glenn Randers-Pehrson81fdf8a2000-04-07 10:34:56 -0500653png_sig_bytes(void)
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600654{
Glenn Randers-Pehrson81fdf8a2000-04-07 10:34:56 -0500655 return ((png_bytep)"\211\120\116\107\015\012\032\012");
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600656}
Glenn Randers-Pehrson81fdf8a2000-04-07 10:34:56 -0500657#endif
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600658
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500659png_charp PNGAPI
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600660png_get_copyright(png_structp png_ptr)
661{
Glenn Randers-Pehrson860ab2b1999-10-14 07:43:10 -0500662 if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
Glenn Randers-Pehrsonc1bfe682002-03-06 22:08:00 -0600663 return ((png_charp) "\n libpng version 1.2.2beta3 - March 7, 2002\n\
Glenn Randers-Pehrsonc6de22d2002-02-23 18:55:25 -0600664 Copyright (c) 1998-2002 Glenn Randers-Pehrson\n\
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600665 Copyright (c) 1996, 1997 Andreas Dilger\n\
Glenn Randers-Pehrsond4366722000-06-04 14:29:29 -0500666 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n");
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500667 return ((png_charp) "");
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600668}
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500669
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600670/* The following return the library version as a short string in the
671 * format 1.0.0 through 99.99.99zz. To get the version of *.h files used
672 * with your application, print out PNG_LIBPNG_VER_STRING, which is defined
673 * in png.h.
674 */
675
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500676png_charp PNGAPI
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600677png_get_libpng_ver(png_structp png_ptr)
678{
679 /* Version of *.c files used when building libpng */
680 if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
Glenn Randers-Pehrsonc1bfe682002-03-06 22:08:00 -0600681 return((png_charp) "1.2.2beta3");
682 return((png_charp) "1.2.2beta3");
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600683}
684
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500685png_charp PNGAPI
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600686png_get_header_ver(png_structp png_ptr)
687{
688 /* Version of *.h files used when building libpng */
689 if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500690 return((png_charp) PNG_LIBPNG_VER_STRING);
691 return((png_charp) PNG_LIBPNG_VER_STRING);
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600692}
693
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500694png_charp PNGAPI
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600695png_get_header_version(png_structp png_ptr)
696{
697 /* Returns longer string containing both version and date */
698 if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500699 return((png_charp) PNG_HEADER_VERSION_STRING);
700 return((png_charp) PNG_HEADER_VERSION_STRING);
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600701}
702
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600703#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
Glenn Randers-Pehrsonc1bfe682002-03-06 22:08:00 -0600704int PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600705png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
706{
707 /* check chunk_name and return "keep" value if it's on the list, else 0 */
708 int i;
709 png_bytep p;
710 if((png_ptr == NULL && chunk_name == NULL) || png_ptr->num_chunk_list<=0)
711 return 0;
712 p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
713 for (i = png_ptr->num_chunk_list; i; i--, p-=5)
714 if (!png_memcmp(chunk_name, p, 4))
715 return ((int)*(p+4));
716 return 0;
717}
718#endif
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500719
720/* This function, added to libpng-1.0.6g, is untested. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500721int PNGAPI
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500722png_reset_zstream(png_structp png_ptr)
723{
724 return (inflateReset(&png_ptr->zstream));
725}
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500726
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600727/* This function was added to libpng-1.0.7 */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500728png_uint_32 PNGAPI
729png_access_version_number(void)
730{
731 /* Version of *.c files used when building libpng */
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600732 return((png_uint_32) 10202L);
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -0500733}
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -0600734
Glenn Randers-Pehrson1fd5fb32001-05-06 05:34:26 -0500735
736#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
737 /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */
738/* this INTERNAL function was added to libpng 1.2.0 */
739void /* PRIVATE */
740png_init_mmx_flags (png_structp png_ptr)
741{
742 png_ptr->mmx_rowbytes_threshold = 0;
743 png_ptr->mmx_bitdepth_threshold = 0;
744
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500745# if (defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD))
Glenn Randers-Pehrson1fd5fb32001-05-06 05:34:26 -0500746
747 png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_COMPILED;
748
749 if (png_mmx_support()) {
750 png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500751# ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
Glenn Randers-Pehrson1fd5fb32001-05-06 05:34:26 -0500752 | PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500753# endif
754# ifdef PNG_HAVE_ASSEMBLER_READ_INTERLACE
Glenn Randers-Pehrson1fd5fb32001-05-06 05:34:26 -0500755 | PNG_ASM_FLAG_MMX_READ_INTERLACE
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500756# endif
757# ifndef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
Glenn Randers-Pehrson1fd5fb32001-05-06 05:34:26 -0500758 ;
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500759# else
Glenn Randers-Pehrson1fd5fb32001-05-06 05:34:26 -0500760 | PNG_ASM_FLAG_MMX_READ_FILTER_SUB
761 | PNG_ASM_FLAG_MMX_READ_FILTER_UP
762 | PNG_ASM_FLAG_MMX_READ_FILTER_AVG
763 | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
764
765 png_ptr->mmx_rowbytes_threshold = PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT;
766 png_ptr->mmx_bitdepth_threshold = PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT;
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500767# endif
Glenn Randers-Pehrson1fd5fb32001-05-06 05:34:26 -0500768 } else {
769 png_ptr->asm_flags &= ~( PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
770 | PNG_MMX_READ_FLAGS
771 | PNG_MMX_WRITE_FLAGS );
772 }
773
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500774# else /* !((PNGVCRD || PNGGCCRD) && PNG_ASSEMBLER_CODE_SUPPORTED)) */
Glenn Randers-Pehrson1fd5fb32001-05-06 05:34:26 -0500775
776 /* clear all MMX flags; no support is compiled in */
777 png_ptr->asm_flags &= ~( PNG_MMX_FLAGS );
778
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500779# endif /* ?(PNGVCRD || PNGGCCRD) */
Glenn Randers-Pehrson1fd5fb32001-05-06 05:34:26 -0500780}
781
782#endif /* !(PNG_ASSEMBLER_CODE_SUPPORTED) */
783
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500784/* this function was added to libpng 1.2.0 */
785#if !defined(PNG_USE_PNGGCCRD) && \
786 !(defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD))
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -0600787int PNGAPI
788png_mmx_support(void)
789{
790 return -1;
791}
792#endif