Copyright 2011-09-18 Werner Randelshofer

ch.randelshofer.awt.graphics
Class OpaqueAntialiasingPipe

java.lang.Object
  extended by java.awt.Graphics
      extended by java.awt.Graphics2D
          extended by ch.randelshofer.awt.graphics.Pipe
              extended by ch.randelshofer.awt.graphics.AbstractPipe
                  extended by ch.randelshofer.awt.graphics.OpaquePipe
                      extended by ch.randelshofer.awt.graphics.OpaqueAntialiasingPipe

public class OpaqueAntialiasingPipe
extends OpaquePipe

A rendering pipe to render graphics primitives with antialiasing with opaque colors. This Graphics2D object only works with a BufferedImage which has the following characteristics:

Usage:

 // Create a raster and a buffered image using the supported characteristics.
 WritableRaster ras = Raster.createWritableRaster(
      new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, gw, gh,
      new int[] {0xff0000, 0xff00, 0xff}),
      new Point(0,0)
      );

 BufferedImage bufferedImage = new BufferedImage(
      new DirectColorModel(24, 0xff0000, 0xff00, 0xff),
      ras, false, new Hashtable());

 // Create the graphics object
 OpaqueAntialiasingPipe g = new OpaqueAntialiasingPipe(bufferedImage);

 // Perform the grapics operations
 g.drawLine(0,0,100,100);
 
XXX - This is a purely experimental implementation. Eventually all code here will be replaced by algorithms taken from the anti-grain project.

Version:
1.0.1 2007-10-06 Fill method missed moveTo segments.
1.0 2007-08-27 Derived from TranslucentAntialiasingPipe.
Author:
Werner Randelshofer

Field Summary
protected  int alpha
          Precomputed values to speed up alpha compositing.
protected  int blueBits
           
protected  int greenBits
           
protected  int oneMinusAlpha
           
protected  int premultipliedB
           
protected  int premultipliedG
           
protected  int premultipliedR
           
protected  int previousIn
           
protected  int previousOut
           
protected  int redBits
           
 
Fields inherited from class ch.randelshofer.awt.graphics.OpaquePipe
color, colorBar, edges
 
Fields inherited from class ch.randelshofer.awt.graphics.AbstractPipe
background, flatness, mis, pixels, previousClip, previousTransform, ras, tx, ty, u1, u2
 
Fields inherited from class ch.randelshofer.awt.graphics.Pipe
cx1, cx2, cy1, cy2, gh, gw
 
Constructor Summary
OpaqueAntialiasingPipe(java.awt.image.BufferedImage image)
          Creates a new instance.
 
Method Summary
protected  void blend(int xy, int intensity)
          Blends an individual pixel at the specified coordinate with the specified alpha transparency.
 void draw(java.awt.Shape s)
           
 void drawLine(int x1, int y1, int x2, int y2)
           
 void fill(java.awt.Shape s)
           
 void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
           
protected  void plot(int xy)
          Plots a single pixel.
protected  void plotH(int scan, ch.randelshofer.awt.graphics.Edge active)
          Fills a scan line between pairs of edges in the active edge list.
protected  void plotHClipped(int scan, ch.randelshofer.awt.graphics.Edge active)
          Fills a scan line between pairs of edges in the active edge list.
protected  void plotLine(int x1, int y1, int x2, int y2)
          Wu antialised line algorithm taken from: http://www.codeproject.com/gdi/antialias.asp#dwuln
protected  void plotVClipped(int scan, ch.randelshofer.awt.graphics.Edge active)
           
protected  void scanFillHorizontal(int[] x, int[] y, int cnt, int miny, int maxy)
          ScanFill algorithm for shapes which are wider than tall.
protected  void scanFillVertical(int[] x, int[] y, int cnt, int minx, int maxx)
          ScanFill algorithm for shapes which are taller than wide.
 void setColor(java.awt.Color c)
           
 
Methods inherited from class ch.randelshofer.awt.graphics.OpaquePipe
buildActiveList, buildEdgeListHorizontal, buildEdgeListVertical, deleteAfter, drawDigital, drawGlyphVector, drawOval, drawPolygon, drawPolyline, drawRect, drawWithSubpixelAccuracy, fillOval, fillRect, getColor, insertEdge, makeEdgeRecHorizontal, makeEdgeRecVertical, prepareEdgeList, resortActiveList, updateActiveList, xNext, yNext
 
Methods inherited from class ch.randelshofer.awt.graphics.AbstractPipe
arrayfill, clearRect, clipRect, clipTest, clipTest, flush, getBackground, setBackground, setClip, setClip, setComposite, setTransform, transform, translate, translate
 
Methods inherited from class ch.randelshofer.awt.graphics.Pipe
addRenderingHints, clip, copyArea, create, dispose, drawArc, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawRenderableImage, drawRenderedImage, drawRoundRect, drawString, drawString, drawString, drawString, fillArc, fillRoundRect, getClip, getClipBounds, getComposite, getDeviceConfiguration, getFont, getFontMetrics, getFontRenderContext, getPaint, getRenderingHint, getRenderingHints, getStroke, getTransform, hit, rotate, rotate, scale, setFont, setPaint, setPaintMode, setRenderingHint, setRenderingHints, setStroke, setXORMode, shear, toString
 
Methods inherited from class java.awt.Graphics2D
draw3DRect, fill3DRect
 
Methods inherited from class java.awt.Graphics
create, drawBytes, drawChars, drawPolygon, fillPolygon, finalize, getClipBounds, getClipRect, getFontMetrics, hitClip
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

alpha

protected int alpha
Precomputed values to speed up alpha compositing.


oneMinusAlpha

protected int oneMinusAlpha

premultipliedR

protected int premultipliedR

premultipliedG

protected int premultipliedG

premultipliedB

protected int premultipliedB

previousIn

protected int previousIn

previousOut

protected int previousOut

redBits

protected int redBits

greenBits

protected int greenBits

blueBits

protected int blueBits
Constructor Detail

OpaqueAntialiasingPipe

public OpaqueAntialiasingPipe(java.awt.image.BufferedImage image)
Creates a new instance.

Method Detail

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Overrides:
drawLine in class OpaquePipe

plotLine

protected void plotLine(int x1,
                        int y1,
                        int x2,
                        int y2)
Wu antialised line algorithm taken from: http://www.codeproject.com/gdi/antialias.asp#dwuln

Parameters:
x1 - start point of line
y1 - start point of line
x2 - end point of line
y2 - end point of line

plot

protected void plot(int xy)
Plots a single pixel.


blend

protected void blend(int xy,
                     int intensity)
Blends an individual pixel at the specified coordinate with the specified alpha transparency. This operation does no clipping.

Parameters:
xy - coordinate of the pixel
intensity - 0=fully transparent, 255=fully opaque

setColor

public void setColor(java.awt.Color c)
Overrides:
setColor in class OpaquePipe

draw

public void draw(java.awt.Shape s)
Overrides:
draw in class OpaquePipe

fillPolygon

public void fillPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Overrides:
fillPolygon in class OpaquePipe

fill

public void fill(java.awt.Shape s)
Overrides:
fill in class OpaquePipe

scanFillHorizontal

protected void scanFillHorizontal(int[] x,
                                  int[] y,
                                  int cnt,
                                  int miny,
                                  int maxy)
ScanFill algorithm for shapes which are wider than tall.

Overrides:
scanFillHorizontal in class OpaquePipe
Parameters:
miny - Must be = smallest y and >= cy1.
maxy - Must be = biggest y and <= cy2.

scanFillVertical

protected void scanFillVertical(int[] x,
                                int[] y,
                                int cnt,
                                int minx,
                                int maxx)
ScanFill algorithm for shapes which are taller than wide.

Overrides:
scanFillVertical in class OpaquePipe
Parameters:
minx - Must be = smallest x and >= cx1.
maxx - Must be = biggest x and <= cx2.

plotHClipped

protected void plotHClipped(int scan,
                            ch.randelshofer.awt.graphics.Edge active)
Fills a scan line between pairs of edges in the active edge list. Uses a brute force algorithm to perform antialiasing.


plotH

protected void plotH(int scan,
                     ch.randelshofer.awt.graphics.Edge active)
Fills a scan line between pairs of edges in the active edge list. Uses a brute force algorithm to perform antialiasing.


plotVClipped

protected void plotVClipped(int scan,
                            ch.randelshofer.awt.graphics.Edge active)

Copyright 2011-09-18 Werner Randelshofer