michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkAvoidXfermode_DEFINED michael@0: #define SkAvoidXfermode_DEFINED michael@0: michael@0: #include "SkXfermode.h" michael@0: michael@0: /** \class SkAvoidXfermode michael@0: michael@0: This xfermode will draw the src everywhere except on top of the specified michael@0: color. michael@0: */ michael@0: class SK_API SkAvoidXfermode : public SkXfermode { michael@0: public: michael@0: enum Mode { michael@0: kAvoidColor_Mode, //!< draw everywhere except on the opColor michael@0: kTargetColor_Mode //!< draw only on top of the opColor michael@0: }; michael@0: michael@0: /** This xfermode draws, or doesn't draw, based on the destination's michael@0: distance from an op-color. michael@0: michael@0: There are two modes, and each mode interprets a tolerance value. michael@0: michael@0: Avoid: In this mode, drawing is allowed only on destination pixels that michael@0: are different from the op-color. michael@0: Tolerance near 0: avoid any colors even remotely similar to the op-color michael@0: Tolerance near 255: avoid only colors nearly identical to the op-color michael@0: michael@0: Target: In this mode, drawing only occurs on destination pixels that michael@0: are similar to the op-color michael@0: Tolerance near 0: draw only on colors that are nearly identical to the op-color michael@0: Tolerance near 255: draw on any colors even remotely similar to the op-color michael@0: */ michael@0: static SkAvoidXfermode* Create(SkColor opColor, U8CPU tolerance, Mode mode) { michael@0: return SkNEW_ARGS(SkAvoidXfermode, (opColor, tolerance, mode)); michael@0: } michael@0: michael@0: // overrides from SkXfermode michael@0: virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count, michael@0: const SkAlpha aa[]) const SK_OVERRIDE; michael@0: virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count, michael@0: const SkAlpha aa[]) const SK_OVERRIDE; michael@0: virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count, michael@0: const SkAlpha aa[]) const SK_OVERRIDE; michael@0: michael@0: SK_TO_STRING_OVERRIDE() michael@0: SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAvoidXfermode) michael@0: michael@0: protected: michael@0: SkAvoidXfermode(SkReadBuffer&); michael@0: virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; michael@0: michael@0: #ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS michael@0: public: michael@0: #endif michael@0: SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode); michael@0: michael@0: private: michael@0: SkColor fOpColor; michael@0: uint32_t fDistMul; // x.14 michael@0: Mode fMode; michael@0: michael@0: typedef SkXfermode INHERITED; michael@0: }; michael@0: michael@0: #endif