http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/EncodedTable.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/EncodedTable.java b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/EncodedTable.java index 77e71c6..a8529ab 100644 --- a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/EncodedTable.java +++ b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/EncodedTable.java @@ -27,65 +27,69 @@ import org.apache.pdfbox.jbig2.segments.Table; /** * This class represents a encoded huffman table. */ -public class EncodedTable extends HuffmanTable { +public class EncodedTable extends HuffmanTable +{ - private Table table; + private Table table; - public EncodedTable(Table table) throws IOException { - this.table = table; - parseTable(); - } + public EncodedTable(Table table) throws IOException + { + this.table = table; + parseTable(); + } - public void parseTable() throws IOException { + public void parseTable() throws IOException + { - SubInputStream sis = table.getSubInputStream(); + SubInputStream sis = table.getSubInputStream(); - List<Code> codeTable = new ArrayList<Code>(); + List<Code> codeTable = new ArrayList<Code>(); - int prefLen, rangeLen, rangeLow; - int curRangeLow = table.getHtLow(); + int prefLen, rangeLen, rangeLow; + int curRangeLow = table.getHtLow(); - /* Annex B.2 5) - decode table lines */ - while (curRangeLow < table.getHtHigh()) { - prefLen = (int) sis.readBits(table.getHtPS()); - rangeLen = (int) sis.readBits(table.getHtRS()); - rangeLow = curRangeLow; + /* Annex B.2 5) - decode table lines */ + while (curRangeLow < table.getHtHigh()) + { + prefLen = (int) sis.readBits(table.getHtPS()); + rangeLen = (int) sis.readBits(table.getHtRS()); + rangeLow = curRangeLow; - codeTable.add(new Code(prefLen, rangeLen, rangeLow, false)); + codeTable.add(new Code(prefLen, rangeLen, rangeLow, false)); - curRangeLow += 1 << rangeLen; - } + curRangeLow += 1 << rangeLen; + } - /* Annex B.2 6) */ - prefLen = (int) sis.readBits(table.getHtPS()); - - /* - * Annex B.2 7) - lower range table line - * - * Made some correction. Spec specifies an incorrect variable -> Replaced highPrefLen with - * lowPrefLen - */ - rangeLen = 32; - rangeLow = table.getHtHigh() - 1; - codeTable.add(new Code(prefLen, rangeLen, rangeLow, true)); - // } - - /* Annex B.2 8) */ - prefLen = (int) sis.readBits(table.getHtPS()); - - /* Annex B.2 9) - upper range table line */ - rangeLen = 32; - rangeLow = table.getHtHigh(); - codeTable.add(new Code(prefLen, rangeLen, rangeLow, false)); - - /* Annex B.2 10) - out-of-band table line */ - if (table.getHtOOB() == 1) { - prefLen = (int) sis.readBits(table.getHtPS()); - codeTable.add(new Code(prefLen, -1, -1, false)); - } + /* Annex B.2 6) */ + prefLen = (int) sis.readBits(table.getHtPS()); + + /* + * Annex B.2 7) - lower range table line + * + * Made some correction. Spec specifies an incorrect variable -> Replaced highPrefLen with lowPrefLen + */ + rangeLen = 32; + rangeLow = table.getHtHigh() - 1; + codeTable.add(new Code(prefLen, rangeLen, rangeLow, true)); + // } - System.out.println(codeTableToString(codeTable)); + /* Annex B.2 8) */ + prefLen = (int) sis.readBits(table.getHtPS()); - initTree(codeTable); - } -} \ No newline at end of file + /* Annex B.2 9) - upper range table line */ + rangeLen = 32; + rangeLow = table.getHtHigh(); + codeTable.add(new Code(prefLen, rangeLen, rangeLow, false)); + + /* Annex B.2 10) - out-of-band table line */ + if (table.getHtOOB() == 1) + { + prefLen = (int) sis.readBits(table.getHtPS()); + codeTable.add(new Code(prefLen, -1, -1, false)); + } + + System.out.println(codeTableToString(codeTable)); + + initTree(codeTable); + } +}
http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/FixedSizeTable.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/FixedSizeTable.java b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/FixedSizeTable.java index b6f8822..d8f6ddb 100644 --- a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/FixedSizeTable.java +++ b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/FixedSizeTable.java @@ -22,8 +22,10 @@ import java.util.List; /** * This class represents a fixed size huffman table. */ -public class FixedSizeTable extends HuffmanTable { - public FixedSizeTable(List<Code> runCodeTable) { - initTree(runCodeTable); - } +public class FixedSizeTable extends HuffmanTable +{ + public FixedSizeTable(List<Code> runCodeTable) + { + initTree(runCodeTable); + } } http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/HuffmanTable.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/HuffmanTable.java b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/HuffmanTable.java index 1e0f661..c4fd265 100644 --- a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/HuffmanTable.java +++ b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/HuffmanTable.java @@ -27,91 +27,107 @@ import org.apache.pdfbox.jbig2.JBIG2ImageReader; /** * This abstract class is the base class for all types of huffman tables. */ -public abstract class HuffmanTable { - - /** - * This static class represents a code for use in huffman tables. - */ - public static class Code { - final int prefixLength; - final int rangeLength; - final int rangeLow; - final boolean isLowerRange; - int code = -1; - - public Code(int prefixLength, int rangeLength, int rangeLow, boolean isLowerRange) { - this.prefixLength = prefixLength; - this.rangeLength = rangeLength; - this.rangeLow = rangeLow; - this.isLowerRange = isLowerRange; - } +public abstract class HuffmanTable +{ + + /** + * This static class represents a code for use in huffman tables. + */ + public static class Code + { + final int prefixLength; + final int rangeLength; + final int rangeLow; + final boolean isLowerRange; + int code = -1; + + public Code(int prefixLength, int rangeLength, int rangeLow, boolean isLowerRange) + { + this.prefixLength = prefixLength; + this.rangeLength = rangeLength; + this.rangeLow = rangeLow; + this.isLowerRange = isLowerRange; + } - @Override - public String toString() { - return (code != -1 ? ValueNode.bitPattern(code, prefixLength) : "?") + "/" + prefixLength + "/" + rangeLength - + "/" + rangeLow; + @Override + public String toString() + { + return (code != -1 ? ValueNode.bitPattern(code, prefixLength) : "?") + "/" + + prefixLength + "/" + rangeLength + "/" + rangeLow; + } } - } - private InternalNode rootNode = new InternalNode(); + private InternalNode rootNode = new InternalNode(); - public void initTree(List<Code> codeTable) { - preprocessCodes(codeTable); + public void initTree(List<Code> codeTable) + { + preprocessCodes(codeTable); - for (Code c : codeTable) { - rootNode.append(c); + for (Code c : codeTable) + { + rootNode.append(c); + } } - } - public long decode(ImageInputStream iis) throws IOException { - return rootNode.decode(iis); - } - - @Override - public String toString() { - return rootNode + "\n"; - } - - public static String codeTableToString(List<Code> codeTable) { - StringBuilder sb = new StringBuilder(); + public long decode(ImageInputStream iis) throws IOException + { + return rootNode.decode(iis); + } - for (Code c : codeTable) { - sb.append(c.toString()).append("\n"); + @Override + public String toString() + { + return rootNode + "\n"; } - return sb.toString(); - } + public static String codeTableToString(List<Code> codeTable) + { + StringBuilder sb = new StringBuilder(); - private void preprocessCodes(List<Code> codeTable) { - /* Annex B.3 1) - build the histogram */ - int maxPrefixLength = 0; + for (Code c : codeTable) + { + sb.append(c.toString()).append("\n"); + } - for (Code c : codeTable) { - maxPrefixLength = Math.max(maxPrefixLength, c.prefixLength); + return sb.toString(); } - int lenCount[] = new int[maxPrefixLength + 1]; - for (Code c : codeTable) { - lenCount[c.prefixLength]++; - } + private void preprocessCodes(List<Code> codeTable) + { + /* Annex B.3 1) - build the histogram */ + int maxPrefixLength = 0; - int curCode; - int firstCode[] = new int[lenCount.length + 1]; - lenCount[0] = 0; - - /* Annex B.3 3) */ - for (int curLen = 1; curLen <= lenCount.length; curLen++) { - firstCode[curLen] = (firstCode[curLen - 1] + (lenCount[curLen - 1]) << 1); - curCode = firstCode[curLen]; - for (Code code : codeTable) { - if (code.prefixLength == curLen) { - code.code = curCode; - curCode++; + for (Code c : codeTable) + { + maxPrefixLength = Math.max(maxPrefixLength, c.prefixLength); + } + + int lenCount[] = new int[maxPrefixLength + 1]; + for (Code c : codeTable) + { + lenCount[c.prefixLength]++; + } + + int curCode; + int firstCode[] = new int[lenCount.length + 1]; + lenCount[0] = 0; + + /* Annex B.3 3) */ + for (int curLen = 1; curLen <= lenCount.length; curLen++) + { + firstCode[curLen] = (firstCode[curLen - 1] + (lenCount[curLen - 1]) << 1); + curCode = firstCode[curLen]; + for (Code code : codeTable) + { + if (code.prefixLength == curLen) + { + code.code = curCode; + curCode++; + } + } } - } - } - if (JBIG2ImageReader.DEBUG) - System.out.println(codeTableToString(codeTable)); - } + if (JBIG2ImageReader.DEBUG) + System.out.println(codeTableToString(codeTable)); + } } http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/InternalNode.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/InternalNode.java b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/InternalNode.java index ea4a4dd..e99c780 100644 --- a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/InternalNode.java +++ b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/InternalNode.java @@ -27,93 +27,115 @@ import org.apache.pdfbox.jbig2.decoder.huffman.HuffmanTable.Code; /** * This class represents an internal node of a huffman tree. It contains two child nodes. */ -class InternalNode extends Node { - private final int depth; - - private Node zero; - private Node one; - - protected InternalNode() { - depth = 0; - } - - protected InternalNode(int depth) { - this.depth = depth; - } - - protected void append(Code c) { - if (JBIG2ImageReader.DEBUG) - System.out.println("I'm working on " + c.toString()); - - // ignore unused codes - if (c.prefixLength == 0) - return; - - int shift = c.prefixLength - 1 - depth; - - if (shift < 0) - throw new IllegalArgumentException("Negative shifting is not possible."); - - int bit = (c.code >> shift) & 1; - if (shift == 0) { - if (c.rangeLength == -1) { - // the child will be a OutOfBand - if (bit == 1) { - if (one != null) - throw new IllegalStateException("already have a OOB for " + c); - one = new OutOfBandNode(c); - } else { - if (zero != null) - throw new IllegalStateException("already have a OOB for " + c); - zero = new OutOfBandNode(c); +class InternalNode extends Node +{ + private final int depth; + + private Node zero; + private Node one; + + protected InternalNode() + { + depth = 0; + } + + protected InternalNode(int depth) + { + this.depth = depth; + } + + protected void append(Code c) + { + if (JBIG2ImageReader.DEBUG) + System.out.println("I'm working on " + c.toString()); + + // ignore unused codes + if (c.prefixLength == 0) + return; + + int shift = c.prefixLength - 1 - depth; + + if (shift < 0) + throw new IllegalArgumentException("Negative shifting is not possible."); + + int bit = (c.code >> shift) & 1; + if (shift == 0) + { + if (c.rangeLength == -1) + { + // the child will be a OutOfBand + if (bit == 1) + { + if (one != null) + throw new IllegalStateException("already have a OOB for " + c); + one = new OutOfBandNode(c); + } + else + { + if (zero != null) + throw new IllegalStateException("already have a OOB for " + c); + zero = new OutOfBandNode(c); + } + } + else + { + // the child will be a ValueNode + if (bit == 1) + { + if (one != null) + throw new IllegalStateException("already have a ValueNode for " + c); + one = new ValueNode(c); + } + else + { + if (zero != null) + throw new IllegalStateException("already have a ValueNode for " + c); + zero = new ValueNode(c); + } + } } - } else { - // the child will be a ValueNode - if (bit == 1) { - if (one != null) - throw new IllegalStateException("already have a ValueNode for " + c); - one = new ValueNode(c); - } else { - if (zero != null) - throw new IllegalStateException("already have a ValueNode for " + c); - zero = new ValueNode(c); + else + { + // the child will be an InternalNode + if (bit == 1) + { + if (one == null) + one = new InternalNode(depth + 1); + ((InternalNode) one).append(c); + } + else + { + if (zero == null) + zero = new InternalNode(depth + 1); + ((InternalNode) zero).append(c); + } } - } - } else { - // the child will be an InternalNode - if (bit == 1) { - if (one == null) - one = new InternalNode(depth + 1); - ((InternalNode) one).append(c); - } else { - if (zero == null) - zero = new InternalNode(depth + 1); - ((InternalNode) zero).append(c); - } } - } - - @Override - protected long decode(ImageInputStream iis) throws IOException { - int b = iis.readBit(); - Node n = b == 0 ? zero : one; - return n.decode(iis); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("\n"); - - pad(sb); - sb.append("0: ").append(zero).append("\n"); - pad(sb); - sb.append("1: ").append(one).append("\n"); - - return sb.toString(); - } - - private void pad(StringBuilder sb) { - for (int i = 0; i < depth; i++) - sb.append(" "); - } + + @Override + protected long decode(ImageInputStream iis) throws IOException + { + int b = iis.readBit(); + Node n = b == 0 ? zero : one; + return n.decode(iis); + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder("\n"); + + pad(sb); + sb.append("0: ").append(zero).append("\n"); + pad(sb); + sb.append("1: ").append(one).append("\n"); + + return sb.toString(); + } + + private void pad(StringBuilder sb) + { + for (int i = 0; i < depth; i++) + sb.append(" "); + } } http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/Node.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/Node.java b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/Node.java index 1adbf8c..79fd7d6 100644 --- a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/Node.java +++ b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/Node.java @@ -24,6 +24,7 @@ import javax.imageio.stream.ImageInputStream; /** * Base class for all nodes in a huffman tree. */ -abstract class Node { - protected abstract long decode(ImageInputStream iis) throws IOException; +abstract class Node +{ + protected abstract long decode(ImageInputStream iis) throws IOException; } http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/OutOfBandNode.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/OutOfBandNode.java b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/OutOfBandNode.java index c379c89..690ab32 100644 --- a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/OutOfBandNode.java +++ b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/OutOfBandNode.java @@ -23,18 +23,20 @@ import javax.imageio.stream.ImageInputStream; import org.apache.pdfbox.jbig2.decoder.huffman.HuffmanTable.Code; - /** * Represents a out of band node in a huffman tree. */ -class OutOfBandNode extends Node { - - protected OutOfBandNode(Code c) { - } - - @Override - protected long decode(ImageInputStream iis) throws IOException { - return Long.MAX_VALUE; - } +class OutOfBandNode extends Node +{ + + protected OutOfBandNode(Code c) + { + } + + @Override + protected long decode(ImageInputStream iis) throws IOException + { + return Long.MAX_VALUE; + } } http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/StandardTables.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/StandardTables.java b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/StandardTables.java index 70452b8..f865ec9 100644 --- a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/StandardTables.java +++ b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/StandardTables.java @@ -22,256 +22,261 @@ import java.util.List; import org.apache.pdfbox.jbig2.*; -public class StandardTables { - static class StandardTable extends HuffmanTable { - private StandardTable(int table[][]) { +public class StandardTables +{ + static class StandardTable extends HuffmanTable + { + private StandardTable(int table[][]) + { - List<Code> codeTable = new ArrayList<Code>(); + List<Code> codeTable = new ArrayList<Code>(); - for (int i = 0; i < table.length; i++) { - int prefixLength = table[i][0]; - int rangeLength = table[i][1]; - int rangeLow = table[i][2]; - boolean isLowerRange = false; - if (table[i].length > 3) - isLowerRange = true; - codeTable.add(new Code(prefixLength, rangeLength, rangeLow, - isLowerRange)); - } + for (int i = 0; i < table.length; i++) + { + int prefixLength = table[i][0]; + int rangeLength = table[i][1]; + int rangeLow = table[i][2]; + boolean isLowerRange = false; + if (table[i].length > 3) + isLowerRange = true; + codeTable.add(new Code(prefixLength, rangeLength, rangeLow, isLowerRange)); + } - if (JBIG2ImageReader.DEBUG) - System.out.println(HuffmanTable.codeTableToString(codeTable)); + if (JBIG2ImageReader.DEBUG) + System.out.println(HuffmanTable.codeTableToString(codeTable)); - initTree(codeTable); - } - } + initTree(codeTable); + } + } - // Fourth Value (999) is used for the LowerRange-line - private static final int TABLES[][][] = { - // B1 - { { 1, 4, 0 }, // - { 2, 8, 16 }, // - { 3, 16, 272 }, // - { 3, 32, 65808 } /* high */ - }, - // B2 - { { 1, 0, 0 }, // - { 2, 0, 1 }, // - { 3, 0, 2 }, // - { 4, 3, 3 }, // - { 5, 6, 11 }, // - { 6, 32, 75 }, /* high */ - { 6, -1, 0 } /* OOB */ - }, - // B3 - { { 8, 8, -256 }, // - { 1, 0, 0 }, // - { 2, 0, 1 }, // - { 3, 0, 2 }, // - { 4, 3, 3 }, // - { 5, 6, 11 }, // - { 8, 32, -257, 999 }, /* low */ - { 7, 32, 75 }, /* high */ - { 6, -1, 0 } /* OOB */ - }, - // B4 - { { 1, 0, 1 }, // - { 2, 0, 2 }, // - { 3, 0, 3 }, // - { 4, 3, 4 }, // - { 5, 6, 12 }, // - { 5, 32, 76 } /* high */ - }, - // B5 - { { 7, 8, -255 }, // - { 1, 0, 1 }, // - { 2, 0, 2 }, // - { 3, 0, 3 }, // - { 4, 3, 4 }, // - { 5, 6, 12 }, // - { 7, 32, -256, 999 }, /* low */ - { 6, 32, 76 } /* high */ - }, - // B6 - { { 5, 10, -2048 }, // - { 4, 9, -1024 }, // - { 4, 8, -512 }, // - { 4, 7, -256 }, // - { 5, 6, -128 }, // - { 5, 5, -64 }, // - { 4, 5, -32 }, // - { 2, 7, 0 }, // - { 3, 7, 128 }, // - { 3, 8, 256 }, // - { 4, 9, 512 }, // - { 4, 10, 1024 }, // - { 6, 32, -2049, 999 }, /* low */ - { 6, 32, 2048 } /* high */ - }, - // B7 - { { 4, 9, -1024 }, // - { 3, 8, -512 }, // - { 4, 7, -256 }, // - { 5, 6, -128 }, // - { 5, 5, -64 }, // - { 4, 5, -32 }, // - { 4, 5, 0 }, // - { 5, 5, 32 }, // - { 5, 6, 64 }, // - { 4, 7, 128 }, // - { 3, 8, 256 }, // - { 3, 9, 512 }, // - { 3, 10, 1024 }, // - { 5, 32, -1025, 999 }, /* low */ - { 5, 32, 2048 } /* high */ - }, - // B8 - { { 8, 3, -15 }, // - { 9, 1, -7 }, // - { 8, 1, -5 }, // - { 9, 0, -3 }, // - { 7, 0, -2 }, // - { 4, 0, -1 }, // - { 2, 1, 0 }, // - { 5, 0, 2 }, // - { 6, 0, 3 }, // - { 3, 4, 4 }, // - { 6, 1, 20 }, // - { 4, 4, 22 }, // - { 4, 5, 38 }, // - { 5, 6, 70 }, // - { 5, 7, 134 }, // - { 6, 7, 262 }, // - { 7, 8, 390 }, // - { 6, 10, 646 }, // - { 9, 32, -16, 999 }, /* low */ - { 9, 32, 1670 }, /* high */ - { 2, -1, 0 } /* OOB */ - }, - // B9 - { { 8, 4, -31 }, // - { 9, 2, -15 }, // - { 8, 2, -11 }, // - { 9, 1, -7 }, // - { 7, 1, -5 }, // - { 4, 1, -3 }, // - { 3, 1, -1 }, // - { 3, 1, 1 }, // - { 5, 1, 3 }, // - { 6, 1, 5 }, // - { 3, 5, 7 }, // - { 6, 2, 39 }, // - { 4, 5, 43 }, // - { 4, 6, 75 }, // - { 5, 7, 139 }, // - { 5, 8, 267 }, // - { 6, 8, 523 }, // - { 7, 9, 779 }, // - { 6, 11, 1291 }, // - { 9, 32, -32, 999 }, /* low */ - { 9, 32, 3339 }, /* high */ - { 2, -1, 0 } /* OOB */ - }, - // B10 - { { 7, 4, -21 }, // - { 8, 0, -5 }, // - { 7, 0, -4 }, // - { 5, 0, -3 }, // - { 2, 2, -2 }, // - { 5, 0, 2 }, // - { 6, 0, 3 }, // - { 7, 0, 4 }, // - { 8, 0, 5 }, // - { 2, 6, 6 }, // - { 5, 5, 70 }, // - { 6, 5, 102 }, // - { 6, 6, 134 }, // - { 6, 7, 198 }, // - { 6, 8, 326 }, // - { 6, 9, 582 }, // - { 6, 10, 1094 }, // - { 7, 11, 2118 }, // - { 8, 32, -22, 999 }, /* low */ - { 8, 32, 4166 }, /* high */ - { 2, -1, 0 } /* OOB */ - }, - // B11 - { { 1, 0, 1 }, // - { 2, 1, 2 }, // - { 4, 0, 4 }, // - { 4, 1, 5 }, // - { 5, 1, 7 }, // - { 5, 2, 9 }, // - { 6, 2, 13 }, // - { 7, 2, 17 }, // - { 7, 3, 21 }, // - { 7, 4, 29 }, // - { 7, 5, 45 }, // - { 7, 6, 77 }, // - { 7, 32, 141 } /* high */ - }, - // B12 - { { 1, 0, 1 }, // - { 2, 0, 2 }, // - { 3, 1, 3 }, // - { 5, 0, 5 }, // - { 5, 1, 6 }, // - { 6, 1, 8 }, // - { 7, 0, 10 }, // - { 7, 1, 11 }, // - { 7, 2, 13 }, // - { 7, 3, 17 }, // - { 7, 4, 25 }, // - { 8, 5, 41 }, // - { 8, 32, 73 } // - }, - // B13 - { { 1, 0, 1 }, // - { 3, 0, 2 }, // - { 4, 0, 3 }, // - { 5, 0, 4 }, // - { 4, 1, 5 }, // - { 3, 3, 7 }, // - { 6, 1, 15 }, // - { 6, 2, 17 }, // - { 6, 3, 21 }, // - { 6, 4, 29 }, // - { 6, 5, 45 }, // - { 7, 6, 77 }, // - { 7, 32, 141 } /* high */ - }, - // B14 - { { 3, 0, -2 }, // - { 3, 0, -1 }, // - { 1, 0, 0 }, // - { 3, 0, 1 }, // - { 3, 0, 2 } // - }, - // B15 - { { 7, 4, -24 }, // - { 6, 2, -8 }, // - { 5, 1, -4 }, // - { 4, 0, -2 }, // - { 3, 0, -1 }, // - { 1, 0, 0 }, // - { 3, 0, 1 }, // - { 4, 0, 2 }, // - { 5, 1, 3 }, // - { 6, 2, 5 }, // - { 7, 4, 9 }, // - { 7, 32, -25, 999 }, /* low */ - { 7, 32, 25 } /* high */ - } }; + // Fourth Value (999) is used for the LowerRange-line + private static final int TABLES[][][] = { + // B1 + { { 1, 4, 0 }, // + { 2, 8, 16 }, // + { 3, 16, 272 }, // + { 3, 32, 65808 } /* high */ + }, + // B2 + { { 1, 0, 0 }, // + { 2, 0, 1 }, // + { 3, 0, 2 }, // + { 4, 3, 3 }, // + { 5, 6, 11 }, // + { 6, 32, 75 }, /* high */ + { 6, -1, 0 } /* OOB */ + }, + // B3 + { { 8, 8, -256 }, // + { 1, 0, 0 }, // + { 2, 0, 1 }, // + { 3, 0, 2 }, // + { 4, 3, 3 }, // + { 5, 6, 11 }, // + { 8, 32, -257, 999 }, /* low */ + { 7, 32, 75 }, /* high */ + { 6, -1, 0 } /* OOB */ + }, + // B4 + { { 1, 0, 1 }, // + { 2, 0, 2 }, // + { 3, 0, 3 }, // + { 4, 3, 4 }, // + { 5, 6, 12 }, // + { 5, 32, 76 } /* high */ + }, + // B5 + { { 7, 8, -255 }, // + { 1, 0, 1 }, // + { 2, 0, 2 }, // + { 3, 0, 3 }, // + { 4, 3, 4 }, // + { 5, 6, 12 }, // + { 7, 32, -256, 999 }, /* low */ + { 6, 32, 76 } /* high */ + }, + // B6 + { { 5, 10, -2048 }, // + { 4, 9, -1024 }, // + { 4, 8, -512 }, // + { 4, 7, -256 }, // + { 5, 6, -128 }, // + { 5, 5, -64 }, // + { 4, 5, -32 }, // + { 2, 7, 0 }, // + { 3, 7, 128 }, // + { 3, 8, 256 }, // + { 4, 9, 512 }, // + { 4, 10, 1024 }, // + { 6, 32, -2049, 999 }, /* low */ + { 6, 32, 2048 } /* high */ + }, + // B7 + { { 4, 9, -1024 }, // + { 3, 8, -512 }, // + { 4, 7, -256 }, // + { 5, 6, -128 }, // + { 5, 5, -64 }, // + { 4, 5, -32 }, // + { 4, 5, 0 }, // + { 5, 5, 32 }, // + { 5, 6, 64 }, // + { 4, 7, 128 }, // + { 3, 8, 256 }, // + { 3, 9, 512 }, // + { 3, 10, 1024 }, // + { 5, 32, -1025, 999 }, /* low */ + { 5, 32, 2048 } /* high */ + }, + // B8 + { { 8, 3, -15 }, // + { 9, 1, -7 }, // + { 8, 1, -5 }, // + { 9, 0, -3 }, // + { 7, 0, -2 }, // + { 4, 0, -1 }, // + { 2, 1, 0 }, // + { 5, 0, 2 }, // + { 6, 0, 3 }, // + { 3, 4, 4 }, // + { 6, 1, 20 }, // + { 4, 4, 22 }, // + { 4, 5, 38 }, // + { 5, 6, 70 }, // + { 5, 7, 134 }, // + { 6, 7, 262 }, // + { 7, 8, 390 }, // + { 6, 10, 646 }, // + { 9, 32, -16, 999 }, /* low */ + { 9, 32, 1670 }, /* high */ + { 2, -1, 0 } /* OOB */ + }, + // B9 + { { 8, 4, -31 }, // + { 9, 2, -15 }, // + { 8, 2, -11 }, // + { 9, 1, -7 }, // + { 7, 1, -5 }, // + { 4, 1, -3 }, // + { 3, 1, -1 }, // + { 3, 1, 1 }, // + { 5, 1, 3 }, // + { 6, 1, 5 }, // + { 3, 5, 7 }, // + { 6, 2, 39 }, // + { 4, 5, 43 }, // + { 4, 6, 75 }, // + { 5, 7, 139 }, // + { 5, 8, 267 }, // + { 6, 8, 523 }, // + { 7, 9, 779 }, // + { 6, 11, 1291 }, // + { 9, 32, -32, 999 }, /* low */ + { 9, 32, 3339 }, /* high */ + { 2, -1, 0 } /* OOB */ + }, + // B10 + { { 7, 4, -21 }, // + { 8, 0, -5 }, // + { 7, 0, -4 }, // + { 5, 0, -3 }, // + { 2, 2, -2 }, // + { 5, 0, 2 }, // + { 6, 0, 3 }, // + { 7, 0, 4 }, // + { 8, 0, 5 }, // + { 2, 6, 6 }, // + { 5, 5, 70 }, // + { 6, 5, 102 }, // + { 6, 6, 134 }, // + { 6, 7, 198 }, // + { 6, 8, 326 }, // + { 6, 9, 582 }, // + { 6, 10, 1094 }, // + { 7, 11, 2118 }, // + { 8, 32, -22, 999 }, /* low */ + { 8, 32, 4166 }, /* high */ + { 2, -1, 0 } /* OOB */ + }, + // B11 + { { 1, 0, 1 }, // + { 2, 1, 2 }, // + { 4, 0, 4 }, // + { 4, 1, 5 }, // + { 5, 1, 7 }, // + { 5, 2, 9 }, // + { 6, 2, 13 }, // + { 7, 2, 17 }, // + { 7, 3, 21 }, // + { 7, 4, 29 }, // + { 7, 5, 45 }, // + { 7, 6, 77 }, // + { 7, 32, 141 } /* high */ + }, + // B12 + { { 1, 0, 1 }, // + { 2, 0, 2 }, // + { 3, 1, 3 }, // + { 5, 0, 5 }, // + { 5, 1, 6 }, // + { 6, 1, 8 }, // + { 7, 0, 10 }, // + { 7, 1, 11 }, // + { 7, 2, 13 }, // + { 7, 3, 17 }, // + { 7, 4, 25 }, // + { 8, 5, 41 }, // + { 8, 32, 73 } // + }, + // B13 + { { 1, 0, 1 }, // + { 3, 0, 2 }, // + { 4, 0, 3 }, // + { 5, 0, 4 }, // + { 4, 1, 5 }, // + { 3, 3, 7 }, // + { 6, 1, 15 }, // + { 6, 2, 17 }, // + { 6, 3, 21 }, // + { 6, 4, 29 }, // + { 6, 5, 45 }, // + { 7, 6, 77 }, // + { 7, 32, 141 } /* high */ + }, + // B14 + { { 3, 0, -2 }, // + { 3, 0, -1 }, // + { 1, 0, 0 }, // + { 3, 0, 1 }, // + { 3, 0, 2 } // + }, + // B15 + { { 7, 4, -24 }, // + { 6, 2, -8 }, // + { 5, 1, -4 }, // + { 4, 0, -2 }, // + { 3, 0, -1 }, // + { 1, 0, 0 }, // + { 3, 0, 1 }, // + { 4, 0, 2 }, // + { 5, 1, 3 }, // + { 6, 2, 5 }, // + { 7, 4, 9 }, // + { 7, 32, -25, 999 }, /* low */ + { 7, 32, 25 } /* high */ + } }; - private static HuffmanTable STANDARD_TABLES[] = new HuffmanTable[TABLES.length]; + private static HuffmanTable STANDARD_TABLES[] = new HuffmanTable[TABLES.length]; - public static HuffmanTable getTable(int number) { - HuffmanTable table = STANDARD_TABLES[number - 1]; - if (table == null) { - table = new StandardTable(TABLES[number - 1]); - STANDARD_TABLES[number - 1] = table; - } + public static HuffmanTable getTable(int number) + { + HuffmanTable table = STANDARD_TABLES[number - 1]; + if (table == null) + { + table = new StandardTable(TABLES[number - 1]); + STANDARD_TABLES[number - 1] = table; + } - return table; - } + return table; + } } http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/ValueNode.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/ValueNode.java b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/ValueNode.java index 7543f7e..f01a166 100644 --- a/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/ValueNode.java +++ b/src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/ValueNode.java @@ -26,34 +26,41 @@ import org.apache.pdfbox.jbig2.decoder.huffman.HuffmanTable.Code; /** * Represents a value node in a huffman tree. It is a leaf of a tree. */ -class ValueNode extends Node { - private int rangeLen; - private int rangeLow; - private boolean isLowerRange; - - protected ValueNode(Code c) { - rangeLen = c.rangeLength; - rangeLow = c.rangeLow; - isLowerRange = c.isLowerRange; - } - - @Override - protected long decode(ImageInputStream iis) throws IOException { - - if (isLowerRange) { - /* B.4 4) */ - return (rangeLow - iis.readBits(rangeLen)); - } else { - /* B.4 5) */ - return rangeLow + iis.readBits(rangeLen); +class ValueNode extends Node +{ + private int rangeLen; + private int rangeLow; + private boolean isLowerRange; + + protected ValueNode(Code c) + { + rangeLen = c.rangeLength; + rangeLow = c.rangeLow; + isLowerRange = c.isLowerRange; } - } - static String bitPattern(int v, int len) { - char result[] = new char[len]; - for (int i = 1; i <= len; i++) - result[i - 1] = (v >> (len - i) & 1) != 0 ? '1' : '0'; + @Override + protected long decode(ImageInputStream iis) throws IOException + { + + if (isLowerRange) + { + /* B.4 4) */ + return (rangeLow - iis.readBits(rangeLen)); + } + else + { + /* B.4 5) */ + return rangeLow + iis.readBits(rangeLen); + } + } - return new String(result); - } + static String bitPattern(int v, int len) + { + char result[] = new char[len]; + for (int i = 1; i <= len; i++) + result[i - 1] = (v >> (len - i) & 1) != 0 ? '1' : '0'; + + return new String(result); + } } http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRConstants.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRConstants.java b/src/main/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRConstants.java index a5d3971..88f08a8 100644 --- a/src/main/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRConstants.java +++ b/src/main/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRConstants.java @@ -20,735 +20,273 @@ package org.apache.pdfbox.jbig2.decoder.mmr; /** * Constants for MMR (de)compression. */ -public class MMRConstants { - public static final int COMP_FAXG3 = 0; - public static final int COMP_FAXG4 = 1; - public static final int COMP_MMR = 2; - public static final int COMP_RLE = 3; - public static final int COMP_FAXG3_2D = 4; +public class MMRConstants +{ + public static final int COMP_FAXG3 = 0; + public static final int COMP_FAXG4 = 1; + public static final int COMP_MMR = 2; + public static final int COMP_RLE = 3; + public static final int COMP_FAXG3_2D = 4; - public static final int NOMASK = 0xFFFF; - public static final int INCOMP = -4; - public static final int EOF = -3; - public static final int INVALID = -2; - public static final int EOL = -1; - public static final int CODE_P = 0; - public static final int CODE_H = 1; - public static final int CODE_V0 = 2; - public static final int CODE_VR1 = 3; - public static final int CODE_VR2 = 4; - public static final int CODE_VR3 = 5; - public static final int CODE_VL1 = 6; - public static final int CODE_VL2 = 7; - public static final int CODE_VL3 = 8; - public static final int CODE_EXT2D = 9; - public static final int CODE_EXT1D = 10; - public static final int CODE_EOL = 11; - public static final int CODE_EOF = 12; - public static final int CODE_MAX = 12; + public static final int NOMASK = 0xFFFF; + public static final int INCOMP = -4; + public static final int EOF = -3; + public static final int INVALID = -2; + public static final int EOL = -1; + public static final int CODE_P = 0; + public static final int CODE_H = 1; + public static final int CODE_V0 = 2; + public static final int CODE_VR1 = 3; + public static final int CODE_VR2 = 4; + public static final int CODE_VR3 = 5; + public static final int CODE_VL1 = 6; + public static final int CODE_VL2 = 7; + public static final int CODE_VL3 = 8; + public static final int CODE_EXT2D = 9; + public static final int CODE_EXT1D = 10; + public static final int CODE_EOL = 11; + public static final int CODE_EOF = 12; + public static final int CODE_MAX = 12; - // -------------------------------------------------------------------------------------------------------------- - public static final int ModeCodes[][] = { - { - 4, 0x1, CODE_P - }, // 0001 pass - { - 3, 0x1, CODE_H - }, // 001 horizontal - { - 1, 0x1, CODE_V0 - }, // 1 vert 0 - { - 3, 0x3, CODE_VR1 - }, // 011 vert r 1 - { - 6, 0x3, CODE_VR2 - }, // 000011 vert r 2 - { - 7, 0x3, CODE_VR3 - }, // 0000011 vert r 3 - { - 3, 0x2, CODE_VL1 - }, // 010 vert l 1 - { - 6, 0x2, CODE_VL2 - }, // 000010 vert l 2 - { - 7, 0x2, CODE_VL3 - }, // 0000010 vert l 3 - { - 10, 0xf, CODE_EXT2D - }, // 0000001111 - { - 12, 0xf, CODE_EXT1D - }, // 000000001111 - { - 12, 0x1, EOL - } - // 000000000001 - }; + // -------------------------------------------------------------------------------------------------------------- + public static final int ModeCodes[][] = { { 4, 0x1, CODE_P }, // 0001 pass + { 3, 0x1, CODE_H }, // 001 horizontal + { 1, 0x1, CODE_V0 }, // 1 vert 0 + { 3, 0x3, CODE_VR1 }, // 011 vert r 1 + { 6, 0x3, CODE_VR2 }, // 000011 vert r 2 + { 7, 0x3, CODE_VR3 }, // 0000011 vert r 3 + { 3, 0x2, CODE_VL1 }, // 010 vert l 1 + { 6, 0x2, CODE_VL2 }, // 000010 vert l 2 + { 7, 0x2, CODE_VL3 }, // 0000010 vert l 3 + { 10, 0xf, CODE_EXT2D }, // 0000001111 + { 12, 0xf, CODE_EXT1D }, // 000000001111 + { 12, 0x1, EOL } + // 000000000001 + }; - public static final int WhiteCodes[][] = { - { - 4, 0x07, 2 - }, // 0111 - { - 4, 0x08, 3 - }, // 1000 - { - 4, 0x0B, 4 - }, // 1011 - { - 4, 0x0C, 5 - }, // 1100 - { - 4, 0x0E, 6 - }, // 1110 - { - 4, 0x0F, 7 - }, // 1111 - { - 5, 0x12, 128 - }, // 1001 0 - { - 5, 0x13, 8 - }, // 1001 1 - { - 5, 0x14, 9 - }, // 1010 0 - { - 5, 0x1B, 64 - }, // 1101 1 - { - 5, 0x07, 10 - }, // 0011 1 - { - 5, 0x08, 11 - }, // 0100 0 - { - 6, 0x17, 192 - }, // 0101 11 - { - 6, 0x18, 1664 - }, // 0110 00 - { - 6, 0x2A, 16 - }, // 1010 10 - { - 6, 0x2B, 17 - }, // 1010 11 - { - 6, 0x03, 13 - }, // 0000 11 - { - 6, 0x34, 14 - }, // 1101 00 - { - 6, 0x35, 15 - }, // 1101 01 - { - 6, 0x07, 1 - }, // 0001 11 - { - 6, 0x08, 12 - }, // 0010 00 - { - 7, 0x13, 26 - }, // 0010 011 - { - 7, 0x17, 21 - }, // 0010 111 - { - 7, 0x18, 28 - }, // 0011 000 - { - 7, 0x24, 27 - }, // 0100 100 - { - 7, 0x27, 18 - }, // 0100 111 - { - 7, 0x28, 24 - }, // 0101 000 - { - 7, 0x2B, 25 - }, // 0101 011 - { - 7, 0x03, 22 - }, // 0000 011 - { - 7, 0x37, 256 - }, // 0110 111 - { - 7, 0x04, 23 - }, // 0000 100 - { - 7, 0x08, 20 - }, // 0001 000 - { - 7, 0xC, 19 - }, // 0001 100 - { - 8, 0x12, 33 - }, // 0001 0010 - { - 8, 0x13, 34 - }, // 0001 0011 - { - 8, 0x14, 35 - }, // 0001 0100 - { - 8, 0x15, 36 - }, // 0001 0101 - { - 8, 0x16, 37 - }, // 0001 0110 - { - 8, 0x17, 38 - }, // 0001 0111 - { - 8, 0x1A, 31 - }, // 0001 1010 - { - 8, 0x1B, 32 - }, // 0001 1011 - { - 8, 0x02, 29 - }, // 0000 0010 - { - 8, 0x24, 53 - }, // 0010 0100 - { - 8, 0x25, 54 - }, // 0010 0101 - { - 8, 0x28, 39 - }, // 0010 1000 - { - 8, 0x29, 40 - }, // 0010 1001 - { - 8, 0x2A, 41 - }, // 0010 1010 - { - 8, 0x2B, 42 - }, // 0010 1011 - { - 8, 0x2C, 43 - }, // 0010 1100 - { - 8, 0x2D, 44 - }, // 0010 1101 - { - 8, 0x03, 30 - }, // 0000 0011 - { - 8, 0x32, 61 - }, // 0011 0010 - { - 8, 0x33, 62 - }, // 0011 0011 - { - 8, 0x34, 63 - }, // 0011 0100 - { - 8, 0x35, 0 - }, // 0011 0101 - { - 8, 0x36, 320 - }, // 0011 0110 - { - 8, 0x37, 384 - }, // 0011 0111 - { - 8, 0x04, 45 - }, // 0000 0100 - { - 8, 0x4A, 59 - }, // 0100 1010 - { - 8, 0x4B, 60 - }, // 0100 1011 - { - 8, 0x5, 46 - }, // 0000 0101 - { - 8, 0x52, 49 - }, // 0101 0010 - { - 8, 0x53, 50 - }, // 0101 0011 - { - 8, 0x54, 51 - }, // 0101 0100 - { - 8, 0x55, 52 - }, // 0101 0101 - { - 8, 0x58, 55 - }, // 0101 1000 - { - 8, 0x59, 56 - }, // 0101 1001 - { - 8, 0x5A, 57 - }, // 0101 1010 - { - 8, 0x5B, 58 - }, // 0101 1011 - { - 8, 0x64, 448 - }, // 0110 0100 - { - 8, 0x65, 512 - }, // 0110 0101 - { - 8, 0x67, 640 - }, // 0110 0111 - { - 8, 0x68, 576 - }, // 0110 1000 - { - 8, 0x0A, 47 - }, // 0000 1010 - { - 8, 0x0B, 48 - }, // 0000 1011 - { - 9, 0x01, INVALID - }, // 0000 0000 1 - { - 9, 0x98, 1472 - }, // 0100 1100 0 - { - 9, 0x99, 1536 - }, // 0100 1100 1 - { - 9, 0x9A, 1600 - }, // 0100 1101 0 - { - 9, 0x9B, 1728 - }, // 0100 1101 1 - { - 9, 0xCC, 704 - }, // 0110 0110 0 - { - 9, 0xCD, 768 - }, // 0110 0110 1 - { - 9, 0xD2, 832 - }, // 0110 1001 0 - { - 9, 0xD3, 896 - }, // 0110 1001 1 - { - 9, 0xD4, 960 - }, // 0110 1010 0 - { - 9, 0xD5, 1024 - }, // 0110 1010 1 - { - 9, 0xD6, 1088 - }, // 0110 1011 0 - { - 9, 0xD7, 1152 - }, // 0110 1011 1 - { - 9, 0xD8, 1216 - }, // 0110 1100 0 - { - 9, 0xD9, 1280 - }, // 0110 1100 1 - { - 9, 0xDA, 1344 - }, // 0110 1101 0 - { - 9, 0xDB, 1408 - }, // 0110 1101 1 - { - 10, 0x01, INVALID - }, // 0000 0000 01 - { - 11, 0x01, INVALID - }, // 0000 0000 001 - { - 11, 0x08, 1792 - }, // 0000 0001 000 - { - 11, 0x0C, 1856 - }, // 0000 0001 100 - { - 11, 0x0D, 1920 - }, // 0000 0001 101 - { - 12, 0x00, EOF - }, // 0000 0000 0000 - { - 12, 0x01, EOL - }, // 0000 0000 0001 - { - 12, 0x12, 1984 - }, // 0000 0001 0010 - { - 12, 0x13, 2048 - }, // 0000 0001 0011 - { - 12, 0x14, 2112 - }, // 0000 0001 0100 - { - 12, 0x15, 2176 - }, // 0000 0001 0101 - { - 12, 0x16, 2240 - }, // 0000 0001 0110 - { - 12, 0x17, 2304 - }, // 0000 0001 0111 - { - 12, 0x1C, 2368 - }, // 0000 0001 1100 - { - 12, 0x1D, 2432 - }, // 0000 0001 1101 - { - 12, 0x1E, 2496 - }, // 0000 0001 1110 - { - 12, 0x1F, 2560 - } - // 0000 0001 1111 - }; - public static final int MAX_WHITE_RUN = 2560; + public static final int WhiteCodes[][] = { { 4, 0x07, 2 }, // 0111 + { 4, 0x08, 3 }, // 1000 + { 4, 0x0B, 4 }, // 1011 + { 4, 0x0C, 5 }, // 1100 + { 4, 0x0E, 6 }, // 1110 + { 4, 0x0F, 7 }, // 1111 + { 5, 0x12, 128 }, // 1001 0 + { 5, 0x13, 8 }, // 1001 1 + { 5, 0x14, 9 }, // 1010 0 + { 5, 0x1B, 64 }, // 1101 1 + { 5, 0x07, 10 }, // 0011 1 + { 5, 0x08, 11 }, // 0100 0 + { 6, 0x17, 192 }, // 0101 11 + { 6, 0x18, 1664 }, // 0110 00 + { 6, 0x2A, 16 }, // 1010 10 + { 6, 0x2B, 17 }, // 1010 11 + { 6, 0x03, 13 }, // 0000 11 + { 6, 0x34, 14 }, // 1101 00 + { 6, 0x35, 15 }, // 1101 01 + { 6, 0x07, 1 }, // 0001 11 + { 6, 0x08, 12 }, // 0010 00 + { 7, 0x13, 26 }, // 0010 011 + { 7, 0x17, 21 }, // 0010 111 + { 7, 0x18, 28 }, // 0011 000 + { 7, 0x24, 27 }, // 0100 100 + { 7, 0x27, 18 }, // 0100 111 + { 7, 0x28, 24 }, // 0101 000 + { 7, 0x2B, 25 }, // 0101 011 + { 7, 0x03, 22 }, // 0000 011 + { 7, 0x37, 256 }, // 0110 111 + { 7, 0x04, 23 }, // 0000 100 + { 7, 0x08, 20 }, // 0001 000 + { 7, 0xC, 19 }, // 0001 100 + { 8, 0x12, 33 }, // 0001 0010 + { 8, 0x13, 34 }, // 0001 0011 + { 8, 0x14, 35 }, // 0001 0100 + { 8, 0x15, 36 }, // 0001 0101 + { 8, 0x16, 37 }, // 0001 0110 + { 8, 0x17, 38 }, // 0001 0111 + { 8, 0x1A, 31 }, // 0001 1010 + { 8, 0x1B, 32 }, // 0001 1011 + { 8, 0x02, 29 }, // 0000 0010 + { 8, 0x24, 53 }, // 0010 0100 + { 8, 0x25, 54 }, // 0010 0101 + { 8, 0x28, 39 }, // 0010 1000 + { 8, 0x29, 40 }, // 0010 1001 + { 8, 0x2A, 41 }, // 0010 1010 + { 8, 0x2B, 42 }, // 0010 1011 + { 8, 0x2C, 43 }, // 0010 1100 + { 8, 0x2D, 44 }, // 0010 1101 + { 8, 0x03, 30 }, // 0000 0011 + { 8, 0x32, 61 }, // 0011 0010 + { 8, 0x33, 62 }, // 0011 0011 + { 8, 0x34, 63 }, // 0011 0100 + { 8, 0x35, 0 }, // 0011 0101 + { 8, 0x36, 320 }, // 0011 0110 + { 8, 0x37, 384 }, // 0011 0111 + { 8, 0x04, 45 }, // 0000 0100 + { 8, 0x4A, 59 }, // 0100 1010 + { 8, 0x4B, 60 }, // 0100 1011 + { 8, 0x5, 46 }, // 0000 0101 + { 8, 0x52, 49 }, // 0101 0010 + { 8, 0x53, 50 }, // 0101 0011 + { 8, 0x54, 51 }, // 0101 0100 + { 8, 0x55, 52 }, // 0101 0101 + { 8, 0x58, 55 }, // 0101 1000 + { 8, 0x59, 56 }, // 0101 1001 + { 8, 0x5A, 57 }, // 0101 1010 + { 8, 0x5B, 58 }, // 0101 1011 + { 8, 0x64, 448 }, // 0110 0100 + { 8, 0x65, 512 }, // 0110 0101 + { 8, 0x67, 640 }, // 0110 0111 + { 8, 0x68, 576 }, // 0110 1000 + { 8, 0x0A, 47 }, // 0000 1010 + { 8, 0x0B, 48 }, // 0000 1011 + { 9, 0x01, INVALID }, // 0000 0000 1 + { 9, 0x98, 1472 }, // 0100 1100 0 + { 9, 0x99, 1536 }, // 0100 1100 1 + { 9, 0x9A, 1600 }, // 0100 1101 0 + { 9, 0x9B, 1728 }, // 0100 1101 1 + { 9, 0xCC, 704 }, // 0110 0110 0 + { 9, 0xCD, 768 }, // 0110 0110 1 + { 9, 0xD2, 832 }, // 0110 1001 0 + { 9, 0xD3, 896 }, // 0110 1001 1 + { 9, 0xD4, 960 }, // 0110 1010 0 + { 9, 0xD5, 1024 }, // 0110 1010 1 + { 9, 0xD6, 1088 }, // 0110 1011 0 + { 9, 0xD7, 1152 }, // 0110 1011 1 + { 9, 0xD8, 1216 }, // 0110 1100 0 + { 9, 0xD9, 1280 }, // 0110 1100 1 + { 9, 0xDA, 1344 }, // 0110 1101 0 + { 9, 0xDB, 1408 }, // 0110 1101 1 + { 10, 0x01, INVALID }, // 0000 0000 01 + { 11, 0x01, INVALID }, // 0000 0000 001 + { 11, 0x08, 1792 }, // 0000 0001 000 + { 11, 0x0C, 1856 }, // 0000 0001 100 + { 11, 0x0D, 1920 }, // 0000 0001 101 + { 12, 0x00, EOF }, // 0000 0000 0000 + { 12, 0x01, EOL }, // 0000 0000 0001 + { 12, 0x12, 1984 }, // 0000 0001 0010 + { 12, 0x13, 2048 }, // 0000 0001 0011 + { 12, 0x14, 2112 }, // 0000 0001 0100 + { 12, 0x15, 2176 }, // 0000 0001 0101 + { 12, 0x16, 2240 }, // 0000 0001 0110 + { 12, 0x17, 2304 }, // 0000 0001 0111 + { 12, 0x1C, 2368 }, // 0000 0001 1100 + { 12, 0x1D, 2432 }, // 0000 0001 1101 + { 12, 0x1E, 2496 }, // 0000 0001 1110 + { 12, 0x1F, 2560 } + // 0000 0001 1111 + }; + public static final int MAX_WHITE_RUN = 2560; - public static final int BlackCodes[][] = { - { - 2, 0x02, 3 - }, // 10 - { - 2, 0x03, 2 - }, // 11 - { - 3, 0x02, 1 - }, // 010 - { - 3, 0x03, 4 - }, // 011 - { - 4, 0x02, 6 - }, // 0010 - { - 4, 0x03, 5 - }, // 0011 - { - 5, 0x03, 7 - }, // 0001 1 - { - 6, 0x04, 9 - }, // 0001 00 - { - 6, 0x05, 8 - }, // 0001 01 - { - 7, 0x04, 10 - }, // 0000 100 - { - 7, 0x05, 11 - }, // 0000 101 - { - 7, 0x07, 12 - }, // 0000 111 - { - 8, 0x04, 13 - }, // 0000 0100 - { - 8, 0x07, 14 - }, // 0000 0111 - { - 9, 0x01, INVALID - }, // 0000 0000 1 - { - 9, 0x18, 15 - }, // 0000 1100 0 - { - 10, 0x01, INVALID - }, // 0000 0000 01 - { - 10, 0x17, 16 - }, // 0000 0101 11 - { - 10, 0x18, 17 - }, // 0000 0110 00 - { - 10, 0x37, 0 - }, // 0000 1101 11 - { - 10, 0x08, 18 - }, // 0000 0010 00 - { - 10, 0x0F, 64 - }, // 0000 0011 11 - { - 11, 0x01, INVALID - }, // 0000 0000 001 - { - 11, 0x17, 24 - }, // 0000 0010 111 - { - 11, 0x18, 25 - }, // 0000 0011 000 - { - 11, 0x28, 23 - }, // 0000 0101 000 - { - 11, 0x37, 22 - }, // 0000 0110 111 - { - 11, 0x67, 19 - }, // 0000 1100 111 - { - 11, 0x68, 20 - }, // 0000 1101 000 - { - 11, 0x6C, 21 - }, // 0000 1101 100 - { - 11, 0x08, 1792 - }, // 0000 0001 000 - { - 11, 0x0C, 1856 - }, // 0000 0001 100 - { - 11, 0x0D, 1920 - }, // 0000 0001 101 - { - 12, 0x00, EOF - }, // 0000 0000 0000 - { - 12, 0x01, EOL - }, // 0000 0000 0001 - { - 12, 0x12, 1984 - }, // 0000 0001 0010 - { - 12, 0x13, 2048 - }, // 0000 0001 0011 - { - 12, 0x14, 2112 - }, // 0000 0001 0100 - { - 12, 0x15, 2176 - }, // 0000 0001 0101 - { - 12, 0x16, 2240 - }, // 0000 0001 0110 - { - 12, 0x17, 2304 - }, // 0000 0001 0111 - { - 12, 0x1C, 2368 - }, // 0000 0001 1100 - { - 12, 0x1D, 2432 - }, // 0000 0001 1101 - { - 12, 0x1E, 2496 - }, // 0000 0001 1110 - { - 12, 0x1F, 2560 - }, // 0000 0001 1111 - { - 12, 0x24, 52 - }, // 0000 0010 0100 - { - 12, 0x27, 55 - }, // 0000 0010 0111 - { - 12, 0x28, 56 - }, // 0000 0010 1000 - { - 12, 0x2B, 59 - }, // 0000 0010 1011 - { - 12, 0x2C, 60 - }, // 0000 0010 1100 - { - 12, 0x33, 320 - }, // 0000 0011 0011 - { - 12, 0x34, 384 - }, // 0000 0011 0100 - { - 12, 0x35, 448 - }, // 0000 0011 0101 - { - 12, 0x37, 53 - }, // 0000 0011 0111 - { - 12, 0x38, 54 - }, // 0000 0011 1000 - { - 12, 0x52, 50 - }, // 0000 0101 0010 - { - 12, 0x53, 51 - }, // 0000 0101 0011 - { - 12, 0x54, 44 - }, // 0000 0101 0100 - { - 12, 0x55, 45 - }, // 0000 0101 0101 - { - 12, 0x56, 46 - }, // 0000 0101 0110 - { - 12, 0x57, 47 - }, // 0000 0101 0111 - { - 12, 0x58, 57 - }, // 0000 0101 1000 - { - 12, 0x59, 58 - }, // 0000 0101 1001 - { - 12, 0x5A, 61 - }, // 0000 0101 1010 - { - 12, 0x5B, 256 - }, // 0000 0101 1011 - { - 12, 0x64, 48 - }, // 0000 0110 0100 - { - 12, 0x65, 49 - }, // 0000 0110 0101 - { - 12, 0x66, 62 - }, // 0000 0110 0110 - { - 12, 0x67, 63 - }, // 0000 0110 0111 - { - 12, 0x68, 30 - }, // 0000 0110 1000 - { - 12, 0x69, 31 - }, // 0000 0110 1001 - { - 12, 0x6A, 32 - }, // 0000 0110 1010 - { - 12, 0x6B, 33 - }, // 0000 0110 1011 - { - 12, 0x6C, 40 - }, // 0000 0110 1100 - { - 12, 0x6D, 41 - }, // 0000 0110 1101 - { - 12, 0xC8, 128 - }, // 0000 1100 1000 - { - 12, 0xC9, 192 - }, // 0000 1100 1001 - { - 12, 0xCA, 26 - }, // 0000 1100 1010 - { - 12, 0xCB, 27 - }, // 0000 1100 1011 - { - 12, 0xCC, 28 - }, // 0000 1100 1100 - { - 12, 0xCD, 29 - }, // 0000 1100 1101 - { - 12, 0xD2, 34 - }, // 0000 1101 0010 - { - 12, 0xD3, 35 - }, // 0000 1101 0011 - { - 12, 0xD4, 36 - }, // 0000 1101 0100 - { - 12, 0xD5, 37 - }, // 0000 1101 0101 - { - 12, 0xD6, 38 - }, // 0000 1101 0110 - { - 12, 0xD7, 39 - }, // 0000 1101 0111 - { - 12, 0xDA, 42 - }, // 0000 1101 1010 - { - 12, 0xDB, 43 - }, // 0000 1101 1011 - { - 13, 0x4A, 640 - }, // 0000 0010 0101 0 - { - 13, 0x4B, 704 - }, // 0000 0010 0101 1 - { - 13, 0x4C, 768 - }, // 0000 0010 0110 0 - { - 13, 0x4D, 832 - }, // 0000 0010 0110 1 - { - 13, 0x52, 1280 - }, // 0000 0010 1001 0 - { - 13, 0x53, 1344 - }, // 0000 0010 1001 1 - { - 13, 0x54, 1408 - }, // 0000 0010 1010 0 - { - 13, 0x55, 1472 - }, // 0000 0010 1010 1 - { - 13, 0x5A, 1536 - }, // 0000 0010 1101 0 - { - 13, 0x5B, 1600 - }, // 0000 0010 1101 1 - { - 13, 0x64, 1664 - }, // 0000 0011 0010 0 - { - 13, 0x65, 1728 - }, // 0000 0011 0010 1 - { - 13, 0x6C, 512 - }, // 0000 0011 0110 0 - { - 13, 0x6D, 576 - }, // 0000 0011 0110 1 - { - 13, 0x72, 896 - }, // 0000 0011 1001 0 - { - 13, 0x73, 960 - }, // 0000 0011 1001 1 - { - 13, 0x74, 1024 - }, // 0000 0011 1010 0 - { - 13, 0x75, 1088 - }, // 0000 0011 1010 1 - { - 13, 0x76, 1152 - }, // 0000 0011 1011 0 - { - 13, 0x77, 1216 - } - // 0000 0011 1011 1 - }; - public static final int MAX_BLACK_RUN = 2560; + public static final int BlackCodes[][] = { { 2, 0x02, 3 }, // 10 + { 2, 0x03, 2 }, // 11 + { 3, 0x02, 1 }, // 010 + { 3, 0x03, 4 }, // 011 + { 4, 0x02, 6 }, // 0010 + { 4, 0x03, 5 }, // 0011 + { 5, 0x03, 7 }, // 0001 1 + { 6, 0x04, 9 }, // 0001 00 + { 6, 0x05, 8 }, // 0001 01 + { 7, 0x04, 10 }, // 0000 100 + { 7, 0x05, 11 }, // 0000 101 + { 7, 0x07, 12 }, // 0000 111 + { 8, 0x04, 13 }, // 0000 0100 + { 8, 0x07, 14 }, // 0000 0111 + { 9, 0x01, INVALID }, // 0000 0000 1 + { 9, 0x18, 15 }, // 0000 1100 0 + { 10, 0x01, INVALID }, // 0000 0000 01 + { 10, 0x17, 16 }, // 0000 0101 11 + { 10, 0x18, 17 }, // 0000 0110 00 + { 10, 0x37, 0 }, // 0000 1101 11 + { 10, 0x08, 18 }, // 0000 0010 00 + { 10, 0x0F, 64 }, // 0000 0011 11 + { 11, 0x01, INVALID }, // 0000 0000 001 + { 11, 0x17, 24 }, // 0000 0010 111 + { 11, 0x18, 25 }, // 0000 0011 000 + { 11, 0x28, 23 }, // 0000 0101 000 + { 11, 0x37, 22 }, // 0000 0110 111 + { 11, 0x67, 19 }, // 0000 1100 111 + { 11, 0x68, 20 }, // 0000 1101 000 + { 11, 0x6C, 21 }, // 0000 1101 100 + { 11, 0x08, 1792 }, // 0000 0001 000 + { 11, 0x0C, 1856 }, // 0000 0001 100 + { 11, 0x0D, 1920 }, // 0000 0001 101 + { 12, 0x00, EOF }, // 0000 0000 0000 + { 12, 0x01, EOL }, // 0000 0000 0001 + { 12, 0x12, 1984 }, // 0000 0001 0010 + { 12, 0x13, 2048 }, // 0000 0001 0011 + { 12, 0x14, 2112 }, // 0000 0001 0100 + { 12, 0x15, 2176 }, // 0000 0001 0101 + { 12, 0x16, 2240 }, // 0000 0001 0110 + { 12, 0x17, 2304 }, // 0000 0001 0111 + { 12, 0x1C, 2368 }, // 0000 0001 1100 + { 12, 0x1D, 2432 }, // 0000 0001 1101 + { 12, 0x1E, 2496 }, // 0000 0001 1110 + { 12, 0x1F, 2560 }, // 0000 0001 1111 + { 12, 0x24, 52 }, // 0000 0010 0100 + { 12, 0x27, 55 }, // 0000 0010 0111 + { 12, 0x28, 56 }, // 0000 0010 1000 + { 12, 0x2B, 59 }, // 0000 0010 1011 + { 12, 0x2C, 60 }, // 0000 0010 1100 + { 12, 0x33, 320 }, // 0000 0011 0011 + { 12, 0x34, 384 }, // 0000 0011 0100 + { 12, 0x35, 448 }, // 0000 0011 0101 + { 12, 0x37, 53 }, // 0000 0011 0111 + { 12, 0x38, 54 }, // 0000 0011 1000 + { 12, 0x52, 50 }, // 0000 0101 0010 + { 12, 0x53, 51 }, // 0000 0101 0011 + { 12, 0x54, 44 }, // 0000 0101 0100 + { 12, 0x55, 45 }, // 0000 0101 0101 + { 12, 0x56, 46 }, // 0000 0101 0110 + { 12, 0x57, 47 }, // 0000 0101 0111 + { 12, 0x58, 57 }, // 0000 0101 1000 + { 12, 0x59, 58 }, // 0000 0101 1001 + { 12, 0x5A, 61 }, // 0000 0101 1010 + { 12, 0x5B, 256 }, // 0000 0101 1011 + { 12, 0x64, 48 }, // 0000 0110 0100 + { 12, 0x65, 49 }, // 0000 0110 0101 + { 12, 0x66, 62 }, // 0000 0110 0110 + { 12, 0x67, 63 }, // 0000 0110 0111 + { 12, 0x68, 30 }, // 0000 0110 1000 + { 12, 0x69, 31 }, // 0000 0110 1001 + { 12, 0x6A, 32 }, // 0000 0110 1010 + { 12, 0x6B, 33 }, // 0000 0110 1011 + { 12, 0x6C, 40 }, // 0000 0110 1100 + { 12, 0x6D, 41 }, // 0000 0110 1101 + { 12, 0xC8, 128 }, // 0000 1100 1000 + { 12, 0xC9, 192 }, // 0000 1100 1001 + { 12, 0xCA, 26 }, // 0000 1100 1010 + { 12, 0xCB, 27 }, // 0000 1100 1011 + { 12, 0xCC, 28 }, // 0000 1100 1100 + { 12, 0xCD, 29 }, // 0000 1100 1101 + { 12, 0xD2, 34 }, // 0000 1101 0010 + { 12, 0xD3, 35 }, // 0000 1101 0011 + { 12, 0xD4, 36 }, // 0000 1101 0100 + { 12, 0xD5, 37 }, // 0000 1101 0101 + { 12, 0xD6, 38 }, // 0000 1101 0110 + { 12, 0xD7, 39 }, // 0000 1101 0111 + { 12, 0xDA, 42 }, // 0000 1101 1010 + { 12, 0xDB, 43 }, // 0000 1101 1011 + { 13, 0x4A, 640 }, // 0000 0010 0101 0 + { 13, 0x4B, 704 }, // 0000 0010 0101 1 + { 13, 0x4C, 768 }, // 0000 0010 0110 0 + { 13, 0x4D, 832 }, // 0000 0010 0110 1 + { 13, 0x52, 1280 }, // 0000 0010 1001 0 + { 13, 0x53, 1344 }, // 0000 0010 1001 1 + { 13, 0x54, 1408 }, // 0000 0010 1010 0 + { 13, 0x55, 1472 }, // 0000 0010 1010 1 + { 13, 0x5A, 1536 }, // 0000 0010 1101 0 + { 13, 0x5B, 1600 }, // 0000 0010 1101 1 + { 13, 0x64, 1664 }, // 0000 0011 0010 0 + { 13, 0x65, 1728 }, // 0000 0011 0010 1 + { 13, 0x6C, 512 }, // 0000 0011 0110 0 + { 13, 0x6D, 576 }, // 0000 0011 0110 1 + { 13, 0x72, 896 }, // 0000 0011 1001 0 + { 13, 0x73, 960 }, // 0000 0011 1001 1 + { 13, 0x74, 1024 }, // 0000 0011 1010 0 + { 13, 0x75, 1088 }, // 0000 0011 1010 1 + { 13, 0x76, 1152 }, // 0000 0011 1011 0 + { 13, 0x77, 1216 } + // 0000 0011 1011 1 + }; + public static final int MAX_BLACK_RUN = 2560; }