Revert "Increase accuracy of float -> fixed in ICC code"

This reverts commit ef8dda227b.

Reason for revert: This is breaking WebKit layout tests on linux and blocking the autoroller. Probably just needs a rebase. See:
https://storage.googleapis.com/chromium-layout-test-archives/linux_trusty_blink_rel/20229/layout-test-results/results.html

Original change's description:
> Increase accuracy of float -> fixed in ICC code
> 
> Add a comment to SkFixed explaining the accuracy issues of the macros.
> 
> Bug: skia:
> Change-Id: Ibfecb16821fefe87822cc3acd1cf8498df10a492
> Reviewed-on: https://skia-review.googlesource.com/85742
> Reviewed-by: Brian Osman <brianosman@google.com>
> Commit-Queue: Brian Osman <brianosman@google.com>

TBR=mtklein@chromium.org,brianosman@google.com,reed@google.com

Change-Id: I354327767bd59a6104b1431b053721c3102719be
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/86281
Reviewed-by: Eric Karl <ericrk@chromium.org>
Commit-Queue: Eric Karl <ericrk@chromium.org>
This commit is contained in:
Eric Karl 2017-12-16 00:40:08 +00:00 committed by Skia Commit-Bot
parent aae533e418
commit dd821bc564
2 changed files with 10 additions and 23 deletions

View File

@ -30,11 +30,6 @@ 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)

View File

@ -281,33 +281,25 @@ static constexpr uint32_t kICCTagTable[3 * kICCNumEntries] {
SkEndian_SwapBE32(kTAG_cprt_Bytes),
};
// This is like SkFloatToFixed, but rounds to nearest, preserving as much accuracy as possible
// when going float -> fixed -> float (it has the same accuracy when going fixed -> float -> fixed).
// The use of double is necessary to accomodate the full potential 32-bit mantissa of the 16.16
// SkFixed value, and so avoiding rounding problems with float. Also, see the comment in SkFixed.h.
static SkFixed float_round_to_fixed(float x) {
return sk_float_saturate2int((float)floor((double)x * SK_Fixed1 + 0.5));
}
static void write_xyz_tag(uint32_t* ptr, const SkMatrix44& toXYZ, int col) {
ptr[0] = SkEndian_SwapBE32(kXYZ_PCSSpace);
ptr[1] = 0;
ptr[2] = SkEndian_SwapBE32(float_round_to_fixed(toXYZ.getFloat(0, col)));
ptr[3] = SkEndian_SwapBE32(float_round_to_fixed(toXYZ.getFloat(1, col)));
ptr[4] = SkEndian_SwapBE32(float_round_to_fixed(toXYZ.getFloat(2, col)));
ptr[2] = SkEndian_SwapBE32(SkFloatToFixed(toXYZ.getFloat(0, col)));
ptr[3] = SkEndian_SwapBE32(SkFloatToFixed(toXYZ.getFloat(1, col)));
ptr[4] = SkEndian_SwapBE32(SkFloatToFixed(toXYZ.getFloat(2, col)));
}
static void write_trc_tag(uint32_t* ptr, const SkColorSpaceTransferFn& fn) {
ptr[0] = SkEndian_SwapBE32(kTAG_ParaCurveType);
ptr[1] = 0;
ptr[2] = (uint32_t) (SkEndian_SwapBE16(kGABCDEF_ParaCurveType));
ptr[3] = SkEndian_SwapBE32(float_round_to_fixed(fn.fG));
ptr[4] = SkEndian_SwapBE32(float_round_to_fixed(fn.fA));
ptr[5] = SkEndian_SwapBE32(float_round_to_fixed(fn.fB));
ptr[6] = SkEndian_SwapBE32(float_round_to_fixed(fn.fC));
ptr[7] = SkEndian_SwapBE32(float_round_to_fixed(fn.fD));
ptr[8] = SkEndian_SwapBE32(float_round_to_fixed(fn.fE));
ptr[9] = SkEndian_SwapBE32(float_round_to_fixed(fn.fF));
ptr[3] = SkEndian_SwapBE32(SkFloatToFixed(fn.fG));
ptr[4] = SkEndian_SwapBE32(SkFloatToFixed(fn.fA));
ptr[5] = SkEndian_SwapBE32(SkFloatToFixed(fn.fB));
ptr[6] = SkEndian_SwapBE32(SkFloatToFixed(fn.fC));
ptr[7] = SkEndian_SwapBE32(SkFloatToFixed(fn.fD));
ptr[8] = SkEndian_SwapBE32(SkFloatToFixed(fn.fE));
ptr[9] = SkEndian_SwapBE32(SkFloatToFixed(fn.fF));
}
static bool is_3x3(const SkMatrix44& toXYZD50) {