Flutter Engine
The Flutter Engine
Functions
ParametricStageTest.cpp File Reference
#include "modules/skcms/skcms.h"
#include "src/core/SkRasterPipeline.h"
#include "src/core/SkRasterPipelineOpContexts.h"
#include "src/core/SkRasterPipelineOpList.h"
#include "tests/Test.h"
#include <cmath>

Go to the source code of this file.

Functions

static void check_error (skiatest::Reporter *r, float limit, skcms_TransferFunction fn)
 
static void check_error (skiatest::Reporter *r, float limit, float gamma)
 
 DEF_TEST (Parametric_sRGB, r)
 
 DEF_TEST (Parametric_1dot0, r)
 
 DEF_TEST (Parametric_1dot2, r)
 
 DEF_TEST (Parametric_1dot4, r)
 
 DEF_TEST (Parametric_1dot8, r)
 
 DEF_TEST (Parametric_2dot0, r)
 
 DEF_TEST (Parametric_2dot2, r)
 
 DEF_TEST (Parametric_2dot4, r)
 
 DEF_TEST (Parametric_inv_1dot2, r)
 
 DEF_TEST (Parametric_inv_1dot4, r)
 
 DEF_TEST (Parametric_inv_1dot8, r)
 
 DEF_TEST (Parametric_inv_2dot0, r)
 
 DEF_TEST (Parametric_inv_2dot2, r)
 
 DEF_TEST (Parametric_inv_2dot4, r)
 

Function Documentation

◆ check_error() [1/2]

static void check_error ( skiatest::Reporter r,
float  limit,
float  gamma 
)
static

Definition at line 47 of file ParametricStageTest.cpp.

47 {
48 skcms_TransferFunction fn = {0,0,0,0,0,0,0};
49 fn.g = gamma;
50 fn.a = 1;
51 check_error(r, limit, fn);
52}
static void check_error(skiatest::Reporter *r, float limit, skcms_TransferFunction fn)

◆ check_error() [2/2]

static void check_error ( skiatest::Reporter r,
float  limit,
skcms_TransferFunction  fn 
)
static

Definition at line 16 of file ParametricStageTest.cpp.

16 {
17 float in[256], out[256];
18 for (int i = 0; i < 256; i++) {
19 in [i] = i / 255.0f;
20 out[i] = 0.0f; // Not likely important. Just being tidy.
21 }
22
23 SkRasterPipeline_MemoryCtx ip = { in, 0},
24 op = {out, 0};
25
27 p.append(SkRasterPipelineOp::load_f32, &ip);
28 p.appendTransferFunction(fn);
29 p.append(SkRasterPipelineOp::store_f32, &op);
30
31 p.run(0,0, 256/4,1);
32
33
34 for (int i = 0; i < 256; i++) {
35 float want = (in[i] <= fn.d) ? fn.c * in[i] + fn.f
36 : powf(in[i] * fn.a + fn.b, fn.g) + fn.e;
37 if (i % 4 == 3) { // alpha should stay unchanged.
38 want = in[i];
39 }
40 float err = fabsf(out[i] - want);
41 if (err > limit) {
42 ERRORF(r, "At %d, error was %g (got %g, want %g)", i, err, out[i], want);
43 }
44 }
45}
#define ERRORF(r,...)
Definition: Test.h:293

◆ DEF_TEST() [1/14]

DEF_TEST ( Parametric_1dot0  ,
 
)

Definition at line 68 of file ParametricStageTest.cpp.

68{ check_error(r, 1/510.0f, 1.0f); }

◆ DEF_TEST() [2/14]

DEF_TEST ( Parametric_1dot2  ,
 
)

Definition at line 70 of file ParametricStageTest.cpp.

70{ check_error(r, 1/510.0f, 1.2f); }

◆ DEF_TEST() [3/14]

DEF_TEST ( Parametric_1dot4  ,
 
)

Definition at line 71 of file ParametricStageTest.cpp.

71{ check_error(r, 1/510.0f, 1.4f); }

◆ DEF_TEST() [4/14]

DEF_TEST ( Parametric_1dot8  ,
 
)

Definition at line 72 of file ParametricStageTest.cpp.

72{ check_error(r, 1/510.0f, 1.8f); }

◆ DEF_TEST() [5/14]

DEF_TEST ( Parametric_2dot0  ,
 
)

Definition at line 73 of file ParametricStageTest.cpp.

73{ check_error(r, 1/510.0f, 2.0f); }

◆ DEF_TEST() [6/14]

DEF_TEST ( Parametric_2dot2  ,
 
)

Definition at line 74 of file ParametricStageTest.cpp.

74{ check_error(r, 1/510.0f, 2.2f); }

◆ DEF_TEST() [7/14]

DEF_TEST ( Parametric_2dot4  ,
 
)

Definition at line 75 of file ParametricStageTest.cpp.

75{ check_error(r, 1/510.0f, 2.4f); }

◆ DEF_TEST() [8/14]

DEF_TEST ( Parametric_inv_1dot2  ,
 
)

Definition at line 77 of file ParametricStageTest.cpp.

77{ check_error(r, 1/510.0f, 1/1.2f); }

◆ DEF_TEST() [9/14]

DEF_TEST ( Parametric_inv_1dot4  ,
 
)

Definition at line 78 of file ParametricStageTest.cpp.

78{ check_error(r, 1/510.0f, 1/1.4f); }

◆ DEF_TEST() [10/14]

DEF_TEST ( Parametric_inv_1dot8  ,
 
)

Definition at line 79 of file ParametricStageTest.cpp.

79{ check_error(r, 1/510.0f, 1/1.8f); }

◆ DEF_TEST() [11/14]

DEF_TEST ( Parametric_inv_2dot0  ,
 
)

Definition at line 80 of file ParametricStageTest.cpp.

80{ check_error(r, 1/510.0f, 1/2.0f); }

◆ DEF_TEST() [12/14]

DEF_TEST ( Parametric_inv_2dot2  ,
 
)

Definition at line 81 of file ParametricStageTest.cpp.

81{ check_error(r, 1/510.0f, 1/2.2f); }

◆ DEF_TEST() [13/14]

DEF_TEST ( Parametric_inv_2dot4  ,
 
)

Definition at line 82 of file ParametricStageTest.cpp.

82{ check_error(r, 1/510.0f, 1/2.4f); }

◆ DEF_TEST() [14/14]

DEF_TEST ( Parametric_sRGB  ,
 
)

Definition at line 54 of file ParametricStageTest.cpp.

54 {
55 // Test our good buddy the sRGB transfer function in resplendent 7-parameter glory.
56 check_error(r, 1/510.0f, {
57 2.4f,
58 1.0f / 1.055f,
59 0.055f / 1.055f,
60 1.0f / 12.92f,
61 0.04045f,
62 0.0f,
63 0.0f,
64 });
65}