I fixed the RasterGraphics constructor to call init(), which makes it
possible to actually draw on the Raster and added a drawImage() method
which makes it possible to draw another BufferedImage onto the Raster.
This enables to run the ImageTest program
(http://www.ii.uib.no/~rolfwr/jcnix/ImageTest.html) to run on my Java2D
impl together with the X-Peers:

http://kennke.org/~roman/java2d-image.png


2006-05-09  Roman Kennke <[EMAIL PROTECTED]>

        * gnu/java/awt/java2d/RasterGraphics.java
        (RasterGraphics): Call init() and super().
        (drawImage): Temporary drawImage impl until AbstractGraphics2D
has
        this.

/Roman

Index: gnu/java/awt/java2d/RasterGraphics.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/java2d/RasterGraphics.java,v
retrieving revision 1.1
diff -u -1 -0 -r1.1 RasterGraphics.java
--- gnu/java/awt/java2d/RasterGraphics.java	7 May 2006 01:39:32 -0000	1.1
+++ gnu/java/awt/java2d/RasterGraphics.java	9 May 2006 15:29:24 -0000
@@ -32,21 +32,25 @@
 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 gnu.java.awt.java2d;
 
 import java.awt.GraphicsConfiguration;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
 import java.awt.image.ColorModel;
+import java.awt.image.ImageObserver;
+import java.awt.image.Raster;
 import java.awt.image.WritableRaster;
 
 /**
  * A Graphics2D implementation that operates on Raster objects. This is
  * primarily used for BufferedImages, but can theoretically be used on
  * arbitrary WritableRasters.
  *
  * @author Roman Kennke ([EMAIL PROTECTED])
  */
 public class RasterGraphics
@@ -58,22 +62,24 @@
    */
   private WritableRaster raster;
 
   /**
    * The color model of this Graphics instance.
    */
   private ColorModel colorModel;
 
   public RasterGraphics(WritableRaster r, ColorModel cm)
   {
+    super();
     raster = r;
     colorModel = cm;
+    init();
   }
 
   /**
    * Returns the color model of this Graphics object.
    *
    * @return the color model of this Graphics object
    */
   protected ColorModel getColorModel()
   {
     return colorModel;
@@ -91,11 +97,28 @@
   {
     return raster;
   }
 
   public GraphicsConfiguration getDeviceConfiguration()
   {
     // TODO Auto-generated method stub
     return null;
   }
 
+  public boolean drawImage(Image image, int x, int y, ImageObserver observer)
+  {
+    // TODO: Hack to make ImageTest working and evaluate image rendering.
+    // Remove as soon as this is fully supported in AbstractGraphics2D.
+    if (image instanceof BufferedImage)
+      {
+        BufferedImage bImage = (BufferedImage) image;
+        Raster src = bImage.getRaster();
+        int srcX = src.getMinX();
+        int srcY = src.getMinY();
+        int w = src.getWidth();
+        int h = src.getHeight();
+        Object data = src.getDataElements(srcX, srcY, w, h, null);
+        raster.setDataElements(x, y, w, h, data);
+      }
+    return true;
+  }
 }

Reply via email to