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);
// 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;
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);
}