reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 27 | class SkAvoidXfermode : public SkXfermode { |
| 28 | public: |
| 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.com | 0db5a7f | 2009-11-09 16:01:36 +0000 | [diff] [blame^] | 34 | /** 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. |
| 41 | Tolerance near 0: avoid anything close to the op-color |
| 42 | Tolerance near 255: avoid only colors very close to the op-color |
| 43 | |
| 44 | Target: In this mode, drawing only occurs on destination pixels that |
| 45 | are similar to the op-color |
| 46 | Tolerance near 0: draw on colors that are very close to op-color |
| 47 | Tolerance near 255: draw on colors that to the op-color |
| 48 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 49 | 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 | |
| 65 | protected: |
| 66 | SkAvoidXfermode(SkFlattenableReadBuffer&); |
| 67 | |
| 68 | private: |
| 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 |