[ 
https://issues.apache.org/jira/browse/PDFBOX-2204?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tilman Hausherr updated PDFBOX-2204:
------------------------------------

    Description: 
I get this with the attached file on page 11:
{code}
java.lang.ArrayIndexOutOfBoundsException: 8296
        at 
org.apache.pdfbox.pdmodel.graphics.image.SampledImageReader.from8bit(SampledImageReader.java:253)
        at 
org.apache.pdfbox.pdmodel.graphics.image.SampledImageReader.getRGBImage(SampledImageReader.java:146)
        at 
org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.getImage(PDImageXObject.java:188)
        at 
org.apache.pdfbox.util.operator.pagedrawer.Invoke.process(Invoke.java:80)
{code}

The problem is in JPXFilter. Per the spec, we must ignore the 
BITS_PER_COMPONENT value from the PDF and use the one from the image. We set 
BITS_PER_COMPONENT to 8 because colorModel.getComponentSize(0) is 8. 
colorModel.getPixelSize() is 4. In "normal" images, the sum of the 
colorModel.getComponentSize() values equals colorModel.getPixelSize().

I'm not sure what to do. I am using this code locally:

{code}
            ColorModel colorModel = image.getColorModel();
            int pixelSize = colorModel.getPixelSize();
            int[] componentSize = colorModel.getComponentSize();
            if (pixelSize < componentSize[0])
            {
                LOG.warn("componentSize[0] of image ignored, because pixelSize 
< componentSize[0]");
                LOG.warn("pixelSize: " + pixelSize);
                LOG.warn("componentSize.length " + componentSize.length);
                for (int i = 0; i < componentSize.length; ++i)
                {
                    LOG.warn("componentSize[" + i + "]: " + componentSize[i]);
                }
            }
            else
            {
                parameters.setInt(COSName.BITS_PER_COMPONENT, componentSize[0]);
            }
{code}
and now the PDF renders properly and the image at the bottom right is almost 
correct. (A circle on the left is missing)



  was:
I get this with the attached file:
{code}
java.lang.ArrayIndexOutOfBoundsException: 8296
        at 
org.apache.pdfbox.pdmodel.graphics.image.SampledImageReader.from8bit(SampledImageReader.java:253)
        at 
org.apache.pdfbox.pdmodel.graphics.image.SampledImageReader.getRGBImage(SampledImageReader.java:146)
        at 
org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.getImage(PDImageXObject.java:188)
        at 
org.apache.pdfbox.util.operator.pagedrawer.Invoke.process(Invoke.java:80)
{code}

The problem is in JPXFilter. Per the spec, we must ignore the 
BITS_PER_COMPONENT value from the PDF and use the one from the image. We set 
BITS_PER_COMPONENT to 8 because colorModel.getComponentSize(0) is 8. 
colorModel.getPixelSize() is 4. In "normal" images, the sum of the 
colorModel.getComponentSize() values equals colorModel.getPixelSize().

I'm not sure what to do. I am using this code locally:

{code}
            ColorModel colorModel = image.getColorModel();
            int pixelSize = colorModel.getPixelSize();
            int[] componentSize = colorModel.getComponentSize();
            if (pixelSize < componentSize[0])
            {
                LOG.warn("componentSize[0] of image ignored, because pixelSize 
< componentSize[0]");
                LOG.warn("pixelSize: " + pixelSize);
                LOG.warn("componentSize.length " + componentSize.length);
                for (int i = 0; i < componentSize.length; ++i)
                {
                    LOG.warn("componentSize[" + i + "]: " + componentSize[i]);
                }
            }
            else
            {
                parameters.setInt(COSName.BITS_PER_COMPONENT, componentSize[0]);
            }
{code}
and now the PDF renders properly and the image at the bottom right is almost 
correct. (A circle on the left is missing)




> java.lang.ArrayIndexOutOfBoundsException in SampledImageReader.from8bit
> -----------------------------------------------------------------------
>
>                 Key: PDFBOX-2204
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2204
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Rendering
>    Affects Versions: 2.0.0
>            Reporter: Tilman Hausherr
>              Labels: JPEG2000, JPXDecode, JPXFilter
>         Attachments: PDFBOX-2204-012411.pdf
>
>
> I get this with the attached file on page 11:
> {code}
> java.lang.ArrayIndexOutOfBoundsException: 8296
>       at 
> org.apache.pdfbox.pdmodel.graphics.image.SampledImageReader.from8bit(SampledImageReader.java:253)
>       at 
> org.apache.pdfbox.pdmodel.graphics.image.SampledImageReader.getRGBImage(SampledImageReader.java:146)
>       at 
> org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.getImage(PDImageXObject.java:188)
>       at 
> org.apache.pdfbox.util.operator.pagedrawer.Invoke.process(Invoke.java:80)
> {code}
> The problem is in JPXFilter. Per the spec, we must ignore the 
> BITS_PER_COMPONENT value from the PDF and use the one from the image. We set 
> BITS_PER_COMPONENT to 8 because colorModel.getComponentSize(0) is 8. 
> colorModel.getPixelSize() is 4. In "normal" images, the sum of the 
> colorModel.getComponentSize() values equals colorModel.getPixelSize().
> I'm not sure what to do. I am using this code locally:
> {code}
>             ColorModel colorModel = image.getColorModel();
>             int pixelSize = colorModel.getPixelSize();
>             int[] componentSize = colorModel.getComponentSize();
>             if (pixelSize < componentSize[0])
>             {
>                 LOG.warn("componentSize[0] of image ignored, because 
> pixelSize < componentSize[0]");
>                 LOG.warn("pixelSize: " + pixelSize);
>                 LOG.warn("componentSize.length " + componentSize.length);
>                 for (int i = 0; i < componentSize.length; ++i)
>                 {
>                     LOG.warn("componentSize[" + i + "]: " + componentSize[i]);
>                 }
>             }
>             else
>             {
>                 parameters.setInt(COSName.BITS_PER_COMPONENT, 
> componentSize[0]);
>             }
> {code}
> and now the PDF renders properly and the image at the bottom right is almost 
> correct. (A circle on the left is missing)



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to