+ 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();
+ }
+