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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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? | 192 // TODO: filtered version which applies a fFilterOne{X,Y}/2 bias instead of epsi
lon? |
193 class SkBitmapProcStateAutoMapper { | 193 class SkBitmapProcStateAutoMapper { |
194 public: | 194 public: |
195 SkBitmapProcStateAutoMapper(const SkBitmapProcState& s, int x, int y) { | 195 SkBitmapProcStateAutoMapper(const SkBitmapProcState& s, int x, int y, |
| 196 SkPoint* scalarPoint = nullptr) { |
196 SkPoint pt; | 197 SkPoint pt; |
197 s.fInvProc(s.fInvMatrix, | 198 s.fInvProc(s.fInvMatrix, |
198 SkIntToScalar(x) + SK_ScalarHalf, | 199 SkIntToScalar(x) + SK_ScalarHalf, |
199 SkIntToScalar(y) + SK_ScalarHalf, &pt); | 200 SkIntToScalar(y) + SK_ScalarHalf, &pt); |
200 | 201 |
201 // SkFixed epsilon bias to ensure inverse-mapped bitmap coordinates are
rounded | 202 // SkFixed epsilon bias to ensure inverse-mapped bitmap coordinates are
rounded |
202 // consistently WRT geometry. Note that we only need the bias for posit
ive scales: | 203 // consistently WRT geometry. Note that we only need the bias for posit
ive scales: |
203 // for negative scales, the rounding is intrinsically correct. | 204 // for negative scales, the rounding is intrinsically correct. |
204 // We scale it to persist SkFractionalInt -> SkFixed conversions. | 205 // We scale it to persist SkFractionalInt -> SkFixed conversions. |
205 const SkFixed biasX = (s.fInvMatrix.getScaleX() > 0); | 206 const SkFixed biasX = (s.fInvMatrix.getScaleX() > 0); |
206 const SkFixed biasY = (s.fInvMatrix.getScaleY() > 0); | 207 const SkFixed biasY = (s.fInvMatrix.getScaleY() > 0); |
207 fX = SkScalarToFractionalInt(pt.x()) - SkFixedToFractionalInt(biasX); | 208 fX = SkScalarToFractionalInt(pt.x()) - SkFixedToFractionalInt(biasX); |
208 fY = SkScalarToFractionalInt(pt.y()) - SkFixedToFractionalInt(biasY); | 209 fY = SkScalarToFractionalInt(pt.y()) - SkFixedToFractionalInt(biasY); |
209 | 210 |
210 /* | 211 if (scalarPoint) { |
211 * (see SkBitmapProcState::setupForTranslate, which is the only user of
this flag) | 212 scalarPoint->set(pt.x() - SkFixedToScalar(biasX), |
212 * | 213 pt.y() - SkFixedToScalar(biasY)); |
213 * if the translate is larger than our ints, we can get random results,
or | 214 } |
214 * worse, we might get 0x80000000, which wreaks havoc on us, since we c
an't | |
215 * negate it. | |
216 */ | |
217 const SkScalar too_big = SkIntToScalar(1 << 30); | |
218 fOverflow = SkScalarAbs(pt.x() - SkFixedToScalar(biasX)) > too_big | |
219 || SkScalarAbs(pt.y() - SkFixedToScalar(biasY)) > too_big; | |
220 } | 215 } |
221 | 216 |
222 SkFractionalInt x() const { return fX; } | 217 SkFractionalInt x() const { return fX; } |
223 SkFractionalInt y() const { return fY; } | 218 SkFractionalInt y() const { return fY; } |
224 | 219 |
225 bool isOverflow() const { return fOverflow; } | |
226 | |
227 private: | 220 private: |
228 SkFractionalInt fX, fY; | 221 SkFractionalInt fX, fY; |
229 bool fOverflow; | |
230 }; | 222 }; |
231 | 223 |
232 #endif | 224 #endif |
OLD | NEW |