/*** FILENAME: GifReader.java CLASS: GifReader PURPOSE: this class uses the PixelGrabber class to get the raster data of an image. AUTHOR: Hanaa Barakat. Email: barakat@cs.queensu.ca ***/ import java.util.*; import java.awt.*; import java.awt.image.*; public class GifPixelGrabber { private PixelGrabber pg; private int[] pixels; public GifPixelGrabber(Image img, int w, int h, int x, int y) { pixels = new int[w * h]; pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w); try { pg.grabPixels(); } catch (InterruptedException e) { System.err.println("interrupted waiting for pixels!"); return; } if ((pg.getStatus() & ImageObserver.ABORT) != 0) { System.err.println("image fetch aborted or errored"); return; } /*** the following is a piece of code that decomposes a pixel into the Red, Green and Blue parts. Note: it is commented out here. ***/ /* Vector cols = new Vector(); for (int i = 0; i < w*h; i++) { int red = (pixels[i] >> 16) & 0xff; int green = (pixels[i] >> 8) & 0xff; int blue = (pixels[i] ) & 0xff; Color oldColor = new Color(red, green, blue); if (!cols.contains(oldColor)) { cols.addElement(oldColor); } } */ } public int[] getPelArray() { return pixels; } }