2003/04/10 01:41:43
[org.ibex.core.git] / src / org / xwt / Box.java
index 4cefc9e..caa7c8a 100644 (file)
@@ -408,13 +408,14 @@ public final class Box extends JSObject {
 
     /** loads the image described by string str, possibly blocking for a network load */
     static ImageDecoder getImage(String str, final Function callback) {
-        boolean ispng = false;
 
         if (str.indexOf(':') == -1) {
             String s = str;
             byte[] b = Resources.getResource(Resources.resolve(s + ".png", null));
-            if (b == null) return null;
-            return PNG.decode(new ByteArrayInputStream(b), str);
+           if (b != null) return PNG.decode(new ByteArrayInputStream(b), str);
+            b = Resources.getResource(Resources.resolve(s + ".jpeg", null));
+           if (b != null) return Platform.decodeJPEG(new ByteArrayInputStream(b), str);
+           return null;
             
         } else {
             Thread thread = Thread.currentThread();
@@ -427,10 +428,6 @@ public final class Box extends JSObject {
             mythread.setPriority(Thread.MIN_PRIORITY);
             mythread.done.release();
             try {
-                // FIXME use mime types here, not extensions
-                if (str.endsWith(".jpeg") || str.endsWith(".jpg"))
-                    str = "http://xmlrpc.xwt.org/jpeg2png/" + str.substring(str.indexOf("//") + 2);
-
                 HTTP http = new HTTP(str);
                 final HTTP.HTTPInputStream in = http.GET();
                 final int contentLength = in.getContentLength();
@@ -461,9 +458,10 @@ public final class Box extends JSObject {
                             return ret;
                         }
                     };
-                
+
                 if (str.endsWith(".gif")) return GIF.decode(is, str);
-                else return PNG.decode(is, str);
+                else if (str.endsWith(".jpeg") || str.endsWith(".jpg")) return Platform.decodeJPEG(is, str);
+               else return PNG.decode(is, str);
 
             } catch (IOException e) {
                 if (Log.on) Log.log(Box.class, "error while trying to load an image from " + str);
@@ -504,7 +502,7 @@ public final class Box extends JSObject {
                 if (Log.on) Log.log(Box.class, "unable to load image " + s + " at " +
                                     Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
                 return;
-            }
+           }
             if (sizetoimage) syncSizeToImage();
             dirty();
         }