• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SkPorterDuff_DEFINED
18 #define SkPorterDuff_DEFINED
19 
20 #include "SkColor.h"
21 
22 class SkXfermode;
23 
24 class SkPorterDuff {
25 public:
26     /** List of predefined xfermodes. In general, the algebra for the modes
27         uses the following symbols:
28         Sa, Sc  - source alpha and color
29         Da, Dc - destination alpha and color (before compositing)
30         [a, c] - Resulting (alpha, color) values
31         For these equations, the colors are in premultiplied state.
32         If no xfermode is specified, kSrcOver is assumed.
33     */
34     enum Mode {
35         kClear_Mode,    //!< [0, 0]
36         kSrc_Mode,      //!< [Sa, Sc]
37         kDst_Mode,      //!< [Da, Dc]
38         kSrcOver_Mode,  //!< [Sa + Da - Sa*Da, Rc = Sc + (1 - Sa)*Dc]
39         kDstOver_Mode,  //!< [Sa + Da - Sa*Da, Rc = Dc + (1 - Da)*Sc]
40         kSrcIn_Mode,    //!< [Sa * Da, Sc * Da]
41         kDstIn_Mode,    //!< [Sa * Da, Sa * Dc]
42         kSrcOut_Mode,   //!< [Sa * (1 - Da), Sc * (1 - Da)]
43         kDstOut_Mode,   //!< [Da * (1 - Sa), Dc * (1 - Sa)]
44         kSrcATop_Mode,  //!< [Da, Sc * Da + (1 - Sa) * Dc]
45         kDstATop_Mode,  //!< [Sa, Sa * Dc + Sc * (1 - Da)]
46         kXor_Mode,      //!< [Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + (1 - Sa) * Dc]
47         kDarken_Mode,   //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + min(Sc, Dc)]
48         kLighten_Mode,  //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + max(Sc, Dc)]
49         kMultiply_Mode, //!< [Sa * Da, Sc * Dc]
50         kScreen_Mode,   //!< [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
51 
52         kModeCount
53     };
54     /** Return an SkXfermode object for the specified mode.
55     */
56     static SkXfermode* CreateXfermode(Mode mode);
57 
58     /** Return a function pointer to a routine that applies the specified
59         porter-duff transfer mode.
60     */
61     static SkXfermodeProc GetXfermodeProc(Mode mode);
62 
63     /** Return a function pointer to a routine that applies the specified
64         porter-duff transfer mode and srcColor to a 16bit device color. Note,
65         if the mode+srcColor might return a non-opaque color, then there is not
66         16bit proc, and this will return NULL.
67     */
68     static SkXfermodeProc16 GetXfermodeProc16(Mode mode, SkColor srcColor);
69 
70     /** If the specified xfermode advertises itself as one of the porterduff
71         modes (via SkXfermode::Coeff), return true and if not null, set mode
72         to the corresponding porterduff mode. If it is not recognized as a one,
73         return false and ignore the mode parameter.
74     */
75     static bool IsMode(SkXfermode*, Mode* mode);
76 };
77 
78 #endif
79 
80