You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2023/05/01 10:51:04 UTC

svn commit: r1909536 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java

Author: tilman
Date: Mon May  1 10:51:04 2023
New Revision: 1909536

URL: http://svn.apache.org/viewvc?rev=1909536&view=rev
Log:
PDFBOX-4892: optimize, as suggested by valerybokov

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java?rev=1909536&r1=1909535&r2=1909536&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java Mon May  1 10:51:04 2023
@@ -93,10 +93,11 @@ public class PDDeviceN extends PDSpecial
         {
             attributes = new PDDeviceNAttributes((COSDictionary)array.getObject(DEVICEN_ATTRIBUTES));
         }
-        initColorConversionCache();
+        List<String> colorantNames = getColorantNames();
+        initColorConversionCache(colorantNames);
 
         // set initial color space
-        int n = getNumberOfComponents();
+        int n = colorantNames.size();
         float[] initial = new float[n];
         for (int i = 0; i < n; i++)
         {
@@ -106,7 +107,7 @@ public class PDDeviceN extends PDSpecial
     }
 
     // initializes the color conversion cache
-    private void initColorConversionCache() throws IOException
+    private void initColorConversionCache(List<String> colorantNames) throws IOException
     {
         // there's nothing to cache for non-attribute spaces
         if (attributes == null)
@@ -115,16 +116,10 @@ public class PDDeviceN extends PDSpecial
         }
 
         // colorant names
-        List<String> colorantNames = getColorantNames();
         numColorants = colorantNames.size();
 
         // process components
         colorantToComponent = new int[numColorants];
-        for (int c = 0; c < numColorants; c++)
-        {
-            colorantToComponent[c] = -1;
-        }
-
         if (attributes.getProcess() != null)
         {
             List<String> components = attributes.getProcess().getComponents();
@@ -138,6 +133,13 @@ public class PDDeviceN extends PDSpecial
             // process color space
             processColorSpace = attributes.getProcess().getColorSpace();
         }
+        else
+        {
+            for (int c = 0; c < numColorants; c++)
+            {
+                colorantToComponent[c] = -1;
+            }
+        }
 
         // spot colorants
         spotColorSpaces = new PDSeparation[numColorants];
@@ -468,7 +470,7 @@ public class PDDeviceN extends PDSpecial
      * Returns the list of colorants.
      * @return the list of colorants
      */
-    public List<String> getColorantNames()
+    public final List<String> getColorantNames()
     {
         COSArray names = (COSArray)array.getObject(COLORANT_NAMES);
         return COSArrayList.convertCOSNameCOSArrayToList(names);