blob: e2472d7d863cf349d13e782b96e23398cff9f66e [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com3f2025f2009-10-29 17:37:56 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2006 The Android Open Source Project
reed@android.com3f2025f2009-10-29 17:37:56 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com3f2025f2009-10-29 17:37:56 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com3f2025f2009-10-29 17:37:56 +000010#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 */
21class SkTableMaskFilter : public SkMaskFilter {
22public:
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.comba28d032012-03-26 17:57:35 +000054 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTableMaskFilter)
reed@android.com3f2025f2009-10-29 17:37:56 +000055
56protected:
57 SkTableMaskFilter(SkFlattenableReadBuffer& rb);
djsollen@google.com54924242012-03-29 15:18:04 +000058 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
reed@android.com3f2025f2009-10-29 17:37:56 +000059
60private:
61 uint8_t fTable[256];
62
63 typedef SkMaskFilter INHERITED;
64};
65
66#endif
67