X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FPicture.java;h=4d563e0c1c747fe645f700a75b4f0facaee4718a;hb=e1da86ef35e219b79c3de0c099cf82b2500dc448;hp=f0eafecfecec32caec4d2fb7712ce2cec52a8cd8;hpb=68c7a72f76129359a3a029b1f34411665ebc3ab8;p=org.ibex.core.git diff --git a/src/org/xwt/Picture.java b/src/org/xwt/Picture.java index f0eafec..4d563e0 100644 --- a/src/org/xwt/Picture.java +++ b/src/org/xwt/Picture.java @@ -33,8 +33,31 @@ public class Picture { final Picture p = ret; if (!ret.isLoaded && callback != null) new java.lang.Thread() { public void run() { + // get the InputStream for the image + InputStream in = null; try { - PushbackInputStream pbis = new PushbackInputStream(r.getInputStream()); + in = r.getInputStream(); + } catch (IOException e) { + in = null; + if (r instanceof Res.Ref) { + // add extensions to the resource, looking for the image + Res.Ref ref = (Res.Ref)r; + Res newr; + + String[] exts = new String[] { ".png", ".jpeg", ".gif" }; + for (int i=0; i < exts.length && in == null; i++) { + newr = ref.addExtension(exts[i]); + try { in = newr.getInputStream(); } + catch (IOException f) { in = null; } + } + } + } + + // could not find image + if (in == null) { Log.info(Picture.class, "couldn't load image for resource " + r); return; } + + try { + PushbackInputStream pbis = new PushbackInputStream(in); int firstByte = pbis.read(); if (firstByte == -1) throw new JSExn("empty stream reading image"); pbis.unread(firstByte); @@ -42,12 +65,14 @@ public class Picture { 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.isLoaded = true; Scheduler.add(callback); } catch (Exception e) { - Log.log(this, "exception while loading image"); - Log.log(this, e); + Log.info(this, "exception while loading image"); + Log.info(this, e); } } }.start(); + return ret; } }