blob: 9af4a4b58e2b2c491d37cf13b74274fe8733218d [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
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#ifndef SkAvoidXfermode_DEFINED
18#define SkAvoidXfermode_DEFINED
19
20#include "SkXfermode.h"
21
22/** \class SkAvoidXfermode
23
24 This xfermode will draw the src everywhere except on top of the specified
25 color.
26*/
27class SkAvoidXfermode : public SkXfermode {
28public:
29 enum Mode {
30 kAvoidColor_Mode, //!< draw everywhere except on the opColor
31 kTargetColor_Mode //!< draw only on top of the opColor
32 };
33
reed@android.com0db5a7f2009-11-09 16:01:36 +000034 /** This xfermode draws, or doesn't draw, based on the destination's
35 distance from an op-color.
36
37 There are two modes, and each mode interprets a tolerance value.
38
39 Avoid: In this mode, drawing is allowed only on destination pixels that
40 are different from the op-color.
reed@android.com81dc3312010-02-18 19:32:03 +000041 Tolerance near 0: avoid any colors even remotely similar to the op-color
42 Tolerance near 255: avoid only colors nearly identical to the op-color
reed@android.com0db5a7f2009-11-09 16:01:36 +000043
44 Target: In this mode, drawing only occurs on destination pixels that
45 are similar to the op-color
reed@android.com81dc3312010-02-18 19:32:03 +000046 Tolerance near 0: draw only on colors that are nearly identical to the op-color
47 Tolerance near 255: draw on any colors even remotely similar to the op-color
reed@android.com0db5a7f2009-11-09 16:01:36 +000048 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000049 SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode);
50
51 // overrides from SkXfermode
52 virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
53 const SkAlpha aa[]);
54 virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
55 const SkAlpha aa[]);
56 virtual void xfer4444(uint16_t dst[], const SkPMColor src[], int count,
57 const SkAlpha aa[]);
58 virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
59 const SkAlpha aa[]);
60
61 // overrides from SkFlattenable
62 virtual Factory getFactory();
63 virtual void flatten(SkFlattenableWriteBuffer&);
64
65protected:
66 SkAvoidXfermode(SkFlattenableReadBuffer&);
67
68private:
69 SkColor fOpColor;
70 uint32_t fDistMul; // x.14
71 Mode fMode;
72
73 static SkFlattenable* Create(SkFlattenableReadBuffer&);
74
75 typedef SkXfermode INHERITED;
76};
77
78#endif