blob: 298ce5b1b79c0f55382fc1fe49670bf009714540 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkAvoidXfermode_DEFINED
11#define SkAvoidXfermode_DEFINED
12
13#include "SkXfermode.h"
14
15/** \class SkAvoidXfermode
16
17 This xfermode will draw the src everywhere except on top of the specified
18 color.
19*/
20class SkAvoidXfermode : public SkXfermode {
21public:
22 enum Mode {
23 kAvoidColor_Mode, //!< draw everywhere except on the opColor
24 kTargetColor_Mode //!< draw only on top of the opColor
25 };
26
reed@android.com0db5a7f2009-11-09 16:01:36 +000027 /** This xfermode draws, or doesn't draw, based on the destination's
28 distance from an op-color.
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000029
reed@android.com0db5a7f2009-11-09 16:01:36 +000030 There are two modes, and each mode interprets a tolerance value.
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000031
reed@android.com0db5a7f2009-11-09 16:01:36 +000032 Avoid: In this mode, drawing is allowed only on destination pixels that
33 are different from the op-color.
reed@android.com81dc3312010-02-18 19:32:03 +000034 Tolerance near 0: avoid any colors even remotely similar to the op-color
35 Tolerance near 255: avoid only colors nearly identical to the op-color
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000036
reed@android.com0db5a7f2009-11-09 16:01:36 +000037 Target: In this mode, drawing only occurs on destination pixels that
38 are similar to the op-color
reed@android.com81dc3312010-02-18 19:32:03 +000039 Tolerance near 0: draw only on colors that are nearly identical to the op-color
40 Tolerance near 255: draw on any colors even remotely similar to the op-color
reed@android.com0db5a7f2009-11-09 16:01:36 +000041 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000042 SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode);
43
44 // overrides from SkXfermode
45 virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
mike@reedtribe.org259210c2011-11-23 02:08:50 +000046 const SkAlpha aa[]) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000047 virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
mike@reedtribe.org259210c2011-11-23 02:08:50 +000048 const SkAlpha aa[]) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000049 virtual void xfer4444(uint16_t dst[], const SkPMColor src[], int count,
mike@reedtribe.org259210c2011-11-23 02:08:50 +000050 const SkAlpha aa[]) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000051 virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
mike@reedtribe.org259210c2011-11-23 02:08:50 +000052 const SkAlpha aa[]) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000053
djsollen@google.comba28d032012-03-26 17:57:35 +000054 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAvoidXfermode)
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000055
reed@android.com8a1c16f2008-12-17 15:59:43 +000056protected:
57 SkAvoidXfermode(SkFlattenableReadBuffer&);
djsollen@google.com54924242012-03-29 15:18:04 +000058 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000059
60private:
61 SkColor fOpColor;
62 uint32_t fDistMul; // x.14
63 Mode fMode;
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000064
reed@android.com8a1c16f2008-12-17 15:59:43 +000065 typedef SkXfermode INHERITED;
66};
67
68#endif