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 private static GIF gif = new GIF();
28 /** turns a resource into a Picture.Source */
29 public static Picture fromRes(Res r) {
30 Picture ret = (Picture)cache.get(r);
33 PushbackInputStream pbis = new PushbackInputStream(r.getInputStream());
36 if (c == 'G') ret = gif.fromInputStream(pbis, r.getDescriptiveName());
37 else if (c == 137) ret = new PNG().fromInputStream(pbis, r.getDescriptiveName());
38 else if (c == 0xff) ret = Platform.decodeJPEG(pbis, r.getDescriptiveName());
39 else throw new JS.Exn("couldn't figure out image type from first byte");
42 } catch (IOException e) {
43 Log.logJS(Picture.class, e);
50 /** the resource that created this Picture */
51 public Res res = null;
53 /** the height of the picture */
54 public abstract int getHeight();
56 /** the width of the picture */
57 public abstract int getWidth();