/* Sample Java program for image display Bilinear Interpolation of colors by T.Nishita */ import java.applet.*; import java.awt.*; import java.awt.image.*; public class bilinear extends Applet implements Runnable { Dimension appsize; Button b1; int xres=380, yres=320; Image imageBuffer; Graphics GR; Thread thread = null; Color C = Color.darkGray; Color C00,C01,C11,C10; int index=0; public void init() { // setLayout(new BorderLayout(0,0)); Panel p = new Panel(); add(b1 = new Button("Display")); // p.add(b1 = new Button("Display")); // p.setBackground(Color.blue); add("North",p); imageBuffer = createImage(size().width, size().height); GR = imageBuffer.getGraphics(); setBackground(Color.lightGray); resize(size()); xres = size().width-50; yres = size().height-70; index=9; } public boolean action(Event e, Object o) { if (e.target == b1) { // Check Draw_button stop(); index++; start(); } return true; } public void start() { if (thread == null) { thread = new Thread(this); thread.start(); } } public void stop() { if(thread != null) { thread.stop(); thread = null; } } public void update(Graphics g) { g.drawImage(imageBuffer, 0, 0, this); } public void paint(Graphics g) { update(g); } public void run() { // set colors at the corneres C00 = col16(index++%16); C10 = col16(index++%16); C11 = col16(index++%16); C01 = col16(index++%16); for (int iy =35; iy1.) u=1.0; if(v<0.) v= 0.; if(v>1.) v=1.0; double red =((1.-u)*(double)C00.getRed() + u*(double)C10.getRed())*(1-v) + ((1.-u)*(double)C01.getRed() + u*(double)C11.getRed())*v; double green = ((1.-u)*(double)C00.getGreen() + u*(double)C10.getGreen())*(1-v) +((1.-u)*(double)C01.getGreen() + u*(double)C11.getGreen())*v; double blue = ((1.-u)*(double)C00.getBlue() + u*(double)C10.getBlue())*(1-v) + ((1.-u)*(double)C01.getBlue() + u*(double)C11.getBlue())*v; return new Color((int)red,(int)green,(int)blue); } // Colors used in Dos 16-color Display public Color col16(int i){ int code[][] ={ {0,0,0}, {0,0,168}, {0,168,0}, {0,168,168}, {168,0,0}, {168,0,168}, {168,84,0}, {168,168,168}, {84,84,84}, {84,84,255}, {84,255,84}, {84,255,255}, {255,84,84}, {255,84,255}, {255,255,84}, {255,255,255} }; return new Color(code[i][0],code[i][1],code[i][2]); } public boolean mouseDown(Event ev, int x, int y) { double v = (double)(y-35)/(double)(yres); double u = (double)(x-20)/(double)(xres); Color C = Clinear(u,v); GR.setColor(C); GR.fillRect(27,yres+40, 85, 22); GR.setColor(Color.black); GR.drawString(" C=(" + C.getRed()+"."+C.getGreen()+","+C.getBlue()+")", 25,yres+53); repaint(); return true; } }