• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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 SkKernel33MaskFilter_DEFINED
18 #define SkKernel33MaskFilter_DEFINED
19 
20 #include "SkMaskFilter.h"
21 
22 class SkKernel33ProcMaskFilter : public SkMaskFilter {
23 public:
24     SkKernel33ProcMaskFilter(unsigned percent256 = 256)
fPercent256(percent256)25         : fPercent256(percent256) {}
26 
27     virtual uint8_t computeValue(uint8_t* const* srcRows) = 0;
28 
29     // overrides from SkMaskFilter
30     virtual SkMask::Format getFormat();
31     virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&, SkIPoint*);
32 
33     // overrides from SkFlattenable
34     virtual void flatten(SkFlattenableWriteBuffer& wb);
35 
36 protected:
37     SkKernel33ProcMaskFilter(SkFlattenableReadBuffer& rb);
38 
39 private:
40     int fPercent256;
41 
42     typedef SkMaskFilter INHERITED;
43 };
44 
45 ///////////////////////////////////////////////////////////////////////////////
46 
47 class SkKernel33MaskFilter : public SkKernel33ProcMaskFilter {
48 public:
49     SkKernel33MaskFilter(const int coeff[3][3], int shift, int percent256 = 256)
SkKernel33ProcMaskFilter(percent256)50         : SkKernel33ProcMaskFilter(percent256)
51     {
52         memcpy(fKernel, coeff, 9 * sizeof(int));
53         fShift = shift;
54     }
55 
56     // override from SkKernel33ProcMaskFilter
57     virtual uint8_t computeValue(uint8_t* const* srcRows);
58 
59     // overrides from SkFlattenable
60     virtual void flatten(SkFlattenableWriteBuffer& wb);
61     virtual Factory getFactory();
62 
63 private:
64     int fKernel[3][3];
65     int fShift;
66 
67     SkKernel33MaskFilter(SkFlattenableReadBuffer& rb);
68     static SkFlattenable* Create(SkFlattenableReadBuffer& rb);
69 
70     typedef SkKernel33ProcMaskFilter INHERITED;
71 };
72 
73 #endif
74