package SE.liu.lysator.gfx; import java.awt.*; import java.awt.image.*; import java.util.*; import java.applet.*; public class ImageBits implements java.awt.image.ImageConsumer { public int width, height; public int pixels[]; Thread myThread; ImageProducer producer; public ImageBits( Image img ) { producer = img.getSource(); producer.startProduction( this ); myThread = Thread.currentThread(); myThread.suspend(); } public ImageBits( ImageBits imgBits ) { int cx, cy; width = imgBits.width; height = imgBits.height; pixels = new int[ width * height ]; for (cy=0; cy < height; cy++) for (cx=0; cx < height; cx++) pixels[ cy * width + cx ] = imgBits.pixels[ cy * width + cx ]; } public void setDimensions( int w, int h ) { width = w; height = h; pixels = new int[ w*h ]; } public void setProperties( Hashtable props ) {} public void setColorModel( ColorModel m ) {} public void setHints( int hintflags ) {} public void setPixels( int x, int y, int w, int h, ColorModel model, byte srcPixels[], int off, int scansize ) { int cx, cy; for (cy = 0; cy < h; cy++) for (cx = 0; cx < w; cx++) pixels[ (cy + y) * width + cx ] = model.getRGB( srcPixels[ off + cy * scansize + cx ] ); } public void setPixels( int x, int y, int w, int h, ColorModel model, int srcPixels[], int off, int scansize ) { int cx, cy; for (cy = 0; cy < h; cy++) for (cx = 0; cx < w; cx++) pixels[ (cy + y) * width + cx ] = model.getRGB( srcPixels[ off + cy * scansize + cx ] ); } public void imageComplete( int status ) { producer.removeConsumer( this ); myThread.resume(); } public Image getImage( Applet foo ) { return foo.createImage( new MemoryImageSource( width, height, pixels, 0, width ) ); } }