pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1759868 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java
Date Thu, 08 Sep 2016 17:28:42 GMT
Author: tilman
Date: Thu Sep  8 17:28:42 2016
New Revision: 1759868

URL: http://svn.apache.org/viewvc?rev=1759868&view=rev
Log:
PDFBOX-3484: cache PDImageXObject if resources are not needed

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java?rev=1759868&r1=1759867&r2=1759868&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java Thu
Sep  8 17:28:42 2016
@@ -409,14 +409,46 @@ public final class PDResources implement
             xobject = PDXObject.createXObject(value, this);
         }
 
-        // we can't cache PDImageXObject, because it holds page resources, see PDFBOX-2370
-        if (cache != null && !(xobject instanceof PDImageXObject))
+        if (cache != null)
         {
-            cache.put(indirect, xobject);
+            if (isAllowedCache(xobject))
+            {
+                cache.put(indirect, xobject);
+            }
         }
         return xobject;
     }
 
+    private boolean isAllowedCache(PDXObject xobject)
+    {
+        if (xobject instanceof PDImageXObject)
+        {
+            COSBase colorSpace = xobject.getCOSObject().getDictionaryObject(COSName.COLORSPACE);
+            if (colorSpace instanceof COSName)
+            {
+                // don't cache if it might use page resources, see PDFBOX-2370 and PDFBOX-3484
+                COSName colorSpaceName = (COSName) colorSpace;
+                if (colorSpaceName.equals(COSName.DEVICECMYK) && hasColorSpace(COSName.DEFAULT_CMYK))
+                {
+                    return false;
+                }
+                if (colorSpaceName.equals(COSName.DEVICERGB) && hasColorSpace(COSName.DEFAULT_RGB))
+                {
+                    return false;
+                }
+                if (colorSpaceName.equals(COSName.DEVICEGRAY) && hasColorSpace(COSName.DEFAULT_GRAY))
+                {
+                    return false;
+                }
+                if (hasColorSpace(colorSpaceName))
+                {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
     /**
      * Returns the resource with the given name and kind as an indirect object, or null.
      */



Mime
View raw message