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 package android.graphics;
18 
19 public class PorterDuff {
20 
21     // these value must match their native equivalents. See SkXfermode.h
22     public enum Mode {
23         /** [0, 0] */
24         CLEAR       (0),
25         /** [Sa, Sc] */
26         SRC         (1),
27         /** [Da, Dc] */
28         DST         (2),
29         /** [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc] */
30         SRC_OVER    (3),
31         /** [Sa + (1 - Sa)*Da, Rc = Dc + (1 - Da)*Sc] */
32         DST_OVER    (4),
33         /** [Sa * Da, Sc * Da] */
34         SRC_IN      (5),
35         /** [Sa * Da, Sa * Dc] */
36         DST_IN      (6),
37         /** [Sa * (1 - Da), Sc * (1 - Da)] */
38         SRC_OUT     (7),
39         /** [Da * (1 - Sa), Dc * (1 - Sa)] */
40         DST_OUT     (8),
41         /** [Da, Sc * Da + (1 - Sa) * Dc] */
42         SRC_ATOP    (9),
43         /** [Sa, Sa * Dc + Sc * (1 - Da)] */
44         DST_ATOP    (10),
45         /** [Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + (1 - Sa) * Dc] */
46         XOR         (11),
47         /** [Sa + Da - Sa*Da,
48              Sc*(1 - Da) + Dc*(1 - Sa) + min(Sc, Dc)] */
49         DARKEN      (16),
50         /** [Sa + Da - Sa*Da,
51              Sc*(1 - Da) + Dc*(1 - Sa) + max(Sc, Dc)] */
52         LIGHTEN     (17),
53         /** [Sa * Da, Sc * Dc] */
54         MULTIPLY    (13),
55         /** [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc] */
56         SCREEN      (14),
57         /** Saturate(S + D) */
58         ADD         (12),
59         OVERLAY     (15);
60 
Mode(int nativeInt)61         Mode(int nativeInt) {
62             this.nativeInt = nativeInt;
63         }
64 
65         /**
66          * @hide
67          */
68         public final int nativeInt;
69     }
70 
71     /**
72      * @hide
73      */
modeToInt(Mode mode)74     public static final int modeToInt(Mode mode) {
75         return mode.nativeInt;
76     }
77 
78     /**
79      * @hide
80      */
intToMode(int val)81     public static final Mode intToMode(int val) {
82         switch (val) {
83             default:
84             case  0: return Mode.CLEAR;
85             case  1: return Mode.SRC;
86             case  2: return Mode.DST;
87             case  3: return Mode.SRC_OVER;
88             case  4: return Mode.DST_OVER;
89             case  5: return Mode.SRC_IN;
90             case  6: return Mode.DST_IN;
91             case  7: return Mode.SRC_OUT;
92             case  8: return Mode.DST_OUT;
93             case  9: return Mode.SRC_ATOP;
94             case 10: return Mode.DST_ATOP;
95             case 11: return Mode.XOR;
96             case 16: return Mode.DARKEN;
97             case 17: return Mode.LIGHTEN;
98             case 13: return Mode.MULTIPLY;
99             case 14: return Mode.SCREEN;
100             case 12: return Mode.ADD;
101             case 15: return Mode.OVERLAY;
102         }
103     }
104 }
105