[kaffe] CVS kaffe (robilad): Resynced with GNU classpath: Jerry's java.awt.image fixes

Kaffe CVS cvs-commits at kaffe.org
Sun Nov 7 13:14:48 PST 2004


PatchSet 5419 
Date: 2004/11/07 21:10:15
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU classpath: Jerry's java.awt.image fixes

2004-11-07  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/java/awt/image/BandCombineOp.java,
        libraries/javalib/java/awt/image/ConvolveOp.java,
        libraries/javalib/java/awt/image/LookupOp.java:
        New files taken from GNU Classpath.

        * libraries/javalib/Makefile.am,
        libraries/javalib/Makefile.in,
        libraries/javalib/all.files:
        Regenerated.

        * libraries/javalib/java/awt/image/AffineTransformOp.java,
        libraries/javalib/java/awt/image/ColorConvertOp.java,
        libraries/javalib/java/awt/image/ComponentSampleModel.java,
        libraries/javalib/java/awt/image/IndexColorModel.java,
        libraries/javalib/java/awt/image/Raster.java,
        libraries/javalib/java/awt/image/RescaleOp.java,
        libraries/javalib/java/awt/image/SampleModel.java:
        Resynced with GNU Classpath.

        2004-11-06  Jerry Quinn  <jlquinn at optonline.net>

        * java/awt/image/AffineTransformOp.java (filter): Implement
        filtering and bilinear interpolation for Rasters.
         Add TYPE_BICUBIC.
        * java/awt/image/IndexColorModel.java (IndexColorModel): Actually
        use the provided colormap.  Throw documented exceptions.  Document
        exceptions.
        * java/awt/image/ComponentSampleModel.java (getDataElements,
        setDataElements): Implement SHORT, FLOAT, and INT transfer types.
        * java/awt/image/Raster.java (createBandedRaster): Implement.
        * java/awt/image/SampleModel.java (createSubsetSampleModel): Add
        javadocs.
        * java/awt/image/RescaleOp.java,
        java/awt/image/ColorConvertOp.java: Fix loop bounds.
        * java/awt/image/BandCombineOp.java,
        java/awt/image/LookupOp.java,
        java/awt/image/ConvolveOp.java: New classes.

Members: 
	ChangeLog:1.2968->1.2969 
	libraries/javalib/Makefile.am:1.259->1.260 
	libraries/javalib/Makefile.in:1.339->1.340 
	libraries/javalib/all.files:1.47->1.48 
	libraries/javalib/java/awt/image/AffineTransformOp.java:1.3->1.4 
	libraries/javalib/java/awt/image/BandCombineOp.java:INITIAL->1.1 
	libraries/javalib/java/awt/image/ColorConvertOp.java:1.1->1.2 
	libraries/javalib/java/awt/image/ComponentSampleModel.java:1.3->1.4 
	libraries/javalib/java/awt/image/ConvolveOp.java:INITIAL->1.1 
	libraries/javalib/java/awt/image/IndexColorModel.java:1.5->1.6 
	libraries/javalib/java/awt/image/LookupOp.java:INITIAL->1.1 
	libraries/javalib/java/awt/image/Raster.java:1.5->1.6 
	libraries/javalib/java/awt/image/RescaleOp.java:1.2->1.3 
	libraries/javalib/java/awt/image/SampleModel.java:1.2->1.3 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2968 kaffe/ChangeLog:1.2969
--- kaffe/ChangeLog:1.2968	Sun Nov  7 20:24:31 2004
+++ kaffe/ChangeLog	Sun Nov  7 21:10:15 2004
@@ -1,5 +1,45 @@
 2004-11-07  Dalibor Topic  <robilad at kaffe.org>
 
+	* libraries/javalib/java/awt/image/BandCombineOp.java,
+	libraries/javalib/java/awt/image/ConvolveOp.java,
+	libraries/javalib/java/awt/image/LookupOp.java:
+	New files taken from GNU Classpath.
+
+	* libraries/javalib/Makefile.am,
+	libraries/javalib/Makefile.in,
+	libraries/javalib/all.files:
+	Regenerated.
+
+	* libraries/javalib/java/awt/image/AffineTransformOp.java,
+	libraries/javalib/java/awt/image/ColorConvertOp.java,
+	libraries/javalib/java/awt/image/ComponentSampleModel.java,
+	libraries/javalib/java/awt/image/IndexColorModel.java,
+	libraries/javalib/java/awt/image/Raster.java,
+	libraries/javalib/java/awt/image/RescaleOp.java,
+	libraries/javalib/java/awt/image/SampleModel.java:
+	Resynced with GNU Classpath.
+
+	2004-11-06  Jerry Quinn  <jlquinn at optonline.net>
+
+        * java/awt/image/AffineTransformOp.java (filter): Implement
+        filtering and bilinear interpolation for Rasters.
+         Add TYPE_BICUBIC.
+        * java/awt/image/IndexColorModel.java (IndexColorModel): Actually
+        use the provided colormap.  Throw documented exceptions.  Document
+        exceptions.
+        * java/awt/image/ComponentSampleModel.java (getDataElements,
+        setDataElements): Implement SHORT, FLOAT, and INT transfer types.
+        * java/awt/image/Raster.java (createBandedRaster): Implement.
+        * java/awt/image/SampleModel.java (createSubsetSampleModel): Add
+        javadocs.
+        * java/awt/image/RescaleOp.java,
+        java/awt/image/ColorConvertOp.java: Fix loop bounds.
+        * java/awt/image/BandCombineOp.java,
+        java/awt/image/LookupOp.java,
+        java/awt/image/ConvolveOp.java: New classes.
+
+2004-11-07  Dalibor Topic  <robilad at kaffe.org>
+
 	* libraries/javalib/java/io/ObjectInputStream.java,
 	libraries/javalib/java/util/Vector.java:
 	Resynced with GNU Classpath.
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.259 kaffe/libraries/javalib/Makefile.am:1.260
--- kaffe/libraries/javalib/Makefile.am:1.259	Mon Nov  1 15:37:58 2004
+++ kaffe/libraries/javalib/Makefile.am	Sun Nov  7 21:10:16 2004
@@ -1769,6 +1769,7 @@
 java_awt_image_SRCS = \
 	java/awt/image/AffineTransformOp.java \
 	java/awt/image/AreaAveragingScaleFilter.java \
+	java/awt/image/BandCombineOp.java \
 	java/awt/image/BandedSampleModel.java \
 	java/awt/image/BufferStrategy.java \
 	java/awt/image/BufferedImage.java \
@@ -1779,6 +1780,7 @@
 	java/awt/image/ColorModel.java \
 	java/awt/image/ComponentColorModel.java \
 	java/awt/image/ComponentSampleModel.java \
+	java/awt/image/ConvolveOp.java \
 	java/awt/image/CropImageFilter.java \
 	java/awt/image/DataBuffer.java \
 	java/awt/image/DataBufferByte.java \
@@ -1796,6 +1798,7 @@
 	java/awt/image/ImagingOpException.java \
 	java/awt/image/IndexColorModel.java \
 	java/awt/image/Kernel.java \
+	java/awt/image/LookupOp.java \
 	java/awt/image/LookupTable.java \
 	java/awt/image/MemoryImageSource.java \
 	java/awt/image/MultiPixelPackedSampleModel.java \
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.339 kaffe/libraries/javalib/Makefile.in:1.340
--- kaffe/libraries/javalib/Makefile.in:1.339	Mon Nov  1 15:37:58 2004
+++ kaffe/libraries/javalib/Makefile.in	Sun Nov  7 21:10:16 2004
@@ -2231,6 +2231,7 @@
 java_awt_image_SRCS = \
 	java/awt/image/AffineTransformOp.java \
 	java/awt/image/AreaAveragingScaleFilter.java \
+	java/awt/image/BandCombineOp.java \
 	java/awt/image/BandedSampleModel.java \
 	java/awt/image/BufferStrategy.java \
 	java/awt/image/BufferedImage.java \
@@ -2241,6 +2242,7 @@
 	java/awt/image/ColorModel.java \
 	java/awt/image/ComponentColorModel.java \
 	java/awt/image/ComponentSampleModel.java \
+	java/awt/image/ConvolveOp.java \
 	java/awt/image/CropImageFilter.java \
 	java/awt/image/DataBuffer.java \
 	java/awt/image/DataBufferByte.java \
@@ -2258,6 +2260,7 @@
 	java/awt/image/ImagingOpException.java \
 	java/awt/image/IndexColorModel.java \
 	java/awt/image/Kernel.java \
+	java/awt/image/LookupOp.java \
 	java/awt/image/LookupTable.java \
 	java/awt/image/MemoryImageSource.java \
 	java/awt/image/MultiPixelPackedSampleModel.java \
Index: kaffe/libraries/javalib/all.files
diff -u kaffe/libraries/javalib/all.files:1.47 kaffe/libraries/javalib/all.files:1.48
--- kaffe/libraries/javalib/all.files:1.47	Mon Nov  1 15:37:59 2004
+++ kaffe/libraries/javalib/all.files	Sun Nov  7 21:10:17 2004
@@ -1321,6 +1321,7 @@
 java/awt/im/spi/InputMethodDescriptor.java
 java/awt/image/AffineTransformOp.java
 java/awt/image/AreaAveragingScaleFilter.java
+java/awt/image/BandCombineOp.java
 java/awt/image/BandedSampleModel.java
 java/awt/image/BufferStrategy.java
 java/awt/image/BufferedImage.java
@@ -1331,6 +1332,7 @@
 java/awt/image/ColorModel.java
 java/awt/image/ComponentColorModel.java
 java/awt/image/ComponentSampleModel.java
+java/awt/image/ConvolveOp.java
 java/awt/image/CropImageFilter.java
 java/awt/image/DataBuffer.java
 java/awt/image/DataBufferByte.java
@@ -1348,6 +1350,7 @@
 java/awt/image/ImagingOpException.java
 java/awt/image/IndexColorModel.java
 java/awt/image/Kernel.java
+java/awt/image/LookupOp.java
 java/awt/image/LookupTable.java
 java/awt/image/MemoryImageSource.java
 java/awt/image/MultiPixelPackedSampleModel.java
Index: kaffe/libraries/javalib/java/awt/image/AffineTransformOp.java
diff -u kaffe/libraries/javalib/java/awt/image/AffineTransformOp.java:1.3 kaffe/libraries/javalib/java/awt/image/AffineTransformOp.java:1.4
--- kaffe/libraries/javalib/java/awt/image/AffineTransformOp.java:1.3	Mon Oct  4 13:32:34 2004
+++ kaffe/libraries/javalib/java/awt/image/AffineTransformOp.java	Sun Nov  7 21:10:17 2004
@@ -42,8 +42,10 @@
 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;
+import java.util.Arrays;
 
 /**
  * This class performs affine transformation between two images or 
@@ -56,13 +58,15 @@
 {
     public static final int TYPE_NEAREST_NEIGHBOR = 1;
     public static final int TYPE_BILINEAR = 2;
+    public static final int TYPE_BICUBIC = 3;
 
     private AffineTransform transform;
     private RenderingHints hints;
     
     /**
      * Construct AffineTransformOp with the given xform and interpolationType.
-     * Interpolation type can be either TYPE_BILINEAR or TYPE_NEAREST_NEIGHBOR.
+     * Interpolation type can be TYPE_BILINEAR, TYPE_BICUBIC or
+     * TYPE_NEAREST_NEIGHBOR.
      *
      * @param xform AffineTransform that will applied to the source image 
      * @param interpolationType type of interpolation used
@@ -70,15 +74,23 @@
     public AffineTransformOp (AffineTransform xform, int interpolationType)
     {
       this.transform = xform;
+      if (xform.getDeterminant() == 0)
+        throw new ImagingOpException(null);
 
-      if (interpolationType == 0) 
+      switch (interpolationType)
+      {
+      case TYPE_BILINEAR:
         hints = new RenderingHints (RenderingHints.KEY_INTERPOLATION, 
                                     RenderingHints.VALUE_INTERPOLATION_BILINEAR);
-				   
-      else
+        break;
+      case TYPE_BICUBIC:
+        hints = new RenderingHints (RenderingHints.KEY_INTERPOLATION, 
+				    RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+        break;
+      default:
         hints = new RenderingHints (RenderingHints.KEY_INTERPOLATION,
                                     RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
-
+      }
     }
 
     /**
@@ -91,6 +103,8 @@
     {
       this.transform = xform;
       this.hints = hints;
+      if (xform.getDeterminant() == 0)
+        throw new ImagingOpException(null);
     }
 
     /**
@@ -183,7 +197,97 @@
      */
     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");
+      
+      double[] dpts = new double[dst.getWidth() * 2];
+      double[] pts = new double[dst.getWidth() * 2];
+      for (int x = 0; x < dst.getWidth(); x++)
+      {
+	dpts[2 * x] = x + dst.getMinX();
+	dpts[2 * x + 1] = x;
+      }
+      Rectangle srcbounds = src.getBounds();
+      if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR))
+      {
+	for (int y = dst.getMinY(); y < dst.getMinY() + dst.getHeight(); y++)
+	  {
+	    try {
+	      transform.inverseTransform(dpts, 0, pts, 0, dst.getWidth() * 2);
+	    } catch (NoninvertibleTransformException e) {
+	      // Can't happen since the constructor traps this
+	      e.printStackTrace();
+	    }
+        
+	    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));
+	      }
+	  }
+      }
+      else if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_BILINEAR))
+      {
+        double[] tmp = new double[4 * src.getNumBands()];
+        for (int y = dst.getMinY(); y < dst.getMinY() + dst.getHeight(); y++)
+        {
+          try {
+            transform.inverseTransform(dpts, 0, pts, 0, dst.getWidth() * 2);
+          } catch (NoninvertibleTransformException e) {
+            // Can't happen since the constructor traps this
+            e.printStackTrace();
+          }
+	    
+          for (int x = 0; x < dst.getWidth(); x++)
+          {
+            if (!srcbounds.contains(pts[2 * x], pts[2 * x + 1]))
+              continue;
+            int xx = (int)pts[2 * x];
+            int yy = (int)pts[2 * x + 1];
+            double dx = (pts[2 * x] - xx);
+            double dy = (pts[2 * x + 1] - yy);
+		
+            // TODO write this more intelligently
+            if (xx == src.getMinX() + src.getWidth() - 1 ||
+                yy == src.getMinY() + src.getHeight() - 1)
+            {
+              // bottom or right edge
+              Arrays.fill(tmp, 0);
+              src.getPixel(xx, yy, tmp);
+            }
+            else
+	    {
+              // Normal case
+              src.getPixels(xx, yy, 2, 2, tmp);
+	      for (int b = 0; b < src.getNumBands(); b++)
+		tmp[b] = dx * dy * tmp[b]
+		  + (1 - dx) * dy * tmp[b + src.getNumBands()]
+		  + dx * (1 - dy) * tmp[b + 2 * src.getNumBands()]
+		  + (1 - dx) * (1 - dy) * tmp[b + 3 * src.getNumBands()];
+	    }
+            dst.setPixel(x, y, tmp);
+          }
+        }
+      }
+      else
+      {
+        // Bicubic
+        throw new UnsupportedOperationException("not implemented yet");
+      }
+      
+      return dst;  
     }
 
     /**
===================================================================
Checking out kaffe/libraries/javalib/java/awt/image/BandCombineOp.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/java/awt/image/BandCombineOp.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/java/awt/image/BandCombineOp.java	Sun Nov  7 21:14:47 2004
@@ -0,0 +1,168 @@
+/* Copyright (C) 2004  Free Software Foundation
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.awt.image;
+
+import java.awt.Point;
+import java.awt.RenderingHints;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * Filter Raster pixels by applying a matrix.
+ * 
+ * BandCombineOp applies a matrix to each pixel to produce new pixel values.
+ * The width of the matrix must be the same or one more than the number of
+ * bands in the source Raster.  If one more, the pixels in the source are
+ * assumed to contain an implicit 1.0 at the end.
+ * 
+ * The rows of the matrix are multiplied by the pixel to produce the values
+ * for the destination.  Therefore the destination Raster must contain the
+ * same number of bands as the number of rows in the filter matrix.
+ * 
+ * @author Jerry Quinn <jlquinn at optonline.net>
+ */
+public class BandCombineOp implements RasterOp
+{
+  private RenderingHints hints;
+  private float[][] matrix;
+  
+  /**
+   * Construct a BandCombineOp.
+   * 
+   * @param matrix The matrix to filter pixels with.
+   * @param hints Rendering hints to apply.  Ignored.
+   */
+  public BandCombineOp(float[][] matrix, RenderingHints hints)
+  {
+    this.matrix = matrix;
+    this.hints = hints;
+  }
+
+  /**
+   * Filter Raster pixels through a matrix.
+   * 
+   * Applies the Op matrix to source pixes to produce dest pixels.  Each row
+   * of the matrix is multiplied by the src pixel components to produce the
+   * dest pixel.  If matrix is one more than the number of bands in the src,
+   * the last element is implicitly multiplied by 1, i.e. added to the sum
+   * for that dest component.
+   * 
+   * If dest is null, a suitable Raster is created.  This implementation uses
+   * createCompatibleDestRaster.  
+   * 
+   * @param src The source Raster.
+   * @param dest  The destination Raster, or null.
+   * @returns The destination Raster or an allocated Raster.
+   * @see java.awt.image.RasterOp#filter(java.awt.image.Raster,
+   *java.awt.image.WritableRaster)
+   */
+  public WritableRaster filter(Raster src, WritableRaster dest) {
+    if (dest == null)
+      dest = createCompatibleDestRaster(src);
+    
+    // Filter the pixels
+    float[] spix = new float[matrix[0].length];
+    float[] dpix = new float[matrix.length];
+    for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++)
+      for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++)
+      {
+        // In case matrix rows have implicit translation
+        spix[spix.length - 1] = 1.0f;
+        src.getPixel(x, y, spix);
+        for (int i = 0; i < matrix.length; i++)
+        {
+          dpix[i] = 0;
+          for (int j = 0; j < matrix[0].length; j++)
+            dpix[i] += spix[j] * matrix[i][j];
+        }
+        dest.setPixel(x, y, dpix);
+      }
+
+    return dest;
+  }
+
+  /* (non-Javadoc)
+   * @see java.awt.image.RasterOp#getBounds2D(java.awt.image.Raster)
+   */
+  public Rectangle2D getBounds2D(Raster src)
+  {
+    return src.getBounds();
+  }
+
+  /**
+   * Creates a new WritableRaster that can be used as the destination for this
+   * Op.  This implementation creates a Banded Raster with data type FLOAT.
+   * @see
+   *java.awt.image.RasterOp#createCompatibleDestRaster(java.awt.image.Raster) 
+   */
+  public WritableRaster createCompatibleDestRaster(Raster src)
+  {
+    return Raster.createBandedRaster(DataBuffer.TYPE_FLOAT, src.getWidth(),
+        src.getHeight(), matrix.length,
+        new Point(src.getMinX(), src.getMinY()));
+  }
+
+  /** Return corresponding destination point for source point.
+   * 
+   * LookupOp will return the value of src unchanged.
+   * @param src The source point.
+   * @param dst The destination point.
+   * @see java.awt.image.RasterOp#getPoint2D(java.awt.geom.Point2D,
+   *java.awt.geom.Point2D) 
+   */
+  public Point2D getPoint2D(Point2D src, Point2D dst)
+  {
+    if (dst == null) return (Point2D)src.clone();
+    dst.setLocation(src);
+    return dst;
+  }
+
+  /* (non-Javadoc)
+   * @see java.awt.image.RasterOp#getRenderingHints()
+   */
+  public RenderingHints getRenderingHints()
+  {
+    return hints;
+  }
+  
+  /** Return the matrix for this Op. */
+  public float[][] getMatrix()
+  {
+    return matrix;
+  }
+
+}
Index: kaffe/libraries/javalib/java/awt/image/ColorConvertOp.java
diff -u kaffe/libraries/javalib/java/awt/image/ColorConvertOp.java:1.1 kaffe/libraries/javalib/java/awt/image/ColorConvertOp.java:1.2
--- kaffe/libraries/javalib/java/awt/image/ColorConvertOp.java:1.1	Sat Oct 30 11:54:18 2004
+++ kaffe/libraries/javalib/java/awt/image/ColorConvertOp.java	Sun Nov  7 21:10:18 2004
@@ -300,16 +300,16 @@
         RenderingHints.VALUE_COLOR_RENDER_QUALITY)
     {
       // use cie for accuracy
-      for (int y = src.getMinY(); y < src.getHeight() - src.getMinY(); y++)
-        for (int x = src.getMinX(); x < src.getWidth() - src.getMinX(); x++)
+      for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++)
+        for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++)
           dst.setPixel(x, y,
 		       dcs.fromCIEXYZ(scs.toCIEXYZ(src.getPixel(x, y, sbuf))));
     }
     else
     {
       // use rgb - it's probably faster
-      for (int y = src.getMinY(); y < src.getHeight() - src.getMinY(); y++)
-        for (int x = src.getMinX(); x < src.getWidth() - src.getMinX(); x++)
+      for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++)
+        for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++)
           dst.setPixel(x, y,
 		       dcs.fromRGB(scs.toRGB(src.getPixel(x, y, sbuf))));
     }
Index: kaffe/libraries/javalib/java/awt/image/ComponentSampleModel.java
diff -u kaffe/libraries/javalib/java/awt/image/ComponentSampleModel.java:1.3 kaffe/libraries/javalib/java/awt/image/ComponentSampleModel.java:1.4
--- kaffe/libraries/javalib/java/awt/image/ComponentSampleModel.java:1.3	Mon Sep 27 17:41:08 2004
+++ kaffe/libraries/javalib/java/awt/image/ComponentSampleModel.java	Sun Nov  7 21:10:18 2004
@@ -265,6 +265,18 @@
 	      }
 	    return outUShort;
 
+	  case DataBuffer.TYPE_SHORT:
+	    DataBufferShort inShort = (DataBufferShort) data;
+	    short[] outShort = (short[]) obj;
+	    if (outShort == null) outShort = new short[numBands];
+		
+	    for (int b=0; b<numBands; b++)
+	      {
+		int dOffset = totalBandDataOffsets[b];
+		outShort[b] = inShort.getData(bankIndices[b])[dOffset];
+	      }
+	    return outShort;
+
 	  case DataBuffer.TYPE_INT:
 	    DataBufferInt inInt = (DataBufferInt) data;
 	    int[] outInt = (int[]) obj;
@@ -276,8 +288,31 @@
 		outInt[b] = inInt.getData(bankIndices[b])[dOffset];
 	      }
 	    return outInt;
-		
-	    // FIXME: Fill in the other possible types.
+
+	  case DataBuffer.TYPE_FLOAT:
+	    DataBufferFloat inFloat = (DataBufferFloat) data;
+	    float[] outFloat = (float[]) obj;
+	    if (outFloat == null) outFloat = new float[numBands];
+
+	    for (int b=0; b<numBands; b++)
+	      {
+		int dOffset = totalBandDataOffsets[b];
+		outFloat[b] = inFloat.getData(bankIndices[b])[dOffset];
+	      }
+	    return outFloat;
+	    
+	  case DataBuffer.TYPE_DOUBLE:
+	    DataBufferDouble inDouble = (DataBufferDouble) data;
+	    double[] outDouble = (double[]) obj;
+	    if (outDouble == null) outDouble = new double[numBands];
+
+	    for (int b=0; b<numBands; b++)
+	      {
+		int dOffset = totalBandDataOffsets[b];
+		outDouble[b] = inDouble.getData(bankIndices[b])[dOffset];
+	      }
+	    return outDouble;
+	    
 	  default:
 	      throw new IllegalStateException("unknown transfer type " +
 					      getTransferType());
@@ -449,10 +484,40 @@
 	  
 	  return;
 	}
+      case DataBuffer.TYPE_SHORT:
+	{
+	  DataBufferShort out = (DataBufferShort) data;
+	  short[] in = (short[]) obj;
+	  
+	  for (int b=0; b<numBands; b++)
+	    out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b];
+	  
+	  return;
+	}
       case DataBuffer.TYPE_INT:
 	{
 	  DataBufferInt out = (DataBufferInt) data;
 	  int[] in = (int[]) obj;
+	  
+	  for (int b=0; b<numBands; b++)
+	    out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b];
+	  
+	  return;
+	}
+      case DataBuffer.TYPE_FLOAT:
+	{
+	  DataBufferFloat out = (DataBufferFloat) data;
+	  float[] in = (float[]) obj;
+	  
+	  for (int b=0; b<numBands; b++)
+	    out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b];
+	  
+	  return;
+	}
+      case DataBuffer.TYPE_DOUBLE:
+	{
+	  DataBufferDouble out = (DataBufferDouble) data;
+	  double[] in = (double[]) obj;
 	  
 	  for (int b=0; b<numBands; b++)
 	    out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b];
===================================================================
Checking out kaffe/libraries/javalib/java/awt/image/ConvolveOp.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/java/awt/image/ConvolveOp.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/java/awt/image/ConvolveOp.java	Sun Nov  7 21:14:48 2004
@@ -0,0 +1,305 @@
+/*
+ * Created on Nov 1, 2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package java.awt.image;
+
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.util.Arrays;
+
+/**
+ * Convolution filter.
+ * 
+ * ConvolveOp convolves the source image with a Kernel to generate a
+ * destination image.  This involves multiplying each pixel and its neighbors
+ * with elements in the kernel to compute a new pixel.
+ * 
+ * Each band in a Raster is convolved and copied to the destination Raster.
+ * 
+ * For BufferedImages, convolution is applied to all components.  If the
+ * source is not premultiplied, the data will be premultiplied before
+ * convolving.  Premultiplication will be undone if the destination is not
+ * premultiplied.  Color conversion will be applied if needed.
+ * 
+ * @author jlquinn at optonline.net
+ */
+public class ConvolveOp implements BufferedImageOp, RasterOp
+{
+  /** Edge pixels are set to 0. */
+  public static final int EDGE_ZERO_FILL = 0;
+  
+  /** Edge pixels are copied from the source. */
+  public static final int EDGE_NO_OP = 1;
+  
+  private Kernel kernel;
+  private int edge;
+  private RenderingHints hints;
+
+  /**
+   * Construct a ConvolveOp.
+   * 
+   * The edge condition specifies that pixels outside the area that can be
+   * filtered are either set to 0 or copied from the source image.
+   * 
+   * @param kernel The kernel to convolve with.
+   * @param edgeCondition Either EDGE_ZERO_FILL or EDGE_NO_OP.
+   * @param hints Rendering hints for color conversion, or null.
+   */
+  public ConvolveOp(Kernel kernel,
+      				int edgeCondition,
+      				RenderingHints hints)
+  {
+    this.kernel = kernel;
+    edge = edgeCondition;
+    this.hints = hints;
+  }
+  
+  /**
+   * Construct a ConvolveOp.
+   * 
+   * The edge condition defaults to EDGE_ZERO_FILL.
+   * 
+   * @param kernel The kernel to convolve with.
+   */
+  public ConvolveOp(Kernel kernel)
+  {
+    this.kernel = kernel;
+    edge = EDGE_ZERO_FILL;
+    hints = null;
+  }
+
+  
+  /* (non-Javadoc)
+   * @see java.awt.image.BufferedImageOp#filter(java.awt.image.BufferedImage,
+   * java.awt.image.BufferedImage)
+   */
+  public BufferedImage filter(BufferedImage src, BufferedImage dst)
+  {
+    if (src == dst)
+      throw new IllegalArgumentException();
+    
+    if (dst == null)
+      dst = createCompatibleDestImage(src, src.getColorModel());
+    
+    // Make sure source image is premultiplied
+    BufferedImage src1 = src;
+    if (!src.isPremultiplied)
+    {
+      src1 = createCompatibleDestImage(src, src.getColorModel());
+      src.copyData(src1.getRaster());
+      src1.coerceData(true);
+    }
+
+    BufferedImage dst1 = dst;
+    if (!src.getColorModel().equals(dst.getColorModel()))
+      dst1 = createCompatibleDestImage(src, src.getColorModel());
+
+    filter(src1.getRaster(), dst1.getRaster());
+    
+    if (dst1 != dst)
+    {
+      // Convert between color models.
+      // TODO Check that premultiplied alpha is handled correctly here.
+      Graphics2D gg = dst.createGraphics();
+      gg.setRenderingHints(hints);
+      gg.drawImage(dst1, 0, 0, null);
+      gg.dispose();
+    }
+    
+    return dst;
+  }
+
+  /* (non-Javadoc)
+   * @see
+   * java.awt.image.BufferedImageOp#createCompatibleDestImage(java.awt.image.BufferedImage,
+   * java.awt.image.ColorModel)
+   */
+  public BufferedImage createCompatibleDestImage(BufferedImage src,
+						 ColorModel dstCM)
+  {
+    // FIXME: set properties to those in src
+    return new BufferedImage(dstCM,
+			     src.getRaster().createCompatibleWritableRaster(),
+			     src.isPremultiplied, null);
+  }
+
+  /* (non-Javadoc)
+   * @see java.awt.image.RasterOp#getRenderingHints()
+   */
+  public RenderingHints getRenderingHints()
+  {
+    return hints;
+  }
+  
+  /**
+   * @return The edge condition.
+   */
+  public int getEdgeCondition()
+  {
+    return edge;
+  }
+  
+  /**
+   * @return The convolution kernel.
+   */
+  public Kernel getKernel()
+  {
+    return kernel;
+  }
+
+  /* (non-Javadoc)
+   * @see java.awt.image.RasterOp#filter(java.awt.image.Raster,
+   * java.awt.image.WritableRaster)
+   */
+  public WritableRaster filter(Raster src, WritableRaster dest) {
+    if (src.numBands != dest.numBands)
+      throw new ImagingOpException(null);
+    if (src == dest)
+      throw new IllegalArgumentException();
+    if (src.getWidth() < kernel.getWidth() ||
+        src.getHeight() < kernel.getHeight())
+      throw new ImagingOpException(null);
+    
+    if (dest == null)
+      dest = createCompatibleDestRaster(src);
+
+    // Deal with bottom edge
+    if (edge == EDGE_ZERO_FILL)
+    {
+      float[] zeros = new float[src.getNumBands() * src.getWidth()
+				* (kernel.getYOrigin() - 1)];
+      Arrays.fill(zeros, 0);
+      dest.setPixels(src.getMinX(), src.getMinY(), src.getWidth(),
+		     kernel.getYOrigin() - 1, zeros);
+    }
+    else
+    {
+      float[] vals = new float[src.getNumBands() * src.getWidth()
+			       * (kernel.getYOrigin() - 1)];
+      src.getPixels(src.getMinX(), src.getMinY(), src.getWidth(),
+		    kernel.getYOrigin() - 1, vals);
+      dest.setPixels(src.getMinX(), src.getMinY(), src.getWidth(),
+		     kernel.getYOrigin() - 1, vals);
+    }
+    
+    // Handle main section
+    float[] kvals = kernel.getKernelData(null);
+
+    float[] tmp = new float[kernel.getWidth() * kernel.getHeight()];
+    for (int y = src.getMinY() + kernel.getYOrigin();
+    	 y < src.getMinY() + src.getHeight() - kernel.getYOrigin() / 2; y++)
+    {
+      // Handle unfiltered edge pixels at start of line
+      float[] t1 = new float[(kernel.getXOrigin() - 1) * src.getNumBands()];
+      if (edge == EDGE_ZERO_FILL)
+        Arrays.fill(t1, 0);
+      else
+        src.getPixels(src.getMinX(), y, kernel.getXOrigin() - 1, 1, t1);
+      dest.setPixels(src.getMinX(), y, kernel.getXOrigin() - 1, 1, t1);
+      
+      for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++)
+      {
+        // FIXME: This needs a much more efficient implementation
+        for (int b = 0; b < src.getNumBands(); b++)
+        {
+          float v = 0;
+          src.getSamples(x, y, kernel.getWidth(), kernel.getHeight(), b, tmp);
+          for (int i=0; i < tmp.length; i++)
+            v += tmp[i] * kvals[i];
+          dest.setSample(x, y, b, v);
+        }
+      }
+
+      // Handle unfiltered edge pixels at end of line
+      float[] t2 = new float[(kernel.getWidth() / 2) * src.getNumBands()];
+      if (edge == EDGE_ZERO_FILL)
+        Arrays.fill(t2, 0);
+      else
+        src.getPixels(src.getMinX() + src.getWidth()
+		      - (kernel.getWidth() / 2),
+		      y, kernel.getWidth() / 2, 1, t2);
+      dest.setPixels(src.getMinX() + src.getWidth() - (kernel.getWidth() / 2),
+		     y, kernel.getWidth() / 2, 1, t2);
+    }
+    for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++)
+      for (int x = src.getMinX(); x< src.getWidth() + src.getMinX(); x++)
+      {
+        
+      }
+    for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++)
+      for (int x = src.getMinX(); x< src.getWidth() + src.getMinX(); x++)
+      {
+        
+      }
+      
+    // Handle top edge
+    if (edge == EDGE_ZERO_FILL)
+    {
+      float[] zeros = new float[src.getNumBands() * src.getWidth() *
+                                (kernel.getHeight() / 2)];
+      Arrays.fill(zeros, 0);
+      dest.setPixels(src.getMinX(),
+          src.getHeight() + src.getMinY() - (kernel.getHeight() / 2),
+          src.getWidth(), kernel.getHeight() / 2, zeros);
+    }
+    else
+    {
+      float[] vals = new float[src.getNumBands() * src.getWidth() *
+                               (kernel.getHeight() / 2)];
+      src.getPixels(src.getMinX(),
+		    src.getHeight() + src.getMinY()
+		    - (kernel.getHeight() / 2),
+		    src.getWidth(), kernel.getHeight() / 2, vals);
+      dest.setPixels(src.getMinX(),
+		     src.getHeight() + src.getMinY()
+		     - (kernel.getHeight() / 2),
+		     src.getWidth(), kernel.getHeight() / 2, vals);
+    }
+    
+    return dest;
+  }
+
+  /* (non-Javadoc)
+   * @see java.awt.image.RasterOp#createCompatibleDestRaster(java.awt.image.Raster)
+   */
+  public WritableRaster createCompatibleDestRaster(Raster src)
+  {
+    return src.createCompatibleWritableRaster();
+  }
+
+  /* (non-Javadoc)
+   * @see java.awt.image.BufferedImageOp#getBounds2D(java.awt.image.BufferedImage)
+   */
+  public Rectangle2D getBounds2D(BufferedImage src)
+  {
+    return src.getRaster().getBounds();
+  }
+
+  /* (non-Javadoc)
+   * @see java.awt.image.RasterOp#getBounds2D(java.awt.image.Raster)
+   */
+  public Rectangle2D getBounds2D(Raster src)
+  {
+    return src.getBounds();
+  }
+
+  /** Return corresponding destination point for source point.
+   * 
+   * ConvolveOp will return the value of src unchanged.
+   * @param src The source point.
+   * @param dst The destination point.
+   * @see java.awt.image.RasterOp#getPoint2D(java.awt.geom.Point2D,
+   * java.awt.geom.Point2D)
+   */
+  public Point2D getPoint2D(Point2D src, Point2D dst)
+  {
+    if (dst == null) return (Point2D)src.clone();
+    dst.setLocation(src);
+    return dst;
+  }
+}
Index: kaffe/libraries/javalib/java/awt/image/IndexColorModel.java
diff -u kaffe/libraries/javalib/java/awt/image/IndexColorModel.java:1.5 kaffe/libraries/javalib/java/awt/image/IndexColorModel.java:1.6
--- kaffe/libraries/javalib/java/awt/image/IndexColorModel.java:1.5	Mon Oct  4 13:32:34 2004
+++ kaffe/libraries/javalib/java/awt/image/IndexColorModel.java	Sun Nov  7 21:10:18 2004
@@ -166,6 +166,7 @@
    * @param cmap packed color components
    * @param start the offset of the first color component in <code>cmap</code>
    * @param hasAlpha <code>cmap</code> has alpha values
+   * @throws IllegalArgumentException if bits < 1, bits > 16, or size < 1.
    */
   public IndexColorModel (int bits, int size, byte[] cmap, int start, 
                           boolean hasAlpha)
@@ -174,34 +175,64 @@
   }
 
   /**
-   * Each array much contain <code>size</code> elements.  For each 
-   * array, the i-th color is described by reds[i], greens[i], 
-   * blues[i], alphas[i], unless alphas is not specified, then all the 
-   * colors are opaque except for the transparent color. 
-   *
+   * Construct an IndexColorModel from an array of red, green, blue, and

*** Patch too long, truncated ***




More information about the kaffe mailing list