| 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 |
| 28 class SkPaint; | 39 class SkPaint; |
| 29 | 40 |
| 30 struct SkBitmapProcState { | 41 struct SkBitmapProcState { |
| 31 SkBitmapProcState(const SkBitmapProvider&, SkShader::TileMode tmx, SkShader:
:TileMode tmy); | 42 SkBitmapProcState(const SkBitmapProvider&, SkShader::TileMode tmx, SkShader:
:TileMode tmy); |
| 32 SkBitmapProcState(const SkBitmap&, SkShader::TileMode tmx, SkShader::TileMod
e tmy); | 43 SkBitmapProcState(const SkBitmap&, SkShader::TileMode tmx, SkShader::TileMod
e tmy); |
| 33 ~SkBitmapProcState(); | 44 ~SkBitmapProcState(); |
| 34 | 45 |
| 35 typedef void (*ShaderProc32)(const SkBitmapProcState&, int x, int y, | 46 typedef void (*ShaderProc32)(const SkBitmapProcState&, int x, int y, |
| 36 SkPMColor[], int count); | 47 SkPMColor[], int count); |
| 37 | 48 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 int count, int x, int y); | 205 int count, int x, int y); |
| 195 void ClampX_ClampY_filter_affine(const SkBitmapProcState& s, | 206 void ClampX_ClampY_filter_affine(const SkBitmapProcState& s, |
| 196 uint32_t xy[], int count, int x, int y); | 207 uint32_t xy[], int count, int x, int y); |
| 197 void ClampX_ClampY_nofilter_affine(const SkBitmapProcState& s, | 208 void ClampX_ClampY_nofilter_affine(const SkBitmapProcState& s, |
| 198 uint32_t xy[], int count, int x, int y); | 209 uint32_t xy[], int count, int x, int y); |
| 199 void S32_D16_filter_DX(const SkBitmapProcState& s, | 210 void S32_D16_filter_DX(const SkBitmapProcState& s, |
| 200 const uint32_t* xy, int count, uint16_t* colors); | 211 const uint32_t* xy, int count, uint16_t* colors); |
| 201 void S32_D16_filter_DXDY(const SkBitmapProcState& s, | 212 void S32_D16_filter_DXDY(const SkBitmapProcState& s, |
| 202 const uint32_t* xy, int count, uint16_t* colors); | 213 const uint32_t* xy, int count, uint16_t* colors); |
| 203 | 214 |
| 204 // Helper class for mapping the middle of pixel (x, y) into SkFixed bitmap space
. | |
| 205 class SkBitmapProcStateAutoMapper { | |
| 206 public: | |
| 207 SkBitmapProcStateAutoMapper(const SkBitmapProcState& s, int x, int y) { | |
| 208 SkPoint pt; | |
| 209 s.fInvProc(s.fInvMatrix, | |
| 210 SkIntToScalar(x) + SK_ScalarHalf, | |
| 211 SkIntToScalar(y) + SK_ScalarHalf, &pt); | |
| 212 | |
| 213 #ifndef SK_SUPPORT_LEGACY_BITMAP_SAMPLER_BIAS | |
| 214 // SkFixed epsilon bias to ensure inverse-mapped bitmap coordinates are
rounded | |
| 215 // consistently WRT geometry. Note that we only need the bias for posit
ive scales: | |
| 216 // for negative scales, the rounding is intrinsically correct. | |
| 217 fX = SkScalarToFixed(pt.x()) - (s.fInvMatrix.getScaleX() > 0); | |
| 218 fY = SkScalarToFixed(pt.y()) - (s.fInvMatrix.getScaleY() > 0); | |
| 219 #else | |
| 220 fX = SkScalarToFixed(pt.x()); | |
| 221 fY = SkScalarToFixed(pt.y()); | |
| 222 #endif | 215 #endif |
| 223 } | |
| 224 | |
| 225 SkFixed x() const { return fX; } | |
| 226 SkFixed y() const { return fY; } | |
| 227 | |
| 228 private: | |
| 229 SkFixed fX, fY; | |
| 230 }; | |
| 231 | |
| 232 #endif | |
| OLD | NEW |