mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-02 19:15:29 -04:00
TMI-TIFF: Code clean-up.
This commit is contained in:
parent
09444ab083
commit
61e01e3316
@ -35,12 +35,14 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements Lempel-Ziv & Welch (LZW) decompression.
|
* Lempel–Ziv–Welch (LZW) decompression. LZW is a universal loss-less data compression algorithm
|
||||||
|
* created by Abraham Lempel, Jacob Ziv, and Terry Welch.
|
||||||
* Inspired by libTiff's LZW decompression.
|
* Inspired by libTiff's LZW decompression.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||||
* @author last modified by $Author: haraldk$
|
* @author last modified by $Author: haraldk$
|
||||||
* @version $Id: LZWDecoder.java,v 1.0 08.05.12 21:11 haraldk Exp$
|
* @version $Id: LZWDecoder.java,v 1.0 08.05.12 21:11 haraldk Exp$
|
||||||
|
* @see <a href="http://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch">LZW (Wikipedia)</a>
|
||||||
*/
|
*/
|
||||||
abstract class LZWDecoder implements Decoder {
|
abstract class LZWDecoder implements Decoder {
|
||||||
/** Clear: Re-initialize tables. */
|
/** Clear: Re-initialize tables. */
|
||||||
@ -51,6 +53,8 @@ abstract class LZWDecoder implements Decoder {
|
|||||||
private static final int MIN_BITS = 9;
|
private static final int MIN_BITS = 9;
|
||||||
private static final int MAX_BITS = 12;
|
private static final int MAX_BITS = 12;
|
||||||
|
|
||||||
|
private static final int TABLE_SIZE = 1 << MAX_BITS;
|
||||||
|
|
||||||
private final boolean compatibilityMode;
|
private final boolean compatibilityMode;
|
||||||
|
|
||||||
private final String[] table;
|
private final String[] table;
|
||||||
@ -68,7 +72,7 @@ abstract class LZWDecoder implements Decoder {
|
|||||||
protected LZWDecoder(final boolean compatibilityMode) {
|
protected LZWDecoder(final boolean compatibilityMode) {
|
||||||
this.compatibilityMode = compatibilityMode;
|
this.compatibilityMode = compatibilityMode;
|
||||||
|
|
||||||
table = new String[compatibilityMode ? 4096 + 1024 : 4096]; // libTiff adds 1024 "for compatibility"...
|
table = new String[compatibilityMode ? TABLE_SIZE + 1024 : TABLE_SIZE]; // libTiff adds 1024 "for compatibility"...
|
||||||
|
|
||||||
// First 258 entries of table is always fixed
|
// First 258 entries of table is always fixed
|
||||||
for (int i = 0; i < 256; i++) {
|
for (int i = 0; i < 256; i++) {
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.tiff;
|
package com.twelvemonkeys.imageio.plugins.tiff;
|
||||||
|
|
||||||
|
import com.twelvemonkeys.lang.Validate;
|
||||||
|
|
||||||
import java.awt.image.DataBufferByte;
|
import java.awt.image.DataBufferByte;
|
||||||
import java.awt.image.Raster;
|
import java.awt.image.Raster;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
@ -64,8 +66,8 @@ final class YCbCrUpsamplerStream extends FilterInputStream {
|
|||||||
int bufferLength;
|
int bufferLength;
|
||||||
int bufferPos;
|
int bufferPos;
|
||||||
|
|
||||||
public YCbCrUpsamplerStream(InputStream stream, int[] chromaSub, int yCbCrPos, int columns, double[] coefficients) {
|
public YCbCrUpsamplerStream(final InputStream stream, final int[] chromaSub, final int yCbCrPos, final int columns, final double[] coefficients) {
|
||||||
super(stream);
|
super(Validate.notNull(stream, "stream"));
|
||||||
|
|
||||||
this.horizChromaSub = chromaSub[0];
|
this.horizChromaSub = chromaSub[0];
|
||||||
this.vertChromaSub = chromaSub[1];
|
this.vertChromaSub = chromaSub[1];
|
||||||
@ -94,7 +96,7 @@ final class YCbCrUpsamplerStream extends FilterInputStream {
|
|||||||
int read;
|
int read;
|
||||||
|
|
||||||
// This *SHOULD* read an entire row of units into the buffer, otherwise decodeRows will throw EOFException
|
// This *SHOULD* read an entire row of units into the buffer, otherwise decodeRows will throw EOFException
|
||||||
while (pos < buffer.length && (read = super.read(buffer, pos, buffer.length - pos)) > 0) {
|
while (pos < buffer.length && (read = in.read(buffer, pos, buffer.length - pos)) > 0) {
|
||||||
pos += read;
|
pos += read;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +170,7 @@ final class YCbCrUpsamplerStream extends FilterInputStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return decodedRows[decodedPos++];
|
return decodedRows[decodedPos++] & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user