OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2007 The Android Open Source Project | 2 * Copyright 2007 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkBitmapProcState_DEFINED | 8 #ifndef SkBitmapProcState_DEFINED |
9 #define SkBitmapProcState_DEFINED | 9 #define SkBitmapProcState_DEFINED |
10 | 10 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 void ClampX_ClampY_filter_scale(const SkBitmapProcState& s, uint32_t xy[], | 182 void ClampX_ClampY_filter_scale(const SkBitmapProcState& s, uint32_t xy[], |
183 int count, int x, int y); | 183 int count, int x, int y); |
184 void ClampX_ClampY_nofilter_scale(const SkBitmapProcState& s, uint32_t xy[], | 184 void ClampX_ClampY_nofilter_scale(const SkBitmapProcState& s, uint32_t xy[], |
185 int count, int x, int y); | 185 int count, int x, int y); |
186 void ClampX_ClampY_filter_affine(const SkBitmapProcState& s, | 186 void ClampX_ClampY_filter_affine(const SkBitmapProcState& s, |
187 uint32_t xy[], int count, int x, int y); | 187 uint32_t xy[], int count, int x, int y); |
188 void ClampX_ClampY_nofilter_affine(const SkBitmapProcState& s, | 188 void ClampX_ClampY_nofilter_affine(const SkBitmapProcState& s, |
189 uint32_t xy[], int count, int x, int y); | 189 uint32_t xy[], int count, int x, int y); |
190 | 190 |
191 // Helper class for mapping the middle of pixel (x, y) into SkFractionalInt bitm
ap space. | 191 // Helper class for mapping the middle of pixel (x, y) into SkFractionalInt bitm
ap space. |
192 // TODO: filtered version which applies a fFilterOne{X,Y}/2 bias instead of epsi
lon? | |
193 class SkBitmapProcStateAutoMapper { | 192 class SkBitmapProcStateAutoMapper { |
194 public: | 193 public: |
195 SkBitmapProcStateAutoMapper(const SkBitmapProcState& s, int x, int y, | 194 SkBitmapProcStateAutoMapper(const SkBitmapProcState& s, int x, int y, |
196 SkPoint* scalarPoint = nullptr) { | 195 SkPoint* scalarPoint = nullptr) { |
197 SkPoint pt; | 196 SkPoint pt; |
198 s.fInvProc(s.fInvMatrix, | 197 s.fInvProc(s.fInvMatrix, |
199 SkIntToScalar(x) + SK_ScalarHalf, | 198 SkIntToScalar(x) + SK_ScalarHalf, |
200 SkIntToScalar(y) + SK_ScalarHalf, &pt); | 199 SkIntToScalar(y) + SK_ScalarHalf, &pt); |
201 | 200 |
202 // SkFixed epsilon bias to ensure inverse-mapped bitmap coordinates are
rounded | 201 SkFixed biasX, biasY; |
203 // consistently WRT geometry. Note that we only need the bias for posit
ive scales: | 202 if (s.fFilterLevel == kNone_SkFilterQuality) { |
204 // for negative scales, the rounding is intrinsically correct. | 203 // SkFixed epsilon bias to ensure inverse-mapped bitmap coordinates
are rounded |
205 // We scale it to persist SkFractionalInt -> SkFixed conversions. | 204 // consistently WRT geometry. Note that we only need the bias for p
ositive scales: |
206 const SkFixed biasX = (s.fInvMatrix.getScaleX() > 0); | 205 // for negative scales, the rounding is intrinsically correct. |
207 const SkFixed biasY = (s.fInvMatrix.getScaleY() > 0); | 206 // We scale it to persist SkFractionalInt -> SkFixed conversions. |
| 207 biasX = (s.fInvMatrix.getScaleX() > 0); |
| 208 biasY = (s.fInvMatrix.getScaleY() > 0); |
| 209 } else { |
| 210 biasX = s.fFilterOneX >> 1; |
| 211 biasY = s.fFilterOneY >> 1; |
| 212 } |
| 213 |
208 fX = SkScalarToFractionalInt(pt.x()) - SkFixedToFractionalInt(biasX); | 214 fX = SkScalarToFractionalInt(pt.x()) - SkFixedToFractionalInt(biasX); |
209 fY = SkScalarToFractionalInt(pt.y()) - SkFixedToFractionalInt(biasY); | 215 fY = SkScalarToFractionalInt(pt.y()) - SkFixedToFractionalInt(biasY); |
210 | 216 |
211 if (scalarPoint) { | 217 if (scalarPoint) { |
212 scalarPoint->set(pt.x() - SkFixedToScalar(biasX), | 218 scalarPoint->set(pt.x() - SkFixedToScalar(biasX), |
213 pt.y() - SkFixedToScalar(biasY)); | 219 pt.y() - SkFixedToScalar(biasY)); |
214 } | 220 } |
215 } | 221 } |
216 | 222 |
217 SkFractionalInt x() const { return fX; } | 223 SkFractionalInt x() const { return fX; } |
218 SkFractionalInt y() const { return fY; } | 224 SkFractionalInt y() const { return fY; } |
219 | 225 |
220 private: | 226 private: |
221 SkFractionalInt fX, fY; | 227 SkFractionalInt fX, fY; |
222 }; | 228 }; |
223 | 229 |
224 #endif | 230 #endif |
OLD | NEW |