aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkSRGB.h
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2016-10-12 09:52:55 -0400
committerGravatar Mike Klein <mtklein@chromium.org>2016-10-12 14:41:29 +0000
commit04adfda9c74481d0b640c0ce18864588babfcdf6 (patch)
tree034c424be3beb3da149766f7015726ef5af5545c /src/core/SkSRGB.h
parent65a09274184ffd25d446352a96d3890ea7e625fa (diff)
SkRasterPipeline: 8x pipelines, without any 8x code enabled.
Original review here: https://skia-review.googlesource.com/c/2990/ Second attempt here: https://skia-review.googlesource.com/c/3064/ This is the same as the second attempt, but with the change to SkOpts_hsw.cpp left out. That omitted part is the key piece... this just lands the refactoring. CQ_INCLUDE_TRYBOTS=master.client.skia:Perf-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Debug-ASAN-Trybot,Perf-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Debug-GN,Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot,Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-Fast-Trybot;master.client.skia.compile:Build-Win-MSVC-x86_64-Debug-Trybot GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3242 Change-Id: Iaafa793a4854c2c9cd7e85cca3701bf871253f71 Reviewed-on: https://skia-review.googlesource.com/3242 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/core/SkSRGB.h')
-rw-r--r--src/core/SkSRGB.h35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/core/SkSRGB.h b/src/core/SkSRGB.h
index e60e288861..a12ce9615d 100644
--- a/src/core/SkSRGB.h
+++ b/src/core/SkSRGB.h
@@ -22,15 +22,17 @@
extern const float sk_linear_from_srgb[256];
-static inline Sk4f sk_clamp_0_255(const Sk4f& x) {
+template <typename V>
+static inline V sk_clamp_0_255(const V& x) {
// The order of the arguments is important here. We want to make sure that NaN
// clamps to zero. Note that max(NaN, 0) = 0, while max(0, NaN) = NaN.
- return Sk4f::Min(Sk4f::Max(x, 0.0f), 255.0f);
+ return V::Min(V::Max(x, 0.0f), 255.0f);
}
// This should probably only be called from sk_linear_to_srgb() or sk_linear_to_srgb_noclamp().
// It generally doesn't make sense to work with sRGB floats.
-static inline Sk4f sk_linear_to_srgb_needs_trunc(const Sk4f& x) {
+template <typename V>
+static inline V sk_linear_to_srgb_needs_trunc(const V& x) {
// Approximation of the sRGB gamma curve (within 1 when scaled to 8-bit pixels).
//
// Constants tuned by brute force to minimize (in order of importance) after truncation:
@@ -43,19 +45,21 @@ static inline Sk4f sk_linear_to_srgb_needs_trunc(const Sk4f& x) {
auto lo = (13.0471f * 255.0f) * x;
- auto hi = (-0.0974983f * 255.0f)
- + (+0.687999f * 255.0f) * sqrt
- + (+0.412999f * 255.0f) * ftrt;
+ auto hi = SkNx_fma(V{+0.412999f * 255.0f}, ftrt,
+ SkNx_fma(V{+0.687999f * 255.0f}, sqrt,
+ V{-0.0974983f * 255.0f}));
return (x < 0.0048f).thenElse(lo, hi);
}
-static inline Sk4i sk_linear_to_srgb(const Sk4f& x) {
- Sk4f f = sk_linear_to_srgb_needs_trunc(x);
+template <int N>
+static inline SkNx<N,int> sk_linear_to_srgb(const SkNx<N,float>& x) {
+ auto f = sk_linear_to_srgb_needs_trunc(x);
return SkNx_cast<int>(sk_clamp_0_255(f));
}
-static inline Sk4i sk_linear_to_srgb_noclamp(const Sk4f& x) {
- Sk4f f = sk_linear_to_srgb_needs_trunc(x);
+template <int N>
+static inline SkNx<N,int> sk_linear_to_srgb_noclamp(const SkNx<N,float>& x) {
+ auto f = sk_linear_to_srgb_needs_trunc(x);
for (int i = 0; i < 4; i++) {
SkASSERTF(0.0f <= f[i] && f[i] < 256.0f, "f[%d] was %g, outside [0,256)\n", i, f[i]);
}
@@ -63,17 +67,18 @@ static inline Sk4i sk_linear_to_srgb_noclamp(const Sk4f& x) {
}
// sRGB -> linear, using math instead of table lookups, scaling better to larger SIMD vectors.
-static inline Sk4f sk_linear_from_srgb_math(const Sk4i& s) {
+template <int N>
+static inline SkNx<N,float> sk_linear_from_srgb_math(const SkNx<N,int>& s) {
auto x = SkNx_cast<float>(s);
const float u = 1/255.0f; // x is [0,255], so x^n needs scaling by u^n.
// Non-linear segment of sRGB curve approximated by
// l = 0.0025 + 0.6975x^2 + 0.3x^3
- const float k0 = 0.0025f,
- k2 = 0.6975f * u*u,
- k3 = 0.3000f * u*u*u;
- auto hi = k0 + (k2 + k3*x) * (x*x);
+ const SkNx<N,float> k0 = 0.0025f,
+ k2 = 0.6975f * u*u,
+ k3 = 0.3000f * u*u*u;
+ auto hi = SkNx_fma(x*x, SkNx_fma(x, k3, k2), k0);
// Linear segment of sRGB curve: the normal slope, extended a little further than normal.
auto lo = x * (u/12.92f);