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 |
11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
12 #include "SkBitmapController.h" | 12 #include "SkBitmapController.h" |
13 #include "SkBitmapFilter.h" | 13 #include "SkBitmapFilter.h" |
14 #include "SkBitmapProvider.h" | 14 #include "SkBitmapProvider.h" |
15 #include "SkFloatBits.h" | 15 #include "SkFloatBits.h" |
16 #include "SkMatrix.h" | 16 #include "SkMatrix.h" |
17 #include "SkMipMap.h" | 17 #include "SkMipMap.h" |
18 #include "SkPaint.h" | 18 #include "SkPaint.h" |
19 #include "SkShader.h" | 19 #include "SkShader.h" |
20 #include "SkTemplates.h" | 20 #include "SkTemplates.h" |
21 | 21 |
22 typedef SkFixed3232 SkFractionalInt; | 22 typedef SkFixed3232 SkFractionalInt; |
23 #define SkScalarToFractionalInt(x) SkScalarToFixed3232(x) | 23 #define SkScalarToFractionalInt(x) SkScalarToFixed3232(x) |
24 #define SkFractionalIntToFixed(x) SkFixed3232ToFixed(x) | 24 #define SkFractionalIntToFixed(x) SkFixed3232ToFixed(x) |
25 #define SkFixedToFractionalInt(x) SkFixedToFixed3232(x) | 25 #define SkFixedToFractionalInt(x) SkFixedToFixed3232(x) |
26 #define SkFractionalIntToInt(x) SkFixed3232ToInt(x) | 26 #define SkFractionalIntToInt(x) SkFixed3232ToInt(x) |
27 | 27 |
28 // Applying a fixed point (SkFixed, SkFractionalInt) epsilon bias ensures that t he inverse-mapped | |
29 // bitmap coordinates are rounded consistently WRT geometry. Note that we only have to do this | |
30 // when the scale is positive - for negative scales we're already rounding in th e right direction. | |
31 static inline int bitmap_sampler_inv_bias(SkScalar scale) { | |
32 #ifndef SK_SUPPORT_LEGACY_BITMAP_SAMPLER_BIAS | |
33 return -(scale > 0); | |
34 #else | |
35 return 0; | |
36 #endif | |
37 } | |
38 | |
39 class SkPaint; | 28 class SkPaint; |
40 | 29 |
41 struct SkBitmapProcState { | 30 struct SkBitmapProcState { |
42 SkBitmapProcState(const SkBitmapProvider&, SkShader::TileMode tmx, SkShader: :TileMode tmy); | 31 SkBitmapProcState(const SkBitmapProvider&, SkShader::TileMode tmx, SkShader: :TileMode tmy); |
43 SkBitmapProcState(const SkBitmap&, SkShader::TileMode tmx, SkShader::TileMod e tmy); | 32 SkBitmapProcState(const SkBitmap&, SkShader::TileMode tmx, SkShader::TileMod e tmy); |
44 ~SkBitmapProcState(); | 33 ~SkBitmapProcState(); |
45 | 34 |
46 typedef void (*ShaderProc32)(const SkBitmapProcState&, int x, int y, | 35 typedef void (*ShaderProc32)(const SkBitmapProcState&, int x, int y, |
47 SkPMColor[], int count); | 36 SkPMColor[], int count); |
48 | 37 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 int count, int x, int y); | 194 int count, int x, int y); |
206 void ClampX_ClampY_filter_affine(const SkBitmapProcState& s, | 195 void ClampX_ClampY_filter_affine(const SkBitmapProcState& s, |
207 uint32_t xy[], int count, int x, int y); | 196 uint32_t xy[], int count, int x, int y); |
208 void ClampX_ClampY_nofilter_affine(const SkBitmapProcState& s, | 197 void ClampX_ClampY_nofilter_affine(const SkBitmapProcState& s, |
209 uint32_t xy[], int count, int x, int y); | 198 uint32_t xy[], int count, int x, int y); |
210 void S32_D16_filter_DX(const SkBitmapProcState& s, | 199 void S32_D16_filter_DX(const SkBitmapProcState& s, |
211 const uint32_t* xy, int count, uint16_t* colors); | 200 const uint32_t* xy, int count, uint16_t* colors); |
212 void S32_D16_filter_DXDY(const SkBitmapProcState& s, | 201 void S32_D16_filter_DXDY(const SkBitmapProcState& s, |
213 const uint32_t* xy, int count, uint16_t* colors); | 202 const uint32_t* xy, int count, uint16_t* colors); |
214 | 203 |
204 // Helper class for mapping the middle of pixel (x, y) into SkFractionalInt bitm ap space. | |
205 // TODO: filtered version which applies a fFilterOne{X,Y}/2 bias instead of epsi lon? | |
206 class SkBitmapProcStateAutoMapper { | |
207 public: | |
208 SkBitmapProcStateAutoMapper(const SkBitmapProcState& s, int x, int y) { | |
209 SkPoint pt; | |
210 s.fInvProc(s.fInvMatrix, | |
211 SkIntToScalar(x) + SK_ScalarHalf, | |
212 SkIntToScalar(y) + SK_ScalarHalf, &pt); | |
213 | |
214 #ifndef SK_SUPPORT_LEGACY_BITMAP_SAMPLER_BIAS | |
215 // SkFixed epsilon bias to ensure inverse-mapped bitmap coordinates are rounded | |
216 // consistently WRT geometry. Note that we only need the bias for posit ive scales: | |
217 // for negative scales, the rounding is intrinsically correct. | |
218 // We scale it to persist SkFractionalInt -> SkFixed conversions. | |
219 fX = SkScalarToFractionalInt(pt.x()) - SkFixedToFractionalInt(s.fInvMatr ix.getScaleX() > 0); | |
reed1
2016/01/04 17:55:57
Now that is a tricky expression: SkFixedToFraction
f(malita)
2016/01/04 18:04:27
Right. Maybe something like this would look more
| |
220 fY = SkScalarToFractionalInt(pt.y()) - SkFixedToFractionalInt(s.fInvMatr ix.getScaleY() > 0); | |
221 #else | |
222 fX = SkScalarToFractionalInt(pt.x()); | |
223 fY = SkScalarToFractionalInt(pt.y()); | |
215 #endif | 224 #endif |
225 } | |
226 | |
227 SkFractionalInt x() const { return fX; } | |
228 SkFractionalInt y() const { return fY; } | |
229 | |
230 private: | |
231 SkFractionalInt fX, fY; | |
232 }; | |
233 | |
234 #endif | |
OLD | NEW |