Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BE5D8109F4 for ; Wed, 23 Oct 2013 17:42:43 +0000 (UTC) Received: (qmail 35747 invoked by uid 500); 23 Oct 2013 17:39:02 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 35645 invoked by uid 500); 23 Oct 2013 17:38:49 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 35525 invoked by uid 99); 23 Oct 2013 17:38:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Oct 2013 17:38:29 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Oct 2013 17:38:28 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id B177E238889B; Wed, 23 Oct 2013 17:38:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: damjan@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131023173806.B177E238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 type attribute can be add,u + + DhtSegment class contains mutable public arrays. + SofnSegment.components - public mutable array. 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 huffmanTables = new ArrayList(); + public final List 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 huffmanTables = new ArrayList(); 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