1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkColorMatrixFilter_DEFINED
18#define SkColorMatrixFilter_DEFINED
19
20#include "SkColorFilter.h"
21#include "SkColorMatrix.h"
22
23class SkColorMatrixFilter : public SkColorFilter {
24public:
25    SkColorMatrixFilter();
26    explicit SkColorMatrixFilter(const SkColorMatrix&);
27    SkColorMatrixFilter(const SkScalar array[20]);
28
29    void setMatrix(const SkColorMatrix&);
30    void setArray(const SkScalar array[20]);
31
32    // overrides from SkColorFilter
33    virtual void filterSpan(const SkPMColor src[], int count, SkPMColor[]);
34    virtual void filterSpan16(const uint16_t src[], int count, uint16_t[]);
35    virtual uint32_t getFlags();
36
37    // overrides for SkFlattenable
38    virtual void flatten(SkFlattenableWriteBuffer& buffer);
39
40    struct State {
41        int32_t fArray[20];
42        int     fShift;
43        int32_t fResult[4];
44    };
45
46    static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer);
47
48protected:
49    // overrides for SkFlattenable
50    virtual Factory getFactory();
51
52    SkColorMatrixFilter(SkFlattenableReadBuffer& buffer);
53
54private:
55
56    typedef void (*Proc)(State*, unsigned r, unsigned g, unsigned b,
57                         unsigned a);
58
59    Proc        fProc;
60    State       fState;
61    uint32_t    fFlags;
62
63    void setup(const SkScalar array[20]);
64
65    typedef SkColorFilter INHERITED;
66};
67
68#endif
69