Skip to content

Commit

Permalink
Merge 1942832 into 471475c
Browse files Browse the repository at this point in the history
  • Loading branch information
arturobernalg committed Jun 15, 2021
2 parents 471475c + 1942832 commit a8a3917
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 43 deletions.
Expand Up @@ -1003,7 +1003,6 @@ public void writeImage(final BufferedImage src, final OutputStream os, Map<Strin
// boolean LocalColorTableFlag = false;
final boolean interlaceFlag = false;
final boolean sortFlag = false;
final int sizeOfLocalColorTable = colorTableScaleLessOne;

// int SizeOfLocalColorTable = 0;

Expand All @@ -1012,12 +1011,12 @@ public void writeImage(final BufferedImage src, final OutputStream os, Map<Strin
packedFields = (LOCAL_COLOR_TABLE_FLAG_MASK
| (interlaceFlag ? INTERLACE_FLAG_MASK : 0)
| (sortFlag ? SORT_FLAG_MASK : 0)
| (7 & sizeOfLocalColorTable));
| (7 & colorTableScaleLessOne));
} else {
packedFields = (0
| (interlaceFlag ? INTERLACE_FLAG_MASK : 0)
| (sortFlag ? SORT_FLAG_MASK : 0)
| (7 & sizeOfLocalColorTable));
| (7 & colorTableScaleLessOne));
}
bos.write(packedFields); // one byte
}
Expand Down
Expand Up @@ -282,15 +282,14 @@ public static void inverseDCT8(final float[] vector) {
final float n1 = vector[0] - vector[4];
final float n2 = b2 - a3;
final float n3 = vector[0] + vector[4];
final float neg_n5 = neg_b4;

// A2
final float m3 = n1 + n2;
final float m4 = n3 + a3;
final float m5 = n1 - n2;
final float m6 = n3 - a3;
// float m7 = n5 - n0;
final float neg_m7 = neg_n5 + n0;
// float m7 = b4 - n0;
final float neg_m7 = neg_b4 + n0;

// A3
vector[0] = m4 + a7;
Expand Down
Expand Up @@ -242,43 +242,41 @@ public boolean visitSegment(final int marker, final byte[] markerBytes,
} else if (marker == JpegConstants.DQT_MARKER) {
final DqtSegment dqtSegment = new DqtSegment(marker, segmentData);
for (final QuantizationTable element : dqtSegment.quantizationTables) {
final DqtSegment.QuantizationTable table = element;
if (0 > table.destinationIdentifier
|| table.destinationIdentifier >= quantizationTables.length) {
if (0 > element.destinationIdentifier
|| element.destinationIdentifier >= quantizationTables.length) {
throw new ImageReadException(
"Invalid quantization table identifier "
+ table.destinationIdentifier);
+ element.destinationIdentifier);
}
quantizationTables[table.destinationIdentifier] = table;
quantizationTables[element.destinationIdentifier] = element;
final int[] quantizationMatrixInt = new int[64];
ZigZag.zigZagToBlock(table.getElements(), quantizationMatrixInt);
ZigZag.zigZagToBlock(element.getElements(), quantizationMatrixInt);
final float[] quantizationMatrixFloat = new float[64];
for (int j = 0; j < 64; j++) {
quantizationMatrixFloat[j] = quantizationMatrixInt[j];
}
Dct.scaleDequantizationMatrix(quantizationMatrixFloat);
scaledQuantizationTables[table.destinationIdentifier] = quantizationMatrixFloat;
scaledQuantizationTables[element.destinationIdentifier] = quantizationMatrixFloat;
}
} else if (marker == JpegConstants.DHT_MARKER) {
final DhtSegment dhtSegment = new DhtSegment(marker, segmentData);
for (final HuffmanTable element : dhtSegment.huffmanTables) {
final DhtSegment.HuffmanTable table = element;
DhtSegment.HuffmanTable[] tables;
if (table.tableClass == 0) {
if (element.tableClass == 0) {
tables = huffmanDCTables;
} else if (table.tableClass == 1) {
} else if (element.tableClass == 1) {
tables = huffmanACTables;
} else {
throw new ImageReadException("Invalid huffman table class "
+ table.tableClass);
+ element.tableClass);
}
if (0 > table.destinationIdentifier
|| table.destinationIdentifier >= tables.length) {
if (0 > element.destinationIdentifier
|| element.destinationIdentifier >= tables.length) {
throw new ImageReadException(
"Invalid huffman table identifier "
+ table.destinationIdentifier);
+ element.destinationIdentifier);
}
tables[table.destinationIdentifier] = table;
tables[element.destinationIdentifier] = element;
}
}
return true;
Expand Down Expand Up @@ -376,16 +374,14 @@ private void readMCU(final JpegInputStream is, final int[] preds, final Block[]
is,
huffmanACTables[scanComponent.acCodingTableSelector]);
final int ssss = rs & 0xf;
final int rrrr = rs >> 4;
final int r = rrrr;

if (ssss == 0) {
if (r != 15) {
if (rs >> 4 != 15) {
break;
}
k += 16;
} else {
k += r;
k += rs >> 4;

// "Decode_ZZ(k)", figure F.14, page 107 of T.81
zz[k] = receive(ssss, is);
Expand Down
Expand Up @@ -254,9 +254,8 @@ public byte[] getICCProfileBytes(final ByteSource byteSource, final Map<String,
}

final PngChunkIccp pngChunkiCCP = (PngChunkIccp) chunks.get(0);
final byte[] bytes = pngChunkiCCP.getUncompressedProfile(); // TODO should this be a clone?

return (bytes);
return (pngChunkiCCP.getUncompressedProfile());
}

@Override
Expand Down
Expand Up @@ -102,15 +102,14 @@ public BufferedImage getBufferedImage(final ByteSource byteSource, final Map<Str
final DataBuffer buffer = new DataBufferFloat(info.getPixelData(),
info.getWidth() * info.getHeight());

final BufferedImage ret = new BufferedImage(new ComponentColorModel(
return new BufferedImage(new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false,
Transparency.OPAQUE, buffer.getDataType()),
Raster.createWritableRaster(
new BandedSampleModel(buffer.getDataType(),
info.getWidth(), info.getHeight(), 3),
buffer,
new Point()), false, null);
return ret;
}
}

Expand Down
Expand Up @@ -85,26 +85,24 @@ private void interpretTile(final ImageBuilder imageBuilder, final byte[] bytes,
if (sampleFormat == TiffTagConstants.SAMPLE_FORMAT_VALUE_IEEE_FLOATING_POINT) {
// tileLength: number of rows in tile
// tileWidth: number of columns in tile
final int i0 = startY;
int i1 = startY + tileLength;
if (i1 > yLimit) {
// the tile is padded past bottom of image
i1 = yLimit;
}
final int j0 = startX;
int j1 = startX + tileWidth;
if (j1 > xLimit) {
// the tile is padded to beyond the tile width
j1 = xLimit;
}
final int[] samples = new int[4];
final int[] b = unpackFloatingPointSamples(
j1 - j0, i1 - i0, tileWidth, bytes,
j1 - startX, i1 - startY, tileWidth, bytes,
predictor, bitsPerPixel, byteOrder);
for (int i = i0; i < i1; i++) {
for (int i = startY; i < i1; i++) {
final int row = i - startY;
final int rowOffset = row * tileWidth;
for (int j = j0; j < j1; j++) {
for (int j = startX; j < j1; j++) {
final int column = j - startX;
samples[0] = b[rowOffset + column];
photometricInterpreter.interpretPixel(
Expand All @@ -129,29 +127,27 @@ private void interpretTile(final ImageBuilder imageBuilder, final byte[] bytes,

if ((bitsPerPixel == 24 || bitsPerPixel == 32) && allSamplesAreOneByte
&& photometricInterpreter instanceof PhotometricInterpreterRgb) {
final int i0 = startY;
int i1 = startY + tileLength;
if (i1 > yLimit) {
// the tile is padded past bottom of image
i1 = yLimit;
}
final int j0 = startX;
int j1 = startX + tileWidth;
if (j1 > xLimit) {
// the tile is padded to beyond the tile width
j1 = xLimit;
}

if (predictor == TiffTagConstants.PREDICTOR_VALUE_HORIZONTAL_DIFFERENCING) {
applyPredictorToBlock(tileWidth, i1 - i0, samplesPerPixel, bytes);
applyPredictorToBlock(tileWidth, i1 - startY, samplesPerPixel, bytes);
}

if (bitsPerPixel == 24) {
// 24 bit case, we don't mask the red byte because any
// sign-extended bits get covered by opacity mask
for (int i = i0; i < i1; i++) {
int k = (i - i0) * tileWidth * 3;
for (int j = j0; j < j1; j++, k += 3) {
for (int i = startY; i < i1; i++) {
int k = (i - startY) * tileWidth * 3;
for (int j = startX; j < j1; j++, k += 3) {
final int rgb = 0xff000000
| (bytes[k] << 16)
| ((bytes[k + 1] & 0xff) << 8)
Expand All @@ -162,9 +158,9 @@ private void interpretTile(final ImageBuilder imageBuilder, final byte[] bytes,
} else if (bitsPerPixel == 32) {
// 32 bit case, we don't mask the high byte because any
// sign-extended bits get shifted up and out of result.
for (int i = i0; i < i1; i++) {
int k = (i - i0) * tileWidth * 4;
for (int j = j0; j < j1; j++, k += 4) {
for (int i = startY; i < i1; i++) {
int k = (i - startY) * tileWidth * 4;
for (int j = startX; j < j1; j++, k += 4) {
final int rgb
= ((bytes[k] & 0xff) << 16)
| ((bytes[k + 1] & 0xff) << 8)
Expand Down

0 comments on commit a8a3917

Please sign in to comment.