27 * This file is available under and governed by the GNU General Public |
27 * This file is available under and governed by the GNU General Public |
28 * License version 2 only, as published by the Free Software Foundation. |
28 * License version 2 only, as published by the Free Software Foundation. |
29 * However, the following notice accompanied the original version of this |
29 * However, the following notice accompanied the original version of this |
30 * file and, per its terms, should not be removed: |
30 * file and, per its terms, should not be removed: |
31 * |
31 * |
32 * Last changed in libpng 1.6.35 [July 15, 2018] |
32 * Copyright (c) 2018 Cosmin Truta |
33 * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson |
33 * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson |
34 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
34 * Copyright (c) 1996-1997 Andreas Dilger |
35 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
35 * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. |
36 * |
36 * |
37 * This code is released under the libpng license. |
37 * This code is released under the libpng license. |
38 * For conditions of distribution and use, see the disclaimer |
38 * For conditions of distribution and use, see the disclaimer |
39 * and license in png.h |
39 * and license in png.h |
40 * |
40 * |
1487 |
1487 |
1488 if (size == 0) |
1488 if (size == 0) |
1489 { |
1489 { |
1490 /* We have the ICC profile header; do the basic header checks. |
1490 /* We have the ICC profile header; do the basic header checks. |
1491 */ |
1491 */ |
1492 const png_uint_32 profile_length = |
1492 png_uint_32 profile_length = png_get_uint_32(profile_header); |
1493 png_get_uint_32(profile_header); |
|
1494 |
1493 |
1495 if (png_icc_check_length(png_ptr, &png_ptr->colorspace, |
1494 if (png_icc_check_length(png_ptr, &png_ptr->colorspace, |
1496 keyword, profile_length) != 0) |
1495 keyword, profile_length) != 0) |
1497 { |
1496 { |
1498 /* The length is apparently ok, so we can check the 132 |
1497 /* The length is apparently ok, so we can check the 132 |
1505 /* Now read the tag table; a variable size buffer is |
1504 /* Now read the tag table; a variable size buffer is |
1506 * needed at this point, allocate one for the whole |
1505 * needed at this point, allocate one for the whole |
1507 * profile. The header check has already validated |
1506 * profile. The header check has already validated |
1508 * that none of this stuff will overflow. |
1507 * that none of this stuff will overflow. |
1509 */ |
1508 */ |
1510 const png_uint_32 tag_count = png_get_uint_32( |
1509 png_uint_32 tag_count = |
1511 profile_header+128); |
1510 png_get_uint_32(profile_header + 128); |
1512 png_bytep profile = png_read_buffer(png_ptr, |
1511 png_bytep profile = png_read_buffer(png_ptr, |
1513 profile_length, 2/*silent*/); |
1512 profile_length, 2/*silent*/); |
1514 |
1513 |
1515 if (profile != NULL) |
1514 if (profile != NULL) |
1516 { |
1515 { |
3389 # define DEPTH_INDEX(d) ((d)==1?0:((d)==2?1:2)) |
3388 # define DEPTH_INDEX(d) ((d)==1?0:((d)==2?1:2)) |
3390 |
3389 |
3391 /* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and |
3390 /* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and |
3392 * then pass: |
3391 * then pass: |
3393 */ |
3392 */ |
3394 static PNG_CONST png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] = |
3393 static const png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] = |
3395 { |
3394 { |
3396 /* Little-endian byte masks for PACKSWAP */ |
3395 /* Little-endian byte masks for PACKSWAP */ |
3397 { S_MASKS(1,0), S_MASKS(2,0), S_MASKS(4,0) }, |
3396 { S_MASKS(1,0), S_MASKS(2,0), S_MASKS(4,0) }, |
3398 /* Normal (big-endian byte) masks - PNG format */ |
3397 /* Normal (big-endian byte) masks - PNG format */ |
3399 { S_MASKS(1,1), S_MASKS(2,1), S_MASKS(4,1) } |
3398 { S_MASKS(1,1), S_MASKS(2,1), S_MASKS(4,1) } |
3400 }; |
3399 }; |
3401 |
3400 |
3402 /* display_mask has only three entries for the odd passes, so index by |
3401 /* display_mask has only three entries for the odd passes, so index by |
3403 * pass>>1. |
3402 * pass>>1. |
3404 */ |
3403 */ |
3405 static PNG_CONST png_uint_32 display_mask[2][3][3] = |
3404 static const png_uint_32 display_mask[2][3][3] = |
3406 { |
3405 { |
3407 /* Little-endian byte masks for PACKSWAP */ |
3406 /* Little-endian byte masks for PACKSWAP */ |
3408 { B_MASKS(1,0), B_MASKS(2,0), B_MASKS(4,0) }, |
3407 { B_MASKS(1,0), B_MASKS(2,0), B_MASKS(4,0) }, |
3409 /* Normal (big-endian byte) masks - PNG format */ |
3408 /* Normal (big-endian byte) masks - PNG format */ |
3410 { B_MASKS(1,1), B_MASKS(2,1), B_MASKS(4,1) } |
3409 { B_MASKS(1,1), B_MASKS(2,1), B_MASKS(4,1) } |
3713 png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, |
3712 png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, |
3714 png_uint_32 transformations /* Because these may affect the byte layout */) |
3713 png_uint_32 transformations /* Because these may affect the byte layout */) |
3715 { |
3714 { |
3716 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ |
3715 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ |
3717 /* Offset to next interlace block */ |
3716 /* Offset to next interlace block */ |
3718 static PNG_CONST unsigned int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; |
3717 static const unsigned int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; |
3719 |
3718 |
3720 png_debug(1, "in png_do_read_interlace"); |
3719 png_debug(1, "in png_do_read_interlace"); |
3721 if (row != NULL && row_info != NULL) |
3720 if (row != NULL && row_info != NULL) |
3722 { |
3721 { |
3723 png_uint_32 final_width; |
3722 png_uint_32 final_width; |
4355 png_read_finish_row(png_structrp png_ptr) |
4354 png_read_finish_row(png_structrp png_ptr) |
4356 { |
4355 { |
4357 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ |
4356 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ |
4358 |
4357 |
4359 /* Start of interlace block */ |
4358 /* Start of interlace block */ |
4360 static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; |
4359 static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; |
4361 |
4360 |
4362 /* Offset to next interlace block */ |
4361 /* Offset to next interlace block */ |
4363 static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; |
4362 static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; |
4364 |
4363 |
4365 /* Start of interlace block in the y direction */ |
4364 /* Start of interlace block in the y direction */ |
4366 static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; |
4365 static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; |
4367 |
4366 |
4368 /* Offset to next interlace block in the y direction */ |
4367 /* Offset to next interlace block in the y direction */ |
4369 static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; |
4368 static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; |
4370 |
4369 |
4371 png_debug(1, "in png_read_finish_row"); |
4370 png_debug(1, "in png_read_finish_row"); |
4372 png_ptr->row_number++; |
4371 png_ptr->row_number++; |
4373 if (png_ptr->row_number < png_ptr->num_rows) |
4372 if (png_ptr->row_number < png_ptr->num_rows) |
4374 return; |
4373 return; |
4420 png_read_start_row(png_structrp png_ptr) |
4419 png_read_start_row(png_structrp png_ptr) |
4421 { |
4420 { |
4422 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ |
4421 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ |
4423 |
4422 |
4424 /* Start of interlace block */ |
4423 /* Start of interlace block */ |
4425 static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; |
4424 static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; |
4426 |
4425 |
4427 /* Offset to next interlace block */ |
4426 /* Offset to next interlace block */ |
4428 static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; |
4427 static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; |
4429 |
4428 |
4430 /* Start of interlace block in the y direction */ |
4429 /* Start of interlace block in the y direction */ |
4431 static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; |
4430 static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; |
4432 |
4431 |
4433 /* Offset to next interlace block in the y direction */ |
4432 /* Offset to next interlace block in the y direction */ |
4434 static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; |
4433 static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; |
4435 |
4434 |
4436 unsigned int max_pixel_depth; |
4435 unsigned int max_pixel_depth; |
4437 size_t row_bytes; |
4436 size_t row_bytes; |
4438 |
4437 |
4439 png_debug(1, "in png_read_start_row"); |
4438 png_debug(1, "in png_read_start_row"); |