[kaffe] CVS kaffe (dalibor): Resynced with GNU Classpath: java.awt

Kaffe CVS cvs-commits at kaffe.org
Tue May 18 07:09:02 PDT 2004


PatchSet 4746 
Date: 2004/05/18 13:38:55
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: java.awt

2004-05-18  Dalibor Topic  <robilad at kaffe.org>

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

* libraries/javalib/java/awt/image/PixelInterleavedSampleModel.java:
New file, taken from GNU Classpath.

        * libraries/javalib/java/awt/Color.java,
        libraries/javalib/java/awt/ColorPaintContext.java,
        libraries/javalib/java/awt/ComponentOrientation.java,
        libraries/javalib/java/awt/datatransfer/DataFlavor.java,
        libraries/javalib/java/awt/geom/Arc2D.java,
        libraries/javalib/java/awt/image/ColorModel.java,
        libraries/javalib/java/awt/image/ComponentColorModel.java,
        libraries/javalib/java/awt/image/ComponentSampleModel.java,
        libraries/javalib/java/awt/image/Raster.java,
        libraries/javalib/java/awt/image/SampleModel.java,
        libraries/javalib/java/awt/image/SinglePixelPackedSampleModel.java,
        libraries/javalib/java/awt/peer/MenuPeer.java:
Resynced with GNU Classpath.

2004-04-28  Ingo Proetel  <proetel at aicas.com>

* java/awt/ColorPaintContext.java (<init>): Added ColorModel to signature.
(getColorModel): Return the actual color model.
(getRaster): Implemented.
(ColorRaster): New inner class.

2004-05-07  Michael Koch  <konqueror at gmx.de>

* java/awt/geom/Arc2D.java:
Fixed javadocs all over.

2004-04-17  David Jee  <djee at redhat.com>

* java/awt/peer/MenuPeer.java
(addSeparator): Remove from interface.

2004-04-07  Ingo Proetel  <proetel at aicas.com>

* java/awt/image/SinglePixelPackedSampleModel.java (getDataElements):
New method.
(setDataElements): New method.
(setPixels): New method.
(toString): New method.

2004-04-28  Ingo Proetel  <proetel at aicas.com>

* java/awt/image/ComponentSampleModel.java (setDataSamples):Do not reset
scanline stride.

2004-04-07  Ingo Proetel  <proetel at aicas.com>

* java/awt/image/Raster.java (toString): Added method.

2004-04-28  Ingo Proetel  <proetel at aicas.com>

* java/awt/image/ComponentSampleModel.java (setDataSamples):Do not reset
scanline stride.

2004-04-15  Sascha Brawer  <brawer at dandelis.ch>

* java/awt/image/ComponentColorModel.java
(createCompatibleSampleModel): Return PixelInterleavedSampleModel
for TYPE_BYTE and TYPE_USHORT transferTypes, in order to pass the
Mauve tests on this method. Improved documentation.

2004-04-28  Ingo Proetel  <proetel at aicas.com>

* java/awt/image/ColorModel.java (getRGBdefault): Default ColorModel has
        32 bit pixels not 8 bit pixels.
(isCompatibleRaster): Added javadoc comment

Members: 
	ChangeLog:1.2319->1.2320 
	libraries/javalib/Makefile.am:1.185->1.186 
	libraries/javalib/Makefile.in:1.248->1.249 
	libraries/javalib/java/awt/Color.java:1.15->1.16 
	libraries/javalib/java/awt/ColorPaintContext.java:1.1->1.2 
	libraries/javalib/java/awt/ComponentOrientation.java:1.1->1.2 
	libraries/javalib/java/awt/datatransfer/DataFlavor.java:1.14->1.15 
	libraries/javalib/java/awt/geom/Arc2D.java:1.3->1.4 
	libraries/javalib/java/awt/image/ColorModel.java:1.8->1.9 
	libraries/javalib/java/awt/image/ComponentColorModel.java:1.3->1.4 
	libraries/javalib/java/awt/image/ComponentSampleModel.java:1.1->1.2 
	libraries/javalib/java/awt/image/PixelInterleavedSampleModel.java:INITIAL->1.1 
	libraries/javalib/java/awt/image/Raster.java:1.3->1.4 
	libraries/javalib/java/awt/image/SampleModel.java:1.1->1.2 
	libraries/javalib/java/awt/image/SinglePixelPackedSampleModel.java:1.3->1.4 
	libraries/javalib/java/awt/peer/MenuPeer.java:1.2->1.3 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2319 kaffe/ChangeLog:1.2320
--- kaffe/ChangeLog:1.2319	Tue May 18 12:33:46 2004
+++ kaffe/ChangeLog	Tue May 18 13:38:55 2004
@@ -1,5 +1,80 @@
 2004-05-18  Dalibor Topic  <robilad at kaffe.org>
 
+	* libraries/javalib/Makefile.am,
+        libraries/javalib/Makefile.in:
+	Regenerated.
+
+	* libraries/javalib/java/awt/image/PixelInterleavedSampleModel.java:
+	New file, taken from GNU Classpath.
+	
+        * libraries/javalib/java/awt/Color.java,
+        libraries/javalib/java/awt/ColorPaintContext.java,
+        libraries/javalib/java/awt/ComponentOrientation.java,
+        libraries/javalib/java/awt/datatransfer/DataFlavor.java,
+        libraries/javalib/java/awt/geom/Arc2D.java,
+        libraries/javalib/java/awt/image/ColorModel.java,
+        libraries/javalib/java/awt/image/ComponentColorModel.java,
+        libraries/javalib/java/awt/image/ComponentSampleModel.java,
+        libraries/javalib/java/awt/image/Raster.java,
+        libraries/javalib/java/awt/image/SampleModel.java,
+        libraries/javalib/java/awt/image/SinglePixelPackedSampleModel.java,
+        libraries/javalib/java/awt/peer/MenuPeer.java:
+	Resynced with GNU Classpath.
+	
+	2004-04-28  Ingo Proetel  <proetel at aicas.com>
+
+	* java/awt/ColorPaintContext.java (<init>): Added ColorModel to signature.
+	(getColorModel): Return the actual color model.
+	(getRaster): Implemented.
+	(ColorRaster): New inner class.
+
+	2004-05-07  Michael Koch  <konqueror at gmx.de>
+
+	* java/awt/geom/Arc2D.java:
+	Fixed javadocs all over.
+
+	2004-04-17  David Jee  <djee at redhat.com>
+
+	* java/awt/peer/MenuPeer.java
+	(addSeparator): Remove from interface.
+
+	2004-04-07  Ingo Proetel  <proetel at aicas.com>
+
+	* java/awt/image/SinglePixelPackedSampleModel.java (getDataElements):
+	New method.
+	(setDataElements): New method.
+	(setPixels): New method.
+	(toString): New method.
+
+	2004-04-28  Ingo Proetel  <proetel at aicas.com>
+
+	* java/awt/image/ComponentSampleModel.java (setDataSamples):Do not reset
+	scanline stride.
+
+	2004-04-07  Ingo Proetel  <proetel at aicas.com>
+
+	* java/awt/image/Raster.java (toString): Added method. 
+
+	2004-04-28  Ingo Proetel  <proetel at aicas.com>
+
+	* java/awt/image/ComponentSampleModel.java (setDataSamples):Do not reset
+	scanline stride.
+
+	2004-04-15  Sascha Brawer  <brawer at dandelis.ch>
+
+	* java/awt/image/ComponentColorModel.java
+	(createCompatibleSampleModel): Return PixelInterleavedSampleModel
+	for TYPE_BYTE and TYPE_USHORT transferTypes, in order to pass the
+	Mauve tests on this method. Improved documentation.
+
+	2004-04-28  Ingo Proetel  <proetel at aicas.com>
+
+	* java/awt/image/ColorModel.java (getRGBdefault): Default ColorModel has
+        32 bit pixels not 8 bit pixels.
+	(isCompatibleRaster): Added javadoc comment.
+
+2004-05-18  Dalibor Topic  <robilad at kaffe.org>
+
 	* libraries/javalib/java/io/BufferedReader.java:
 	Resynced with GNU Classpath.
 	
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.185 kaffe/libraries/javalib/Makefile.am:1.186
--- kaffe/libraries/javalib/Makefile.am:1.185	Tue May 18 03:35:01 2004
+++ kaffe/libraries/javalib/Makefile.am	Tue May 18 13:39:00 2004
@@ -916,6 +916,7 @@
 	java/awt/image/MemoryImageSource.java \
 	java/awt/image/PackedColorModel.java \
 	java/awt/image/PixelGrabber.java \
+	java/awt/image/PixelInterleavedSampleModel.java \
 	java/awt/image/RasterFormatException.java \
 	java/awt/image/Raster.java \
 	java/awt/image/RasterOp.java \
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.248 kaffe/libraries/javalib/Makefile.in:1.249
--- kaffe/libraries/javalib/Makefile.in:1.248	Tue May 18 03:35:01 2004
+++ kaffe/libraries/javalib/Makefile.in	Tue May 18 13:39:00 2004
@@ -1260,6 +1260,7 @@
 	java/awt/image/MemoryImageSource.java \
 	java/awt/image/PackedColorModel.java \
 	java/awt/image/PixelGrabber.java \
+	java/awt/image/PixelInterleavedSampleModel.java \
 	java/awt/image/RasterFormatException.java \
 	java/awt/image/Raster.java \
 	java/awt/image/RasterOp.java \
Index: kaffe/libraries/javalib/java/awt/Color.java
diff -u kaffe/libraries/javalib/java/awt/Color.java:1.15 kaffe/libraries/javalib/java/awt/Color.java:1.16
--- kaffe/libraries/javalib/java/awt/Color.java:1.15	Tue Sep 16 12:35:54 2003
+++ kaffe/libraries/javalib/java/awt/Color.java	Tue May 18 13:39:02 2004
@@ -294,8 +294,7 @@
    * The paint context for this solid color. Package visible for use in
    * subclass.
    */
-  // XXX get ColorPaintContext in from Classpath and merge it in
-  //transient ColorPaintContext context;
+  transient ColorPaintContext context;
 
   /**
    * Initializes a new instance of <code>Color</code> using the specified
@@ -340,7 +339,12 @@
   {
     if ((red & 255) != red || (green & 255) != green || (blue & 255) != blue
         || (alpha & 255) != alpha)
-      throw new IllegalArgumentException("Bad RGB values");
+      throw new IllegalArgumentException("Bad RGB values"
+                                        +" red=0x"+Integer.toHexString(red)
+                                        +" green=0x"+Integer.toHexString(green)
+                                        +" blue=0x"+Integer.toHexString(blue)
+                                        +" alpha=0x"+Integer.toHexString(alpha)  );
+
     value = (alpha << 24) | (red << 16) | (green << 8) | blue;
     falpha = 1;
     cs = null;
@@ -971,7 +975,7 @@
    * object, regardless of the parameters. Subclasses, however, may have a
    * mutable result.
    *
-   * @param cm the requested color model, ignored
+   * @param cm the requested color model
    * @param deviceBounds the bounding box in device coordinates, ignored
    * @param userBounds the bounding box in user coordinates, ignored
    * @param xform the bounds transformation, ignored
@@ -983,11 +987,9 @@
                                     AffineTransform xform,
                                     RenderingHints hints)
   {
-    // XXX get ColorPaintContext in from Classpath and merge it in
-    throw new Error("createContext not implemented");
-    //if (context == null)
-    //context = new ColorPaintContext(value);
-    //return context;
+    if (context == null || !context.getColorModel().equals(cm))
+      context = new ColorPaintContext(cm,value);
+    return context;
   }
 
   /**
Index: kaffe/libraries/javalib/java/awt/ColorPaintContext.java
diff -u kaffe/libraries/javalib/java/awt/ColorPaintContext.java:1.1 kaffe/libraries/javalib/java/awt/ColorPaintContext.java:1.2
--- kaffe/libraries/javalib/java/awt/ColorPaintContext.java:1.1	Fri Aug 15 16:58:55 2003
+++ kaffe/libraries/javalib/java/awt/ColorPaintContext.java	Tue May 18 13:39:02 2004
@@ -1,5 +1,5 @@
 /* ColorPaintContext.java -- context for painting solid colors
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -55,15 +55,31 @@
    * SystemColor.
    */
   final int color;
+  final ColorModel colorModel;
 
+  private ColorRaster cachedRaster;
+
+  
   /**
    * Create the context for a given color.
    *
-   * @param c the solid color to use
+   * @param c The solid color to use.
    */
-  ColorPaintContext(int c)
+  ColorPaintContext(int colorRGB)
   {
-    color = c;
+    this(ColorModel.getRGBdefault(), colorRGB);
+  }
+  
+  /**
+   * Create the context for a given color.
+   *
+   * @param cm The color model of this context. 
+   * @param c The solid color to use.
+   */
+  ColorPaintContext(ColorModel cm,int colorRGB)
+  {
+    color = colorRGB;
+    colorModel = cm;
   }
 
   /**
@@ -75,14 +91,13 @@
   }
 
   /**
-   * Return the color model of this context. This ignores the model passed
-   * in the request, since colors are always in sRGB.
+   * Return the color model of this context. 
    *
    * @return the context color model
    */
   public ColorModel getColorModel()
   {
-    return ColorModel.getRGBdefault();
+    return colorModel;
   }
 
   /**
@@ -94,10 +109,87 @@
    * @param h the height, in device space
    * @return a raster for the given area and color
    */
-  public Raster getRaster(int x, int y, int w, int h)
+  public Raster getRaster(int x, int y, int width, int height)
+  {
+   if(  cachedRaster == null 
+       || cachedRaster.getWidth() < width
+       || cachedRaster.getHeight() < height)
+   {
+     cachedRaster = new ColorRaster(colorModel, 0, 0, width, height, color);
+   }
+   return cachedRaster.createChild(0 ,0 ,width ,height ,x ,y , null);
+  }
+  
+  /**
+   * A ColorRaster is a raster that is completely filled with one color. The 
+   * data layout is taken from the color model given to the constructor.
+   */
+  private class ColorRaster extends Raster
   {
-    // XXX Implement. Sun uses undocumented implementation class
-    // sun.awt.image.IntegerInterleavedRaster.
-    throw new Error("not implemented");
+    
+    /**
+     * Create a raster that is compaltible with the given color model and 
+     * filled with the given color.
+     * @param cm The color model for this raster.
+     * @param x The smallest horizontal corrdinate in the raster.
+     * @param y The smallest vertical coordinate in the raster.
+     * @param width The width of the raster.
+     * @param height The height of the raster.
+     * @param rgbPixel The RGB value of the color for this raster.
+     */
+    ColorRaster(ColorModel cm,int x, int y, int width, int height, int rgbPixel)
+    {         
+      super(cm.createCompatibleSampleModel(width,height),new Point(x,y));
+      Object pixel = cm.getDataElements(rgbPixel,null);
+      getSampleModel().setDataElements(0, 0,
+                                       width, height,
+                                       multiplyData(pixel,null,width*height),
+                                       dataBuffer);
+    }
+    
+    
+    
+    private Object multiplyData(Object src, Object dest, int factor)
+    {
+      Object from;
+      int srcLength = 0;
+      if (src instanceof byte[])
+      {
+        srcLength = ((byte[])src).length;
+        
+        if (dest == null) dest = new byte[factor * srcLength];
+      }
+      else if (src instanceof short[])
+      {
+        srcLength = ((short[])src).length;
+        if (dest == null) dest = new short[factor * srcLength];
+      }
+      else if (src instanceof int[])
+      {
+        srcLength = ((int[]) src).length;
+        if (dest == null) dest = new int[factor * srcLength];
+      }
+      else
+      {
+        throw new ClassCastException("Unknown data buffer type");
+      }
+      
+      System.arraycopy(src,0,dest,0,srcLength);
+      
+      int count = 1;
+      while(count*2 < factor)
+      {
+        System.arraycopy(dest, 0, dest, count * srcLength, count*srcLength);
+        count *= 2; 
+      }
+      
+      if(factor > count)
+        System.arraycopy(dest,0, dest, count * srcLength, 
+                         (factor - count) * srcLength );
+      
+      return dest;
+    }
+    
   }
+  
 } // class ColorPaintContext
Index: kaffe/libraries/javalib/java/awt/ComponentOrientation.java
diff -u kaffe/libraries/javalib/java/awt/ComponentOrientation.java:1.1 kaffe/libraries/javalib/java/awt/ComponentOrientation.java:1.2
--- kaffe/libraries/javalib/java/awt/ComponentOrientation.java:1.1	Fri Aug 15 16:58:55 2003
+++ kaffe/libraries/javalib/java/awt/ComponentOrientation.java	Tue May 18 13:39:02 2004
@@ -171,13 +171,15 @@
   }
 
   /**
-   * Gets an orientation from a resource bundle. This tries the following:<ol>
+   * Gets an orientation from a resource bundle. This tries the following:
+   *
+   * <ul>
    * <li>Use the key "Orientation" to find an instance of ComponentOrientation
    * in the bundle.</li>
    * <li>Get the locale of the resource bundle, and get the orientation of
    * that locale.</li>
-   * <li>Give up and get the orientation of the default locale.<li>
-   * <ol>
+   * <li>Give up and get the orientation of the default locale.</li>
+   * </ul>
    *
    * @param bdl the bundle to use
    * @return the orientation
Index: kaffe/libraries/javalib/java/awt/datatransfer/DataFlavor.java
diff -u kaffe/libraries/javalib/java/awt/datatransfer/DataFlavor.java:1.14 kaffe/libraries/javalib/java/awt/datatransfer/DataFlavor.java:1.15
--- kaffe/libraries/javalib/java/awt/datatransfer/DataFlavor.java:1.14	Mon Mar 22 11:24:35 2004
+++ kaffe/libraries/javalib/java/awt/datatransfer/DataFlavor.java	Tue May 18 13:39:03 2004
@@ -39,11 +39,11 @@
 package java.awt.datatransfer;
 
 import java.io.ByteArrayInputStream;
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.ObjectInput;
+import java.io.IOException;
 import java.io.ObjectOutput;
+import java.io.ObjectInput;
 import java.io.Reader;
 import java.io.StringReader;
 import java.io.UnsupportedEncodingException;
@@ -270,7 +270,7 @@
 /**
  * Initializes a new instance of <code>DataFlavor</code> with the
  * specified MIME type and description.  If the MIME type has a
- * "class=<rep class>" parameter then the representation class will
+ * "class=&lt;rep class&gt;" parameter then the representation class will
  * be the class name specified. Otherwise the class defaults to
  * <code>java.io.InputStream</code>. If the human readable name
  * is not specified (<code>null</code>) then the human readable name
@@ -319,7 +319,7 @@
 /**
  * Initializes a new instance of <code>DataFlavor</code> with the
  * specified MIME type and description.  If the MIME type has a
- * "class=<rep class>" parameter then the representation class will
+ * "class=&lt;rep class&gt;" parameter then the representation class will
  * be the class name specified. Otherwise the class defaults to
  * <code>java.io.InputStream</code>. If the human readable name
  * is not specified (<code>null</code>) then the human readable name
@@ -709,10 +709,10 @@
  * are met:
  * <p>
  * <ul>
- * <li>The object is not <code>null</code>.
- * <li>The object is an instance of <code>DataFlavor</code>.
+ * <li>The object is not <code>null</code>.</li>
+ * <li>The object is an instance of <code>DataFlavor</code>.</li>
  * <li>The object's MIME type and representation class are equal to
- * this object's.
+ * this object's.</li>
  * </ul>
  *
  * @param obj The <code>Object</code> to test against.
Index: kaffe/libraries/javalib/java/awt/geom/Arc2D.java
diff -u kaffe/libraries/javalib/java/awt/geom/Arc2D.java:1.3 kaffe/libraries/javalib/java/awt/geom/Arc2D.java:1.4
--- kaffe/libraries/javalib/java/awt/geom/Arc2D.java:1.3	Wed Oct 22 10:34:50 2003
+++ kaffe/libraries/javalib/java/awt/geom/Arc2D.java	Tue May 18 13:39:04 2004
@@ -50,7 +50,7 @@
  * and while the angle can be any value, the path iterator only traverses the
  * first 360 degrees. Storage is up to the subclasses.
  *
- * @author Eric Blake <ebb9 at email.byu.edu>
+ * @author Eric Blake (ebb9 at email.byu.edu)
  * @since 1.2
  * @status updated to 1.4, but still missing functionality
  */
@@ -527,7 +527,7 @@
    * This class is used to iterate over an arc. Since ellipses are a subclass
    * of arcs, this is used by Ellipse2D as well.
    *
-   * @author Eric Blake <ebb9 at email.byu.edu>
+   * @author Eric Blake (ebb9 at email.byu.edu)
    */
   static final class ArcIterator implements PathIterator
   {
@@ -766,7 +766,7 @@
   /**
    * This class implements an arc in double precision.
    *
-   * @author Eric Blake <ebb9 at email.byu.edu
+   * @author Eric Blake (ebb9 at email.byu.edu)
    * @since 1.2
    */
   public static class Double extends Arc2D
@@ -985,7 +985,7 @@
   /**
    * This class implements an arc in float precision.
    *
-   * @author Eric Blake <ebb9 at email.byu.edu
+   * @author Eric Blake (ebb9 at email.byu.edu)
    * @since 1.2
    */
   public static class Float extends Arc2D
Index: kaffe/libraries/javalib/java/awt/image/ColorModel.java
diff -u kaffe/libraries/javalib/java/awt/image/ColorModel.java:1.8 kaffe/libraries/javalib/java/awt/image/ColorModel.java:1.9
--- kaffe/libraries/javalib/java/awt/image/ColorModel.java:1.8	Mon Mar 22 11:24:39 2004
+++ kaffe/libraries/javalib/java/awt/image/ColorModel.java	Tue May 18 13:39:05 2004
@@ -37,11 +37,10 @@
 
 package java.awt.image;
 
-import gnu.java.awt.Buffers;
-
 import java.awt.Point;
 import java.awt.Transparency;
 import java.awt.color.ColorSpace;
+import gnu.java.awt.Buffers;
 
 /**
  * A color model operates with colors in several formats:
@@ -167,7 +166,7 @@
    */
   public static ColorModel getRGBdefault()
   {
-    return new DirectColorModel(8, 0xff0000, 0xff00, 0xff, 0xff000000);
+    return new DirectColorModel(32, 0xff0000, 0xff00, 0xff, 0xff000000);
   }
 
   public final boolean hasAlpha()
@@ -598,7 +597,11 @@
     return null;
   }
     
-  // Typically overridden
+  /**
+   * Checks if the given raster has a compatible data-layout (SampleModel).
+   * @param raster The Raster to test.
+   * @return true if raster is compatible.
+   */ 
   public boolean isCompatibleRaster(Raster raster)
   {
     SampleModel sampleModel = raster.getSampleModel();
Index: kaffe/libraries/javalib/java/awt/image/ComponentColorModel.java
diff -u kaffe/libraries/javalib/java/awt/image/ComponentColorModel.java:1.3 kaffe/libraries/javalib/java/awt/image/ComponentColorModel.java:1.4
--- kaffe/libraries/javalib/java/awt/image/ComponentColorModel.java:1.3	Mon Mar 22 11:24:39 2004
+++ kaffe/libraries/javalib/java/awt/image/ComponentColorModel.java	Tue May 18 13:39:05 2004
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2002  Free Software Foundation
+/* Copyright (C) 2000, 2002, 2004  Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -37,10 +37,9 @@
 
 package java.awt.image;
 
-import gnu.java.awt.Buffers;
-
 import java.awt.Point;
 import java.awt.color.ColorSpace;
+import gnu.java.awt.Buffers;
 
 public class ComponentColorModel extends ColorModel
 {
@@ -293,18 +292,55 @@
     return Raster.createWritableRaster(sm, origin);
   }
 
+
+  /**
+   * Creates a <code>SampleModel</code> whose arrangement of pixel
+   * data is compatible to this <code>ColorModel</code>.
+   *
+   * @param w the number of pixels in the horizontal direction.
+   * @param h the number of pixels in the vertical direction.
+   */
   public SampleModel createCompatibleSampleModel(int w, int h)
   {
-    int pixelStride = getNumComponents();
-    
-    /* TODO: Maybe we don't need to create a new offset array each
-       time, but rather use the same array every time. */
-    int[] bandOffsets = new int[pixelStride];
-    for (int i=0; i<pixelStride; i++) bandOffsets[i] = i;
-    return new ComponentSampleModel(transferType, w, h,
-				    pixelStride, pixelStride*w,
-				    bandOffsets);
+    int pixelStride, scanlineStride;
+    int[] bandOffsets;
+
+    pixelStride = getNumComponents();
+    scanlineStride = pixelStride * w;
+
+    /* We might be able to re-use the same bandOffsets array among
+     * multiple calls to this method. However, this optimization does
+     * not seem worthwile because setting up descriptive data
+     * structures (such as SampleModels) is neglectible in comparision
+     * to shuffling around masses of pixel data.
+     */
+    bandOffsets = new int[pixelStride];
+    for (int i = 0; i < pixelStride; i++)
+      bandOffsets[i] = i;
+
+    /* FIXME: Think about whether it would make sense to return the
+     * possibly more efficient PixelInterleavedSampleModel for other
+     * transferTypes as well. It seems unlikely that this would break
+     * any user applications, so the Mauve tests on this method
+     * might be too restrictive.
+     */
+    switch (transferType)
+      {
+      case DataBuffer.TYPE_BYTE:
+      case DataBuffer.TYPE_USHORT:
+        return new PixelInterleavedSampleModel(transferType, w, h,
+                                               pixelStride,
+                                               scanlineStride,
+                                               bandOffsets);
+
+      default:
+        return new ComponentSampleModel(transferType, w, h,
+                                        pixelStride,
+                                        scanlineStride,
+                                        bandOffsets);
+      }
   }
+
 
   public boolean isCompatibleSampleModel(SampleModel sm)
   {
Index: kaffe/libraries/javalib/java/awt/image/ComponentSampleModel.java
diff -u kaffe/libraries/javalib/java/awt/image/ComponentSampleModel.java:1.1 kaffe/libraries/javalib/java/awt/image/ComponentSampleModel.java:1.2
--- kaffe/libraries/javalib/java/awt/image/ComponentSampleModel.java:1.1	Mon Nov 11 12:01:53 2002
+++ kaffe/libraries/javalib/java/awt/image/ComponentSampleModel.java	Tue May 18 13:39:05 2004
@@ -349,7 +349,7 @@
     if (scanlineStride == rowSize)
       {
 	// Collapse scan lines:
-	scanlineStride = rowSize *= h;
+	rowSize *= h;
 	h = 1;
       }
 
===================================================================
Checking out kaffe/libraries/javalib/java/awt/image/PixelInterleavedSampleModel.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/java/awt/image/PixelInterleavedSampleModel.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/java/awt/image/PixelInterleavedSampleModel.java	Tue May 18 14:02:37 2004
@@ -0,0 +1,98 @@
+/* PixelInterleavedSampleModel.java
+   Copyright (C) 2004 Free Software Foundation, Inc.
+
+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;
+
+
+/**
+ * A <code>SampleModel</code> that uses exactly one element of the
+ * raster&#x2019;s {@link DataBuffer} per pixel, holds all bands in a
+ * single bank, and stores band data in pixel-interleaved manner.
+ *
+ * @since 1.2
+ *
+ * @author <a href="mailto:brawer at dandelis.ch">Sascha Brawer</a>
+ */
+public class PixelInterleavedSampleModel
+  extends ComponentSampleModel
+{
+  public PixelInterleavedSampleModel(int dataType, int width, int height,
+                                     int pixelStride, int scanlineStride,
+                                     int[] bandOffsets)
+  {
+    super(dataType, width, height, pixelStride, scanlineStride,
+          bandOffsets);
+  }
+
+  
+  /**
+   * Creates a new <code>SampleModel</code> that is like this one, but
+   * uses the specified width and height.
+   *
+   * @param width the number of pixels in the horizontal direction.
+   *
+   * @param height the number of pixels in the vertical direction.
+   */
+  public SampleModel createCompatibleSampleModel(int width, int height)
+  {
+    return new PixelInterleavedSampleModel(dataType, width, height,
+                                           pixelStride, scanlineStride,
+                                           bandOffsets);
+  }
+
+
+  /**
+   * Creates a new <code>SampleModel</code> that is like this one, but
+   * uses only a subset of its bands.
+   *
+   * @param bands an array whose elements indicate which bands shall
+   * be part of the subset. For example, <code>[0, 2, 3]</code> would
+   * create a SampleModel containing bands #0, #2 and #3.
+   */
+  public SampleModel createSubsetSampleModel(int[] bands)
+  {
+    int[] subOffsets;
+
+    subOffsets = new int[bands.length];
+    for (int i = 0; i < bands.length; i++)
+      subOffsets[i] = bandOffsets[bands[i]];
+
+    return new PixelInterleavedSampleModel(dataType, width, height,
+                                           pixelStride, scanlineStride,
+                                           subOffsets);
+  }
+}
Index: kaffe/libraries/javalib/java/awt/image/Raster.java
diff -u kaffe/libraries/javalib/java/awt/image/Raster.java:1.3 kaffe/libraries/javalib/java/awt/image/Raster.java:1.4
--- kaffe/libraries/javalib/java/awt/image/Raster.java:1.3	Wed Oct 22 10:34:51 2003
+++ kaffe/libraries/javalib/java/awt/image/Raster.java	Tue May 18 13:39:05 2004
@@ -452,4 +452,25 @@
 				  y-sampleModelTranslateY,
 				  w, h, b, dArray, dataBuffer);
   }
+  
+  /**
+   * Create a String representing the stat of this Raster.
+   * @return A String representing the stat of this Raster.
+   * @see java.lang.Object#toString()
+   */
+  public String toString()
+  {
+    StringBuffer result = new StringBuffer();
+    
+    result.append(getClass().getName());
+    result.append("[(");
+    result.append(minX).append(",").append(minY).append("), ");
+    result.append(width).append(" x ").append(height).append(",");
+    result.append(sampleModel).append(",");
+    result.append(dataBuffer);
+    result.append("]");
+    
+    return result.toString();
+  }
+  
 }
Index: kaffe/libraries/javalib/java/awt/image/SampleModel.java
diff -u kaffe/libraries/javalib/java/awt/image/SampleModel.java:1.1 kaffe/libraries/javalib/java/awt/image/SampleModel.java:1.2
--- kaffe/libraries/javalib/java/awt/image/SampleModel.java:1.1	Mon Nov 11 12:01:53 2002
+++ kaffe/libraries/javalib/java/awt/image/SampleModel.java	Tue May 18 13:39:06 2004
@@ -58,7 +58,9 @@
 
   public SampleModel(int dataType, int w, int h, int numBands)
   {
-    if ((w<=0) || (h<=0)) throw new IllegalArgumentException();
+    if ((w <= 0) || (h <= 0)) 
+      throw new IllegalArgumentException((w <= 0 ? " width<=0" : " width is ok")
+                                         +(h <= 0 ? " height<=0" : " height is ok"));
 	
     // FIXME: How can an int be greater than Integer.MAX_VALUE?
     // FIXME: How do we identify an unsupported data type?
@@ -68,7 +70,7 @@
     this.height = h;
     this.numBands = numBands;  
   }
-
+  
   public final int getWidth()
   {
     return width;
Index: kaffe/libraries/javalib/java/awt/image/SinglePixelPackedSampleModel.java
diff -u kaffe/libraries/javalib/java/awt/image/SinglePixelPackedSampleModel.java:1.3 kaffe/libraries/javalib/java/awt/image/SinglePixelPackedSampleModel.java:1.4
--- kaffe/libraries/javalib/java/awt/image/SinglePixelPackedSampleModel.java:1.3	Sat Jan 10 18:47:53 2004
+++ kaffe/libraries/javalib/java/awt/image/SinglePixelPackedSampleModel.java	Tue May 18 13:39:06 2004
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2002, 2003  Free Software Foundation
+/* Copyright (C) 2000, 2002, 2003, 2004  Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -162,6 +162,63 @@
 			   1  // length
 			   );
   }
+  
+  /**
+   * This is a more efficient implementation of the default implementation in the super
+   * class. 
+   * @param x The x-coordinate of the pixel rectangle to store in <code>obj</code>.
+   * @param y The y-coordinate of the pixel rectangle to store in <code>obj</code>.
+   * @param w The width of the pixel rectangle to store in <code>obj</code>.
+   * @param h The height of the pixel rectangle to store in <code>obj</code>.
+   * @param obj The primitive array to store the pixels into or null to force creation.
+   * @param data The DataBuffer that is the source of the pixel data.
+   * @return The primitive array containing the pixel data.
+   * @see java.awt.image.SampleModel#getDataElements(int, int, int, int, java.lang.Object, java.awt.image.DataBuffer)
+   */
+  public Object getDataElements(int x, int y, int w, int h, Object obj,
+							DataBuffer data)
+  {
+    int size = w*h;
+    int dataSize = size;
+    Object pixelData = null;
+    switch (getTransferType())
+    {
+      case DataBuffer.TYPE_BYTE:
+        pixelData = ((DataBufferByte) data).getData();
+        if (obj == null) obj = new byte[dataSize];
+        break;
+       case DataBuffer.TYPE_USHORT:
+         pixelData = ((DataBufferUShort) data).getData();
+         if (obj == null) obj = new short[dataSize];
+         break;
+        case DataBuffer.TYPE_INT:
+          pixelData = ((DataBufferInt) data).getData();
+          if (obj == null) obj = new int[dataSize];
+          break;
+         default:
+             // Seems like the only sensible thing to do.
+           throw new ClassCastException();
+      }
+      if(x==0 && scanlineStride == w)
+      { 
+        // The full width need to be copied therefore we can copy in one shot.
+        System.arraycopy(pixelData, scanlineStride*y + data.getOffset(), obj, 0, size);
+      }
+      else
+      {  
+        // Since we do not need the full width we need to copy line by line.
+        int outOffset = 0;
+        int dataOffset = scanlineStride*y + x + data.getOffset();
+        for (int yy = y; yy<(y+h); yy++)
+        {
+          System.arraycopy(pixelData, dataOffset, obj, outOffset, w);
+          dataOffset += scanlineStride;
+          outOffset += w;
+        }
+      }
+    return obj;
+  }
+  
 
   public int[] getPixel(int x, int y, int[] iArray, DataBuffer data)
   {
@@ -201,7 +258,51 @@
     int samples = data.getElem(offset);
     return (samples & bitMasks[b]) >>> bitOffsets[b];
   }
-
+  
+  /**
+   * This method implements a more efficient way to set data elements than the default
+   * implementation of the super class. It sets the data elements line by line instead 
+   * of pixel by pixel.
+   * @param x The x-coordinate of the data elements in <code>obj</code>.
+   * @param y The y-coordinate of the data elements in <code>obj</code>.
+   * @param w The width of the data elements in <code>obj</code>.
+   * @param h The height of the data elements in <code>obj</code>.
+   * @param obj The primitive array containing the data elements to set.
+   * @param data The DataBuffer to store the data elements into.
+   * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, java.lang.Object, java.awt.image.DataBuffer)
+   */
+  public void setDataElements(int x, int y, int w, int h,
+				Object obj, DataBuffer data)
+  {
+    
+    Object pixelData;
+    switch (getTransferType())
+    {
+      case DataBuffer.TYPE_BYTE:
+        pixelData = ((DataBufferByte) data).getData();
+        break;
+       case DataBuffer.TYPE_USHORT:
+         pixelData = ((DataBufferUShort) data).getData();
+         break;
+       case DataBuffer.TYPE_INT:
+         pixelData = ((DataBufferInt) data).getData();
+         break;
+       default:
+          // Seems like the only sensible thing to do.
+          throw new ClassCastException();
+    }
+    
+    int inOffset = 0;
+    int dataOffset = scanlineStride*y + x + data.getOffset();
+    for (int yy=y; yy<(y+h); yy++)
+    {
+      System.arraycopy(obj,inOffset,pixelData,dataOffset,w);
+      dataOffset += scanlineStride;
+      inOffset += w;
+    }
+  }
+  
+  
   public void setDataElements(int x, int y, Object obj, DataBuffer data)
   {
     int offset = scanlineStride*y + x + data.getOffset();
@@ -273,6 +374,39 @@
     data.setElem(offset, samples);
   }
 
+  /**
+   * This method implements a more efficient way to set pixels than the default
+   * implementation of the super class. It copies the pixel components directly
+   * from the input array instead of creating a intermediate buffer.
+   * @param x The x-coordinate of the pixel rectangle in <code>obj</code>.
+   * @param y The y-coordinate of the pixel rectangle in <code>obj</code>.
+   * @param w The width of the pixel rectangle in <code>obj</code>.
+   * @param h The height of the pixel rectangle in <code>obj</code>.
+   * @param obj The primitive array containing the pixels to set.
+   * @param data The DataBuffer to store the pixels into.
+   * @see java.awt.image.SampleModel#setPixels(int, int, int, int, int[], java.awt.image.DataBuffer)
+   */
+  public void setPixels(int x, int y, int w, int h, int[] iArray,
+						DataBuffer data)
+  {
+    int inOffset = 0;
+    int[] pixel = new int[numBands];
+    for (int yy=y; yy<(y+h); yy++)
+     {
+      int offset = scanlineStride*yy + x;
+      for (int xx=x; xx<(x+w); xx++)
+       { 
+        int samples = 0;
+        for (int b=0; b<numBands; b++)
+          samples |= (iArray[inOffset+b] << bitOffsets[b]) & bitMasks[b];
+        data.setElem(0, offset, samples);
+        inOffset += numBands;
+        offset += 1;
+      }
+    }
+  }
+  
+  
   public void setSample(int x, int y, int b, int s, DataBuffer data)
   {
     int offset = scanlineStride*y + x;
@@ -281,5 +415,25 @@
     samples &= ~bitMask;
     samples |= (s << bitOffsets[b]) & bitMask;
     data.setElem(offset, samples);

*** Patch too long, truncated ***




More information about the kaffe mailing list