Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 2 | /* png.c - location for general purpose libpng functions |
| 3 | * |
Glenn Randers-Pehrson | c1bfe68 | 2002-03-06 22:08:00 -0600 | [diff] [blame^] | 4 | * libpng version 1.2.2beta3 - March 7, 2002 |
Glenn Randers-Pehrson | c6de22d | 2002-02-23 18:55:25 -0600 | [diff] [blame] | 5 | * Copyright (c) 1998-2002 Glenn Randers-Pehrson |
Glenn Randers-Pehrson | d436672 | 2000-06-04 14:29:29 -0500 | [diff] [blame] | 6 | * (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-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 8 | * |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 9 | */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 10 | |
| 11 | #define PNG_INTERNAL |
| 12 | #define PNG_NO_EXTERN |
| 13 | #include "png.h" |
| 14 | |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 15 | /* Generate a compiler error if there is an old png.h in the search path. */ |
Glenn Randers-Pehrson | c1bfe68 | 2002-03-06 22:08:00 -0600 | [diff] [blame^] | 16 | typedef version_1_2_2beta3 Your_png_h_is_not_version_1_2_2beta3; |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 17 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 18 | /* Version information for C files. This had better match the version |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 19 | * string defined in png.h. */ |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 20 | |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 21 | #ifdef PNG_USE_GLOBAL_ARRAYS |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 22 | /* png_libpng_ver was changed to a function in version 1.0.5c */ |
Glenn Randers-Pehrson | c1bfe68 | 2002-03-06 22:08:00 -0600 | [diff] [blame^] | 23 | const char png_libpng_ver[18] = "1.2.2beta3"; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 24 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 25 | /* png_sig was changed to a function in version 1.0.5c */ |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 26 | /* Place to hold the signature string for a PNG file. */ |
Glenn Randers-Pehrson | 5e5c1e1 | 2000-11-10 12:26:19 -0600 | [diff] [blame] | 27 | const png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 28 | |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 29 | /* Invoke global declarations for constant strings for known chunk types */ |
| 30 | PNG_IHDR; |
| 31 | PNG_IDAT; |
| 32 | PNG_IEND; |
| 33 | PNG_PLTE; |
| 34 | PNG_bKGD; |
| 35 | PNG_cHRM; |
| 36 | PNG_gAMA; |
| 37 | PNG_hIST; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 38 | PNG_iCCP; |
| 39 | PNG_iTXt; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 40 | PNG_oFFs; |
| 41 | PNG_pCAL; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 42 | PNG_sCAL; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 43 | PNG_pHYs; |
| 44 | PNG_sBIT; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 45 | PNG_sPLT; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 46 | PNG_sRGB; |
| 47 | PNG_tEXt; |
| 48 | PNG_tIME; |
| 49 | PNG_tRNS; |
| 50 | PNG_zTXt; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 51 | |
| 52 | /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ |
| 53 | |
| 54 | /* start of interlace block */ |
Glenn Randers-Pehrson | 5e5c1e1 | 2000-11-10 12:26:19 -0600 | [diff] [blame] | 55 | const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 56 | |
| 57 | /* offset to next interlace block */ |
Glenn Randers-Pehrson | 5e5c1e1 | 2000-11-10 12:26:19 -0600 | [diff] [blame] | 58 | const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 59 | |
| 60 | /* start of interlace block in the y direction */ |
Glenn Randers-Pehrson | 5e5c1e1 | 2000-11-10 12:26:19 -0600 | [diff] [blame] | 61 | const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 62 | |
| 63 | /* offset to next interlace block in the y direction */ |
Glenn Randers-Pehrson | 5e5c1e1 | 2000-11-10 12:26:19 -0600 | [diff] [blame] | 64 | const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 65 | |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 66 | /* width of interlace block (used in assembler routines only) */ |
| 67 | #ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW |
Glenn Randers-Pehrson | 5e5c1e1 | 2000-11-10 12:26:19 -0600 | [diff] [blame] | 68 | const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 69 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 70 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 71 | /* Height of interlace block. This is not currently used - if you need |
| 72 | * it, uncomment it here and in png.h |
Glenn Randers-Pehrson | 5e5c1e1 | 2000-11-10 12:26:19 -0600 | [diff] [blame] | 73 | const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 74 | */ |
| 75 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 76 | /* Mask to determine which pixels are valid in a pass */ |
Glenn Randers-Pehrson | 5e5c1e1 | 2000-11-10 12:26:19 -0600 | [diff] [blame] | 77 | const int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 78 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 79 | /* Mask to determine which pixels to overwrite while displaying */ |
Glenn Randers-Pehrson | 5e5c1e1 | 2000-11-10 12:26:19 -0600 | [diff] [blame] | 80 | const int FARDATA png_pass_dsp_mask[] |
| 81 | = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 82 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 83 | #endif |
| 84 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 85 | /* 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-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 90 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 91 | void PNGAPI |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 92 | png_set_sig_bytes(png_structp png_ptr, int num_bytes) |
| 93 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 94 | png_debug(1, "in png_set_sig_bytes\n"); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 95 | if (num_bytes > 8) |
| 96 | png_error(png_ptr, "Too many bytes for PNG signature."); |
| 97 | |
Glenn Randers-Pehrson | 860ab2b | 1999-10-14 07:43:10 -0500 | [diff] [blame] | 98 | png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 99 | } |
| 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-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 109 | int PNGAPI |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 110 | png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 111 | { |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 112 | png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 113 | if (num_to_check > 8) |
| 114 | num_to_check = 8; |
| 115 | else if (num_to_check < 1) |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 116 | return (0); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 117 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 118 | if (start > 7) |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 119 | return (0); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 120 | |
| 121 | if (start + num_to_check > 8) |
| 122 | num_to_check = 8 - start; |
| 123 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 124 | return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check))); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /* (Obsolete) function to check signature bytes. It does not allow one |
Glenn Randers-Pehrson | c944229 | 1999-01-06 21:50:16 -0600 | [diff] [blame] | 128 | * 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-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 130 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 131 | int PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 132 | png_check_sig(png_bytep sig, int num) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 133 | { |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 134 | return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num)); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 135 | } |
| 136 | |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 137 | /* Function to allocate memory for zlib and clear it to 0. */ |
Glenn Randers-Pehrson | c1bfe68 | 2002-03-06 22:08:00 -0600 | [diff] [blame^] | 138 | voidpf PNGAPI |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 139 | png_zalloc(voidpf png_ptr, uInt items, uInt size) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 140 | { |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 141 | png_uint_32 num_bytes = (png_uint_32)items * size; |
Glenn Randers-Pehrson | 9c0f094 | 2002-02-21 23:14:23 -0600 | [diff] [blame] | 142 | 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 Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 149 | |
Glenn Randers-Pehrson | a4d54bd | 2000-07-14 08:15:12 -0500 | [diff] [blame] | 150 | #ifndef PNG_NO_ZALLOC_ZERO |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 151 | if (num_bytes > (png_uint_32)0x8000L) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 152 | { |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 153 | 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 Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 160 | } |
Glenn Randers-Pehrson | a4d54bd | 2000-07-14 08:15:12 -0500 | [diff] [blame] | 161 | #endif |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 162 | return ((voidpf)ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /* function to free memory for zlib */ |
Glenn Randers-Pehrson | c1bfe68 | 2002-03-06 22:08:00 -0600 | [diff] [blame^] | 166 | void PNGAPI |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 167 | png_zfree(voidpf png_ptr, voidpf ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 168 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 169 | png_free((png_structp)png_ptr, (png_voidp)ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 170 | } |
| 171 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 172 | /* Reset the CRC variable to 32 bits of 1's. Care must be taken |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 173 | * in case CRC is > 32 bits to leave the top bits 0. |
| 174 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 175 | void /* PRIVATE */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 176 | png_reset_crc(png_structp png_ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 177 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 178 | png_ptr->crc = crc32(0, Z_NULL, 0); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 179 | } |
| 180 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 181 | /* Calculate the CRC over a section of data. We can only pass as |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 182 | * 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-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 186 | void /* PRIVATE */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 187 | png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 188 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 189 | 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-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 204 | png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 205 | } |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 206 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 207 | /* Allocate the memory for an info_struct for the application. We don't |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 208 | * 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-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 213 | png_infop PNGAPI |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 214 | png_create_info_struct(png_structp png_ptr) |
| 215 | { |
| 216 | png_infop info_ptr; |
| 217 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 218 | png_debug(1, "in png_create_info_struct\n"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 219 | if(png_ptr == NULL) return (NULL); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 220 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 5cded0b | 2001-11-07 07:10:08 -0600 | [diff] [blame] | 221 | info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, |
| 222 | png_ptr->malloc_fn, png_ptr->mem_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 223 | #else |
Glenn Randers-Pehrson | 5cded0b | 2001-11-07 07:10:08 -0600 | [diff] [blame] | 224 | info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 225 | #endif |
Glenn Randers-Pehrson | 5cded0b | 2001-11-07 07:10:08 -0600 | [diff] [blame] | 226 | if (info_ptr != NULL) |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 227 | png_info_init_3(&info_ptr, sizeof(png_info)); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 228 | |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 229 | return (info_ptr); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 230 | } |
| 231 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 232 | /* This function frees the memory associated with a single info struct. |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 233 | * 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-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 237 | void PNGAPI |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 238 | png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) |
| 239 | { |
| 240 | png_infop info_ptr = NULL; |
| 241 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 242 | png_debug(1, "in png_destroy_info_struct\n"); |
| 243 | if (info_ptr_ptr != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 244 | info_ptr = *info_ptr_ptr; |
| 245 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 246 | if (info_ptr != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 247 | { |
| 248 | png_info_destroy(png_ptr, info_ptr); |
| 249 | |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 250 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 251 | png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn, |
| 252 | png_ptr->mem_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 253 | #else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 254 | png_destroy_struct((png_voidp)info_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 255 | #endif |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 256 | *info_ptr_ptr = NULL; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
| 260 | /* Initialize the info structure. This is now an internal function (0.89) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 261 | * and applications using it are urged to use png_create_info_struct() |
| 262 | * instead. |
| 263 | */ |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 264 | #undef png_info_init |
| 265 | void PNGAPI |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 266 | png_info_init(png_infop info_ptr) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 267 | { |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 268 | /* We only come here via pre-1.0.12-compiled applications */ |
| 269 | png_info_init_3(&info_ptr, 0); |
| 270 | } |
| 271 | |
| 272 | void PNGAPI |
| 273 | png_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 Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 286 | /* set everything to 0 */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 287 | png_memset(info_ptr, 0, sizeof (png_info)); |
| 288 | } |
| 289 | |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 290 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 291 | void PNGAPI |
Glenn Randers-Pehrson | 38e6e77 | 2000-04-09 19:06:13 -0500 | [diff] [blame] | 292 | png_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-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 306 | #endif |
Glenn Randers-Pehrson | 38e6e77 | 2000-04-09 19:06:13 -0500 | [diff] [blame] | 307 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 308 | void PNGAPI |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 309 | png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, |
| 310 | int num) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 311 | { |
Glenn Randers-Pehrson | 38e6e77 | 2000-04-09 19:06:13 -0500 | [diff] [blame] | 312 | png_debug(1, "in png_free_data\n"); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 313 | if (png_ptr == NULL || info_ptr == NULL) |
| 314 | return; |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 315 | |
| 316 | #if defined(PNG_TEXT_SUPPORTED) |
| 317 | /* free text item num or (if num == -1) all text items */ |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 318 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 319 | if ((mask & PNG_FREE_TEXT) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 320 | #else |
| 321 | if (mask & PNG_FREE_TEXT) |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 322 | #endif |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 323 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 324 | if (num != -1) |
| 325 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 326 | if (info_ptr->text && info_ptr->text[num].key) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 327 | { |
| 328 | png_free(png_ptr, info_ptr->text[num].key); |
| 329 | info_ptr->text[num].key = NULL; |
| 330 | } |
| 331 | } |
Glenn Randers-Pehrson | ec61c23 | 2000-05-16 06:17:36 -0500 | [diff] [blame] | 332 | else |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 333 | { |
Glenn Randers-Pehrson | ec61c23 | 2000-05-16 06:17:36 -0500 | [diff] [blame] | 334 | 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-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | #endif |
| 343 | |
| 344 | #if defined(PNG_tRNS_SUPPORTED) |
| 345 | /* free any tRNS entry */ |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 346 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 347 | if ((mask & PNG_FREE_TRNS) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 348 | #else |
| 349 | if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS)) |
| 350 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 351 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 352 | png_free(png_ptr, info_ptr->trans); |
| 353 | info_ptr->valid &= ~PNG_INFO_tRNS; |
Glenn Randers-Pehrson | c1bfe68 | 2002-03-06 22:08:00 -0600 | [diff] [blame^] | 354 | #ifndef PNG_FREE_ME_SUPPORTED |
| 355 | png_ptr->flags &= ~PNG_FLAG_FREE_TRNS; |
| 356 | #endif |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 357 | info_ptr->trans = NULL; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 358 | } |
| 359 | #endif |
| 360 | |
| 361 | #if defined(PNG_sCAL_SUPPORTED) |
| 362 | /* free any sCAL entry */ |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 363 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 364 | if ((mask & PNG_FREE_SCAL) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 365 | #else |
| 366 | if (mask & PNG_FREE_SCAL) |
| 367 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 368 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 369 | #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 370 | png_free(png_ptr, info_ptr->scal_s_width); |
| 371 | png_free(png_ptr, info_ptr->scal_s_height); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 372 | info_ptr->scal_s_width = NULL; |
| 373 | info_ptr->scal_s_height = NULL; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 374 | #endif |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 375 | info_ptr->valid &= ~PNG_INFO_sCAL; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 376 | } |
| 377 | #endif |
| 378 | |
| 379 | #if defined(PNG_pCAL_SUPPORTED) |
| 380 | /* free any pCAL entry */ |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 381 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 382 | if ((mask & PNG_FREE_PCAL) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 383 | #else |
| 384 | if (mask & PNG_FREE_PCAL) |
| 385 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 386 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 387 | png_free(png_ptr, info_ptr->pcal_purpose); |
| 388 | png_free(png_ptr, info_ptr->pcal_units); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 389 | info_ptr->pcal_purpose = NULL; |
| 390 | info_ptr->pcal_units = NULL; |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 391 | if (info_ptr->pcal_params != NULL) |
| 392 | { |
| 393 | int i; |
| 394 | for (i = 0; i < (int)info_ptr->pcal_nparams; i++) |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 395 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 396 | png_free(png_ptr, info_ptr->pcal_params[i]); |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 397 | info_ptr->pcal_params[i]=NULL; |
| 398 | } |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 399 | png_free(png_ptr, info_ptr->pcal_params); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 400 | info_ptr->pcal_params = NULL; |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 401 | } |
| 402 | info_ptr->valid &= ~PNG_INFO_pCAL; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 403 | } |
| 404 | #endif |
| 405 | |
| 406 | #if defined(PNG_iCCP_SUPPORTED) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 407 | /* free any iCCP entry */ |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 408 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 409 | if ((mask & PNG_FREE_ICCP) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 410 | #else |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 411 | if (mask & PNG_FREE_ICCP) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 412 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 413 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 414 | png_free(png_ptr, info_ptr->iccp_name); |
| 415 | png_free(png_ptr, info_ptr->iccp_profile); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 416 | info_ptr->iccp_name = NULL; |
| 417 | info_ptr->iccp_profile = NULL; |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 418 | info_ptr->valid &= ~PNG_INFO_iCCP; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 419 | } |
| 420 | #endif |
| 421 | |
| 422 | #if defined(PNG_sPLT_SUPPORTED) |
| 423 | /* free a given sPLT entry, or (if num == -1) all sPLT entries */ |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 424 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 425 | if ((mask & PNG_FREE_SPLT) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 426 | #else |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 427 | if (mask & PNG_FREE_SPLT) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 428 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 429 | { |
| 430 | if (num != -1) |
| 431 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 432 | 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-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 436 | info_ptr->splt_palettes[num].name = NULL; |
| 437 | info_ptr->splt_palettes[num].entries = NULL; |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 438 | } |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 439 | } |
| 440 | else |
| 441 | { |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 442 | 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-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 447 | |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 448 | png_free(png_ptr, info_ptr->splt_palettes); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 449 | info_ptr->splt_palettes = NULL; |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 450 | info_ptr->splt_palettes_num = 0; |
| 451 | } |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 452 | info_ptr->valid &= ~PNG_INFO_sPLT; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | #endif |
| 456 | |
| 457 | #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 458 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 459 | if ((mask & PNG_FREE_UNKN) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 460 | #else |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 461 | if (mask & PNG_FREE_UNKN) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 462 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 463 | { |
| 464 | if (num != -1) |
| 465 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 466 | 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-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 471 | } |
| 472 | else |
| 473 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 474 | int i; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 475 | |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 476 | 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-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 480 | |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 481 | png_free(png_ptr, info_ptr->unknown_chunks); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 482 | info_ptr->unknown_chunks = NULL; |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 483 | info_ptr->unknown_chunks_num = 0; |
| 484 | } |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | #endif |
| 488 | |
| 489 | #if defined(PNG_hIST_SUPPORTED) |
| 490 | /* free any hIST entry */ |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 491 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 492 | if ((mask & PNG_FREE_HIST) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 493 | #else |
| 494 | if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST)) |
| 495 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 496 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 497 | png_free(png_ptr, info_ptr->hist); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 498 | info_ptr->hist = NULL; |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 499 | info_ptr->valid &= ~PNG_INFO_hIST; |
Glenn Randers-Pehrson | c1bfe68 | 2002-03-06 22:08:00 -0600 | [diff] [blame^] | 500 | #ifndef PNG_FREE_ME_SUPPORTED |
| 501 | png_ptr->flags &= ~PNG_FLAG_FREE_HIST; |
| 502 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 503 | } |
| 504 | #endif |
| 505 | |
| 506 | /* free any PLTE entry that was internally allocated */ |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 507 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 508 | if ((mask & PNG_FREE_PLTE) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 509 | #else |
| 510 | if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE)) |
| 511 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 512 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 513 | png_zfree(png_ptr, info_ptr->palette); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 514 | info_ptr->palette = NULL; |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 515 | info_ptr->valid &= ~PNG_INFO_PLTE; |
Glenn Randers-Pehrson | c1bfe68 | 2002-03-06 22:08:00 -0600 | [diff] [blame^] | 516 | #ifndef PNG_FREE_ME_SUPPORTED |
| 517 | png_ptr->flags &= ~PNG_FLAG_FREE_PLTE; |
| 518 | #endif |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 519 | info_ptr->num_palette = 0; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | #if defined(PNG_INFO_IMAGE_SUPPORTED) |
| 523 | /* free any image bits attached to the info structure */ |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 524 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 525 | if ((mask & PNG_FREE_ROWS) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 526 | #else |
| 527 | if (mask & PNG_FREE_ROWS) |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 528 | #endif |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 529 | { |
| 530 | if(info_ptr->row_pointers) |
| 531 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 532 | int row; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 533 | for (row = 0; row < (int)info_ptr->height; row++) |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 534 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 535 | png_free(png_ptr, info_ptr->row_pointers[row]); |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 536 | info_ptr->row_pointers[row]=NULL; |
| 537 | } |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 538 | png_free(png_ptr, info_ptr->row_pointers); |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 539 | info_ptr->row_pointers=NULL; |
| 540 | } |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 541 | info_ptr->valid &= ~PNG_INFO_IDAT; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 542 | } |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 543 | #endif |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 544 | |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 545 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 546 | if(num == -1) |
| 547 | info_ptr->free_me &= ~mask; |
Glenn Randers-Pehrson | ec61c23 | 2000-05-16 06:17:36 -0500 | [diff] [blame] | 548 | else |
| 549 | info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL); |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 550 | #endif |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 551 | } |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 552 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 553 | /* This is an internal routine to free any memory that the info struct is |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 554 | * 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-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 557 | void /* PRIVATE */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 558 | png_info_destroy(png_structp png_ptr, png_infop info_ptr) |
| 559 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 560 | png_debug(1, "in png_info_destroy\n"); |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 561 | |
| 562 | png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); |
Glenn Randers-Pehrson | d56aca7 | 2000-11-23 11:51:42 -0600 | [diff] [blame] | 563 | |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 564 | #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 565 | if (png_ptr->num_chunk_list) |
| 566 | { |
| 567 | png_free(png_ptr, png_ptr->chunk_list); |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 568 | png_ptr->chunk_list=NULL; |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 569 | png_ptr->num_chunk_list=0; |
| 570 | } |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 571 | #endif |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 572 | |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 573 | png_info_init_3(&info_ptr, sizeof(png_info)); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 574 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 575 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 576 | /* This function returns a pointer to the io_ptr associated with the user |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 577 | * 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-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 580 | png_voidp PNGAPI |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 581 | png_get_io_ptr(png_structp png_ptr) |
| 582 | { |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 583 | return (png_ptr->io_ptr); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 584 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 585 | |
| 586 | #if !defined(PNG_NO_STDIO) |
| 587 | /* Initialize the default input/output functions for the PNG file. If you |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 588 | * use your own read or write routines, you can call either png_set_read_fn() |
Glenn Randers-Pehrson | 38e6e77 | 2000-04-09 19:06:13 -0500 | [diff] [blame] | 589 | * 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-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 592 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 593 | void PNGAPI |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 594 | png_init_io(png_structp png_ptr, png_FILE_p fp) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 595 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 596 | png_debug(1, "in png_init_io\n"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 597 | png_ptr->io_ptr = (png_voidp)fp; |
| 598 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 599 | #endif |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 600 | |
| 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-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 605 | png_charp PNGAPI |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 606 | png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) |
| 607 | { |
| 608 | static PNG_CONST char short_months[12][4] = |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 609 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
| 610 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 611 | |
| 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-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 618 | #if defined(_WIN32_WCE) |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 619 | { |
| 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-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 628 | #else |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 629 | #ifdef USE_FAR_KEYWORD |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 630 | { |
| 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-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 639 | #else |
| 640 | sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000", |
Glenn Randers-Pehrson | e1eff58 | 2001-04-14 20:15:41 -0500 | [diff] [blame] | 641 | ptime->day % 32, short_months[(ptime->month - 1) % 12], |
| 642 | ptime->year, ptime->hour % 24, ptime->minute % 60, |
| 643 | ptime->second % 61); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 644 | #endif |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 645 | #endif /* _WIN32_WCE */ |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 646 | return ((png_charp)png_ptr->time_buffer); |
| 647 | } |
| 648 | #endif /* PNG_TIME_RFC1123_SUPPORTED */ |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 649 | |
Glenn Randers-Pehrson | 81fdf8a | 2000-04-07 10:34:56 -0500 | [diff] [blame] | 650 | #if 0 |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 651 | /* Signature string for a PNG file. */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 652 | png_bytep PNGAPI |
Glenn Randers-Pehrson | 81fdf8a | 2000-04-07 10:34:56 -0500 | [diff] [blame] | 653 | png_sig_bytes(void) |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 654 | { |
Glenn Randers-Pehrson | 81fdf8a | 2000-04-07 10:34:56 -0500 | [diff] [blame] | 655 | return ((png_bytep)"\211\120\116\107\015\012\032\012"); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 656 | } |
Glenn Randers-Pehrson | 81fdf8a | 2000-04-07 10:34:56 -0500 | [diff] [blame] | 657 | #endif |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 658 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 659 | png_charp PNGAPI |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 660 | png_get_copyright(png_structp png_ptr) |
| 661 | { |
Glenn Randers-Pehrson | 860ab2b | 1999-10-14 07:43:10 -0500 | [diff] [blame] | 662 | if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */ |
Glenn Randers-Pehrson | c1bfe68 | 2002-03-06 22:08:00 -0600 | [diff] [blame^] | 663 | return ((png_charp) "\n libpng version 1.2.2beta3 - March 7, 2002\n\ |
Glenn Randers-Pehrson | c6de22d | 2002-02-23 18:55:25 -0600 | [diff] [blame] | 664 | Copyright (c) 1998-2002 Glenn Randers-Pehrson\n\ |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 665 | Copyright (c) 1996, 1997 Andreas Dilger\n\ |
Glenn Randers-Pehrson | d436672 | 2000-06-04 14:29:29 -0500 | [diff] [blame] | 666 | Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n"); |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 667 | return ((png_charp) ""); |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 668 | } |
Glenn Randers-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 669 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 670 | /* 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-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 676 | png_charp PNGAPI |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 677 | png_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-Pehrson | c1bfe68 | 2002-03-06 22:08:00 -0600 | [diff] [blame^] | 681 | return((png_charp) "1.2.2beta3"); |
| 682 | return((png_charp) "1.2.2beta3"); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 683 | } |
| 684 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 685 | png_charp PNGAPI |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 686 | png_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-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 690 | return((png_charp) PNG_LIBPNG_VER_STRING); |
| 691 | return((png_charp) PNG_LIBPNG_VER_STRING); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 692 | } |
| 693 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 694 | png_charp PNGAPI |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 695 | png_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-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 699 | return((png_charp) PNG_HEADER_VERSION_STRING); |
| 700 | return((png_charp) PNG_HEADER_VERSION_STRING); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 701 | } |
| 702 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 703 | #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
Glenn Randers-Pehrson | c1bfe68 | 2002-03-06 22:08:00 -0600 | [diff] [blame^] | 704 | int PNGAPI |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 705 | png_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-Pehrson | 228bd39 | 2000-04-23 23:14:02 -0500 | [diff] [blame] | 719 | |
| 720 | /* This function, added to libpng-1.0.6g, is untested. */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 721 | int PNGAPI |
Glenn Randers-Pehrson | 228bd39 | 2000-04-23 23:14:02 -0500 | [diff] [blame] | 722 | png_reset_zstream(png_structp png_ptr) |
| 723 | { |
| 724 | return (inflateReset(&png_ptr->zstream)); |
| 725 | } |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 726 | |
Glenn Randers-Pehrson | 5e5c1e1 | 2000-11-10 12:26:19 -0600 | [diff] [blame] | 727 | /* This function was added to libpng-1.0.7 */ |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 728 | png_uint_32 PNGAPI |
| 729 | png_access_version_number(void) |
| 730 | { |
| 731 | /* Version of *.c files used when building libpng */ |
Glenn Randers-Pehrson | 9c0f094 | 2002-02-21 23:14:23 -0600 | [diff] [blame] | 732 | return((png_uint_32) 10202L); |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 733 | } |
Glenn Randers-Pehrson | 231e687 | 2001-01-12 15:13:06 -0600 | [diff] [blame] | 734 | |
Glenn Randers-Pehrson | 1fd5fb3 | 2001-05-06 05:34:26 -0500 | [diff] [blame] | 735 | |
| 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 */ |
| 739 | void /* PRIVATE */ |
| 740 | png_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-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 745 | # if (defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD)) |
Glenn Randers-Pehrson | 1fd5fb3 | 2001-05-06 05:34:26 -0500 | [diff] [blame] | 746 | |
| 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-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 751 | # ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW |
Glenn Randers-Pehrson | 1fd5fb3 | 2001-05-06 05:34:26 -0500 | [diff] [blame] | 752 | | PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 753 | # endif |
| 754 | # ifdef PNG_HAVE_ASSEMBLER_READ_INTERLACE |
Glenn Randers-Pehrson | 1fd5fb3 | 2001-05-06 05:34:26 -0500 | [diff] [blame] | 755 | | PNG_ASM_FLAG_MMX_READ_INTERLACE |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 756 | # endif |
| 757 | # ifndef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW |
Glenn Randers-Pehrson | 1fd5fb3 | 2001-05-06 05:34:26 -0500 | [diff] [blame] | 758 | ; |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 759 | # else |
Glenn Randers-Pehrson | 1fd5fb3 | 2001-05-06 05:34:26 -0500 | [diff] [blame] | 760 | | 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-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 767 | # endif |
Glenn Randers-Pehrson | 1fd5fb3 | 2001-05-06 05:34:26 -0500 | [diff] [blame] | 768 | } 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-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 774 | # else /* !((PNGVCRD || PNGGCCRD) && PNG_ASSEMBLER_CODE_SUPPORTED)) */ |
Glenn Randers-Pehrson | 1fd5fb3 | 2001-05-06 05:34:26 -0500 | [diff] [blame] | 775 | |
| 776 | /* clear all MMX flags; no support is compiled in */ |
| 777 | png_ptr->asm_flags &= ~( PNG_MMX_FLAGS ); |
| 778 | |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 779 | # endif /* ?(PNGVCRD || PNGGCCRD) */ |
Glenn Randers-Pehrson | 1fd5fb3 | 2001-05-06 05:34:26 -0500 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | #endif /* !(PNG_ASSEMBLER_CODE_SUPPORTED) */ |
| 783 | |
Glenn Randers-Pehrson | e68f5a3 | 2001-05-14 09:20:53 -0500 | [diff] [blame] | 784 | /* 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-Pehrson | 231e687 | 2001-01-12 15:13:06 -0600 | [diff] [blame] | 787 | int PNGAPI |
| 788 | png_mmx_support(void) |
| 789 | { |
| 790 | return -1; |
| 791 | } |
| 792 | #endif |