From 672c7a698ae1eba35f05626dcefab8196d78d451 Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Thu, 30 Apr 2020 19:55:10 -0400 Subject: [PATCH] [skottie] More accurate contrast effect option (disabled by default) nojit: 12 -> 15 (ms) jit: 5 -> 6 (ms) Change-Id: I24a1b05d13327be93b5d9c374b2b765b0e198b0a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/286658 Commit-Queue: Florin Malita Reviewed-by: Mike Klein --- .../src/effects/BrightnessContrastEffect.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/modules/skottie/src/effects/BrightnessContrastEffect.cpp b/modules/skottie/src/effects/BrightnessContrastEffect.cpp index e480cfeafd..1c3e828fe9 100644 --- a/modules/skottie/src/effects/BrightnessContrastEffect.cpp +++ b/modules/skottie/src/effects/BrightnessContrastEffect.cpp @@ -56,6 +56,8 @@ namespace { // [3] https://www.desmos.com/calculator/ehem0vy3ft // [4] https://www.desmos.com/calculator/5t4xi10q4v // + +#ifndef SKOTTIE_ACCURATE_CONTRAST_APPROXIMATION static sk_sp make_contrast_coeffs(float contrast) { struct { float a, b, c; } coeffs; @@ -76,6 +78,28 @@ static constexpr char CONTRAST_EFFECT[] = R"( color.rgb = ((a*color.rgb + b)*color.rgb + c)*color.rgb; } )"; +#else +// More accurate (but slower) approximation: +// +// f(x) = x + a * sin(2πx) +// +// a = -contrast/3π +// +static sk_sp make_contrast_coeffs(float contrast) { + const auto coeff_a = -contrast / (3 * SK_ScalarPI); + + return SkData::MakeWithCopy(&coeff_a, sizeof(coeff_a)); +} + +static constexpr char CONTRAST_EFFECT[] = R"( + uniform half a; + + void main(inout half4 color) { + color.rgb += a * sin(color.rgb * 6.283185); + } +)"; + +#endif class BrightnessContrastAdapter final : public DiscardableAdapterBase {