Home | History | Annotate | Download | only in graphics
      1 /*
      2  * Copyright (C) 2008 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 package android.graphics;
     18 
     19 /**
     20  * AvoidXfermode xfermode will draw the src everywhere except on top of the
     21  * opColor or, depending on the Mode, draw only on top of the opColor.
     22  */
     23 @Deprecated
     24 public class AvoidXfermode extends Xfermode {
     25 
     26     // these need to match the enum in SkAvoidXfermode.h on the native side
     27     public enum Mode {
     28         AVOID   (0),    //!< draw everywhere except on the opColor
     29         TARGET  (1);    //!< draw only on top of the opColor
     30 
     31         Mode(int nativeInt) {
     32             this.nativeInt = nativeInt;
     33         }
     34         final int nativeInt;
     35     }
     36 
     37     /** This xfermode draws, or doesn't draw, based on the destination's
     38      * distance from an op-color.
     39      *
     40      * There are two modes, and each mode interprets a tolerance value.
     41      *
     42      * Avoid: In this mode, drawing is allowed only on destination pixels that
     43      * are different from the op-color.
     44      * Tolerance near 0: avoid any colors even remotely similar to the op-color
     45      * Tolerance near 255: avoid only colors nearly identical to the op-color
     46 
     47      * Target: In this mode, drawing only occurs on destination pixels that
     48      * are similar to the op-color
     49      * Tolerance near 0: draw only on colors that are nearly identical to the op-color
     50      * Tolerance near 255: draw on any colors even remotely similar to the op-color
     51      */
     52     public AvoidXfermode(int opColor, int tolerance, Mode mode) {
     53         if (tolerance < 0 || tolerance > 255) {
     54             throw new IllegalArgumentException("tolerance must be 0..255");
     55         }
     56         native_instance = nativeCreate(opColor, tolerance, mode.nativeInt);
     57     }
     58 
     59     private static native int nativeCreate(int opColor, int tolerance,
     60                                            int nativeMode);
     61 }
     62