You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Andreas Lehmkühler (Jira)" <ji...@apache.org> on 2022/03/12 11:13:00 UTC

[jira] [Commented] (PDFBOX-5375) Allow creating of PDFXObjectImage without accessing to the image stream

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

Andreas Lehmkühler commented on PDFBOX-5375:
--------------------------------------------

How about something like this
{code}
### Eclipse Workspace Patch 1.0
#P pdfbox
Index: src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
===================================================================
--- src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java	(Revision 1898440)
+++ src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java	(Arbeitskopie)
@@ -79,6 +79,8 @@
 
     // initialize to MAX_VALUE as we prefer lower subsampling when keeping/replacing cache.
     private int cachedImageSubsampling = Integer.MAX_VALUE;
+    // indicates wether this image has an JPX-based filter applied
+    private boolean hasJPXFilter = false;
 
     /**
      * current resource dictionary (has color spaces)
@@ -142,12 +144,7 @@
         List<COSName> filters = stream.getFilters();
         if (!filters.isEmpty() && COSName.JPX_DECODE.equals(filters.get(filters.size() - 1)))
         {
-            try (COSInputStream is = stream.createInputStream())
-            {
-                DecodeResult decodeResult = is.getDecodeResult();
-                stream.getCOSObject().addAll(decodeResult.getParameters());
-                this.colorSpace = decodeResult.getJPXColorSpace();
-            }
+            hasJPXFilter = true;
         }
     }
 
@@ -780,6 +777,17 @@
     {
         if (colorSpace == null)
         {
+            if (hasJPXFilter)
+            {
+                PDStream stream = getStream();
+                try (COSInputStream is = stream.createInputStream())
+                {
+                    DecodeResult decodeResult = is.getDecodeResult();
+                    stream.getCOSObject().addAll(decodeResult.getParameters());
+                    colorSpace = decodeResult.getJPXColorSpace();
+                    return colorSpace;
+                }
+            }
             COSBase cosBase = getCOSObject().getItem(COSName.COLORSPACE, COSName.CS);
             if (cosBase != null)
             {
{code}

> Allow creating of PDFXObjectImage without accessing to the image stream
> -----------------------------------------------------------------------
>
>                 Key: PDFBOX-5375
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5375
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 2.0.25, 3.0.0 PDFBox
>            Reporter: Thomas Ledoux
>            Priority: Major
>         Attachments: patch.txt, patch2.txt
>
>
> Currently, when a PDF embeds JPEG2000 images, the simple parsing of the file generates a warning
> when the code hits a call to getXObject(name) from a PDResources for a image without creating the
> underlining PDFXObjectImage object, related to the absence of the JAI third-party.
> However, when we just want to access the width or height propertis (which are defined outside the stream in the associated dictionnary).
> Looking at the constructor of PDFXObjectImage, it appears that the image is always read to retrieve the colorspace.
> The proposed patch is moved this initialization to the getColorSpace() method so that the object is created and the Exception will be raised only if the image needs to be really accessed.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org