import java.awt.*; import java.awt.geom.* ; public class Test { public static void main(String[] args) { Img srcimg = new Img("drg1.jpg"); srcimg.ShowImage(); Point2D.Double p1, p2, p3, P1, P2, P3; Point2D.Double B = new Point2D.Double(); Point2D.Double A1 = new Point2D.Double(); Point2D.Double A2 = new Point2D.Double(); p1 = new Point2D.Double(0, 0); p2 = new Point2D.Double(srcimg.getWidth(), 0); p3 = new Point2D.Double(0, srcimg.getHeight()); int newwidth = 620; int newheight = 480; // int newwidth = srcimg.getWidth(); // int newheight = srcimg.getHeight(); P1 = new Point2D.Double(10, 0); P2 = new Point2D.Double(600, 0); P3 = new Point2D.Double(0, 480); Gauss g1 = new Gauss(); g1.makeMatrix(3, 4); Gauss g2 = new Gauss(); g2.makeMatrix(3, 4); g1.setValue(0, 0, P1.x); g1.setValue(0, 1, P1.y); g1.setValue(0, 2, 1.0); g1.setValue(0, 3, p1.x); g1.setValue(1, 0, P2.x); g1.setValue(1, 1, P2.y); g1.setValue(1, 2, 1.0); g1.setValue(1, 3, p2.x); g1.setValue(2, 0, P3.x); g1.setValue(2, 1, P3.y); g1.setValue(2, 2, 1.0); g1.setValue(2, 3, p3.x); g2.setValue(0, 0, P1.x); g2.setValue(0, 1, P1.y); g2.setValue(0, 2, 1.0); g2.setValue(0, 3, p1.y); g2.setValue(1, 0, P2.x); g2.setValue(1, 1, P2.y); g2.setValue(1, 2, 1.0); g2.setValue(1, 3, p2.y); g2.setValue(2, 0, P3.x); g2.setValue(2, 1, P3.y); g2.setValue(2, 2, 1.0); g2.setValue(2, 3, p3.y); g1.dumpMatrix(); double[] ret1 = g1.Eliminate(); double[] ret2 = g2.Eliminate(); double a11, a21, a22, a12, b11, b21; a11 = ret1[0]; a21 = ret1[1]; b11 = ret1[2]; a12 = ret2[0]; a22 = ret2[1]; b21 = ret2[2]; Img newimg = new Img(newwidth, newheight); int x, y; double x1, y1; double alpha, beta; int redA, blueA, greenA; int redB, blueB, greenB; int redD, blueD, greenD; Color pixel1, pixel2; for (x = 0; x < newwidth; x++) { for (y = 0; y < newheight; y++) { x1 = a11*x + a12*y; y1 = a21*x + a22*y; x1 += b21; y1 += b11; alpha = x1 - (int)x1; beta = y1 - (int)y1; //pixel = ((1-alpha) * srcimg.GetPixelColor((int)x1, (int)y1) + alpha * srcimg.GetPixelColor((int)(x1+1), (int)(y1+1))); // pixel1 = srcimg.GetPixelColor((int)x1, (int)y1); // pixel2 = srcimg.GetPixelColor((int)(x1+1), (int)(y1+1)); if((x1 < 0.0) || (x1 >(srcimg.getWidth())-1) || (y1 < 0.0) || (y1 > (srcimg.getHeight())-1)) { newimg.SetPixelColor(x, y, Color.RED); continue; } int dpx2 = Math.min((int)(x1 + 1), srcimg.getWidth()-1); int dpy2 = Math.min((int)(y1 + 1), srcimg.getHeight()-1); blueA = (int)((1-alpha) * srcimg.GetPixelColor((int)x1, (int)y1).getBlue()) + (int)(alpha * srcimg.GetPixelColor((int)(dpx2), (int)(y1)).getBlue()); redA = (int)((1-alpha) * srcimg.GetPixelColor((int)x1, (int)y1).getRed()) + (int)(alpha * srcimg.GetPixelColor((int)(dpx2), (int)(y1)).getRed()); greenA = (int)((1-alpha) * srcimg.GetPixelColor((int)x1, (int)y1).getGreen()) + (int)(alpha * srcimg.GetPixelColor((int)(dpx2), (int)(y1)).getGreen()); blueB = (int)((1-alpha) * srcimg.GetPixelColor((int)x1, (int)dpy2).getBlue()) + (int)(alpha * srcimg.GetPixelColor((int)(dpx2), (int)(dpy2)).getBlue()); redB = (int)((1-alpha) * srcimg.GetPixelColor((int)x1, (int)dpy2).getRed()) + (int)(alpha * srcimg.GetPixelColor((int)(dpx2), (int)(dpy2)).getRed()); greenB = (int)((1-alpha) * srcimg.GetPixelColor((int)x1, (int)dpy2).getGreen()) + (int)(alpha * srcimg.GetPixelColor((int)(dpx2), (int)(dpy2)).getGreen()); blueD = (int)(((1-beta) * blueA) + (beta * blueB)); redD = (int)(((1-beta) * redA) + (beta * redB)); greenD = (int)(((1-beta) * greenA) + (beta * greenB)); //newimg.SetPixelColor(x, y, srcimg.GetPixelColor((int)x1, (int)y1)); newimg.SetPixelColor(x, y, new Color(redD, greenD, blueD)); } } newimg.Build(); newimg.ShowImage(); } }