skia2/tests/NonlinearBlendingTest.cpp
Brian Osman c3186302bd Add skcms directory to public includes
skcms is part of Skia's public API now. This attempts to recognize that,
and pave the way for moving the header to another location more easily
in a follow up CL, or - at a minimum - for clients that redistribute
Skia as a library + includes to relocate the skcms.h header as part of
that.

Change-Id: I15da63b0d4ab8916a71fb7e6ab3656db87252707
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209640
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-04-22 20:32:23 +00:00

71 lines
2.7 KiB
C++

/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "skcms.h"
#include "SkColorSpace.h"
#include "SkColorSpaceXformSteps.h"
#include "Test.h"
DEF_TEST(SkColorSpaceXformSteps_vs_skcms, r) {
auto srgb = SkColorSpace::MakeSRGB();
auto dp3 = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
skcms_ICCProfile srgb_profile;
srgb->toProfile(&srgb_profile);
skcms_ICCProfile dp3_profile;
dp3->toProfile(&dp3_profile);
// These colors provide a good spread of interesting test cases.
SkColor colors[] = {
0xffff0000, 0x7fff0000, 0x7f7f0000,
0xff00ff00, 0x7f00ff00, 0x7f007f00,
};
for (auto color : colors) {
auto bgra = skcms_PixelFormat_BGRA_8888,
f32 = skcms_PixelFormat_RGBA_ffff;
auto unpremul = skcms_AlphaFormat_Unpremul,
premul = skcms_AlphaFormat_PremulAsEncoded;
float via_skcms[4];
skcms_Transform(&color, bgra, unpremul, &srgb_profile,
&via_skcms, f32, premul, &dp3_profile,
1);
SkColorSpaceXformSteps steps(srgb.get(), kUnpremul_SkAlphaType,
dp3.get(), kPremul_SkAlphaType);
float via_steps[4] = {
SkColorGetR(color) * (1 / 255.0f),
SkColorGetG(color) * (1 / 255.0f),
SkColorGetB(color) * (1 / 255.0f),
SkColorGetA(color) * (1 / 255.0f),
};
steps.apply(via_steps);
REPORTER_ASSERT(r, fabsf(via_skcms[0] - via_steps[0]) <= 0.005f);
REPORTER_ASSERT(r, fabsf(via_skcms[1] - via_steps[1]) <= 0.005f);
REPORTER_ASSERT(r, fabsf(via_skcms[2] - via_steps[2]) <= 0.005f);
REPORTER_ASSERT(r, fabsf(via_skcms[3] - via_steps[3]) <= 0.0f);
// Now go back using the other method's inverse transform
float steps_to_skcms[4];
skcms_Transform(via_steps, f32, premul, &dp3_profile,
steps_to_skcms, f32, premul, &srgb_profile,
1);
float skcms_to_steps[4] = { via_skcms[0], via_skcms[1], via_skcms[2], via_skcms[3] };
SkColorSpaceXformSteps inv_steps(dp3.get(), kPremul_SkAlphaType,
srgb.get(), kPremul_SkAlphaType);
inv_steps.apply(skcms_to_steps);
REPORTER_ASSERT(r, fabsf(skcms_to_steps[0] - steps_to_skcms[0]) <= 0.005f);
REPORTER_ASSERT(r, fabsf(skcms_to_steps[1] - steps_to_skcms[1]) <= 0.005f);
REPORTER_ASSERT(r, fabsf(skcms_to_steps[2] - steps_to_skcms[2]) <= 0.005f);
REPORTER_ASSERT(r, fabsf(skcms_to_steps[3] - steps_to_skcms[3]) <= 0.0f);
}
}