Hi Roman,

It is great to see the progress you are making on this!

When I tried this out tonight, I got a NullPointerException which I think is caused by the init() method - see below.

Roman Kennke wrote:

I implemented support for painting (Color, Texture and Gradient, at
least theoretically - see below) and compositing for the
AbstractGraphics2D class. This allows for the following:

http://kennke.org/blog/blosxom.cgi/2006/05/06#java2d

This means that the rendering pipeline is mostly complete. I have to
implement clipping properly, which will be done directly in the scanline
conversion for optimum efficiency (thanks Sven for his hints on that
topic).

Note that painting only works for solid colors at the moment
(java.awt.Color). Textures and gradients still need to be implemented.
Also note that painting and compositing is slow as hell, partly because
the algorithm in AlphaCompositeContext is not optimized at all, partly
because the painting and compositing could be accelerated greatly with
native support (i.e. using OpenGL or Cairo or homegrown algorithms for
that). Filling and computing on large arrays (in this case the backing
Raster) is always a little slow in plain Java. I still want to provide
Java-only impls for these, but where possible, these operations should
finally be accelerated (they are the most performance critical parts in
the rendering pipeline).

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

       * gnu/java/awt/java2d/AbstractGraphics2D.java
       (fillShape): Determine user space bounds of shape and feed them
       into the actual rendering pipeline.
       (rawSetPixel): Made non-abstract for now. Maybe remove later.
       (rawSetForeground): Likewise.
       (getDestinationColorModel): Removed.
       (getDeviceBounds): Made non-abstract. Provide useful default
impl.
       (rawFillShape): Handle paint context.
       (fillScanline): Implement painting and compositing.
       (fillShapeAntialias): Handle paint context.
       (fillScanlineAA): Implemented preliminary antialiasing based on
       composite context. Not working yet.
       (fillScanlineAlpha): Removed.
       (init): Fetch destination raster.
       (getDestinationRaster): New abstract method.
       (updateRaster): New backend method.

/Roman
------------------------------------------------------------------------

Index: gnu/java/awt/java2d/AbstractGraphics2D.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/awt/java2d/AbstractGraphics2D.java,v
retrieving revision 1.4
diff -u -1 -0 -r1.4 AbstractGraphics2D.java
--- gnu/java/awt/java2d/AbstractGraphics2D.java 2 May 2006 14:03:08 -0000       
1.4
+++ gnu/java/awt/java2d/AbstractGraphics2D.java 7 May 2006 01:29:52 -0000


Note (in the code below) that getDeviceBounds() accesses destinationRaster directly...

-
-  /**
   * Returns the bounds of the target.
   *
   * @return the bounds of the target
   */
-  protected abstract Rectangle getDeviceBounds();
+  protected Rectangle getDeviceBounds()
+  {
+    return destinationRaster.getBounds();
+  }


In the init() method (below), getDeviceBounds() is called before destinationRaster is initialised. This throws a NullPointerException. This problem went away for me when I switched around the last two lines...

  /**
   * Initializes this graphics object. This must be called by subclasses in
   * order to correctly initialize the state of this object.
   */
  protected void init()
  {
    setPaint(Color.BLACK);
    setFont(new Font("SansSerif", Font.PLAIN, 12));
    isOptimized = true;

    // FIXME: Should not be necessary. A clip of null should mean
    // 'clip against device bounds.
    clip = getDeviceBounds();
+    destinationRaster = getDestinationRaster();
  }


After that, some simple drawing finished but I've run into troubles exporting to a PNG file so I can't see the output yet (I'll try to modify my test programs to display the output some other way). If I try something more complex (for example, a JFreeChart object) I run into exceptions like this:

Exception during event dispatch:
java.lang.ArrayIndexOutOfBoundsException: 506
at java.awt.image.SinglePixelPackedSampleModel.getPixels(SinglePixelPackedSampleModel.java:258)
  at java.awt.image.Raster.getPixels(Raster.java:441)
at gnu.java.awt.java2d.AbstractGraphics2D.fillScanlineAA(AbstractGraphics2D.java:1704) at gnu.java.awt.java2d.AbstractGraphics2D.fillShapeAntialias(AbstractGraphics2D.java:1675) at gnu.java.awt.java2d.AbstractGraphics2D.fillShape(AbstractGraphics2D.java:1174) at gnu.java.awt.java2d.AbstractGraphics2D.fill(AbstractGraphics2D.java:316) at org.jfree.chart.JFreeChart.draw(JFreeChart.java:974)

I'll try to determine if this is AbstractGraphics2D requesting the wrong pixels, or a bug in the Raster or SinglePixelPackedSampleModel. But first I'll try to confirm that my simple examples are working...

Regards,

Dave

Reply via email to