SkAvoidXfermode.h revision b83b6b4f7690fe929d8d6b1a3d2b7ed562b95ba6
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*/
18class SK_API SkAvoidXfermode : public SkXfermode {
19public:
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     */
40    SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode);
41
42    // overrides from SkXfermode
43    virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
44                        const SkAlpha aa[]) const SK_OVERRIDE;
45    virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
46                        const SkAlpha aa[]) const SK_OVERRIDE;
47    virtual void xfer4444(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_DEVELOPER_TO_STRING()
53    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAvoidXfermode)
54
55protected:
56    SkAvoidXfermode(SkFlattenableReadBuffer&);
57    virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
58
59private:
60    SkColor     fOpColor;
61    uint32_t    fDistMul;   // x.14
62    Mode        fMode;
63
64    typedef SkXfermode INHERITED;
65};
66
67#endif
68