pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1838334 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
Date Sat, 18 Aug 2018 15:08:25 GMT
Author: tilman
Date: Sat Aug 18 15:08:25 2018
New Revision: 1838334

URL: http://svn.apache.org/viewvc?rev=1838334&view=rev
Log:
PDFBOX-4267: refactor matte extraction into method

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java?rev=1838334&r1=1838333&r2=1838334&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
Sat Aug 18 15:08:25 2018
@@ -447,28 +447,7 @@ public final class PDImageXObject extend
         PDImageXObject softMask = getSoftMask();
         if (softMask != null)
         {
-            COSBase base = softMask.getCOSObject().getItem(COSName.MATTE);
-            float[] matte = null;
-            if (base instanceof COSArray)
-            {
-                // PDFBOX-4267: process /Matte
-                // see PDF specification 1.7, 11.6.5.3 Soft-Mask Images
-                matte = ((COSArray) base).toFloatArray();
-                if (getColorSpace().getNumberOfComponents() == 1 &&
-                    matte.length >= 1)
-                {
-                    // /DeviceGray has only one element in Matte
-                    // See file from PDFBOX-1359, page 14
-                    // Root/Pages/Kids/[2]/Kids/[2]/Resources/XObject/Im1/Resources/XObject/Im0
-                    matte = new float[] { matte[0], matte[0], matte[0] };
-                }
-                if (matte.length != 3)
-                {
-                    LOG.warn("/Matte entry " + Arrays.toString(matte) + 
-                             " for Soft-Mask may not work properly");
-                    matte = Arrays.copyOf(matte, 3);
-                }
-            }
+            float[] matte = extractMatte(softMask);
             image = applyMask(image, softMask.getOpaqueImage(), true, matte);
         }
         else
@@ -492,6 +471,33 @@ public final class PDImageXObject extend
         return image;
     }
 
+    private float[] extractMatte(PDImageXObject softMask) throws IOException
+    {
+        COSBase base = softMask.getCOSObject().getItem(COSName.MATTE);
+        float[] matte = null;
+        if (base instanceof COSArray)
+        {
+            // PDFBOX-4267: process /Matte
+            // see PDF specification 1.7, 11.6.5.3 Soft-Mask Images
+            matte = ((COSArray) base).toFloatArray();
+            if (getColorSpace().getNumberOfComponents() == 1 &&
+                    matte.length >= 1)
+            {
+                // /DeviceGray has only one element in Matte
+                // See file from PDFBOX-1359, page 14
+                // Root/Pages/Kids/[2]/Kids/[2]/Resources/XObject/Im1/Resources/XObject/Im0
+                matte = new float[] { matte[0], matte[0], matte[0] };
+            }
+            if (matte.length != 3)
+            {
+                LOG.warn("/Matte entry " + Arrays.toString(matte) +
+                        " for Soft-Mask may not work properly");
+                matte = Arrays.copyOf(matte, 3);
+            }
+        }
+        return matte;
+    }
+
     /**
      * {@inheritDoc}
      * The returned images are not cached.



Mime
View raw message