// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
using T = float; // required by EvalLog2 using D = HWY_FULL(T);
// These templates are not found via ADL. using hwy::HWY_NAMESPACE::Abs; using hwy::HWY_NAMESPACE::Add; using hwy::HWY_NAMESPACE::Eq; using hwy::HWY_NAMESPACE::GetLane; using hwy::HWY_NAMESPACE::ShiftLeft; using hwy::HWY_NAMESPACE::ShiftRight; using hwy::HWY_NAMESPACE::Sub;
T LinearToSrgb8Direct(T val) { if (val < 0.0) return 0.0; if (val >= 255.0) return 255.0; if (val <= 10.0 / 12.92) return val * 12.92; return 255.0 * (std::pow(val / 255.0, 1.0 / 2.4) * 1.055 - 0.055);
}
T SimpleGamma(T v) { staticconst T kGamma = 0.387494322593; staticconst T limit = 43.01745241042018;
T bright = v - limit; if (bright >= 0) { staticconst T mul = 0.0383723643799;
v -= bright * mul;
} staticconst T limit2 = 94.68634353321337;
T bright2 = v - limit2; if (bright2 >= 0) { staticconst T mul = 0.22885405968;
v -= bright2 * mul;
} staticconst T offset = 0.156775786057; staticconst T scale = 8.898059160493739;
T retval = scale * (offset + pow(v, kGamma)); return retval;
}
// Runs CaratheodoryFejer and verifies the polynomial using a lot of samples to // return the biggest error. template <size_t NP, size_t NQ, class Eval>
T RunApproximation(T x0, T x1, const T (&p)[NP], const T (&q)[NQ], const Eval& eval, T func_to_approx(T)) { float maxerr = 0;
T lastPrint = 0; // NOLINTNEXTLINE(clang-analyzer-security.FloatLoopCounter) for (T x = x0; x <= x1; x += (x1 - x0) / 10000.0) { const T f = func_to_approx(x); const T g = eval(x, p, q);
maxerr = std::max(fabsf(g - f), maxerr); if (x == x0 || x - lastPrint > (x1 - x0) / 20.0) {
printf("x: %11.6f, f: %11.6f, g: %11.6f, e: %11.6f\n", x, f, g,
fabs(g - f));
lastPrint = x;
}
} return maxerr;
}
void TestNegExp() { // 4,3 is the min required for monotonicity; max error in 0,10: 751 ppm // no benefit for k>50. const T p[4 * (4 + 1)] = {
HWY_REP4(5.9580258551150123E-02), HWY_REP4(-2.5073728806886408E-02),
HWY_REP4(4.1561830213689248E-03), HWY_REP4(-3.1815408488900372E-04),
HWY_REP4(9.3866690094906802E-06)}; const T q[4 * (3 + 1)] = {
HWY_REP4(5.9579108238812878E-02), HWY_REP4(3.4542074345478582E-02),
HWY_REP4(8.7263562483501714E-03), HWY_REP4(1.4095109143061216E-03)};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.