blob: abfd95d7d18544ca7cb95c124d953606772d1100 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2007 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +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.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkColorMatrixFilter_DEFINED
11#define SkColorMatrixFilter_DEFINED
12
13#include "SkColorFilter.h"
14#include "SkColorMatrix.h"
15
senorblanco@chromium.orgc79fd6e2012-01-10 21:56:40 +000016class SK_API SkColorMatrixFilter : public SkColorFilter {
reed@android.com8a1c16f2008-12-17 15:59:43 +000017public:
18 SkColorMatrixFilter();
19 explicit SkColorMatrixFilter(const SkColorMatrix&);
20 SkColorMatrixFilter(const SkScalar array[20]);
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000021
reed@android.com8a1c16f2008-12-17 15:59:43 +000022 void setMatrix(const SkColorMatrix&);
23 void setArray(const SkScalar array[20]);
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000024
reed@android.com8a1c16f2008-12-17 15:59:43 +000025 // overrides from SkColorFilter
mike@reedtribe.org70121622011-12-28 20:17:42 +000026 virtual void filterSpan(const SkPMColor src[], int count, SkPMColor[]) SK_OVERRIDE;
27 virtual void filterSpan16(const uint16_t src[], int count, uint16_t[]) SK_OVERRIDE;
28 virtual uint32_t getFlags() SK_OVERRIDE;
senorblanco@chromium.orge5ff3ce2011-12-20 20:58:18 +000029 virtual bool asColorMatrix(SkScalar matrix[20]) SK_OVERRIDE;
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000030
reed@android.com8a1c16f2008-12-17 15:59:43 +000031 // overrides for SkFlattenable
mike@reedtribe.org70121622011-12-28 20:17:42 +000032 virtual void flatten(SkFlattenableWriteBuffer& buffer) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000033
34 struct State {
35 int32_t fArray[20];
36 int fShift;
37 int32_t fResult[4];
38 };
39
djsollen@google.comba28d032012-03-26 17:57:35 +000040 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorMatrixFilter)
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000041
reed@android.com8a1c16f2008-12-17 15:59:43 +000042protected:
reed@android.com8a1c16f2008-12-17 15:59:43 +000043 SkColorMatrixFilter(SkFlattenableReadBuffer& buffer);
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000044
reed@android.com8a1c16f2008-12-17 15:59:43 +000045private:
reed@android.com8a1c16f2008-12-17 15:59:43 +000046
47 typedef void (*Proc)(State*, unsigned r, unsigned g, unsigned b,
48 unsigned a);
49
50 Proc fProc;
51 State fState;
52 uint32_t fFlags;
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000053
reed@android.com8a1c16f2008-12-17 15:59:43 +000054 void setup(const SkScalar array[20]);
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000055
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 typedef SkColorFilter INHERITED;
57};
58
59#endif