jdk/src/share/classes/java/awt/AlphaComposite.java
author dxu
Thu, 04 Apr 2013 15:39:17 -0700
changeset 16734 da1901d79073
parent 12317 9670c1610c53
child 21278 ef8a3a2a72f2
permissions -rw-r--r--
8000406: change files using @GenerateNativeHeader to use @Native Summary: Use @Native annotation to mark constants interested by native codes Reviewed-by: alanb, anthony, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
     2
 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4955
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4955
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4955
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4955
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4955
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.image.ColorModel;
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
    29
import java.lang.annotation.Native;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.java2d.SunCompositeContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * The <code>AlphaComposite</code> class implements basic alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * compositing rules for combining source and destination colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * to achieve blending and transparency effects with graphics and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * images.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * The specific rules implemented by this class are the basic set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * of 12 rules described in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * T. Porter and T. Duff, "Compositing Digital Images", SIGGRAPH 84,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * 253-259.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The rest of this documentation assumes some familiarity with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * definitions and concepts outlined in that paper.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * This class extends the standard equations defined by Porter and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Duff to include one additional factor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * An instance of the <code>AlphaComposite</code> class can contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * an alpha value that is used to modify the opacity or coverage of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * every source pixel before it is used in the blending equations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * It is important to note that the equations defined by the Porter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * and Duff paper are all defined to operate on color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * that are premultiplied by their corresponding alpha components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Since the <code>ColorModel</code> and <code>Raster</code> classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * allow the storage of pixel data in either premultiplied or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * non-premultiplied form, all input data must be normalized into
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * premultiplied form before applying the equations and all results
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * might need to be adjusted back to the form required by the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * before the pixel values are stored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Also note that this class defines only the equations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * for combining color and alpha values in a purely mathematical
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * sense. The accurate application of its equations depends
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * on the way the data is retrieved from its sources and stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * in its destinations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * See <a href="#caveats">Implementation Caveats</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * for further information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * The following factors are used in the description of the blending
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * equation in the Porter and Duff paper:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <table summary="layout">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <tr><th align=left>Factor&nbsp;&nbsp;<th align=left>Definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <tr><td><em>A<sub>s</sub></em><td>the alpha component of the source pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <tr><td><em>C<sub>s</sub></em><td>a color component of the source pixel in premultiplied form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <tr><td><em>A<sub>d</sub></em><td>the alpha component of the destination pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <tr><td><em>C<sub>d</sub></em><td>a color component of the destination pixel in premultiplied form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <tr><td><em>F<sub>s</sub></em><td>the fraction of the source pixel that contributes to the output
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <tr><td><em>F<sub>d</sub></em><td>the fraction of the destination pixel that contributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * to the output
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <tr><td><em>A<sub>r</sub></em><td>the alpha component of the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <tr><td><em>C<sub>r</sub></em><td>a color component of the result in premultiplied form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * Using these factors, Porter and Duff define 12 ways of choosing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * the blending factors <em>F<sub>s</sub></em> and <em>F<sub>d</sub></em> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * produce each of 12 desirable visual effects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * The equations for determining <em>F<sub>s</sub></em> and <em>F<sub>d</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * are given in the descriptions of the 12 static fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * that specify visual effects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * the description for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * <a href="#SRC_OVER"><code>SRC_OVER</code></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * specifies that <em>F<sub>s</sub></em> = 1 and <em>F<sub>d</sub></em> = (1-<em>A<sub>s</sub></em>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * Once a set of equations for determining the blending factors is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * known they can then be applied to each pixel to produce a result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * using the following set of equations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *      <em>F<sub>s</sub></em> = <em>f</em>(<em>A<sub>d</sub></em>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *      <em>F<sub>d</sub></em> = <em>f</em>(<em>A<sub>s</sub></em>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *      <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*<em>F<sub>s</sub></em> + <em>A<sub>d</sub></em>*<em>F<sub>d</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *      <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*<em>F<sub>s</sub></em> + <em>C<sub>d</sub></em>*<em>F<sub>d</sub></em></pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * The following factors will be used to discuss our extensions to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * the blending equation in the Porter and Duff paper:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <table summary="layout">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * <tr><th align=left>Factor&nbsp;&nbsp;<th align=left>Definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * <tr><td><em>C<sub>sr</sub></em> <td>one of the raw color components of the source pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * <tr><td><em>C<sub>dr</sub></em> <td>one of the raw color components of the destination pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <tr><td><em>A<sub>ac</sub></em>  <td>the "extra" alpha component from the AlphaComposite instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * <tr><td><em>A<sub>sr</sub></em> <td>the raw alpha component of the source pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * <tr><td><em>A<sub>dr</sub></em><td>the raw alpha component of the destination pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * <tr><td><em>A<sub>df</sub></em> <td>the final alpha component stored in the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * <tr><td><em>C<sub>df</sub></em> <td>the final raw color component stored in the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * <h3>Preparing Inputs</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * The <code>AlphaComposite</code> class defines an additional alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * value that is applied to the source alpha.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * This value is applied as if an implicit SRC_IN rule were first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * applied to the source pixel against a pixel with the indicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * alpha by multiplying both the raw source alpha and the raw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * source colors by the alpha in the <code>AlphaComposite</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * This leads to the following equation for producing the alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * used in the Porter and Duff blending equation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 *      <em>A<sub>s</sub></em> = <em>A<sub>sr</sub></em> * <em>A<sub>ac</sub></em> </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * All of the raw source color components need to be multiplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * by the alpha in the <code>AlphaComposite</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * Additionally, if the source was not in premultiplied form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * then the color components also need to be multiplied by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * source alpha.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * Thus, the equation for producing the source color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * for the Porter and Duff equation depends on whether the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * pixels are premultiplied or not:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *      <em>C<sub>s</sub></em> = <em>C<sub>sr</sub></em> * <em>A<sub>sr</sub></em> * <em>A<sub>ac</sub></em>     (if source is not premultiplied)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *      <em>C<sub>s</sub></em> = <em>C<sub>sr</sub></em> * <em>A<sub>ac</sub></em>           (if source is premultiplied) </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * No adjustment needs to be made to the destination alpha:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 *      <em>A<sub>d</sub></em> = <em>A<sub>dr</sub></em> </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * The destination color components need to be adjusted only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * they are not in premultiplied form:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 *      <em>C<sub>d</sub></em> = <em>C<sub>dr</sub></em> * <em>A<sub>d</sub></em>    (if destination is not premultiplied)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *      <em>C<sub>d</sub></em> = <em>C<sub>dr</sub></em>         (if destination is premultiplied) </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * <h3>Applying the Blending Equation</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * The adjusted <em>A<sub>s</sub></em>, <em>A<sub>d</sub></em>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * <em>C<sub>s</sub></em>, and <em>C<sub>d</sub></em> are used in the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * Porter and Duff equations to calculate the blending factors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * <em>F<sub>s</sub></em> and <em>F<sub>d</sub></em> and then the resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * premultiplied components <em>A<sub>r</sub></em> and <em>C<sub>r</sub></em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * <h3>Preparing Results</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * The results only need to be adjusted if they are to be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * back into a destination buffer that holds data that is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * premultiplied, using the following equations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 *      <em>A<sub>df</sub></em> = <em>A<sub>r</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 *      <em>C<sub>df</sub></em> = <em>C<sub>r</sub></em>                 (if dest is premultiplied)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 *      <em>C<sub>df</sub></em> = <em>C<sub>r</sub></em> / <em>A<sub>r</sub></em>            (if dest is not premultiplied) </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * Note that since the division is undefined if the resulting alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * is zero, the division in that case is omitted to avoid the "divide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * by zero" and the color components are left as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * all zeros.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * <h3>Performance Considerations</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * For performance reasons, it is preferrable that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * <code>Raster</code> objects passed to the <code>compose</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * method of a {@link CompositeContext} object created by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * <code>AlphaComposite</code> class have premultiplied data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * If either the source <code>Raster</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * or the destination <code>Raster</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * is not premultiplied, however,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * appropriate conversions are performed before and after the compositing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * <h3><a name="caveats">Implementation Caveats</a></h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 * Many sources, such as some of the opaque image types listed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * in the <code>BufferedImage</code> class, do not store alpha values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * for their pixels.  Such sources supply an alpha of 1.0 for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 * all of their pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * Many destinations also have no place to store the alpha values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * that result from the blending calculations performed by this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 * Such destinations thus implicitly discard the resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 * alpha values that this class produces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * It is recommended that such destinations should treat their stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * color values as non-premultiplied and divide the resulting color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 * values by the resulting alpha value before storing the color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * values and discarding the alpha value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 * The accuracy of the results depends on the manner in which pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 * are stored in the destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 * An image format that provides at least 8 bits of storage per color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 * and alpha component is at least adequate for use as a destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 * for a sequence of a few to a dozen compositing operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * An image format with fewer than 8 bits of storage per component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 * is of limited use for just one or two compositing operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 * before the rounding errors dominate the results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 * An image format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 * that does not separately store
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 * color components is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 * good candidate for any type of translucent blending.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * For example, <code>BufferedImage.TYPE_BYTE_INDEXED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 * should not be used as a destination for a blending operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 * because every operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 * can introduce large errors, due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 * the need to choose a pixel from a limited palette to match the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 * results of the blending equations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 * Nearly all formats store pixels as discrete integers rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 * the floating point values used in the reference equations above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 * The implementation can either scale the integer pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 * values into floating point values in the range 0.0 to 1.0 or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 * use slightly modified versions of the equations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 * that operate entirely in the integer domain and yet produce
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 * analogous results to the reference equations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 * Typically the integer values are related to the floating point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 * values in such a way that the integer 0 is equated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 * to the floating point value 0.0 and the integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 * 2^<em>n</em>-1 (where <em>n</em> is the number of bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 * in the representation) is equated to 1.0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 * For 8-bit representations, this means that 0x00
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 * represents 0.0 and 0xff represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 * 1.0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 * The internal implementation can approximate some of the equations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 * and it can also eliminate some steps to avoid unnecessary operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 * For example, consider a discrete integer image with non-premultiplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 * alpha values that uses 8 bits per component for storage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 * The stored values for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 * nearly transparent darkened red might be:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 *    (A, R, G, B) = (0x01, 0xb0, 0x00, 0x00)</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 * If integer math were being used and this value were being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 * composited in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 * <a href="#SRC"><code>SRC</code></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 * mode with no extra alpha, then the math would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 * indicate that the results were (in integer format):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 *    (A, R, G, B) = (0x01, 0x01, 0x00, 0x00)</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 * Note that the intermediate values, which are always in premultiplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
 * form, would only allow the integer red component to be either 0x00
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
 * or 0x01.  When we try to store this result back into a destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 * that is not premultiplied, dividing out the alpha will give us
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 * very few choices for the non-premultiplied red value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 * In this case an implementation that performs the math in integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 * space without shortcuts is likely to end up with the final pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
 * values of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 *    (A, R, G, B) = (0x01, 0xff, 0x00, 0x00)</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 * (Note that 0x01 divided by 0x01 gives you 1.0, which is equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
 * to the value 0xff in an 8-bit storage format.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
 * Alternately, an implementation that uses floating point math
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
 * might produce more accurate results and end up returning to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
 * original pixel value with little, if any, roundoff error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
 * Or, an implementation using integer math might decide that since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
 * the equations boil down to a virtual NOP on the color values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
 * if performed in a floating point space, it can transfer the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
 * pixel untouched to the destination and avoid all the math entirely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
 * These implementations all attempt to honor the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
 * same equations, but use different tradeoffs of integer and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
 * floating point math and reduced or full equations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
 * To account for such differences, it is probably best to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
 * expect only that the premultiplied form of the results to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
 * match between implementations and image formats.  In this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
 * case both answers, expressed in premultiplied form would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
 * equate to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
 *    (A, R, G, B) = (0x01, 0x01, 0x00, 0x00)</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
 * and thus they would all match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
 * Because of the technique of simplifying the equations for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
 * calculation efficiency, some implementations might perform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
 * differently when encountering result alpha values of 0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
 * on a non-premultiplied destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
 * Note that the simplification of removing the divide by alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
 * in the case of the SRC rule is technically not valid if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
 * denominator (alpha) is 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
 * But, since the results should only be expected to be accurate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
 * when viewed in premultiplied form, a resulting alpha of 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
 * essentially renders the resulting color components irrelevant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
 * and so exact behavior in this case should not be expected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
 * @see Composite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
 * @see CompositeContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
public final class AlphaComposite implements Composite {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * Both the color and the alpha of the destination are cleared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * (Porter-Duff Clear rule).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * Neither the source nor the destination is used as input.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * <em>F<sub>s</sub></em> = 0 and <em>F<sub>d</sub></em> = 0, thus:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *  <em>A<sub>r</sub></em> = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *  <em>C<sub>r</sub></em> = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
   365
    @Native public static final int     CLEAR           = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * The source is copied to the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * (Porter-Duff Source rule).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * The destination is not used as input.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * <em>F<sub>s</sub></em> = 1 and <em>F<sub>d</sub></em> = 0, thus:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *  <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *  <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
   378
    @Native public static final int     SRC             = 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * The destination is left untouched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * (Porter-Duff Destination rule).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * <em>F<sub>s</sub></em> = 0 and <em>F<sub>d</sub></em> = 1, thus:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *  <em>A<sub>r</sub></em> = <em>A<sub>d</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *  <em>C<sub>r</sub></em> = <em>C<sub>d</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
   391
    @Native public static final int     DST             = 9;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    // Note that DST was added in 1.4 so it is numbered out of order...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * The source is composited over the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * (Porter-Duff Source Over Destination rule).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * <em>F<sub>s</sub></em> = 1 and <em>F<sub>d</sub></em> = (1-<em>A<sub>s</sub></em>), thus:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *  <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em> + <em>A<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *  <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em> + <em>C<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
   404
    @Native public static final int     SRC_OVER        = 3;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * The destination is composited over the source and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * the result replaces the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * (Porter-Duff Destination Over Source rule).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * <em>F<sub>s</sub></em> = (1-<em>A<sub>d</sub></em>) and <em>F<sub>d</sub></em> = 1, thus:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *  <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>A<sub>d</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *  <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>C<sub>d</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
   417
    @Native public static final int     DST_OVER        = 4;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * The part of the source lying inside of the destination replaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * (Porter-Duff Source In Destination rule).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * <em>F<sub>s</sub></em> = <em>A<sub>d</sub></em> and <em>F<sub>d</sub></em> = 0, thus:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *  <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*<em>A<sub>d</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *  <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*<em>A<sub>d</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
   430
    @Native public static final int     SRC_IN          = 5;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * The part of the destination lying inside of the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * replaces the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * (Porter-Duff Destination In Source rule).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * <em>F<sub>s</sub></em> = 0 and <em>F<sub>d</sub></em> = <em>A<sub>s</sub></em>, thus:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *  <em>A<sub>r</sub></em> = <em>A<sub>d</sub></em>*<em>A<sub>s</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *  <em>C<sub>r</sub></em> = <em>C<sub>d</sub></em>*<em>A<sub>s</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
   443
    @Native public static final int     DST_IN          = 6;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * The part of the source lying outside of the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * replaces the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * (Porter-Duff Source Held Out By Destination rule).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * <em>F<sub>s</sub></em> = (1-<em>A<sub>d</sub></em>) and <em>F<sub>d</sub></em> = 0, thus:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *  <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *  <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
   456
    @Native public static final int     SRC_OUT         = 7;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * The part of the destination lying outside of the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * replaces the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * (Porter-Duff Destination Held Out By Source rule).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * <em>F<sub>s</sub></em> = 0 and <em>F<sub>d</sub></em> = (1-<em>A<sub>s</sub></em>), thus:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *  <em>A<sub>r</sub></em> = <em>A<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *  <em>C<sub>r</sub></em> = <em>C<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
   469
    @Native public static final int     DST_OUT         = 8;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    // Rule 9 is DST which is defined above where it fits into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    // list logically, rather than numerically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    // public static final int  DST             = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * The part of the source lying inside of the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * is composited onto the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * (Porter-Duff Source Atop Destination rule).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * <em>F<sub>s</sub></em> = <em>A<sub>d</sub></em> and <em>F<sub>d</sub></em> = (1-<em>A<sub>s</sub></em>), thus:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     *  <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*<em>A<sub>d</sub></em> + <em>A<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) = <em>A<sub>d</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *  <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*<em>A<sub>d</sub></em> + <em>C<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
   488
    @Native public static final int     SRC_ATOP        = 10;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * The part of the destination lying inside of the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * is composited over the source and replaces the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * (Porter-Duff Destination Atop Source rule).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * <em>F<sub>s</sub></em> = (1-<em>A<sub>d</sub></em>) and <em>F<sub>d</sub></em> = <em>A<sub>s</sub></em>, thus:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *  <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>A<sub>d</sub></em>*<em>A<sub>s</sub></em> = <em>A<sub>s</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *  <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>C<sub>d</sub></em>*<em>A<sub>s</sub></em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
   502
    @Native public static final int     DST_ATOP        = 11;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * The part of the source that lies outside of the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * is combined with the part of the destination that lies outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * of the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * (Porter-Duff Source Xor Destination rule).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * <em>F<sub>s</sub></em> = (1-<em>A<sub>d</sub></em>) and <em>F<sub>d</sub></em> = (1-<em>A<sub>s</sub></em>), thus:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *  <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>A<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *  <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>C<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
   517
    @Native public static final int     XOR             = 12;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * <code>AlphaComposite</code> object that implements the opaque CLEAR rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * with an alpha of 1.0f.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @see #CLEAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    public static final AlphaComposite Clear    = new AlphaComposite(CLEAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * <code>AlphaComposite</code> object that implements the opaque SRC rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * with an alpha of 1.0f.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @see #SRC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    public static final AlphaComposite Src      = new AlphaComposite(SRC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * <code>AlphaComposite</code> object that implements the opaque DST rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * with an alpha of 1.0f.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @see #DST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    public static final AlphaComposite Dst      = new AlphaComposite(DST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * <code>AlphaComposite</code> object that implements the opaque SRC_OVER rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * with an alpha of 1.0f.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @see #SRC_OVER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    public static final AlphaComposite SrcOver  = new AlphaComposite(SRC_OVER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * <code>AlphaComposite</code> object that implements the opaque DST_OVER rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * with an alpha of 1.0f.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * @see #DST_OVER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    public static final AlphaComposite DstOver  = new AlphaComposite(DST_OVER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * <code>AlphaComposite</code> object that implements the opaque SRC_IN rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * with an alpha of 1.0f.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @see #SRC_IN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    public static final AlphaComposite SrcIn    = new AlphaComposite(SRC_IN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * <code>AlphaComposite</code> object that implements the opaque DST_IN rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * with an alpha of 1.0f.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @see #DST_IN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    public static final AlphaComposite DstIn    = new AlphaComposite(DST_IN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * <code>AlphaComposite</code> object that implements the opaque SRC_OUT rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * with an alpha of 1.0f.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * @see #SRC_OUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    public static final AlphaComposite SrcOut   = new AlphaComposite(SRC_OUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * <code>AlphaComposite</code> object that implements the opaque DST_OUT rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * with an alpha of 1.0f.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @see #DST_OUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    public static final AlphaComposite DstOut   = new AlphaComposite(DST_OUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * <code>AlphaComposite</code> object that implements the opaque SRC_ATOP rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * with an alpha of 1.0f.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @see #SRC_ATOP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    public static final AlphaComposite SrcAtop  = new AlphaComposite(SRC_ATOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * <code>AlphaComposite</code> object that implements the opaque DST_ATOP rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * with an alpha of 1.0f.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * @see #DST_ATOP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    public static final AlphaComposite DstAtop  = new AlphaComposite(DST_ATOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * <code>AlphaComposite</code> object that implements the opaque XOR rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * with an alpha of 1.0f.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @see #XOR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    public static final AlphaComposite Xor      = new AlphaComposite(XOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
   607
    @Native private static final int MIN_RULE = CLEAR;
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
   608
    @Native private static final int MAX_RULE = XOR;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    float extraAlpha;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    int rule;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    private AlphaComposite(int rule) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        this(rule, 1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    private AlphaComposite(int rule, float alpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        if (rule < MIN_RULE || rule > MAX_RULE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            throw new IllegalArgumentException("unknown composite rule");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
4955
e99245ecb5b2 6918065: Crash in Java2D blit loop (IntArgbToIntArgbPreSrcOverMaskBlit) in 64bit mode
minqi
parents: 2
diff changeset
   621
        if (alpha >= 0.0f && alpha <= 1.0f) {
e99245ecb5b2 6918065: Crash in Java2D blit loop (IntArgbToIntArgbPreSrcOverMaskBlit) in 64bit mode
minqi
parents: 2
diff changeset
   622
            this.rule = rule;
e99245ecb5b2 6918065: Crash in Java2D blit loop (IntArgbToIntArgbPreSrcOverMaskBlit) in 64bit mode
minqi
parents: 2
diff changeset
   623
            this.extraAlpha = alpha;
e99245ecb5b2 6918065: Crash in Java2D blit loop (IntArgbToIntArgbPreSrcOverMaskBlit) in 64bit mode
minqi
parents: 2
diff changeset
   624
        } else {
e99245ecb5b2 6918065: Crash in Java2D blit loop (IntArgbToIntArgbPreSrcOverMaskBlit) in 64bit mode
minqi
parents: 2
diff changeset
   625
            throw new IllegalArgumentException("alpha value out of range");
e99245ecb5b2 6918065: Crash in Java2D blit loop (IntArgbToIntArgbPreSrcOverMaskBlit) in 64bit mode
minqi
parents: 2
diff changeset
   626
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * Creates an <code>AlphaComposite</code> object with the specified rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * @param rule the compositing rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * @throws IllegalArgumentException if <code>rule</code> is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     *         the following:  {@link #CLEAR}, {@link #SRC}, {@link #DST},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     *         {@link #SRC_OVER}, {@link #DST_OVER}, {@link #SRC_IN},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *         {@link #DST_IN}, {@link #SRC_OUT}, {@link #DST_OUT},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     *         {@link #SRC_ATOP}, {@link #DST_ATOP}, or {@link #XOR}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    public static AlphaComposite getInstance(int rule) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        switch (rule) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        case CLEAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            return Clear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        case SRC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            return Src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        case DST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            return Dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        case SRC_OVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            return SrcOver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        case DST_OVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            return DstOver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        case SRC_IN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            return SrcIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        case DST_IN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            return DstIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        case SRC_OUT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            return SrcOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        case DST_OUT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            return DstOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        case SRC_ATOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            return SrcAtop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        case DST_ATOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            return DstAtop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        case XOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            return Xor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            throw new IllegalArgumentException("unknown composite rule");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * Creates an <code>AlphaComposite</code> object with the specified rule and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * the constant alpha to multiply with the alpha of the source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * The source is multiplied with the specified alpha before being composited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * with the destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * @param rule the compositing rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * @param alpha the constant alpha to be multiplied with the alpha of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * the source. <code>alpha</code> must be a floating point number in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * inclusive range [0.0,&nbsp;1.0].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * @throws IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     *         <code>alpha</code> is less than 0.0 or greater than 1.0, or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     *         <code>rule</code> is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     *         the following:  {@link #CLEAR}, {@link #SRC}, {@link #DST},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *         {@link #SRC_OVER}, {@link #DST_OVER}, {@link #SRC_IN},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     *         {@link #DST_IN}, {@link #SRC_OUT}, {@link #DST_OUT},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *         {@link #SRC_ATOP}, {@link #DST_ATOP}, or {@link #XOR}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    public static AlphaComposite getInstance(int rule, float alpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        if (alpha == 1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            return getInstance(rule);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        return new AlphaComposite(rule, alpha);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * Creates a context for the compositing operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * The context contains state that is used in performing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * the compositing operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * @param srcColorModel  the {@link ColorModel} of the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @param dstColorModel  the <code>ColorModel</code> of the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @return the <code>CompositeContext</code> object to be used to perform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * compositing operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    public CompositeContext createContext(ColorModel srcColorModel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                                          ColorModel dstColorModel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                                          RenderingHints hints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        return new SunCompositeContext(this, srcColorModel, dstColorModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * Returns the alpha value of this <code>AlphaComposite</code>.  If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * <code>AlphaComposite</code> does not have an alpha value, 1.0 is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * @return the alpha value of this <code>AlphaComposite</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    public float getAlpha() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        return extraAlpha;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * Returns the compositing rule of this <code>AlphaComposite</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * @return the compositing rule of this <code>AlphaComposite</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    public int getRule() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        return rule;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * Returns a similar <code>AlphaComposite</code> object that uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * the specified compositing rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * If this object already uses the specified compositing rule,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * this object is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * @return an <code>AlphaComposite</code> object derived from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * this object that uses the specified compositing rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * @param rule the compositing rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * @throws IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     *         <code>rule</code> is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     *         the following:  {@link #CLEAR}, {@link #SRC}, {@link #DST},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     *         {@link #SRC_OVER}, {@link #DST_OVER}, {@link #SRC_IN},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     *         {@link #DST_IN}, {@link #SRC_OUT}, {@link #DST_OUT},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     *         {@link #SRC_ATOP}, {@link #DST_ATOP}, or {@link #XOR}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    public AlphaComposite derive(int rule) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        return (this.rule == rule)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            ? this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            : getInstance(rule, this.extraAlpha);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * Returns a similar <code>AlphaComposite</code> object that uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * the specified alpha value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * If this object already has the specified alpha value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * this object is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * @return an <code>AlphaComposite</code> object derived from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * this object that uses the specified alpha value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * @param alpha the constant alpha to be multiplied with the alpha of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * the source. <code>alpha</code> must be a floating point number in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * inclusive range [0.0,&nbsp;1.0].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * @throws IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     *         <code>alpha</code> is less than 0.0 or greater than 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    public AlphaComposite derive(float alpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        return (this.extraAlpha == alpha)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            ? this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            : getInstance(this.rule, alpha);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * Returns the hashcode for this composite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * @return      a hash code for this composite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        return (Float.floatToIntBits(extraAlpha) * 31 + rule);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * Determines whether the specified object is equal to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * <code>AlphaComposite</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * The result is <code>true</code> if and only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * the argument is not <code>null</code> and is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * <code>AlphaComposite</code> object that has the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * compositing rule and alpha value as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * @param obj the <code>Object</code> to test for equality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * @return <code>true</code> if <code>obj</code> equals this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * <code>AlphaComposite</code>; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        if (!(obj instanceof AlphaComposite)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        AlphaComposite ac = (AlphaComposite) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        if (rule != ac.rule) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        if (extraAlpha != ac.extraAlpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
}