aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-12-18 10:14:12 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-18 19:49:12 +0000
commitff5000830544f23a2af7a861068b1a8deebef7ba (patch)
tree9963fed8e741cd16ad0dc1b61eb9bde85e360d0a /include
parentf1f1162273b382db99f8609e5bbfff24f5594821 (diff)
Increase accuracy of float -> fixed in ICC code
Add a comment to SkFixed explaining the accuracy issues of the macros. Re-land of: https://skia-review.googlesource.com/85742 Bug: skia: Change-Id: I09cef45bdb858608a6afe6c30424d8046cac50ec Reviewed-on: https://skia-review.googlesource.com/86540 Commit-Queue: Brian Osman <brianosman@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org> Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/private/SkFixed.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/include/private/SkFixed.h b/include/private/SkFixed.h
index adb0343bc7..05e1de49c9 100644
--- a/include/private/SkFixed.h
+++ b/include/private/SkFixed.h
@@ -30,6 +30,11 @@ typedef int32_t SkFixed;
#define SK_FixedTanPIOver8 (0x6A0A)
#define SK_FixedRoot2Over2 (0xB505)
+// NOTE: SkFixedToFloat is exact. SkFloatToFixed seems to lack a rounding step. For all fixed-point
+// values, this version is as accurate as possible for (fixed -> float -> fixed). Rounding reduces
+// accuracy if the intermediate floats are in the range that only holds integers (adding 0.5f to an
+// odd integer then snaps to nearest even). Using double for the rounding math gives maximum
+// accuracy for (float -> fixed -> float), but that's usually overkill.
#define SkFixedToFloat(x) ((x) * 1.52587890625e-5f)
#define SkFloatToFixed(x) sk_float_saturate2int((x) * SK_Fixed1)