Java DTV API 1.3
18-Nov-2009

com.sun.dtv.ui
Class AlphaComposite

java.lang.Object
  extended by com.sun.dtv.ui.AlphaComposite

public final class AlphaComposite
extends Object

This AlphaComposite class implements all 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 the set of Porter-Duff rules described in T. Porter and T. Duff, "Compositing Digital Images", SIGGRAPH 84, 253-259.

This AlphaComposite class is similar to the java.awt.AlphaComposite class but differs by the fact that all alpha compositing rules are supported here whereas the PBP variant of java.awt.AlphaComposite only supports the first three rules described below.

The following rules are supported:

Rule Coding

If any input does not have an alpha channel, an alpha value of 1.0f, which is 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:

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.

The alpha resulting from 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.0f, the color values are set to 0.0f.

If either source or destination pixels have color components not premultiplied by the alpha component, appropriate conversions are performed before and after the compositing operation.

Note: no restrictions applies on the implementation of these rules.

See Also:
AlphaComposite

Field Summary
static AlphaComposite Clear
          AlphaComposite object that implements the opaque CLEAR rule with an alpha of 1.0f.
static int CLEAR
          Porter-Duff Clear rule.
static AlphaComposite Dst
          AlphaComposite object that implements the opaque DST rule with an alpha of 1.0f.
static int DST
          Porter-Duff Destination rule.
static int DST_ATOP
          Porter-Duff Destination Atop Source rule.
static int DST_IN
          Porter-Duff Destination In Source rule.
static int DST_OUT
          Porter-Duff Destination Held Out By Source rule.
static int DST_OVER
          Porter-Duff Destination Over Source rule.
static AlphaComposite DstAtop
          AlphaComposite object that implements the opaque DST_ATOP rule with an alpha of 1.0f.
static AlphaComposite DstIn
          AlphaComposite object that implements the opaque DST_IN rule with an alpha of 1.0f.
static AlphaComposite DstOut
          AlphaComposite object that implements the opaque DST_OUT rule with an alpha of 1.0f.
static AlphaComposite DstOver
          AlphaComposite object that implements the opaque DST_OVER rule with an alpha of 1.0f.
static AlphaComposite Src
          AlphaComposite object that implements the opaque SRC rule with an alpha of 1.0f.
static int SRC
          Porter-Duff Source rule.
static int SRC_ATOP
          Porter-Duff Source Atop Destination rule.
static int SRC_IN
          Porter-Duff Source In Destination rule.
static int SRC_OUT
          Porter-Duff Source Held Out By Destination rule.
static int SRC_OVER
          Porter-Duff Source Over Destination rule.
static AlphaComposite SrcAtop
          AlphaComposite object that implements the opaque SRC_ATOP rule with an alpha of 1.0f.
static AlphaComposite SrcIn
          AlphaComposite object that implements the opaque SRC_IN rule with an alpha of 1.0f.
static AlphaComposite SrcOut
          AlphaComposite object that implements the opaque SRC_OUT rule with an alpha of 1.0f.
static AlphaComposite SrcOver
          AlphaComposite object that implements the opaque SRC_OVER rule with an alpha of 1.0f.
static AlphaComposite Xor
          AlphaComposite object that implements the opaque XOR rule with an alpha of 1.0f.
static int XOR
          Porter-Duff Source Xor Destination rule.
 
Method Summary
 boolean equals(Object obj)
          Determines whether the specified object is equal to this AlphaComposite.
 float getAlpha()
          Returns the alpha value of this AlphaComposite.
static AlphaComposite getInstance(int rule)
          Creates an AlphaComposite object with the specified rule.
static AlphaComposite getInstance(int rule, float alpha)
          Creates an AlphaComposite object with the specified rule and the constant alpha to multiply with the alpha of the source.
 int getRule()
          Returns the compositing rule of this AlphaComposite.
 int hashCode()
          Returns the hashcode for this composite.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLEAR

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

Fs = 0 and Fd = 0, thus:

        Cd = 0
        Ad = 0

See Also:
Constant Field Values

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

See Also:
Constant Field Values

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)

See Also:
Constant Field Values

DST

public static final int DST
Porter-Duff Destination rule. The destination is left untouched.

Fs = 0 and Fd = 1, thus:

        Cd = Cd
        Ad = Ad

See Also:
Constant Field Values

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

See Also:
Constant Field Values

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

See Also:
Constant Field Values

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

See Also:
Constant Field Values

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)

See Also:
Constant Field Values

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)

See Also:
Constant Field Values

SRC_ATOP

public static final int SRC_ATOP
Porter-Duff Source Atop Destination rule. The part of the source lying inside of the destination is composited onto the destination.

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

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

See Also:
Constant Field Values

DST_ATOP

public static final int DST_ATOP
Porter-Duff Destination Atop Source rule. The part of the destination lying inside of the source is composited over the source and replaces the destination.

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

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

See Also:
Constant Field Values

XOR

public static final int XOR
Porter-Duff Source Xor Destination rule. The part of the source that lies outside of the destination is combined with the part of the destination that lies outside of the source.

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

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

See Also:
Constant Field Values

Clear

public static final AlphaComposite Clear
AlphaComposite object that implements the opaque CLEAR rule with an alpha of 1.0f.

See Also:
CLEAR

Src

public static final AlphaComposite Src
AlphaComposite object that implements the opaque SRC rule with an alpha of 1.0f.

See Also:
SRC

Dst

public static final AlphaComposite Dst
AlphaComposite object that implements the opaque DST rule with an alpha of 1.0f.

See Also:
DST

SrcOver

public static final AlphaComposite SrcOver
AlphaComposite object that implements the opaque SRC_OVER rule with an alpha of 1.0f.

See Also:
SRC_OVER

DstOver

public static final AlphaComposite DstOver
AlphaComposite object that implements the opaque DST_OVER rule with an alpha of 1.0f.

See Also:
DST_OVER

SrcIn

public static final AlphaComposite SrcIn
AlphaComposite object that implements the opaque SRC_IN rule with an alpha of 1.0f.

See Also:
SRC_IN

DstIn

public static final AlphaComposite DstIn
AlphaComposite object that implements the opaque DST_IN rule with an alpha of 1.0f.

See Also:
DST_IN

SrcOut

public static final AlphaComposite SrcOut
AlphaComposite object that implements the opaque SRC_OUT rule with an alpha of 1.0f.

See Also:
SRC_OUT

DstOut

public static final AlphaComposite DstOut
AlphaComposite object that implements the opaque DST_OUT rule with an alpha of 1.0f.

See Also:
DST_OUT

SrcAtop

public static final AlphaComposite SrcAtop
AlphaComposite object that implements the opaque SRC_ATOP rule with an alpha of 1.0f.

See Also:
SRC_ATOP

DstAtop

public static final AlphaComposite DstAtop
AlphaComposite object that implements the opaque DST_ATOP rule with an alpha of 1.0f.

See Also:
DST_ATOP

Xor

public static final AlphaComposite Xor
AlphaComposite object that implements the opaque XOR rule with an alpha of 1.0f.

See Also:
XOR
Method Detail

getInstance

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

Parameters:
rule - the compositing rule.
Returns:
an AlphaComposite object.
Throws:
IllegalArgumentException - if rule is not one of the following: CLEAR, SRC, SRC_OVER, DST, DST_OVER, SRC_IN, DST_IN, SRC_OUT, DST_OUT, SRC_ATOP, DST_ATOP or XOR

getInstance

public static AlphaComposite getInstance(int rule,
                                         float alpha)
Creates an AlphaComposite object with the specified rule and the constant alpha to multiply with the alpha of the source. The source is multiplied with the specified alpha before being composited with the destination.

Parameters:
rule - The compositing rule.
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.0f, 1.0f].
Returns:
an AlphaComposite object.
Throws:
IllegalArgumentException - if alpha is less than 0.0f or greater than 1.0f, or if rule is not one of the following: CLEAR, SRC, SRC_OVER, DST, DST_OVER, SRC_IN, DST_IN, SRC_OUT, DST_OUT, SRC_ATOP, DST_ATOP or XOR

getAlpha

public float getAlpha()
Returns the alpha value of this AlphaComposite. If this AlphaComposite does not have an alpha value, 1.0f is returned.

Returns:
the alpha value of this AlphaComposite.

getRule

public int getRule()
Returns the compositing rule of this AlphaComposite.

Returns:
the compositing rule of this AlphaComposite.

hashCode

public int hashCode()
Returns the hashcode for this composite.

Overrides:
hashCode in class Object
Returns:
A hash code for this composite.

equals

public boolean equals(Object obj)
Determines whether the specified object is equal to this AlphaComposite.

The result is true if and only if the argument is not null and is an AlphaComposite object that has the same compositing rule and alpha value as this object.

Overrides:
equals in class Object
Parameters:
obj - the Object to test for equality
Returns:
true if obj equals this AlphaComposite; false otherwise.

Java DTV API 1.3
18-Nov-2009

Copyright © 2008-2009 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved.

U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its supplements. Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.Products covered by and information contained in this service manual are controlled by U.S. Export Control laws and may be subject to the export or import laws in other countries. Nuclear, missile, chemical biological weapons or nuclear maritime end uses or end users, whether direct or indirect, are strictly prohibited. Export or reexport to countries subject to U.S. embargo or to entities identified on U.S. export exclusion lists, including, but not limited to, the denied persons and specially designated nationals lists is strictly prohibited.

DOCUMENTATION IS PROVIDED AS IS AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.

Use of this document is subject to license terms.