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