OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SKIA_EXT_CONVOLVER_H_ | 5 #ifndef SKIA_EXT_CONVOLVER_H_ |
6 #define SKIA_EXT_CONVOLVER_H_ | 6 #define SKIA_EXT_CONVOLVER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 // avoid confusion with Mac OS X's math library (Carbon) | 11 // avoid confusion with Mac OS X's math library (Carbon) |
12 #if defined(__APPLE__) | 12 #if defined(__APPLE__) |
13 #undef FloatToFixed | 13 #undef FloatToFixed |
14 #endif | 14 #endif |
15 | 15 |
16 namespace skia { | 16 namespace skia { |
17 | 17 |
18 // Represents a filter in one dimension. Each output pixel has one entry in this | 18 // Represents a filter in one dimension. Each output pixel has one entry in this |
19 // object for the filter values contributing to it. You build up the filter | 19 // object for the filter values contributing to it. You build up the filter |
20 // list by calling AddFilter for each output pixel (in order). | 20 // list by calling AddFilter for each output pixel (in order). |
21 // | 21 // |
22 // We do 2-dimensional convolution by first convolving each row by one | 22 // We do 2-dimensional convolution by first convolving each row by one |
23 // ConvolutionFilter1D, then convolving each column by another one. | 23 // ConvolutionFilter1D, then convolving each column by another one. |
24 // | 24 // |
25 // Entries are stored in fixed point, shifted left by kShiftBits. | 25 // Entries are stored in fixed point, shifted left by kShiftBits. |
26 class ConvolutionFilter1D { | 26 class ConvolutionFilter1D { |
27 public: | 27 public: |
| 28 typedef short Fixed; |
| 29 |
28 // The number of bits that fixed point values are shifted by. | 30 // The number of bits that fixed point values are shifted by. |
29 enum { kShiftBits = 14 }; | 31 enum { kShiftBits = 14 }; |
30 | 32 |
31 typedef short Fixed; | |
32 | |
33 ConvolutionFilter1D(); | 33 ConvolutionFilter1D(); |
34 ~ConvolutionFilter1D(); | 34 ~ConvolutionFilter1D(); |
35 | 35 |
36 // Convert between floating point and our fixed point representation. | 36 // Convert between floating point and our fixed point representation. |
37 static Fixed FloatToFixed(float f) { | 37 static Fixed FloatToFixed(float f) { |
38 return static_cast<Fixed>(f * (1 << kShiftBits)); | 38 return static_cast<Fixed>(f * (1 << kShiftBits)); |
39 } | 39 } |
40 static unsigned char FixedToChar(Fixed x) { | 40 static unsigned char FixedToChar(Fixed x) { |
41 return static_cast<unsigned char>(x >> kShiftBits); | 41 return static_cast<unsigned char>(x >> kShiftBits); |
42 } | 42 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 int source_byte_row_stride, | 129 int source_byte_row_stride, |
130 bool source_has_alpha, | 130 bool source_has_alpha, |
131 const ConvolutionFilter1D& xfilter, | 131 const ConvolutionFilter1D& xfilter, |
132 const ConvolutionFilter1D& yfilter, | 132 const ConvolutionFilter1D& yfilter, |
133 unsigned char* output); | 133 unsigned char* output); |
134 | 134 |
135 } // namespace skia | 135 } // namespace skia |
136 | 136 |
137 #endif // SKIA_EXT_CONVOLVER_H_ | 137 #endif // SKIA_EXT_CONVOLVER_H_ |
138 | 138 |
OLD | NEW |