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 SK_CONVOLVER_H | 5 #ifndef SK_CONVOLVER_H |
6 #define SK_CONVOLVER_H | 6 #define SK_CONVOLVER_H |
7 | 7 |
8 #include "SkSize.h" | 8 #include "SkSize.h" |
9 #include "SkTypes.h" | 9 #include "SkTDArray.h" |
10 #include "SkTArray.h" | |
11 | 10 |
12 // avoid confusion with Mac OS X's math library (Carbon) | 11 // avoid confusion with Mac OS X's math library (Carbon) |
13 #if defined(__APPLE__) | 12 #if defined(__APPLE__) |
14 #undef FloatToConvolutionFixed | 13 #undef FloatToConvolutionFixed |
15 #undef ConvolutionFixedToFloat | 14 #undef ConvolutionFixedToFloat |
16 #undef FloatToFixed | 15 #undef FloatToFixed |
17 #undef FixedToFloat | 16 #undef FixedToFloat |
18 #endif | 17 #endif |
19 | 18 |
20 // Represents a filter in one dimension. Each output pixel has one entry in this | 19 // Represents a filter in one dimension. Each output pixel has one entry in this |
(...skipping 30 matching lines...) Expand all Loading... |
51 return ldexpf(raw, -kShiftBits); | 50 return ldexpf(raw, -kShiftBits); |
52 } | 51 } |
53 | 52 |
54 // Returns the maximum pixel span of a filter. | 53 // Returns the maximum pixel span of a filter. |
55 int maxFilter() const { return fMaxFilter; } | 54 int maxFilter() const { return fMaxFilter; } |
56 | 55 |
57 // Returns the number of filters in this filter. This is the dimension of th
e | 56 // Returns the number of filters in this filter. This is the dimension of th
e |
58 // output image. | 57 // output image. |
59 int numValues() const { return static_cast<int>(fFilters.count()); } | 58 int numValues() const { return static_cast<int>(fFilters.count()); } |
60 | 59 |
| 60 void reserveAdditional(int filterCount, int filterValueCount) { |
| 61 fFilters.setReserve(fFilters.count() + filterCount); |
| 62 fFilterValues.setReserve(fFilterValues.count() + filterValueCount); |
| 63 } |
| 64 |
61 // Appends the given list of scaling values for generating a given output | 65 // Appends the given list of scaling values for generating a given output |
62 // pixel. |filterOffset| is the distance from the edge of the image to where | 66 // pixel. |filterOffset| is the distance from the edge of the image to where |
63 // the scaling factors start. The scaling factors apply to the source pixels | 67 // the scaling factors start. The scaling factors apply to the source pixels |
64 // starting from this position, and going for the next |filterLength| pixels
. | 68 // starting from this position, and going for the next |filterLength| pixels
. |
65 // | 69 // |
66 // You will probably want to make sure your input is normalized (that is, | 70 // You will probably want to make sure your input is normalized (that is, |
67 // all entries in |filterValuesg| sub to one) to prevent affecting the overa
ll | 71 // all entries in |filterValuesg| sub to one) to prevent affecting the overa
ll |
68 // brighness of the image. | 72 // brighness of the image. |
69 // | 73 // |
70 // The filterLength must be > 0. | 74 // The filterLength must be > 0. |
71 // | |
72 // This version will automatically convert your input to ConvolutionFixed po
int. | |
73 SK_API void AddFilter(int filterOffset, | |
74 const float* filterValues, | |
75 int filterLength); | |
76 | |
77 // Same as the above version, but the input is already ConvolutionFixed poin
t. | |
78 void AddFilter(int filterOffset, | 75 void AddFilter(int filterOffset, |
79 const ConvolutionFixed* filterValues, | 76 const ConvolutionFixed* filterValues, |
80 int filterLength); | 77 int filterLength); |
81 | 78 |
82 // Retrieves a filter for the given |valueOffset|, a position in the output | 79 // Retrieves a filter for the given |valueOffset|, a position in the output |
83 // image in the direction we're convolving. The offset and length of the | 80 // image in the direction we're convolving. The offset and length of the |
84 // filter values are put into the corresponding out arguments (see AddFilter | 81 // filter values are put into the corresponding out arguments (see AddFilter |
85 // above for what these mean), and a pointer to the first scaling factor is | 82 // above for what these mean), and a pointer to the first scaling factor is |
86 // returned. There will be |filterLength| values in this array. | 83 // returned. There will be |filterLength| values in this array. |
87 inline const ConvolutionFixed* FilterForValue(int valueOffset, | 84 inline const ConvolutionFixed* FilterForValue(int valueOffset, |
(...skipping 17 matching lines...) Expand all Loading... |
105 // Returns nullptr if the filter is 0-length (for instance when all floating | 102 // Returns nullptr if the filter is 0-length (for instance when all floating |
106 // point values passed to AddFilter were clipped to 0). | 103 // point values passed to AddFilter were clipped to 0). |
107 SK_API const ConvolutionFixed* GetSingleFilter(int* specifiedFilterLength, | 104 SK_API const ConvolutionFixed* GetSingleFilter(int* specifiedFilterLength, |
108 int* filterOffset, | 105 int* filterOffset, |
109 int* filterLength) const; | 106 int* filterLength) const; |
110 | 107 |
111 // Add another value to the fFilterValues array -- useful for | 108 // Add another value to the fFilterValues array -- useful for |
112 // SIMD padding which happens outside of this class. | 109 // SIMD padding which happens outside of this class. |
113 | 110 |
114 void addFilterValue( ConvolutionFixed val ) { | 111 void addFilterValue( ConvolutionFixed val ) { |
115 fFilterValues.push_back( val ); | 112 fFilterValues.push( val ); |
116 } | 113 } |
117 private: | 114 private: |
118 struct FilterInstance { | 115 struct FilterInstance { |
119 // Offset within filterValues for this instance of the filter. | 116 // Offset within filterValues for this instance of the filter. |
120 int fDataLocation; | 117 int fDataLocation; |
121 | 118 |
122 // Distance from the left of the filter to the center. IN PIXELS | 119 // Distance from the left of the filter to the center. IN PIXELS |
123 int fOffset; | 120 int fOffset; |
124 | 121 |
125 // Number of values in this filter instance. | 122 // Number of values in this filter instance. |
126 int fTrimmedLength; | 123 int fTrimmedLength; |
127 | 124 |
128 // Filter length as specified. Note that this may be different from | 125 // Filter length as specified. Note that this may be different from |
129 // 'trimmed_length' if leading/trailing zeros of the original floating | 126 // 'trimmed_length' if leading/trailing zeros of the original floating |
130 // point form were clipped differently on each tail. | 127 // point form were clipped differently on each tail. |
131 int fLength; | 128 int fLength; |
132 }; | 129 }; |
133 | 130 |
134 // Stores the information for each filter added to this class. | 131 // Stores the information for each filter added to this class. |
135 SkTArray<FilterInstance> fFilters; | 132 SkTDArray<FilterInstance> fFilters; |
136 | 133 |
137 // We store all the filter values in this flat list, indexed by | 134 // We store all the filter values in this flat list, indexed by |
138 // |FilterInstance.data_location| to avoid the mallocs required for storing | 135 // |FilterInstance.data_location| to avoid the mallocs required for storing |
139 // each one separately. | 136 // each one separately. |
140 SkTArray<ConvolutionFixed> fFilterValues; | 137 SkTDArray<ConvolutionFixed> fFilterValues; |
141 | 138 |
142 // The maximum size of any filter we've added. | 139 // The maximum size of any filter we've added. |
143 int fMaxFilter; | 140 int fMaxFilter; |
144 }; | 141 }; |
145 | 142 |
146 typedef void (*SkConvolveVertically_pointer)( | 143 typedef void (*SkConvolveVertically_pointer)( |
147 const SkConvolutionFilter1D::ConvolutionFixed* filterValues, | 144 const SkConvolutionFilter1D::ConvolutionFixed* filterValues, |
148 int filterLength, | 145 int filterLength, |
149 unsigned char* const* sourceDataRows, | 146 unsigned char* const* sourceDataRows, |
150 int pixelWidth, | 147 int pixelWidth, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 int sourceByteRowStride, | 198 int sourceByteRowStride, |
202 bool sourceHasAlpha, | 199 bool sourceHasAlpha, |
203 const SkConvolutionFilter1D& xfilter, | 200 const SkConvolutionFilter1D& xfilter, |
204 const SkConvolutionFilter1D& yfilter, | 201 const SkConvolutionFilter1D& yfilter, |
205 int outputByteRowStride, | 202 int outputByteRowStride, |
206 unsigned char* output, | 203 unsigned char* output, |
207 const SkConvolutionProcs&, | 204 const SkConvolutionProcs&, |
208 bool useSimdIfPossible); | 205 bool useSimdIfPossible); |
209 | 206 |
210 #endif // SK_CONVOLVER_H | 207 #endif // SK_CONVOLVER_H |
OLD | NEW |