com.nerius.grafx.d2
Class RasterFloatGraphics

java.lang.Object
  extended by com.nerius.grafx.d2.RasterFloatGraphics
All Implemented Interfaces:
FloatGraphics

public class RasterFloatGraphics
extends java.lang.Object
implements FloatGraphics

An implementation of FloatGraphics that converts operations into pixel data.

Todo: documentation. Sampling points: middle of unit square. At boundary: shift object -x; shift object -y if still necessary.


Constructor Summary
RasterFloatGraphics(int[] pix, int width, int height)
          Array pix will be used to store pixel information; the array's length must therefore be at least width * height.
RasterFloatGraphics(RasterFloatPixBuff pixBuff)
           
 
Method Summary
 void clear()
          Paints the current clip area with the current color.
 void drawLine(double x0, double y0, double x1, double y1)
           
 void drawPoint(double x, double y)
           
 void fillPolygon(double[] xPts, double[] yPts, int offset, int numPts)
          Uses the even-odd fill rule for self-intersecting polygons.
 ClipRectangle getClip()
          The return value of this method is not necessarily equal to the clip previously set by setClip(); the clip returned here is no larger than the entire area that is visible by this graphics context.
 FloatColor getColor()
          Returns the color that was previously set via setColor().
 int getIntColor()
           
 java.awt.Rectangle getModifiedArea()
          Returns a Rectangle iRect which is as small as possible and which, for every pixel (n, m) modified since the last call to startModifiedAreaCalculation(), returns true in a call iRect.contains(n, m) (if the initial Rectangle passed into startModifiedAreaCalculation() represented a nonempty area, then all pixel points contained in that rectangle count as modified).
 void setClip(ClipRectangle clip)
          setClip(null) sets the clip to be the entire image dimension.
 void setColor(FloatColor color)
          For drawing points, drawing lines, and filling polygons, how non-opaque colors are handled is up to the implementation of this interface.
 void setIntColor(int color)
          Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue.
 void setRectClip(java.awt.Rectangle rect)
          Sets the clip area to be such that only pixels (n, m) for which rect.contains(n, m) == true are allowed to be modified.
 void startModifiedAreaCalculation(java.awt.Rectangle rect)
          Starts a modified area calculation if rect is not null, and stops such a calculation if rect is null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RasterFloatGraphics

public RasterFloatGraphics(int[] pix,
                           int width,
                           int height)
                    throws java.lang.ArrayIndexOutOfBoundsException
Array pix will be used to store pixel information; the array's length must therefore be at least width * height. Orientation: imagePixel(x, y) = pix[y * width + x]. The values stored in pix represent color in the ARGB format - in each int, bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue. For example, an integer 0xff000000 represents the color black.

Pixel data is written through; no alpha blending is done. For custom alpha blending behavior, subclass RasterFloatPixBuff and use the other constructor.

Throws:
java.lang.ArrayIndexOutOfBoundsException

RasterFloatGraphics

public RasterFloatGraphics(RasterFloatPixBuff pixBuff)
Method Detail

startModifiedAreaCalculation

public void startModifiedAreaCalculation(java.awt.Rectangle rect)
Starts a modified area calculation if rect is not null, and stops such a calculation if rect is null. If either of rect.width or rect.height are positive nonzero, then rect will be used to represent the initial area that has been modified. Call getModifiedArea() after any sequence of drawing operations to get an area that has been modified since this method was last called.

There is a tiny bit of extra overhead in calculating the modified area in each of the drawing operations (these calculations are only performed if rect is not null).

See Also:
getModifiedArea()

getModifiedArea

public java.awt.Rectangle getModifiedArea()
Returns a Rectangle iRect which is as small as possible and which, for every pixel (n, m) modified since the last call to startModifiedAreaCalculation(), returns true in a call iRect.contains(n, m) (if the initial Rectangle passed into startModifiedAreaCalculation() represented a nonempty area, then all pixel points contained in that rectangle count as modified). The return value == the rect that was previously passed into startModifiedAreaCalculation().

See Also:
startModifiedAreaCalculation(Rectangle)

setColor

public void setColor(FloatColor color)
Description copied from interface: FloatGraphics
For drawing points, drawing lines, and filling polygons, how non-opaque colors are handled is up to the implementation of this interface.

Specified by:
setColor in interface FloatGraphics

getColor

public FloatColor getColor()
Description copied from interface: FloatGraphics
Returns the color that was previously set via setColor().

Specified by:
getColor in interface FloatGraphics

setIntColor

public void setIntColor(int color)
Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue. For example, black is 0xff000000.


getIntColor

public int getIntColor()

setClip

public void setClip(ClipRectangle clip)
setClip(null) sets the clip to be the entire image dimension.

Specified by:
setClip in interface FloatGraphics

setRectClip

public void setRectClip(java.awt.Rectangle rect)
Sets the clip area to be such that only pixels (n, m) for which rect.contains(n, m) == true are allowed to be modified. Basically, makes the following call:
 setClip(rect == null ?
         null :
         new ClipRectangle(rect.x,
                           rect.y,
                           rect.x + Math.max(rect.width, 0),
                           rect.y + Math.max(rect.height, 0)));
 
This method is compatible with getModifiedArea() in that setRectClip(getModifiedArea()) will set the clip to be exactly the smallest possible rectangle which contains all the modified pixels.


getClip

public ClipRectangle getClip()
Description copied from interface: FloatGraphics
The return value of this method is not necessarily equal to the clip previously set by setClip(); the clip returned here is no larger than the entire area that is visible by this graphics context.

For example, to find out the maximum possible area that is visible by this context, first setClip(null) and then inspect the return value of this method.

This method never returns null.

Specified by:
getClip in interface FloatGraphics

clear

public void clear()
Description copied from interface: FloatGraphics
Paints the current clip area with the current color. This is not necessarily equivalent to filling a rectangle of clip area because clear() is required to clobber all visual information in the current clip, whereas filling a polygon may handle transparent or translucent colors in a special way.

Specified by:
clear in interface FloatGraphics

drawPoint

public void drawPoint(double x,
                      double y)
Specified by:
drawPoint in interface FloatGraphics

drawLine

public void drawLine(double x0,
                     double y0,
                     double x1,
                     double y1)
Specified by:
drawLine in interface FloatGraphics

fillPolygon

public void fillPolygon(double[] xPts,
                        double[] yPts,
                        int offset,
                        int numPts)
Uses the even-odd fill rule for self-intersecting polygons.

Specified by:
fillPolygon in interface FloatGraphics