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 | |
| 34 | /** This xfermode will draw the src everywhere except on top of the opColor |
| 35 | or, depending on the Mode, draw only on top of the opColor. |
| 36 | @param opColor the color to avoid (or to target depending on Mode). |
| 37 | note: the alpha in opColor is ignored |
| 38 | @param tolerance How closely we compare a pixel to the opColor. |
| 39 | 0 - only operate if exact match |
| 40 | 255 - maximum gradation (blending) based on how |
| 41 | similar the pixel is to our opColor (max tolerance) |
| 42 | @param mode If we should avoid or target the opColor |
| 43 | */ |
| 44 | SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode); |
| 45 | |
| 46 | // overrides from SkXfermode |
| 47 | virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count, |
| 48 | const SkAlpha aa[]); |
| 49 | virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count, |
| 50 | const SkAlpha aa[]); |
| 51 | virtual void xfer4444(uint16_t dst[], const SkPMColor src[], int count, |
| 52 | const SkAlpha aa[]); |
| 53 | virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count, |
| 54 | const SkAlpha aa[]); |
| 55 | |
| 56 | // overrides from SkFlattenable |
| 57 | virtual Factory getFactory(); |
| 58 | virtual void flatten(SkFlattenableWriteBuffer&); |
| 59 | |
| 60 | protected: |
| 61 | SkAvoidXfermode(SkFlattenableReadBuffer&); |
| 62 | |
| 63 | private: |
| 64 | SkColor fOpColor; |
| 65 | uint32_t fDistMul; // x.14 |
| 66 | Mode fMode; |
| 67 | |
| 68 | static SkFlattenable* Create(SkFlattenableReadBuffer&); |
| 69 | |
| 70 | typedef SkXfermode INHERITED; |
| 71 | }; |
| 72 | |
| 73 | #endif |