// consume the header
if ((inputStream.read() != 137) || (inputStream.read() != 80) || (inputStream.read() != 78) || (inputStream.read() != 71) ||
(inputStream.read() != 13) || (inputStream.read() != 10) || (inputStream.read() != 26) || (inputStream.read() != 10)) {
- System.out.println("PNG: error: input file " + name + " is not a PNG file");
+ Log.log(this, "PNG: error: input file " + name + " is not a PNG file");
data = new int[] { };
width = height = 0;
return;
/** handle transparency chunk; modifies palette */
private void handletRNS() throws IOException {
int chunkLen = chunkLength;
- if (palette == null) throw new IOException("tRNS chunk encountered before pLTE");
- int len = palette.length;
+ if (palette == null) {
+ if (Log.on) Log.log(this, "warning: tRNS chunk encountered before pLTE; ignoring alpha channel");
+ inputStream.skip(chunkLength);
+ return;
+ }
+ int len = palette.length;
if (colorType == 3) {
transparency = true;
} else {
data[i] =
0xFF000000 |
- ((palette[3 * pix[i] + 0] & 0xff) << 16) |
- ((palette[3 * pix[i] + 1] & 0xff) << 8) |
- (palette[3 * pix[i] + 2] & 0xff);
+ ((palette[3 * (pix[i] & 0xff) + 0] & 0xff) << 16) |
+ ((palette[3 * (pix[i] & 0xff) + 1] & 0xff) << 8) |
+ (palette[3 * (pix[i] & 0xff) + 2] & 0xff);
}
}