blob: 63b32b2bd348aeea18303b7a7a87381345448b37 [file] [log] [blame]
reed@android.com3f2025f2009-10-29 17:37:56 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com3f2025f2009-10-29 17:37:56 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com3f2025f2009-10-29 17:37:56 +00006 */
7
reed@android.com3f2025f2009-10-29 17:37:56 +00008#ifndef SkTableMaskFilter_DEFINED
9#define SkTableMaskFilter_DEFINED
10
11#include "SkMaskFilter.h"
12#include "SkScalar.h"
13
14/** \class SkTableMaskFilter
rmistry@google.comfbfcd562012-08-23 18:09:54 +000015
reed@android.com3f2025f2009-10-29 17:37:56 +000016 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.org6806fe82012-10-12 14:41:39 +000019class SK_API SkTableMaskFilter : public SkMaskFilter {
reed@android.com3f2025f2009-10-29 17:37:56 +000020public:
reed@android.com3f2025f2009-10-29 17:37:56 +000021 virtual ~SkTableMaskFilter();
22
reed@android.com3f2025f2009-10-29 17:37:56 +000023 /** 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.org7c9d0f32014-02-21 10:13:32 +000032 static SkTableMaskFilter* Create(const uint8_t table[256]) {
33 return SkNEW_ARGS(SkTableMaskFilter, (table));
34 }
35
reed@android.com3f2025f2009-10-29 17:37:56 +000036 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.com30711b72012-12-18 19:18:39 +000048 virtual SkMask::Format getFormat() const SK_OVERRIDE;
49 virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&,
50 SkIPoint*) const SK_OVERRIDE;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000051
robertphillips@google.com0bd80fa2013-03-18 17:53:38 +000052 SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
djsollen@google.comba28d032012-03-26 17:57:35 +000053 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTableMaskFilter)
reed@android.com3f2025f2009-10-29 17:37:56 +000054
55protected:
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000056 SkTableMaskFilter(SkReadBuffer& rb);
57 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
reed@android.com3f2025f2009-10-29 17:37:56 +000058
commit-bot@chromium.org7c9d0f32014-02-21 10:13:32 +000059#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
60public:
61#endif
62 SkTableMaskFilter();
63 SkTableMaskFilter(const uint8_t table[256]);
64
reed@android.com3f2025f2009-10-29 17:37:56 +000065private:
66 uint8_t fTable[256];
rmistry@google.comfbfcd562012-08-23 18:09:54 +000067
reed@android.com3f2025f2009-10-29 17:37:56 +000068 typedef SkMaskFilter INHERITED;
69};
70
71#endif