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 /** 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 */ 39 public 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 public LightingColorFilter(int mul, int add) { 49 mMul = mul; 50 mAdd = add; 51 update(); 52 } 53 54 /** 55 * Returns the RGB color used to multiply the source color when the 56 * color filter is applied. 57 * 58 * @see #setColorMultiply(int) 59 * 60 * @hide 61 */ 62 public int getColorMultiply() { 63 return mMul; 64 } 65 66 /** 67 * Specifies the RGB color used to multiply the source color when the 68 * color filter is applied. 69 * The alpha channel of this color is ignored. 70 * 71 * @see #getColorMultiply() 72 * 73 * @hide 74 */ 75 public void setColorMultiply(int mul) { 76 mMul = mul; 77 update(); 78 } 79 80 /** 81 * Returns the RGB color that will be added to the source color 82 * when the color filter is applied. 83 * 84 * @see #setColorAdd(int) 85 * 86 * @hide 87 */ 88 public int getColorAdd() { 89 return mAdd; 90 } 91 92 /** 93 * Specifies the RGB that will be added to the source color when 94 * the color filter is applied. 95 * The alpha channel of this color is ignored. 96 * 97 * @see #getColorAdd() 98 * 99 * @hide 100 */ 101 public void setColorAdd(int add) { 102 mAdd = add; 103 update(); 104 } 105 106 private void update() { 107 destroyFilter(native_instance); 108 native_instance = native_CreateLightingFilter(mMul, mAdd); 109 } 110 111 private static native long native_CreateLightingFilter(int mul, int add); 112 } 113