Class RasterFloatGraphics

  • All Implemented Interfaces:
    FloatGraphics

    public class RasterFloatGraphics
    extends java.lang.Object
    implements FloatGraphics
    An implementation of FloatGraphics that converts operations into pixel data.

    • Constructor Summary

      Constructors 
      Constructor Description
      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)
      Exposes a level of abstraction for deciding on how to handle turning on of pixels; in particular this way of constructing the graphics context potentially gives it the capability for handling translucent colors.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Paints the current clip area with the current color.
      void drawLine​(double x0, double y0, double x1, double y1)
      Draws a line segment between two endpoints, namely (x0,y0) and (x1,y1).
      void drawPoint​(double x, double y)
      Affects exactly one pixel, assuming that it's not outside of the clip area.
      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()
      Returns the color previously set via setIntColor(int).
      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(iRect), returns true in the call to iRect.contains(n,m).
      void setClip​(ClipRectangle clip)
      The clip determines how much of an object [to be rendered] is visible.
      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)
      Sets the ARGB color directly, for more control in native representation.
      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, or 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)
        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 32 bit integer, bits 24-31 (the high bits) are alpha, bits 16-23 are red, bits 8-15 are green, and bits 0-7 (the low bits) are blue. For example, an integer 0xff0000ff represents the fully opaque color bright blue.

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

        See Also:
        RasterFloatGraphics(RasterFloatPixBuff)
      • RasterFloatGraphics

        public RasterFloatGraphics​(RasterFloatPixBuff pixBuff)
        Exposes a level of abstraction for deciding on how to handle turning on of pixels; in particular this way of constructing the graphics context potentially gives it the capability for handling translucent colors.
    • Method Detail

      • startModifiedAreaCalculation

        public void startModifiedAreaCalculation​(java.awt.Rectangle rect)
        Starts a modified area calculation if rect is not null, or 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. Please note that no copy of input rectangle is made; it is kept by reference.

        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 isn't 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(iRect), returns true in the call to iRect.contains(n,m). (If the initial startModifiedAreaCalculation() rectangle represented a nonempty area, then all pixel points contained in that rectangle count as modified as well).

        The return value is equal by reference to the rectangle that was previously passed into startModifiedAreaCalculation(). Returns null if no modified area calculations are taking place.

        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
      • setIntColor

        public void setIntColor​(int color)
        Sets the ARGB color directly, for more control in native representation. High bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue. For example, bright opaque green is 0xff00ff00.
      • getIntColor

        public int getIntColor()
        Returns the color previously set via setIntColor(int).
      • setClip

        public void setClip​(ClipRectangle clip)
        Description copied from interface: FloatGraphics
        The clip determines how much of an object [to be rendered] is visible. The clip does not necessarily force objects to be clipped against it before they are rendered; rather, you can think of objects being rendered onto an infinite [blank] canvas, with the clip being applied to the canvas to determine how much of the object is visible; the visible portion would then be actually painted. This principle is important for objects such as lines, for example, which are represented by an infinitely thin concept but may, when rendered, have some thickness.

        setClip(null) sets the clip to the maximum possible area that is visible by this context.

        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 an invocation makes the following call internally:
         setClip(rect == null ?
                 null :
                 new ClipRectangle(rect.x,
                                   rect.y,
                                   rect.x + Math.max(0, rect.width),
                                   rect.y + Math.max(0, rect.height)));
         

        This method is compatible with getModifiedArea() in that setRectClip(getModifiedArea()) will set the clip to be exactly the smallest possible rectangle which contains all of 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)
        Affects exactly one pixel, assuming that it's not outside of the clip area. The decision of which pixel to affect interplays well with fillPolygon(). In fillPolygon(), pixel (i,j) is turned on if and only if the polygon "contains" imaginary point (i+0.5,j+0.5), where the "contains" is necessarily open on the upper bound and isn't necessarily open on the lower bound, for each of the x and y directions. On the other hand in drawPoint(), pixel (i,j) is turned on if and only if the x coordinate lies in the interval (i,i+1] and the y coordinate lies in the interval (j,j+1]. There are certain casts made between 64 bit floating point space and 32 bit floating point space before these comparisons are made however, in the same way that such casts take place in all of the operations (lines included) which affect pixels.
        Specified by:
        drawPoint in interface FloatGraphics
      • drawLine

        public void drawLine​(double x0,
                             double y0,
                             double x1,
                             double y1)
        Description copied from interface: FloatGraphics
        Draws a line segment between two endpoints, namely (x0,y0) and (x1,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