1/*
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#ifndef SkColorSpace_DEFINED
9#define SkColorSpace_DEFINED
10
11// Some terms
12//
13//  PCS : Profile Connection Space : where color number values have an absolute meaning.
14//        Part of the work float is to convert colors to and from this space...
15//        src_linear_unit_floats --> PCS --> PCS' --> dst_linear_unit_floats
16//
17// Some nice documents
18//
19// http://www.cambridgeincolour.com/tutorials/color-space-conversion.htm
20// https://www.w3.org/Graphics/Color/srgb
21// http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html
22//
23
24#include "SkRefCnt.h"
25
26struct SkFloat3 {
27    float fVec[3];
28
29    void dump() const;
30};
31
32struct SkFloat3x3 {
33    float fMat[9];
34
35    void dump() const;
36};
37
38struct SkPM4f;
39void SkApply3x3ToPM4f(const SkFloat3x3&, const SkPM4f src[], SkPM4f dst[], int count);
40
41class SkColorSpace : public SkRefCnt {
42public:
43    enum Named {
44        kUnknown_Named,
45        kDevice_Named,
46        kSRGB_Named,
47    };
48
49    /**
50     *  Return a colorspace instance, given a 3x3 transform from linear_RGB to D50_XYZ
51     *  and the src-gamma, return a ColorSpace
52     */
53    static SkColorSpace* NewRGB(const SkFloat3x3& toXYZD50, const SkFloat3& gamma);
54
55    static SkColorSpace* NewNamed(Named);
56    static SkColorSpace* NewICC(const void*, size_t);
57
58    SkFloat3 gamma() const { return fGamma; }
59    Named named() const { return fNamed; }
60    uint32_t uniqueID() const { return fUniqueID; }
61
62    enum Result {
63        kFailure_Result,
64        kIdentity_Result,
65        kNormal_Result,
66    };
67
68    /**
69     *  Given a src and dst colorspace, return the 3x3 matrix that will convert src_linear_RGB
70     *  values into dst_linear_RGB values.
71     */
72    static Result Concat(const SkColorSpace* src, const SkColorSpace* dst, SkFloat3x3* result);
73
74    static void Test();
75    void dump() const;
76
77protected:
78    SkColorSpace(const SkFloat3x3& toXYZ, const SkFloat3& gamma, Named);
79
80private:
81    const SkFloat3x3 fToXYZD50;
82    const SkFloat3   fGamma;
83    const uint32_t   fUniqueID;
84    const Named      fNamed;
85};
86
87#endif
88