All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Class java.awt.AlphaComposite

java.lang.Object
    |
    +----java.awt.AlphaComposite

public final class AlphaComposite
extends Object
implements Composite
This class implements the basic alpha compositing rules for combining source and destination pixels to achieve blending and transparency effects with graphics and images. The rules implemented by this class are a subset of the Porter-Duff rules described in T. Porter and T. Duff, "Compositing Digital Images", SIGGRAPH 84, 253-259.

If any input does not have an alpha channel, an alpha value of 1.0 (completely opaque) is assumed for all pixels.

A constant alpha value can also be specified to be multiplied with the alpha value of the source pixels.

The following abbreviations are used in the description of the rules:

  • Cs = one of the Color components of the Source Pixel.
  • Cd = one of the Color components of the Destination Pixel.
  • As = Alpha component of the Source Pixel.
  • Ad = Alpha component of the Destination Pixel.
  • Fs = fraction of the Source Pixel which contributes to the output.
  • Fd = fraction of the input Destination Pixel which contributes to the output.

    The color and alpha components produced by the compositing operation are calculated as follows:

     	Cd = Cs*Fs + Cd*Fd
     	Ad = As*Fs + Ad*Fd
    
    where Fs and Fd are specified by each rule. The above equations assume that both source and destination pixels have the color components premultiplied by the alpha component. Similarly, the equations expressed in the definitions of compositing rules below assume premultiplied alpha.

    For performance reasons, it is preferable that Tiles passed to the compose method of a CompositeContext object created by the AlphaComposite class have premultiplied data. However, if either source or destination Tiles are not premultiplied, appropriate conversions will be performed before and after the compositing operation.

    The resulting alpha of the compositing operation is stored in the destination if the destination has an alpha channel. Otherwise, the resulting color is divided by the resulting alpha before being stored in the destination and the alpha is discarded (if the alpha value is 0.0, the color values are set to 0.0).

    See Also:
    Composite, CompositeContext

    Variable Index

     o CLEAR
    Porter-Duff Clear rule.
     o DST_IN
    Porter-Duff Destination In Source rule.
     o DST_OUT
    Porter-Duff Destination Held Out By Source rule.
     o DST_OVER
    Porter-Duff Destination Over Source rule.
     o SRC
    Porter-Duff Source rule.
     o SRC_IN
    Porter-Duff Source In Destination rule.
     o SRC_OUT
    Porter-Duff Source Held Out By Destination rule.
     o SRC_OVER
    Porter-Duff Source Over Destination rule.

    Method Index

     o createContext(ColorModel, ColorModel)
    Creates a context for the compositing operation.
     o equals(Object)
    Compares two Objects for equality.
     o getAlpha()
    Returns the additional alpha value that was given when this AlphaComposiste instance was created.
     o getInstance(int)
    Creates an AlphaComposite object with the given rule.
     o getInstance(int, float)
    Creates an AlphaComposite object with the given rule and the constant alpha to multiply with the alpha of the source.
     o getRule()
    Returns the compositing rule that was specified when this AlphaComposiste instance was created.

    Variables

     o CLEAR
    public static final int CLEAR
    Porter-Duff Clear rule. Both the color and the alpha of destination are cleared. Neither the source nor the destination is used as input.

    Fs = 0 and Fd = 0, thus:

     	Cd = 0
     	Ad = 0
    

     o SRC
    public static final int SRC
    Porter-Duff Source rule. The source is copied to the destination. The destination is not used as input.

    Fs = 1 and Fd = 0, thus:

     	Cd = Cs
     	Ad = As
    

     o SRC_OVER
    public static final int SRC_OVER
    Porter-Duff Source Over Destination rule. The source is composited over the destination.

    Fs = 1 and Fd = (1-As), thus:

     	Cd = Cs + Cd*(1-As)
     	Ad = As + Ad*(1-As)
    

     o DST_OVER
    public static final int DST_OVER
    Porter-Duff Destination Over Source rule. The destination is composited over the source and the result replaces the destination.

    Fs = (1-Ad) and Fd = 1, thus:

     	Cd = Cs*(1-Ad) + Cd
     	Ad = As*(1-Ad) + Ad
    

     o SRC_IN
    public static final int SRC_IN
    Porter-Duff Source In Destination rule. The part of the source lying inside of the destination replaces the destination.

    Fs = Ad and Fd = 0, thus:

     	Cd = Cs*Ad
     	Ad = As*Ad
    

     o DST_IN
    public static final int DST_IN
    Porter-Duff Destination In Source rule. The part of the destination lying inside of the source replaces the destination.

    Fs = 0 and Fd = As, thus:

     	Cd = Cd*As
     	Ad = Ad*As
    

     o SRC_OUT
    public static final int SRC_OUT
    Porter-Duff Source Held Out By Destination rule. The part of the source lying outside of the destination replaces the destination.

    Fs = (1-Ad) and Fd = 0, thus:

     	Cd = Cs*(1-Ad)
     	Ad = As*(1-Ad)
    

     o DST_OUT
    public static final int DST_OUT
    Porter-Duff Destination Held Out By Source rule. The part of the destination lying outside of the source replaces the destination.

    Fs = 0 and Fd = (1-As), thus:

     	Cd = Cd*(1-As)
     	Ad = Ad*(1-As)
    

    Methods

     o getInstance
    public static AlphaComposite getInstance(int rule)
    Creates an AlphaComposite object with the given rule.

    Parameters:
    rule - Rule for the composition.
     o getInstance
    public static AlphaComposite getInstance(int rule,
                                             float alpha)
    Creates an AlphaComposite object with the given rule and the constant alpha to multiply with the alpha of the source. The source is multiplied with the given alpha before being composited with the destination.

    Parameters:
    rule - Rule for the composition.
    alpha - The constant alpha to be multiplied with the alpha of the source. Alpha must be a floating point number in the inclusive range [0.0, 1.0].
     o createContext
    public CompositeContext createContext(ColorModel srcColorModel,
                                          ColorModel dstColorModel)
    Creates a context for the compositing operation. The context contains state that is used in performing the compositing operation.

    Parameters:
    srcColorModel - The ColorModel of the source.
    dstColorModel - The ColorModel of the destination.
    Returns:
    The CompositeContext object to be used to perform compositing operations.
     o getAlpha
    public float getAlpha()
    Returns the additional alpha value that was given when this AlphaComposiste instance was created. If this instance was created without the addtional alpha value, the value 1.0 is returned.

     o getRule
    public int getRule()
    Returns the compositing rule that was specified when this AlphaComposiste instance was created.

     o equals
    public boolean equals(Object obj)
    Compares two Objects for equality.

    Overrides:
    equals in class Object

    All Packages  Class Hierarchy  This Package  Previous  Next  Index  

    Submit a bug or feature