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 2019/08/22 03:49:37 UTC

svn commit: r1865667 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java

Author: tilman
Date: Thu Aug 22 03:49:37 2019
New Revision: 1865667

URL: http://svn.apache.org/viewvc?rev=1865667&view=rev
Log:
PDFBOX-4071: SonarQube fix: move methods into class

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java?rev=1865667&r1=1865666&r2=1865667&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java Thu Aug 22 03:49:37 2019
@@ -100,51 +100,6 @@ public class PDFunctionType0 extends PDF
     }
 
     /**
-     * Get all sample values of this function.
-     * 
-     * @return an array with all samples.
-     */
-    private int[][] getSamples()
-    {
-        if (samples == null)
-        {
-            int arraySize = 1;
-            int numberOfInputValues = getNumberOfInputParameters();
-            int numberOfOutputValues = getNumberOfOutputParameters();
-            COSArray sizes = getSize();
-            for (int i = 0; i < numberOfInputValues; i++)
-            {
-                arraySize *= sizes.getInt(i);
-            }
-            samples = new int[arraySize][numberOfOutputValues];
-            int bitsPerSample = getBitsPerSample();
-            int index = 0;
-            try
-            {
-                // PDF spec 1.7 p.171:
-                // Each sample value is represented as a sequence of BitsPerSample bits. 
-                // Successive values are adjacent in the bit stream; there is no padding at byte boundaries.
-                ImageInputStream mciis = new MemoryCacheImageInputStream(getPDStream().createInputStream());
-                for (int i = 0; i < arraySize; i++)
-                {
-                    for (int k = 0; k < numberOfOutputValues; k++)
-                    {
-                        // TODO will this cast work properly for 32 bitsPerSample or should we use long[]?
-                        samples[index][k] = (int) mciis.readBits(bitsPerSample); 
-                    }
-                    index++;
-                }
-                mciis.close();
-            }
-            catch (IOException exception)
-            {
-                LOG.error("IOException while reading the sample values of this function.", exception);
-            }
-        }
-        return samples;
-    }
-
-    /**
      * Get the number of bits that the output value will take up.  
      * 
      * Valid values are 1,2,4,8,12,16,24,32.
@@ -283,36 +238,6 @@ public class PDFunctionType0 extends PDF
     }
     
     /**
-     * calculate array index (structure described in p.171 PDF spec 1.7) in
-     * multiple dimensions.
-     *
-     * @param vector with coordinates
-     * @return index in flat array
-     */
-    private int calcSampleIndex(int[] vector)
-    {
-        // inspiration: http://stackoverflow.com/a/12113479/535646
-        // but used in reverse
-        float[] sizeValues = getSize().toFloatArray();
-        int index = 0;
-        int sizeProduct = 1;
-        int dimension = vector.length;
-        for (int i = dimension - 2; i >= 0; --i)
-        {
-            sizeProduct *= sizeValues[i];
-        }
-        for (int i = dimension - 1; i >= 0; --i)
-        {
-            index += sizeProduct * vector[i];
-            if (i - 1 >= 0)
-            {
-                sizeProduct /= sizeValues[i - 1];
-            }
-        }
-        return index;
-    }
-
-    /**
      * Inner class do to an interpolation in the Nth dimension by comparing the
      * content size of N-1 dimensional objects. This is done with the help of
      * recursive calls. To understand the algorithm without recursion, here is a
@@ -414,6 +339,80 @@ public class PDFunctionType0 extends PDF
                 return resultSample;
             }
         }
+
+        /**
+         * calculate array index (structure described in p.171 PDF spec 1.7) in multiple dimensions.
+         *
+         * @param vector with coordinates
+         * @return index in flat array
+         */
+        private int calcSampleIndex(int[] vector)
+        {
+            // inspiration: http://stackoverflow.com/a/12113479/535646
+            // but used in reverse
+            float[] sizeValues = getSize().toFloatArray();
+            int index = 0;
+            int sizeProduct = 1;
+            int dimension = vector.length;
+            for (int i = dimension - 2; i >= 0; --i)
+            {
+                sizeProduct *= sizeValues[i];
+            }
+            for (int i = dimension - 1; i >= 0; --i)
+            {
+                index += sizeProduct * vector[i];
+                if (i - 1 >= 0)
+                {
+                    sizeProduct /= sizeValues[i - 1];
+                }
+            }
+            return index;
+        }
+
+        /**
+         * Get all sample values of this function.
+         *
+         * @return an array with all samples.
+         */
+        private int[][] getSamples()
+        {
+            if (samples == null)
+            {
+                int arraySize = 1;
+                int nIn = getNumberOfInputParameters();
+                int nOut = getNumberOfOutputParameters();
+                COSArray sizes = getSize();
+                for (int i = 0; i < nIn; i++)
+                {
+                    arraySize *= sizes.getInt(i);
+                }
+                samples = new int[arraySize][nOut];
+                int bitsPerSample = getBitsPerSample();
+                int index = 0;
+                try
+                {
+                    // PDF spec 1.7 p.171:
+                    // Each sample value is represented as a sequence of BitsPerSample bits. 
+                    // Successive values are adjacent in the bit stream; there is no padding at byte boundaries.
+                    ImageInputStream mciis = new MemoryCacheImageInputStream(getPDStream().createInputStream());
+                    for (int i = 0; i < arraySize; i++)
+                    {
+                        for (int k = 0; k < nOut; k++)
+                        {
+                            // TODO will this cast work properly for 32 bitsPerSample or should we use long[]?
+                            samples[index][k] = (int) mciis.readBits(bitsPerSample);
+                        }
+                        index++;
+                    }
+                    mciis.close();
+                }
+                catch (IOException exception)
+                {
+                    LOG.error("IOException while reading the sample values of this function.", exception);
+                }
+            }
+            return samples;
+        }
     }
 
     /**