1 package JSci.instruments; 2 3 import java.awt.*; 4 import java.awt.image.*; 5 import java.util.*; 6 7 8 9 public abstract class Image implements Dimensions { 10 11 12 public int getWidth() { return getSize().width; } 13 14 15 public int getHeight() { return getSize().height; } 16 17 18 public abstract Dimension getSize(); 19 20 21 public int getScansize() { return getSize().width; } 22 23 24 public int getOffset() { return 0; } 25 26 private static ColorModel cm; 27 static { 28 byte [] r = new byte[256]; 29 byte [] g = new byte[256]; 30 byte [] b = new byte[256]; 31 for (int j=0;j<256;j++) r[j]=g[j]=b[j]=(byte)j; 32 cm = new IndexColorModel(8,256,r,g,b); 33 } 34 35 public ColorModel getColorModel() { return cm; } 36 37 38 public abstract byte[] getData(); 39 40 41 public long getTimeStamp() { return 0; } 42 43 44 private ArrayList ovrl = new ArrayList(); 45 46 50 public void doOverlay(Graphics g) { 51 for (int j=0;j<ovrl.size();j++) ((Overlay)(ovrl.get(j))).paint(g) ; 52 } 53 54 57 public void addOverlay(Overlay o) { ovrl.add(o); } 58 59 62 public Image getSubImage(Rectangle r) { 63 final int w=r.width; 64 final int h=r.height; 65 final byte[] b=new byte[w*h]; 66 for (int j=0;j<w;j++) for (int k=0;k<h;k++) 67 b[j+k*w]=getData()[getOffset()+(r.x+j)+(r.y+k)*getScansize()]; 68 return new Image() { 69 public int getWidth() { return w; } 70 public int getHeight() { return h; } 71 public Dimension getSize() { return new Dimension(w,h); } 72 public int getScansize() { return w; } 73 public int getOffset() { return 0; } 74 public byte[] getData() { return b; } 75 }; 76 } 77 78 79 } 80 81 82 | Popular Tags |