| OLD | NEW |
| 1 | 1 |
| 2 /* png.c - location for general purpose libpng functions | 2 /* png.c - location for general purpose libpng functions |
| 3 * | 3 * |
| 4 * Last changed in libpng 1.2.37 [June 4, 2009] | 4 * Last changed in libpng 1.2.43 [February 25, 2010] |
| 5 * For conditions of distribution and use, see copyright notice in png.h | 5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson |
| 6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson | |
| 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
| 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
| 8 * |
| 9 * This code is released under the libpng license. |
| 10 * For conditions of distribution and use, see the disclaimer |
| 11 * and license in png.h |
| 9 */ | 12 */ |
| 10 | 13 |
| 11 #define PNG_INTERNAL | 14 #define PNG_INTERNAL |
| 12 #define PNG_NO_EXTERN | 15 #define PNG_NO_EXTERN |
| 16 #define PNG_NO_PEDANTIC_WARNINGS |
| 13 #include "png.h" | 17 #include "png.h" |
| 14 | 18 |
| 15 /* Generate a compiler error if there is an old png.h in the search path. */ | 19 /* Generate a compiler error if there is an old png.h in the search path. */ |
| 16 typedef version_1_2_37 Your_png_h_is_not_version_1_2_37; | 20 typedef version_1_2_43 Your_png_h_is_not_version_1_2_43; |
| 17 | 21 |
| 18 /* Version information for C files. This had better match the version | 22 /* Version information for C files. This had better match the version |
| 19 * string defined in png.h. */ | 23 * string defined in png.h. |
| 24 */ |
| 20 | 25 |
| 21 #ifdef PNG_USE_GLOBAL_ARRAYS | 26 #ifdef PNG_USE_GLOBAL_ARRAYS |
| 22 /* png_libpng_ver was changed to a function in version 1.0.5c */ | 27 /* png_libpng_ver was changed to a function in version 1.0.5c */ |
| 23 PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING; | 28 PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING; |
| 24 | 29 |
| 25 #ifdef PNG_READ_SUPPORTED | 30 #ifdef PNG_READ_SUPPORTED |
| 26 | 31 |
| 27 /* png_sig was changed to a function in version 1.0.5c */ | 32 /* png_sig was changed to a function in version 1.0.5c */ |
| 28 /* Place to hold the signature string for a PNG file. */ | 33 /* Place to hold the signature string for a PNG file. */ |
| 29 PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; | 34 PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 71 |
| 67 /* Offset to next interlace block in the y direction */ | 72 /* Offset to next interlace block in the y direction */ |
| 68 PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; | 73 PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; |
| 69 | 74 |
| 70 /* Height of interlace block. This is not currently used - if you need | 75 /* Height of interlace block. This is not currently used - if you need |
| 71 * it, uncomment it here and in png.h | 76 * it, uncomment it here and in png.h |
| 72 PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; | 77 PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; |
| 73 */ | 78 */ |
| 74 | 79 |
| 75 /* Mask to determine which pixels are valid in a pass */ | 80 /* Mask to determine which pixels are valid in a pass */ |
| 76 PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xf
f}; | 81 PNG_CONST int FARDATA png_pass_mask[] = |
| 82 {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; |
| 77 | 83 |
| 78 /* Mask to determine which pixels to overwrite while displaying */ | 84 /* Mask to determine which pixels to overwrite while displaying */ |
| 79 PNG_CONST int FARDATA png_pass_dsp_mask[] | 85 PNG_CONST int FARDATA png_pass_dsp_mask[] |
| 80 = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; | 86 = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; |
| 81 | 87 |
| 82 #endif /* PNG_READ_SUPPORTED */ | 88 #endif /* PNG_READ_SUPPORTED */ |
| 83 #endif /* PNG_USE_GLOBAL_ARRAYS */ | 89 #endif /* PNG_USE_GLOBAL_ARRAYS */ |
| 84 | 90 |
| 85 /* Tells libpng that we have already handled the first "num_bytes" bytes | 91 /* 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 | 92 * 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 | 93 * 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. | 94 * or write any of the magic bytes before it starts on the IHDR. |
| 89 */ | 95 */ |
| 90 | 96 |
| 91 #ifdef PNG_READ_SUPPORTED | 97 #ifdef PNG_READ_SUPPORTED |
| 92 void PNGAPI | 98 void PNGAPI |
| 93 png_set_sig_bytes(png_structp png_ptr, int num_bytes) | 99 png_set_sig_bytes(png_structp png_ptr, int num_bytes) |
| 94 { | 100 { |
| 101 png_debug(1, "in png_set_sig_bytes"); |
| 102 |
| 95 if (png_ptr == NULL) | 103 if (png_ptr == NULL) |
| 96 return; | 104 return; |
| 97 png_debug(1, "in png_set_sig_bytes"); | 105 |
| 98 if (num_bytes > 8) | 106 if (num_bytes > 8) |
| 99 png_error(png_ptr, "Too many bytes for PNG signature."); | 107 png_error(png_ptr, "Too many bytes for PNG signature."); |
| 100 | 108 |
| 101 png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes); | 109 png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes); |
| 102 } | 110 } |
| 103 | 111 |
| 104 /* Checks whether the supplied bytes match the PNG signature. We allow | 112 /* Checks whether the supplied bytes match the PNG signature. We allow |
| 105 * checking less than the full 8-byte signature so that those apps that | 113 * checking less than the full 8-byte signature so that those apps that |
| 106 * already read the first few bytes of a file to determine the file type | 114 * already read the first few bytes of a file to determine the file type |
| 107 * can simply check the remaining bytes for extra assurance. Returns | 115 * can simply check the remaining bytes for extra assurance. Returns |
| (...skipping 30 matching lines...) Expand all Loading... |
| 138 return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num)); | 146 return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num)); |
| 139 } | 147 } |
| 140 #endif | 148 #endif |
| 141 #endif /* PNG_READ_SUPPORTED */ | 149 #endif /* PNG_READ_SUPPORTED */ |
| 142 | 150 |
| 143 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) | 151 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) |
| 144 /* Function to allocate memory for zlib and clear it to 0. */ | 152 /* Function to allocate memory for zlib and clear it to 0. */ |
| 145 #ifdef PNG_1_0_X | 153 #ifdef PNG_1_0_X |
| 146 voidpf PNGAPI | 154 voidpf PNGAPI |
| 147 #else | 155 #else |
| 148 voidpf /* private */ | 156 voidpf /* PRIVATE */ |
| 149 #endif | 157 #endif |
| 150 png_zalloc(voidpf png_ptr, uInt items, uInt size) | 158 png_zalloc(voidpf png_ptr, uInt items, uInt size) |
| 151 { | 159 { |
| 152 png_voidp ptr; | 160 png_voidp ptr; |
| 153 png_structp p=(png_structp)png_ptr; | 161 png_structp p=(png_structp)png_ptr; |
| 154 png_uint_32 save_flags=p->flags; | 162 png_uint_32 save_flags=p->flags; |
| 155 png_uint_32 num_bytes; | 163 png_uint_32 num_bytes; |
| 156 | 164 |
| 157 if (png_ptr == NULL) | 165 if (png_ptr == NULL) |
| 158 return (NULL); | 166 return (NULL); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 182 png_memset(ptr, 0, (png_size_t)num_bytes); | 190 png_memset(ptr, 0, (png_size_t)num_bytes); |
| 183 } | 191 } |
| 184 #endif | 192 #endif |
| 185 return ((voidpf)ptr); | 193 return ((voidpf)ptr); |
| 186 } | 194 } |
| 187 | 195 |
| 188 /* Function to free memory for zlib */ | 196 /* Function to free memory for zlib */ |
| 189 #ifdef PNG_1_0_X | 197 #ifdef PNG_1_0_X |
| 190 void PNGAPI | 198 void PNGAPI |
| 191 #else | 199 #else |
| 192 void /* private */ | 200 void /* PRIVATE */ |
| 193 #endif | 201 #endif |
| 194 png_zfree(voidpf png_ptr, voidpf ptr) | 202 png_zfree(voidpf png_ptr, voidpf ptr) |
| 195 { | 203 { |
| 196 png_free((png_structp)png_ptr, (png_voidp)ptr); | 204 png_free((png_structp)png_ptr, (png_voidp)ptr); |
| 197 } | 205 } |
| 198 | 206 |
| 199 /* Reset the CRC variable to 32 bits of 1's. Care must be taken | 207 /* Reset the CRC variable to 32 bits of 1's. Care must be taken |
| 200 * in case CRC is > 32 bits to leave the top bits 0. | 208 * in case CRC is > 32 bits to leave the top bits 0. |
| 201 */ | 209 */ |
| 202 void /* PRIVATE */ | 210 void /* PRIVATE */ |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 * future. This should be used in favour of malloc(png_sizeof(png_info)) | 244 * future. This should be used in favour of malloc(png_sizeof(png_info)) |
| 237 * and png_info_init() so that applications that want to use a shared | 245 * and png_info_init() so that applications that want to use a shared |
| 238 * libpng don't have to be recompiled if png_info changes size. | 246 * libpng don't have to be recompiled if png_info changes size. |
| 239 */ | 247 */ |
| 240 png_infop PNGAPI | 248 png_infop PNGAPI |
| 241 png_create_info_struct(png_structp png_ptr) | 249 png_create_info_struct(png_structp png_ptr) |
| 242 { | 250 { |
| 243 png_infop info_ptr; | 251 png_infop info_ptr; |
| 244 | 252 |
| 245 png_debug(1, "in png_create_info_struct"); | 253 png_debug(1, "in png_create_info_struct"); |
| 254 |
| 246 if (png_ptr == NULL) | 255 if (png_ptr == NULL) |
| 247 return (NULL); | 256 return (NULL); |
| 257 |
| 248 #ifdef PNG_USER_MEM_SUPPORTED | 258 #ifdef PNG_USER_MEM_SUPPORTED |
| 249 info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, | 259 info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, |
| 250 png_ptr->malloc_fn, png_ptr->mem_ptr); | 260 png_ptr->malloc_fn, png_ptr->mem_ptr); |
| 251 #else | 261 #else |
| 252 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); | 262 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); |
| 253 #endif | 263 #endif |
| 254 if (info_ptr != NULL) | 264 if (info_ptr != NULL) |
| 255 png_info_init_3(&info_ptr, png_sizeof(png_info)); | 265 png_info_init_3(&info_ptr, png_sizeof(png_info)); |
| 256 | 266 |
| 257 return (info_ptr); | 267 return (info_ptr); |
| 258 } | 268 } |
| 259 | 269 |
| 260 /* This function frees the memory associated with a single info struct. | 270 /* This function frees the memory associated with a single info struct. |
| 261 * Normally, one would use either png_destroy_read_struct() or | 271 * Normally, one would use either png_destroy_read_struct() or |
| 262 * png_destroy_write_struct() to free an info struct, but this may be | 272 * png_destroy_write_struct() to free an info struct, but this may be |
| 263 * useful for some applications. | 273 * useful for some applications. |
| 264 */ | 274 */ |
| 265 void PNGAPI | 275 void PNGAPI |
| 266 png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) | 276 png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) |
| 267 { | 277 { |
| 268 png_infop info_ptr = NULL; | 278 png_infop info_ptr = NULL; |
| 279 |
| 280 png_debug(1, "in png_destroy_info_struct"); |
| 281 |
| 269 if (png_ptr == NULL) | 282 if (png_ptr == NULL) |
| 270 return; | 283 return; |
| 271 | 284 |
| 272 png_debug(1, "in png_destroy_info_struct"); | |
| 273 if (info_ptr_ptr != NULL) | 285 if (info_ptr_ptr != NULL) |
| 274 info_ptr = *info_ptr_ptr; | 286 info_ptr = *info_ptr_ptr; |
| 275 | 287 |
| 276 if (info_ptr != NULL) | 288 if (info_ptr != NULL) |
| 277 { | 289 { |
| 278 png_info_destroy(png_ptr, info_ptr); | 290 png_info_destroy(png_ptr, info_ptr); |
| 279 | 291 |
| 280 #ifdef PNG_USER_MEM_SUPPORTED | 292 #ifdef PNG_USER_MEM_SUPPORTED |
| 281 png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn, | 293 png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn, |
| 282 png_ptr->mem_ptr); | 294 png_ptr->mem_ptr); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 299 /* We only come here via pre-1.0.12-compiled applications */ | 311 /* We only come here via pre-1.0.12-compiled applications */ |
| 300 png_info_init_3(&info_ptr, 0); | 312 png_info_init_3(&info_ptr, 0); |
| 301 } | 313 } |
| 302 #endif | 314 #endif |
| 303 | 315 |
| 304 void PNGAPI | 316 void PNGAPI |
| 305 png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) | 317 png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) |
| 306 { | 318 { |
| 307 png_infop info_ptr = *ptr_ptr; | 319 png_infop info_ptr = *ptr_ptr; |
| 308 | 320 |
| 321 png_debug(1, "in png_info_init_3"); |
| 322 |
| 309 if (info_ptr == NULL) | 323 if (info_ptr == NULL) |
| 310 return; | 324 return; |
| 311 | 325 |
| 312 png_debug(1, "in png_info_init_3"); | |
| 313 | |
| 314 if (png_sizeof(png_info) > png_info_struct_size) | 326 if (png_sizeof(png_info) > png_info_struct_size) |
| 315 { | 327 { |
| 316 png_destroy_struct(info_ptr); | 328 png_destroy_struct(info_ptr); |
| 317 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); | 329 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); |
| 318 *ptr_ptr = info_ptr; | 330 *ptr_ptr = info_ptr; |
| 319 } | 331 } |
| 320 | 332 |
| 321 /* Set everything to 0 */ | 333 /* Set everything to 0 */ |
| 322 png_memset(info_ptr, 0, png_sizeof(png_info)); | 334 png_memset(info_ptr, 0, png_sizeof(png_info)); |
| 323 } | 335 } |
| 324 | 336 |
| 325 #ifdef PNG_FREE_ME_SUPPORTED | 337 #ifdef PNG_FREE_ME_SUPPORTED |
| 326 void PNGAPI | 338 void PNGAPI |
| 327 png_data_freer(png_structp png_ptr, png_infop info_ptr, | 339 png_data_freer(png_structp png_ptr, png_infop info_ptr, |
| 328 int freer, png_uint_32 mask) | 340 int freer, png_uint_32 mask) |
| 329 { | 341 { |
| 330 png_debug(1, "in png_data_freer"); | 342 png_debug(1, "in png_data_freer"); |
| 343 |
| 331 if (png_ptr == NULL || info_ptr == NULL) | 344 if (png_ptr == NULL || info_ptr == NULL) |
| 332 return; | 345 return; |
| 346 |
| 333 if (freer == PNG_DESTROY_WILL_FREE_DATA) | 347 if (freer == PNG_DESTROY_WILL_FREE_DATA) |
| 334 info_ptr->free_me |= mask; | 348 info_ptr->free_me |= mask; |
| 335 else if (freer == PNG_USER_WILL_FREE_DATA) | 349 else if (freer == PNG_USER_WILL_FREE_DATA) |
| 336 info_ptr->free_me &= ~mask; | 350 info_ptr->free_me &= ~mask; |
| 337 else | 351 else |
| 338 png_warning(png_ptr, | 352 png_warning(png_ptr, |
| 339 "Unknown freer parameter in png_data_freer."); | 353 "Unknown freer parameter in png_data_freer."); |
| 340 } | 354 } |
| 341 #endif | 355 #endif |
| 342 | 356 |
| 343 void PNGAPI | 357 void PNGAPI |
| 344 png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, | 358 png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, |
| 345 int num) | 359 int num) |
| 346 { | 360 { |
| 347 png_debug(1, "in png_free_data"); | 361 png_debug(1, "in png_free_data"); |
| 362 |
| 348 if (png_ptr == NULL || info_ptr == NULL) | 363 if (png_ptr == NULL || info_ptr == NULL) |
| 349 return; | 364 return; |
| 350 | 365 |
| 351 #if defined(PNG_TEXT_SUPPORTED) | 366 #ifdef PNG_TEXT_SUPPORTED |
| 352 /* Free text item num or (if num == -1) all text items */ | 367 /* Free text item num or (if num == -1) all text items */ |
| 353 #ifdef PNG_FREE_ME_SUPPORTED | 368 #ifdef PNG_FREE_ME_SUPPORTED |
| 354 if ((mask & PNG_FREE_TEXT) & info_ptr->free_me) | 369 if ((mask & PNG_FREE_TEXT) & info_ptr->free_me) |
| 355 #else | 370 #else |
| 356 if (mask & PNG_FREE_TEXT) | 371 if (mask & PNG_FREE_TEXT) |
| 357 #endif | 372 #endif |
| 358 { | 373 { |
| 359 if (num != -1) | 374 if (num != -1) |
| 360 { | 375 { |
| 361 if (info_ptr->text && info_ptr->text[num].key) | 376 if (info_ptr->text && info_ptr->text[num].key) |
| 362 { | 377 { |
| 363 png_free(png_ptr, info_ptr->text[num].key); | 378 png_free(png_ptr, info_ptr->text[num].key); |
| 364 info_ptr->text[num].key = NULL; | 379 info_ptr->text[num].key = NULL; |
| 365 } | 380 } |
| 366 } | 381 } |
| 367 else | 382 else |
| 368 { | 383 { |
| 369 int i; | 384 int i; |
| 370 for (i = 0; i < info_ptr->num_text; i++) | 385 for (i = 0; i < info_ptr->num_text; i++) |
| 371 png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i); | 386 png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i); |
| 372 png_free(png_ptr, info_ptr->text); | 387 png_free(png_ptr, info_ptr->text); |
| 373 info_ptr->text = NULL; | 388 info_ptr->text = NULL; |
| 374 info_ptr->num_text=0; | 389 info_ptr->num_text=0; |
| 375 } | 390 } |
| 376 } | 391 } |
| 377 #endif | 392 #endif |
| 378 | 393 |
| 379 #if defined(PNG_tRNS_SUPPORTED) | 394 #ifdef PNG_tRNS_SUPPORTED |
| 380 /* Free any tRNS entry */ | 395 /* Free any tRNS entry */ |
| 381 #ifdef PNG_FREE_ME_SUPPORTED | 396 #ifdef PNG_FREE_ME_SUPPORTED |
| 382 if ((mask & PNG_FREE_TRNS) & info_ptr->free_me) | 397 if ((mask & PNG_FREE_TRNS) & info_ptr->free_me) |
| 383 #else | 398 #else |
| 384 if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS)) | 399 if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS)) |
| 385 #endif | 400 #endif |
| 386 { | 401 { |
| 387 png_free(png_ptr, info_ptr->trans); | 402 png_free(png_ptr, info_ptr->trans); |
| 388 info_ptr->trans = NULL; | 403 info_ptr->trans = NULL; |
| 389 info_ptr->valid &= ~PNG_INFO_tRNS; | 404 info_ptr->valid &= ~PNG_INFO_tRNS; |
| 390 #ifndef PNG_FREE_ME_SUPPORTED | 405 #ifndef PNG_FREE_ME_SUPPORTED |
| 391 png_ptr->flags &= ~PNG_FLAG_FREE_TRNS; | 406 png_ptr->flags &= ~PNG_FLAG_FREE_TRNS; |
| 392 #endif | 407 #endif |
| 393 } | 408 } |
| 394 #endif | 409 #endif |
| 395 | 410 |
| 396 #if defined(PNG_sCAL_SUPPORTED) | 411 #ifdef PNG_sCAL_SUPPORTED |
| 397 /* Free any sCAL entry */ | 412 /* Free any sCAL entry */ |
| 398 #ifdef PNG_FREE_ME_SUPPORTED | 413 #ifdef PNG_FREE_ME_SUPPORTED |
| 399 if ((mask & PNG_FREE_SCAL) & info_ptr->free_me) | 414 if ((mask & PNG_FREE_SCAL) & info_ptr->free_me) |
| 400 #else | 415 #else |
| 401 if (mask & PNG_FREE_SCAL) | 416 if (mask & PNG_FREE_SCAL) |
| 402 #endif | 417 #endif |
| 403 { | 418 { |
| 404 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) | 419 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) |
| 405 png_free(png_ptr, info_ptr->scal_s_width); | 420 png_free(png_ptr, info_ptr->scal_s_width); |
| 406 png_free(png_ptr, info_ptr->scal_s_height); | 421 png_free(png_ptr, info_ptr->scal_s_height); |
| 407 info_ptr->scal_s_width = NULL; | 422 info_ptr->scal_s_width = NULL; |
| 408 info_ptr->scal_s_height = NULL; | 423 info_ptr->scal_s_height = NULL; |
| 409 #endif | 424 #endif |
| 410 info_ptr->valid &= ~PNG_INFO_sCAL; | 425 info_ptr->valid &= ~PNG_INFO_sCAL; |
| 411 } | 426 } |
| 412 #endif | 427 #endif |
| 413 | 428 |
| 414 #if defined(PNG_pCAL_SUPPORTED) | 429 #ifdef PNG_pCAL_SUPPORTED |
| 415 /* Free any pCAL entry */ | 430 /* Free any pCAL entry */ |
| 416 #ifdef PNG_FREE_ME_SUPPORTED | 431 #ifdef PNG_FREE_ME_SUPPORTED |
| 417 if ((mask & PNG_FREE_PCAL) & info_ptr->free_me) | 432 if ((mask & PNG_FREE_PCAL) & info_ptr->free_me) |
| 418 #else | 433 #else |
| 419 if (mask & PNG_FREE_PCAL) | 434 if (mask & PNG_FREE_PCAL) |
| 420 #endif | 435 #endif |
| 421 { | 436 { |
| 422 png_free(png_ptr, info_ptr->pcal_purpose); | 437 png_free(png_ptr, info_ptr->pcal_purpose); |
| 423 png_free(png_ptr, info_ptr->pcal_units); | 438 png_free(png_ptr, info_ptr->pcal_units); |
| 424 info_ptr->pcal_purpose = NULL; | 439 info_ptr->pcal_purpose = NULL; |
| 425 info_ptr->pcal_units = NULL; | 440 info_ptr->pcal_units = NULL; |
| 426 if (info_ptr->pcal_params != NULL) | 441 if (info_ptr->pcal_params != NULL) |
| 427 { | 442 { |
| 428 int i; | 443 int i; |
| 429 for (i = 0; i < (int)info_ptr->pcal_nparams; i++) | 444 for (i = 0; i < (int)info_ptr->pcal_nparams; i++) |
| 430 { | 445 { |
| 431 png_free(png_ptr, info_ptr->pcal_params[i]); | 446 png_free(png_ptr, info_ptr->pcal_params[i]); |
| 432 info_ptr->pcal_params[i]=NULL; | 447 info_ptr->pcal_params[i] = NULL; |
| 433 } | 448 } |
| 434 png_free(png_ptr, info_ptr->pcal_params); | 449 png_free(png_ptr, info_ptr->pcal_params); |
| 435 info_ptr->pcal_params = NULL; | 450 info_ptr->pcal_params = NULL; |
| 436 } | 451 } |
| 437 info_ptr->valid &= ~PNG_INFO_pCAL; | 452 info_ptr->valid &= ~PNG_INFO_pCAL; |
| 438 } | 453 } |
| 439 #endif | 454 #endif |
| 440 | 455 |
| 441 #if defined(PNG_iCCP_SUPPORTED) | 456 #ifdef PNG_iCCP_SUPPORTED |
| 442 /* Free any iCCP entry */ | 457 /* Free any iCCP entry */ |
| 443 #ifdef PNG_FREE_ME_SUPPORTED | 458 #ifdef PNG_FREE_ME_SUPPORTED |
| 444 if ((mask & PNG_FREE_ICCP) & info_ptr->free_me) | 459 if ((mask & PNG_FREE_ICCP) & info_ptr->free_me) |
| 445 #else | 460 #else |
| 446 if (mask & PNG_FREE_ICCP) | 461 if (mask & PNG_FREE_ICCP) |
| 447 #endif | 462 #endif |
| 448 { | 463 { |
| 449 png_free(png_ptr, info_ptr->iccp_name); | 464 png_free(png_ptr, info_ptr->iccp_name); |
| 450 png_free(png_ptr, info_ptr->iccp_profile); | 465 png_free(png_ptr, info_ptr->iccp_profile); |
| 451 info_ptr->iccp_name = NULL; | 466 info_ptr->iccp_name = NULL; |
| 452 info_ptr->iccp_profile = NULL; | 467 info_ptr->iccp_profile = NULL; |
| 453 info_ptr->valid &= ~PNG_INFO_iCCP; | 468 info_ptr->valid &= ~PNG_INFO_iCCP; |
| 454 } | 469 } |
| 455 #endif | 470 #endif |
| 456 | 471 |
| 457 #if defined(PNG_sPLT_SUPPORTED) | 472 #ifdef PNG_sPLT_SUPPORTED |
| 458 /* Free a given sPLT entry, or (if num == -1) all sPLT entries */ | 473 /* Free a given sPLT entry, or (if num == -1) all sPLT entries */ |
| 459 #ifdef PNG_FREE_ME_SUPPORTED | 474 #ifdef PNG_FREE_ME_SUPPORTED |
| 460 if ((mask & PNG_FREE_SPLT) & info_ptr->free_me) | 475 if ((mask & PNG_FREE_SPLT) & info_ptr->free_me) |
| 461 #else | 476 #else |
| 462 if (mask & PNG_FREE_SPLT) | 477 if (mask & PNG_FREE_SPLT) |
| 463 #endif | 478 #endif |
| 464 { | 479 { |
| 465 if (num != -1) | 480 if (num != -1) |
| 466 { | 481 { |
| 467 if (info_ptr->splt_palettes) | 482 if (info_ptr->splt_palettes) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 482 | 497 |
| 483 png_free(png_ptr, info_ptr->splt_palettes); | 498 png_free(png_ptr, info_ptr->splt_palettes); |
| 484 info_ptr->splt_palettes = NULL; | 499 info_ptr->splt_palettes = NULL; |
| 485 info_ptr->splt_palettes_num = 0; | 500 info_ptr->splt_palettes_num = 0; |
| 486 } | 501 } |
| 487 info_ptr->valid &= ~PNG_INFO_sPLT; | 502 info_ptr->valid &= ~PNG_INFO_sPLT; |
| 488 } | 503 } |
| 489 } | 504 } |
| 490 #endif | 505 #endif |
| 491 | 506 |
| 492 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) | 507 #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED |
| 493 if (png_ptr->unknown_chunk.data) | 508 if (png_ptr->unknown_chunk.data) |
| 494 { | 509 { |
| 495 png_free(png_ptr, png_ptr->unknown_chunk.data); | 510 png_free(png_ptr, png_ptr->unknown_chunk.data); |
| 496 png_ptr->unknown_chunk.data = NULL; | 511 png_ptr->unknown_chunk.data = NULL; |
| 497 } | 512 } |
| 498 | 513 |
| 499 #ifdef PNG_FREE_ME_SUPPORTED | 514 #ifdef PNG_FREE_ME_SUPPORTED |
| 500 if ((mask & PNG_FREE_UNKN) & info_ptr->free_me) | 515 if ((mask & PNG_FREE_UNKN) & info_ptr->free_me) |
| 501 #else | 516 #else |
| 502 if (mask & PNG_FREE_UNKN) | 517 if (mask & PNG_FREE_UNKN) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 520 png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i); | 535 png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i); |
| 521 | 536 |
| 522 png_free(png_ptr, info_ptr->unknown_chunks); | 537 png_free(png_ptr, info_ptr->unknown_chunks); |
| 523 info_ptr->unknown_chunks = NULL; | 538 info_ptr->unknown_chunks = NULL; |
| 524 info_ptr->unknown_chunks_num = 0; | 539 info_ptr->unknown_chunks_num = 0; |
| 525 } | 540 } |
| 526 } | 541 } |
| 527 } | 542 } |
| 528 #endif | 543 #endif |
| 529 | 544 |
| 530 #if defined(PNG_hIST_SUPPORTED) | 545 #ifdef PNG_hIST_SUPPORTED |
| 531 /* Free any hIST entry */ | 546 /* Free any hIST entry */ |
| 532 #ifdef PNG_FREE_ME_SUPPORTED | 547 #ifdef PNG_FREE_ME_SUPPORTED |
| 533 if ((mask & PNG_FREE_HIST) & info_ptr->free_me) | 548 if ((mask & PNG_FREE_HIST) & info_ptr->free_me) |
| 534 #else | 549 #else |
| 535 if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST)) | 550 if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST)) |
| 536 #endif | 551 #endif |
| 537 { | 552 { |
| 538 png_free(png_ptr, info_ptr->hist); | 553 png_free(png_ptr, info_ptr->hist); |
| 539 info_ptr->hist = NULL; | 554 info_ptr->hist = NULL; |
| 540 info_ptr->valid &= ~PNG_INFO_hIST; | 555 info_ptr->valid &= ~PNG_INFO_hIST; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 553 { | 568 { |
| 554 png_zfree(png_ptr, info_ptr->palette); | 569 png_zfree(png_ptr, info_ptr->palette); |
| 555 info_ptr->palette = NULL; | 570 info_ptr->palette = NULL; |
| 556 info_ptr->valid &= ~PNG_INFO_PLTE; | 571 info_ptr->valid &= ~PNG_INFO_PLTE; |
| 557 #ifndef PNG_FREE_ME_SUPPORTED | 572 #ifndef PNG_FREE_ME_SUPPORTED |
| 558 png_ptr->flags &= ~PNG_FLAG_FREE_PLTE; | 573 png_ptr->flags &= ~PNG_FLAG_FREE_PLTE; |
| 559 #endif | 574 #endif |
| 560 info_ptr->num_palette = 0; | 575 info_ptr->num_palette = 0; |
| 561 } | 576 } |
| 562 | 577 |
| 563 #if defined(PNG_INFO_IMAGE_SUPPORTED) | 578 #ifdef PNG_INFO_IMAGE_SUPPORTED |
| 564 /* Free any image bits attached to the info structure */ | 579 /* Free any image bits attached to the info structure */ |
| 565 #ifdef PNG_FREE_ME_SUPPORTED | 580 #ifdef PNG_FREE_ME_SUPPORTED |
| 566 if ((mask & PNG_FREE_ROWS) & info_ptr->free_me) | 581 if ((mask & PNG_FREE_ROWS) & info_ptr->free_me) |
| 567 #else | 582 #else |
| 568 if (mask & PNG_FREE_ROWS) | 583 if (mask & PNG_FREE_ROWS) |
| 569 #endif | 584 #endif |
| 570 { | 585 { |
| 571 if (info_ptr->row_pointers) | 586 if (info_ptr->row_pointers) |
| 572 { | 587 { |
| 573 int row; | 588 int row; |
| 574 for (row = 0; row < (int)info_ptr->height; row++) | 589 for (row = 0; row < (int)info_ptr->height; row++) |
| 575 { | 590 { |
| 576 png_free(png_ptr, info_ptr->row_pointers[row]); | 591 png_free(png_ptr, info_ptr->row_pointers[row]); |
| 577 info_ptr->row_pointers[row]=NULL; | 592 info_ptr->row_pointers[row] = NULL; |
| 578 } | 593 } |
| 579 png_free(png_ptr, info_ptr->row_pointers); | 594 png_free(png_ptr, info_ptr->row_pointers); |
| 580 info_ptr->row_pointers=NULL; | 595 info_ptr->row_pointers = NULL; |
| 581 } | 596 } |
| 582 info_ptr->valid &= ~PNG_INFO_IDAT; | 597 info_ptr->valid &= ~PNG_INFO_IDAT; |
| 583 } | 598 } |
| 584 #endif | 599 #endif |
| 585 | 600 |
| 586 #ifdef PNG_FREE_ME_SUPPORTED | 601 #ifdef PNG_FREE_ME_SUPPORTED |
| 587 if (num == -1) | 602 if (num == -1) |
| 588 info_ptr->free_me &= ~mask; | 603 info_ptr->free_me &= ~mask; |
| 589 else | 604 else |
| 590 info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL); | 605 info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL); |
| 591 #endif | 606 #endif |
| 592 } | 607 } |
| 593 | 608 |
| 594 /* This is an internal routine to free any memory that the info struct is | 609 /* This is an internal routine to free any memory that the info struct is |
| 595 * pointing to before re-using it or freeing the struct itself. Recall | 610 * pointing to before re-using it or freeing the struct itself. Recall |
| 596 * that png_free() checks for NULL pointers for us. | 611 * that png_free() checks for NULL pointers for us. |
| 597 */ | 612 */ |
| 598 void /* PRIVATE */ | 613 void /* PRIVATE */ |
| 599 png_info_destroy(png_structp png_ptr, png_infop info_ptr) | 614 png_info_destroy(png_structp png_ptr, png_infop info_ptr) |
| 600 { | 615 { |
| 601 png_debug(1, "in png_info_destroy"); | 616 png_debug(1, "in png_info_destroy"); |
| 602 | 617 |
| 603 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); | 618 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); |
| 604 | 619 |
| 605 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) | 620 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
| 606 if (png_ptr->num_chunk_list) | 621 if (png_ptr->num_chunk_list) |
| 607 { | 622 { |
| 608 png_free(png_ptr, png_ptr->chunk_list); | 623 png_free(png_ptr, png_ptr->chunk_list); |
| 609 png_ptr->chunk_list=NULL; | 624 png_ptr->chunk_list = NULL; |
| 610 png_ptr->num_chunk_list = 0; | 625 png_ptr->num_chunk_list = 0; |
| 611 } | 626 } |
| 612 #endif | 627 #endif |
| 613 | 628 |
| 614 png_info_init_3(&info_ptr, png_sizeof(png_info)); | 629 png_info_init_3(&info_ptr, png_sizeof(png_info)); |
| 615 } | 630 } |
| 616 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ | 631 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ |
| 617 | 632 |
| 618 /* This function returns a pointer to the io_ptr associated with the user | 633 /* This function returns a pointer to the io_ptr associated with the user |
| 619 * functions. The application should free any memory associated with this | 634 * functions. The application should free any memory associated with this |
| 620 * pointer before png_write_destroy() or png_read_destroy() are called. | 635 * pointer before png_write_destroy() or png_read_destroy() are called. |
| 621 */ | 636 */ |
| 622 png_voidp PNGAPI | 637 png_voidp PNGAPI |
| 623 png_get_io_ptr(png_structp png_ptr) | 638 png_get_io_ptr(png_structp png_ptr) |
| 624 { | 639 { |
| 625 if (png_ptr == NULL) | 640 if (png_ptr == NULL) |
| 626 return (NULL); | 641 return (NULL); |
| 627 return (png_ptr->io_ptr); | 642 return (png_ptr->io_ptr); |
| 628 } | 643 } |
| 629 | 644 |
| 630 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) | 645 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) |
| 631 #if !defined(PNG_NO_STDIO) | 646 #ifdef PNG_STDIO_SUPPORTED |
| 632 /* Initialize the default input/output functions for the PNG file. If you | 647 /* Initialize the default input/output functions for the PNG file. If you |
| 633 * use your own read or write routines, you can call either png_set_read_fn() | 648 * use your own read or write routines, you can call either png_set_read_fn() |
| 634 * or png_set_write_fn() instead of png_init_io(). If you have defined | 649 * or png_set_write_fn() instead of png_init_io(). If you have defined |
| 635 * PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't | 650 * PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't |
| 636 * necessarily available. | 651 * necessarily available. |
| 637 */ | 652 */ |
| 638 void PNGAPI | 653 void PNGAPI |
| 639 png_init_io(png_structp png_ptr, png_FILE_p fp) | 654 png_init_io(png_structp png_ptr, png_FILE_p fp) |
| 640 { | 655 { |
| 641 png_debug(1, "in png_init_io"); | 656 png_debug(1, "in png_init_io"); |
| 657 |
| 642 if (png_ptr == NULL) | 658 if (png_ptr == NULL) |
| 643 return; | 659 return; |
| 660 |
| 644 png_ptr->io_ptr = (png_voidp)fp; | 661 png_ptr->io_ptr = (png_voidp)fp; |
| 645 } | 662 } |
| 646 #endif | 663 #endif |
| 647 | 664 |
| 648 #if defined(PNG_TIME_RFC1123_SUPPORTED) | 665 #ifdef PNG_TIME_RFC1123_SUPPORTED |
| 649 /* Convert the supplied time into an RFC 1123 string suitable for use in | 666 /* Convert the supplied time into an RFC 1123 string suitable for use in |
| 650 * a "Creation Time" or other text-based time string. | 667 * a "Creation Time" or other text-based time string. |
| 651 */ | 668 */ |
| 652 png_charp PNGAPI | 669 png_charp PNGAPI |
| 653 png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) | 670 png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) |
| 654 { | 671 { |
| 655 static PNG_CONST char short_months[12][4] = | 672 static PNG_CONST char short_months[12][4] = |
| 656 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | 673 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
| 657 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; | 674 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
| 658 | 675 |
| 659 if (png_ptr == NULL) | 676 if (png_ptr == NULL) |
| 660 return (NULL); | 677 return (NULL); |
| 661 if (png_ptr->time_buffer == NULL) | 678 if (png_ptr->time_buffer == NULL) |
| 662 { | 679 { |
| 663 png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29* | 680 png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29* |
| 664 png_sizeof(char))); | 681 png_sizeof(char))); |
| 665 } | 682 } |
| 666 | 683 |
| 667 #if defined(_WIN32_WCE) | 684 #ifdef _WIN32_WCE |
| 668 { | 685 { |
| 669 wchar_t time_buf[29]; | 686 wchar_t time_buf[29]; |
| 670 wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"), | 687 wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"), |
| 671 ptime->day % 32, short_months[(ptime->month - 1) % 12], | 688 ptime->day % 32, short_months[(ptime->month - 1) % 12], |
| 672 ptime->year, ptime->hour % 24, ptime->minute % 60, | 689 ptime->year, ptime->hour % 24, ptime->minute % 60, |
| 673 ptime->second % 61); | 690 ptime->second % 61); |
| 674 WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29, | 691 WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, |
| 675 NULL, NULL); | 692 29, NULL, NULL); |
| 676 } | 693 } |
| 677 #else | 694 #else |
| 678 #ifdef USE_FAR_KEYWORD | 695 #ifdef USE_FAR_KEYWORD |
| 679 { | 696 { |
| 680 char near_time_buf[29]; | 697 char near_time_buf[29]; |
| 681 png_snprintf6(near_time_buf, 29, "%d %s %d %02d:%02d:%02d +0000", | 698 png_snprintf6(near_time_buf, 29, "%d %s %d %02d:%02d:%02d +0000", |
| 682 ptime->day % 32, short_months[(ptime->month - 1) % 12], | 699 ptime->day % 32, short_months[(ptime->month - 1) % 12], |
| 683 ptime->year, ptime->hour % 24, ptime->minute % 60, | 700 ptime->year, ptime->hour % 24, ptime->minute % 60, |
| 684 ptime->second % 61); | 701 ptime->second % 61); |
| 685 png_memcpy(png_ptr->time_buffer, near_time_buf, | 702 png_memcpy(png_ptr->time_buffer, near_time_buf, |
| 686 29*png_sizeof(char)); | 703 29*png_sizeof(char)); |
| 687 } | 704 } |
| 688 #else | 705 #else |
| 689 png_snprintf6(png_ptr->time_buffer, 29, "%d %s %d %02d:%02d:%02d +0000", | 706 png_snprintf6(png_ptr->time_buffer, 29, "%d %s %d %02d:%02d:%02d +0000", |
| 690 ptime->day % 32, short_months[(ptime->month - 1) % 12], | 707 ptime->day % 32, short_months[(ptime->month - 1) % 12], |
| 691 ptime->year, ptime->hour % 24, ptime->minute % 60, | 708 ptime->year, ptime->hour % 24, ptime->minute % 60, |
| 692 ptime->second % 61); | 709 ptime->second % 61); |
| 693 #endif | 710 #endif |
| 694 #endif /* _WIN32_WCE */ | 711 #endif /* _WIN32_WCE */ |
| 695 return ((png_charp)png_ptr->time_buffer); | 712 return ((png_charp)png_ptr->time_buffer); |
| 696 } | 713 } |
| 697 #endif /* PNG_TIME_RFC1123_SUPPORTED */ | 714 #endif /* PNG_TIME_RFC1123_SUPPORTED */ |
| 698 | 715 |
| 699 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ | 716 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ |
| 700 | 717 |
| 701 png_charp PNGAPI | 718 png_charp PNGAPI |
| 702 png_get_copyright(png_structp png_ptr) | 719 png_get_copyright(png_structp png_ptr) |
| 703 { | 720 { |
| 704 png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ | 721 png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ |
| 705 return ((png_charp) "\n libpng version 1.2.37 - June 4, 2009\n\ | 722 #ifdef PNG_STRING_COPYRIGHT |
| 706 Copyright (c) 1998-2009 Glenn Randers-Pehrson\n\ | 723 return PNG_STRING_COPYRIGHT |
| 707 Copyright (c) 1996-1997 Andreas Dilger\n\ | 724 #else |
| 708 Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n"); | 725 #ifdef __STDC__ |
| 726 return ((png_charp) PNG_STRING_NEWLINE \ |
| 727 "libpng version 1.2.43 - February 25, 2010" PNG_STRING_NEWLINE \ |
| 728 "Copyright (c) 1998-2010 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ |
| 729 "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ |
| 730 "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ |
| 731 PNG_STRING_NEWLINE); |
| 732 #else |
| 733 return ((png_charp) "libpng version 1.2.43 - February 25, 2010\ |
| 734 Copyright (c) 1998-2010 Glenn Randers-Pehrson\ |
| 735 Copyright (c) 1996-1997 Andreas Dilger\ |
| 736 Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."); |
| 737 #endif |
| 738 #endif |
| 709 } | 739 } |
| 710 | 740 |
| 711 /* The following return the library version as a short string in the | 741 /* The following return the library version as a short string in the |
| 712 * format 1.0.0 through 99.99.99zz. To get the version of *.h files | 742 * format 1.0.0 through 99.99.99zz. To get the version of *.h files |
| 713 * used with your application, print out PNG_LIBPNG_VER_STRING, which | 743 * used with your application, print out PNG_LIBPNG_VER_STRING, which |
| 714 * is defined in png.h. | 744 * is defined in png.h. |
| 715 * Note: now there is no difference between png_get_libpng_ver() and | 745 * Note: now there is no difference between png_get_libpng_ver() and |
| 716 * png_get_header_ver(). Due to the version_nn_nn_nn typedef guard, | 746 * png_get_header_ver(). Due to the version_nn_nn_nn typedef guard, |
| 717 * it is guaranteed that png.c uses the correct version of png.h. | 747 * it is guaranteed that png.c uses the correct version of png.h. |
| 718 */ | 748 */ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 730 /* Version of *.h files used when building libpng */ | 760 /* Version of *.h files used when building libpng */ |
| 731 png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ | 761 png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ |
| 732 return ((png_charp) PNG_LIBPNG_VER_STRING); | 762 return ((png_charp) PNG_LIBPNG_VER_STRING); |
| 733 } | 763 } |
| 734 | 764 |
| 735 png_charp PNGAPI | 765 png_charp PNGAPI |
| 736 png_get_header_version(png_structp png_ptr) | 766 png_get_header_version(png_structp png_ptr) |
| 737 { | 767 { |
| 738 /* Returns longer string containing both version and date */ | 768 /* Returns longer string containing both version and date */ |
| 739 png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ | 769 png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ |
| 770 #ifdef __STDC__ |
| 740 return ((png_charp) PNG_HEADER_VERSION_STRING | 771 return ((png_charp) PNG_HEADER_VERSION_STRING |
| 741 #ifndef PNG_READ_SUPPORTED | 772 #ifndef PNG_READ_SUPPORTED |
| 742 " (NO READ SUPPORT)" | 773 " (NO READ SUPPORT)" |
| 743 #endif | 774 #endif |
| 744 "\n"); | 775 PNG_STRING_NEWLINE); |
| 776 #else |
| 777 return ((png_charp) PNG_HEADER_VERSION_STRING); |
| 778 #endif |
| 745 } | 779 } |
| 746 | 780 |
| 747 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) | 781 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) |
| 748 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED | 782 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
| 749 int PNGAPI | 783 int PNGAPI |
| 750 png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name) | 784 png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name) |
| 751 { | 785 { |
| 752 /* Check chunk_name and return "keep" value if it's on the list, else 0 */ | 786 /* Check chunk_name and return "keep" value if it's on the list, else 0 */ |
| 753 int i; | 787 int i; |
| 754 png_bytep p; | 788 png_bytep p; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 775 /* This function was added to libpng-1.0.7 */ | 809 /* This function was added to libpng-1.0.7 */ |
| 776 png_uint_32 PNGAPI | 810 png_uint_32 PNGAPI |
| 777 png_access_version_number(void) | 811 png_access_version_number(void) |
| 778 { | 812 { |
| 779 /* Version of *.c files used when building libpng */ | 813 /* Version of *.c files used when building libpng */ |
| 780 return((png_uint_32) PNG_LIBPNG_VER); | 814 return((png_uint_32) PNG_LIBPNG_VER); |
| 781 } | 815 } |
| 782 | 816 |
| 783 | 817 |
| 784 #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) | 818 #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) |
| 785 #if !defined(PNG_1_0_X) | 819 #ifndef PNG_1_0_X |
| 786 /* This function was added to libpng 1.2.0 */ | 820 /* This function was added to libpng 1.2.0 */ |
| 787 int PNGAPI | 821 int PNGAPI |
| 788 png_mmx_support(void) | 822 png_mmx_support(void) |
| 789 { | 823 { |
| 790 /* Obsolete, to be removed from libpng-1.4.0 */ | 824 /* Obsolete, to be removed from libpng-1.4.0 */ |
| 791 return -1; | 825 return -1; |
| 792 } | 826 } |
| 793 #endif /* PNG_1_0_X */ | 827 #endif /* PNG_1_0_X */ |
| 794 #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */ | 828 #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */ |
| 795 | 829 |
| 796 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) | 830 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) |
| 797 #ifdef PNG_SIZE_T | 831 #ifdef PNG_SIZE_T |
| 798 /* Added at libpng version 1.2.6 */ | 832 /* Added at libpng version 1.2.6 */ |
| 799 PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size)); | 833 PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size)); |
| 800 png_size_t PNGAPI | 834 png_size_t PNGAPI |
| 801 png_convert_size(size_t size) | 835 png_convert_size(size_t size) |
| 802 { | 836 { |
| 803 if (size > (png_size_t)-1) | 837 if (size > (png_size_t)-1) |
| 804 PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */ | 838 PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */ |
| 805 return ((png_size_t)size); | 839 return ((png_size_t)size); |
| 806 } | 840 } |
| 807 #endif /* PNG_SIZE_T */ | 841 #endif /* PNG_SIZE_T */ |
| 808 | 842 |
| 809 /* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */ | 843 /* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */ |
| 810 #if defined(PNG_cHRM_SUPPORTED) | 844 #ifdef PNG_cHRM_SUPPORTED |
| 811 #if !defined(PNG_NO_CHECK_cHRM) | 845 #ifdef PNG_CHECK_cHRM_SUPPORTED |
| 812 | 846 |
| 813 /* | 847 /* |
| 814 * Multiply two 32-bit numbers, V1 and V2, using 32-bit | 848 * Multiply two 32-bit numbers, V1 and V2, using 32-bit |
| 815 * arithmetic, to produce a 64 bit result in the HI/LO words. | 849 * arithmetic, to produce a 64 bit result in the HI/LO words. |
| 816 * | 850 * |
| 817 * A B | 851 * A B |
| 818 * x C D | 852 * x C D |
| 819 * ------ | 853 * ------ |
| 820 * AD || BD | 854 * AD || BD |
| 821 * AC || CB || 0 | 855 * AC || CB || 0 |
| 822 * | 856 * |
| 823 * where A and B are the high and low 16-bit words of V1, | 857 * where A and B are the high and low 16-bit words of V1, |
| 824 * C and D are the 16-bit words of V2, AD is the product of | 858 * C and D are the 16-bit words of V2, AD is the product of |
| 825 * A and D, and X || Y is (X << 16) + Y. | 859 * A and D, and X || Y is (X << 16) + Y. |
| 826 */ | 860 */ |
| 827 | 861 |
| 828 void png_64bit_product (long v1, long v2, unsigned long *hi_product, | 862 void /* PRIVATE */ |
| 863 png_64bit_product (long v1, long v2, unsigned long *hi_product, |
| 829 unsigned long *lo_product) | 864 unsigned long *lo_product) |
| 830 { | 865 { |
| 831 int a, b, c, d; | 866 int a, b, c, d; |
| 832 long lo, hi, x, y; | 867 long lo, hi, x, y; |
| 833 | 868 |
| 834 a = (v1 >> 16) & 0xffff; | 869 a = (v1 >> 16) & 0xffff; |
| 835 b = v1 & 0xffff; | 870 b = v1 & 0xffff; |
| 836 c = (v2 >> 16) & 0xffff; | 871 c = (v2 >> 16) & 0xffff; |
| 837 d = v2 & 0xffff; | 872 d = v2 & 0xffff; |
| 838 | 873 |
| 839 lo = b * d; /* BD */ | 874 lo = b * d; /* BD */ |
| 840 x = a * d + c * b; /* AD + CB */ | 875 x = a * d + c * b; /* AD + CB */ |
| 841 y = ((lo >> 16) & 0xffff) + x; | 876 y = ((lo >> 16) & 0xffff) + x; |
| 842 | 877 |
| 843 lo = (lo & 0xffff) | ((y & 0xffff) << 16); | 878 lo = (lo & 0xffff) | ((y & 0xffff) << 16); |
| 844 hi = (y >> 16) & 0xffff; | 879 hi = (y >> 16) & 0xffff; |
| 845 | 880 |
| 846 hi += a * c; /* AC */ | 881 hi += a * c; /* AC */ |
| 847 | 882 |
| 848 *hi_product = (unsigned long)hi; | 883 *hi_product = (unsigned long)hi; |
| 849 *lo_product = (unsigned long)lo; | 884 *lo_product = (unsigned long)lo; |
| 850 } | 885 } |
| 851 | 886 |
| 852 int /* private */ | 887 int /* PRIVATE */ |
| 853 png_check_cHRM_fixed(png_structp png_ptr, | 888 png_check_cHRM_fixed(png_structp png_ptr, |
| 854 png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, | 889 png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, |
| 855 png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, | 890 png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, |
| 856 png_fixed_point blue_x, png_fixed_point blue_y) | 891 png_fixed_point blue_x, png_fixed_point blue_y) |
| 857 { | 892 { |
| 858 int ret = 1; | 893 int ret = 1; |
| 859 unsigned long xy_hi,xy_lo,yx_hi,yx_lo; | 894 unsigned long xy_hi,xy_lo,yx_hi,yx_lo; |
| 860 | 895 |
| 861 png_debug(1, "in function png_check_cHRM_fixed"); | 896 png_debug(1, "in function png_check_cHRM_fixed"); |
| 897 |
| 862 if (png_ptr == NULL) | 898 if (png_ptr == NULL) |
| 863 return 0; | 899 return 0; |
| 864 | 900 |
| 865 if (white_x < 0 || white_y <= 0 || | 901 if (white_x < 0 || white_y <= 0 || |
| 866 red_x < 0 || red_y < 0 || | 902 red_x < 0 || red_y < 0 || |
| 867 green_x < 0 || green_y < 0 || | 903 green_x < 0 || green_y < 0 || |
| 868 blue_x < 0 || blue_y < 0) | 904 blue_x < 0 || blue_y < 0) |
| 869 { | 905 { |
| 870 png_warning(png_ptr, | 906 png_warning(png_ptr, |
| 871 "Ignoring attempt to set negative chromaticity value"); | 907 "Ignoring attempt to set negative chromaticity value"); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 | 946 |
| 911 if (xy_hi == yx_hi && xy_lo == yx_lo) | 947 if (xy_hi == yx_hi && xy_lo == yx_lo) |
| 912 { | 948 { |
| 913 png_warning(png_ptr, | 949 png_warning(png_ptr, |
| 914 "Ignoring attempt to set cHRM RGB triangle with zero area"); | 950 "Ignoring attempt to set cHRM RGB triangle with zero area"); |
| 915 ret = 0; | 951 ret = 0; |
| 916 } | 952 } |
| 917 | 953 |
| 918 return ret; | 954 return ret; |
| 919 } | 955 } |
| 920 #endif /* NO_PNG_CHECK_cHRM */ | 956 #endif /* PNG_CHECK_cHRM_SUPPORTED */ |
| 921 #endif /* PNG_cHRM_SUPPORTED */ | 957 #endif /* PNG_cHRM_SUPPORTED */ |
| 958 |
| 959 void /* PRIVATE */ |
| 960 png_check_IHDR(png_structp png_ptr, |
| 961 png_uint_32 width, png_uint_32 height, int bit_depth, |
| 962 int color_type, int interlace_type, int compression_type, |
| 963 int filter_type) |
| 964 { |
| 965 int error = 0; |
| 966 |
| 967 /* Check for width and height valid values */ |
| 968 if (width == 0) |
| 969 { |
| 970 png_warning(png_ptr, "Image width is zero in IHDR"); |
| 971 error = 1; |
| 972 } |
| 973 |
| 974 if (height == 0) |
| 975 { |
| 976 png_warning(png_ptr, "Image height is zero in IHDR"); |
| 977 error = 1; |
| 978 } |
| 979 |
| 980 #ifdef PNG_SET_USER_LIMITS_SUPPORTED |
| 981 if (width > png_ptr->user_width_max || width > PNG_USER_WIDTH_MAX) |
| 982 #else |
| 983 if (width > PNG_USER_WIDTH_MAX) |
| 984 #endif |
| 985 { |
| 986 png_warning(png_ptr, "Image width exceeds user limit in IHDR"); |
| 987 error = 1; |
| 988 } |
| 989 |
| 990 #ifdef PNG_SET_USER_LIMITS_SUPPORTED |
| 991 if (height > png_ptr->user_height_max || height > PNG_USER_HEIGHT_MAX) |
| 992 #else |
| 993 if (height > PNG_USER_HEIGHT_MAX) |
| 994 #endif |
| 995 { |
| 996 png_warning(png_ptr, "Image height exceeds user limit in IHDR"); |
| 997 error = 1; |
| 998 } |
| 999 |
| 1000 if (width > PNG_UINT_31_MAX) |
| 1001 { |
| 1002 png_warning(png_ptr, "Invalid image width in IHDR"); |
| 1003 error = 1; |
| 1004 } |
| 1005 |
| 1006 if ( height > PNG_UINT_31_MAX) |
| 1007 { |
| 1008 png_warning(png_ptr, "Invalid image height in IHDR"); |
| 1009 error = 1; |
| 1010 } |
| 1011 |
| 1012 if ( width > (PNG_UINT_32_MAX |
| 1013 >> 3) /* 8-byte RGBA pixels */ |
| 1014 - 64 /* bigrowbuf hack */ |
| 1015 - 1 /* filter byte */ |
| 1016 - 7*8 /* rounding of width to multiple of 8 pixels */ |
| 1017 - 8) /* extra max_pixel_depth pad */ |
| 1018 png_warning(png_ptr, "Width is too large for libpng to process pixels"); |
| 1019 |
| 1020 /* Check other values */ |
| 1021 if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && |
| 1022 bit_depth != 8 && bit_depth != 16) |
| 1023 { |
| 1024 png_warning(png_ptr, "Invalid bit depth in IHDR"); |
| 1025 error = 1; |
| 1026 } |
| 1027 |
| 1028 if (color_type < 0 || color_type == 1 || |
| 1029 color_type == 5 || color_type > 6) |
| 1030 { |
| 1031 png_warning(png_ptr, "Invalid color type in IHDR"); |
| 1032 error = 1; |
| 1033 } |
| 1034 |
| 1035 if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) || |
| 1036 ((color_type == PNG_COLOR_TYPE_RGB || |
| 1037 color_type == PNG_COLOR_TYPE_GRAY_ALPHA || |
| 1038 color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8)) |
| 1039 { |
| 1040 png_warning(png_ptr, "Invalid color type/bit depth combination in IHDR"); |
| 1041 error = 1; |
| 1042 } |
| 1043 |
| 1044 if (interlace_type >= PNG_INTERLACE_LAST) |
| 1045 { |
| 1046 png_warning(png_ptr, "Unknown interlace method in IHDR"); |
| 1047 error = 1; |
| 1048 } |
| 1049 |
| 1050 if (compression_type != PNG_COMPRESSION_TYPE_BASE) |
| 1051 { |
| 1052 png_warning(png_ptr, "Unknown compression method in IHDR"); |
| 1053 error = 1; |
| 1054 } |
| 1055 |
| 1056 #ifdef PNG_MNG_FEATURES_SUPPORTED |
| 1057 /* Accept filter_method 64 (intrapixel differencing) only if |
| 1058 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and |
| 1059 * 2. Libpng did not read a PNG signature (this filter_method is only |
| 1060 * used in PNG datastreams that are embedded in MNG datastreams) and |
| 1061 * 3. The application called png_permit_mng_features with a mask that |
| 1062 * included PNG_FLAG_MNG_FILTER_64 and |
| 1063 * 4. The filter_method is 64 and |
| 1064 * 5. The color_type is RGB or RGBA |
| 1065 */ |
| 1066 if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) && |
| 1067 png_ptr->mng_features_permitted) |
| 1068 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); |
| 1069 |
| 1070 if (filter_type != PNG_FILTER_TYPE_BASE) |
| 1071 { |
| 1072 if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && |
| 1073 (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && |
| 1074 ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) && |
| 1075 (color_type == PNG_COLOR_TYPE_RGB || |
| 1076 color_type == PNG_COLOR_TYPE_RGB_ALPHA))) |
| 1077 { |
| 1078 png_warning(png_ptr, "Unknown filter method in IHDR"); |
| 1079 error = 1; |
| 1080 } |
| 1081 |
| 1082 if (png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) |
| 1083 { |
| 1084 png_warning(png_ptr, "Invalid filter method in IHDR"); |
| 1085 error = 1; |
| 1086 } |
| 1087 } |
| 1088 |
| 1089 #else |
| 1090 if (filter_type != PNG_FILTER_TYPE_BASE) |
| 1091 { |
| 1092 png_warning(png_ptr, "Unknown filter method in IHDR"); |
| 1093 error = 1; |
| 1094 } |
| 1095 #endif |
| 1096 |
| 1097 if (error == 1) |
| 1098 png_error(png_ptr, "Invalid IHDR data"); |
| 1099 } |
| 922 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ | 1100 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ |
| OLD | NEW |