You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by vh...@apache.org on 2014/03/11 18:49:36 UTC
svn commit: r1576437 [2/5] - in /xmlgraphics/commons/trunk: ./
src/java/org/apache/xmlgraphics/image/
src/java/org/apache/xmlgraphics/image/codec/png/
src/java/org/apache/xmlgraphics/image/codec/tiff/
src/java/org/apache/xmlgraphics/image/codec/util/ s...
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGImageDecoder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGImageDecoder.java?rev=1576437&r1=1576436&r2=1576437&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGImageDecoder.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGImageDecoder.java Tue Mar 11 17:49:35 2014
@@ -159,7 +159,7 @@ class PNGImage extends SimpleRenderedIma
private boolean emitProperties = true;
- private float fileGamma = 45455/100000.0F;
+ private float fileGamma = 45455 / 100000.0F;
private float userExponent = 1.0F;
@@ -244,15 +244,15 @@ class PNGImage extends SimpleRenderedIma
private int[] gammaLut = null;
private void initGammaLut(int bits) {
- double exp = (double)userExponent/(fileGamma*displayExponent);
+ double exp = (double)userExponent / (fileGamma * displayExponent);
int numSamples = 1 << bits;
int maxOutSample = (bits == 16) ? 65535 : 255;
gammaLut = new int[numSamples];
for (int i = 0; i < numSamples; i++) {
- double gbright = (double)i/(numSamples - 1);
+ double gbright = (double)i / (numSamples - 1);
double gamma = Math.pow(gbright, exp);
- int igamma = (int)(gamma*maxOutSample + 0.5);
+ int igamma = (int)(gamma * maxOutSample + 0.5);
if (igamma > maxOutSample) {
igamma = maxOutSample;
}
@@ -423,8 +423,8 @@ class PNGImage extends SimpleRenderedIma
bitDepth = chunk.getInt1(8);
- if ((bitDepth != 1) && (bitDepth != 2) && (bitDepth != 4) &&
- (bitDepth != 8) && (bitDepth != 16)) {
+ if ((bitDepth != 1) && (bitDepth != 2) && (bitDepth != 4)
+ && (bitDepth != 8) && (bitDepth != 16)) {
// Error -- bad bit depth
String msg = PropertyUtil.getString("PNGImageDecoder3");
throw new RuntimeException(msg);
@@ -432,11 +432,11 @@ class PNGImage extends SimpleRenderedIma
maxOpacity = (1 << bitDepth) - 1;
colorType = chunk.getInt1(9);
- if ((colorType != PNG_COLOR_GRAY) &&
- (colorType != PNG_COLOR_RGB) &&
- (colorType != PNG_COLOR_PALETTE) &&
- (colorType != PNG_COLOR_GRAY_ALPHA) &&
- (colorType != PNG_COLOR_RGB_ALPHA)) {
+ if ((colorType != PNG_COLOR_GRAY)
+ && (colorType != PNG_COLOR_RGB)
+ && (colorType != PNG_COLOR_PALETTE)
+ && (colorType != PNG_COLOR_GRAY_ALPHA)
+ && (colorType != PNG_COLOR_RGB_ALPHA)) {
System.out.println(PropertyUtil.getString("PNGImageDecoder4"));
}
@@ -471,8 +471,8 @@ class PNGImage extends SimpleRenderedIma
if (generateEncodeParam) {
if (colorType == PNG_COLOR_PALETTE) {
encodeParam = new PNGEncodeParam.Palette();
- } else if (colorType == PNG_COLOR_GRAY ||
- colorType == PNG_COLOR_GRAY_ALPHA) {
+ } else if (colorType == PNG_COLOR_GRAY
+ || colorType == PNG_COLOR_GRAY_ALPHA) {
encodeParam = new PNGEncodeParam.Gray();
} else {
encodeParam = new PNGEncodeParam.RGB();
@@ -489,7 +489,7 @@ class PNGImage extends SimpleRenderedIma
if (performGammaCorrection) {
// Assume file gamma is 1/2.2 unless we get a gAMA chunk
- float gamma = (1.0F/2.2F)*(displayExponent/userExponent);
+ float gamma = (1.0F / 2.2F) * (displayExponent / userExponent);
if (encodeParam != null) {
encodeParam.setGamma(gamma);
}
@@ -614,12 +614,12 @@ class PNGImage extends SimpleRenderedIma
private void parse_IEND_chunk(PNGChunk chunk) throws Exception {
// Store text strings
int textLen = textKeys.size();
- String[] textArray = new String[2*textLen];
+ String[] textArray = new String[2 * textLen];
for (int i = 0; i < textLen; i++) {
String key = (String)textKeys.get(i);
String val = (String)textStrings.get(i);
- textArray[2*i] = key;
- textArray[2*i + 1] = val;
+ textArray[2 * i] = key;
+ textArray[2 * i + 1] = val;
if (emitProperties) {
String uniqueKey = "text_" + i + ':' + key;
properties.put(uniqueKey.toLowerCase(), val);
@@ -631,12 +631,12 @@ class PNGImage extends SimpleRenderedIma
// Store compressed text strings
int ztextLen = ztextKeys.size();
- String[] ztextArray = new String[2*ztextLen];
+ String[] ztextArray = new String[2 * ztextLen];
for (int i = 0; i < ztextLen; i++) {
String key = (String)ztextKeys.get(i);
String val = (String)ztextStrings.get(i);
- ztextArray[2*i] = key;
- ztextArray[2*i + 1] = val;
+ ztextArray[2 * i] = key;
+ ztextArray[2 * i + 1] = val;
if (emitProperties) {
String uniqueKey = "ztext_" + i + ':' + key;
properties.put(uniqueKey.toLowerCase(), val);
@@ -655,16 +655,16 @@ class PNGImage extends SimpleRenderedIma
// Create an empty WritableRaster
int depth = bitDepth;
- if ((colorType == PNG_COLOR_GRAY) &&
- (bitDepth < 8) && output8BitGray) {
+ if ((colorType == PNG_COLOR_GRAY)
+ && (bitDepth < 8) && output8BitGray) {
depth = 8;
}
if ((colorType == PNG_COLOR_PALETTE) && expandPalette) {
depth = 8;
}
- int bytesPerRow = (outputBands*width*depth + 7)/8;
+ int bytesPerRow = (outputBands * width * depth + 7) / 8;
int scanlineStride =
- (depth == 16) ? (bytesPerRow/2) : bytesPerRow;
+ (depth == 16) ? (bytesPerRow / 2) : bytesPerRow;
theTile = createRaster(width, height, outputBands,
scanlineStride,
@@ -673,9 +673,9 @@ class PNGImage extends SimpleRenderedIma
if (performGammaCorrection && (gammaLut == null)) {
initGammaLut(bitDepth);
}
- if ((postProcess == POST_GRAY_LUT) ||
- (postProcess == POST_GRAY_LUT_ADD_TRANS) ||
- (postProcess == POST_GRAY_LUT_ADD_TRANS_EXP)) {
+ if ((postProcess == POST_GRAY_LUT)
+ || (postProcess == POST_GRAY_LUT_ADD_TRANS)
+ || (postProcess == POST_GRAY_LUT_ADD_TRANS_EXP)) {
initGrayLut(bitDepth);
}
@@ -697,8 +697,8 @@ class PNGImage extends SimpleRenderedIma
greenPalette,
bluePalette);
}
- } else if ((colorType == PNG_COLOR_GRAY) &&
- (bitDepth < 8) && !output8BitGray) {
+ } else if ((colorType == PNG_COLOR_GRAY)
+ && (bitDepth < 8) && !output8BitGray) {
byte[] palette = expandBits[bitDepth];
colorModel = new IndexColorModel(bitDepth,
palette.length,
@@ -860,7 +860,7 @@ class PNGImage extends SimpleRenderedIma
}
private void parse_PLTE_chunk(PNGChunk chunk) {
- paletteEntries = chunk.getLength()/3;
+ paletteEntries = chunk.getLength() / 3;
redPalette = new byte[paletteEntries];
greenPalette = new byte[paletteEntries];
bluePalette = new byte[paletteEntries];
@@ -901,8 +901,7 @@ class PNGImage extends SimpleRenderedIma
bkgdBlue = bluePalette[bkgdIndex] & 0xff;
if (encodeParam != null) {
- ((PNGEncodeParam.Palette)encodeParam).
- setBackgroundPaletteIndex(bkgdIndex);
+ ((PNGEncodeParam.Palette)encodeParam).setBackgroundPaletteIndex(bkgdIndex);
}
break;
case PNG_COLOR_GRAY: case PNG_COLOR_GRAY_ALPHA:
@@ -910,8 +909,7 @@ class PNGImage extends SimpleRenderedIma
bkgdRed = bkgdGreen = bkgdBlue = bkgdGray;
if (encodeParam != null) {
- ((PNGEncodeParam.Gray)encodeParam).
- setBackgroundGray(bkgdGray);
+ ((PNGEncodeParam.Gray)encodeParam).setBackgroundGray(bkgdGray);
}
break;
case PNG_COLOR_RGB: case PNG_COLOR_RGB_ALPHA:
@@ -924,13 +922,14 @@ class PNGImage extends SimpleRenderedIma
bkgdRGB[1] = bkgdGreen;
bkgdRGB[2] = bkgdBlue;
if (encodeParam != null) {
- ((PNGEncodeParam.RGB)encodeParam).
- setBackgroundRGB(bkgdRGB);
+ ((PNGEncodeParam.RGB)encodeParam).setBackgroundRGB(bkgdRGB);
}
break;
}
- int r = 0, g = 0, b = 0;
+ int r = 0;
+ int g = 0;
+ int b = 0;
if (bitDepth < 8) {
r = expandBits[bitDepth][bkgdRed];
g = expandBits[bitDepth][bkgdGreen];
@@ -956,14 +955,14 @@ class PNGImage extends SimpleRenderedIma
}
chromaticity = new float[8];
- chromaticity[0] = chunk.getInt4(0)/100000.0F;
- chromaticity[1] = chunk.getInt4(4)/100000.0F;
- chromaticity[2] = chunk.getInt4(8)/100000.0F;
- chromaticity[3] = chunk.getInt4(12)/100000.0F;
- chromaticity[4] = chunk.getInt4(16)/100000.0F;
- chromaticity[5] = chunk.getInt4(20)/100000.0F;
- chromaticity[6] = chunk.getInt4(24)/100000.0F;
- chromaticity[7] = chunk.getInt4(28)/100000.0F;
+ chromaticity[0] = chunk.getInt4(0) / 100000.0F;
+ chromaticity[1] = chunk.getInt4(4) / 100000.0F;
+ chromaticity[2] = chunk.getInt4(8) / 100000.0F;
+ chromaticity[3] = chunk.getInt4(12) / 100000.0F;
+ chromaticity[4] = chunk.getInt4(16) / 100000.0F;
+ chromaticity[5] = chunk.getInt4(20) / 100000.0F;
+ chromaticity[6] = chunk.getInt4(24) / 100000.0F;
+ chromaticity[7] = chunk.getInt4(28) / 100000.0F;
if (encodeParam != null) {
encodeParam.setChromaticity(chromaticity);
@@ -986,15 +985,15 @@ class PNGImage extends SimpleRenderedIma
return;
}
- fileGamma = chunk.getInt4(0)/100000.0F;
+ fileGamma = chunk.getInt4(0) / 100000.0F;
float exp =
- performGammaCorrection ? displayExponent/userExponent : 1.0F;
+ performGammaCorrection ? displayExponent / userExponent : 1.0F;
if (encodeParam != null) {
- encodeParam.setGamma(fileGamma*exp);
+ encodeParam.setGamma(fileGamma * exp);
}
if (emitProperties) {
- properties.put("gamma", new Float(fileGamma*exp));
+ properties.put("gamma", new Float(fileGamma * exp));
}
}
@@ -1007,7 +1006,7 @@ class PNGImage extends SimpleRenderedIma
int length = redPalette.length;
int[] hist = new int[length];
for (int i = 0; i < length; i++) {
- hist[i] = chunk.getInt2(2*i);
+ hist[i] = chunk.getInt2(2 * i);
}
if (encodeParam != null) {
@@ -1039,7 +1038,7 @@ class PNGImage extends SimpleRenderedIma
properties.put("x_pixels_per_unit", new Integer(xPixelsPerUnit));
properties.put("y_pixels_per_unit", new Integer(yPixelsPerUnit));
properties.put("pixel_aspect_ratio",
- new Float((float)xPixelsPerUnit/yPixelsPerUnit));
+ new Float((float)xPixelsPerUnit / yPixelsPerUnit));
if (unitSpecifier == 1) {
properties.put("pixel_units", "Meters");
} else if (unitSpecifier != 0) {
@@ -1081,21 +1080,21 @@ class PNGImage extends SimpleRenderedIma
// The presence of an sRGB chunk implies particular
// settings for gamma and chroma.
- fileGamma = 45455/100000.0F;
+ fileGamma = 45455 / 100000.0F;
chromaticity = new float[8];
- chromaticity[0] = 31270/10000.0F;
- chromaticity[1] = 32900/10000.0F;
- chromaticity[2] = 64000/10000.0F;
- chromaticity[3] = 33000/10000.0F;
- chromaticity[4] = 30000/10000.0F;
- chromaticity[5] = 60000/10000.0F;
- chromaticity[6] = 15000/10000.0F;
- chromaticity[7] = 6000/10000.0F;
+ chromaticity[0] = 31270 / 10000.0F;
+ chromaticity[1] = 32900 / 10000.0F;
+ chromaticity[2] = 64000 / 10000.0F;
+ chromaticity[3] = 33000 / 10000.0F;
+ chromaticity[4] = 30000 / 10000.0F;
+ chromaticity[5] = 60000 / 10000.0F;
+ chromaticity[6] = 15000 / 10000.0F;
+ chromaticity[7] = 6000 / 10000.0F;
if (performGammaCorrection) {
// File gamma is 1/2.2
- float gamma = fileGamma*(displayExponent/userExponent);
+ float gamma = fileGamma * (displayExponent / userExponent);
if (encodeParam != null) {
encodeParam.setGamma(gamma);
encodeParam.setChromaticity(chromaticity);
@@ -1120,7 +1119,7 @@ class PNGImage extends SimpleRenderedIma
StringBuffer key = new StringBuffer();
int textIndex = 0;
while ((b = chunk.getByte(textIndex++)) != 0) {
- key.append( (char)b );
+ key.append((char)b);
}
StringBuilder value = new StringBuilder();
@@ -1203,8 +1202,7 @@ class PNGImage extends SimpleRenderedIma
}
if (encodeParam != null) {
- ((PNGEncodeParam.Gray)encodeParam).
- setTransparentGray(grayTransparentAlpha);
+ ((PNGEncodeParam.Gray)encodeParam).setTransparentGray(grayTransparentAlpha);
}
}
} else if (colorType == PNG_COLOR_RGB) {
@@ -1221,12 +1219,11 @@ class PNGImage extends SimpleRenderedIma
rgbTrans[0] = redTransparentAlpha;
rgbTrans[1] = greenTransparentAlpha;
rgbTrans[2] = blueTransparentAlpha;
- ((PNGEncodeParam.RGB)encodeParam).
- setTransparentRGB(rgbTrans);
+ ((PNGEncodeParam.RGB)encodeParam).setTransparentRGB(rgbTrans);
}
}
- } else if (colorType == PNG_COLOR_GRAY_ALPHA ||
- colorType == PNG_COLOR_RGB_ALPHA) {
+ } else if (colorType == PNG_COLOR_GRAY_ALPHA
+ || colorType == PNG_COLOR_RGB_ALPHA) {
// Error -- GA or RGBA image can't have a tRNS chunk.
String msg = PropertyUtil.getString("PNGImageDecoder15");
throw new RuntimeException(msg);
@@ -1239,7 +1236,7 @@ class PNGImage extends SimpleRenderedIma
StringBuffer key = new StringBuffer();
byte b;
while ((b = chunk.getByte(textIndex++)) != 0) {
- key.append( (char)b );
+ key.append((char)b);
}
/* int method = */ chunk.getByte(textIndex++);
@@ -1271,13 +1268,13 @@ class PNGImage extends SimpleRenderedIma
WritableRaster ras = null;
Point origin = new Point(0, 0);
if ((bitDepth < 8) && (bands == 1)) {
- dataBuffer = new DataBufferByte(height*scanlineStride);
+ dataBuffer = new DataBufferByte(height * scanlineStride);
ras = Raster.createPackedRaster(dataBuffer,
width, height,
bitDepth,
origin);
} else if (bitDepth <= 8) {
- dataBuffer = new DataBufferByte(height*scanlineStride);
+ dataBuffer = new DataBufferByte(height * scanlineStride);
ras = Raster.createInterleavedRaster(dataBuffer,
width, height,
scanlineStride,
@@ -1285,7 +1282,7 @@ class PNGImage extends SimpleRenderedIma
bandOffsets[bands],
origin);
} else {
- dataBuffer = new DataBufferUShort(height*scanlineStride);
+ dataBuffer = new DataBufferUShort(height * scanlineStride);
ras = Raster.createInterleavedRaster(dataBuffer,
width, height,
scanlineStride,
@@ -1322,13 +1319,15 @@ class PNGImage extends SimpleRenderedIma
private static void decodeAverageFilter(byte[] curr, byte[] prev,
int count, int bpp) {
- int raw, priorPixel, priorRow;
+ int raw;
+ int priorPixel;
+ int priorRow;
for (int i = 0; i < bpp; i++) {
raw = curr[i] & 0xff;
priorRow = prev[i] & 0xff;
- curr[i] = (byte)(raw + priorRow/2);
+ curr[i] = (byte)(raw + priorRow / 2);
}
for (int i = bpp; i < count; i++) {
@@ -1336,13 +1335,16 @@ class PNGImage extends SimpleRenderedIma
priorPixel = curr[i - bpp] & 0xff;
priorRow = prev[i] & 0xff;
- curr[i] = (byte)(raw + (priorPixel + priorRow)/2);
+ curr[i] = (byte)(raw + (priorPixel + priorRow) / 2);
}
}
private static void decodePaethFilter(byte[] curr, byte[] prev,
int count, int bpp) {
- int raw, priorPixel, priorRow, priorRowPixel;
+ int raw;
+ int priorPixel;
+ int priorRow;
+ int priorRowPixel;
for (int i = 0; i < bpp; i++) {
raw = curr[i] & 0xff;
@@ -1366,7 +1368,8 @@ class PNGImage extends SimpleRenderedIma
private void processPixels(int process,
Raster src, WritableRaster dst,
int xOffset, int step, int y, int width) {
- int srcX, dstX;
+ int srcX;
+ int dstX;
// Create an array suitable for holding one pixel
int[] ps = src.getPixel(0, 0, (int[])null);
@@ -1489,9 +1492,9 @@ class PNGImage extends SimpleRenderedIma
pd[1] = g;
pd[2] = b;
}
- if ((r == redTransparentAlpha) &&
- (g == greenTransparentAlpha) &&
- (b == blueTransparentAlpha)) {
+ if ((r == redTransparentAlpha)
+ && (g == greenTransparentAlpha)
+ && (b == blueTransparentAlpha)) {
pd[3] = 0;
} else {
pd[3] = maxOpacity;
@@ -1629,8 +1632,8 @@ class PNGImage extends SimpleRenderedIma
return;
}
- int bytesPerRow = (inputBands*passWidth*bitDepth + 7)/8;
- int eltsPerRow = (bitDepth == 16) ? bytesPerRow/2 : bytesPerRow;
+ int bytesPerRow = (inputBands * passWidth * bitDepth + 7) / 8;
+ int eltsPerRow = (bitDepth == 16) ? bytesPerRow / 2 : bytesPerRow;
byte[] curr = new byte[bytesPerRow];
byte[] prior = new byte[bytesPerRow];
@@ -1650,7 +1653,8 @@ class PNGImage extends SimpleRenderedIma
}
// Decode the (sub)image row-by-row
- int srcY, dstY;
+ int srcY;
+ int dstY;
for (srcY = 0, dstY = yOffset;
srcY < passHeight;
srcY++, dstY += yStep) {
@@ -1710,13 +1714,13 @@ class PNGImage extends SimpleRenderedIma
if (!useInterlacing) {
decodePass(theTile, 0, 0, 1, 1, width, height);
} else {
- decodePass(theTile, 0, 0, 8, 8, (width + 7)/8, (height + 7)/8);
- decodePass(theTile, 4, 0, 8, 8, (width + 3)/8, (height + 7)/8);
- decodePass(theTile, 0, 4, 4, 8, (width + 3)/4, (height + 3)/8);
- decodePass(theTile, 2, 0, 4, 4, (width + 1)/4, (height + 3)/4);
- decodePass(theTile, 0, 2, 2, 4, (width + 1)/2, (height + 1)/4);
- decodePass(theTile, 1, 0, 2, 2, width/2, (height + 1)/2);
- decodePass(theTile, 0, 1, 1, 2, width, height/2);
+ decodePass(theTile, 0, 0, 8, 8, (width + 7) / 8, (height + 7) / 8);
+ decodePass(theTile, 4, 0, 8, 8, (width + 3) / 8, (height + 7) / 8);
+ decodePass(theTile, 0, 4, 4, 8, (width + 3) / 4, (height + 3) / 8);
+ decodePass(theTile, 2, 0, 4, 4, (width + 1) / 4, (height + 3) / 4);
+ decodePass(theTile, 0, 2, 2, 4, (width + 1) / 2, (height + 1) / 4);
+ decodePass(theTile, 1, 0, 2, 2, width / 2, (height + 1) / 2);
+ decodePass(theTile, 0, 1, 1, 2, width, height / 2);
}
}
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGImageEncoder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGImageEncoder.java?rev=1576437&r1=1576436&r2=1576437&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGImageEncoder.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGImageEncoder.java Tue Mar 11 17:49:35 2014
@@ -182,7 +182,7 @@ class ChunkStream extends OutputStream i
@Override
public void close() throws IOException {
- if ( baos != null ) {
+ if (baos != null) {
baos.close();
baos = null;
}
@@ -196,7 +196,7 @@ class ChunkStream extends OutputStream i
class IDATOutputStream extends FilterOutputStream {
- private static final byte[] typeSignature
+ private static final byte[] TYPE_SIGNATURE
= {(byte)'I', (byte)'D', (byte)'A', (byte)'T'};
private int bytesWritten = 0;
@@ -231,12 +231,12 @@ class IDATOutputStream extends FilterOut
// Length
writeInt(bytesWritten);
// 'IDAT' signature
- out.write(typeSignature);
+ out.write(TYPE_SIGNATURE);
// Data
out.write(buffer, 0, bytesWritten);
int crc = 0xffffffff;
- crc = CRC.updateCRC(crc, typeSignature, 0, 4);
+ crc = CRC.updateCRC(crc, TYPE_SIGNATURE, 0, 4);
crc = CRC.updateCRC(crc, buffer, 0, bytesWritten);
// CRC
@@ -288,7 +288,7 @@ public class PNGImageEncoder extends Ima
private static final int PNG_COLOR_GRAY_ALPHA = 4;
private static final int PNG_COLOR_RGB_ALPHA = 6;
- private static final byte[] magic = {
+ private static final byte[] MAGIC = {
(byte)137, (byte) 80, (byte) 78, (byte) 71,
(byte) 13, (byte) 10, (byte) 26, (byte) 10
};
@@ -328,7 +328,7 @@ public class PNGImageEncoder extends Ima
}
private void writeMagic() throws IOException {
- dataOutput.write(magic);
+ dataOutput.write(MAGIC);
}
private void writeIHDR() throws IOException {
@@ -366,15 +366,15 @@ public class PNGImageEncoder extends Ima
xOffset *= numBands;
xSkip *= numBands;
- int samplesPerByte = 8/bitDepth;
+ int samplesPerByte = 8 / bitDepth;
- int numSamples = width*numBands;
+ int numSamples = width * numBands;
int[] samples = new int[numSamples];
- int pixels = (numSamples - xOffset + xSkip - 1)/xSkip;
- int bytesPerRow = pixels*numBands;
+ int pixels = (numSamples - xOffset + xSkip - 1) / xSkip;
+ int bytesPerRow = pixels * numBands;
if (bitDepth < 8) {
- bytesPerRow = (bytesPerRow + samplesPerByte - 1)/samplesPerByte;
+ bytesPerRow = (bytesPerRow + samplesPerByte - 1) / samplesPerByte;
} else if (bitDepth == 16) {
bytesPerRow *= 2;
}
@@ -422,7 +422,7 @@ public class PNGImageEncoder extends Ima
// Left shift the last byte
if (pos != 0) {
- tmp <<= (samplesPerByte - pos)*bitDepth;
+ tmp <<= (samplesPerByte - pos) * bitDepth;
currRow[count++] = (byte)tmp;
}
break;
@@ -532,7 +532,7 @@ public class PNGImageEncoder extends Ima
cs.close();
}
- private static final float[] srgbChroma = {
+ private static final float[] SRGB_CHROMA = {
0.31270F, 0.329F, 0.64F, 0.33F, 0.3F, 0.6F, 0.15F, 0.06F
};
@@ -544,11 +544,11 @@ public class PNGImageEncoder extends Ima
if (!param.isSRGBIntentSet()) {
chroma = param.getChromaticity();
} else {
- chroma = srgbChroma; // SRGB chromaticities
+ chroma = SRGB_CHROMA; // SRGB chromaticities
}
for (int i = 0; i < 8; i++) {
- cs.writeInt((int)(chroma[i]*100000));
+ cs.writeInt((int)(chroma[i] * 100000));
}
cs.writeToStream(dataOutput);
cs.close();
@@ -563,11 +563,11 @@ public class PNGImageEncoder extends Ima
if (!param.isSRGBIntentSet()) {
gamma = param.getGamma();
} else {
- gamma = 1.0F/2.2F; // SRGB gamma
+ gamma = 1.0F / 2.2F; // SRGB gamma
}
// TD should include the .5 but causes regard to say
// everything is different.
- cs.writeInt((int)(gamma*100000/*+0.5*/));
+ cs.writeInt((int)(gamma * 100000/*+0.5*/));
cs.writeToStream(dataOutput);
cs.close();
}
@@ -576,8 +576,8 @@ public class PNGImageEncoder extends Ima
private void writeICCP() throws IOException {
if (param.isICCProfileDataSet()) {
ChunkStream cs = new ChunkStream("iCCP");
- byte[] ICCProfileData = param.getICCProfileData();
- cs.write(ICCProfileData);
+ byte[] iccProfileData = param.getICCProfileData();
+ cs.write(iccProfileData);
cs.writeToStream(dataOutput);
cs.close();
}
@@ -669,9 +669,9 @@ public class PNGImageEncoder extends Ima
}
private void writeTRNS() throws IOException {
- if (param.isTransparencySet() &&
- (colorType != PNG_COLOR_GRAY_ALPHA) &&
- (colorType != PNG_COLOR_RGB_ALPHA)) {
+ if (param.isTransparencySet()
+ && (colorType != PNG_COLOR_GRAY_ALPHA)
+ && (colorType != PNG_COLOR_RGB_ALPHA)) {
ChunkStream cs = new ChunkStream("tRNS");
if (param instanceof PNGEncodeParam.Palette) {
@@ -770,9 +770,9 @@ public class PNGImageEncoder extends Ima
if (param.isTextSet()) {
String[] text = param.getText();
- for (int i = 0; i < text.length/2; i++) {
- byte[] keyword = text[2*i].getBytes();
- byte[] value = text[2*i + 1].getBytes();
+ for (int i = 0; i < text.length / 2; i++) {
+ byte[] keyword = text[2 * i].getBytes();
+ byte[] value = text[2 * i + 1].getBytes();
ChunkStream cs = new ChunkStream("tEXt");
@@ -790,9 +790,9 @@ public class PNGImageEncoder extends Ima
if (param.isCompressedTextSet()) {
String[] text = param.getCompressedText();
- for (int i = 0; i < text.length/2; i++) {
- byte[] keyword = text[2*i].getBytes();
- byte[] value = text[2*i + 1].getBytes();
+ for (int i = 0; i < text.length / 2; i++) {
+ byte[] keyword = text[2 * i].getBytes();
+ byte[] value = text[2 * i + 1].getBytes();
ChunkStream cs = new ChunkStream("zTXt");
@@ -839,13 +839,13 @@ public class PNGImageEncoder extends Ima
PNGEncodeParam.Gray param = new PNGEncodeParam.Gray();
int numTransparent = 0;
- int grayFactor = 255/((1 << bitDepth) - 1);
+ int grayFactor = 255 / ((1 << bitDepth) - 1);
int entries = 1 << bitDepth;
for (int i = 0; i < entries; i++) {
byte red = redPalette[i];
- if ((red != i*grayFactor) ||
- (red != greenPalette[i]) ||
- (red != bluePalette[i])) {
+ if ((red != i * grayFactor)
+ || (red != greenPalette[i])
+ || (red != bluePalette[i])) {
return null;
}
@@ -923,7 +923,7 @@ public class PNGImageEncoder extends Ima
}
this.numBands = sampleModel.getNumBands();
- this.bpp = numBands*((bitDepth == 16) ? 2 : 1);
+ this.bpp = numBands * ((bitDepth == 16) ? 2 : 1);
ColorModel colorModel = image.getColorModel();
if (colorModel instanceof IndexColorModel) {
@@ -966,7 +966,7 @@ public class PNGImageEncoder extends Ima
PNGEncodeParam.Palette parami = (PNGEncodeParam.Palette)param;
if (parami.isPaletteSet()) {
int[] palette = parami.getPalette();
- size = palette.length/3;
+ size = palette.length / 3;
int index = 0;
for (int i = 0; i < size; i++) {
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGRed.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGRed.java?rev=1576437&r1=1576436&r2=1576437&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGRed.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGRed.java Tue Mar 11 17:49:35 2014
@@ -115,15 +115,15 @@ public class PNGRed extends AbstractRed
}
public int getInt2(int offset) {
- return ((data[offset] & 0xff) << 8) |
- (data[offset + 1] & 0xff);
+ return ((data[offset] & 0xff) << 8)
+ | (data[offset + 1] & 0xff);
}
public int getInt4(int offset) {
- return ((data[offset] & 0xff) << 24) |
- ((data[offset + 1] & 0xff) << 16) |
- ((data[offset + 2] & 0xff) << 8) |
- (data[offset + 3] & 0xff);
+ return ((data[offset] & 0xff) << 24)
+ | ((data[offset + 1] & 0xff) << 16)
+ | ((data[offset + 2] & 0xff) << 8)
+ | (data[offset + 3] & 0xff);
}
public String getString4(int offset) {
@@ -222,7 +222,7 @@ public class PNGRed extends AbstractRed
private boolean emitProperties = true;
- private float fileGamma = 45455/100000.0F;
+ private float fileGamma = 45455 / 100000.0F;
private float userExponent = 1.0F;
@@ -312,15 +312,15 @@ public class PNGRed extends AbstractRed
private int[] gammaLut = null;
private void initGammaLut(int bits) {
- double exp = (double)userExponent/(fileGamma*displayExponent);
+ double exp = (double)userExponent / (fileGamma * displayExponent);
int numSamples = 1 << bits;
int maxOutSample = (bits == 16) ? 65535 : 255;
gammaLut = new int[numSamples];
for (int i = 0; i < numSamples; i++) {
- double gbright = (double)i/(numSamples - 1);
+ double gbright = (double)i / (numSamples - 1);
double gamma = Math.pow(gbright, exp);
- int igamma = (int)(gamma*maxOutSample + 0.5);
+ int igamma = (int)(gamma * maxOutSample + 0.5);
if (igamma > maxOutSample) {
igamma = maxOutSample;
}
@@ -502,7 +502,7 @@ public class PNGRed extends AbstractRed
+ (char)((type >> 24) & 0xff)
+ (char)((type >> 16) & 0xff)
+ (char)((type >> 8) & 0xff)
- + (char)( type & 0xff);
+ + (char)(type & 0xff);
return typeString;
} catch (Exception e) {
e.printStackTrace();
@@ -542,11 +542,11 @@ public class PNGRed extends AbstractRed
maxOpacity = (1 << bitDepth) - 1;
colorType = chunk.getInt1(9);
- if ((colorType != PNG_COLOR_GRAY) &&
- (colorType != PNG_COLOR_RGB) &&
- (colorType != PNG_COLOR_PALETTE) &&
- (colorType != PNG_COLOR_GRAY_ALPHA) &&
- (colorType != PNG_COLOR_RGB_ALPHA)) {
+ if ((colorType != PNG_COLOR_GRAY)
+ && (colorType != PNG_COLOR_RGB)
+ && (colorType != PNG_COLOR_PALETTE)
+ && (colorType != PNG_COLOR_GRAY_ALPHA)
+ && (colorType != PNG_COLOR_RGB_ALPHA)) {
System.out.println(PropertyUtil.getString("PNGImageDecoder4"));
}
@@ -581,8 +581,8 @@ public class PNGRed extends AbstractRed
if (generateEncodeParam) {
if (colorType == PNG_COLOR_PALETTE) {
encodeParam = new PNGEncodeParam.Palette();
- } else if (colorType == PNG_COLOR_GRAY ||
- colorType == PNG_COLOR_GRAY_ALPHA) {
+ } else if (colorType == PNG_COLOR_GRAY
+ || colorType == PNG_COLOR_GRAY_ALPHA) {
encodeParam = new PNGEncodeParam.Gray();
} else {
encodeParam = new PNGEncodeParam.RGB();
@@ -599,7 +599,7 @@ public class PNGRed extends AbstractRed
if (performGammaCorrection) {
// Assume file gamma is 1/2.2 unless we get a gAMA chunk
- float gamma = (1.0F/2.2F)*(displayExponent/userExponent);
+ float gamma = (1.0F / 2.2F) * (displayExponent / userExponent);
if (encodeParam != null) {
encodeParam.setGamma(gamma);
}
@@ -724,12 +724,12 @@ public class PNGRed extends AbstractRed
private void parse_IEND_chunk(PNGChunk chunk) throws Exception {
// Store text strings
int textLen = textKeys.size();
- String[] textArray = new String[2*textLen];
+ String[] textArray = new String[2 * textLen];
for (int i = 0; i < textLen; i++) {
String key = (String)textKeys.get(i);
String val = (String)textStrings.get(i);
- textArray[2*i] = key;
- textArray[2*i + 1] = val;
+ textArray[2 * i] = key;
+ textArray[2 * i + 1] = val;
if (emitProperties) {
String uniqueKey = "text_" + i + ':' + key;
properties.put(uniqueKey.toLowerCase(), val);
@@ -741,12 +741,12 @@ public class PNGRed extends AbstractRed
// Store compressed text strings
int ztextLen = ztextKeys.size();
- String[] ztextArray = new String[2*ztextLen];
+ String[] ztextArray = new String[2 * ztextLen];
for (int i = 0; i < ztextLen; i++) {
String key = (String)ztextKeys.get(i);
String val = (String)ztextStrings.get(i);
- ztextArray[2*i] = key;
- ztextArray[2*i + 1] = val;
+ ztextArray[2 * i] = key;
+ ztextArray[2 * i + 1] = val;
if (emitProperties) {
String uniqueKey = "ztext_" + i + ':' + key;
properties.put(uniqueKey.toLowerCase(), val);
@@ -758,15 +758,15 @@ public class PNGRed extends AbstractRed
// Parse prior IDAT chunks
InputStream seqStream =
- new SequenceInputStream( Collections.enumeration( streamVec ));
+ new SequenceInputStream(Collections.enumeration(streamVec));
InputStream infStream =
new InflaterInputStream(seqStream, new Inflater());
dataStream = new DataInputStream(infStream);
// Create an empty WritableRaster
int depth = bitDepth;
- if ((colorType == PNG_COLOR_GRAY) &&
- (bitDepth < 8) && output8BitGray) {
+ if ((colorType == PNG_COLOR_GRAY)
+ && (bitDepth < 8) && output8BitGray) {
depth = 8;
}
if ((colorType == PNG_COLOR_PALETTE) && expandPalette) {
@@ -775,9 +775,9 @@ public class PNGRed extends AbstractRed
int width = bounds.width;
int height = bounds.height;
- int bytesPerRow = (outputBands*width*depth + 7)/8;
+ int bytesPerRow = (outputBands * width * depth + 7) / 8;
int scanlineStride =
- (depth == 16) ? (bytesPerRow/2) : bytesPerRow;
+ (depth == 16) ? (bytesPerRow / 2) : bytesPerRow;
theTile = createRaster(width, height, outputBands,
scanlineStride,
@@ -786,9 +786,9 @@ public class PNGRed extends AbstractRed
if (performGammaCorrection && (gammaLut == null)) {
initGammaLut(bitDepth);
}
- if ((postProcess == POST_GRAY_LUT) ||
- (postProcess == POST_GRAY_LUT_ADD_TRANS) ||
- (postProcess == POST_GRAY_LUT_ADD_TRANS_EXP)) {
+ if ((postProcess == POST_GRAY_LUT)
+ || (postProcess == POST_GRAY_LUT_ADD_TRANS)
+ || (postProcess == POST_GRAY_LUT_ADD_TRANS_EXP)) {
initGrayLut(bitDepth);
}
@@ -818,8 +818,8 @@ public class PNGRed extends AbstractRed
greenPalette,
bluePalette);
}
- } else if ((colorType == PNG_COLOR_GRAY) &&
- (bitDepth < 8) && !output8BitGray) {
+ } else if ((colorType == PNG_COLOR_GRAY)
+ && (bitDepth < 8) && !output8BitGray) {
byte[] palette = expandBits[bitDepth];
cm = new IndexColorModel(bitDepth,
palette.length,
@@ -983,7 +983,7 @@ public class PNGRed extends AbstractRed
}
private void parse_PLTE_chunk(PNGChunk chunk) {
- paletteEntries = chunk.getLength()/3;
+ paletteEntries = chunk.getLength() / 3;
redPalette = new byte[paletteEntries];
greenPalette = new byte[paletteEntries];
bluePalette = new byte[paletteEntries];
@@ -1024,8 +1024,7 @@ public class PNGRed extends AbstractRed
bkgdBlue = bluePalette[bkgdIndex] & 0xff;
if (encodeParam != null) {
- ((PNGEncodeParam.Palette)encodeParam).
- setBackgroundPaletteIndex(bkgdIndex);
+ ((PNGEncodeParam.Palette)encodeParam).setBackgroundPaletteIndex(bkgdIndex);
}
break;
case PNG_COLOR_GRAY: case PNG_COLOR_GRAY_ALPHA:
@@ -1033,8 +1032,7 @@ public class PNGRed extends AbstractRed
bkgdRed = bkgdGreen = bkgdBlue = bkgdGray;
if (encodeParam != null) {
- ((PNGEncodeParam.Gray)encodeParam).
- setBackgroundGray(bkgdGray);
+ ((PNGEncodeParam.Gray)encodeParam).setBackgroundGray(bkgdGray);
}
break;
case PNG_COLOR_RGB: case PNG_COLOR_RGB_ALPHA:
@@ -1047,14 +1045,15 @@ public class PNGRed extends AbstractRed
bkgdRGB[1] = bkgdGreen;
bkgdRGB[2] = bkgdBlue;
if (encodeParam != null) {
- ((PNGEncodeParam.RGB)encodeParam).
- setBackgroundRGB(bkgdRGB);
+ ((PNGEncodeParam.RGB)encodeParam).setBackgroundRGB(bkgdRGB);
}
break;
}
if (emitProperties) {
- int r = 0, g = 0, b = 0;
+ int r = 0;
+ int g = 0;
+ int b = 0;
if ((colorType == PNG_COLOR_PALETTE) || (bitDepth == 8)) {
r = bkgdRed;
g = bkgdGreen;
@@ -1079,14 +1078,14 @@ public class PNGRed extends AbstractRed
}
chromaticity = new float[8];
- chromaticity[0] = chunk.getInt4(0)/100000.0F;
- chromaticity[1] = chunk.getInt4(4)/100000.0F;
- chromaticity[2] = chunk.getInt4(8)/100000.0F;
- chromaticity[3] = chunk.getInt4(12)/100000.0F;
- chromaticity[4] = chunk.getInt4(16)/100000.0F;
- chromaticity[5] = chunk.getInt4(20)/100000.0F;
- chromaticity[6] = chunk.getInt4(24)/100000.0F;
- chromaticity[7] = chunk.getInt4(28)/100000.0F;
+ chromaticity[0] = chunk.getInt4(0) / 100000.0F;
+ chromaticity[1] = chunk.getInt4(4) / 100000.0F;
+ chromaticity[2] = chunk.getInt4(8) / 100000.0F;
+ chromaticity[3] = chunk.getInt4(12) / 100000.0F;
+ chromaticity[4] = chunk.getInt4(16) / 100000.0F;
+ chromaticity[5] = chunk.getInt4(20) / 100000.0F;
+ chromaticity[6] = chunk.getInt4(24) / 100000.0F;
+ chromaticity[7] = chunk.getInt4(28) / 100000.0F;
if (encodeParam != null) {
encodeParam.setChromaticity(chromaticity);
@@ -1109,15 +1108,15 @@ public class PNGRed extends AbstractRed
return;
}
- fileGamma = chunk.getInt4(0)/100000.0F;
+ fileGamma = chunk.getInt4(0) / 100000.0F;
// System.out.println("Gamma: " + fileGamma);
float exp =
- performGammaCorrection ? displayExponent/userExponent : 1.0F;
+ performGammaCorrection ? displayExponent / userExponent : 1.0F;
if (encodeParam != null) {
- encodeParam.setGamma(fileGamma*exp);
+ encodeParam.setGamma(fileGamma * exp);
}
if (emitProperties) {
- properties.put("gamma", new Float(fileGamma*exp));
+ properties.put("gamma", new Float(fileGamma * exp));
}
}
@@ -1130,7 +1129,7 @@ public class PNGRed extends AbstractRed
int length = redPalette.length;
int[] hist = new int[length];
for (int i = 0; i < length; i++) {
- hist[i] = chunk.getInt2(2*i);
+ hist[i] = chunk.getInt2(2 * i);
}
if (encodeParam != null) {
@@ -1162,7 +1161,7 @@ public class PNGRed extends AbstractRed
properties.put("x_pixels_per_unit", new Integer(xPixelsPerUnit));
properties.put("y_pixels_per_unit", new Integer(yPixelsPerUnit));
properties.put("pixel_aspect_ratio",
- new Float((float)xPixelsPerUnit/yPixelsPerUnit));
+ new Float((float)xPixelsPerUnit / yPixelsPerUnit));
if (unitSpecifier == 1) {
properties.put("pixel_units", "Meters");
} else if (unitSpecifier != 0) {
@@ -1204,21 +1203,21 @@ public class PNGRed extends AbstractRed
// The presence of an sRGB chunk implies particular
// settings for gamma and chroma.
- fileGamma = 45455/100000.0F;
+ fileGamma = 45455 / 100000.0F;
chromaticity = new float[8];
- chromaticity[0] = 31270/10000.0F;
- chromaticity[1] = 32900/10000.0F;
- chromaticity[2] = 64000/10000.0F;
- chromaticity[3] = 33000/10000.0F;
- chromaticity[4] = 30000/10000.0F;
- chromaticity[5] = 60000/10000.0F;
- chromaticity[6] = 15000/10000.0F;
- chromaticity[7] = 6000/10000.0F;
+ chromaticity[0] = 31270 / 10000.0F;
+ chromaticity[1] = 32900 / 10000.0F;
+ chromaticity[2] = 64000 / 10000.0F;
+ chromaticity[3] = 33000 / 10000.0F;
+ chromaticity[4] = 30000 / 10000.0F;
+ chromaticity[5] = 60000 / 10000.0F;
+ chromaticity[6] = 15000 / 10000.0F;
+ chromaticity[7] = 6000 / 10000.0F;
if (performGammaCorrection) {
// File gamma is 1/2.2
- float gamma = fileGamma*(displayExponent/userExponent);
+ float gamma = fileGamma * (displayExponent / userExponent);
if (encodeParam != null) {
encodeParam.setGamma(gamma);
encodeParam.setChromaticity(chromaticity);
@@ -1326,8 +1325,7 @@ public class PNGRed extends AbstractRed
}
if (encodeParam != null) {
- ((PNGEncodeParam.Gray)encodeParam).
- setTransparentGray(grayTransparentAlpha);
+ ((PNGEncodeParam.Gray)encodeParam).setTransparentGray(grayTransparentAlpha);
}
}
} else if (colorType == PNG_COLOR_RGB) {
@@ -1344,12 +1342,11 @@ public class PNGRed extends AbstractRed
rgbTrans[0] = redTransparentAlpha;
rgbTrans[1] = greenTransparentAlpha;
rgbTrans[2] = blueTransparentAlpha;
- ((PNGEncodeParam.RGB)encodeParam).
- setTransparentRGB(rgbTrans);
+ ((PNGEncodeParam.RGB)encodeParam).setTransparentRGB(rgbTrans);
}
}
- } else if (colorType == PNG_COLOR_GRAY_ALPHA ||
- colorType == PNG_COLOR_RGB_ALPHA) {
+ } else if (colorType == PNG_COLOR_GRAY_ALPHA
+ || colorType == PNG_COLOR_RGB_ALPHA) {
// Error -- GA or RGBA image can't have a tRNS chunk.
String msg = PropertyUtil.getString("PNGImageDecoder15");
throw new RuntimeException(msg);
@@ -1379,8 +1376,8 @@ public class PNGRed extends AbstractRed
value.append((char)c);
}
- ztextKeys.add(key.toString() );
- ztextStrings.add(value.toString() );
+ ztextKeys.add(key.toString());
+ ztextStrings.add(value.toString());
} catch (Exception e) {
e.printStackTrace();
}
@@ -1394,13 +1391,13 @@ public class PNGRed extends AbstractRed
WritableRaster ras = null;
Point origin = new Point(0, 0);
if ((bitDepth < 8) && (bands == 1)) {
- dataBuffer = new DataBufferByte(height*scanlineStride);
+ dataBuffer = new DataBufferByte(height * scanlineStride);
ras = Raster.createPackedRaster(dataBuffer,
width, height,
bitDepth,
origin);
} else if (bitDepth <= 8) {
- dataBuffer = new DataBufferByte(height*scanlineStride);
+ dataBuffer = new DataBufferByte(height * scanlineStride);
ras = Raster.createInterleavedRaster(dataBuffer,
width, height,
scanlineStride,
@@ -1408,7 +1405,7 @@ public class PNGRed extends AbstractRed
bandOffsets[bands],
origin);
} else {
- dataBuffer = new DataBufferUShort(height*scanlineStride);
+ dataBuffer = new DataBufferUShort(height * scanlineStride);
ras = Raster.createInterleavedRaster(dataBuffer,
width, height,
scanlineStride,
@@ -1449,7 +1446,7 @@ public class PNGRed extends AbstractRed
int raw = curr[i] & 0xff;
int priorRow = prev[i] & 0xff;
- curr[i] = (byte)(raw + priorRow/2);
+ curr[i] = (byte)(raw + priorRow / 2);
}
for (int i = bpp; i < count; i++) {
@@ -1457,7 +1454,7 @@ public class PNGRed extends AbstractRed
int priorPixel = curr[i - bpp] & 0xff;
int priorRow = prev[i] & 0xff;
- curr[i] = (byte)(raw + (priorPixel + priorRow)/2);
+ curr[i] = (byte)(raw + (priorPixel + priorRow) / 2);
}
}
@@ -1478,7 +1475,8 @@ public class PNGRed extends AbstractRed
private static void decodePaethFilter(byte[] curr, byte[] prev,
int count, int bpp) {
- int priorPixel, priorRowPixel;
+ int priorPixel;
+ int priorRowPixel;
for (int i = 0; i < bpp; i++) {
int raw = curr[i] & 0xff;
@@ -1502,7 +1500,8 @@ public class PNGRed extends AbstractRed
private void processPixels(int process,
Raster src, WritableRaster dst,
int xOffset, int step, int y, int width) {
- int srcX, dstX;
+ int srcX;
+ int dstX;
// Create an array suitable for holding one pixel
int[] ps = src.getPixel(0, 0, (int[])null);
@@ -1627,9 +1626,9 @@ public class PNGRed extends AbstractRed
pd[1] = g;
pd[2] = b;
}
- if ((r == redTransparentAlpha) &&
- (g == greenTransparentAlpha) &&
- (b == blueTransparentAlpha)) {
+ if ((r == redTransparentAlpha)
+ && (g == greenTransparentAlpha)
+ && (b == blueTransparentAlpha)) {
pd[3] = 0;
} else {
pd[3] = maxOpacity;
@@ -1767,8 +1766,8 @@ public class PNGRed extends AbstractRed
return;
}
- int bytesPerRow = (inputBands*passWidth*bitDepth + 7)/8;
- int eltsPerRow = (bitDepth == 16) ? bytesPerRow/2 : bytesPerRow;
+ int bytesPerRow = (inputBands * passWidth * bitDepth + 7) / 8;
+ int eltsPerRow = (bitDepth == 16) ? bytesPerRow / 2 : bytesPerRow;
byte[] curr = new byte[bytesPerRow];
byte[] prior = new byte[bytesPerRow];
@@ -1788,7 +1787,8 @@ public class PNGRed extends AbstractRed
}
// Decode the (sub)image row-by-row
- int srcY, dstY;
+ int srcY;
+ int dstY;
for (srcY = 0, dstY = yOffset;
srcY < passHeight;
srcY++, dstY += yStep) {
@@ -1851,13 +1851,13 @@ public class PNGRed extends AbstractRed
if (!useInterlacing) {
decodePass(theTile, 0, 0, 1, 1, width, height);
} else {
- decodePass(theTile, 0, 0, 8, 8, (width + 7)/8, (height + 7)/8);
- decodePass(theTile, 4, 0, 8, 8, (width + 3)/8, (height + 7)/8);
- decodePass(theTile, 0, 4, 4, 8, (width + 3)/4, (height + 3)/8);
- decodePass(theTile, 2, 0, 4, 4, (width + 1)/4, (height + 3)/4);
- decodePass(theTile, 0, 2, 2, 4, (width + 1)/2, (height + 1)/4);
- decodePass(theTile, 1, 0, 2, 2, width/2, (height + 1)/2);
- decodePass(theTile, 0, 1, 1, 2, width, height/2);
+ decodePass(theTile, 0, 0, 8, 8, (width + 7) / 8, (height + 7) / 8);
+ decodePass(theTile, 4, 0, 8, 8, (width + 3) / 8, (height + 7) / 8);
+ decodePass(theTile, 0, 4, 4, 8, (width + 3) / 4, (height + 3) / 8);
+ decodePass(theTile, 2, 0, 4, 4, (width + 1) / 4, (height + 3) / 4);
+ decodePass(theTile, 0, 2, 2, 4, (width + 1) / 2, (height + 1) / 4);
+ decodePass(theTile, 1, 0, 2, 2, width / 2, (height + 1) / 2);
+ decodePass(theTile, 0, 1, 1, 2, width, height / 2);
}
}
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFDirectory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFDirectory.java?rev=1576437&r1=1576436&r2=1576437&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFDirectory.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFDirectory.java Tue Mar 11 17:49:35 2014
@@ -77,13 +77,13 @@ public class TIFFDirectory implements Se
Map fieldIndex = new HashMap();
/** The offset of this IFD. */
- long IFDOffset = 8;
+ long ifdOffset = 8;
/** The offset of the next IFD. */
long nextIFDOffset = 0;
/** The default constructor. */
- TIFFDirectory() {}
+ TIFFDirectory() { }
private static boolean isValidEndianTag(int endian) {
return ((endian == 0x4949) || (endian == 0x4d4d));
@@ -102,8 +102,8 @@ public class TIFFDirectory implements Se
public TIFFDirectory(SeekableStream stream, int directory)
throws IOException {
- long global_save_offset = stream.getFilePointer();
- long ifd_offset;
+ long globalSaveOffset = stream.getFilePointer();
+ long ifdOffset;
// Read the TIFF header
stream.seek(0L);
@@ -119,26 +119,26 @@ public class TIFFDirectory implements Se
}
// Get the initial ifd offset as an unsigned int (using a long)
- ifd_offset = readUnsignedInt(stream);
+ ifdOffset = readUnsignedInt(stream);
for (int i = 0; i < directory; i++) {
- if (ifd_offset == 0L) {
+ if (ifdOffset == 0L) {
throw new IllegalArgumentException(PropertyUtil.getString("TIFFDirectory3"));
}
- stream.seek(ifd_offset);
+ stream.seek(ifdOffset);
long entries = readUnsignedShort(stream);
- stream.skip(12*entries);
+ stream.skip(12 * entries);
- ifd_offset = readUnsignedInt(stream);
+ ifdOffset = readUnsignedInt(stream);
}
- if (ifd_offset == 0L) {
+ if (ifdOffset == 0L) {
throw new IllegalArgumentException(PropertyUtil.getString("TIFFDirectory3"));
}
- stream.seek(ifd_offset);
+ stream.seek(ifdOffset);
initialize(stream);
- stream.seek(global_save_offset);
+ stream.seek(globalSaveOffset);
}
/**
@@ -149,15 +149,15 @@ public class TIFFDirectory implements Se
* sequence of IFDs.
*
* @param stream a SeekableStream to read from.
- * @param ifd_offset the long byte offset of the directory.
+ * @param ifdOffset the long byte offset of the directory.
* @param directory the index of the directory to read beyond the
* one at the current stream offset; zero indicates the IFD
* at the current offset.
*/
- public TIFFDirectory(SeekableStream stream, long ifd_offset, int directory)
+ public TIFFDirectory(SeekableStream stream, long ifdOffset, int directory)
throws IOException {
- long global_save_offset = stream.getFilePointer();
+ long globalSaveOffset = stream.getFilePointer();
stream.seek(0L);
int endian = stream.readUnsignedShort();
if (!isValidEndianTag(endian)) {
@@ -166,32 +166,32 @@ public class TIFFDirectory implements Se
isBigEndian = (endian == 0x4d4d);
// Seek to the first IFD.
- stream.seek(ifd_offset);
+ stream.seek(ifdOffset);
// Seek to desired IFD if necessary.
int dirNum = 0;
- while(dirNum < directory) {
+ while (dirNum < directory) {
// Get the number of fields in the current IFD.
long numEntries = readUnsignedShort(stream);
// Skip to the next IFD offset value field.
- stream.seek(ifd_offset + 12*numEntries);
+ stream.seek(ifdOffset + 12 * numEntries);
// Read the offset to the next IFD beyond this one.
- ifd_offset = readUnsignedInt(stream);
+ ifdOffset = readUnsignedInt(stream);
// Seek to the next IFD.
- stream.seek(ifd_offset);
+ stream.seek(ifdOffset);
// Increment the directory.
dirNum++;
}
initialize(stream);
- stream.seek(global_save_offset);
+ stream.seek(globalSaveOffset);
}
- private static final int[] sizeOfType = {
+ private static final int[] SIZE_OF_TYPE = {
0, // 0 = n/a
1, // 1 = byte
1, // 2 = ascii
@@ -209,9 +209,10 @@ public class TIFFDirectory implements Se
private void initialize(SeekableStream stream) throws IOException {
long nextTagOffset;
- int i, j;
+ int i;
+ int j;
- IFDOffset = stream.getFilePointer();
+ ifdOffset = stream.getFilePointer();
numEntries = readUnsignedShort(stream);
fields = new TIFFField[numEntries];
@@ -228,7 +229,7 @@ public class TIFFDirectory implements Se
try {
// If the tag data can't fit in 4 bytes, the next 4 bytes
// contain the starting offset of the data
- if (count*sizeOfType[type] > 4) {
+ if (count * SIZE_OF_TYPE[type] > 4) {
value = (int)(readUnsignedInt(stream));
stream.seek(value);
}
@@ -253,16 +254,19 @@ public class TIFFDirectory implements Se
if (type == TIFFField.TIFF_ASCII) {
// Can be multiple strings
- int index = 0, prevIndex = 0;
+ int index = 0;
+ int prevIndex = 0;
List v = new ArrayList();
while (index < count) {
- while ((index < count) && (bvalues[index++] != 0));
+ while ((index < count) && (bvalues[index++] != 0)) {
+ // NOP
+ }
// When we encountered zero, means one string has ended
v.add(new String(bvalues, prevIndex,
- (index - prevIndex)) );
+ (index - prevIndex)));
prevIndex = index;
}
@@ -578,7 +582,7 @@ public class TIFFDirectory implements Se
* given TIFF file, represented by a <code>SeekableStream</code>.
*/
public static int getNumDirectories(SeekableStream stream)
- throws IOException{
+ throws IOException {
long pointer = stream.getFilePointer(); // Save stream pointer
stream.seek(0L);
@@ -601,7 +605,7 @@ public class TIFFDirectory implements Se
stream.seek(offset);
long entries = readUnsignedShort(stream, isBigEndian);
- stream.skip(12*entries);
+ stream.skip(12 * entries);
offset = readUnsignedInt(stream, isBigEndian);
}
@@ -623,7 +627,7 @@ public class TIFFDirectory implements Se
* <code>TIFFDirectory</code>.
*/
public long getIFDOffset() {
- return IFDOffset;
+ return ifdOffset;
}
/**
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFFaxDecoder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFFaxDecoder.java?rev=1576437&r1=1576436&r2=1576437&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFFaxDecoder.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFFaxDecoder.java Tue Mar 11 17:49:35 2014
@@ -28,9 +28,11 @@ import org.apache.xmlgraphics.image.code
class TIFFFaxDecoder {
- private int bitPointer, bytePointer;
+ private int bitPointer;
+ private int bytePointer;
private byte[] data;
- private int w, h;
+ private int w;
+ private int h;
private int fillOrder;
// Data structures needed to store changing elements for the previous
@@ -578,7 +580,7 @@ class TIFFFaxDecoder {
this.data = compData;
int lineOffset = 0;
- int scanlineStride = (w + 7)/8;
+ int scanlineStride = (w + 7) / 8;
bitPointer = 0;
bytePointer = 0;
@@ -591,8 +593,12 @@ class TIFFFaxDecoder {
public void decodeNextScanline(byte[] buffer,
int lineOffset, int bitOffset) {
- int bits = 0, code = 0, isT = 0;
- int current, entry, twoBits;
+ int bits = 0;
+ int code = 0;
+ int isT = 0;
+ int current;
+ int entry;
+ int twoBits;
boolean isWhite = true;
// Initialize starting of the changing elements array
@@ -739,11 +745,16 @@ class TIFFFaxDecoder {
bitPointer = 0;
bytePointer = 0;
- int scanlineStride = (w + 7)/8;
+ int scanlineStride = (w + 7) / 8;
- int a0, a1, b1, b2;
+ int a0;
+ int a1;
+ int b1;
+ int b2;
int[] b = new int[2];
- int entry, code, bits;
+ int entry;
+ int code;
+ int bits;
boolean isWhite;
int currIndex = 0;
int[] temp;
@@ -890,10 +901,15 @@ class TIFFFaxDecoder {
bitPointer = 0;
bytePointer = 0;
- int scanlineStride = (w + 7)/8;
+ int scanlineStride = (w + 7) / 8;
- int a0, a1, b1, b2;
- int entry, code, bits;
+ int a0;
+ int a1;
+ int b1;
+ int b2;
+ int entry;
+ int code;
+ int bits;
boolean isWhite;
int currIndex;
int[] temp;
@@ -1093,7 +1109,7 @@ class TIFFFaxDecoder {
private void setToBlack(byte[] buffer,
int lineOffset, int bitOffset,
int numBits) {
- int bitNum = 8*lineOffset + bitOffset;
+ int bitNum = 8 * lineOffset + bitOffset;
int lastBit = bitNum + numBits;
int byteNum = bitNum >> 3;
@@ -1128,7 +1144,12 @@ class TIFFFaxDecoder {
// Returns run length
private int decodeWhiteCodeWord() {
- int current, entry, bits, isT, twoBits, code = -1;
+ int current;
+ int entry;
+ int bits;
+ int isT;
+ int twoBits;
+ int code = -1;
int runLength = 0;
boolean isWhite = true;
@@ -1170,7 +1191,11 @@ class TIFFFaxDecoder {
// Returns run length
private int decodeBlackCodeWord() {
- int current, entry, bits, isT, code = -1;
+ int current;
+ int entry;
+ int bits;
+ int isT;
+ int code = -1;
int runLength = 0;
boolean isWhite = false;
@@ -1313,7 +1338,9 @@ class TIFFFaxDecoder {
}
private int nextNBits(int bitsToGet) {
- byte b, next, next2next;
+ byte b;
+ byte next;
+ byte next2next;
int l = data.length - 1;
int bp = this.bytePointer;
@@ -1363,8 +1390,8 @@ class TIFFFaxDecoder {
int i3 = 0;
if (bitsFromNext2NextByte != 0) {
i2 <<= bitsFromNext2NextByte;
- i3 = (next2next & table2[bitsFromNext2NextByte]) >>>
- (8 - bitsFromNext2NextByte);
+ i3 = (next2next & table2[bitsFromNext2NextByte])
+ >>> (8 - bitsFromNext2NextByte);
i2 |= i3;
bytePointer++;
bitPointer = bitsFromNext2NextByte;
@@ -1382,7 +1409,8 @@ class TIFFFaxDecoder {
}
private int nextLesserThan8Bits(int bitsToGet) {
- byte b, next;
+ byte b;
+ byte next;
int l = data.length - 1;
int bp = this.bytePointer;
@@ -1408,7 +1436,8 @@ class TIFFFaxDecoder {
int bitsFromNextByte = bitsToGet - bitsLeft;
int shift = bitsLeft - bitsToGet;
- int i1, i2;
+ int i1;
+ int i2;
if (shift >= 0) {
i1 = (b & table1[bitsLeft]) >>> shift;
bitPointer += bitsToGet;
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFField.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFField.java?rev=1576437&r1=1576436&r2=1576437&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFField.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFField.java Tue Mar 11 17:49:35 2014
@@ -90,7 +90,7 @@ public class TIFFField implements Compar
Object data;
/** The default constructor. */
- TIFFField() {}
+ TIFFField() { }
/**
* Constructs a TIFFField with arbitrary data. The data
@@ -353,10 +353,10 @@ public class TIFFField implements Compar
return (float)((double[])data)[index];
case TIFF_SRATIONAL:
int[] ivalue = getAsSRational(index);
- return (float)((double)ivalue[0]/ivalue[1]);
+ return (float)((double)ivalue[0] / ivalue[1]);
case TIFF_RATIONAL:
long[] lvalue = getAsRational(index);
- return (float)((double)lvalue[0]/lvalue[1]);
+ return (float)((double)lvalue[0] / lvalue[1]);
default:
throw new ClassCastException();
}
@@ -391,10 +391,10 @@ public class TIFFField implements Compar
return ((double[])data)[index];
case TIFF_SRATIONAL:
int[] ivalue = getAsSRational(index);
- return (double)ivalue[0]/ivalue[1];
+ return (double)ivalue[0] / ivalue[1];
case TIFF_RATIONAL:
long[] lvalue = getAsRational(index);
- return (double)lvalue[0]/lvalue[1];
+ return (double)lvalue[0] / lvalue[1];
default:
throw new ClassCastException();
}
@@ -444,15 +444,15 @@ public class TIFFField implements Compar
* <code>TIFFField</code>.
*/
public int compareTo(Object o) {
- if(o == null) {
+ if (o == null) {
throw new NullPointerException();
}
int oTag = ((TIFFField)o).getTag();
- if(tag < oTag) {
+ if (tag < oTag) {
return -1;
- } else if(tag > oTag) {
+ } else if (tag > oTag) {
return 1;
} else {
return 0;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org