blob: 4c9050b3bd565a393392e783dcc2f35828c842fa [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-Pehrson074af5e1999-11-28 23:32:18 -06004 * libpng version 1.0.5d - November 29, 1999
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-Pehrson87544ac1999-01-13 22:06:39 -06007 * Copyright (c) 1998, 1999 Glenn Randers-Pehrson
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -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
Andreas Dilger47a0c421997-05-16 02:46:07 -050015/* Version information for C files. This had better match the version
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060016 * string defined in png.h.
17 */
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -060018
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -060019#ifdef PNG_USE_GLOBAL_ARRAYS
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -060020/* png_libpng_ver was changed to a function in version 1.0.5c */
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -060021char png_libpng_ver[12] = "1.0.5d";
Guy Schalnat51f0eb41995-09-26 05:22:39 -050022
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -060023/* png_sig was changed to a function in version 1.0.5c */
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060024/* Place to hold the signature string for a PNG file. */
Guy Schalnat6d764711995-12-19 03:22:19 -060025png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -060026
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -060027/* Invoke global declarations for constant strings for known chunk types */
28PNG_IHDR;
29PNG_IDAT;
30PNG_IEND;
31PNG_PLTE;
32PNG_bKGD;
33PNG_cHRM;
34PNG_gAMA;
35PNG_hIST;
36PNG_oFFs;
37PNG_pCAL;
38PNG_pHYs;
39PNG_sBIT;
40PNG_sRGB;
41PNG_tEXt;
42PNG_tIME;
43PNG_tRNS;
44PNG_zTXt;
Guy Schalnat0d580581995-07-20 02:43:20 -050045
46/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
47
48/* start of interlace block */
Guy Schalnat6d764711995-12-19 03:22:19 -060049int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
Guy Schalnat0d580581995-07-20 02:43:20 -050050
51/* offset to next interlace block */
Guy Schalnat6d764711995-12-19 03:22:19 -060052int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
Guy Schalnat0d580581995-07-20 02:43:20 -050053
54/* start of interlace block in the y direction */
Guy Schalnat6d764711995-12-19 03:22:19 -060055int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
Guy Schalnat0d580581995-07-20 02:43:20 -050056
57/* offset to next interlace block in the y direction */
Guy Schalnat6d764711995-12-19 03:22:19 -060058int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
Guy Schalnat0d580581995-07-20 02:43:20 -050059
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060060/* Width of interlace block. This is not currently used - if you need
61 * it, uncomment it here and in png.h
Guy Schalnat6d764711995-12-19 03:22:19 -060062int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
Guy Schalnat0d580581995-07-20 02:43:20 -050063*/
64
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060065/* Height of interlace block. This is not currently used - if you need
66 * it, uncomment it here and in png.h
Guy Schalnat6d764711995-12-19 03:22:19 -060067int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
Guy Schalnat0d580581995-07-20 02:43:20 -050068*/
69
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060070/* Mask to determine which pixels are valid in a pass */
Guy Schalnat6d764711995-12-19 03:22:19 -060071int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
Guy Schalnat0d580581995-07-20 02:43:20 -050072
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060073/* Mask to determine which pixels to overwrite while displaying */
Guy Schalnat6d764711995-12-19 03:22:19 -060074int FARDATA png_pass_dsp_mask[] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
Guy Schalnat0d580581995-07-20 02:43:20 -050075
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -060076#endif
77
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060078/* Tells libpng that we have already handled the first "num_bytes" bytes
79 * of the PNG file signature. If the PNG data is embedded into another
80 * stream we can set num_bytes = 8 so that libpng will not attempt to read
81 * or write any of the magic bytes before it starts on the IHDR.
82 */
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -050083
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060084void
85png_set_sig_bytes(png_structp png_ptr, int num_bytes)
86{
Andreas Dilger47a0c421997-05-16 02:46:07 -050087 png_debug(1, "in png_set_sig_bytes\n");
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060088 if (num_bytes > 8)
89 png_error(png_ptr, "Too many bytes for PNG signature.");
90
Glenn Randers-Pehrson860ab2b1999-10-14 07:43:10 -050091 png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060092}
93
94/* Checks whether the supplied bytes match the PNG signature. We allow
95 * checking less than the full 8-byte signature so that those apps that
96 * already read the first few bytes of a file to determine the file type
97 * can simply check the remaining bytes for extra assurance. Returns
98 * an integer less than, equal to, or greater than zero if sig is found,
99 * respectively, to be less than, to match, or be greater than the correct
100 * PNG signature (this is the same behaviour as strcmp, memcmp, etc).
101 */
102int
Andreas Dilger47a0c421997-05-16 02:46:07 -0500103png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600104{
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600105 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600106 if (num_to_check > 8)
107 num_to_check = 8;
108 else if (num_to_check < 1)
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600109 return (0);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600110
Andreas Dilger47a0c421997-05-16 02:46:07 -0500111 if (start > 7)
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600112 return (0);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600113
114 if (start + num_to_check > 8)
115 num_to_check = 8 - start;
116
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600117 return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600118}
119
120/* (Obsolete) function to check signature bytes. It does not allow one
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -0600121 * to check a partial signature. This function might be removed in the
122 * future - use png_sig_cmp(). Returns true (nonzero) if the file is a PNG.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600123 */
Guy Schalnat0d580581995-07-20 02:43:20 -0500124int
Guy Schalnat6d764711995-12-19 03:22:19 -0600125png_check_sig(png_bytep sig, int num)
Guy Schalnat0d580581995-07-20 02:43:20 -0500126{
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600127 return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
Guy Schalnat0d580581995-07-20 02:43:20 -0500128}
129
130/* Function to allocate memory for zlib. */
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500131voidpf
132png_zalloc(voidpf png_ptr, uInt items, uInt size)
Guy Schalnat0d580581995-07-20 02:43:20 -0500133{
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500134 png_uint_32 num_bytes = (png_uint_32)items * size;
135 png_voidp ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
Guy Schalnat6d764711995-12-19 03:22:19 -0600136
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500137 if (num_bytes > (png_uint_32)0x8000L)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600138 {
139 png_memset(ptr, 0, (png_size_t)0x8000L);
140 png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
141 (png_size_t)(num_bytes - (png_uint_32)0x8000L));
142 }
143 else
144 {
145 png_memset(ptr, 0, (png_size_t)num_bytes);
146 }
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600147 return ((voidpf)ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500148}
149
150/* function to free memory for zlib */
151void
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500152png_zfree(voidpf png_ptr, voidpf ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500153{
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600154 png_free((png_structp)png_ptr, (png_voidp)ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500155}
156
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600157/* Reset the CRC variable to 32 bits of 1's. Care must be taken
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600158 * in case CRC is > 32 bits to leave the top bits 0.
159 */
Guy Schalnat0d580581995-07-20 02:43:20 -0500160void
Guy Schalnat6d764711995-12-19 03:22:19 -0600161png_reset_crc(png_structp png_ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500162{
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600163 png_ptr->crc = crc32(0, Z_NULL, 0);
Guy Schalnat0d580581995-07-20 02:43:20 -0500164}
165
Andreas Dilger47a0c421997-05-16 02:46:07 -0500166/* Calculate the CRC over a section of data. We can only pass as
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600167 * much data to this routine as the largest single buffer size. We
168 * also check that this data will actually be used before going to the
169 * trouble of calculating it.
170 */
Guy Schalnat0d580581995-07-20 02:43:20 -0500171void
Andreas Dilger47a0c421997-05-16 02:46:07 -0500172png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
Guy Schalnat0d580581995-07-20 02:43:20 -0500173{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500174 int need_crc = 1;
175
176 if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
177 {
178 if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
179 (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
180 need_crc = 0;
181 }
182 else /* critical */
183 {
184 if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
185 need_crc = 0;
186 }
187
188 if (need_crc)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600189 png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
Guy Schalnat0d580581995-07-20 02:43:20 -0500190}
Guy Schalnate5a37791996-06-05 15:50:50 -0500191
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600192/* Allocate the memory for an info_struct for the application. We don't
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600193 * really need the png_ptr, but it could potentially be useful in the
194 * future. This should be used in favour of malloc(sizeof(png_info))
195 * and png_info_init() so that applications that want to use a shared
196 * libpng don't have to be recompiled if png_info changes size.
197 */
Guy Schalnate5a37791996-06-05 15:50:50 -0500198png_infop
199png_create_info_struct(png_structp png_ptr)
200{
201 png_infop info_ptr;
202
Andreas Dilger47a0c421997-05-16 02:46:07 -0500203 png_debug(1, "in png_create_info_struct\n");
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600204 if(png_ptr == NULL) return (NULL);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500205#ifdef PNG_USER_MEM_SUPPORTED
206 if ((info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
207 png_ptr->malloc_fn)) != NULL)
208#else
Guy Schalnate5a37791996-06-05 15:50:50 -0500209 if ((info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO)) != NULL)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500210#endif
Guy Schalnate5a37791996-06-05 15:50:50 -0500211 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600212 png_info_init(info_ptr);
Guy Schalnate5a37791996-06-05 15:50:50 -0500213 }
214
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600215 return (info_ptr);
Guy Schalnate5a37791996-06-05 15:50:50 -0500216}
217
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600218/* This function frees the memory associated with a single info struct.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600219 * Normally, one would use either png_destroy_read_struct() or
220 * png_destroy_write_struct() to free an info struct, but this may be
221 * useful for some applications.
222 */
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500223void
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600224png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
225{
226 png_infop info_ptr = NULL;
227
Andreas Dilger47a0c421997-05-16 02:46:07 -0500228 png_debug(1, "in png_destroy_info_struct\n");
229 if (info_ptr_ptr != NULL)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600230 info_ptr = *info_ptr_ptr;
231
Andreas Dilger47a0c421997-05-16 02:46:07 -0500232 if (info_ptr != NULL)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600233 {
234 png_info_destroy(png_ptr, info_ptr);
235
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500236#ifdef PNG_USER_MEM_SUPPORTED
237 png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn);
238#else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600239 png_destroy_struct((png_voidp)info_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500240#endif
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600241 *info_ptr_ptr = (png_infop)NULL;
242 }
243}
244
245/* Initialize the info structure. This is now an internal function (0.89)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600246 * and applications using it are urged to use png_create_info_struct()
247 * instead.
248 */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600249void
250png_info_init(png_infop info_ptr)
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500251{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500252 png_debug(1, "in png_info_init\n");
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500253 /* set everything to 0 */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600254 png_memset(info_ptr, 0, sizeof (png_info));
255}
256
257/* This is an internal routine to free any memory that the info struct is
Andreas Dilger47a0c421997-05-16 02:46:07 -0500258 * pointing to before re-using it or freeing the struct itself. Recall
259 * that png_free() checks for NULL pointers for us.
260 */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600261void
262png_info_destroy(png_structp png_ptr, png_infop info_ptr)
263{
264#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500265 png_debug(1, "in png_info_destroy\n");
266 if (info_ptr->text != NULL)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600267 {
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500268 int i;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500269 for (i = 0; i < info_ptr->num_text; i++)
270 {
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500271 if(info_ptr->text[i].key != NULL)
272 {
273 png_free(png_ptr, info_ptr->text[i].key);
274 info_ptr->text[i].key = NULL;
275 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500276 }
277 png_free(png_ptr, info_ptr->text);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500278 info_ptr->text = NULL;
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600279 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500280#endif
281#if defined(PNG_READ_pCAL_SUPPORTED)
282 png_free(png_ptr, info_ptr->pcal_purpose);
283 png_free(png_ptr, info_ptr->pcal_units);
284 if (info_ptr->pcal_params != NULL)
285 {
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500286 int i;
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600287 for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500288 {
289 png_free(png_ptr, info_ptr->pcal_params[i]);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500290 info_ptr->pcal_params[i]=NULL;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500291 }
292 png_free(png_ptr, info_ptr->pcal_params);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500293 info_ptr->pcal_params = NULL;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500294 }
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600295#endif
296
297 png_info_init(info_ptr);
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500298}
Guy Schalnat0d580581995-07-20 02:43:20 -0500299
Guy Schalnate5a37791996-06-05 15:50:50 -0500300/* This function returns a pointer to the io_ptr associated with the user
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600301 * functions. The application should free any memory associated with this
302 * pointer before png_write_destroy() or png_read_destroy() are called.
303 */
Guy Schalnate5a37791996-06-05 15:50:50 -0500304png_voidp
305png_get_io_ptr(png_structp png_ptr)
306{
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600307 return (png_ptr->io_ptr);
Guy Schalnate5a37791996-06-05 15:50:50 -0500308}
Andreas Dilger47a0c421997-05-16 02:46:07 -0500309
310#if !defined(PNG_NO_STDIO)
311/* Initialize the default input/output functions for the PNG file. If you
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600312 * use your own read or write routines, you can call either png_set_read_fn()
313 * or png_set_write_fn() instead of png_init_io().
314 */
Guy Schalnate5a37791996-06-05 15:50:50 -0500315void
316png_init_io(png_structp png_ptr, FILE *fp)
317{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500318 png_debug(1, "in png_init_io\n");
Guy Schalnate5a37791996-06-05 15:50:50 -0500319 png_ptr->io_ptr = (png_voidp)fp;
320}
Andreas Dilger47a0c421997-05-16 02:46:07 -0500321#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500322
323#if defined(PNG_TIME_RFC1123_SUPPORTED)
324/* Convert the supplied time into an RFC 1123 string suitable for use in
325 * a "Creation Time" or other text-based time string.
326 */
327png_charp
328png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
329{
330 static PNG_CONST char short_months[12][4] =
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600331 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
332 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500333
334 if (png_ptr->time_buffer == NULL)
335 {
336 png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
337 sizeof(char)));
338 }
339
340#ifdef USE_FAR_KEYWORD
341 {
342 char near_time_buf[29];
343 sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000",
344 ptime->day % 32, short_months[(ptime->month - 1) % 12],
345 ptime->year, ptime->hour % 24, ptime->minute % 60,
346 ptime->second % 61);
347 png_memcpy(png_ptr->time_buffer, near_time_buf,
348 29*sizeof(char));
349 }
350#else
351 sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
352 ptime->day % 32, short_months[(ptime->month - 1) % 12],
353 ptime->year, ptime->hour % 24, ptime->minute % 60,
354 ptime->second % 61);
355#endif
356 return ((png_charp)png_ptr->time_buffer);
357}
358#endif /* PNG_TIME_RFC1123_SUPPORTED */
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600359
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600360/* Signature string for a PNG file. */
361png_bytep
362png_sig_bytes(png_structp png_ptr)
363{
364 const png_byte png_sig_numbers[9] = {137, 80, 78, 71, 13, 10, 26, 10, 0};
365 if (png_ptr == NULL) /* silence compiler warning */
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600366 return ((png_bytep) strdup((png_const_charp)png_sig_numbers));
367 return ((png_bytep) strdup((png_const_charp)png_sig_numbers));
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600368}
369
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600370png_charp
371png_get_copyright(png_structp png_ptr)
372{
Glenn Randers-Pehrson860ab2b1999-10-14 07:43:10 -0500373 if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600374 return ("\n libpng version 1.0.5d - November 29, 1999\n\
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600375 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n\
376 Copyright (c) 1996, 1997 Andreas Dilger\n\
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500377 Copyright (c) 1998, 1999 Glenn Randers-Pehrson\n");
Glenn Randers-Pehrson860ab2b1999-10-14 07:43:10 -0500378 return ("");
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600379}
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500380
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600381/* The following return the library version as a short string in the
382 * format 1.0.0 through 99.99.99zz. To get the version of *.h files used
383 * with your application, print out PNG_LIBPNG_VER_STRING, which is defined
384 * in png.h.
385 */
386
387png_charp
388png_get_libpng_ver(png_structp png_ptr)
389{
390 /* Version of *.c files used when building libpng */
391 if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600392 return("1.0.5d");
393 return("1.0.5d");
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600394}
395
396png_charp
397png_get_header_ver(png_structp png_ptr)
398{
399 /* Version of *.h files used when building libpng */
400 if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
401 return(PNG_LIBPNG_VER_STRING);
402 return(PNG_LIBPNG_VER_STRING);
403}
404
405png_charp
406png_get_header_version(png_structp png_ptr)
407{
408 /* Returns longer string containing both version and date */
409 if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
410 return(PNG_HEADER_VERSION_STRING);
411 return(PNG_HEADER_VERSION_STRING);
412}
413
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500414/* Generate a compiler error if there is an old png.h in the search path. */
415void
416png_check_version
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600417 (version_1_0_5d png_h_is_not_version_1_0_5d)
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500418{
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600419 if(png_h_is_not_version_1_0_5d == NULL)
Glenn Randers-Pehrson860ab2b1999-10-14 07:43:10 -0500420 return;
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500421}