/** * Reads GIF file header information. */ private void readHeader() { String id = ""; for (int i = 0; i < 6; i++) id += (char) read(); if (!id.startsWith("GIF")) { status = STATUS_FORMAT_ERROR; return; } readLSD(); if (gctFlag && !err()) { gct = readColorTable(gctSize); bgColor = gct[bgIndex]; } }
/** * Gets the first (or only) image read. * * @return ImageProcessor containing first frame, or null if none. */ public ImageProcessor getImage() { return getFrame(0); }
/** * Reads GIF image from stream * * @param BufferedInputStream containing GIF file. * @return int read status code */ public int read(BufferedInputStream is) { init(); if (is != null) { in = is; readHeader(); if (!err()) { readContents(); if (frameCount < 0) status = STATUS_FORMAT_ERROR; } } else { status = STATUS_OPEN_ERROR; } try { is.close(); } catch (IOException e) {} return status; }
/** * Reads Graphics Control Extension values */ private void readGraphicControlExt() { read(); // block size int packed = read(); // packed fields dispose = (packed & 0x1c) >> 1; transparency = (packed & 1) != 0; delay = readShort() * 10; // delay in milliseconds transIndex = read(); // transparent color index read(); // block terminator }
ix = readShort(); // (sub)image position & size iy = readShort(); iw = readShort(); ih = readShort(); int packed = read(); lctFlag = (packed & 0x80) != 0; // 1 - local color table flag interlace = (packed & 0x40) != 0; // 2 - interlace flag lct = readColorTable(lctSize); // read table if (err()) return; decodeImageData(); // decode pixel data skip(); if (err()) return; setPixels(); // transfer pixel data to image resetFrame();
while (!(done || err())) { int code = read(); switch (code) { readImage(); break; code = read(); switch (code) { readGraphicControlExt(); break; readBlock(); String app = ""; for (int i = 0; i < 11; i++) app += (char) block[i]; if (app.equals("NETSCAPE2.0")) readNetscapeExt(); else skip(); // don't care break; skip();
return; String dir = od.getDirectory(); GifDecoder d = new GifDecoder(); int status = d.read(dir+name); int n = d.getFrameCount(); ImageStack stack = null; if (n==1) { } else { for (int i=0; i < n; i++) { ImageProcessor frame = d.getFrame(i); if (i==0) stack = new ImageStack(frame.getWidth(), frame.getHeight()); int t = d.getDelay(i); // display duration of frame in milliseconds stack.addSlice(null, frame);
ix = readShort(); // (sub)image position & size iy = readShort(); iw = readShort(); ih = readShort(); int packed = read(); lctFlag = (packed & 0x80) != 0; // 1 - local color table flag interlace = (packed & 0x40) != 0; // 2 - interlace flag lct = readColorTable(lctSize); // read table if (err()) return; decodeImageData(); // decode pixel data skip(); if (err()) return; setPixels(); // transfer pixel data to image resetFrame();
while (!(done || err())) { int code = read(); switch (code) { readImage(); break; code = read(); switch (code) { readGraphicControlExt(); break; readBlock(); String app = ""; for (int i = 0; i < 11; i++) app += (char) block[i]; if (app.equals("NETSCAPE2.0")) readNetscapeExt(); else skip(); // don't care break; skip();
return; String dir = od.getDirectory(); GifDecoder d = new GifDecoder(); int status = d.read(dir+name); int n = d.getFrameCount(); ImageStack stack = null; if (n==1) { } else { for (int i=0; i < n; i++) { ImageProcessor frame = d.getFrame(i); if (i==0) stack = new ImageStack(frame.getWidth(), frame.getHeight()); int t = d.getDelay(i); // display duration of frame in milliseconds stack.addSlice(null, frame);
/** * Reads Graphics Control Extension values */ private void readGraphicControlExt() { read(); // block size int packed = read(); // packed fields dispose = (packed & 0x1c) >> 1; transparency = (packed & 1) != 0; delay = readShort() * 10; // delay in milliseconds transIndex = read(); // transparent color index read(); // block terminator }
/** * Reads GIF file header information. */ private void readHeader() { String id = ""; for (int i = 0; i < 6; i++) id += (char) read(); if (!id.startsWith("GIF")) { status = STATUS_FORMAT_ERROR; return; } readLSD(); if (gctFlag && !err()) { gct = readColorTable(gctSize); bgColor = gct[bgIndex]; } }
/** * Reads GIF image from stream * * @param BufferedInputStream containing GIF file. * @return int read status code */ public int read(BufferedInputStream is) { init(); if (is != null) { in = is; readHeader(); if (!err()) { readContents(); if (frameCount < 0) status = STATUS_FORMAT_ERROR; } } else { status = STATUS_OPEN_ERROR; } try { is.close(); } catch (IOException e) {} return status; }