2 * Copyright 2017 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkColorSpace.h"
9 #include "SkRasterPipeline.h"
12 static void check_error(skiatest::Reporter* r, float limit, SkColorSpaceTransferFn fn) {
13 float in[256], out[256];
14 for (int i = 0; i < 256; i++) {
16 out[i] = 0.0f; // Not likely important. Just being tidy.
22 SkRasterPipeline_<256> p;
23 p.append(SkRasterPipeline::load_f32, &ip);
24 p.append(SkRasterPipeline::parametric_r, &fn);
25 p.append(SkRasterPipeline::parametric_g, &fn);
26 p.append(SkRasterPipeline::parametric_b, &fn);
27 p.append(SkRasterPipeline::parametric_a, &fn);
28 p.append(SkRasterPipeline::store_f32, &op);
33 for (int i = 0; i < 256; i++) {
34 float want = (in[i] <= fn.fD) ? fn.fC * in[i] + fn.fF
35 : powf(in[i] * fn.fA + fn.fB, fn.fG) + fn.fE;
36 float err = fabsf(out[i] - want);
38 ERRORF(r, "At %d, error was %g (got %g, want %g)", i, err, out[i], want);
43 static void check_error(skiatest::Reporter* r, float limit, float gamma) {
44 SkColorSpaceTransferFn fn = {0,0,0,0,0,0,0};
47 check_error(r, limit, fn);
50 DEF_TEST(Parametric_sRGB, r) {
51 // Test our good buddy the sRGB transfer function in resplendent 7-parameter glory.
52 check_error(r, 1/510.0f, {
63 // A nice little spread of simple gammas.
64 DEF_TEST(Parametric_1dot0, r) { check_error(r, 1/510.0f, 1.0f); }
66 DEF_TEST(Parametric_1dot2, r) { check_error(r, 1/510.0f, 1.2f); }
67 DEF_TEST(Parametric_1dot4, r) { check_error(r, 1/510.0f, 1.4f); }
68 DEF_TEST(Parametric_1dot8, r) { check_error(r, 1/510.0f, 1.8f); }
69 DEF_TEST(Parametric_2dot0, r) { check_error(r, 1/510.0f, 2.0f); }
70 DEF_TEST(Parametric_2dot2, r) { check_error(r, 1/510.0f, 2.2f); }
71 DEF_TEST(Parametric_2dot4, r) { check_error(r, 1/510.0f, 2.4f); }
73 DEF_TEST(Parametric_inv_1dot2, r) { check_error(r, 1/510.0f, 1/1.2f); }
74 DEF_TEST(Parametric_inv_1dot4, r) { check_error(r, 1/510.0f, 1/1.4f); }
75 DEF_TEST(Parametric_inv_1dot8, r) { check_error(r, 1/510.0f, 1/1.8f); }
76 DEF_TEST(Parametric_inv_2dot0, r) { check_error(r, 1/510.0f, 1/2.0f); }
77 DEF_TEST(Parametric_inv_2dot2, r) { check_error(r, 1/510.0f, 1/2.2f); }
78 DEF_TEST(Parametric_inv_2dot4, r) { check_error(r, 1/510.0f, 1/2.4f); }