aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkBitmapProcState.h
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2016-01-04 10:28:11 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-01-04 10:28:11 -0800
commitb3a835891cf221bdf4c6eeb4cf404b374955015f (patch)
tree13a52c1b1e6268330790b2e70c46cf991ac5f031 /src/core/SkBitmapProcState.h
parent0152cc3819291841298013d2b5515a61e974e41f (diff)
[Reland] Repeating SkBitmapProcState rounding bias
1) observe the bias in repeat matrix procs also. 2) add utility for device space -> bitmap space mapping. 3) remove unneeded filter bias This is a reland of https://codereview.chromium.org/1529833003/. The main difference (and the fix) vs. the prev version is increased precision: the mapper now operates with SkFractionalInts. R=reed@google.com BUG=skia:4680, skia:4649 GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1539083002 Review URL: https://codereview.chromium.org/1539083002
Diffstat (limited to 'src/core/SkBitmapProcState.h')
-rw-r--r--src/core/SkBitmapProcState.h41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/core/SkBitmapProcState.h b/src/core/SkBitmapProcState.h
index 4d7e7f32dc..24c6db6552 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 {
@@ -210,4 +199,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);
+ 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