skia2/tests/ICCTest.cpp
Brian Osman 8dc68c67f8 Make skcms mandatory
Change-Id: I6b08cd586d313e3bc41c0da90698fc26ae1a8bb8
Reviewed-on: https://skia-review.googlesource.com/130822
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2018-05-30 17:37:49 +00:00

70 lines
2.4 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#include "Resources.h"
#include "SkColorSpacePriv.h"
#include "SkICC.h"
#include "SkString.h"
#include "Test.h"
#include "../third_party/skcms/skcms.h"
DEF_TEST(WriteICCProfile, r) {
auto adobeRGB = SkColorSpace::MakeRGB(g2Dot2_TransferFn, SkColorSpace::kAdobeRGB_Gamut);
struct {
SkColorSpaceTransferFn fn;
const float* toXYZD50;
const char* desc;
sk_sp<SkColorSpace> want;
} tests[] = {
{g2Dot2_TransferFn, gAdobeRGB_toXYZD50, "AdobeRGB", adobeRGB},
{ gSRGB_TransferFn, gSRGB_toXYZD50, "sRGB", SkColorSpace::MakeSRGB()},
};
for (auto test : tests) {
sk_sp<SkData> profile = SkWriteICCProfile(test.fn, test.toXYZD50);
REPORTER_ASSERT(r, profile);
skcms_ICCProfile parsed;
REPORTER_ASSERT(r, skcms_Parse(profile->data(), profile->size(), &parsed));
sk_sp<SkColorSpace> got = SkColorSpace::Make(parsed);
REPORTER_ASSERT(r, got);
REPORTER_ASSERT(r, SkColorSpace::Equals(got.get(), test.want.get()));
skcms_ICCTag desc;
REPORTER_ASSERT(r, skcms_GetTagBySignature(&parsed,
SkSetFourByteTag('d','e','s','c'),
&desc));
// Rather than really carefully break down the 'desc' tag,
// just check our expected description is somewhere in there (as big-endian UTF-16).
uint8_t big_endian_utf16[16];
for (size_t i = 0; i < strlen(test.desc); i++) {
big_endian_utf16[2*i+0] = 0;
big_endian_utf16[2*i+1] = test.desc[i];
}
SkString haystack((const char*)desc.buf, desc.size),
needle ((const char*)big_endian_utf16, 2*strlen(test.desc));
REPORTER_ASSERT(r, haystack.contains(needle.c_str()));
}
}
DEF_TEST(AdobeRGB, r) {
if (sk_sp<SkData> profile = GetResourceAsData("icc_profiles/AdobeRGB1998.icc")) {
skcms_ICCProfile parsed;
REPORTER_ASSERT(r, skcms_Parse(profile->data(), profile->size(), &parsed));
auto got = SkColorSpace::Make(parsed);
auto want = SkColorSpace::MakeRGB(g2Dot2_TransferFn, SkColorSpace::kAdobeRGB_Gamut);
REPORTER_ASSERT(r, SkColorSpace::Equals(got.get(), want.get()));
}
}