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 | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame^] | 4 | * libpng version 1.0.7beta15 - May 29, 2000 |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 5 | * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. |
| 6 | * Copyright (c) 1996, 1997 Andreas Dilger |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 7 | * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson |
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 |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 13 | #include <assert.h> |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 14 | #include "png.h" |
| 15 | |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 16 | /* Generate a compiler error if there is an old png.h in the search path. */ |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame^] | 17 | typedef version_1_0_7beta15 Your_png_h_is_not_version_1_0_7beta15; |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 18 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 19 | /* Version information for C files. This had better match the version |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 20 | * string defined in png.h. */ |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 21 | |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 22 | #ifdef PNG_USE_GLOBAL_ARRAYS |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 23 | /* png_libpng_ver was changed to a function in version 1.0.5c */ |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame^] | 24 | char png_libpng_ver[12] = "1.0.7beta15"; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 25 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 26 | /* 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] | 27 | /* Place to hold the signature string for a PNG file. */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 28 | 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] | 29 | |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 30 | /* Invoke global declarations for constant strings for known chunk types */ |
| 31 | PNG_IHDR; |
| 32 | PNG_IDAT; |
| 33 | PNG_IEND; |
| 34 | PNG_PLTE; |
| 35 | PNG_bKGD; |
| 36 | PNG_cHRM; |
| 37 | PNG_gAMA; |
| 38 | PNG_hIST; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 39 | PNG_iCCP; |
| 40 | PNG_iTXt; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 41 | PNG_oFFs; |
| 42 | PNG_pCAL; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 43 | PNG_sCAL; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 44 | PNG_pHYs; |
| 45 | PNG_sBIT; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 46 | PNG_sPLT; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 47 | PNG_sRGB; |
| 48 | PNG_tEXt; |
| 49 | PNG_tIME; |
| 50 | PNG_tRNS; |
| 51 | PNG_zTXt; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 52 | |
| 53 | /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ |
| 54 | |
| 55 | /* start of interlace block */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 56 | int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 57 | |
| 58 | /* offset to next interlace block */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 59 | int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 60 | |
| 61 | /* start of interlace block in the y direction */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 62 | int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 63 | |
| 64 | /* offset to next interlace block in the y direction */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 65 | int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 66 | |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 67 | /* width of interlace block (used in assembler routines only) */ |
| 68 | #ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 69 | 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] | 70 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 71 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 72 | /* Height of interlace block. This is not currently used - if you need |
| 73 | * it, uncomment it here and in png.h |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 74 | int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 75 | */ |
| 76 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 77 | /* Mask to determine which pixels are valid in a pass */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 78 | int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 79 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 80 | /* Mask to determine which pixels to overwrite while displaying */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 81 | int FARDATA png_pass_dsp_mask[] = {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 | 7529457 | 2000-05-06 14:09:57 -0500 | [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; |
| 142 | png_voidp ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 143 | |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 144 | if (num_bytes > (png_uint_32)0x8000L) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 145 | { |
| 146 | png_memset(ptr, 0, (png_size_t)0x8000L); |
| 147 | png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0, |
| 148 | (png_size_t)(num_bytes - (png_uint_32)0x8000L)); |
| 149 | } |
| 150 | else |
| 151 | { |
| 152 | png_memset(ptr, 0, (png_size_t)num_bytes); |
| 153 | } |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 154 | return ((voidpf)ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /* function to free memory for zlib */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 158 | void PNGAPI |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 159 | png_zfree(voidpf png_ptr, voidpf ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 160 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 161 | png_free((png_structp)png_ptr, (png_voidp)ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 162 | } |
| 163 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 164 | /* 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] | 165 | * in case CRC is > 32 bits to leave the top bits 0. |
| 166 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 167 | void /* PRIVATE */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 168 | png_reset_crc(png_structp png_ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 169 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 170 | png_ptr->crc = crc32(0, Z_NULL, 0); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 171 | } |
| 172 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 173 | /* 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] | 174 | * much data to this routine as the largest single buffer size. We |
| 175 | * also check that this data will actually be used before going to the |
| 176 | * trouble of calculating it. |
| 177 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 178 | void /* PRIVATE */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 179 | 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] | 180 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 181 | int need_crc = 1; |
| 182 | |
| 183 | if (png_ptr->chunk_name[0] & 0x20) /* ancillary */ |
| 184 | { |
| 185 | if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) == |
| 186 | (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN)) |
| 187 | need_crc = 0; |
| 188 | } |
| 189 | else /* critical */ |
| 190 | { |
| 191 | if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) |
| 192 | need_crc = 0; |
| 193 | } |
| 194 | |
| 195 | if (need_crc) |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 196 | png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 197 | } |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 198 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 199 | /* 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] | 200 | * really need the png_ptr, but it could potentially be useful in the |
| 201 | * future. This should be used in favour of malloc(sizeof(png_info)) |
| 202 | * and png_info_init() so that applications that want to use a shared |
| 203 | * libpng don't have to be recompiled if png_info changes size. |
| 204 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 205 | png_infop PNGAPI |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 206 | png_create_info_struct(png_structp png_ptr) |
| 207 | { |
| 208 | png_infop info_ptr; |
| 209 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 210 | png_debug(1, "in png_create_info_struct\n"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 211 | if(png_ptr == NULL) return (NULL); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 212 | #ifdef PNG_USER_MEM_SUPPORTED |
| 213 | if ((info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, |
| 214 | png_ptr->malloc_fn)) != NULL) |
| 215 | #else |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 216 | if ((info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO)) != NULL) |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 217 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 218 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 219 | png_info_init(info_ptr); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 220 | } |
| 221 | |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 222 | return (info_ptr); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 223 | } |
| 224 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 225 | /* This function frees the memory associated with a single info struct. |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 226 | * Normally, one would use either png_destroy_read_struct() or |
| 227 | * png_destroy_write_struct() to free an info struct, but this may be |
| 228 | * useful for some applications. |
| 229 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 230 | void PNGAPI |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 231 | png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) |
| 232 | { |
| 233 | png_infop info_ptr = NULL; |
| 234 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 235 | png_debug(1, "in png_destroy_info_struct\n"); |
| 236 | if (info_ptr_ptr != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 237 | info_ptr = *info_ptr_ptr; |
| 238 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 239 | if (info_ptr != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 240 | { |
| 241 | png_info_destroy(png_ptr, info_ptr); |
| 242 | |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 243 | #ifdef PNG_USER_MEM_SUPPORTED |
| 244 | png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn); |
| 245 | #else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 246 | png_destroy_struct((png_voidp)info_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 247 | #endif |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 248 | *info_ptr_ptr = (png_infop)NULL; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | /* 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] | 253 | * and applications using it are urged to use png_create_info_struct() |
| 254 | * instead. |
| 255 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 256 | void PNGAPI |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 257 | png_info_init(png_infop info_ptr) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 258 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 259 | png_debug(1, "in png_info_init\n"); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 260 | /* set everything to 0 */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 261 | png_memset(info_ptr, 0, sizeof (png_info)); |
| 262 | } |
| 263 | |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 264 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 265 | void PNGAPI |
Glenn Randers-Pehrson | 38e6e77 | 2000-04-09 19:06:13 -0500 | [diff] [blame] | 266 | png_data_freer(png_structp png_ptr, png_infop info_ptr, |
| 267 | int freer, png_uint_32 mask) |
| 268 | { |
| 269 | png_debug(1, "in png_data_freer\n"); |
| 270 | if (png_ptr == NULL || info_ptr == NULL) |
| 271 | return; |
| 272 | if(freer == PNG_DESTROY_WILL_FREE_DATA) |
| 273 | info_ptr->free_me |= mask; |
| 274 | else if(freer == PNG_USER_WILL_FREE_DATA) |
| 275 | info_ptr->free_me &= ~mask; |
| 276 | else |
| 277 | png_warning(png_ptr, |
| 278 | "Unknown freer parameter in png_data_freer."); |
| 279 | } |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 280 | #endif |
Glenn Randers-Pehrson | 38e6e77 | 2000-04-09 19:06:13 -0500 | [diff] [blame] | 281 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 282 | void PNGAPI |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 283 | png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, int num) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 284 | { |
Glenn Randers-Pehrson | 38e6e77 | 2000-04-09 19:06:13 -0500 | [diff] [blame] | 285 | png_debug(1, "in png_free_data\n"); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 286 | if (png_ptr == NULL || info_ptr == NULL) |
| 287 | return; |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 288 | |
| 289 | #if defined(PNG_TEXT_SUPPORTED) |
| 290 | /* free text item num or (if num == -1) all text items */ |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 291 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 292 | if ((mask & PNG_FREE_TEXT) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 293 | #else |
| 294 | if (mask & PNG_FREE_TEXT) |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 295 | #endif |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 296 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 297 | if (num != -1) |
| 298 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 299 | if (info_ptr->text && info_ptr->text[num].key) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 300 | { |
| 301 | png_free(png_ptr, info_ptr->text[num].key); |
| 302 | info_ptr->text[num].key = NULL; |
| 303 | } |
| 304 | } |
Glenn Randers-Pehrson | ec61c23 | 2000-05-16 06:17:36 -0500 | [diff] [blame] | 305 | else |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 306 | { |
Glenn Randers-Pehrson | ec61c23 | 2000-05-16 06:17:36 -0500 | [diff] [blame] | 307 | int i; |
| 308 | for (i = 0; i < info_ptr->num_text; i++) |
| 309 | png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i); |
| 310 | png_free(png_ptr, info_ptr->text); |
| 311 | info_ptr->text = NULL; |
| 312 | info_ptr->num_text=0; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | #endif |
| 316 | |
| 317 | #if defined(PNG_tRNS_SUPPORTED) |
| 318 | /* free any tRNS entry */ |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 319 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 320 | if ((mask & PNG_FREE_TRNS) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 321 | #else |
| 322 | if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS)) |
| 323 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 324 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 325 | png_free(png_ptr, info_ptr->trans); |
| 326 | info_ptr->valid &= ~PNG_INFO_tRNS; |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame^] | 327 | info_ptr->trans = NULL; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 328 | } |
| 329 | #endif |
| 330 | |
| 331 | #if defined(PNG_sCAL_SUPPORTED) |
| 332 | /* free any sCAL entry */ |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 333 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 334 | if ((mask & PNG_FREE_SCAL) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 335 | #else |
| 336 | if (mask & PNG_FREE_SCAL) |
| 337 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 338 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 339 | #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 340 | png_free(png_ptr, info_ptr->scal_s_width); |
| 341 | png_free(png_ptr, info_ptr->scal_s_height); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame^] | 342 | info_ptr->scal_s_width = NULL; |
| 343 | info_ptr->scal_s_height = NULL; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 344 | #endif |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 345 | info_ptr->valid &= ~PNG_INFO_sCAL; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 346 | } |
| 347 | #endif |
| 348 | |
| 349 | #if defined(PNG_pCAL_SUPPORTED) |
| 350 | /* free any pCAL entry */ |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 351 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 352 | if ((mask & PNG_FREE_PCAL) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 353 | #else |
| 354 | if (mask & PNG_FREE_PCAL) |
| 355 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 356 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 357 | png_free(png_ptr, info_ptr->pcal_purpose); |
| 358 | png_free(png_ptr, info_ptr->pcal_units); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame^] | 359 | info_ptr->pcal_purpose = NULL; |
| 360 | info_ptr->pcal_units = NULL; |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 361 | if (info_ptr->pcal_params != NULL) |
| 362 | { |
| 363 | int i; |
| 364 | for (i = 0; i < (int)info_ptr->pcal_nparams; i++) |
| 365 | png_free(png_ptr, info_ptr->pcal_params[i]); |
| 366 | png_free(png_ptr, info_ptr->pcal_params); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame^] | 367 | info_ptr->pcal_params = NULL; |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 368 | } |
| 369 | info_ptr->valid &= ~PNG_INFO_pCAL; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 370 | } |
| 371 | #endif |
| 372 | |
| 373 | #if defined(PNG_iCCP_SUPPORTED) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 374 | /* free any iCCP entry */ |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 375 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 376 | if ((mask & PNG_FREE_ICCP) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 377 | #else |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 378 | if (mask & PNG_FREE_ICCP) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 379 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 380 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 381 | png_free(png_ptr, info_ptr->iccp_name); |
| 382 | png_free(png_ptr, info_ptr->iccp_profile); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame^] | 383 | info_ptr->iccp_name = NULL; |
| 384 | info_ptr->iccp_profile = NULL; |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 385 | info_ptr->valid &= ~PNG_INFO_iCCP; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 386 | } |
| 387 | #endif |
| 388 | |
| 389 | #if defined(PNG_sPLT_SUPPORTED) |
| 390 | /* 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] | 391 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 392 | if ((mask & PNG_FREE_SPLT) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 393 | #else |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 394 | if (mask & PNG_FREE_SPLT) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 395 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 396 | { |
| 397 | if (num != -1) |
| 398 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 399 | if(info_ptr->splt_palettes) |
| 400 | { |
| 401 | png_free(png_ptr, info_ptr->splt_palettes[num].name); |
| 402 | png_free(png_ptr, info_ptr->splt_palettes[num].entries); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame^] | 403 | info_ptr->splt_palettes[num].name = NULL; |
| 404 | info_ptr->splt_palettes[num].entries = NULL; |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 405 | } |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 406 | } |
| 407 | else |
| 408 | { |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 409 | if(info_ptr->splt_palettes_num) |
| 410 | { |
| 411 | int i; |
| 412 | for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) |
| 413 | png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 414 | |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 415 | png_free(png_ptr, info_ptr->splt_palettes); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame^] | 416 | info_ptr->splt_palettes = NULL; |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 417 | info_ptr->splt_palettes_num = 0; |
| 418 | } |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 419 | info_ptr->valid &= ~PNG_INFO_sPLT; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | #endif |
| 423 | |
| 424 | #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 425 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 426 | if ((mask & PNG_FREE_UNKN) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 427 | #else |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 428 | if (mask & PNG_FREE_UNKN) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 429 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 430 | { |
| 431 | if (num != -1) |
| 432 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 433 | if(info_ptr->unknown_chunks) |
| 434 | { |
| 435 | png_free(png_ptr, info_ptr->unknown_chunks[num].data); |
| 436 | info_ptr->unknown_chunks[num].data = NULL; |
| 437 | } |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 438 | } |
| 439 | else |
| 440 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 441 | int i; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 442 | |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 443 | if(info_ptr->unknown_chunks_num) |
| 444 | { |
| 445 | for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++) |
| 446 | png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 447 | |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 448 | png_free(png_ptr, info_ptr->unknown_chunks); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame^] | 449 | info_ptr->unknown_chunks = NULL; |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 450 | info_ptr->unknown_chunks_num = 0; |
| 451 | } |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | #endif |
| 455 | |
| 456 | #if defined(PNG_hIST_SUPPORTED) |
| 457 | /* free any hIST entry */ |
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_HIST) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 460 | #else |
| 461 | if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST)) |
| 462 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 463 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 464 | png_free(png_ptr, info_ptr->hist); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame^] | 465 | info_ptr->hist = NULL; |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 466 | info_ptr->valid &= ~PNG_INFO_hIST; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 467 | } |
| 468 | #endif |
| 469 | |
| 470 | /* free any PLTE entry that was internally allocated */ |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 471 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 472 | if ((mask & PNG_FREE_PLTE) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 473 | #else |
| 474 | if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE)) |
| 475 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 476 | { |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 477 | png_zfree(png_ptr, info_ptr->palette); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame^] | 478 | info_ptr->palette = NULL; |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 479 | info_ptr->valid &= ~PNG_INFO_PLTE; |
| 480 | info_ptr->num_palette = 0; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | #if defined(PNG_INFO_IMAGE_SUPPORTED) |
| 484 | /* free any image bits attached to the info structure */ |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 485 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 486 | if ((mask & PNG_FREE_ROWS) & info_ptr->free_me) |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 487 | #else |
| 488 | if (mask & PNG_FREE_ROWS) |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 489 | #endif |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 490 | { |
| 491 | if(info_ptr->row_pointers) |
| 492 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 493 | int row; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 494 | for (row = 0; row < (int)info_ptr->height; row++) |
| 495 | png_free(png_ptr, info_ptr->row_pointers[row]); |
| 496 | png_free(png_ptr, info_ptr->row_pointers); |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 497 | info_ptr->row_pointers=NULL; |
| 498 | } |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 499 | info_ptr->valid &= ~PNG_INFO_IDAT; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 500 | } |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 501 | #endif |
Glenn Randers-Pehrson | fc4a143 | 2000-05-17 17:39:34 -0500 | [diff] [blame] | 502 | |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 503 | #ifdef PNG_FREE_ME_SUPPORTED |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 504 | if(num == -1) |
| 505 | info_ptr->free_me &= ~mask; |
Glenn Randers-Pehrson | ec61c23 | 2000-05-16 06:17:36 -0500 | [diff] [blame] | 506 | else |
| 507 | info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL); |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 508 | #endif |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 509 | } |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 510 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 511 | /* 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] | 512 | * pointing to before re-using it or freeing the struct itself. Recall |
| 513 | * that png_free() checks for NULL pointers for us. |
| 514 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 515 | void /* PRIVATE */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 516 | png_info_destroy(png_structp png_ptr, png_infop info_ptr) |
| 517 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 518 | png_debug(1, "in png_info_destroy\n"); |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 519 | |
| 520 | png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); |
| 521 | |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 522 | #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 523 | if (png_ptr->num_chunk_list) |
| 524 | { |
| 525 | png_free(png_ptr, png_ptr->chunk_list); |
| 526 | png_ptr->num_chunk_list=0; |
| 527 | } |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 528 | #endif |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 529 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 530 | png_info_init(info_ptr); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 531 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 532 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 533 | /* 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] | 534 | * functions. The application should free any memory associated with this |
| 535 | * pointer before png_write_destroy() or png_read_destroy() are called. |
| 536 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 537 | png_voidp PNGAPI |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 538 | png_get_io_ptr(png_structp png_ptr) |
| 539 | { |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 540 | return (png_ptr->io_ptr); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 541 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 542 | |
| 543 | #if !defined(PNG_NO_STDIO) |
| 544 | /* 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] | 545 | * 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] | 546 | * or png_set_write_fn() instead of png_init_io(). If you have defined |
| 547 | * PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't |
| 548 | * necessarily available. |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 549 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 550 | void PNGAPI |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 551 | png_init_io(png_structp png_ptr, FILE *fp) |
| 552 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 553 | png_debug(1, "in png_init_io\n"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 554 | png_ptr->io_ptr = (png_voidp)fp; |
| 555 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 556 | #endif |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 557 | |
| 558 | #if defined(PNG_TIME_RFC1123_SUPPORTED) |
| 559 | /* Convert the supplied time into an RFC 1123 string suitable for use in |
| 560 | * a "Creation Time" or other text-based time string. |
| 561 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 562 | png_charp PNGAPI |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 563 | png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) |
| 564 | { |
| 565 | static PNG_CONST char short_months[12][4] = |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 566 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
| 567 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 568 | |
| 569 | if (png_ptr->time_buffer == NULL) |
| 570 | { |
| 571 | png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29* |
| 572 | sizeof(char))); |
| 573 | } |
| 574 | |
| 575 | #ifdef USE_FAR_KEYWORD |
| 576 | { |
| 577 | char near_time_buf[29]; |
| 578 | sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000", |
| 579 | ptime->day % 32, short_months[(ptime->month - 1) % 12], |
| 580 | ptime->year, ptime->hour % 24, ptime->minute % 60, |
| 581 | ptime->second % 61); |
| 582 | png_memcpy(png_ptr->time_buffer, near_time_buf, |
| 583 | 29*sizeof(char)); |
| 584 | } |
| 585 | #else |
| 586 | sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000", |
| 587 | ptime->day % 32, short_months[(ptime->month - 1) % 12], |
| 588 | ptime->year, ptime->hour % 24, ptime->minute % 60, |
| 589 | ptime->second % 61); |
| 590 | #endif |
| 591 | return ((png_charp)png_ptr->time_buffer); |
| 592 | } |
| 593 | #endif /* PNG_TIME_RFC1123_SUPPORTED */ |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 594 | |
Glenn Randers-Pehrson | 81fdf8a | 2000-04-07 10:34:56 -0500 | [diff] [blame] | 595 | #if 0 |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 596 | /* Signature string for a PNG file. */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 597 | png_bytep PNGAPI |
Glenn Randers-Pehrson | 81fdf8a | 2000-04-07 10:34:56 -0500 | [diff] [blame] | 598 | png_sig_bytes(void) |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 599 | { |
Glenn Randers-Pehrson | 81fdf8a | 2000-04-07 10:34:56 -0500 | [diff] [blame] | 600 | return ((png_bytep)"\211\120\116\107\015\012\032\012"); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 601 | } |
Glenn Randers-Pehrson | 81fdf8a | 2000-04-07 10:34:56 -0500 | [diff] [blame] | 602 | #endif |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 603 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 604 | png_charp PNGAPI |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 605 | png_get_copyright(png_structp png_ptr) |
| 606 | { |
Glenn Randers-Pehrson | 860ab2b | 1999-10-14 07:43:10 -0500 | [diff] [blame] | 607 | if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */ |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame^] | 608 | return ("\n libpng version 1.0.7beta15 - May 29, 2000\n\ |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 609 | Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n\ |
| 610 | Copyright (c) 1996, 1997 Andreas Dilger\n\ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 611 | Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson\n"); |
Glenn Randers-Pehrson | 860ab2b | 1999-10-14 07:43:10 -0500 | [diff] [blame] | 612 | return (""); |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 613 | } |
Glenn Randers-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 614 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 615 | /* The following return the library version as a short string in the |
| 616 | * format 1.0.0 through 99.99.99zz. To get the version of *.h files used |
| 617 | * with your application, print out PNG_LIBPNG_VER_STRING, which is defined |
| 618 | * in png.h. |
| 619 | */ |
| 620 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 621 | png_charp PNGAPI |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 622 | png_get_libpng_ver(png_structp png_ptr) |
| 623 | { |
| 624 | /* Version of *.c files used when building libpng */ |
| 625 | if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */ |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame^] | 626 | return("1.0.7beta15"); |
| 627 | return("1.0.7beta15"); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 628 | } |
| 629 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 630 | png_charp PNGAPI |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 631 | png_get_header_ver(png_structp png_ptr) |
| 632 | { |
| 633 | /* Version of *.h files used when building libpng */ |
| 634 | if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */ |
| 635 | return(PNG_LIBPNG_VER_STRING); |
| 636 | return(PNG_LIBPNG_VER_STRING); |
| 637 | } |
| 638 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 639 | png_charp PNGAPI |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 640 | png_get_header_version(png_structp png_ptr) |
| 641 | { |
| 642 | /* Returns longer string containing both version and date */ |
| 643 | if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */ |
| 644 | return(PNG_HEADER_VERSION_STRING); |
| 645 | return(PNG_HEADER_VERSION_STRING); |
| 646 | } |
| 647 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 648 | #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 649 | int PNGAPI |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 650 | png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name) |
| 651 | { |
| 652 | /* check chunk_name and return "keep" value if it's on the list, else 0 */ |
| 653 | int i; |
| 654 | png_bytep p; |
| 655 | if((png_ptr == NULL && chunk_name == NULL) || png_ptr->num_chunk_list<=0) |
| 656 | return 0; |
| 657 | p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5; |
| 658 | for (i = png_ptr->num_chunk_list; i; i--, p-=5) |
| 659 | if (!png_memcmp(chunk_name, p, 4)) |
| 660 | return ((int)*(p+4)); |
| 661 | return 0; |
| 662 | } |
| 663 | #endif |
Glenn Randers-Pehrson | 228bd39 | 2000-04-23 23:14:02 -0500 | [diff] [blame] | 664 | |
| 665 | /* This function, added to libpng-1.0.6g, is untested. */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 666 | int PNGAPI |
Glenn Randers-Pehrson | 228bd39 | 2000-04-23 23:14:02 -0500 | [diff] [blame] | 667 | png_reset_zstream(png_structp png_ptr) |
| 668 | { |
| 669 | return (inflateReset(&png_ptr->zstream)); |
| 670 | } |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 671 | |
| 672 | png_uint_32 PNGAPI |
| 673 | png_access_version_number(void) |
| 674 | { |
| 675 | /* Version of *.c files used when building libpng */ |
| 676 | return((png_uint_32) 10007L); |
| 677 | } |