X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FPNG.java;h=4f5640a2c15fa2ec47283931db4a7a7f11e87d48;hb=ac49a62b989af76577f5b62e5afd58e7972623b4;hp=f0d9b7e3251968f3e2f23e760bce8645f7873dc4;hpb=6242c991f365dbd67eba62ecfa5df769a83fcbc6;p=org.ibex.core.git diff --git a/src/org/xwt/PNG.java b/src/org/xwt/PNG.java index f0d9b7e..4f5640a 100644 --- a/src/org/xwt/PNG.java +++ b/src/org/xwt/PNG.java @@ -21,7 +21,7 @@ import java.util.Enumeration; import java.util.zip.*; /** Converts an InputStream carrying a PNG image into an ARGB int[] */ -public class PNG implements ImageDecoder { +public class PNG extends ImageDecoder { // Public Methods /////////////////////////////////////////////////////////////////////////////// @@ -54,7 +54,7 @@ public class PNG implements ImageDecoder { // 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; @@ -159,8 +159,12 @@ public class PNG implements ImageDecoder { /** 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; @@ -255,9 +259,9 @@ public class PNG implements ImageDecoder { } 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); } }