reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 8 | #ifndef SkTableMaskFilter_DEFINED |
| 9 | #define SkTableMaskFilter_DEFINED |
| 10 | |
| 11 | #include "SkMaskFilter.h" |
| 12 | #include "SkScalar.h" |
| 13 | |
| 14 | /** \class SkTableMaskFilter |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 15 | |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 16 | Applies a table lookup on each of the alpha values in the mask. |
| 17 | Helper methods create some common tables (e.g. gamma, clipping) |
| 18 | */ |
tfarina@chromium.org | 6806fe8 | 2012-10-12 14:41:39 +0000 | [diff] [blame] | 19 | class SK_API SkTableMaskFilter : public SkMaskFilter { |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 20 | public: |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 21 | virtual ~SkTableMaskFilter(); |
| 22 | |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 23 | /** Utility that sets the gamma table |
| 24 | */ |
| 25 | static void MakeGammaTable(uint8_t table[256], SkScalar gamma); |
| 26 | |
| 27 | /** Utility that creates a clipping table: clamps values below min to 0 |
| 28 | and above max to 255, and rescales the remaining into 0..255 |
| 29 | */ |
| 30 | static void MakeClipTable(uint8_t table[256], uint8_t min, uint8_t max); |
| 31 | |
commit-bot@chromium.org | 7c9d0f3 | 2014-02-21 10:13:32 +0000 | [diff] [blame^] | 32 | static SkTableMaskFilter* Create(const uint8_t table[256]) { |
| 33 | return SkNEW_ARGS(SkTableMaskFilter, (table)); |
| 34 | } |
| 35 | |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 36 | static SkTableMaskFilter* CreateGamma(SkScalar gamma) { |
| 37 | uint8_t table[256]; |
| 38 | MakeGammaTable(table, gamma); |
| 39 | return SkNEW_ARGS(SkTableMaskFilter, (table)); |
| 40 | } |
| 41 | |
| 42 | static SkTableMaskFilter* CreateClip(uint8_t min, uint8_t max) { |
| 43 | uint8_t table[256]; |
| 44 | MakeClipTable(table, min, max); |
| 45 | return SkNEW_ARGS(SkTableMaskFilter, (table)); |
| 46 | } |
| 47 | |
reed@google.com | 30711b7 | 2012-12-18 19:18:39 +0000 | [diff] [blame] | 48 | virtual SkMask::Format getFormat() const SK_OVERRIDE; |
| 49 | virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&, |
| 50 | SkIPoint*) const SK_OVERRIDE; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 51 | |
robertphillips@google.com | 0bd80fa | 2013-03-18 17:53:38 +0000 | [diff] [blame] | 52 | SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;) |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 53 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTableMaskFilter) |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 54 | |
| 55 | protected: |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 56 | SkTableMaskFilter(SkReadBuffer& rb); |
| 57 | virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 58 | |
commit-bot@chromium.org | 7c9d0f3 | 2014-02-21 10:13:32 +0000 | [diff] [blame^] | 59 | #ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS |
| 60 | public: |
| 61 | #endif |
| 62 | SkTableMaskFilter(); |
| 63 | SkTableMaskFilter(const uint8_t table[256]); |
| 64 | |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 65 | private: |
| 66 | uint8_t fTable[256]; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 67 | |
reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame] | 68 | typedef SkMaskFilter INHERITED; |
| 69 | }; |
| 70 | |
| 71 | #endif |