547 /* Various modes of operation. Note that after an init, mode is set to |
577 /* Various modes of operation. Note that after an init, mode is set to |
548 * zero automatically when the structure is created. Three of these |
578 * zero automatically when the structure is created. Three of these |
549 * are defined in png.h because they need to be visible to applications |
579 * are defined in png.h because they need to be visible to applications |
550 * that call png_set_unknown_chunk(). |
580 * that call png_set_unknown_chunk(). |
551 */ |
581 */ |
552 /* #define PNG_HAVE_IHDR 0x01 (defined in png.h) */ |
582 /* #define PNG_HAVE_IHDR 0x01U (defined in png.h) */ |
553 /* #define PNG_HAVE_PLTE 0x02 (defined in png.h) */ |
583 /* #define PNG_HAVE_PLTE 0x02U (defined in png.h) */ |
554 #define PNG_HAVE_IDAT 0x04 |
584 #define PNG_HAVE_IDAT 0x04U |
555 /* #define PNG_AFTER_IDAT 0x08 (defined in png.h) */ |
585 /* #define PNG_AFTER_IDAT 0x08U (defined in png.h) */ |
556 #define PNG_HAVE_IEND 0x10 |
586 #define PNG_HAVE_IEND 0x10U |
557 /* 0x20 (unused) */ |
587 /* 0x20U (unused) */ |
558 /* 0x40 (unused) */ |
588 /* 0x40U (unused) */ |
559 /* 0x80 (unused) */ |
589 /* 0x80U (unused) */ |
560 #define PNG_HAVE_CHUNK_HEADER 0x100 |
590 #define PNG_HAVE_CHUNK_HEADER 0x100U |
561 #define PNG_WROTE_tIME 0x200 |
591 #define PNG_WROTE_tIME 0x200U |
562 #define PNG_WROTE_INFO_BEFORE_PLTE 0x400 |
592 #define PNG_WROTE_INFO_BEFORE_PLTE 0x400U |
563 #define PNG_BACKGROUND_IS_GRAY 0x800 |
593 #define PNG_BACKGROUND_IS_GRAY 0x800U |
564 #define PNG_HAVE_PNG_SIGNATURE 0x1000 |
594 #define PNG_HAVE_PNG_SIGNATURE 0x1000U |
565 #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */ |
595 #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000U /* Have another chunk after IDAT */ |
566 /* 0x4000 (unused) */ |
596 /* 0x4000U (unused) */ |
567 #define PNG_IS_READ_STRUCT 0x8000 /* Else is a write struct */ |
597 #define PNG_IS_READ_STRUCT 0x8000U /* Else is a write struct */ |
568 |
598 |
569 /* Flags for the transformations the PNG library does on the image data */ |
599 /* Flags for the transformations the PNG library does on the image data */ |
570 #define PNG_BGR 0x0001 |
600 #define PNG_BGR 0x0001U |
571 #define PNG_INTERLACE 0x0002 |
601 #define PNG_INTERLACE 0x0002U |
572 #define PNG_PACK 0x0004 |
602 #define PNG_PACK 0x0004U |
573 #define PNG_SHIFT 0x0008 |
603 #define PNG_SHIFT 0x0008U |
574 #define PNG_SWAP_BYTES 0x0010 |
604 #define PNG_SWAP_BYTES 0x0010U |
575 #define PNG_INVERT_MONO 0x0020 |
605 #define PNG_INVERT_MONO 0x0020U |
576 #define PNG_QUANTIZE 0x0040 |
606 #define PNG_QUANTIZE 0x0040U |
577 #define PNG_COMPOSE 0x0080 /* Was PNG_BACKGROUND */ |
607 #define PNG_COMPOSE 0x0080U /* Was PNG_BACKGROUND */ |
578 #define PNG_BACKGROUND_EXPAND 0x0100 |
608 #define PNG_BACKGROUND_EXPAND 0x0100U |
579 #define PNG_EXPAND_16 0x0200 /* Added to libpng 1.5.2 */ |
609 #define PNG_EXPAND_16 0x0200U /* Added to libpng 1.5.2 */ |
580 #define PNG_16_TO_8 0x0400 /* Becomes 'chop' in 1.5.4 */ |
610 #define PNG_16_TO_8 0x0400U /* Becomes 'chop' in 1.5.4 */ |
581 #define PNG_RGBA 0x0800 |
611 #define PNG_RGBA 0x0800U |
582 #define PNG_EXPAND 0x1000 |
612 #define PNG_EXPAND 0x1000U |
583 #define PNG_GAMMA 0x2000 |
613 #define PNG_GAMMA 0x2000U |
584 #define PNG_GRAY_TO_RGB 0x4000 |
614 #define PNG_GRAY_TO_RGB 0x4000U |
585 #define PNG_FILLER 0x8000 |
615 #define PNG_FILLER 0x8000U |
586 #define PNG_PACKSWAP 0x10000 |
616 #define PNG_PACKSWAP 0x10000U |
587 #define PNG_SWAP_ALPHA 0x20000 |
617 #define PNG_SWAP_ALPHA 0x20000U |
588 #define PNG_STRIP_ALPHA 0x40000 |
618 #define PNG_STRIP_ALPHA 0x40000U |
589 #define PNG_INVERT_ALPHA 0x80000 |
619 #define PNG_INVERT_ALPHA 0x80000U |
590 #define PNG_USER_TRANSFORM 0x100000 |
620 #define PNG_USER_TRANSFORM 0x100000U |
591 #define PNG_RGB_TO_GRAY_ERR 0x200000 |
621 #define PNG_RGB_TO_GRAY_ERR 0x200000U |
592 #define PNG_RGB_TO_GRAY_WARN 0x400000 |
622 #define PNG_RGB_TO_GRAY_WARN 0x400000U |
593 #define PNG_RGB_TO_GRAY 0x600000 /* two bits, RGB_TO_GRAY_ERR|WARN */ |
623 #define PNG_RGB_TO_GRAY 0x600000U /* two bits, RGB_TO_GRAY_ERR|WARN */ |
594 #define PNG_ENCODE_ALPHA 0x800000 /* Added to libpng-1.5.4 */ |
624 #define PNG_ENCODE_ALPHA 0x800000U /* Added to libpng-1.5.4 */ |
595 #define PNG_ADD_ALPHA 0x1000000 /* Added to libpng-1.2.7 */ |
625 #define PNG_ADD_ALPHA 0x1000000U /* Added to libpng-1.2.7 */ |
596 #define PNG_EXPAND_tRNS 0x2000000 /* Added to libpng-1.2.9 */ |
626 #define PNG_EXPAND_tRNS 0x2000000U /* Added to libpng-1.2.9 */ |
597 #define PNG_SCALE_16_TO_8 0x4000000 /* Added to libpng-1.5.4 */ |
627 #define PNG_SCALE_16_TO_8 0x4000000U /* Added to libpng-1.5.4 */ |
598 /* 0x8000000 unused */ |
628 /* 0x8000000U unused */ |
599 /* 0x10000000 unused */ |
629 /* 0x10000000U unused */ |
600 /* 0x20000000 unused */ |
630 /* 0x20000000U unused */ |
601 /* 0x40000000 unused */ |
631 /* 0x40000000U unused */ |
602 /* Flags for png_create_struct */ |
632 /* Flags for png_create_struct */ |
603 #define PNG_STRUCT_PNG 0x0001 |
633 #define PNG_STRUCT_PNG 0x0001U |
604 #define PNG_STRUCT_INFO 0x0002 |
634 #define PNG_STRUCT_INFO 0x0002U |
605 |
635 |
606 /* Flags for the png_ptr->flags rather than declaring a byte for each one */ |
636 /* Flags for the png_ptr->flags rather than declaring a byte for each one */ |
607 #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001 |
637 #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001U |
608 #define PNG_FLAG_ZSTREAM_INITIALIZED 0x0002 /* Added to libpng-1.6.0 */ |
638 #define PNG_FLAG_ZSTREAM_INITIALIZED 0x0002U /* Added to libpng-1.6.0 */ |
609 /* 0x0004 unused */ |
639 /* 0x0004U unused */ |
610 #define PNG_FLAG_ZSTREAM_ENDED 0x0008 /* Added to libpng-1.6.0 */ |
640 #define PNG_FLAG_ZSTREAM_ENDED 0x0008U /* Added to libpng-1.6.0 */ |
611 /* 0x0010 unused */ |
641 /* 0x0010U unused */ |
612 /* 0x0020 unused */ |
642 /* 0x0020U unused */ |
613 #define PNG_FLAG_ROW_INIT 0x0040 |
643 #define PNG_FLAG_ROW_INIT 0x0040U |
614 #define PNG_FLAG_FILLER_AFTER 0x0080 |
644 #define PNG_FLAG_FILLER_AFTER 0x0080U |
615 #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100 |
645 #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100U |
616 #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200 |
646 #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200U |
617 #define PNG_FLAG_CRC_CRITICAL_USE 0x0400 |
647 #define PNG_FLAG_CRC_CRITICAL_USE 0x0400U |
618 #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800 |
648 #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800U |
619 #define PNG_FLAG_ASSUME_sRGB 0x1000 /* Added to libpng-1.5.4 */ |
649 #define PNG_FLAG_ASSUME_sRGB 0x1000U /* Added to libpng-1.5.4 */ |
620 #define PNG_FLAG_OPTIMIZE_ALPHA 0x2000 /* Added to libpng-1.5.4 */ |
650 #define PNG_FLAG_OPTIMIZE_ALPHA 0x2000U /* Added to libpng-1.5.4 */ |
621 #define PNG_FLAG_DETECT_UNINITIALIZED 0x4000 /* Added to libpng-1.5.4 */ |
651 #define PNG_FLAG_DETECT_UNINITIALIZED 0x4000U /* Added to libpng-1.5.4 */ |
622 /* #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000 */ |
652 /* #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000U */ |
623 /* #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000 */ |
653 /* #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000U */ |
624 #define PNG_FLAG_LIBRARY_MISMATCH 0x20000 |
654 #define PNG_FLAG_LIBRARY_MISMATCH 0x20000U |
625 #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000 |
655 #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000U |
626 #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000 |
656 #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000U |
627 #define PNG_FLAG_BENIGN_ERRORS_WARN 0x100000 /* Added to libpng-1.4.0 */ |
657 #define PNG_FLAG_BENIGN_ERRORS_WARN 0x100000U /* Added to libpng-1.4.0 */ |
628 #define PNG_FLAG_APP_WARNINGS_WARN 0x200000 /* Added to libpng-1.6.0 */ |
658 #define PNG_FLAG_APP_WARNINGS_WARN 0x200000U /* Added to libpng-1.6.0 */ |
629 #define PNG_FLAG_APP_ERRORS_WARN 0x400000 /* Added to libpng-1.6.0 */ |
659 #define PNG_FLAG_APP_ERRORS_WARN 0x400000U /* Added to libpng-1.6.0 */ |
630 /* 0x800000 unused */ |
660 /* 0x800000U unused */ |
631 /* 0x1000000 unused */ |
661 /* 0x1000000U unused */ |
632 /* 0x2000000 unused */ |
662 /* 0x2000000U unused */ |
633 /* 0x4000000 unused */ |
663 /* 0x4000000U unused */ |
634 /* 0x8000000 unused */ |
664 /* 0x8000000U unused */ |
635 /* 0x10000000 unused */ |
665 /* 0x10000000U unused */ |
636 /* 0x20000000 unused */ |
666 /* 0x20000000U unused */ |
637 /* 0x40000000 unused */ |
667 /* 0x40000000U unused */ |
638 |
668 |
639 #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ |
669 #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ |
640 PNG_FLAG_CRC_ANCILLARY_NOWARN) |
670 PNG_FLAG_CRC_ANCILLARY_NOWARN) |
641 |
671 |
642 #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \ |
672 #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \ |
665 /* Added to libpng-1.2.6 JB */ |
695 /* Added to libpng-1.2.6 JB */ |
666 #define PNG_ROWBYTES(pixel_bits, width) \ |
696 #define PNG_ROWBYTES(pixel_bits, width) \ |
667 ((pixel_bits) >= 8 ? \ |
697 ((pixel_bits) >= 8 ? \ |
668 ((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \ |
698 ((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \ |
669 (( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 3) ) |
699 (( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 3) ) |
|
700 |
|
701 /* This returns the number of trailing bits in the last byte of a row, 0 if the |
|
702 * last byte is completely full of pixels. It is, in principle, (pixel_bits x |
|
703 * width) % 8, but that would overflow for large 'width'. The second macro is |
|
704 * the same except that it returns the number of unused bits in the last byte; |
|
705 * (8-TRAILBITS), but 0 when TRAILBITS is 0. |
|
706 * |
|
707 * NOTE: these macros are intended to be self-evidently correct and never |
|
708 * overflow on the assumption that pixel_bits is in the range 0..255. The |
|
709 * arguments are evaluated only once and they can be signed (e.g. as a result of |
|
710 * the integral promotions). The result of the expression always has type |
|
711 * (png_uint_32), however the compiler always knows it is in the range 0..7. |
|
712 */ |
|
713 #define PNG_TRAILBITS(pixel_bits, width) \ |
|
714 (((pixel_bits) * ((width) % (png_uint_32)8)) % 8) |
|
715 |
|
716 #define PNG_PADBITS(pixel_bits, width) \ |
|
717 ((8 - PNG_TRAILBITS(pixel_bits, width)) % 8) |
670 |
718 |
671 /* PNG_OUT_OF_RANGE returns true if value is outside the range |
719 /* PNG_OUT_OF_RANGE returns true if value is outside the range |
672 * ideal-delta..ideal+delta. Each argument is evaluated twice. |
720 * ideal-delta..ideal+delta. Each argument is evaluated twice. |
673 * "ideal" and "delta" should be constants, normally simple |
721 * "ideal" and "delta" should be constants, normally simple |
674 * integers, "value" a variable. Added to libpng-1.2.6 JB |
722 * integers, "value" a variable. Added to libpng-1.2.6 JB |
1214 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); |
1263 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); |
1215 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_neon,(png_row_infop |
1264 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_neon,(png_row_infop |
1216 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); |
1265 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); |
1217 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_neon,(png_row_infop |
1266 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_neon,(png_row_infop |
1218 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); |
1267 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); |
|
1268 #endif |
|
1269 |
|
1270 #if PNG_MIPS_MSA_OPT > 0 |
|
1271 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_msa,(png_row_infop row_info, |
|
1272 png_bytep row, png_const_bytep prev_row),PNG_EMPTY); |
|
1273 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_msa,(png_row_infop |
|
1274 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); |
|
1275 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_msa,(png_row_infop |
|
1276 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); |
|
1277 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_msa,(png_row_infop |
|
1278 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); |
|
1279 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_msa,(png_row_infop |
|
1280 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); |
|
1281 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_msa,(png_row_infop |
|
1282 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); |
|
1283 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_msa,(png_row_infop |
|
1284 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); |
|
1285 #endif |
1219 |
1286 |
1220 /* Choose the best filter to use and filter the row data */ |
1287 /* Choose the best filter to use and filter the row data */ |
1221 PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr, |
1288 PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr, |
1222 png_row_infop row_info),PNG_EMPTY); |
1289 png_row_infop row_info),PNG_EMPTY); |
1223 |
1290 |
1439 PNG_INTERNAL_FUNCTION(void,png_push_have_info,(png_structrp png_ptr, |
1506 PNG_INTERNAL_FUNCTION(void,png_push_have_info,(png_structrp png_ptr, |
1440 png_inforp info_ptr),PNG_EMPTY); |
1507 png_inforp info_ptr),PNG_EMPTY); |
1441 PNG_INTERNAL_FUNCTION(void,png_push_have_end,(png_structrp png_ptr, |
1508 PNG_INTERNAL_FUNCTION(void,png_push_have_end,(png_structrp png_ptr, |
1442 png_inforp info_ptr),PNG_EMPTY); |
1509 png_inforp info_ptr),PNG_EMPTY); |
1443 PNG_INTERNAL_FUNCTION(void,png_push_have_row,(png_structrp png_ptr, |
1510 PNG_INTERNAL_FUNCTION(void,png_push_have_row,(png_structrp png_ptr, |
1444 png_bytep row),PNG_EMPTY); |
1511 png_bytep row),PNG_EMPTY); |
1445 PNG_INTERNAL_FUNCTION(void,png_push_read_end,(png_structrp png_ptr, |
1512 PNG_INTERNAL_FUNCTION(void,png_push_read_end,(png_structrp png_ptr, |
1446 png_inforp info_ptr),PNG_EMPTY); |
1513 png_inforp info_ptr),PNG_EMPTY); |
1447 PNG_INTERNAL_FUNCTION(void,png_process_some_data,(png_structrp png_ptr, |
1514 PNG_INTERNAL_FUNCTION(void,png_process_some_data,(png_structrp png_ptr, |
1448 png_inforp info_ptr),PNG_EMPTY); |
1515 png_inforp info_ptr),PNG_EMPTY); |
1449 PNG_INTERNAL_FUNCTION(void,png_read_push_finish_row,(png_structrp png_ptr), |
1516 PNG_INTERNAL_FUNCTION(void,png_read_push_finish_row,(png_structrp png_ptr), |
1518 png_uint_32 profile_length, png_const_bytep profile, int color_type), |
1585 png_uint_32 profile_length, png_const_bytep profile, int color_type), |
1519 PNG_EMPTY); |
1586 PNG_EMPTY); |
1520 /* The 'name' is used for information only */ |
1587 /* The 'name' is used for information only */ |
1521 |
1588 |
1522 /* Routines for checking parts of an ICC profile. */ |
1589 /* Routines for checking parts of an ICC profile. */ |
|
1590 #ifdef PNG_READ_iCCP_SUPPORTED |
1523 PNG_INTERNAL_FUNCTION(int,png_icc_check_length,(png_const_structrp png_ptr, |
1591 PNG_INTERNAL_FUNCTION(int,png_icc_check_length,(png_const_structrp png_ptr, |
1524 png_colorspacerp colorspace, png_const_charp name, |
1592 png_colorspacerp colorspace, png_const_charp name, |
1525 png_uint_32 profile_length), PNG_EMPTY); |
1593 png_uint_32 profile_length), PNG_EMPTY); |
|
1594 #endif /* READ_iCCP */ |
1526 PNG_INTERNAL_FUNCTION(int,png_icc_check_header,(png_const_structrp png_ptr, |
1595 PNG_INTERNAL_FUNCTION(int,png_icc_check_header,(png_const_structrp png_ptr, |
1527 png_colorspacerp colorspace, png_const_charp name, |
1596 png_colorspacerp colorspace, png_const_charp name, |
1528 png_uint_32 profile_length, |
1597 png_uint_32 profile_length, |
1529 png_const_bytep profile /* first 132 bytes only */, int color_type), |
1598 png_const_bytep profile /* first 132 bytes only */, int color_type), |
1530 PNG_EMPTY); |
1599 PNG_EMPTY); |