SkTableMaskFilter.h revision fbfcd5602128ec010c82cb733c9cdc0a3254f9f3
1
2/*
3 * Copyright 2006 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
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 */
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    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTableMaskFilter)
55
56protected:
57    SkTableMaskFilter(SkFlattenableReadBuffer& rb);
58    virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
59
60private:
61    uint8_t fTable[256];
62
63    typedef SkMaskFilter INHERITED;
64};
65
66#endif
67
68