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.26 [October 20, 2016] |
32 * Last changed in libpng 1.6.33 [September 28, 2017] |
33 * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson |
33 * Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson |
34 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
34 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
35 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
35 * (Version 0.88 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 |
540 if (row_info->bit_depth == 8) |
540 if (row_info->bit_depth == 8) |
541 { |
541 { |
542 if (at_start != 0) /* Skip initial filler */ |
542 if (at_start != 0) /* Skip initial filler */ |
543 ++sp; |
543 ++sp; |
544 else /* Skip initial channel and, for sp, the filler */ |
544 else /* Skip initial channel and, for sp, the filler */ |
545 sp += 2, ++dp; |
545 { |
|
546 sp += 2; ++dp; |
|
547 } |
546 |
548 |
547 /* For a 1 pixel wide image there is nothing to do */ |
549 /* For a 1 pixel wide image there is nothing to do */ |
548 while (sp < ep) |
550 while (sp < ep) |
549 *dp++ = *sp, sp += 2; |
551 { |
|
552 *dp++ = *sp; sp += 2; |
|
553 } |
550 |
554 |
551 row_info->pixel_depth = 8; |
555 row_info->pixel_depth = 8; |
552 } |
556 } |
553 |
557 |
554 else if (row_info->bit_depth == 16) |
558 else if (row_info->bit_depth == 16) |
555 { |
559 { |
556 if (at_start != 0) /* Skip initial filler */ |
560 if (at_start != 0) /* Skip initial filler */ |
557 sp += 2; |
561 sp += 2; |
558 else /* Skip initial channel and, for sp, the filler */ |
562 else /* Skip initial channel and, for sp, the filler */ |
559 sp += 4, dp += 2; |
563 { |
|
564 sp += 4; dp += 2; |
|
565 } |
560 |
566 |
561 while (sp < ep) |
567 while (sp < ep) |
562 *dp++ = *sp++, *dp++ = *sp, sp += 3; |
568 { |
|
569 *dp++ = *sp++; *dp++ = *sp; sp += 3; |
|
570 } |
563 |
571 |
564 row_info->pixel_depth = 16; |
572 row_info->pixel_depth = 16; |
565 } |
573 } |
566 |
574 |
567 else |
575 else |
580 if (row_info->bit_depth == 8) |
588 if (row_info->bit_depth == 8) |
581 { |
589 { |
582 if (at_start != 0) /* Skip initial filler */ |
590 if (at_start != 0) /* Skip initial filler */ |
583 ++sp; |
591 ++sp; |
584 else /* Skip initial channels and, for sp, the filler */ |
592 else /* Skip initial channels and, for sp, the filler */ |
585 sp += 4, dp += 3; |
593 { |
|
594 sp += 4; dp += 3; |
|
595 } |
586 |
596 |
587 /* Note that the loop adds 3 to dp and 4 to sp each time. */ |
597 /* Note that the loop adds 3 to dp and 4 to sp each time. */ |
588 while (sp < ep) |
598 while (sp < ep) |
589 *dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2; |
599 { |
|
600 *dp++ = *sp++; *dp++ = *sp++; *dp++ = *sp; sp += 2; |
|
601 } |
590 |
602 |
591 row_info->pixel_depth = 24; |
603 row_info->pixel_depth = 24; |
592 } |
604 } |
593 |
605 |
594 else if (row_info->bit_depth == 16) |
606 else if (row_info->bit_depth == 16) |
595 { |
607 { |
596 if (at_start != 0) /* Skip initial filler */ |
608 if (at_start != 0) /* Skip initial filler */ |
597 sp += 2; |
609 sp += 2; |
598 else /* Skip initial channels and, for sp, the filler */ |
610 else /* Skip initial channels and, for sp, the filler */ |
599 sp += 8, dp += 6; |
611 { |
|
612 sp += 8; dp += 6; |
|
613 } |
600 |
614 |
601 while (sp < ep) |
615 while (sp < ep) |
602 { |
616 { |
603 /* Copy 6 bytes, skip 2 */ |
617 /* Copy 6 bytes, skip 2 */ |
604 *dp++ = *sp++, *dp++ = *sp++; |
618 *dp++ = *sp++; *dp++ = *sp++; |
605 *dp++ = *sp++, *dp++ = *sp++; |
619 *dp++ = *sp++; *dp++ = *sp++; |
606 *dp++ = *sp++, *dp++ = *sp, sp += 3; |
620 *dp++ = *sp++; *dp++ = *sp; sp += 3; |
607 } |
621 } |
608 |
622 |
609 row_info->pixel_depth = 48; |
623 row_info->pixel_depth = 48; |
610 } |
624 } |
611 |
625 |
621 |
635 |
622 else |
636 else |
623 return; /* The filler channel has gone already */ |
637 return; /* The filler channel has gone already */ |
624 |
638 |
625 /* Fix the rowbytes value. */ |
639 /* Fix the rowbytes value. */ |
626 row_info->rowbytes = (unsigned int)(dp-row); |
640 row_info->rowbytes = (png_size_t)(dp-row); |
627 } |
641 } |
628 #endif |
642 #endif |
629 |
643 |
630 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) |
644 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) |
631 /* Swaps red and blue bytes within a pixel */ |
645 /* Swaps red and blue bytes within a pixel */ |
720 * an 'int' because pixel_depth becomes an 'int' in the expression below, |
734 * an 'int' because pixel_depth becomes an 'int' in the expression below, |
721 * and this calculation is used because it avoids warnings that other |
735 * and this calculation is used because it avoids warnings that other |
722 * forms produced on either GCC or MSVC. |
736 * forms produced on either GCC or MSVC. |
723 */ |
737 */ |
724 int padding = PNG_PADBITS(row_info->pixel_depth, row_info->width); |
738 int padding = PNG_PADBITS(row_info->pixel_depth, row_info->width); |
725 png_bytep rp = png_ptr->row_buf + row_info->rowbytes; |
739 png_bytep rp = png_ptr->row_buf + row_info->rowbytes - 1; |
726 |
740 |
727 switch (row_info->bit_depth) |
741 switch (row_info->bit_depth) |
728 { |
742 { |
729 case 1: |
743 case 1: |
730 { |
744 { |