| 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.21 October 4, 2007 | 4 * Last changed in libpng 1.2.30 [August 15, 2008] |
| 5 * For conditions of distribution and use, see copyright notice in png.h | 5 * For conditions of distribution and use, see copyright notice in png.h |
| 6 * Copyright (c) 1998-2007 Glenn Randers-Pehrson | 6 * Copyright (c) 1998-2008 Glenn Randers-Pehrson |
| 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
| 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #define PNG_INTERNAL | 11 #define PNG_INTERNAL |
| 12 #define PNG_NO_EXTERN | 12 #define PNG_NO_EXTERN |
| 13 #include "png.h" | 13 #include "png.h" |
| 14 | 14 |
| 15 /* Generate a compiler error if there is an old png.h in the search path. */ | 15 /* Generate a compiler error if there is an old png.h in the search path. */ |
| 16 typedef version_1_2_29 Your_png_h_is_not_version_1_2_29; | 16 typedef version_1_2_33 Your_png_h_is_not_version_1_2_33; |
| 17 | 17 |
| 18 /* Version information for C files. This had better match the version | 18 /* Version information for C files. This had better match the version |
| 19 * string defined in png.h. */ | 19 * string defined in png.h. */ |
| 20 | 20 |
| 21 #ifdef PNG_USE_GLOBAL_ARRAYS | 21 #ifdef PNG_USE_GLOBAL_ARRAYS |
| 22 /* png_libpng_ver was changed to a function in version 1.0.5c */ | 22 /* 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; | 23 PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING; |
| 24 | 24 |
| 25 #ifdef PNG_READ_SUPPORTED | 25 #ifdef PNG_READ_SUPPORTED |
| 26 | 26 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 /* Tells libpng that we have already handled the first "num_bytes" bytes | 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 | 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 | 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. | 88 * or write any of the magic bytes before it starts on the IHDR. |
| 89 */ | 89 */ |
| 90 | 90 |
| 91 #ifdef PNG_READ_SUPPORTED | 91 #ifdef PNG_READ_SUPPORTED |
| 92 void PNGAPI | 92 void PNGAPI |
| 93 png_set_sig_bytes(png_structp png_ptr, int num_bytes) | 93 png_set_sig_bytes(png_structp png_ptr, int num_bytes) |
| 94 { | 94 { |
| 95 if(png_ptr == NULL) return; | 95 if (png_ptr == NULL) return; |
| 96 png_debug(1, "in png_set_sig_bytes\n"); | 96 png_debug(1, "in png_set_sig_bytes\n"); |
| 97 if (num_bytes > 8) | 97 if (num_bytes > 8) |
| 98 png_error(png_ptr, "Too many bytes for PNG signature."); | 98 png_error(png_ptr, "Too many bytes for PNG signature."); |
| 99 | 99 |
| 100 png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes); | 100 png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes); |
| 101 } | 101 } |
| 102 | 102 |
| 103 /* Checks whether the supplied bytes match the PNG signature. We allow | 103 /* Checks whether the supplied bytes match the PNG signature. We allow |
| 104 * checking less than the full 8-byte signature so that those apps that | 104 * checking less than the full 8-byte signature so that those apps that |
| 105 * already read the first few bytes of a file to determine the file type | 105 * already read the first few bytes of a file to determine the file type |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 #else | 146 #else |
| 147 voidpf /* private */ | 147 voidpf /* private */ |
| 148 #endif | 148 #endif |
| 149 png_zalloc(voidpf png_ptr, uInt items, uInt size) | 149 png_zalloc(voidpf png_ptr, uInt items, uInt size) |
| 150 { | 150 { |
| 151 png_voidp ptr; | 151 png_voidp ptr; |
| 152 png_structp p=(png_structp)png_ptr; | 152 png_structp p=(png_structp)png_ptr; |
| 153 png_uint_32 save_flags=p->flags; | 153 png_uint_32 save_flags=p->flags; |
| 154 png_uint_32 num_bytes; | 154 png_uint_32 num_bytes; |
| 155 | 155 |
| 156 if(png_ptr == NULL) return (NULL); | 156 if (png_ptr == NULL) return (NULL); |
| 157 if (items > PNG_UINT_32_MAX/size) | 157 if (items > PNG_UINT_32_MAX/size) |
| 158 { | 158 { |
| 159 png_warning (p, "Potential overflow in png_zalloc()"); | 159 png_warning (p, "Potential overflow in png_zalloc()"); |
| 160 return (NULL); | 160 return (NULL); |
| 161 } | 161 } |
| 162 num_bytes = (png_uint_32)items * size; | 162 num_bytes = (png_uint_32)items * size; |
| 163 | 163 |
| 164 p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; | 164 p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; |
| 165 ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes); | 165 ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes); |
| 166 p->flags=save_flags; | 166 p->flags=save_flags; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 * future. This should be used in favour of malloc(png_sizeof(png_info)) | 234 * future. This should be used in favour of malloc(png_sizeof(png_info)) |
| 235 * and png_info_init() so that applications that want to use a shared | 235 * and png_info_init() so that applications that want to use a shared |
| 236 * libpng don't have to be recompiled if png_info changes size. | 236 * libpng don't have to be recompiled if png_info changes size. |
| 237 */ | 237 */ |
| 238 png_infop PNGAPI | 238 png_infop PNGAPI |
| 239 png_create_info_struct(png_structp png_ptr) | 239 png_create_info_struct(png_structp png_ptr) |
| 240 { | 240 { |
| 241 png_infop info_ptr; | 241 png_infop info_ptr; |
| 242 | 242 |
| 243 png_debug(1, "in png_create_info_struct\n"); | 243 png_debug(1, "in png_create_info_struct\n"); |
| 244 if(png_ptr == NULL) return (NULL); | 244 if (png_ptr == NULL) return (NULL); |
| 245 #ifdef PNG_USER_MEM_SUPPORTED | 245 #ifdef PNG_USER_MEM_SUPPORTED |
| 246 info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, | 246 info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, |
| 247 png_ptr->malloc_fn, png_ptr->mem_ptr); | 247 png_ptr->malloc_fn, png_ptr->mem_ptr); |
| 248 #else | 248 #else |
| 249 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); | 249 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); |
| 250 #endif | 250 #endif |
| 251 if (info_ptr != NULL) | 251 if (info_ptr != NULL) |
| 252 png_info_init_3(&info_ptr, png_sizeof(png_info)); | 252 png_info_init_3(&info_ptr, png_sizeof(png_info)); |
| 253 | 253 |
| 254 return (info_ptr); | 254 return (info_ptr); |
| 255 } | 255 } |
| 256 | 256 |
| 257 /* This function frees the memory associated with a single info struct. | 257 /* This function frees the memory associated with a single info struct. |
| 258 * Normally, one would use either png_destroy_read_struct() or | 258 * Normally, one would use either png_destroy_read_struct() or |
| 259 * png_destroy_write_struct() to free an info struct, but this may be | 259 * png_destroy_write_struct() to free an info struct, but this may be |
| 260 * useful for some applications. | 260 * useful for some applications. |
| 261 */ | 261 */ |
| 262 void PNGAPI | 262 void PNGAPI |
| 263 png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) | 263 png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) |
| 264 { | 264 { |
| 265 png_infop info_ptr = NULL; | 265 png_infop info_ptr = NULL; |
| 266 if(png_ptr == NULL) return; | 266 if (png_ptr == NULL) return; |
| 267 | 267 |
| 268 png_debug(1, "in png_destroy_info_struct\n"); | 268 png_debug(1, "in png_destroy_info_struct\n"); |
| 269 if (info_ptr_ptr != NULL) | 269 if (info_ptr_ptr != NULL) |
| 270 info_ptr = *info_ptr_ptr; | 270 info_ptr = *info_ptr_ptr; |
| 271 | 271 |
| 272 if (info_ptr != NULL) | 272 if (info_ptr != NULL) |
| 273 { | 273 { |
| 274 png_info_destroy(png_ptr, info_ptr); | 274 png_info_destroy(png_ptr, info_ptr); |
| 275 | 275 |
| 276 #ifdef PNG_USER_MEM_SUPPORTED | 276 #ifdef PNG_USER_MEM_SUPPORTED |
| (...skipping 18 matching lines...) Expand all Loading... |
| 295 /* We only come here via pre-1.0.12-compiled applications */ | 295 /* We only come here via pre-1.0.12-compiled applications */ |
| 296 png_info_init_3(&info_ptr, 0); | 296 png_info_init_3(&info_ptr, 0); |
| 297 } | 297 } |
| 298 #endif | 298 #endif |
| 299 | 299 |
| 300 void PNGAPI | 300 void PNGAPI |
| 301 png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) | 301 png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) |
| 302 { | 302 { |
| 303 png_infop info_ptr = *ptr_ptr; | 303 png_infop info_ptr = *ptr_ptr; |
| 304 | 304 |
| 305 if(info_ptr == NULL) return; | 305 if (info_ptr == NULL) return; |
| 306 | 306 |
| 307 png_debug(1, "in png_info_init_3\n"); | 307 png_debug(1, "in png_info_init_3\n"); |
| 308 | 308 |
| 309 if(png_sizeof(png_info) > png_info_struct_size) | 309 if (png_sizeof(png_info) > png_info_struct_size) |
| 310 { | 310 { |
| 311 png_destroy_struct(info_ptr); | 311 png_destroy_struct(info_ptr); |
| 312 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); | 312 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); |
| 313 *ptr_ptr = info_ptr; | 313 *ptr_ptr = info_ptr; |
| 314 } | 314 } |
| 315 | 315 |
| 316 /* set everything to 0 */ | 316 /* set everything to 0 */ |
| 317 png_memset(info_ptr, 0, png_sizeof (png_info)); | 317 png_memset(info_ptr, 0, png_sizeof(png_info)); |
| 318 } | 318 } |
| 319 | 319 |
| 320 #ifdef PNG_FREE_ME_SUPPORTED | 320 #ifdef PNG_FREE_ME_SUPPORTED |
| 321 void PNGAPI | 321 void PNGAPI |
| 322 png_data_freer(png_structp png_ptr, png_infop info_ptr, | 322 png_data_freer(png_structp png_ptr, png_infop info_ptr, |
| 323 int freer, png_uint_32 mask) | 323 int freer, png_uint_32 mask) |
| 324 { | 324 { |
| 325 png_debug(1, "in png_data_freer\n"); | 325 png_debug(1, "in png_data_freer\n"); |
| 326 if (png_ptr == NULL || info_ptr == NULL) | 326 if (png_ptr == NULL || info_ptr == NULL) |
| 327 return; | 327 return; |
| 328 if(freer == PNG_DESTROY_WILL_FREE_DATA) | 328 if (freer == PNG_DESTROY_WILL_FREE_DATA) |
| 329 info_ptr->free_me |= mask; | 329 info_ptr->free_me |= mask; |
| 330 else if(freer == PNG_USER_WILL_FREE_DATA) | 330 else if (freer == PNG_USER_WILL_FREE_DATA) |
| 331 info_ptr->free_me &= ~mask; | 331 info_ptr->free_me &= ~mask; |
| 332 else | 332 else |
| 333 png_warning(png_ptr, | 333 png_warning(png_ptr, |
| 334 "Unknown freer parameter in png_data_freer."); | 334 "Unknown freer parameter in png_data_freer."); |
| 335 } | 335 } |
| 336 #endif | 336 #endif |
| 337 | 337 |
| 338 void PNGAPI | 338 void PNGAPI |
| 339 png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, | 339 png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, |
| 340 int num) | 340 int num) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 373 |
| 374 #if defined(PNG_tRNS_SUPPORTED) | 374 #if defined(PNG_tRNS_SUPPORTED) |
| 375 /* free any tRNS entry */ | 375 /* free any tRNS entry */ |
| 376 #ifdef PNG_FREE_ME_SUPPORTED | 376 #ifdef PNG_FREE_ME_SUPPORTED |
| 377 if ((mask & PNG_FREE_TRNS) & info_ptr->free_me) | 377 if ((mask & PNG_FREE_TRNS) & info_ptr->free_me) |
| 378 #else | 378 #else |
| 379 if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS)) | 379 if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS)) |
| 380 #endif | 380 #endif |
| 381 { | 381 { |
| 382 png_free(png_ptr, info_ptr->trans); | 382 png_free(png_ptr, info_ptr->trans); |
| 383 info_ptr->trans = NULL; |
| 383 info_ptr->valid &= ~PNG_INFO_tRNS; | 384 info_ptr->valid &= ~PNG_INFO_tRNS; |
| 384 #ifndef PNG_FREE_ME_SUPPORTED | 385 #ifndef PNG_FREE_ME_SUPPORTED |
| 385 png_ptr->flags &= ~PNG_FLAG_FREE_TRNS; | 386 png_ptr->flags &= ~PNG_FLAG_FREE_TRNS; |
| 386 #endif | 387 #endif |
| 387 info_ptr->trans = NULL; | |
| 388 } | 388 } |
| 389 #endif | 389 #endif |
| 390 | 390 |
| 391 #if defined(PNG_sCAL_SUPPORTED) | 391 #if defined(PNG_sCAL_SUPPORTED) |
| 392 /* free any sCAL entry */ | 392 /* free any sCAL entry */ |
| 393 #ifdef PNG_FREE_ME_SUPPORTED | 393 #ifdef PNG_FREE_ME_SUPPORTED |
| 394 if ((mask & PNG_FREE_SCAL) & info_ptr->free_me) | 394 if ((mask & PNG_FREE_SCAL) & info_ptr->free_me) |
| 395 #else | 395 #else |
| 396 if (mask & PNG_FREE_SCAL) | 396 if (mask & PNG_FREE_SCAL) |
| 397 #endif | 397 #endif |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 #if defined(PNG_sPLT_SUPPORTED) | 452 #if defined(PNG_sPLT_SUPPORTED) |
| 453 /* free a given sPLT entry, or (if num == -1) all sPLT entries */ | 453 /* free a given sPLT entry, or (if num == -1) all sPLT entries */ |
| 454 #ifdef PNG_FREE_ME_SUPPORTED | 454 #ifdef PNG_FREE_ME_SUPPORTED |
| 455 if ((mask & PNG_FREE_SPLT) & info_ptr->free_me) | 455 if ((mask & PNG_FREE_SPLT) & info_ptr->free_me) |
| 456 #else | 456 #else |
| 457 if (mask & PNG_FREE_SPLT) | 457 if (mask & PNG_FREE_SPLT) |
| 458 #endif | 458 #endif |
| 459 { | 459 { |
| 460 if (num != -1) | 460 if (num != -1) |
| 461 { | 461 { |
| 462 if(info_ptr->splt_palettes) | 462 if (info_ptr->splt_palettes) |
| 463 { | 463 { |
| 464 png_free(png_ptr, info_ptr->splt_palettes[num].name); | 464 png_free(png_ptr, info_ptr->splt_palettes[num].name); |
| 465 png_free(png_ptr, info_ptr->splt_palettes[num].entries); | 465 png_free(png_ptr, info_ptr->splt_palettes[num].entries); |
| 466 info_ptr->splt_palettes[num].name = NULL; | 466 info_ptr->splt_palettes[num].name = NULL; |
| 467 info_ptr->splt_palettes[num].entries = NULL; | 467 info_ptr->splt_palettes[num].entries = NULL; |
| 468 } | 468 } |
| 469 } | 469 } |
| 470 else | 470 else |
| 471 { | 471 { |
| 472 if(info_ptr->splt_palettes_num) | 472 if (info_ptr->splt_palettes_num) |
| 473 { | 473 { |
| 474 int i; | 474 int i; |
| 475 for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) | 475 for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) |
| 476 png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i); | 476 png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i); |
| 477 | 477 |
| 478 png_free(png_ptr, info_ptr->splt_palettes); | 478 png_free(png_ptr, info_ptr->splt_palettes); |
| 479 info_ptr->splt_palettes = NULL; | 479 info_ptr->splt_palettes = NULL; |
| 480 info_ptr->splt_palettes_num = 0; | 480 info_ptr->splt_palettes_num = 0; |
| 481 } | 481 } |
| 482 info_ptr->valid &= ~PNG_INFO_sPLT; | 482 info_ptr->valid &= ~PNG_INFO_sPLT; |
| 483 } | 483 } |
| 484 } | 484 } |
| 485 #endif | 485 #endif |
| 486 | 486 |
| 487 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) | 487 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) |
| 488 if(png_ptr->unknown_chunk.data) | 488 if (png_ptr->unknown_chunk.data) |
| 489 { | 489 { |
| 490 png_free(png_ptr, png_ptr->unknown_chunk.data); | 490 png_free(png_ptr, png_ptr->unknown_chunk.data); |
| 491 png_ptr->unknown_chunk.data = NULL; | 491 png_ptr->unknown_chunk.data = NULL; |
| 492 } | 492 } |
| 493 |
| 493 #ifdef PNG_FREE_ME_SUPPORTED | 494 #ifdef PNG_FREE_ME_SUPPORTED |
| 494 if ((mask & PNG_FREE_UNKN) & info_ptr->free_me) | 495 if ((mask & PNG_FREE_UNKN) & info_ptr->free_me) |
| 495 #else | 496 #else |
| 496 if (mask & PNG_FREE_UNKN) | 497 if (mask & PNG_FREE_UNKN) |
| 497 #endif | 498 #endif |
| 498 { | 499 { |
| 499 if (num != -1) | 500 if (num != -1) |
| 500 { | 501 { |
| 501 if(info_ptr->unknown_chunks) | 502 if (info_ptr->unknown_chunks) |
| 502 { | 503 { |
| 503 png_free(png_ptr, info_ptr->unknown_chunks[num].data); | 504 png_free(png_ptr, info_ptr->unknown_chunks[num].data); |
| 504 info_ptr->unknown_chunks[num].data = NULL; | 505 info_ptr->unknown_chunks[num].data = NULL; |
| 505 } | 506 } |
| 506 } | 507 } |
| 507 else | 508 else |
| 508 { | 509 { |
| 509 int i; | 510 int i; |
| 510 | 511 |
| 511 if(info_ptr->unknown_chunks_num) | 512 if (info_ptr->unknown_chunks_num) |
| 512 { | 513 { |
| 513 for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++) | 514 for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++) |
| 514 png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i); | 515 png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i); |
| 515 | 516 |
| 516 png_free(png_ptr, info_ptr->unknown_chunks); | 517 png_free(png_ptr, info_ptr->unknown_chunks); |
| 517 info_ptr->unknown_chunks = NULL; | 518 info_ptr->unknown_chunks = NULL; |
| 518 info_ptr->unknown_chunks_num = 0; | 519 info_ptr->unknown_chunks_num = 0; |
| 519 } | 520 } |
| 520 } | 521 } |
| 521 } | 522 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 } | 556 } |
| 556 | 557 |
| 557 #if defined(PNG_INFO_IMAGE_SUPPORTED) | 558 #if defined(PNG_INFO_IMAGE_SUPPORTED) |
| 558 /* free any image bits attached to the info structure */ | 559 /* free any image bits attached to the info structure */ |
| 559 #ifdef PNG_FREE_ME_SUPPORTED | 560 #ifdef PNG_FREE_ME_SUPPORTED |
| 560 if ((mask & PNG_FREE_ROWS) & info_ptr->free_me) | 561 if ((mask & PNG_FREE_ROWS) & info_ptr->free_me) |
| 561 #else | 562 #else |
| 562 if (mask & PNG_FREE_ROWS) | 563 if (mask & PNG_FREE_ROWS) |
| 563 #endif | 564 #endif |
| 564 { | 565 { |
| 565 if(info_ptr->row_pointers) | 566 if (info_ptr->row_pointers) |
| 566 { | 567 { |
| 567 int row; | 568 int row; |
| 568 for (row = 0; row < (int)info_ptr->height; row++) | 569 for (row = 0; row < (int)info_ptr->height; row++) |
| 569 { | 570 { |
| 570 png_free(png_ptr, info_ptr->row_pointers[row]); | 571 png_free(png_ptr, info_ptr->row_pointers[row]); |
| 571 info_ptr->row_pointers[row]=NULL; | 572 info_ptr->row_pointers[row]=NULL; |
| 572 } | 573 } |
| 573 png_free(png_ptr, info_ptr->row_pointers); | 574 png_free(png_ptr, info_ptr->row_pointers); |
| 574 info_ptr->row_pointers=NULL; | 575 info_ptr->row_pointers=NULL; |
| 575 } | 576 } |
| 576 info_ptr->valid &= ~PNG_INFO_IDAT; | 577 info_ptr->valid &= ~PNG_INFO_IDAT; |
| 577 } | 578 } |
| 578 #endif | 579 #endif |
| 579 | 580 |
| 580 #ifdef PNG_FREE_ME_SUPPORTED | 581 #ifdef PNG_FREE_ME_SUPPORTED |
| 581 if(num == -1) | 582 if (num == -1) |
| 582 info_ptr->free_me &= ~mask; | 583 info_ptr->free_me &= ~mask; |
| 583 else | 584 else |
| 584 info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL); | 585 info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL); |
| 585 #endif | 586 #endif |
| 586 } | 587 } |
| 587 | 588 |
| 588 /* This is an internal routine to free any memory that the info struct is | 589 /* This is an internal routine to free any memory that the info struct is |
| 589 * pointing to before re-using it or freeing the struct itself. Recall | 590 * pointing to before re-using it or freeing the struct itself. Recall |
| 590 * that png_free() checks for NULL pointers for us. | 591 * that png_free() checks for NULL pointers for us. |
| 591 */ | 592 */ |
| 592 void /* PRIVATE */ | 593 void /* PRIVATE */ |
| 593 png_info_destroy(png_structp png_ptr, png_infop info_ptr) | 594 png_info_destroy(png_structp png_ptr, png_infop info_ptr) |
| 594 { | 595 { |
| 595 png_debug(1, "in png_info_destroy\n"); | 596 png_debug(1, "in png_info_destroy\n"); |
| 596 | 597 |
| 597 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); | 598 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); |
| 598 | 599 |
| 599 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) | 600 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) |
| 600 if (png_ptr->num_chunk_list) | 601 if (png_ptr->num_chunk_list) |
| 601 { | 602 { |
| 602 png_free(png_ptr, png_ptr->chunk_list); | 603 png_free(png_ptr, png_ptr->chunk_list); |
| 603 png_ptr->chunk_list=NULL; | 604 png_ptr->chunk_list=NULL; |
| 604 png_ptr->num_chunk_list=0; | 605 png_ptr->num_chunk_list = 0; |
| 605 } | 606 } |
| 606 #endif | 607 #endif |
| 607 | 608 |
| 608 png_info_init_3(&info_ptr, png_sizeof(png_info)); | 609 png_info_init_3(&info_ptr, png_sizeof(png_info)); |
| 609 } | 610 } |
| 610 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ | 611 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ |
| 611 | 612 |
| 612 /* This function returns a pointer to the io_ptr associated with the user | 613 /* This function returns a pointer to the io_ptr associated with the user |
| 613 * functions. The application should free any memory associated with this | 614 * functions. The application should free any memory associated with this |
| 614 * pointer before png_write_destroy() or png_read_destroy() are called. | 615 * pointer before png_write_destroy() or png_read_destroy() are called. |
| 615 */ | 616 */ |
| 616 png_voidp PNGAPI | 617 png_voidp PNGAPI |
| 617 png_get_io_ptr(png_structp png_ptr) | 618 png_get_io_ptr(png_structp png_ptr) |
| 618 { | 619 { |
| 619 if(png_ptr == NULL) return (NULL); | 620 if (png_ptr == NULL) return (NULL); |
| 620 return (png_ptr->io_ptr); | 621 return (png_ptr->io_ptr); |
| 621 } | 622 } |
| 622 | 623 |
| 623 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) | 624 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) |
| 624 #if !defined(PNG_NO_STDIO) | 625 #if !defined(PNG_NO_STDIO) |
| 625 /* Initialize the default input/output functions for the PNG file. If you | 626 /* Initialize the default input/output functions for the PNG file. If you |
| 626 * use your own read or write routines, you can call either png_set_read_fn() | 627 * use your own read or write routines, you can call either png_set_read_fn() |
| 627 * or png_set_write_fn() instead of png_init_io(). If you have defined | 628 * or png_set_write_fn() instead of png_init_io(). If you have defined |
| 628 * PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't | 629 * PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't |
| 629 * necessarily available. | 630 * necessarily available. |
| 630 */ | 631 */ |
| 631 void PNGAPI | 632 void PNGAPI |
| 632 png_init_io(png_structp png_ptr, png_FILE_p fp) | 633 png_init_io(png_structp png_ptr, png_FILE_p fp) |
| 633 { | 634 { |
| 634 png_debug(1, "in png_init_io\n"); | 635 png_debug(1, "in png_init_io\n"); |
| 635 if(png_ptr == NULL) return; | 636 if (png_ptr == NULL) return; |
| 636 png_ptr->io_ptr = (png_voidp)fp; | 637 png_ptr->io_ptr = (png_voidp)fp; |
| 637 } | 638 } |
| 638 #endif | 639 #endif |
| 639 | 640 |
| 640 #if defined(PNG_TIME_RFC1123_SUPPORTED) | 641 #if defined(PNG_TIME_RFC1123_SUPPORTED) |
| 641 /* Convert the supplied time into an RFC 1123 string suitable for use in | 642 /* Convert the supplied time into an RFC 1123 string suitable for use in |
| 642 * a "Creation Time" or other text-based time string. | 643 * a "Creation Time" or other text-based time string. |
| 643 */ | 644 */ |
| 644 png_charp PNGAPI | 645 png_charp PNGAPI |
| 645 png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) | 646 png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) |
| 646 { | 647 { |
| 647 static PNG_CONST char short_months[12][4] = | 648 static PNG_CONST char short_months[12][4] = |
| 648 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | 649 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
| 649 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; | 650 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
| 650 | 651 |
| 651 if(png_ptr == NULL) return (NULL); | 652 if (png_ptr == NULL) return (NULL); |
| 652 if (png_ptr->time_buffer == NULL) | 653 if (png_ptr->time_buffer == NULL) |
| 653 { | 654 { |
| 654 png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29* | 655 png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29* |
| 655 png_sizeof(char))); | 656 png_sizeof(char))); |
| 656 } | 657 } |
| 657 | 658 |
| 658 #if defined(_WIN32_WCE) | 659 #if defined(_WIN32_WCE) |
| 659 { | 660 { |
| 660 wchar_t time_buf[29]; | 661 wchar_t time_buf[29]; |
| 661 wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"), | 662 wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"), |
| 662 ptime->day % 32, short_months[(ptime->month - 1) % 12], | 663 ptime->day % 32, short_months[(ptime->month - 1) % 12], |
| 663 ptime->year, ptime->hour % 24, ptime->minute % 60, | 664 ptime->year, ptime->hour % 24, ptime->minute % 60, |
| 664 ptime->second % 61); | 665 ptime->second % 61); |
| 665 WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29, | 666 WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29, |
| 666 NULL, NULL); | 667 NULL, NULL); |
| 667 } | 668 } |
| 668 #else | 669 #else |
| 669 #ifdef USE_FAR_KEYWORD | 670 #ifdef USE_FAR_KEYWORD |
| 670 { | 671 { |
| 671 char near_time_buf[29]; | 672 char near_time_buf[29]; |
| 672 png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000", | 673 png_snprintf6(near_time_buf, 29, "%d %s %d %02d:%02d:%02d +0000", |
| 673 ptime->day % 32, short_months[(ptime->month - 1) % 12], | 674 ptime->day % 32, short_months[(ptime->month - 1) % 12], |
| 674 ptime->year, ptime->hour % 24, ptime->minute % 60, | 675 ptime->year, ptime->hour % 24, ptime->minute % 60, |
| 675 ptime->second % 61); | 676 ptime->second % 61); |
| 676 png_memcpy(png_ptr->time_buffer, near_time_buf, | 677 png_memcpy(png_ptr->time_buffer, near_time_buf, |
| 677 29*png_sizeof(char)); | 678 29*png_sizeof(char)); |
| 678 } | 679 } |
| 679 #else | 680 #else |
| 680 png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000", | 681 png_snprintf6(png_ptr->time_buffer, 29, "%d %s %d %02d:%02d:%02d +0000", |
| 681 ptime->day % 32, short_months[(ptime->month - 1) % 12], | 682 ptime->day % 32, short_months[(ptime->month - 1) % 12], |
| 682 ptime->year, ptime->hour % 24, ptime->minute % 60, | 683 ptime->year, ptime->hour % 24, ptime->minute % 60, |
| 683 ptime->second % 61); | 684 ptime->second % 61); |
| 684 #endif | 685 #endif |
| 685 #endif /* _WIN32_WCE */ | 686 #endif /* _WIN32_WCE */ |
| 686 return ((png_charp)png_ptr->time_buffer); | 687 return ((png_charp)png_ptr->time_buffer); |
| 687 } | 688 } |
| 688 #endif /* PNG_TIME_RFC1123_SUPPORTED */ | 689 #endif /* PNG_TIME_RFC1123_SUPPORTED */ |
| 689 | 690 |
| 690 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ | 691 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ |
| 691 | 692 |
| 692 png_charp PNGAPI | 693 png_charp PNGAPI |
| 693 png_get_copyright(png_structp png_ptr) | 694 png_get_copyright(png_structp png_ptr) |
| 694 { | 695 { |
| 695 png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */ | 696 png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */ |
| 696 return ((png_charp) "\n libpng version 1.2.29 - May 8, 2008\n\ | 697 return ((png_charp) "\n libpng version 1.2.33 - October 31, 2008\n\ |
| 697 Copyright (c) 1998-2008 Glenn Randers-Pehrson\n\ | 698 Copyright (c) 1998-2008 Glenn Randers-Pehrson\n\ |
| 698 Copyright (c) 1996-1997 Andreas Dilger\n\ | 699 Copyright (c) 1996-1997 Andreas Dilger\n\ |
| 699 Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n"); | 700 Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n"); |
| 700 } | 701 } |
| 701 | 702 |
| 702 /* The following return the library version as a short string in the | 703 /* The following return the library version as a short string in the |
| 703 * format 1.0.0 through 99.99.99zz. To get the version of *.h files | 704 * format 1.0.0 through 99.99.99zz. To get the version of *.h files |
| 704 * used with your application, print out PNG_LIBPNG_VER_STRING, which | 705 * used with your application, print out PNG_LIBPNG_VER_STRING, which |
| 705 * is defined in png.h. | 706 * is defined in png.h. |
| 706 * Note: now there is no difference between png_get_libpng_ver() and | 707 * Note: now there is no difference between png_get_libpng_ver() and |
| (...skipping 29 matching lines...) Expand all Loading... |
| 736 } | 737 } |
| 737 | 738 |
| 738 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) | 739 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) |
| 739 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED | 740 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
| 740 int PNGAPI | 741 int PNGAPI |
| 741 png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name) | 742 png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name) |
| 742 { | 743 { |
| 743 /* check chunk_name and return "keep" value if it's on the list, else 0 */ | 744 /* check chunk_name and return "keep" value if it's on the list, else 0 */ |
| 744 int i; | 745 int i; |
| 745 png_bytep p; | 746 png_bytep p; |
| 746 if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0) | 747 if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0) |
| 747 return 0; | 748 return 0; |
| 748 p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5; | 749 p = png_ptr->chunk_list + png_ptr->num_chunk_list*5 - 5; |
| 749 for (i = png_ptr->num_chunk_list; i; i--, p-=5) | 750 for (i = png_ptr->num_chunk_list; i; i--, p -= 5) |
| 750 if (!png_memcmp(chunk_name, p, 4)) | 751 if (!png_memcmp(chunk_name, p, 4)) |
| 751 return ((int)*(p+4)); | 752 return ((int)*(p + 4)); |
| 752 return 0; | 753 return 0; |
| 753 } | 754 } |
| 754 #endif | 755 #endif |
| 755 | 756 |
| 756 /* This function, added to libpng-1.0.6g, is untested. */ | 757 /* This function, added to libpng-1.0.6g, is untested. */ |
| 757 int PNGAPI | 758 int PNGAPI |
| 758 png_reset_zstream(png_structp png_ptr) | 759 png_reset_zstream(png_structp png_ptr) |
| 759 { | 760 { |
| 760 if (png_ptr == NULL) return Z_STREAM_ERROR; | 761 if (png_ptr == NULL) return Z_STREAM_ERROR; |
| 761 return (inflateReset(&png_ptr->zstream)); | 762 return (inflateReset(&png_ptr->zstream)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 789 PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size)); | 790 PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size)); |
| 790 png_size_t PNGAPI | 791 png_size_t PNGAPI |
| 791 png_convert_size(size_t size) | 792 png_convert_size(size_t size) |
| 792 { | 793 { |
| 793 if (size > (png_size_t)-1) | 794 if (size > (png_size_t)-1) |
| 794 PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */ | 795 PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */ |
| 795 return ((png_size_t)size); | 796 return ((png_size_t)size); |
| 796 } | 797 } |
| 797 #endif /* PNG_SIZE_T */ | 798 #endif /* PNG_SIZE_T */ |
| 798 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ | 799 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ |
| OLD | NEW |