Remove assert from powf_
This assert is being hit on some builders, likely from the call to
powf_(tf->a * x + tf->b, tf->g)
inside skcms_TransferFunction_eval.
Rather than patch up this powf_ call, change powf_ to return 0 for
negative inputs. This allows us to remove the powf_(fmaxf_) pattern
from skcms_TFType_PQish.
Bug: chromium:333638402
Change-Id: I6edc8af2818a1252fb88d5da89f91ee25e285247
Reviewed-on: https://skia-review.googlesource.com/c/skcms/+/839557
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Christopher Cameron <ccameron@google.com>
Commit-Queue: Christopher Cameron <ccameron@google.com>
diff --git a/skcms.cc b/skcms.cc
index e2565b3..6c9c111 100644
--- a/skcms.cc
+++ b/skcms.cc
@@ -91,9 +91,13 @@
// Not static, as it's used by some test tools.
float powf_(float x, float y) {
- assert (x >= 0);
- return (x == 0) || (x == 1) ? x
- : exp2f_(log2f_(x) * y);
+ if (x <= 0.f) {
+ return 0.f;
+ }
+ if (x == 1.f) {
+ return 1.f;
+ }
+ return exp2f_(log2f_(x) * y);
}
static float expf_(float x) {
@@ -232,9 +236,9 @@
return sign * (x < tf->d ? tf->c * x + tf->f
: powf_(tf->a * x + tf->b, tf->g) + tf->e);
- case skcms_TFType_PQish: return sign * powf_(fmaxf_(pq.A + pq.B * powf_(x, pq.C), 0)
- / (pq.D + pq.E * powf_(x, pq.C)),
- pq.F);
+ case skcms_TFType_PQish:
+ return sign *
+ powf_((pq.A + pq.B * powf_(x, pq.C)) / (pq.D + pq.E * powf_(x, pq.C)), pq.F);
}
return 0;
}