epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #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 | */ |
| 20 | class SkAvoidXfermode : public SkXfermode { |
| 21 | public: |
| 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.com | 0db5a7f | 2009-11-09 16:01:36 +0000 | [diff] [blame] | 27 | /** This xfermode draws, or doesn't draw, based on the destination's |
| 28 | distance from an op-color. |
tomhudson@google.com | 1447c6f | 2011-04-27 14:09:52 +0000 | [diff] [blame] | 29 | |
reed@android.com | 0db5a7f | 2009-11-09 16:01:36 +0000 | [diff] [blame] | 30 | There are two modes, and each mode interprets a tolerance value. |
tomhudson@google.com | 1447c6f | 2011-04-27 14:09:52 +0000 | [diff] [blame] | 31 | |
reed@android.com | 0db5a7f | 2009-11-09 16:01:36 +0000 | [diff] [blame] | 32 | Avoid: In this mode, drawing is allowed only on destination pixels that |
| 33 | are different from the op-color. |
reed@android.com | 81dc331 | 2010-02-18 19:32:03 +0000 | [diff] [blame] | 34 | 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.com | 1447c6f | 2011-04-27 14:09:52 +0000 | [diff] [blame] | 36 | |
reed@android.com | 0db5a7f | 2009-11-09 16:01:36 +0000 | [diff] [blame] | 37 | Target: In this mode, drawing only occurs on destination pixels that |
| 38 | are similar to the op-color |
reed@android.com | 81dc331 | 2010-02-18 19:32:03 +0000 | [diff] [blame] | 39 | 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.com | 0db5a7f | 2009-11-09 16:01:36 +0000 | [diff] [blame] | 41 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 42 | 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.org | 259210c | 2011-11-23 02:08:50 +0000 | [diff] [blame] | 46 | const SkAlpha aa[]) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 47 | virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count, |
mike@reedtribe.org | 259210c | 2011-11-23 02:08:50 +0000 | [diff] [blame] | 48 | const SkAlpha aa[]) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 49 | virtual void xfer4444(uint16_t dst[], const SkPMColor src[], int count, |
mike@reedtribe.org | 259210c | 2011-11-23 02:08:50 +0000 | [diff] [blame] | 50 | const SkAlpha aa[]) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count, |
mike@reedtribe.org | 259210c | 2011-11-23 02:08:50 +0000 | [diff] [blame] | 52 | const SkAlpha aa[]) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 53 | |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 54 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAvoidXfermode) |
tomhudson@google.com | 1447c6f | 2011-04-27 14:09:52 +0000 | [diff] [blame] | 55 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 56 | protected: |
| 57 | SkAvoidXfermode(SkFlattenableReadBuffer&); |
djsollen@google.com | 5492424 | 2012-03-29 15:18:04 +0000 | [diff] [blame^] | 58 | virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 59 | |
| 60 | private: |
| 61 | SkColor fOpColor; |
| 62 | uint32_t fDistMul; // x.14 |
| 63 | Mode fMode; |
tomhudson@google.com | 1447c6f | 2011-04-27 14:09:52 +0000 | [diff] [blame] | 64 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 65 | typedef SkXfermode INHERITED; |
| 66 | }; |
| 67 | |
| 68 | #endif |