From: xwt Date: Fri, 30 Jan 2004 08:05:25 +0000 (+0000) Subject: 2004/01/27 02:19:47 X-Git-Tag: RC3~100 X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=commitdiff_plain;h=7d832e12a5f66911b042885f8f07e37844501208 2004/01/27 02:19:47 darcs-hash:20040130080525-3ac31-105e7f3b241bebea4c3c063dbd2de08ec91a0fcc.gz --- diff --git a/src/org/xwt/translators/PNG.java b/src/org/xwt/translators/PNG.java index c20263f..33440ea 100644 --- a/src/org/xwt/translators/PNG.java +++ b/src/org/xwt/translators/PNG.java @@ -27,6 +27,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); @@ -44,13 +45,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; @@ -65,34 +64,31 @@ public class PNG { 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); }