• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkAvoidXfermode_DEFINED
9 #define SkAvoidXfermode_DEFINED
10 
11 #include "SkXfermode.h"
12 
13 /** \class SkAvoidXfermode
14 
15     This xfermode will draw the src everywhere except on top of the specified
16     color.
17 */
18 class SK_API SkAvoidXfermode : public SkXfermode {
19 public:
20     enum Mode {
21         kAvoidColor_Mode,   //!< draw everywhere except on the opColor
22         kTargetColor_Mode   //!< draw only on top of the opColor
23     };
24 
25     /** This xfermode draws, or doesn't draw, based on the destination's
26         distance from an op-color.
27 
28         There are two modes, and each mode interprets a tolerance value.
29 
30         Avoid: In this mode, drawing is allowed only on destination pixels that
31                are different from the op-color.
32                Tolerance near 0: avoid any colors even remotely similar to the op-color
33                Tolerance near 255: avoid only colors nearly identical to the op-color
34 
35         Target: In this mode, drawing only occurs on destination pixels that
36                 are similar to the op-color
37                 Tolerance near 0: draw only on colors that are nearly identical to the op-color
38                 Tolerance near 255: draw on any colors even remotely similar to the op-color
39      */
Create(SkColor opColor,U8CPU tolerance,Mode mode)40     static SkAvoidXfermode* Create(SkColor opColor, U8CPU tolerance, Mode mode) {
41         return SkNEW_ARGS(SkAvoidXfermode, (opColor, tolerance, mode));
42     }
43 
44     // overrides from SkXfermode
45     virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
46                         const SkAlpha aa[]) const SK_OVERRIDE;
47     virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
48                         const SkAlpha aa[]) const SK_OVERRIDE;
49     virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
50                         const SkAlpha aa[]) const SK_OVERRIDE;
51 
52     SK_TO_STRING_OVERRIDE()
53     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAvoidXfermode)
54 
55 protected:
56     SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode);
57     explicit SkAvoidXfermode(SkReadBuffer&);
58     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
59 
60 private:
61     SkColor     fOpColor;
62     uint32_t    fDistMul;   // x.14
63     Mode        fMode;
64 
65     typedef SkXfermode INHERITED;
66 };
67 
68 #endif
69