X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fxwt%2Ftranslators%2FPNG.java;h=5653a03bd1908d4983225144af049feb1aea426f;hb=3591b88b94a6bb378af3d4abe6eb5233ce583104;hp=6b7b11f5764dec0d1c934f91f10f1b59a0ccfc66;hpb=c00709f3cca592226f6f6bc1e8caa455d2ced0d5;p=org.ibex.core.git diff --git a/src/org/xwt/translators/PNG.java b/src/org/xwt/translators/PNG.java index 6b7b11f..5653a03 100644 --- a/src/org/xwt/translators/PNG.java +++ b/src/org/xwt/translators/PNG.java @@ -13,11 +13,9 @@ package org.xwt.translators; -import org.xwt.*; -import org.xwt.util.*; +import org.ibex.*; +import org.ibex.util.*; import java.io.*; -import java.util.Hashtable; -import java.util.Vector; import java.util.Enumeration; import java.util.zip.*; @@ -27,6 +25,7 @@ public class PNG { public PNG() { } private static Queue instances = new Queue(10); + private Picture p; public static void load(InputStream is, Picture p) { PNG g = (PNG)instances.remove(false); @@ -35,7 +34,7 @@ public class PNG { g._load(is, p); p.data = g.data; } catch (Exception e) { - if (Log.on) Log.log(PNG.class, e); + if (Log.on) Log.info(PNG.class, e); return; } // FIXME: must reset fields @@ -44,13 +43,11 @@ public class PNG { // Public Methods /////////////////////////////////////////////////////////////////////////////// - private Picture p; - /** process a PNG as an inputstream; returns null if there is an error @param name A string describing the image, to be used when logging errors */ - private void _load(InputStream is, Picture p) throws IOException { - this.p = p; + private void _load(InputStream is, Picture pic) throws IOException { + p = pic; if (is instanceof BufferedInputStream) underlyingStream = (BufferedInputStream)is; else underlyingStream = new BufferedInputStream(is); target_offset = 0; @@ -59,40 +56,37 @@ public class PNG { // 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)) { - Log.log(this, "PNG: error: input file is not a PNG file"); + Log.info(this, "PNG: error: input file is not a PNG file"); data = p.data = new int[] { }; p.width = p.height = 0; return; } - DONE: while (!error) { + + while (!error) { if (needChunkInfo) { chunkLength = inputStream.readInt(); chunkType = inputStream.readInt(); needChunkInfo = false; } - switch (chunkType) { - case CHUNK_bKGD: inputStream.skip(chunkLength); break; - case CHUNK_cHRM: inputStream.skip(chunkLength); break; - case CHUNK_gAMA: inputStream.skip(chunkLength); break; - case CHUNK_hIST: inputStream.skip(chunkLength); break; - case CHUNK_pHYs: inputStream.skip(chunkLength); break; - case CHUNK_sBIT: inputStream.skip(chunkLength); break; - case CHUNK_tEXt: inputStream.skip(chunkLength); break; - case CHUNK_zTXt: inputStream.skip(chunkLength); break; - case CHUNK_tIME: inputStream.skip(chunkLength); break; - - case CHUNK_IHDR: handleIHDR(); break; - case CHUNK_PLTE: handlePLTE(); break; - case CHUNK_tRNS: handletRNS(); break; - - case CHUNK_IDAT: handleIDAT(); break; - - case CHUNK_IEND: break DONE; - default: - System.err.println("unrecognized chunk type " + - Integer.toHexString(chunkType) + ". skipping"); + // I rewrote this as an if/else to work around a JODE bug with switch() blocks + if (chunkType == CHUNK_bKGD) inputStream.skip(chunkLength); + else if (chunkType == CHUNK_cHRM) inputStream.skip(chunkLength); + else if (chunkType == CHUNK_gAMA) inputStream.skip(chunkLength); + else if (chunkType == CHUNK_hIST) inputStream.skip(chunkLength); + else if (chunkType == CHUNK_pHYs) inputStream.skip(chunkLength); + else if (chunkType == CHUNK_sBIT) inputStream.skip(chunkLength); + else if (chunkType == CHUNK_tEXt) inputStream.skip(chunkLength); + else if (chunkType == CHUNK_zTXt) inputStream.skip(chunkLength); + else if (chunkType == CHUNK_tIME) inputStream.skip(chunkLength); + else if (chunkType == CHUNK_IHDR) handleIHDR(); + else if (chunkType == CHUNK_PLTE) handlePLTE(); + else if (chunkType == CHUNK_tRNS) handletRNS(); + else if (chunkType == CHUNK_IDAT) handleIDAT(); + else if (chunkType == CHUNK_IEND) break; + else { + System.err.println("unrecognized chunk type " + Integer.toHexString(chunkType) + ". skipping"); inputStream.skip(chunkLength); } @@ -166,7 +160,7 @@ public class PNG { private void handletRNS() throws IOException { int chunkLen = chunkLength; if (palette == null) { - if (Log.on) Log.log(this, "warning: tRNS chunk encountered before pLTE; ignoring alpha channel"); + if (Log.on) Log.info(this, "warning: tRNS chunk encountered before pLTE; ignoring alpha channel"); inputStream.skip(chunkLength); return; }