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 import android.annotation.ColorInt; 25 import android.compat.annotation.UnsupportedAppUsage; 26 import android.os.Build; 27 28 /** 29 * A color filter that can be used to simulate simple lighting effects. 30 * A <code>LightingColorFilter</code> is defined by two parameters, one 31 * used to multiply the source color (called <code>colorMultiply</code>) 32 * and one used to add to the source color (called <code>colorAdd</code>). 33 * The alpha channel is left untouched by this color filter. 34 * 35 * Given a source color RGB, the resulting R'G'B' color is computed thusly: 36 * <pre> 37 * R' = R * colorMultiply.R + colorAdd.R 38 * G' = G * colorMultiply.G + colorAdd.G 39 * B' = B * colorMultiply.B + colorAdd.B 40 * </pre> 41 * The result is pinned to the <code>[0..255]</code> range for each channel. 42 */ 43 public class LightingColorFilter extends ColorFilter { 44 @ColorInt 45 private int mMul; 46 @ColorInt 47 private int mAdd; 48 49 /** 50 * Create a colorfilter that multiplies the RGB channels by one color, 51 * and then adds a second color. The alpha components of the mul and add 52 * arguments are ignored. 53 */ LightingColorFilter(@olorInt int mul, @ColorInt int add)54 public LightingColorFilter(@ColorInt int mul, @ColorInt int add) { 55 mMul = mul; 56 mAdd = add; 57 } 58 59 /** 60 * Returns the RGB color used to multiply the source color when the 61 * color filter is applied. 62 */ 63 @ColorInt getColorMultiply()64 public int getColorMultiply() { 65 return mMul; 66 } 67 68 /** 69 * Specifies the RGB color used to multiply the source color when the 70 * color filter is applied. 71 * The alpha channel of this color is ignored. 72 * 73 * @see #getColorMultiply() 74 * 75 * @hide 76 */ 77 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setColorMultiply(@olorInt int mul)78 public void setColorMultiply(@ColorInt int mul) { 79 if (mMul != mul) { 80 mMul = mul; 81 discardNativeInstance(); 82 } 83 } 84 85 /** 86 * Returns the RGB color that will be added to the source color 87 * when the color filter is applied. 88 */ 89 @ColorInt getColorAdd()90 public int getColorAdd() { 91 return mAdd; 92 } 93 94 /** 95 * Specifies the RGB that will be added to the source color when 96 * the color filter is applied. 97 * The alpha channel of this color is ignored. 98 * 99 * @see #getColorAdd() 100 * 101 * @hide 102 */ 103 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setColorAdd(@olorInt int add)104 public void setColorAdd(@ColorInt int add) { 105 if (mAdd != add) { 106 mAdd = add; 107 discardNativeInstance(); 108 } 109 } 110 111 @Override createNativeInstance()112 long createNativeInstance() { 113 return native_CreateLightingFilter(mMul, mAdd); 114 } 115 native_CreateLightingFilter(int mul, int add)116 private static native long native_CreateLightingFilter(int mul, int add); 117 } 118