[ 
https://issues.apache.org/jira/browse/PDFBOX-2274?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14103682#comment-14103682
 ] 

Dominic Tubach commented on PDFBOX-2274:
----------------------------------------

Yes, you are right. I've now looked why the code works with 1.8, but not 2.0. 
This is what I found out:
The DCT decode filter is removed by the application through setItem() -- that's 
missing in the example code. (Yeah, that's stupid and getFilteredStream() 
should be used.) It worked in 1.8 because the attribute unfilteredStream in 
COSStream is null at that point. However in 2.0 it is not because in
{code}
PDImageXObject(PDStream stream, Map<String, PDColorSpace> colorSpaces)
{code}
getDecodeResult() is called and the stream is decoded then. That's happening 
when getting the XObjects through PDResources. I've not investigated it 
further, but I'm wondering whether it is really necessary to decode the image 
at that point.

Another thing I thought about when looking at the code: Should it be ensured in 
COSStream.setFilters() that unfilteredStream is not null by decoding the stream 
before setting the filter? Otherwise the stream's content is lost and a call of 
getFilteredStream() or getUnfilteredStream() would trigger a 
NullPointerException.

> Decoding issue in PDImageXObject
> --------------------------------
>
>                 Key: PDFBOX-2274
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2274
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 2.0.0
>            Reporter: Dominic Tubach
>
> I'm using JpegFactory to create an PDImageXObject from a content stream. 
> There the constrcutor
> {code}
> PDImageXObject(PDDocument document, InputStream filteredStream, 
>             COSBase cosFilter, int width, int height, int bitsPerComponent, 
>             PDColorSpace initColorSpace)
> {code}
> is used.
> I've found the following issue:
> The method getUnfilteredStream() of the COSStream in the PDImageXObject 
> returns an input stream containing a RandomAccessFileInputStream with
> {{currentPosition = 50814}} and {{endPosition = 1440000}} and my following 
> operation fails.
> If the method doDecode() of the COSStream is called before the filter is set 
> in the COSStream the input stream returned by getUnfilteredStream() contains 
> a RandomAccessFileInputStream with {{currentPosition = 0}} and {{endPosition 
> = 50814}} and the result is as expected.
> I've achieved this by adding
> {code}
> getStream().getStream().getDecodeResult();
> {code}
> before
> {code}
> getCOSStream().setItem(COSName.FILTER, cosFilter);
> {code}
> in the PDImageXObject contructor.



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

Reply via email to