OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
8 #include <cmath> | 8 #include <cmath> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/cpu.h" | 12 #include "base/cpu.h" |
13 #include "third_party/skia/include/core/SkSize.h" | |
Stephen White
2013/04/10 15:20:31
I think you could forward-declare SkISize instead
motek.
2013/04/11 16:18:38
SkISize is declared:
typedef struct SkTSize<int> S
Stephen White
2013/04/11 17:16:38
Ahh, you're right. I'd forgotten it was a typedef
| |
13 #include "third_party/skia/include/core/SkTypes.h" | 14 #include "third_party/skia/include/core/SkTypes.h" |
14 | 15 |
15 #if defined(ARCH_CPU_X86_FAMILY) | 16 #if defined(ARCH_CPU_X86_FAMILY) |
16 #if defined(__x86_64__) || defined(_M_X64) || defined(__SSE2__) || _M_IX86_FP==2 | 17 #if defined(__x86_64__) || defined(_M_X64) || defined(__SSE2__) || _M_IX86_FP==2 |
17 // This is where we had compiler support for SSE2 instructions. | 18 // This is where we had compiler support for SSE2 instructions. |
18 // FIXME: Known buggy, so disabling for M22. | 19 // FIXME: Known buggy, so disabling for M22. |
19 // #define SIMD_SSE2 1 | 20 // #define SIMD_SSE2 1 |
20 #endif | 21 #endif |
21 #endif | 22 #endif |
22 | 23 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 int* filter_length) const { | 101 int* filter_length) const { |
101 const FilterInstance& filter = filters_[value_offset]; | 102 const FilterInstance& filter = filters_[value_offset]; |
102 *filter_offset = filter.offset; | 103 *filter_offset = filter.offset; |
103 *filter_length = filter.length; | 104 *filter_length = filter.length; |
104 if (filter.length == 0) { | 105 if (filter.length == 0) { |
105 return NULL; | 106 return NULL; |
106 } | 107 } |
107 return &filter_values_[filter.data_location]; | 108 return &filter_values_[filter.data_location]; |
108 } | 109 } |
109 | 110 |
111 // Retrieves the filter for the offset 0, presumed to be the one and only. | |
112 // The offset and length of the filter values are put into the corresponding | |
113 // out arguments (see AddFilter). Note that |filter_legth| and | |
114 // |specified_filter_size| may be different if leading/trailing zeros of the | |
Stephen White
2013/04/10 15:20:31
Maybe this comment should be on the declaration fo
motek.
2013/04/11 16:18:38
Added it there.
| |
115 // original floating point form were clipped. | |
116 // There will be |filter_length| values in the return array. | |
reed1
2013/04/09 15:43:18
Do you want to comment that this can return NULL (
motek.
2013/04/11 16:18:38
Done.
| |
117 inline const Fixed* GetSingleFilter(int* specified_filter_size, | |
Stephen White
2013/04/10 15:20:31
Nit: prefer out-of-line here unless performance i
motek.
2013/04/11 16:18:38
The original is processed in a loop, so I assume t
| |
118 int* filter_offset, | |
119 int* filter_length) const { | |
120 const FilterInstance& filter = filters_[0]; | |
121 *filter_offset = filter.offset; | |
122 *filter_length = filter.length; | |
123 *specified_filter_size = filter.filter_size; | |
124 if (filter.length == 0) { | |
125 return NULL; | |
126 } | |
127 return &filter_values_[filter.data_location]; | |
128 } | |
129 | |
110 | 130 |
111 inline void PaddingForSIMD(int padding_count) { | 131 inline void PaddingForSIMD(int padding_count) { |
112 // Padding |padding_count| of more dummy coefficients after the coefficients | 132 // Padding |padding_count| of more dummy coefficients after the coefficients |
113 // of last filter to prevent SIMD instructions which load 8 or 16 bytes | 133 // of last filter to prevent SIMD instructions which load 8 or 16 bytes |
114 // together to access invalid memory areas. We are not trying to align the | 134 // together to access invalid memory areas. We are not trying to align the |
115 // coefficients right now due to the opaqueness of <vector> implementation. | 135 // coefficients right now due to the opaqueness of <vector> implementation. |
116 // This has to be done after all |AddFilter| calls. | 136 // This has to be done after all |AddFilter| calls. |
117 for (int i = 0; i < padding_count; ++i) | 137 for (int i = 0; i < padding_count; ++i) |
118 filter_values_.push_back(static_cast<Fixed>(0)); | 138 filter_values_.push_back(static_cast<Fixed>(0)); |
119 } | 139 } |
120 | 140 |
121 private: | 141 private: |
122 struct FilterInstance { | 142 struct FilterInstance { |
123 // Offset within filter_values for this instance of the filter. | 143 // Offset within filter_values for this instance of the filter. |
124 int data_location; | 144 int data_location; |
125 | 145 |
126 // Distance from the left of the filter to the center. IN PIXELS | 146 // Distance from the left of the filter to the center. IN PIXELS |
127 int offset; | 147 int offset; |
128 | 148 |
129 // Number of values in this filter instance. | 149 // Number of values in this filter instance. |
130 int length; | 150 int length; |
151 | |
152 // Given filter size. | |
153 int filter_size; | |
Stephen White
2013/04/10 15:20:31
A bit confusing.. maybe filter_size -> length, and
motek.
2013/04/11 16:18:38
Done.
| |
131 }; | 154 }; |
132 | 155 |
133 // Stores the information for each filter added to this class. | 156 // Stores the information for each filter added to this class. |
134 std::vector<FilterInstance> filters_; | 157 std::vector<FilterInstance> filters_; |
135 | 158 |
136 // We store all the filter values in this flat list, indexed by | 159 // We store all the filter values in this flat list, indexed by |
137 // |FilterInstance.data_location| to avoid the mallocs required for storing | 160 // |FilterInstance.data_location| to avoid the mallocs required for storing |
138 // each one separately. | 161 // each one separately. |
139 std::vector<Fixed> filter_values_; | 162 std::vector<Fixed> filter_values_; |
140 | 163 |
(...skipping 20 matching lines...) Expand all Loading... | |
161 // The layout in memory is assumed to be 4-bytes per pixel in B-G-R-A order | 184 // The layout in memory is assumed to be 4-bytes per pixel in B-G-R-A order |
162 // (this is ARGB when loaded into 32-bit words on a little-endian machine). | 185 // (this is ARGB when loaded into 32-bit words on a little-endian machine). |
163 SK_API void BGRAConvolve2D(const unsigned char* source_data, | 186 SK_API void BGRAConvolve2D(const unsigned char* source_data, |
164 int source_byte_row_stride, | 187 int source_byte_row_stride, |
165 bool source_has_alpha, | 188 bool source_has_alpha, |
166 const ConvolutionFilter1D& xfilter, | 189 const ConvolutionFilter1D& xfilter, |
167 const ConvolutionFilter1D& yfilter, | 190 const ConvolutionFilter1D& yfilter, |
168 int output_byte_row_stride, | 191 int output_byte_row_stride, |
169 unsigned char* output, | 192 unsigned char* output, |
170 bool use_sse2); | 193 bool use_sse2); |
194 | |
195 // Does a 1D convolution of the given source image along the X dimension on | |
196 // a single channel of the bitmap. | |
197 // | |
198 // The function uses the same convolution kernel for each pixel. That kernel | |
199 // must be added to |filter| at offset 0. This is a most straightforward | |
200 // implementation of convolution, intended chiefly for development purposes. | |
201 SK_API void SingleChannelConvolve1D_X(const unsigned char* source_data, | |
Stephen White
2013/04/10 15:20:31
Style guide says no underscores in function names,
motek.
2013/04/11 16:18:38
Renamed as suggested.
As for the other suggestio
| |
202 int source_byte_row_stride, | |
203 int input_channel_index, | |
204 int input_channel_count, | |
205 const ConvolutionFilter1D& filter, | |
206 const SkISize& image_size, | |
207 unsigned char* output, | |
208 int output_byte_row_stride, | |
209 int output_channel_index, | |
210 int output_channel_count, | |
211 bool absolute_values); | |
212 | |
213 // Does a 1D convolution of the given source image along the Y dimension on | |
214 // a single channel of the bitmap. | |
215 SK_API void SingleChannelConvolve1D_Y(const unsigned char* source_data, | |
216 int source_byte_row_stride, | |
217 int input_channel_index, | |
218 int input_channel_count, | |
219 const ConvolutionFilter1D& filter, | |
220 const SkISize& image_size, | |
221 unsigned char* output, | |
222 int output_byte_row_stride, | |
223 int output_channel_index, | |
224 int output_channel_count, | |
225 bool absolute_values); | |
226 | |
171 } // namespace skia | 227 } // namespace skia |
172 | 228 |
173 #endif // SKIA_EXT_CONVOLVER_H_ | 229 #endif // SKIA_EXT_CONVOLVER_H_ |
OLD | NEW |