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 // This file was generated from the C++ include file: SkColorFilter.h
18 // Any changes made to this file will be discarded by the build.
19 // To change this file, either edit the include, or device/tools/gluemaker/main.cpp,
20 // or one of the auxilary file specifications in device/tools/gluemaker.
21 
22 package android.graphics;
23 
24 import android.annotation.ColorInt;
25 import android.compat.annotation.UnsupportedAppUsage;
26 
27 /**
28  * A color filter that can be used to simulate simple lighting effects.
29  * A <code>LightingColorFilter</code> is defined by two parameters, one
30  * used to multiply the source color (called <code>colorMultiply</code>)
31  * and one used to add to the source color (called <code>colorAdd</code>).
32  * The alpha channel is left untouched by this color filter.
33  *
34  * Given a source color RGB, the resulting R'G'B' color is computed thusly:
35  * <pre>
36  * R' = R * colorMultiply.R + colorAdd.R
37  * G' = G * colorMultiply.G + colorAdd.G
38  * B' = B * colorMultiply.B + colorAdd.B
39  * </pre>
40  * The result is pinned to the <code>[0..255]</code> range for each channel.
41  */
42 public class LightingColorFilter extends ColorFilter {
43     @ColorInt
44     private int mMul;
45     @ColorInt
46     private int mAdd;
47 
48     /**
49      * Create a colorfilter that multiplies the RGB channels by one color,
50      * and then adds a second color. The alpha components of the mul and add
51      * arguments are ignored.
52      */
LightingColorFilter(@olorInt int mul, @ColorInt int add)53     public LightingColorFilter(@ColorInt int mul, @ColorInt int add) {
54         mMul = mul;
55         mAdd = add;
56     }
57 
58     /**
59      * Returns the RGB color used to multiply the source color when the
60      * color filter is applied.
61      */
62     @ColorInt
getColorMultiply()63     public int getColorMultiply() {
64         return mMul;
65     }
66 
67     /**
68      * Specifies the RGB color used to multiply the source color when the
69      * color filter is applied.
70      * The alpha channel of this color is ignored.
71      *
72      * @see #getColorMultiply()
73      *
74      * @hide
75      */
76     @UnsupportedAppUsage
setColorMultiply(@olorInt int mul)77     public void setColorMultiply(@ColorInt int mul) {
78         if (mMul != mul) {
79             mMul = mul;
80             discardNativeInstance();
81         }
82     }
83 
84     /**
85      * Returns the RGB color that will be added to the source color
86      * when the color filter is applied.
87      */
88     @ColorInt
getColorAdd()89     public int getColorAdd() {
90         return mAdd;
91     }
92 
93     /**
94      * Specifies the RGB that will be added to the source color when
95      * the color filter is applied.
96      * The alpha channel of this color is ignored.
97      *
98      * @see #getColorAdd()
99      *
100      * @hide
101      */
102     @UnsupportedAppUsage
setColorAdd(@olorInt int add)103     public void setColorAdd(@ColorInt int add) {
104         if (mAdd != add) {
105             mAdd = add;
106             discardNativeInstance();
107         }
108     }
109 
110     @Override
createNativeInstance()111     long createNativeInstance() {
112         return native_CreateLightingFilter(mMul, mAdd);
113     }
114 
native_CreateLightingFilter(int mul, int add)115     private static native long native_CreateLightingFilter(int mul, int add);
116 }
117