1 // Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
6 import org.xwt.translators.*;
10 * The in-memory representation of a PNG or GIF image. It is
11 * read-only. It is usually passed to PixelBuffer.drawPicture()
15 * Implementations of the Platform class should return objects
16 * supporting this interface from the createPicture() method. These
17 * implementations may choose to implement caching strategies (for
18 * example, using a Pixmap on X11).
21 public abstract class Picture {
23 /** Pictures, cached by Res */
24 private static Cache cache = new Cache();
26 /** turns a resource into a Picture.Source */
27 public static Picture fromRes(Res r) {
28 // FIXME: put self in background thread if needed
29 Picture ret = (Picture)cache.get(r);
32 PushbackInputStream pbis = new PushbackInputStream(r.getInputStream());
35 // FEATURE: cache GIF/PNG objects, reuse int[]'s?
36 if (c == 'G') ret = new GIF().fromInputStream(pbis, "FIXME");
37 else if (c == 137) ret = new PNG().fromInputStream(pbis, "FIXME");
38 else if (c == 0xff) ret = Platform.decodeJPEG(pbis, "FIXME");
39 else throw new JS.Exn("couldn't figure out image type from first byte");
41 } catch (IOException e) {
42 Log.logJS(Picture.class, e);
49 /** the height of the picture */
50 public abstract int getHeight();
52 /** the width of the picture */
53 public abstract int getWidth();