Index: src/core/SkBitmapProcState.h |
diff --git a/src/core/SkBitmapProcState.h b/src/core/SkBitmapProcState.h |
index e6e7a3f393661ff729a2abecde11d62950b5e6a6..9c50eb4d3d15f48c3ef8f3cdc9c36a3f59928f08 100644 |
--- a/src/core/SkBitmapProcState.h |
+++ b/src/core/SkBitmapProcState.h |
@@ -25,17 +25,6 @@ typedef SkFixed3232 SkFractionalInt; |
#define SkFixedToFractionalInt(x) SkFixedToFixed3232(x) |
#define SkFractionalIntToInt(x) SkFixed3232ToInt(x) |
-// Applying a fixed point (SkFixed, SkFractionalInt) epsilon bias ensures that the inverse-mapped |
-// bitmap coordinates are rounded consistently WRT geometry. Note that we only have to do this |
-// when the scale is positive - for negative scales we're already rounding in the right direction. |
-static inline int bitmap_sampler_inv_bias(SkScalar scale) { |
-#ifndef SK_SUPPORT_LEGACY_BITMAP_SAMPLER_BIAS |
- return -(scale > 0); |
-#else |
- return 0; |
-#endif |
-} |
- |
class SkPaint; |
struct SkBitmapProcState { |
@@ -212,4 +201,34 @@ void S32_D16_filter_DX(const SkBitmapProcState& s, |
void S32_D16_filter_DXDY(const SkBitmapProcState& s, |
const uint32_t* xy, int count, uint16_t* colors); |
+// Helper class for mapping the middle of pixel (x, y) into SkFractionalInt bitmap space. |
+// TODO: filtered version which applies a fFilterOne{X,Y}/2 bias instead of epsilon? |
+class SkBitmapProcStateAutoMapper { |
+public: |
+ SkBitmapProcStateAutoMapper(const SkBitmapProcState& s, int x, int y) { |
+ SkPoint pt; |
+ s.fInvProc(s.fInvMatrix, |
+ SkIntToScalar(x) + SK_ScalarHalf, |
+ SkIntToScalar(y) + SK_ScalarHalf, &pt); |
+ |
+#ifndef SK_SUPPORT_LEGACY_BITMAP_SAMPLER_BIAS |
+ // SkFixed epsilon bias to ensure inverse-mapped bitmap coordinates are rounded |
+ // consistently WRT geometry. Note that we only need the bias for positive scales: |
+ // for negative scales, the rounding is intrinsically correct. |
+ // We scale it to persist SkFractionalInt -> SkFixed conversions. |
+ fX = SkScalarToFractionalInt(pt.x()) - SkFixedToFractionalInt(s.fInvMatrix.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
|
+ fY = SkScalarToFractionalInt(pt.y()) - SkFixedToFractionalInt(s.fInvMatrix.getScaleY() > 0); |
+#else |
+ fX = SkScalarToFractionalInt(pt.x()); |
+ fY = SkScalarToFractionalInt(pt.y()); |
+#endif |
+ } |
+ |
+ SkFractionalInt x() const { return fX; } |
+ SkFractionalInt y() const { return fY; } |
+ |
+private: |
+ SkFractionalInt fX, fY; |
+}; |
+ |
#endif |