aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ParametricStageTest.cpp
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2017-04-21 12:05:01 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-21 17:16:07 +0000
commit795c5b156756796cbb3a584c99b1ab51fb5fe187 (patch)
tree49db029fef63d853d930f4535ae624abddd7bf3a /tests/ParametricStageTest.cpp
parent9f5d4679e107ab83de635392798b3ddd62f48a12 (diff)
jumper, implement 2.2 stages with approx_powf
My main interest is getting rid of weird code, but it's also faster. The new bench drops from 667 to 412. Change-Id: Ibf889601284cf925780320c828394f79937dc705 Reviewed-on: https://skia-review.googlesource.com/14035 Reviewed-by: Matt Sarett <msarett@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'tests/ParametricStageTest.cpp')
-rw-r--r--tests/ParametricStageTest.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/ParametricStageTest.cpp b/tests/ParametricStageTest.cpp
index 5810148454..0185abcb36 100644
--- a/tests/ParametricStageTest.cpp
+++ b/tests/ParametricStageTest.cpp
@@ -73,3 +73,36 @@ DEF_TEST(Parametric_inv_1dot8, r) { check_error(r, 1/510.0f, 1/1.8f); }
DEF_TEST(Parametric_inv_2dot0, r) { check_error(r, 1/510.0f, 1/2.0f); }
DEF_TEST(Parametric_inv_2dot2, r) { check_error(r, 1/510.0f, 1/2.2f); }
DEF_TEST(Parametric_inv_2dot4, r) { check_error(r, 1/510.0f, 1/2.4f); }
+
+// As above, checking that the stage implements gamma within limit.
+static void check_error(skiatest::Reporter* r, float limit,
+ float gamma, SkRasterPipeline::StockStage stage) {
+
+ // We expect the gamma will only be applied to R,G,B, leaving A alone.
+ // So this isn't quite exhaustive, but it's pretty good.
+ float in[256], out[256];
+ for (int i = 0; i < 256; i++) {
+ in [i] = i / 255.0f;
+ out[i] = 0.0f; // Not likely important. Just being tidy.
+ }
+
+ const float* ip = in;
+ float* op = out;
+
+ SkRasterPipeline p;
+ p.append(SkRasterPipeline::load_f32, &ip);
+ p.append(stage);
+ p.append(SkRasterPipeline::store_f32, &op);
+ p.run(0, 256/4);
+
+ for (int i = 0; i < 256; i++) {
+ float want = powf(i/255.0f, (i%4) == 3 ? 1.0f
+ : gamma);
+ float err = fabsf(out[i] - want);
+ if (err > limit) {
+ ERRORF(r, "At %d, error was %g (got %g, want %g)", i, err, out[i], want);
+ }
+ }
+}
+DEF_TEST(from_2dot2, r) { check_error(r, 1/510.f, 2.2f, SkRasterPipeline::from_2dot2); }
+DEF_TEST( to_2dot2, r) { check_error(r, 1/510.f, 1/2.2f,SkRasterPipeline:: to_2dot2); }