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 246097eca72134034fcc6086c110673b5df94913b0Chris Craikimport android.annotation.ColorInt; 256097eca72134034fcc6086c110673b5df94913b0Chris Craik 2613656743cc21bac43676568314366497346713eeRomain Guy/** 2713656743cc21bac43676568314366497346713eeRomain Guy * A color filter that can be used to simulate simple lighting effects. 2813656743cc21bac43676568314366497346713eeRomain Guy * A <code>LightingColorFilter</code> is defined by two parameters, one 2913656743cc21bac43676568314366497346713eeRomain Guy * used to multiply the source color (called <code>colorMultiply</code>) 3013656743cc21bac43676568314366497346713eeRomain Guy * and one used to add to the source color (called <code>colorAdd</code>). 3113656743cc21bac43676568314366497346713eeRomain Guy * The alpha channel is left untouched by this color filter. 3213656743cc21bac43676568314366497346713eeRomain Guy * 3313656743cc21bac43676568314366497346713eeRomain Guy * Given a source color RGB, the resulting R'G'B' color is computed thusly: 3413656743cc21bac43676568314366497346713eeRomain Guy * <pre> 3513656743cc21bac43676568314366497346713eeRomain Guy * R' = R * colorMultiply.R + colorAdd.R 3613656743cc21bac43676568314366497346713eeRomain Guy * G' = G * colorMultiply.G + colorAdd.G 3713656743cc21bac43676568314366497346713eeRomain Guy * B' = B * colorMultiply.B + colorAdd.B 3813656743cc21bac43676568314366497346713eeRomain Guy * </pre> 3913656743cc21bac43676568314366497346713eeRomain Guy * The result is pinned to the <code>[0..255]</code> range for each channel. 4013656743cc21bac43676568314366497346713eeRomain Guy */ 419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class LightingColorFilter extends ColorFilter { 426097eca72134034fcc6086c110673b5df94913b0Chris Craik @ColorInt 4313656743cc21bac43676568314366497346713eeRomain Guy private int mMul; 446097eca72134034fcc6086c110673b5df94913b0Chris Craik @ColorInt 4513656743cc21bac43676568314366497346713eeRomain Guy private int mAdd; 469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4813656743cc21bac43676568314366497346713eeRomain Guy * Create a colorfilter that multiplies the RGB channels by one color, 4913656743cc21bac43676568314366497346713eeRomain Guy * and then adds a second color. The alpha components of the mul and add 5013656743cc21bac43676568314366497346713eeRomain Guy * arguments are ignored. 519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 526097eca72134034fcc6086c110673b5df94913b0Chris Craik public LightingColorFilter(@ColorInt int mul, @ColorInt int add) { 5313656743cc21bac43676568314366497346713eeRomain Guy mMul = mul; 5413656743cc21bac43676568314366497346713eeRomain Guy mAdd = add; 5513656743cc21bac43676568314366497346713eeRomain Guy } 5613656743cc21bac43676568314366497346713eeRomain Guy 5713656743cc21bac43676568314366497346713eeRomain Guy /** 5813656743cc21bac43676568314366497346713eeRomain Guy * Returns the RGB color used to multiply the source color when the 5913656743cc21bac43676568314366497346713eeRomain Guy * color filter is applied. 6013656743cc21bac43676568314366497346713eeRomain Guy */ 616097eca72134034fcc6086c110673b5df94913b0Chris Craik @ColorInt 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() 728a6ad4a89d1b9ed61d3ec6f5bc12d479bc8d9f3bChris Craik * 738a6ad4a89d1b9ed61d3ec6f5bc12d479bc8d9f3bChris Craik * @hide 7413656743cc21bac43676568314366497346713eeRomain Guy */ 756097eca72134034fcc6086c110673b5df94913b0Chris Craik public void setColorMultiply(@ColorInt int mul) { 766097eca72134034fcc6086c110673b5df94913b0Chris Craik if (mMul != mul) { 776097eca72134034fcc6086c110673b5df94913b0Chris Craik mMul = mul; 786097eca72134034fcc6086c110673b5df94913b0Chris Craik discardNativeInstance(); 796097eca72134034fcc6086c110673b5df94913b0Chris Craik } 8013656743cc21bac43676568314366497346713eeRomain Guy } 8113656743cc21bac43676568314366497346713eeRomain Guy 8213656743cc21bac43676568314366497346713eeRomain Guy /** 8313656743cc21bac43676568314366497346713eeRomain Guy * Returns the RGB color that will be added to the source color 8413656743cc21bac43676568314366497346713eeRomain Guy * when the color filter is applied. 8513656743cc21bac43676568314366497346713eeRomain Guy */ 866097eca72134034fcc6086c110673b5df94913b0Chris Craik @ColorInt 8713656743cc21bac43676568314366497346713eeRomain Guy public int getColorAdd() { 8813656743cc21bac43676568314366497346713eeRomain Guy return mAdd; 8913656743cc21bac43676568314366497346713eeRomain Guy } 9013656743cc21bac43676568314366497346713eeRomain Guy 9113656743cc21bac43676568314366497346713eeRomain Guy /** 9213656743cc21bac43676568314366497346713eeRomain Guy * Specifies the RGB that will be added to the source color when 9313656743cc21bac43676568314366497346713eeRomain Guy * the color filter is applied. 9413656743cc21bac43676568314366497346713eeRomain Guy * The alpha channel of this color is ignored. 9513656743cc21bac43676568314366497346713eeRomain Guy * 9613656743cc21bac43676568314366497346713eeRomain Guy * @see #getColorAdd() 978a6ad4a89d1b9ed61d3ec6f5bc12d479bc8d9f3bChris Craik * 988a6ad4a89d1b9ed61d3ec6f5bc12d479bc8d9f3bChris Craik * @hide 9913656743cc21bac43676568314366497346713eeRomain Guy */ 1006097eca72134034fcc6086c110673b5df94913b0Chris Craik public void setColorAdd(@ColorInt int add) { 1016097eca72134034fcc6086c110673b5df94913b0Chris Craik if (mAdd != add) { 1026097eca72134034fcc6086c110673b5df94913b0Chris Craik mAdd = add; 1036097eca72134034fcc6086c110673b5df94913b0Chris Craik discardNativeInstance(); 1046097eca72134034fcc6086c110673b5df94913b0Chris Craik } 10513656743cc21bac43676568314366497346713eeRomain Guy } 10613656743cc21bac43676568314366497346713eeRomain Guy 1076097eca72134034fcc6086c110673b5df94913b0Chris Craik @Override 1086097eca72134034fcc6086c110673b5df94913b0Chris Craik long createNativeInstance() { 1096097eca72134034fcc6086c110673b5df94913b0Chris Craik return native_CreateLightingFilter(mMul, mAdd); 1109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 11236bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native long native_CreateLightingFilter(int mul, int add); 1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 114