This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gui] Implement AffineTransformOp raster filter


2004-11-02 Jerry Quinn <jlquinn@optonline.net>

	* java/awt/image/AffineTransformOp.java (filter): Implement Raster
	filtering.

Index: AffineTransformOp.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/image/AffineTransformOp.java,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -r1.1.2.7 -r1.1.2.8
--- AffineTransformOp.java	7 Oct 2004 07:00:42 -0000	1.1.2.7
+++ AffineTransformOp.java	3 Nov 2004 04:22:24 -0000	1.1.2.8
@@ -42,6 +42,7 @@
 import java.awt.Rectangle;
 import java.awt.RenderingHints;
 import java.awt.geom.AffineTransform;
+import java.awt.geom.NoninvertibleTransformException;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;

@@ -70,6 +71,8 @@
     public AffineTransformOp (AffineTransform xform, int interpolationType)
     {
       this.transform = xform;
+      if (xform.getDeterminant() == 0)
+        throw new ImagingOpException(null);

       if (interpolationType == 0)
         hints = new RenderingHints (RenderingHints.KEY_INTERPOLATION,
@@ -91,6 +94,8 @@
     {
       this.transform = xform;
       this.hints = hints;
+      if (xform.getDeterminant() == 0)
+        throw new ImagingOpException(null);
     }

     /**
@@ -183,7 +188,47 @@
      */
     public WritableRaster filter (Raster src, WritableRaster dst)
     {
-      throw new UnsupportedOperationException ("not implemented yet");	
+      if (dst == src)
+        throw new IllegalArgumentException("src image cannot be the same as"
+					   + " the dst image");
+
+      if (dst == null)
+        dst = createCompatibleDestRaster(src);
+
+      if (src.getNumBands() != dst.getNumBands())
+        throw new IllegalArgumentException("src and dst must have same number"
+					   + " of bands");
+
+      Rectangle srcbounds = src.getBounds();
+      for (int y = dst.getMinY(); y < dst.getMinY() + dst.getHeight(); y++)
+      {
+        double[] pts = new double[dst.getWidth() * 2];
+        for (int x = 0; x < dst.getWidth(); x++)
+        {
+          pts[2 * x] = x + dst.getMinX();
+          pts[2 * x + 1] = y;
+        }
+        try {
+          transform.inverseTransform(pts, 0, pts, 0, dst.getWidth() * 2);
+        } catch (NoninvertibleTransformException e) {
+          // Can't happen since the constructor traps this
+          e.printStackTrace();
+        }
+
+        // FIXME: nearest neighbor is hardwired here.  In fact, these should
+        // be rounded properly.
+        for (int x = 0; x < dst.getWidth(); x++)
+        {
+          if (!srcbounds.contains(pts[2 * x], pts[2 * x + 1]))
+            continue;
+          dst.setDataElements(x + dst.getMinX(), y,
+			      src.getDataElements((int)pts[2 * x],
+						  (int)pts[2 * x + 1],
+						  null));
+        }
+      }
+
+      return dst;
     }

/**


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]