Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
SRGBTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkTypes.h"
#include "src/base/SkArenaAlloc.h"
#include "src/core/SkColorSpaceXformSteps.h"
#include "src/core/SkRasterPipeline.h"
#include "src/core/SkRasterPipelineOpContexts.h"
#include "src/core/SkRasterPipelineOpList.h"
#include "tests/Test.h"
#include <cstdint>
#include <cstring>

Go to the source code of this file.

Functions

 DEF_TEST (srgb_roundtrip, r)
 
 DEF_TEST (srgb_edge_cases, r)
 
 DEF_TEST (srgb_roundtrip_extended, r)
 

Function Documentation

◆ DEF_TEST() [1/3]

DEF_TEST ( srgb_edge_cases  ,
 
)

Definition at line 53 of file SRGBTest.cpp.

53 {
54 // We need to run at least 4 pixels to make sure we hit all specializations.
55 float colors[4][4] = { {0,1,1,1}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} };
56 auto& color = colors[0];
57
59
61 linear = sRGB->makeLinearGamma();
63
64 SkColorSpaceXformSteps steps {linear.get(),upm, sRGB.get(),upm};
65
67 SkRasterPipeline p(&alloc);
68 p.appendConstantColor(&alloc, color);
69 steps.apply(&p);
70 p.append(SkRasterPipelineOp::store_f32, &dst);
71 p.run(0,0,4,1);
72
73 if (color[0] != 0.0f) {
74 ERRORF(r, "expected to_srgb() to map 0.0f to 0.0f, got %f", color[0]);
75 }
76 if (color[1] != 1.0f) {
77 float f = color[1];
78 uint32_t x;
79 memcpy(&x, &f, 4);
80 ERRORF(r, "expected to_srgb() to map 1.0f to 1.0f, got %f (%08x)", color[1], x);
81 }
82}
SkColor4f color
kUnpremul_SkAlphaType
SkAlphaType
Definition SkAlphaType.h:26
#define ERRORF(r,...)
Definition Test.h:293
static sk_sp< SkColorSpace > MakeSRGB()
T * get() const
Definition SkRefCnt.h:303
double x
PODArray< SkColor > colors
Definition SkRecords.h:276
dst
Definition cp.py:12
static sk_sp< SkShader > linear(sk_sp< SkShader > shader)

◆ DEF_TEST() [2/3]

DEF_TEST ( srgb_roundtrip  ,
 
)

Definition at line 23 of file SRGBTest.cpp.

23 {
24 uint32_t reds[256];
25 for (int i = 0; i < 256; i++) {
26 reds[i] = i;
27 }
28
29 SkRasterPipeline_MemoryCtx ptr = { reds, 0 };
30
32 linear = sRGB->makeLinearGamma();
34
35 SkColorSpaceXformSteps linearize{ sRGB.get(),upm, linear.get(),upm},
36 reencode {linear.get(),upm, sRGB.get(),upm};
37
39 p.append(SkRasterPipelineOp::load_8888, &ptr);
40 linearize.apply(&p);
41 reencode .apply(&p);
42 p.append(SkRasterPipelineOp::store_8888, &ptr);
43
44 p.run(0,0,256,1);
45
46 for (int i = 0; i < 256; i++) {
47 if (reds[i] != (uint32_t)i) {
48 ERRORF(r, "%d doesn't round trip, %u", i, reds[i]);
49 }
50 }
51}

◆ DEF_TEST() [3/3]

DEF_TEST ( srgb_roundtrip_extended  ,
 
)

Definition at line 85 of file SRGBTest.cpp.

85 {
86 static const int kSteps = 128;
87 SkColor4f rgba[kSteps];
88
89 auto expected = [=](int i) {
90 float scale = 10000.0f / (3*kSteps);
91 return SkColor4f{
92 (3*i+0) * scale,
93 (3*i+1) * scale,
94 (3*i+2) * scale,
95 1.0f,
96 };
97 };
98
99 for (int i = 0; i < kSteps; i++) {
100 rgba[i] = expected(i);
101 }
102
103 SkRasterPipeline_MemoryCtx ptr = { rgba, 0 };
104
106 sk_sp<SkColorSpace> linear = cs->makeLinearGamma();
108
109 SkColorSpaceXformSteps linearize{ cs.get(),upm, linear.get(),upm},
110 reencode {linear.get(),upm, cs.get(),upm};
111
113 p.append(SkRasterPipelineOp::load_f32, &ptr);
114 linearize.apply(&p);
115 reencode .apply(&p);
116 p.append(SkRasterPipelineOp::store_f32, &ptr);
117 p.run(0,0,kSteps,1);
118
119 auto close = [=](float x, float y) {
120 return x == y
121 || (x/y < 1.001f && y/x < 1.001f);
122 };
123
124 for (int i = 0; i < kSteps; i++) {
125 SkColor4f want = expected(i);
126 #if 0
127 SkDebugf("got %g %g %g, want %g %g %g\n",
128 rgba[i].fR, rgba[i].fG, rgba[i].fB,
129 want.fR, want.fG, want.fB);
130 #endif
131 REPORTER_ASSERT(r, close(rgba[i].fR, want.fR));
132 REPORTER_ASSERT(r, close(rgba[i].fG, want.fG));
133 REPORTER_ASSERT(r, close(rgba[i].fB, want.fB));
134 }
135}
static const uint32_t rgba[kNumPixels]
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
double y
const Scalar scale