blob: cf7560228fdf8704f32d52725ac50af87f495291 [file] [log] [blame]
msarett6a738212016-03-04 13:27:35 -08001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "Resources.h"
9#include "SkCodec.h"
10#include "SkColorSpace.h"
11#include "Test.h"
12
13static SkStreamAsset* resource(const char path[]) {
14 SkString fullPath = GetResourcePath(path);
15 return SkStream::NewFromFile(fullPath.c_str());
16}
17
18static bool almost_equal(float a, float b) {
19 return SkTAbs(a - b) < 0.0001f;
20}
21
22DEF_TEST(ColorSpaceParseICCProfile, r) {
23 SkAutoTDelete<SkStream> stream(resource("color_wheel_with_profile.png"));
24 REPORTER_ASSERT(r, nullptr != stream);
25
26 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
27 REPORTER_ASSERT(r, nullptr != codec);
28
29 SkColorSpace* colorSpace = codec->getColorSpace();
30 REPORTER_ASSERT(r, nullptr != colorSpace);
31
32 // No need to use almost equal here. The color profile that we have extracted
33 // actually has a table of gammas. And our current implementation guesses 2.2f.
34 SkFloat3 gammas = colorSpace->gamma();
35 REPORTER_ASSERT(r, 2.2f == gammas.fVec[0]);
36 REPORTER_ASSERT(r, 2.2f == gammas.fVec[1]);
37 REPORTER_ASSERT(r, 2.2f == gammas.fVec[2]);
38
39 // These nine values were extracted from the color profile in isolation (before
40 // we embedded it in the png). Here we check that we still extract the same values.
41 SkFloat3x3 xyz = colorSpace->xyz();
42 REPORTER_ASSERT(r, almost_equal(0.436066f, xyz.fMat[0]));
43 REPORTER_ASSERT(r, almost_equal(0.222488f, xyz.fMat[1]));
44 REPORTER_ASSERT(r, almost_equal(0.013916f, xyz.fMat[2]));
45 REPORTER_ASSERT(r, almost_equal(0.385147f, xyz.fMat[3]));
46 REPORTER_ASSERT(r, almost_equal(0.716873f, xyz.fMat[4]));
47 REPORTER_ASSERT(r, almost_equal(0.0970764f, xyz.fMat[5]));
48 REPORTER_ASSERT(r, almost_equal(0.143066f, xyz.fMat[6]));
49 REPORTER_ASSERT(r, almost_equal(0.0606079f, xyz.fMat[7]));
50 REPORTER_ASSERT(r, almost_equal(0.714096f, xyz.fMat[8]));
51}