Flutter Engine
The Flutter Engine
Functions
NonlinearBlendingTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkRefCnt.h"
#include "modules/skcms/skcms.h"
#include "src/core/SkColorSpaceXformSteps.h"
#include "tests/Test.h"
#include <cmath>

Go to the source code of this file.

Functions

 DEF_TEST (SkColorSpaceXformSteps_vs_skcms, r)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( SkColorSpaceXformSteps_vs_skcms  ,
 
)

Definition at line 18 of file NonlinearBlendingTest.cpp.

18 {
19 auto srgb = SkColorSpace::MakeSRGB();
21
22 skcms_ICCProfile srgb_profile;
23 srgb->toProfile(&srgb_profile);
24 skcms_ICCProfile dp3_profile;
25 dp3->toProfile(&dp3_profile);
26
27 // These colors provide a good spread of interesting test cases.
28 SkColor colors[] = {
29 0xffff0000, 0x7fff0000, 0x7f7f0000,
30 0xff00ff00, 0x7f00ff00, 0x7f007f00,
31 };
32
33 for (auto color : colors) {
36 auto unpremul = skcms_AlphaFormat_Unpremul,
38
39 float via_skcms[4];
40 skcms_Transform(&color, bgra, unpremul, &srgb_profile,
41 &via_skcms, f32, premul, &dp3_profile,
42 1);
43
45 dp3.get(), kPremul_SkAlphaType);
46 float via_steps[4] = {
47 SkColorGetR(color) * (1 / 255.0f),
48 SkColorGetG(color) * (1 / 255.0f),
49 SkColorGetB(color) * (1 / 255.0f),
50 SkColorGetA(color) * (1 / 255.0f),
51 };
52 steps.apply(via_steps);
53
54 REPORTER_ASSERT(r, fabsf(via_skcms[0] - via_steps[0]) <= 0.005f);
55 REPORTER_ASSERT(r, fabsf(via_skcms[1] - via_steps[1]) <= 0.005f);
56 REPORTER_ASSERT(r, fabsf(via_skcms[2] - via_steps[2]) <= 0.005f);
57 REPORTER_ASSERT(r, fabsf(via_skcms[3] - via_steps[3]) <= 0.0f);
58
59 // Now go back using the other method's inverse transform
60 float steps_to_skcms[4];
61 skcms_Transform(via_steps, f32, premul, &dp3_profile,
62 steps_to_skcms, f32, premul, &srgb_profile,
63 1);
64
65 float skcms_to_steps[4] = { via_skcms[0], via_skcms[1], via_skcms[2], via_skcms[3] };
67 srgb.get(), kPremul_SkAlphaType);
68 inv_steps.apply(skcms_to_steps);
69
70 REPORTER_ASSERT(r, fabsf(skcms_to_steps[0] - steps_to_skcms[0]) <= 0.005f);
71 REPORTER_ASSERT(r, fabsf(skcms_to_steps[1] - steps_to_skcms[1]) <= 0.005f);
72 REPORTER_ASSERT(r, fabsf(skcms_to_steps[2] - steps_to_skcms[2]) <= 0.005f);
73 REPORTER_ASSERT(r, fabsf(skcms_to_steps[3] - steps_to_skcms[3]) <= 0.0f);
74 }
75}
kUnpremul_SkAlphaType
static const uint32_t bgra[kNumPixels]
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#define SkColorGetR(color)
Definition: SkColor.h:65
#define SkColorGetG(color)
Definition: SkColor.h:69
uint32_t SkColor
Definition: SkColor.h:37
#define SkColorGetA(color)
Definition: SkColor.h:61
#define SkColorGetB(color)
Definition: SkColor.h:73
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
static uint32_t premul(uint32_t color)
static sk_sp< SkColorSpace > MakeSRGB()
static sk_sp< SkColorSpace > MakeRGB(const skcms_TransferFunction &transferFn, const skcms_Matrix3x3 &toXYZ)
DlColor color
static constexpr skcms_Matrix3x3 kDisplayP3
Definition: SkColorSpace.h:87
static constexpr skcms_TransferFunction kSRGB
Definition: SkColorSpace.h:45
PODArray< SkColor > colors
Definition: SkRecords.h:276
bool skcms_Transform(const void *src, skcms_PixelFormat srcFmt, skcms_AlphaFormat srcAlpha, const skcms_ICCProfile *srcProfile, void *dst, skcms_PixelFormat dstFmt, skcms_AlphaFormat dstAlpha, const skcms_ICCProfile *dstProfile, size_t nz)
Definition: skcms.cc:2495
@ skcms_PixelFormat_RGBA_ffff
Definition: skcms_public.h:317
@ skcms_PixelFormat_BGRA_8888
Definition: skcms_public.h:288
@ skcms_AlphaFormat_Unpremul
Definition: skcms_public.h:339
@ skcms_AlphaFormat_PremulAsEncoded
Definition: skcms_public.h:341