WebP cleanup

This commit is contained in:
Harald Kuhr 2023-03-18 11:33:29 +01:00
parent 606fd53823
commit ac7612b3df
3 changed files with 31 additions and 36 deletions

View File

@ -62,7 +62,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import static com.twelvemonkeys.imageio.plugins.webp.lossless.VP8LDecoder.copyIntoRasterWithParams; import static com.twelvemonkeys.imageio.plugins.webp.lossless.VP8LDecoder.copyIntoRasterWithParams;
import static java.lang.Math.max; import static java.lang.Math.max;
import static java.lang.Math.min; import static java.lang.Math.min;
@ -134,8 +133,8 @@ final class WebPImageReader extends ImageReaderBase {
if (DEBUG) { if (DEBUG) {
System.out.printf("chunk: '%s'\n", fourCC(nextChunk)); System.out.printf("chunk: '%s'\n", fourCC(nextChunk));
System.out.println("chunkLength: " + chunkLength);
System.out.println("chunkStart: " + chunkStart); System.out.println("chunkStart: " + chunkStart);
System.out.println("chunkLength: " + chunkLength);
} }
switch (nextChunk) { switch (nextChunk) {
@ -473,8 +472,8 @@ final class WebPImageReader extends ImageReaderBase {
if (DEBUG) { if (DEBUG) {
System.out.printf("chunk: '%s'\n", fourCC(nextChunk)); System.out.printf("chunk: '%s'\n", fourCC(nextChunk));
System.out.println("chunkLength: " + chunkLength);
System.out.println("chunkStart: " + chunkStart); System.out.println("chunkStart: " + chunkStart);
System.out.println("chunkLength: " + chunkLength);
} }
switch (nextChunk) { switch (nextChunk) {
@ -684,8 +683,8 @@ final class WebPImageReader extends ImageReaderBase {
long chunkStart = imageInput.getStreamPosition(); long chunkStart = imageInput.getStreamPosition();
// System.err.printf("chunk: '%s'\n", fourCC(nextChunk)); // System.err.printf("chunk: '%s'\n", fourCC(nextChunk));
// System.err.println("chunkLength: " + chunkLength);
// System.err.println("chunkStart: " + chunkStart); // System.err.println("chunkStart: " + chunkStart);
// System.err.println("chunkLength: " + chunkLength);
switch (nextChunk) { switch (nextChunk) {
case WebP.CHUNK_EXIF: case WebP.CHUNK_EXIF:

View File

@ -67,6 +67,11 @@ final class ColorIndexingTransform implements Transform {
// Arraycopy for 4 elements might not be beneficial // Arraycopy for 4 elements might not be beneficial
System.arraycopy(colorTable, index * 4, rgba, 0, 4); System.arraycopy(colorTable, index * 4, rgba, 0, 4);
// rgba[0] = colorTable[index * 4];
// rgba[1] = colorTable[index * 4 + 1];
// rgba[2] = colorTable[index * 4 + 2];
// rgba[3] = colorTable[index * 4 + 3];
raster.setDataElements(x, y, rgba); raster.setDataElements(x, y, rgba);
} }
} }

View File

@ -35,11 +35,11 @@ import javax.imageio.stream.ImageInputStream;
import java.io.IOException; import java.io.IOException;
final class BoolDecoder { final class BoolDecoder {
private int bit_count; /* # of bits shifted out of value, at most 7 */ private int bitCount; // # of bits shifted out of value, at most 7
ImageInputStream data; ImageInputStream data;
private long offset; /* pointer to next compressed data byte */ private long offset; // pointer to next compressed data byte
private int range; /* always identical to encoder's range */ private int range; // always identical to encoder's range
private int value; /* contains at least 24 significant bits */ private int value; // contains at least 24 significant bits
BoolDecoder(ImageInputStream frame, long offset) throws IOException { BoolDecoder(ImageInputStream frame, long offset) throws IOException {
this.data = frame; this.data = frame;
@ -48,15 +48,15 @@ final class BoolDecoder {
} }
private void initBoolDecoder() throws IOException { private void initBoolDecoder() throws IOException {
value = 0; /* value = first 16 input bits */ value = 0; // value = first 16 input bits
data.seek(offset); data.seek(offset);
value = data.readUnsignedByte() << 8; value = data.readUnsignedByte() << 8;
// value = (data[offset]) << 8; // value = (data[offset]) << 8;
offset++; offset++;
range = 255; /* initial range is full */ range = 255; // initial range is full
bit_count = 0; /* have not yet shifted out any bits */ bitCount = 0; // have not yet shifted out any bits
} }
public int readBit() throws IOException { public int readBit() throws IOException {
@ -66,21 +66,21 @@ final class BoolDecoder {
public int readBool(int probability) throws IOException { public int readBool(int probability) throws IOException {
int bit = 0; int bit = 0;
int split; int split;
int bigsplit; int bigSplit;
int range = this.range; int range = this.range;
int value = this.value; int value = this.value;
split = 1 + (((range - 1) * probability) >> 8); split = 1 + (((range - 1) * probability) >> 8);
bigsplit = (split << 8); bigSplit = (split << 8);
range = split; range = split;
if (value >= bigsplit) { if (value >= bigSplit) {
range = this.range - split; range = this.range - split;
value = value - bigsplit; value = value - bigSplit;
bit = 1; bit = 1;
} }
{ {
int count = this.bit_count; int count = this.bitCount;
int shift = Globals.vp8dxBitreaderNorm[range]; int shift = Globals.vp8dxBitreaderNorm[range];
range <<= shift; range <<= shift;
value <<= shift; value <<= shift;
@ -94,44 +94,35 @@ final class BoolDecoder {
count += 8; count += 8;
} }
this.bit_count = count; this.bitCount = count;
} }
this.value = value; this.value = value;
this.range = range; this.range = range;
return bit; return bit;
} }
/* /**
* Convenience function reads a "literal", that is, a "num_bits" wide * Convenience method reads a "literal", that is, a "numBits" wide
* unsigned value whose bits come high- to low-order, with each bit encoded * unsigned value whose bits come high- to low-order, with each bit encoded
* at probability 128 (i.e., 1/2). * at probability 128 (i.e., 1/2).
*/ */
public int readLiteral(int num_bits) throws IOException { public int readLiteral(int numBits) throws IOException {
int v = 0; int v = 0;
while (num_bits-- > 0) { while (numBits-- > 0) {
v = (v << 1) + readBool(128); v = (v << 1) + readBool(128);
} }
return v; return v;
} }
// int readTree(int t[], /* tree specification */ int p[] /* corresponding interior node probabilities */) throws IOException { int readTree(int[] t, /* tree specification */ int[] p, /* corresponding interior node probabilities */ int skipBranches) throws IOException {
// int i = 0; /* begin at root */ int i = skipBranches * 2; // begin at root
//
// /* Descend tree until leaf is reached */
// while ((i = t[i + readBool(p[i >> 1])]) > 0) {
// }
// return -i; /* return value is negation of nonpositive index */
//
// }
//
// int readTree(int t[], /* tree specification */ int p[], /* corresponding interior node probabilities */ int skip_branches) throws IOException {
int readTree(int[] t, /* tree specification */ int[] p, /* corresponding interior node probabilities */ int skip_branches) throws IOException {
int i = skip_branches * 2; /* begin at root */
/* Descend tree until leaf is reached */ // Descend tree until leaf is reached
while ((i = t[i + readBool(p[i >> 1])]) > 0) { while ((i = t[i + readBool(p[i >> 1])]) > 0) {
} }
return -i; /* return value is negation of nonpositive index */ return -i; // return value is negation of nonpositive index
} }
public void seek() throws IOException { public void seek() throws IOException {