epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +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 | 3f2025f | 2009-10-29 17:37:56 +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 | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 10 | #ifndef SkTableMaskFilter_DEFINED |
| 11 | #define SkTableMaskFilter_DEFINED |
| 12 | |
| 13 | #include "SkMaskFilter.h" |
| 14 | #include "SkScalar.h" |
| 15 | |
| 16 | /** \class SkTableMaskFilter |
| 17 | |
| 18 | Applies a table lookup on each of the alpha values in the mask. |
| 19 | Helper methods create some common tables (e.g. gamma, clipping) |
| 20 | */ |
| 21 | class SkTableMaskFilter : public SkMaskFilter { |
| 22 | public: |
| 23 | SkTableMaskFilter(); |
| 24 | SkTableMaskFilter(const uint8_t table[256]); |
| 25 | virtual ~SkTableMaskFilter(); |
| 26 | |
| 27 | void setTable(const uint8_t table[256]); |
| 28 | |
| 29 | /** Utility that sets the gamma table |
| 30 | */ |
| 31 | static void MakeGammaTable(uint8_t table[256], SkScalar gamma); |
| 32 | |
| 33 | /** Utility that creates a clipping table: clamps values below min to 0 |
| 34 | and above max to 255, and rescales the remaining into 0..255 |
| 35 | */ |
| 36 | static void MakeClipTable(uint8_t table[256], uint8_t min, uint8_t max); |
| 37 | |
| 38 | static SkTableMaskFilter* CreateGamma(SkScalar gamma) { |
| 39 | uint8_t table[256]; |
| 40 | MakeGammaTable(table, gamma); |
| 41 | return SkNEW_ARGS(SkTableMaskFilter, (table)); |
| 42 | } |
| 43 | |
| 44 | static SkTableMaskFilter* CreateClip(uint8_t min, uint8_t max) { |
| 45 | uint8_t table[256]; |
| 46 | MakeClipTable(table, min, max); |
| 47 | return SkNEW_ARGS(SkTableMaskFilter, (table)); |
| 48 | } |
| 49 | |
| 50 | // overrides from SkMaskFilter |
| 51 | virtual SkMask::Format getFormat(); |
| 52 | virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&, SkIPoint*); |
| 53 | |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 54 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTableMaskFilter) |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 55 | |
| 56 | protected: |
| 57 | SkTableMaskFilter(SkFlattenableReadBuffer& rb); |
djsollen@google.com | 5492424 | 2012-03-29 15:18:04 +0000 | [diff] [blame^] | 58 | virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 59 | |
| 60 | private: |
| 61 | uint8_t fTable[256]; |
| 62 | |
| 63 | typedef SkMaskFilter INHERITED; |
| 64 | }; |
| 65 | |
| 66 | #endif |
| 67 | |