pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1865664 - /pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java
Date Thu, 22 Aug 2019 03:49:22 GMT
Author: tilman
Date: Thu Aug 22 03:49:22 2019
New Revision: 1865664

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

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

Modified: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java?rev=1865664&r1=1865663&r2=1865664&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java
(original)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java
Thu Aug 22 03:49:22 2019
@@ -100,52 +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.
-                try (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++;
-                    }
-                }
-            }
-            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.
@@ -282,36 +236,6 @@ public class PDFunctionType0 extends PDF
         decode = decodeValues;
         getCOSObject().setItem(COSName.DECODE, decodeValues);
     }
-    
-    /**
-     * 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
@@ -415,6 +339,81 @@ 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.
+                    try (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++;
+                        }
+                    }
+                }
+                catch (IOException exception)
+                {
+                    LOG.error("IOException while reading the sample values of this function.",
exception);
+                }
+            }
+            return samples;
+        }
     }
 
     /**



Mime
View raw message