19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2006 The Android Open Source Project
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License.
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License.
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// This file was generated from the C++ include file: SkColorFilter.h
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// Any changes made to this file will be discarded by the build.
199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// To change this file, either edit the include, or device/tools/gluemaker/main.cpp,
209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// or one of the auxilary file specifications in device/tools/gluemaker.
219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.graphics;
239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2413656743cc21bac43676568314366497346713eeRomain Guy/**
2513656743cc21bac43676568314366497346713eeRomain Guy * A color filter that can be used to simulate simple lighting effects.
2613656743cc21bac43676568314366497346713eeRomain Guy * A <code>LightingColorFilter</code> is defined by two parameters, one
2713656743cc21bac43676568314366497346713eeRomain Guy * used to multiply the source color (called <code>colorMultiply</code>)
2813656743cc21bac43676568314366497346713eeRomain Guy * and one used to add to the source color (called <code>colorAdd</code>).
2913656743cc21bac43676568314366497346713eeRomain Guy * The alpha channel is left untouched by this color filter.
3013656743cc21bac43676568314366497346713eeRomain Guy *
3113656743cc21bac43676568314366497346713eeRomain Guy * Given a source color RGB, the resulting R'G'B' color is computed thusly:
3213656743cc21bac43676568314366497346713eeRomain Guy * <pre>
3313656743cc21bac43676568314366497346713eeRomain Guy * R' = R * colorMultiply.R + colorAdd.R
3413656743cc21bac43676568314366497346713eeRomain Guy * G' = G * colorMultiply.G + colorAdd.G
3513656743cc21bac43676568314366497346713eeRomain Guy * B' = B * colorMultiply.B + colorAdd.B
3613656743cc21bac43676568314366497346713eeRomain Guy * </pre>
3713656743cc21bac43676568314366497346713eeRomain Guy * The result is pinned to the <code>[0..255]</code> range for each channel.
3813656743cc21bac43676568314366497346713eeRomain Guy */
399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class LightingColorFilter extends ColorFilter {
4013656743cc21bac43676568314366497346713eeRomain Guy    private int mMul;
4113656743cc21bac43676568314366497346713eeRomain Guy    private int mAdd;
429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
4413656743cc21bac43676568314366497346713eeRomain Guy     * Create a colorfilter that multiplies the RGB channels by one color,
4513656743cc21bac43676568314366497346713eeRomain Guy     * and then adds a second color. The alpha components of the mul and add
4613656743cc21bac43676568314366497346713eeRomain Guy     * arguments are ignored.
479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public LightingColorFilter(int mul, int add) {
4913656743cc21bac43676568314366497346713eeRomain Guy        mMul = mul;
5013656743cc21bac43676568314366497346713eeRomain Guy        mAdd = add;
5113656743cc21bac43676568314366497346713eeRomain Guy        update();
5213656743cc21bac43676568314366497346713eeRomain Guy    }
5313656743cc21bac43676568314366497346713eeRomain Guy
5413656743cc21bac43676568314366497346713eeRomain Guy    /**
5513656743cc21bac43676568314366497346713eeRomain Guy     * Returns the RGB color used to multiply the source color when the
5613656743cc21bac43676568314366497346713eeRomain Guy     * color filter is applied.
5713656743cc21bac43676568314366497346713eeRomain Guy     *
5813656743cc21bac43676568314366497346713eeRomain Guy     * @see #setColorMultiply(int)
59f559326b182e321f51ab9711614d3e37fefa603aChris Craik     *
60f559326b182e321f51ab9711614d3e37fefa603aChris Craik     * @hide
6113656743cc21bac43676568314366497346713eeRomain Guy     */
6213656743cc21bac43676568314366497346713eeRomain Guy    public int getColorMultiply() {
6313656743cc21bac43676568314366497346713eeRomain Guy        return mMul;
6413656743cc21bac43676568314366497346713eeRomain Guy    }
6513656743cc21bac43676568314366497346713eeRomain Guy
6613656743cc21bac43676568314366497346713eeRomain Guy    /**
6713656743cc21bac43676568314366497346713eeRomain Guy     * Specifies the RGB color used to multiply the source color when the
6813656743cc21bac43676568314366497346713eeRomain Guy     * color filter is applied.
6913656743cc21bac43676568314366497346713eeRomain Guy     * The alpha channel of this color is ignored.
7013656743cc21bac43676568314366497346713eeRomain Guy     *
7113656743cc21bac43676568314366497346713eeRomain Guy     * @see #getColorMultiply()
72f559326b182e321f51ab9711614d3e37fefa603aChris Craik     *
73f559326b182e321f51ab9711614d3e37fefa603aChris Craik     * @hide
7413656743cc21bac43676568314366497346713eeRomain Guy     */
7513656743cc21bac43676568314366497346713eeRomain Guy    public void setColorMultiply(int mul) {
7613656743cc21bac43676568314366497346713eeRomain Guy        mMul = mul;
7713656743cc21bac43676568314366497346713eeRomain Guy        update();
7813656743cc21bac43676568314366497346713eeRomain Guy    }
7913656743cc21bac43676568314366497346713eeRomain Guy
8013656743cc21bac43676568314366497346713eeRomain Guy    /**
8113656743cc21bac43676568314366497346713eeRomain Guy     * Returns the RGB color that will be added to the source color
8213656743cc21bac43676568314366497346713eeRomain Guy     * when the color filter is applied.
8313656743cc21bac43676568314366497346713eeRomain Guy     *
8413656743cc21bac43676568314366497346713eeRomain Guy     * @see #setColorAdd(int)
85f559326b182e321f51ab9711614d3e37fefa603aChris Craik     *
86f559326b182e321f51ab9711614d3e37fefa603aChris Craik     * @hide
8713656743cc21bac43676568314366497346713eeRomain Guy     */
8813656743cc21bac43676568314366497346713eeRomain Guy    public int getColorAdd() {
8913656743cc21bac43676568314366497346713eeRomain Guy        return mAdd;
9013656743cc21bac43676568314366497346713eeRomain Guy    }
9113656743cc21bac43676568314366497346713eeRomain Guy
9213656743cc21bac43676568314366497346713eeRomain Guy    /**
9313656743cc21bac43676568314366497346713eeRomain Guy     * Specifies the RGB that will be added to the source color when
9413656743cc21bac43676568314366497346713eeRomain Guy     * the color filter is applied.
9513656743cc21bac43676568314366497346713eeRomain Guy     * The alpha channel of this color is ignored.
9613656743cc21bac43676568314366497346713eeRomain Guy     *
9713656743cc21bac43676568314366497346713eeRomain Guy     * @see #getColorAdd()
98f559326b182e321f51ab9711614d3e37fefa603aChris Craik     *
99f559326b182e321f51ab9711614d3e37fefa603aChris Craik     * @hide
10013656743cc21bac43676568314366497346713eeRomain Guy     */
10113656743cc21bac43676568314366497346713eeRomain Guy    public void setColorAdd(int add) {
10213656743cc21bac43676568314366497346713eeRomain Guy        mAdd = add;
10313656743cc21bac43676568314366497346713eeRomain Guy        update();
10413656743cc21bac43676568314366497346713eeRomain Guy    }
10513656743cc21bac43676568314366497346713eeRomain Guy
10613656743cc21bac43676568314366497346713eeRomain Guy    private void update() {
10776d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger        destroyFilter(native_instance);
10813656743cc21bac43676568314366497346713eeRomain Guy        native_instance = native_CreateLightingFilter(mMul, mAdd);
1099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
11136bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    private static native long native_CreateLightingFilter(int mul, int add);
1129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
113