fix bug that prevented scar image from loading
[org.ibex.core.git] / src / org / ibex / graphics / Picture.java
index ce7b20b..fb236ea 100644 (file)
@@ -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");