X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fgraphics%2FPicture.java;h=fb236ea55669f002cbbcdb156b1b04a289f10fc5;hp=ce7b20b2d3b802daa00530c9f1ff4ea709649dbf;hb=a05e958733d401711a850ea77b9dfb3120fe7c8b;hpb=890000a10a0ccdc49f62946bddf1c0b840495a94 diff --git a/src/org/ibex/graphics/Picture.java b/src/org/ibex/graphics/Picture.java index ce7b20b..fb236ea 100644 --- a/src/org/ibex/graphics/Picture.java +++ b/src/org/ibex/graphics/Picture.java @@ -29,6 +29,20 @@ public class Picture { public int[] data = null; ///< argb samples public boolean isLoaded = false; ///< true iff the image is fully loaded + public Picture(InputStream is) throws IOException { load(this, is); } + + public static void load(Picture p, InputStream in) throws IOException { + PushbackInputStream pbis = new PushbackInputStream(in); + int firstByte = pbis.read(); + if (firstByte == -1) throw new IOException("empty stream reading image"); + pbis.unread(firstByte); + if ((firstByte & 0xff) == 'G') GIF.load(pbis, p); + else if ((firstByte & 0xff) == 137) PNG.load(pbis, p); + else if ((firstByte & 0xff) == 0xff) Platform.decodeJPEG(pbis, p); + else throw new IOException("couldn't figure out image type from first byte"); + p.loaded(); + } + /** invoked when an image is fully loaded; subclasses can use this to initialize platform-specific constructs */ protected void loaded() { isLoaded = true; } @@ -52,15 +66,7 @@ public class Picture { } if (in == null) { Log.warn(Picture.class, "couldn't load image for stream " + stream.unclone()); return; } try { - PushbackInputStream pbis = new PushbackInputStream(in); - int firstByte = pbis.read(); - if (firstByte == -1) throw new JSExn("empty stream reading image"); - pbis.unread(firstByte); - if ((firstByte & 0xff) == 'G') GIF.load(pbis, p); - else if ((firstByte & 0xff) == 137) PNG.load(pbis, p); - else if ((firstByte & 0xff) == 0xff) Platform.decodeJPEG(pbis, p); - else throw new JSExn("couldn't figure out image type from first byte"); - p.loaded(); + load(p, in); Platform.Scheduler.add(callback); } catch (Exception e) { Log.info(this, "exception while loading image");