SkColorMatrixFilter.h revision e5ff3cefe007d092daf9d0bc2b03f9ff87b2c34e
1
2/*
3 * Copyright 2007 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 SkColorMatrixFilter_DEFINED
11#define SkColorMatrixFilter_DEFINED
12
13#include "SkColorFilter.h"
14#include "SkColorMatrix.h"
15
16class SkColorMatrixFilter : public SkColorFilter {
17public:
18    SkColorMatrixFilter();
19    explicit SkColorMatrixFilter(const SkColorMatrix&);
20    SkColorMatrixFilter(const SkScalar array[20]);
21
22    void setMatrix(const SkColorMatrix&);
23    void setArray(const SkScalar array[20]);
24
25    // overrides from SkColorFilter
26    virtual void filterSpan(const SkPMColor src[], int count, SkPMColor[]);
27    virtual void filterSpan16(const uint16_t src[], int count, uint16_t[]);
28    virtual uint32_t getFlags();
29    virtual bool asColorMatrix(SkScalar matrix[20]) SK_OVERRIDE;
30
31    // overrides for SkFlattenable
32    virtual void flatten(SkFlattenableWriteBuffer& buffer);
33
34    struct State {
35        int32_t fArray[20];
36        int     fShift;
37        int32_t fResult[4];
38    };
39
40    static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer);
41
42    SK_DECLARE_FLATTENABLE_REGISTRAR()
43
44protected:
45    // overrides for SkFlattenable
46    virtual Factory getFactory();
47
48    SkColorMatrixFilter(SkFlattenableReadBuffer& buffer);
49
50private:
51
52    typedef void (*Proc)(State*, unsigned r, unsigned g, unsigned b,
53                         unsigned a);
54
55    Proc        fProc;
56    State       fState;
57    uint32_t    fFlags;
58
59    void setup(const SkScalar array[20]);
60
61    typedef SkColorFilter INHERITED;
62};
63
64#endif
65