blob: f213de773ce58937f60e2444f7193c29e74d4bbf [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
54 // overrides from SkFlattenable
55 virtual void flatten(SkFlattenableWriteBuffer& wb);
56 virtual Factory getFactory();
57
58protected:
59 SkTableMaskFilter(SkFlattenableReadBuffer& rb);
60 static SkFlattenable* Factory(SkFlattenableReadBuffer&);
61
62private:
63 uint8_t fTable[256];
64
65 typedef SkMaskFilter INHERITED;
66};
67
68#endif
69