|
33 | 33 | import org.apache.logging.log4j.Logger; |
34 | 34 | import org.apache.logging.log4j.LogManager; |
35 | 35 | import org.apache.pdfbox.cos.COSArray; |
| 36 | +import org.apache.pdfbox.cos.COSBase; |
36 | 37 | import org.apache.pdfbox.cos.COSNumber; |
37 | 38 | import org.apache.pdfbox.filter.DecodeOptions; |
38 | 39 | import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace; |
@@ -741,45 +742,40 @@ private static BufferedImage applyColorKeyMask(BufferedImage image, BufferedImag |
741 | 742 | private static float[] getDecodeArray(PDImage pdImage) throws IOException |
742 | 743 | { |
743 | 744 | final COSArray cosDecode = pdImage.getDecode(); |
744 | | - float[] decode = null; |
745 | 745 |
|
746 | 746 | if (cosDecode != null) |
747 | 747 | { |
748 | 748 | int numberOfComponents = pdImage.getColorSpace().getNumberOfComponents(); |
749 | | - if (cosDecode.size() != numberOfComponents * 2) |
| 749 | + if (cosDecode.size() >= numberOfComponents * 2) |
750 | 750 | { |
751 | | - if (pdImage.isStencil() && cosDecode.size() >= 2 |
752 | | - && cosDecode.get(0) instanceof COSNumber |
753 | | - && cosDecode.get(1) instanceof COSNumber) |
| 751 | + boolean error = false; |
| 752 | + float[] decode = new float[numberOfComponents * 2]; |
| 753 | + for (int i = 0; i < decode.length; ++i) |
754 | 754 | { |
755 | | - float decode0 = ((COSNumber) cosDecode.get(0)).floatValue(); |
756 | | - float decode1 = ((COSNumber) cosDecode.get(1)).floatValue(); |
757 | | - if (decode0 >= 0 && decode0 <= 1 && decode1 >= 0 && decode1 <= 1) |
| 755 | + COSBase base = cosDecode.get(i); |
| 756 | + if (base instanceof COSNumber) |
758 | 757 | { |
759 | | - LOG.warn( |
760 | | - "decode array {} not compatible with color space, using the first two entries", |
761 | | - cosDecode); |
762 | | - return new float[] |
763 | | - { |
764 | | - decode0, decode1 |
765 | | - }; |
| 758 | + decode[i] = ((COSNumber) base).floatValue(); |
| 759 | + } |
| 760 | + else |
| 761 | + { |
| 762 | + error = true; |
| 763 | + break; |
766 | 764 | } |
767 | 765 | } |
768 | | - LOG.error("decode array {} not compatible with color space, using default", |
769 | | - cosDecode); |
770 | | - } |
771 | | - else |
772 | | - { |
773 | | - decode = cosDecode.toFloatArray(); |
| 766 | + if (pdImage.isStencil() && (decode[0] < 0 || decode[0] > 1 || decode[1] < 0 || decode[1] > 1)) |
| 767 | + { |
| 768 | + error = true; |
| 769 | + } |
| 770 | + if (!error) |
| 771 | + { |
| 772 | + return decode; |
| 773 | + } |
774 | 774 | } |
775 | 775 | } |
776 | 776 |
|
777 | 777 | // use color space default |
778 | | - if (decode == null) |
779 | | - { |
780 | | - return pdImage.getColorSpace().getDefaultDecode(pdImage.getBitsPerComponent()); |
781 | | - } |
782 | | - |
783 | | - return decode; |
| 778 | + LOG.error("decode array {} not compatible with color space, using default", cosDecode); |
| 779 | + return pdImage.getColorSpace().getDefaultDecode(pdImage.getBitsPerComponent()); |
784 | 780 | } |
785 | 781 | } |
0 commit comments