| OLD | NEW |
| 1 | 1 |
| 2 /* pngread.c - read a PNG file | 2 /* pngread.c - read a PNG file |
| 3 * | 3 * |
| 4 * Last changed in libpng 1.2.35 [February 14, 2009] | 4 * Last changed in libpng 1.2.37 [June 4, 2009] |
| 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-2009 Glenn Randers-Pehrson | 6 * Copyright (c) 1998-2009 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 * This file contains routines that an application calls directly to | 10 * This file contains routines that an application calls directly to |
| 11 * read a PNG file or stream. | 11 * read a PNG file or stream. |
| 12 */ | 12 */ |
| 13 | 13 |
| 14 #define PNG_INTERNAL | 14 #define PNG_INTERNAL |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 png_debug(1, "in png_create_read_struct"); | 50 png_debug(1, "in png_create_read_struct"); |
| 51 #ifdef PNG_USER_MEM_SUPPORTED | 51 #ifdef PNG_USER_MEM_SUPPORTED |
| 52 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, | 52 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, |
| 53 (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); | 53 (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); |
| 54 #else | 54 #else |
| 55 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); | 55 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); |
| 56 #endif | 56 #endif |
| 57 if (png_ptr == NULL) | 57 if (png_ptr == NULL) |
| 58 return (NULL); | 58 return (NULL); |
| 59 | 59 |
| 60 /* added at libpng-1.2.6 */ | 60 /* Added at libpng-1.2.6 */ |
| 61 #ifdef PNG_SET_USER_LIMITS_SUPPORTED | 61 #ifdef PNG_SET_USER_LIMITS_SUPPORTED |
| 62 png_ptr->user_width_max=PNG_USER_WIDTH_MAX; | 62 png_ptr->user_width_max=PNG_USER_WIDTH_MAX; |
| 63 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; | 63 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 #ifdef PNG_SETJMP_SUPPORTED | 66 #ifdef PNG_SETJMP_SUPPORTED |
| 67 #ifdef USE_FAR_KEYWORD | 67 #ifdef USE_FAR_KEYWORD |
| 68 if (setjmp(jmpbuf)) | 68 if (setjmp(jmpbuf)) |
| 69 #else | 69 #else |
| 70 if (setjmp(png_ptr->jmpbuf)) | 70 if (setjmp(png_ptr->jmpbuf)) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 png_warning(png_ptr, msg); | 130 png_warning(png_ptr, msg); |
| 131 #endif | 131 #endif |
| 132 #ifdef PNG_ERROR_NUMBERS_SUPPORTED | 132 #ifdef PNG_ERROR_NUMBERS_SUPPORTED |
| 133 png_ptr->flags = 0; | 133 png_ptr->flags = 0; |
| 134 #endif | 134 #endif |
| 135 png_error(png_ptr, | 135 png_error(png_ptr, |
| 136 "Incompatible libpng version in application and library"); | 136 "Incompatible libpng version in application and library"); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 /* initialize zbuf - compression buffer */ | 140 /* Initialize zbuf - compression buffer */ |
| 141 png_ptr->zbuf_size = PNG_ZBUF_SIZE; | 141 png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
| 142 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, | 142 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, |
| 143 (png_uint_32)png_ptr->zbuf_size); | 143 (png_uint_32)png_ptr->zbuf_size); |
| 144 png_ptr->zstream.zalloc = png_zalloc; | 144 png_ptr->zstream.zalloc = png_zalloc; |
| 145 png_ptr->zstream.zfree = png_zfree; | 145 png_ptr->zstream.zfree = png_zfree; |
| 146 png_ptr->zstream.opaque = (voidpf)png_ptr; | 146 png_ptr->zstream.opaque = (voidpf)png_ptr; |
| 147 | 147 |
| 148 switch (inflateInit(&png_ptr->zstream)) | 148 switch (inflateInit(&png_ptr->zstream)) |
| 149 { | 149 { |
| 150 case Z_OK: /* Do nothing */ break; | 150 case Z_OK: /* Do nothing */ break; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 { | 185 { |
| 186 /* We only come here via pre-1.0.7-compiled applications */ | 186 /* We only come here via pre-1.0.7-compiled applications */ |
| 187 png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0); | 187 png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void PNGAPI | 190 void PNGAPI |
| 191 png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver, | 191 png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver, |
| 192 png_size_t png_struct_size, png_size_t png_info_size) | 192 png_size_t png_struct_size, png_size_t png_info_size) |
| 193 { | 193 { |
| 194 /* We only come here via pre-1.0.12-compiled applications */ | 194 /* We only come here via pre-1.0.12-compiled applications */ |
| 195 if (png_ptr == NULL) return; | 195 if (png_ptr == NULL) |
| 196 return; |
| 196 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) | 197 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) |
| 197 if (png_sizeof(png_struct) > png_struct_size || | 198 if (png_sizeof(png_struct) > png_struct_size || |
| 198 png_sizeof(png_info) > png_info_size) | 199 png_sizeof(png_info) > png_info_size) |
| 199 { | 200 { |
| 200 char msg[80]; | 201 char msg[80]; |
| 201 png_ptr->warning_fn = NULL; | 202 png_ptr->warning_fn = NULL; |
| 202 if (user_png_ver) | 203 if (user_png_ver) |
| 203 { | 204 { |
| 204 png_snprintf(msg, 80, | 205 png_snprintf(msg, 80, |
| 205 "Application was compiled with png.h from libpng-%.20s", | 206 "Application was compiled with png.h from libpng-%.20s", |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 png_size_t png_struct_size) | 240 png_size_t png_struct_size) |
| 240 { | 241 { |
| 241 #ifdef PNG_SETJMP_SUPPORTED | 242 #ifdef PNG_SETJMP_SUPPORTED |
| 242 jmp_buf tmp_jmp; /* to save current jump buffer */ | 243 jmp_buf tmp_jmp; /* to save current jump buffer */ |
| 243 #endif | 244 #endif |
| 244 | 245 |
| 245 int i = 0; | 246 int i = 0; |
| 246 | 247 |
| 247 png_structp png_ptr=*ptr_ptr; | 248 png_structp png_ptr=*ptr_ptr; |
| 248 | 249 |
| 249 if (png_ptr == NULL) return; | 250 if (png_ptr == NULL) |
| 251 return; |
| 250 | 252 |
| 251 do | 253 do |
| 252 { | 254 { |
| 253 if (user_png_ver[i] != png_libpng_ver[i]) | 255 if (user_png_ver[i] != png_libpng_ver[i]) |
| 254 { | 256 { |
| 255 #ifdef PNG_LEGACY_SUPPORTED | 257 #ifdef PNG_LEGACY_SUPPORTED |
| 256 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; | 258 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
| 257 #else | 259 #else |
| 258 png_ptr->warning_fn = NULL; | 260 png_ptr->warning_fn = NULL; |
| 259 png_warning(png_ptr, | 261 png_warning(png_ptr, |
| 260 "Application uses deprecated png_read_init() and should be recompiled.")
; | 262 "Application uses deprecated png_read_init() and should be recompiled.")
; |
| 261 break; | 263 break; |
| 262 #endif | 264 #endif |
| 263 } | 265 } |
| 264 } while (png_libpng_ver[i++]); | 266 } while (png_libpng_ver[i++]); |
| 265 | 267 |
| 266 png_debug(1, "in png_read_init_3"); | 268 png_debug(1, "in png_read_init_3"); |
| 267 | 269 |
| 268 #ifdef PNG_SETJMP_SUPPORTED | 270 #ifdef PNG_SETJMP_SUPPORTED |
| 269 /* save jump buffer and error functions */ | 271 /* Save jump buffer and error functions */ |
| 270 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); | 272 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); |
| 271 #endif | 273 #endif |
| 272 | 274 |
| 273 if (png_sizeof(png_struct) > png_struct_size) | 275 if (png_sizeof(png_struct) > png_struct_size) |
| 274 { | 276 { |
| 275 png_destroy_struct(png_ptr); | 277 png_destroy_struct(png_ptr); |
| 276 *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); | 278 *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); |
| 277 png_ptr = *ptr_ptr; | 279 png_ptr = *ptr_ptr; |
| 278 } | 280 } |
| 279 | 281 |
| 280 /* reset all variables to 0 */ | 282 /* Reset all variables to 0 */ |
| 281 png_memset(png_ptr, 0, png_sizeof(png_struct)); | 283 png_memset(png_ptr, 0, png_sizeof(png_struct)); |
| 282 | 284 |
| 283 #ifdef PNG_SETJMP_SUPPORTED | 285 #ifdef PNG_SETJMP_SUPPORTED |
| 284 /* restore jump buffer */ | 286 /* Restore jump buffer */ |
| 285 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); | 287 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); |
| 286 #endif | 288 #endif |
| 287 | 289 |
| 288 /* added at libpng-1.2.6 */ | 290 /* Added at libpng-1.2.6 */ |
| 289 #ifdef PNG_SET_USER_LIMITS_SUPPORTED | 291 #ifdef PNG_SET_USER_LIMITS_SUPPORTED |
| 290 png_ptr->user_width_max=PNG_USER_WIDTH_MAX; | 292 png_ptr->user_width_max=PNG_USER_WIDTH_MAX; |
| 291 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; | 293 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; |
| 292 #endif | 294 #endif |
| 293 | 295 |
| 294 /* initialize zbuf - compression buffer */ | 296 /* Initialize zbuf - compression buffer */ |
| 295 png_ptr->zbuf_size = PNG_ZBUF_SIZE; | 297 png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
| 296 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, | 298 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, |
| 297 (png_uint_32)png_ptr->zbuf_size); | 299 (png_uint_32)png_ptr->zbuf_size); |
| 298 png_ptr->zstream.zalloc = png_zalloc; | 300 png_ptr->zstream.zalloc = png_zalloc; |
| 299 png_ptr->zstream.zfree = png_zfree; | 301 png_ptr->zstream.zfree = png_zfree; |
| 300 png_ptr->zstream.opaque = (voidpf)png_ptr; | 302 png_ptr->zstream.opaque = (voidpf)png_ptr; |
| 301 | 303 |
| 302 switch (inflateInit(&png_ptr->zstream)) | 304 switch (inflateInit(&png_ptr->zstream)) |
| 303 { | 305 { |
| 304 case Z_OK: /* Do nothing */ break; | 306 case Z_OK: /* Do nothing */ break; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 319 * changed in v0.90 to allow reading a file that already has the magic | 321 * changed in v0.90 to allow reading a file that already has the magic |
| 320 * bytes read from the stream. You can tell libpng how many bytes have | 322 * bytes read from the stream. You can tell libpng how many bytes have |
| 321 * been read from the beginning of the stream (up to the maximum of 8) | 323 * been read from the beginning of the stream (up to the maximum of 8) |
| 322 * via png_set_sig_bytes(), and we will only check the remaining bytes | 324 * via png_set_sig_bytes(), and we will only check the remaining bytes |
| 323 * here. The application can then have access to the signature bytes we | 325 * here. The application can then have access to the signature bytes we |
| 324 * read if it is determined that this isn't a valid PNG file. | 326 * read if it is determined that this isn't a valid PNG file. |
| 325 */ | 327 */ |
| 326 void PNGAPI | 328 void PNGAPI |
| 327 png_read_info(png_structp png_ptr, png_infop info_ptr) | 329 png_read_info(png_structp png_ptr, png_infop info_ptr) |
| 328 { | 330 { |
| 329 if (png_ptr == NULL || info_ptr == NULL) return; | 331 if (png_ptr == NULL || info_ptr == NULL) |
| 332 return; |
| 330 png_debug(1, "in png_read_info"); | 333 png_debug(1, "in png_read_info"); |
| 331 /* If we haven't checked all of the PNG signature bytes, do so now. */ | 334 /* If we haven't checked all of the PNG signature bytes, do so now. */ |
| 332 if (png_ptr->sig_bytes < 8) | 335 if (png_ptr->sig_bytes < 8) |
| 333 { | 336 { |
| 334 png_size_t num_checked = png_ptr->sig_bytes, | 337 png_size_t num_checked = png_ptr->sig_bytes, |
| 335 num_to_check = 8 - num_checked; | 338 num_to_check = 8 - num_checked; |
| 336 | 339 |
| 337 png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check); | 340 png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check); |
| 338 png_ptr->sig_bytes = 8; | 341 png_ptr->sig_bytes = 8; |
| 339 | 342 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 #if defined(PNG_READ_iTXt_SUPPORTED) | 525 #if defined(PNG_READ_iTXt_SUPPORTED) |
| 523 else if (!png_memcmp(chunk_name, png_iTXt, 4)) | 526 else if (!png_memcmp(chunk_name, png_iTXt, 4)) |
| 524 png_handle_iTXt(png_ptr, info_ptr, length); | 527 png_handle_iTXt(png_ptr, info_ptr, length); |
| 525 #endif | 528 #endif |
| 526 else | 529 else |
| 527 png_handle_unknown(png_ptr, info_ptr, length); | 530 png_handle_unknown(png_ptr, info_ptr, length); |
| 528 } | 531 } |
| 529 } | 532 } |
| 530 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ | 533 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ |
| 531 | 534 |
| 532 /* optional call to update the users info_ptr structure */ | 535 /* Optional call to update the users info_ptr structure */ |
| 533 void PNGAPI | 536 void PNGAPI |
| 534 png_read_update_info(png_structp png_ptr, png_infop info_ptr) | 537 png_read_update_info(png_structp png_ptr, png_infop info_ptr) |
| 535 { | 538 { |
| 536 png_debug(1, "in png_read_update_info"); | 539 png_debug(1, "in png_read_update_info"); |
| 537 if (png_ptr == NULL) return; | 540 if (png_ptr == NULL) |
| 541 return; |
| 538 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) | 542 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
| 539 png_read_start_row(png_ptr); | 543 png_read_start_row(png_ptr); |
| 540 else | 544 else |
| 541 png_warning(png_ptr, | 545 png_warning(png_ptr, |
| 542 "Ignoring extra png_read_update_info() call; row buffer not reallocated"); | 546 "Ignoring extra png_read_update_info() call; row buffer not reallocated"); |
| 543 png_read_transform_info(png_ptr, info_ptr); | 547 png_read_transform_info(png_ptr, info_ptr); |
| 544 } | 548 } |
| 545 | 549 |
| 546 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED | 550 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED |
| 547 /* Initialize palette, background, etc, after transformations | 551 /* Initialize palette, background, etc, after transformations |
| 548 * are set, but before any reading takes place. This allows | 552 * are set, but before any reading takes place. This allows |
| 549 * the user to obtain a gamma-corrected palette, for example. | 553 * the user to obtain a gamma-corrected palette, for example. |
| 550 * If the user doesn't call this, we will do it ourselves. | 554 * If the user doesn't call this, we will do it ourselves. |
| 551 */ | 555 */ |
| 552 void PNGAPI | 556 void PNGAPI |
| 553 png_start_read_image(png_structp png_ptr) | 557 png_start_read_image(png_structp png_ptr) |
| 554 { | 558 { |
| 555 png_debug(1, "in png_start_read_image"); | 559 png_debug(1, "in png_start_read_image"); |
| 556 if (png_ptr == NULL) return; | 560 if (png_ptr == NULL) |
| 561 return; |
| 557 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) | 562 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
| 558 png_read_start_row(png_ptr); | 563 png_read_start_row(png_ptr); |
| 559 } | 564 } |
| 560 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ | 565 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ |
| 561 | 566 |
| 562 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED | 567 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED |
| 563 void PNGAPI | 568 void PNGAPI |
| 564 png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) | 569 png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) |
| 565 { | 570 { |
| 566 #ifdef PNG_USE_LOCAL_ARRAYS | 571 #ifdef PNG_USE_LOCAL_ARRAYS |
| 567 PNG_CONST PNG_IDAT; | 572 PNG_CONST PNG_IDAT; |
| 568 PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, | 573 PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, |
| 569 0xff}; | 574 0xff}; |
| 570 PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; | 575 PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; |
| 571 #endif | 576 #endif |
| 572 int ret; | 577 int ret; |
| 573 if (png_ptr == NULL) return; | 578 if (png_ptr == NULL) |
| 579 return; |
| 574 png_debug2(1, "in png_read_row (row %lu, pass %d)", | 580 png_debug2(1, "in png_read_row (row %lu, pass %d)", |
| 575 png_ptr->row_number, png_ptr->pass); | 581 png_ptr->row_number, png_ptr->pass); |
| 576 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) | 582 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
| 577 png_read_start_row(png_ptr); | 583 png_read_start_row(png_ptr); |
| 578 if (png_ptr->row_number == 0 && png_ptr->pass == 0) | 584 if (png_ptr->row_number == 0 && png_ptr->pass == 0) |
| 579 { | 585 { |
| 580 /* check for transforms that have been set but were defined out */ | 586 /* Check for transforms that have been set but were defined out */ |
| 581 #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) | 587 #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) |
| 582 if (png_ptr->transformations & PNG_INVERT_MONO) | 588 if (png_ptr->transformations & PNG_INVERT_MONO) |
| 583 png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined."); | 589 png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined."); |
| 584 #endif | 590 #endif |
| 585 #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED) | 591 #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED) |
| 586 if (png_ptr->transformations & PNG_FILLER) | 592 if (png_ptr->transformations & PNG_FILLER) |
| 587 png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined."); | 593 png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined."); |
| 588 #endif | 594 #endif |
| 589 #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTE
D) | 595 #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTE
D) |
| 590 if (png_ptr->transformations & PNG_PACKSWAP) | 596 if (png_ptr->transformations & PNG_PACKSWAP) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 602 if (png_ptr->transformations & PNG_BGR) | 608 if (png_ptr->transformations & PNG_BGR) |
| 603 png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined."); | 609 png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined."); |
| 604 #endif | 610 #endif |
| 605 #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED) | 611 #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED) |
| 606 if (png_ptr->transformations & PNG_SWAP_BYTES) | 612 if (png_ptr->transformations & PNG_SWAP_BYTES) |
| 607 png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined."); | 613 png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined."); |
| 608 #endif | 614 #endif |
| 609 } | 615 } |
| 610 | 616 |
| 611 #if defined(PNG_READ_INTERLACING_SUPPORTED) | 617 #if defined(PNG_READ_INTERLACING_SUPPORTED) |
| 612 /* if interlaced and we do not need a new row, combine row and return */ | 618 /* If interlaced and we do not need a new row, combine row and return */ |
| 613 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) | 619 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) |
| 614 { | 620 { |
| 615 switch (png_ptr->pass) | 621 switch (png_ptr->pass) |
| 616 { | 622 { |
| 617 case 0: | 623 case 0: |
| 618 if (png_ptr->row_number & 0x07) | 624 if (png_ptr->row_number & 0x07) |
| 619 { | 625 { |
| 620 if (dsp_row != NULL) | 626 if (dsp_row != NULL) |
| 621 png_combine_row(png_ptr, dsp_row, | 627 png_combine_row(png_ptr, dsp_row, |
| 622 png_pass_dsp_mask[png_ptr->pass]); | 628 png_pass_dsp_mask[png_ptr->pass]); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 /* Intrapixel differencing */ | 755 /* Intrapixel differencing */ |
| 750 png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); | 756 png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); |
| 751 } | 757 } |
| 752 #endif | 758 #endif |
| 753 | 759 |
| 754 | 760 |
| 755 if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) | 761 if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) |
| 756 png_do_read_transformations(png_ptr); | 762 png_do_read_transformations(png_ptr); |
| 757 | 763 |
| 758 #if defined(PNG_READ_INTERLACING_SUPPORTED) | 764 #if defined(PNG_READ_INTERLACING_SUPPORTED) |
| 759 /* blow up interlaced rows to full size */ | 765 /* Blow up interlaced rows to full size */ |
| 760 if (png_ptr->interlaced && | 766 if (png_ptr->interlaced && |
| 761 (png_ptr->transformations & PNG_INTERLACE)) | 767 (png_ptr->transformations & PNG_INTERLACE)) |
| 762 { | 768 { |
| 763 if (png_ptr->pass < 6) | 769 if (png_ptr->pass < 6) |
| 764 /* old interface (pre-1.0.9): | 770 /* Old interface (pre-1.0.9): |
| 765 png_do_read_interlace(&(png_ptr->row_info), | 771 * png_do_read_interlace(&(png_ptr->row_info), |
| 766 png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); | 772 * png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); |
| 767 */ | 773 */ |
| 768 png_do_read_interlace(png_ptr); | 774 png_do_read_interlace(png_ptr); |
| 769 | 775 |
| 770 if (dsp_row != NULL) | 776 if (dsp_row != NULL) |
| 771 png_combine_row(png_ptr, dsp_row, | 777 png_combine_row(png_ptr, dsp_row, |
| 772 png_pass_dsp_mask[png_ptr->pass]); | 778 png_pass_dsp_mask[png_ptr->pass]); |
| 773 if (row != NULL) | 779 if (row != NULL) |
| 774 png_combine_row(png_ptr, row, | 780 png_combine_row(png_ptr, row, |
| 775 png_pass_mask[png_ptr->pass]); | 781 png_pass_mask[png_ptr->pass]); |
| 776 } | 782 } |
| 777 else | 783 else |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 | 822 |
| 817 void PNGAPI | 823 void PNGAPI |
| 818 png_read_rows(png_structp png_ptr, png_bytepp row, | 824 png_read_rows(png_structp png_ptr, png_bytepp row, |
| 819 png_bytepp display_row, png_uint_32 num_rows) | 825 png_bytepp display_row, png_uint_32 num_rows) |
| 820 { | 826 { |
| 821 png_uint_32 i; | 827 png_uint_32 i; |
| 822 png_bytepp rp; | 828 png_bytepp rp; |
| 823 png_bytepp dp; | 829 png_bytepp dp; |
| 824 | 830 |
| 825 png_debug(1, "in png_read_rows"); | 831 png_debug(1, "in png_read_rows"); |
| 826 if (png_ptr == NULL) return; | 832 if (png_ptr == NULL) |
| 833 return; |
| 827 rp = row; | 834 rp = row; |
| 828 dp = display_row; | 835 dp = display_row; |
| 829 if (rp != NULL && dp != NULL) | 836 if (rp != NULL && dp != NULL) |
| 830 for (i = 0; i < num_rows; i++) | 837 for (i = 0; i < num_rows; i++) |
| 831 { | 838 { |
| 832 png_bytep rptr = *rp++; | 839 png_bytep rptr = *rp++; |
| 833 png_bytep dptr = *dp++; | 840 png_bytep dptr = *dp++; |
| 834 | 841 |
| 835 png_read_row(png_ptr, rptr, dptr); | 842 png_read_row(png_ptr, rptr, dptr); |
| 836 } | 843 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 865 * [*] png_handle_alpha() does not exist yet, as of this version of libpng | 872 * [*] png_handle_alpha() does not exist yet, as of this version of libpng |
| 866 */ | 873 */ |
| 867 void PNGAPI | 874 void PNGAPI |
| 868 png_read_image(png_structp png_ptr, png_bytepp image) | 875 png_read_image(png_structp png_ptr, png_bytepp image) |
| 869 { | 876 { |
| 870 png_uint_32 i, image_height; | 877 png_uint_32 i, image_height; |
| 871 int pass, j; | 878 int pass, j; |
| 872 png_bytepp rp; | 879 png_bytepp rp; |
| 873 | 880 |
| 874 png_debug(1, "in png_read_image"); | 881 png_debug(1, "in png_read_image"); |
| 875 if (png_ptr == NULL) return; | 882 if (png_ptr == NULL) |
| 883 return; |
| 876 | 884 |
| 877 #ifdef PNG_READ_INTERLACING_SUPPORTED | 885 #ifdef PNG_READ_INTERLACING_SUPPORTED |
| 878 pass = png_set_interlace_handling(png_ptr); | 886 pass = png_set_interlace_handling(png_ptr); |
| 879 #else | 887 #else |
| 880 if (png_ptr->interlaced) | 888 if (png_ptr->interlaced) |
| 881 png_error(png_ptr, | 889 png_error(png_ptr, |
| 882 "Cannot read interlaced image -- interlace handler disabled."); | 890 "Cannot read interlaced image -- interlace handler disabled."); |
| 883 pass = 1; | 891 pass = 1; |
| 884 #endif | 892 #endif |
| 885 | 893 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 901 | 909 |
| 902 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED | 910 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED |
| 903 /* Read the end of the PNG file. Will not read past the end of the | 911 /* Read the end of the PNG file. Will not read past the end of the |
| 904 * file, will verify the end is accurate, and will read any comments | 912 * file, will verify the end is accurate, and will read any comments |
| 905 * or time information at the end of the file, if info is not NULL. | 913 * or time information at the end of the file, if info is not NULL. |
| 906 */ | 914 */ |
| 907 void PNGAPI | 915 void PNGAPI |
| 908 png_read_end(png_structp png_ptr, png_infop info_ptr) | 916 png_read_end(png_structp png_ptr, png_infop info_ptr) |
| 909 { | 917 { |
| 910 png_debug(1, "in png_read_end"); | 918 png_debug(1, "in png_read_end"); |
| 911 if (png_ptr == NULL) return; | 919 if (png_ptr == NULL) |
| 920 return; |
| 912 png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ | 921 png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ |
| 913 | 922 |
| 914 do | 923 do |
| 915 { | 924 { |
| 916 #ifdef PNG_USE_LOCAL_ARRAYS | 925 #ifdef PNG_USE_LOCAL_ARRAYS |
| 917 PNG_CONST PNG_IHDR; | 926 PNG_CONST PNG_IHDR; |
| 918 PNG_CONST PNG_IDAT; | 927 PNG_CONST PNG_IDAT; |
| 919 PNG_CONST PNG_IEND; | 928 PNG_CONST PNG_IEND; |
| 920 PNG_CONST PNG_PLTE; | 929 PNG_CONST PNG_PLTE; |
| 921 #if defined(PNG_READ_bKGD_SUPPORTED) | 930 #if defined(PNG_READ_bKGD_SUPPORTED) |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 #if defined(PNG_READ_iTXt_SUPPORTED) | 1077 #if defined(PNG_READ_iTXt_SUPPORTED) |
| 1069 else if (!png_memcmp(chunk_name, png_iTXt, 4)) | 1078 else if (!png_memcmp(chunk_name, png_iTXt, 4)) |
| 1070 png_handle_iTXt(png_ptr, info_ptr, length); | 1079 png_handle_iTXt(png_ptr, info_ptr, length); |
| 1071 #endif | 1080 #endif |
| 1072 else | 1081 else |
| 1073 png_handle_unknown(png_ptr, info_ptr, length); | 1082 png_handle_unknown(png_ptr, info_ptr, length); |
| 1074 } while (!(png_ptr->mode & PNG_HAVE_IEND)); | 1083 } while (!(png_ptr->mode & PNG_HAVE_IEND)); |
| 1075 } | 1084 } |
| 1076 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ | 1085 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ |
| 1077 | 1086 |
| 1078 /* free all memory used by the read */ | 1087 /* Free all memory used by the read */ |
| 1079 void PNGAPI | 1088 void PNGAPI |
| 1080 png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, | 1089 png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, |
| 1081 png_infopp end_info_ptr_ptr) | 1090 png_infopp end_info_ptr_ptr) |
| 1082 { | 1091 { |
| 1083 png_structp png_ptr = NULL; | 1092 png_structp png_ptr = NULL; |
| 1084 png_infop info_ptr = NULL, end_info_ptr = NULL; | 1093 png_infop info_ptr = NULL, end_info_ptr = NULL; |
| 1085 #ifdef PNG_USER_MEM_SUPPORTED | 1094 #ifdef PNG_USER_MEM_SUPPORTED |
| 1086 png_free_ptr free_fn = NULL; | 1095 png_free_ptr free_fn = NULL; |
| 1087 png_voidp mem_ptr = NULL; | 1096 png_voidp mem_ptr = NULL; |
| 1088 #endif | 1097 #endif |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1140 #ifdef PNG_USER_MEM_SUPPORTED | 1149 #ifdef PNG_USER_MEM_SUPPORTED |
| 1141 png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, | 1150 png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, |
| 1142 (png_voidp)mem_ptr); | 1151 (png_voidp)mem_ptr); |
| 1143 #else | 1152 #else |
| 1144 png_destroy_struct((png_voidp)png_ptr); | 1153 png_destroy_struct((png_voidp)png_ptr); |
| 1145 #endif | 1154 #endif |
| 1146 *png_ptr_ptr = NULL; | 1155 *png_ptr_ptr = NULL; |
| 1147 } | 1156 } |
| 1148 } | 1157 } |
| 1149 | 1158 |
| 1150 /* free all memory used by the read (old method) */ | 1159 /* Free all memory used by the read (old method) */ |
| 1151 void /* PRIVATE */ | 1160 void /* PRIVATE */ |
| 1152 png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
) | 1161 png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
) |
| 1153 { | 1162 { |
| 1154 #ifdef PNG_SETJMP_SUPPORTED | 1163 #ifdef PNG_SETJMP_SUPPORTED |
| 1155 jmp_buf tmp_jmp; | 1164 jmp_buf tmp_jmp; |
| 1156 #endif | 1165 #endif |
| 1157 png_error_ptr error_fn; | 1166 png_error_ptr error_fn; |
| 1158 png_error_ptr warning_fn; | 1167 png_error_ptr warning_fn; |
| 1159 png_voidp error_ptr; | 1168 png_voidp error_ptr; |
| 1160 #ifdef PNG_USER_MEM_SUPPORTED | 1169 #ifdef PNG_USER_MEM_SUPPORTED |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1289 | 1298 |
| 1290 #ifdef PNG_SETJMP_SUPPORTED | 1299 #ifdef PNG_SETJMP_SUPPORTED |
| 1291 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); | 1300 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); |
| 1292 #endif | 1301 #endif |
| 1293 | 1302 |
| 1294 } | 1303 } |
| 1295 | 1304 |
| 1296 void PNGAPI | 1305 void PNGAPI |
| 1297 png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) | 1306 png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) |
| 1298 { | 1307 { |
| 1299 if (png_ptr == NULL) return; | 1308 if (png_ptr == NULL) |
| 1309 return; |
| 1300 png_ptr->read_row_fn = read_row_fn; | 1310 png_ptr->read_row_fn = read_row_fn; |
| 1301 } | 1311 } |
| 1302 | 1312 |
| 1303 | 1313 |
| 1304 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED | 1314 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED |
| 1305 #if defined(PNG_INFO_IMAGE_SUPPORTED) | 1315 #if defined(PNG_INFO_IMAGE_SUPPORTED) |
| 1306 void PNGAPI | 1316 void PNGAPI |
| 1307 png_read_png(png_structp png_ptr, png_infop info_ptr, | 1317 png_read_png(png_structp png_ptr, png_infop info_ptr, |
| 1308 int transforms, | 1318 int transforms, |
| 1309 voidp params) | 1319 voidp params) |
| 1310 { | 1320 { |
| 1311 int row; | 1321 int row; |
| 1312 | 1322 |
| 1313 if (png_ptr == NULL) return; | 1323 if (png_ptr == NULL) |
| 1324 return; |
| 1314 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) | 1325 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) |
| 1315 /* invert the alpha channel from opacity to transparency | 1326 /* Invert the alpha channel from opacity to transparency |
| 1316 */ | 1327 */ |
| 1317 if (transforms & PNG_TRANSFORM_INVERT_ALPHA) | 1328 if (transforms & PNG_TRANSFORM_INVERT_ALPHA) |
| 1318 png_set_invert_alpha(png_ptr); | 1329 png_set_invert_alpha(png_ptr); |
| 1319 #endif | 1330 #endif |
| 1320 | 1331 |
| 1321 /* png_read_info() gives us all of the information from the | 1332 /* png_read_info() gives us all of the information from the |
| 1322 * PNG file before the first IDAT (image data chunk). | 1333 * PNG file before the first IDAT (image data chunk). |
| 1323 */ | 1334 */ |
| 1324 png_read_info(png_ptr, info_ptr); | 1335 png_read_info(png_ptr, info_ptr); |
| 1325 if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) | 1336 if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) |
| 1326 png_error(png_ptr, "Image is too high to process with png_read_png()"); | 1337 png_error(png_ptr, "Image is too high to process with png_read_png()"); |
| 1327 | 1338 |
| 1328 /* -------------- image transformations start here ------------------- */ | 1339 /* -------------- image transformations start here ------------------- */ |
| 1329 | 1340 |
| 1330 #if defined(PNG_READ_16_TO_8_SUPPORTED) | 1341 #if defined(PNG_READ_16_TO_8_SUPPORTED) |
| 1331 /* tell libpng to strip 16 bit/color files down to 8 bits per color | 1342 /* Tell libpng to strip 16 bit/color files down to 8 bits per color. |
| 1332 */ | 1343 */ |
| 1333 if (transforms & PNG_TRANSFORM_STRIP_16) | 1344 if (transforms & PNG_TRANSFORM_STRIP_16) |
| 1334 png_set_strip_16(png_ptr); | 1345 png_set_strip_16(png_ptr); |
| 1335 #endif | 1346 #endif |
| 1336 | 1347 |
| 1337 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) | 1348 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) |
| 1338 /* Strip alpha bytes from the input data without combining with | 1349 /* Strip alpha bytes from the input data without combining with |
| 1339 * the background (not recommended). | 1350 * the background (not recommended). |
| 1340 */ | 1351 */ |
| 1341 if (transforms & PNG_TRANSFORM_STRIP_ALPHA) | 1352 if (transforms & PNG_TRANSFORM_STRIP_ALPHA) |
| 1342 png_set_strip_alpha(png_ptr); | 1353 png_set_strip_alpha(png_ptr); |
| 1343 #endif | 1354 #endif |
| 1344 | 1355 |
| 1345 #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED) | 1356 #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED) |
| 1346 /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single | 1357 /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single |
| 1347 * byte into separate bytes (useful for paletted and grayscale images). | 1358 * byte into separate bytes (useful for paletted and grayscale images). |
| 1348 */ | 1359 */ |
| 1349 if (transforms & PNG_TRANSFORM_PACKING) | 1360 if (transforms & PNG_TRANSFORM_PACKING) |
| 1350 png_set_packing(png_ptr); | 1361 png_set_packing(png_ptr); |
| 1351 #endif | 1362 #endif |
| 1352 | 1363 |
| 1353 #if defined(PNG_READ_PACKSWAP_SUPPORTED) | 1364 #if defined(PNG_READ_PACKSWAP_SUPPORTED) |
| 1354 /* Change the order of packed pixels to least significant bit first | 1365 /* Change the order of packed pixels to least significant bit first |
| 1355 * (not useful if you are using png_set_packing). | 1366 * (not useful if you are using png_set_packing). |
| 1356 */ | 1367 */ |
| 1357 if (transforms & PNG_TRANSFORM_PACKSWAP) | 1368 if (transforms & PNG_TRANSFORM_PACKSWAP) |
| 1358 png_set_packswap(png_ptr); | 1369 png_set_packswap(png_ptr); |
| 1359 #endif | 1370 #endif |
| 1360 | 1371 |
| 1361 #if defined(PNG_READ_EXPAND_SUPPORTED) | 1372 #if defined(PNG_READ_EXPAND_SUPPORTED) |
| 1362 /* Expand paletted colors into true RGB triplets | 1373 /* Expand paletted colors into true RGB triplets |
| 1363 * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel | 1374 * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel |
| 1364 * Expand paletted or RGB images with transparency to full alpha | 1375 * Expand paletted or RGB images with transparency to full alpha |
| 1365 * channels so the data will be available as RGBA quartets. | 1376 * channels so the data will be available as RGBA quartets. |
| 1366 */ | 1377 */ |
| 1367 if (transforms & PNG_TRANSFORM_EXPAND) | 1378 if (transforms & PNG_TRANSFORM_EXPAND) |
| 1368 if ((png_ptr->bit_depth < 8) || | 1379 if ((png_ptr->bit_depth < 8) || |
| 1369 (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) || | 1380 (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) || |
| 1370 (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))) | 1381 (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))) |
| 1371 png_set_expand(png_ptr); | 1382 png_set_expand(png_ptr); |
| 1372 #endif | 1383 #endif |
| 1373 | 1384 |
| 1374 /* We don't handle background color or gamma transformation or dithering. | 1385 /* We don't handle background color or gamma transformation or dithering. |
| 1375 */ | 1386 */ |
| 1376 | 1387 |
| 1377 #if defined(PNG_READ_INVERT_SUPPORTED) | 1388 #if defined(PNG_READ_INVERT_SUPPORTED) |
| 1378 /* invert monochrome files to have 0 as white and 1 as black | 1389 /* Invert monochrome files to have 0 as white and 1 as black |
| 1379 */ | 1390 */ |
| 1380 if (transforms & PNG_TRANSFORM_INVERT_MONO) | 1391 if (transforms & PNG_TRANSFORM_INVERT_MONO) |
| 1381 png_set_invert_mono(png_ptr); | 1392 png_set_invert_mono(png_ptr); |
| 1382 #endif | 1393 #endif |
| 1383 | 1394 |
| 1384 #if defined(PNG_READ_SHIFT_SUPPORTED) | 1395 #if defined(PNG_READ_SHIFT_SUPPORTED) |
| 1385 /* If you want to shift the pixel values from the range [0,255] or | 1396 /* If you want to shift the pixel values from the range [0,255] or |
| 1386 * [0,65535] to the original [0,7] or [0,31], or whatever range the | 1397 * [0,65535] to the original [0,7] or [0,31], or whatever range the |
| 1387 * colors were originally in: | 1398 * colors were originally in: |
| 1388 */ | 1399 */ |
| 1389 if ((transforms & PNG_TRANSFORM_SHIFT) | 1400 if ((transforms & PNG_TRANSFORM_SHIFT) |
| 1390 && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT)) | 1401 && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT)) |
| 1391 { | 1402 { |
| 1392 png_color_8p sig_bit; | 1403 png_color_8p sig_bit; |
| 1393 | 1404 |
| 1394 png_get_sBIT(png_ptr, info_ptr, &sig_bit); | 1405 png_get_sBIT(png_ptr, info_ptr, &sig_bit); |
| 1395 png_set_shift(png_ptr, sig_bit); | 1406 png_set_shift(png_ptr, sig_bit); |
| 1396 } | 1407 } |
| 1397 #endif | 1408 #endif |
| 1398 | 1409 |
| 1399 #if defined(PNG_READ_BGR_SUPPORTED) | 1410 #if defined(PNG_READ_BGR_SUPPORTED) |
| 1400 /* flip the RGB pixels to BGR (or RGBA to BGRA) | 1411 /* Flip the RGB pixels to BGR (or RGBA to BGRA) |
| 1401 */ | 1412 */ |
| 1402 if (transforms & PNG_TRANSFORM_BGR) | 1413 if (transforms & PNG_TRANSFORM_BGR) |
| 1403 png_set_bgr(png_ptr); | 1414 png_set_bgr(png_ptr); |
| 1404 #endif | 1415 #endif |
| 1405 | 1416 |
| 1406 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) | 1417 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) |
| 1407 /* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) | 1418 /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) |
| 1408 */ | 1419 */ |
| 1409 if (transforms & PNG_TRANSFORM_SWAP_ALPHA) | 1420 if (transforms & PNG_TRANSFORM_SWAP_ALPHA) |
| 1410 png_set_swap_alpha(png_ptr); | 1421 png_set_swap_alpha(png_ptr); |
| 1411 #endif | 1422 #endif |
| 1412 | 1423 |
| 1413 #if defined(PNG_READ_SWAP_SUPPORTED) | 1424 #if defined(PNG_READ_SWAP_SUPPORTED) |
| 1414 /* swap bytes of 16 bit files to least significant byte first | 1425 /* Swap bytes of 16 bit files to least significant byte first |
| 1415 */ | 1426 */ |
| 1416 if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) | 1427 if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) |
| 1417 png_set_swap(png_ptr); | 1428 png_set_swap(png_ptr); |
| 1418 #endif | 1429 #endif |
| 1419 | 1430 |
| 1420 /* We don't handle adding filler bytes */ | 1431 /* We don't handle adding filler bytes */ |
| 1421 | 1432 |
| 1422 /* Optional call to gamma correct and add the background to the palette | 1433 /* Optional call to gamma correct and add the background to the palette |
| 1423 * and update info structure. REQUIRED if you are expecting libpng to | 1434 * and update info structure. REQUIRED if you are expecting libpng to |
| 1424 * update the palette for you (i.e., you selected such a transform above). | 1435 * update the palette for you (i.e., you selected such a transform above). |
| 1425 */ | 1436 */ |
| 1426 png_read_update_info(png_ptr, info_ptr); | 1437 png_read_update_info(png_ptr, info_ptr); |
| 1427 | 1438 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1440 info_ptr->free_me |= PNG_FREE_ROWS; | 1451 info_ptr->free_me |= PNG_FREE_ROWS; |
| 1441 #endif | 1452 #endif |
| 1442 for (row = 0; row < (int)info_ptr->height; row++) | 1453 for (row = 0; row < (int)info_ptr->height; row++) |
| 1443 info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, | 1454 info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, |
| 1444 png_get_rowbytes(png_ptr, info_ptr)); | 1455 png_get_rowbytes(png_ptr, info_ptr)); |
| 1445 } | 1456 } |
| 1446 | 1457 |
| 1447 png_read_image(png_ptr, info_ptr->row_pointers); | 1458 png_read_image(png_ptr, info_ptr->row_pointers); |
| 1448 info_ptr->valid |= PNG_INFO_IDAT; | 1459 info_ptr->valid |= PNG_INFO_IDAT; |
| 1449 | 1460 |
| 1450 /* read rest of file, and get additional chunks in info_ptr - REQUIRED */ | 1461 /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */ |
| 1451 png_read_end(png_ptr, info_ptr); | 1462 png_read_end(png_ptr, info_ptr); |
| 1452 | 1463 |
| 1453 transforms = transforms; /* quiet compiler warnings */ | 1464 transforms = transforms; /* Quiet compiler warnings */ |
| 1454 params = params; | 1465 params = params; |
| 1455 | 1466 |
| 1456 } | 1467 } |
| 1457 #endif /* PNG_INFO_IMAGE_SUPPORTED */ | 1468 #endif /* PNG_INFO_IMAGE_SUPPORTED */ |
| 1458 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ | 1469 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ |
| 1459 #endif /* PNG_READ_SUPPORTED */ | 1470 #endif /* PNG_READ_SUPPORTED */ |
| OLD | NEW |