LightingColorFilter.java revision 18b4cbeedef21c1fa666a110a157bab66edff976
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
22package android.graphics;
23
24/**
25 * A color filter that can be used to simulate simple lighting effects.
26 * A <code>LightingColorFilter</code> is defined by two parameters, one
27 * used to multiply the source color (called <code>colorMultiply</code>)
28 * and one used to add to the source color (called <code>colorAdd</code>).
29 * The alpha channel is left untouched by this color filter.
30 *
31 * Given a source color RGB, the resulting R'G'B' color is computed thusly:
32 * <pre>
33 * R' = R * colorMultiply.R + colorAdd.R
34 * G' = G * colorMultiply.G + colorAdd.G
35 * B' = B * colorMultiply.B + colorAdd.B
36 * </pre>
37 * The result is pinned to the <code>[0..255]</code> range for each channel.
38 */
39public class LightingColorFilter extends ColorFilter {
40    private int mMul;
41    private int mAdd;
42
43    /**
44     * Create a colorfilter that multiplies the RGB channels by one color,
45     * and then adds a second color. The alpha components of the mul and add
46     * arguments are ignored.
47     *
48     * @see #setColorMultiply(int)
49     * @see #setColorAdd(int)
50     */
51    public LightingColorFilter(int mul, int add) {
52        mMul = mul;
53        mAdd = add;
54        update();
55    }
56
57    /**
58     * Returns the RGB color used to multiply the source color when the
59     * color filter is applied.
60     *
61     * @see #setColorMultiply(int)
62     */
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    public void setColorMultiply(int mul) {
75        mMul = mul;
76        update();
77    }
78
79    /**
80     * Returns the RGB color that will be added to the source color
81     * when the color filter is applied.
82     *
83     * @see #setColorAdd(int)
84     */
85    public int getColorAdd() {
86        return mAdd;
87    }
88
89    /**
90     * Specifies the RGB that will be added to the source color when
91     * the color filter is applied.
92     * The alpha channel of this color is ignored.
93     *
94     * @see #getColorAdd()
95     */
96    public void setColorAdd(int add) {
97        mAdd = add;
98        update();
99    }
100
101    private void update() {
102        destroyFilter(native_instance, nativeColorFilter);
103        native_instance = native_CreateLightingFilter(mMul, mAdd);
104        nativeColorFilter = nCreateLightingFilter(native_instance, mMul, mAdd);
105    }
106
107    private static native long native_CreateLightingFilter(int mul, int add);
108    private static native long nCreateLightingFilter(long nativeFilter, int mul, int add);
109}
110