JPEGHuffmanTablepublic class JPEGHuffmanTable extends Object The JPEGHuffmanTable class represents a single JPEG Huffman table. It
contains the standard tables from the JPEG specification. |
Fields Summary |
---|
public static final JPEGHuffmanTable | StdDCLuminanceThe standard DC luminance Huffman table . | public static final JPEGHuffmanTable | StdDCChrominanceThe standard DC chrominance Huffman table. | public static final JPEGHuffmanTable | StdACLuminanceThe standard AC luminance Huffman table. | public static final JPEGHuffmanTable | StdACChrominanceThe standard AC chrominance Huffman table. | private short[] | lengthsThe lengths. | private short[] | valuesThe values. |
Constructors Summary |
---|
JPEGHuffmanTable(short[] lengths, short[] values, boolean copy)Instantiates a new jPEG huffman table.
// Construction of standard tables without checks
// The third param is dummy
// Could be also used for copying of the existing tables
this.lengths = lengths;
this.values = values;
| public JPEGHuffmanTable(short[] lengths, short[] values)Instantiates a new JPEGHuffmanTable.
if (lengths == null) {
throw new IllegalArgumentException("lengths array is null!");
}
if (values == null) {
throw new IllegalArgumentException("values array is null!");
}
if (lengths.length > 16) { // According to the spec
throw new IllegalArgumentException("lengths array is too long!");
}
if (values.length > 256) { // According to the spec
throw new IllegalArgumentException("values array is too long");
}
for (short length : lengths) {
if (length < 0) {
throw new IllegalArgumentException("Values in lengths array must be non-negative.");
}
}
for (short value : values) {
if (value < 0) {
throw new IllegalArgumentException("Values in values array must be non-negative.");
}
}
checkHuffmanTable(lengths, values);
this.lengths = new short[lengths.length];
this.values = new short[values.length];
System.arraycopy(lengths, 0, this.lengths, 0, lengths.length);
System.arraycopy(values, 0, this.values, 0, values.length);
|
Methods Summary |
---|
private static void | checkHuffmanTable(short[] lengths, short[] values)Check huffman table.
int numLeaves = 0;
int possibleLeaves = 2;
for (short length : lengths) {
numLeaves += length;
possibleLeaves -= length;
if (possibleLeaves < 0) {
throw new IllegalArgumentException(
"Invalid Huffman table provided, lengths are incorrect.");
}
possibleLeaves <<= 1;
}
if (values.length != numLeaves) {
throw new IllegalArgumentException(
"Invalid Huffman table provided, sum of lengths != values.");
}
| public short[] | getLengths()Gets an array of lengths in the Huffman table.
short newLengths[] = new short[lengths.length];
System.arraycopy(lengths, 0, newLengths, 0, lengths.length);
return newLengths;
| public short[] | getValues()Gets an array of values represented by increasing length of their codes.
short newValues[] = new short[values.length];
System.arraycopy(values, 0, newValues, 0, values.length);
return newValues;
| public java.lang.String | toString()Returns the string representation of this JPEGHuffmanTable object.
StringBuffer sb = new StringBuffer();
sb.append("JPEGHuffmanTable:\nlengths:");
for (short length : lengths) {
sb.append(' ").append(length);
}
sb.append("\nvalues:");
for (short value : values) {
sb.append(' ").append(value);
}
return sb.toString();
|
|