summaryrefslogtreecommitdiffstats
path: root/graphics/java/android/graphics/LightingColorFilter.java
blob: ad78430e247294b5d7b48df3b58556dc29e4221b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// This file was generated from the C++ include file: SkColorFilter.h
// Any changes made to this file will be discarded by the build.
// To change this file, either edit the include, or device/tools/gluemaker/main.cpp, 
// or one of the auxilary file specifications in device/tools/gluemaker.

package android.graphics;

/**
 * A color filter that can be used to simulate simple lighting effects.
 * A <code>LightingColorFilter</code> is defined by two parameters, one
 * used to multiply the source color (called <code>colorMultiply</code>)
 * and one used to add to the source color (called <code>colorAdd</code>).
 * The alpha channel is left untouched by this color filter.
 *
 * Given a source color RGB, the resulting R'G'B' color is computed thusly:
 * <pre>
 * R' = R * colorMultiply.R + colorAdd.R
 * G' = G * colorMultiply.G + colorAdd.G
 * B' = B * colorMultiply.B + colorAdd.B
 * </pre>
 * The result is pinned to the <code>[0..255]</code> range for each channel.
 */
public class LightingColorFilter extends ColorFilter {
    private int mMul;
    private int mAdd;

    /**
     * Create a colorfilter that multiplies the RGB channels by one color,
     * and then adds a second color. The alpha components of the mul and add
     * arguments are ignored.
     */
    public LightingColorFilter(int mul, int add) {
        mMul = mul;
        mAdd = add;
        update();
    }

    /**
     * Returns the RGB color used to multiply the source color when the
     * color filter is applied.
     *
     * @see #setColorMultiply(int)
     *
     * @hide
     */
    public int getColorMultiply() {
        return mMul;
    }

    /**
     * Specifies the RGB color used to multiply the source color when the
     * color filter is applied.
     * The alpha channel of this color is ignored.
     *
     * @see #getColorMultiply()
     *
     * @hide
     */
    public void setColorMultiply(int mul) {
        mMul = mul;
        update();
    }

    /**
     * Returns the RGB color that will be added to the source color
     * when the color filter is applied.
     *
     * @see #setColorAdd(int)
     *
     * @hide
     */
    public int getColorAdd() {
        return mAdd;
    }

    /**
     * Specifies the RGB that will be added to the source color when
     * the color filter is applied.
     * The alpha channel of this color is ignored.
     *
     * @see #getColorAdd()
     *
     * @hide
     */
    public void setColorAdd(int add) {
        mAdd = add;
        update();
    }

    private void update() {
        destroyFilter(native_instance);
        native_instance = native_CreateLightingFilter(mMul, mAdd);
    }

    private static native long native_CreateLightingFilter(int mul, int add);
}