commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1535081 - in /commons/proper/imaging/trunk/src: changes/changes.xml main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java main/java/org/apache/commons/imaging/formats/jpeg/segments/DhtSegment.java
Date Wed, 23 Oct 2013 17:38:06 GMT
Author: damjan
Date: Wed Oct 23 17:38:06 2013
New Revision: 1535081

URL: http://svn.apache.org/r1535081
Log:
Encapsulate DhtSegment's public mutable arrays.

Jira issue key: IMAGING-115


Modified:
    commons/proper/imaging/trunk/src/changes/changes.xml
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DhtSegment.java

Modified: commons/proper/imaging/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/changes/changes.xml?rev=1535081&r1=1535080&r2=1535081&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/changes/changes.xml (original)
+++ commons/proper/imaging/trunk/src/changes/changes.xml Wed Oct 23 17:38:06 2013
@@ -46,6 +46,9 @@ The <action> type attribute can be add,u
   <body>
 
     <release version="1.0" date="TBA" description="TBA">
+      <action issue="IMAGING-115" dev="damjan" type="fix">
+        DhtSegment class contains mutable public arrays.
+      </action>
       <action issue="IMAGING-117" dev="damjan" type="fix">
         SofnSegment.components - public mutable array.
       </action>

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java?rev=1535081&r1=1535080&r2=1535081&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
Wed Oct 23 17:38:06 2013
@@ -411,13 +411,13 @@ public class JpegDecoder extends BinaryF
         // "DECODE", section F.2.2.3, figure F.16, page 109 of T.81
         int i = 1;
         int code = is.nextBit();
-        while (code > huffmanTable.maxCode[i]) {
+        while (code > huffmanTable.getMaxCode()[i]) {
             i++;
             code = (code << 1) | is.nextBit();
         }
-        int j = huffmanTable.valPtr[i];
-        j += code - huffmanTable.minCode[i];
-        final int value = huffmanTable.huffVal[j];
+        int j = huffmanTable.getValPtr()[i];
+        j += code - huffmanTable.getMinCode()[i];
+        final int value = huffmanTable.getHuffVal()[j];
         return value;
     }
 

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DhtSegment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DhtSegment.java?rev=1535081&r1=1535080&r2=1535081&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DhtSegment.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DhtSegment.java
Wed Oct 23 17:38:06 2013
@@ -19,25 +19,26 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 public class DhtSegment extends Segment {
-    public final List<HuffmanTable> huffmanTables = new ArrayList<HuffmanTable>();
+    public final List<HuffmanTable> huffmanTables;
 
     public static class HuffmanTable {
         // some arrays are better off one-based
         // to avoid subtractions by one later when indexing them
         public final int tableClass;
         public final int destinationIdentifier;
-        public final int[] bits; // 1-based
-        public final int[] huffVal; // 0-based
+        private final int[] bits; // 1-based
+        private final int[] huffVal; // 0-based
 
         // derived properties:
-        public final int[] huffSize = new int[16 * 256]; // 0-based
-        public final int[] huffCode; // 0-based
-        public final int[] minCode = new int[1 + 16]; // 1-based
-        public final int[] maxCode = new int[1 + 16]; // 1-based
-        public final int[] valPtr = new int[1 + 16]; // 1-based
+        private final int[] huffSize = new int[16 * 256]; // 0-based
+        private final int[] huffCode; // 0-based
+        private final int[] minCode = new int[1 + 16]; // 1-based
+        private final int[] maxCode = new int[1 + 16]; // 1-based
+        private final int[] valPtr = new int[1 + 16]; // 1-based
 
         public HuffmanTable(final int tableClass, final int destinationIdentifier,
                 final int[] bits, final int[] huffVal) {
@@ -111,6 +112,34 @@ public class DhtSegment extends Segment 
             }
 
         }
+
+        public int[] getBits() {
+            return bits;
+        }
+
+        public int[] getHuffVal() {
+            return huffVal;
+        }
+
+        public int[] getHuffSize() {
+            return huffSize;
+        }
+
+        public int[] getHuffCode() {
+            return huffCode;
+        }
+
+        public int[] getMinCode() {
+            return minCode;
+        }
+
+        public int[] getMaxCode() {
+            return maxCode;
+        }
+
+        public int[] getValPtr() {
+            return valPtr;
+        }
     }
 
     public DhtSegment(final int marker, final byte[] segmentData) throws IOException {
@@ -121,6 +150,7 @@ public class DhtSegment extends Segment 
             throws IOException {
         super(marker, length);
 
+        final ArrayList<HuffmanTable> huffmanTables = new ArrayList<DhtSegment.HuffmanTable>();
         while (length > 0) {
             final int tableClassAndDestinationId = 0xff & readByte(
                     "TableClassAndDestinationId", is, "Not a Valid JPEG File");
@@ -143,6 +173,7 @@ public class DhtSegment extends Segment 
             huffmanTables.add(new HuffmanTable(tableClass,
                     destinationIdentifier, bits, huffVal));
         }
+        this.huffmanTables = Collections.unmodifiableList(huffmanTables);
     }
 
     @Override



Mime
View raw message