8 #ifndef SkColorSpace_DEFINED
9 #define SkColorSpace_DEFINED
13 #include "include/private/base/SkFixed.h"
14 #include "include/private/base/SkOnce.h"
15 #include "modules/skcms/skcms.h"
39 bool toXYZD50(skcms_Matrix3x3* toXYZD50)
const;
45 static constexpr skcms_TransferFunction
kSRGB =
46 { 2.4f, (float)(1/1.055), (float)(0.055/1.055), (float)(1/12.92), 0.04045f, 0.0f, 0.0f };
48 static constexpr skcms_TransferFunction
k2Dot2 =
49 { 2.2f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
51 static constexpr skcms_TransferFunction
kLinear =
52 { 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
54 static constexpr skcms_TransferFunction
kRec2020 =
55 {2.22222f, 0.909672f, 0.0903276f, 0.222222f, 0.0812429f, 0, 0};
57 static constexpr skcms_TransferFunction
kPQ =
58 {-2.0f, -107/128.0f, 1.0f, 32/2523.0f, 2413/128.0f, -2392/128.0f, 8192/1305.0f };
60 static constexpr skcms_TransferFunction
kHLG =
61 {-3.0f, 2.0f, 2.0f, 1/0.17883277f, 0.28466892f, 0.55991073f, 0.0f };
67 static constexpr skcms_Matrix3x3
kSRGB = {{
72 { SkFixedToFloat(0x6FA2), SkFixedToFloat(0x6299), SkFixedToFloat(0x24A0) },
73 { SkFixedToFloat(0x38F5), SkFixedToFloat(0xB785), SkFixedToFloat(0x0F84) },
74 { SkFixedToFloat(0x0390), SkFixedToFloat(0x18DA), SkFixedToFloat(0xB6CF) },
82 { SkFixedToFloat(0x9c18), SkFixedToFloat(0x348d), SkFixedToFloat(0x2631) },
83 { SkFixedToFloat(0x4fa5), SkFixedToFloat(0xa02c), SkFixedToFloat(0x102f) },
84 { SkFixedToFloat(0x04fc), SkFixedToFloat(0x0f95), SkFixedToFloat(0xbe9c) },
88 { 0.515102f, 0.291965f, 0.157153f },
89 { 0.241182f, 0.692236f, 0.0665819f },
90 { -0.00104941f, 0.0418818f, 0.784378f },
94 { 0.673459f, 0.165661f, 0.125100f },
95 { 0.279033f, 0.675338f, 0.0456288f },
96 { -0.00193139f, 0.0299794f, 0.797162f },
99 static constexpr skcms_Matrix3x3
kXYZ = {{
100 { 1.0f, 0.0f, 0.0f },
101 { 0.0f, 1.0f, 0.0f },
102 { 0.0f, 0.0f, 1.0f },
123 const skcms_Matrix3x3& toXYZ);
222 uint64_t
hash()
const {
return (uint64_t)fTransferFnHash << 32 | fToXYZD50Hash; }
225 friend class SkColorSpaceSingletonFactory;
227 SkColorSpace(
const skcms_TransferFunction& transferFn,
const skcms_Matrix3x3& toXYZ);
229 void computeLazyDstFields()
const;
231 uint32_t fTransferFnHash;
232 uint32_t fToXYZD50Hash;
234 skcms_TransferFunction fTransferFn;
235 skcms_Matrix3x3 fToXYZD50;
237 mutable skcms_TransferFunction fInvTransferFn;
238 mutable skcms_Matrix3x3 fFromXYZD50;
239 mutable SkOnce fLazyDstFieldsOnce;
Definition: SkColorSpace.h:107
static sk_sp< SkColorSpace > MakeSRGBLinear()
Colorspace with the sRGB primaries, but a linear (1.0) gamma.
bool gammaIsLinear() const
Returns true if the color space gamma is linear.
static sk_sp< SkColorSpace > MakeRGB(const skcms_TransferFunction &transferFn, const skcms_Matrix3x3 &toXYZ)
Create an SkColorSpace from a transfer function and a row-major 3x3 transformation to XYZ.
sk_sp< SkColorSpace > makeSRGBGamma() const
Returns a color space with the same gamut as this one, but with the sRGB transfer function.
sk_sp< SkColorSpace > makeLinearGamma() const
Returns a color space with the same gamut as this one, but with a linear gamma.
bool gammaCloseToSRGB() const
Returns true if the color space gamma is near enough to be approximated as sRGB.
uint64_t hash() const
Definition: SkColorSpace.h:222
static sk_sp< SkColorSpace > Deserialize(const void *data, size_t length)
void toProfile(skcms_ICCProfile *) const
Convert this color space to an skcms ICC profile struct.
bool isNumericalTransferFn(skcms_TransferFunction *fn) const
Sets |fn| to the transfer function from this color space.
static bool Equals(const SkColorSpace *, const SkColorSpace *)
If both are null, we return true.
sk_sp< SkColorSpace > makeColorSpin() const
Returns a color space with the same transfer function as this one, but with the primary colors rotate...
void transferFn(skcms_TransferFunction *fn) const
bool toXYZD50(skcms_Matrix3x3 *toXYZD50) const
Returns true and sets |toXYZD50|.
void invTransferFn(skcms_TransferFunction *fn) const
void gamutTransformTo(const SkColorSpace *dst, skcms_Matrix3x3 *src_to_dst) const
static sk_sp< SkColorSpace > MakeSRGB()
Create the sRGB color space.
static sk_sp< SkColorSpace > Make(const skcms_ICCProfile &)
Create an SkColorSpace from a parsed (skcms) ICC profile.
void transferFn(float gabcdef[7]) const
size_t writeToMemory(void *memory) const
If |memory| is nullptr, returns the size required to serialize.
uint32_t toXYZD50Hash() const
Returns a hash of the gamut transformation to XYZ D50.
Definition: SkColorSpace.h:161
sk_sp< SkData > serialize() const
Returns a serialized representation of this color space.
uint32_t transferFnHash() const
Definition: SkColorSpace.h:221
bool isSRGB() const
Returns true if the color space is sRGB.
SkData holds an immutable data buffer.
Definition: SkData.h:25
Definition: SkRefCnt.h:160
Definition: SkColorSpace.h:65
static constexpr skcms_Matrix3x3 kSRGB
Definition: SkColorSpace.h:67
static constexpr skcms_Matrix3x3 kAdobeRGB
Definition: SkColorSpace.h:77
static constexpr skcms_Matrix3x3 kXYZ
Definition: SkColorSpace.h:99
static constexpr skcms_Matrix3x3 kRec2020
Definition: SkColorSpace.h:93
static constexpr skcms_Matrix3x3 kDisplayP3
Definition: SkColorSpace.h:87
Definition: SkColorSpace.h:42
static constexpr skcms_TransferFunction kRec2020
Definition: SkColorSpace.h:54
static constexpr skcms_TransferFunction k2Dot2
Definition: SkColorSpace.h:48
static constexpr skcms_TransferFunction kSRGB
Definition: SkColorSpace.h:45
static constexpr skcms_TransferFunction kHLG
Definition: SkColorSpace.h:60
static constexpr skcms_TransferFunction kPQ
Definition: SkColorSpace.h:57
static constexpr skcms_TransferFunction kLinear
Definition: SkColorSpace.h:51
Describes a color gamut with primaries and a white point.
Definition: SkColorSpace.h:25
float fBY
Definition: SkColorSpace.h:31
float fRY
Definition: SkColorSpace.h:27
float fWX
Definition: SkColorSpace.h:32
float fBX
Definition: SkColorSpace.h:30
float fRX
Definition: SkColorSpace.h:26
float fWY
Definition: SkColorSpace.h:33
float fGX
Definition: SkColorSpace.h:28
float fGY
Definition: SkColorSpace.h:29
bool toXYZD50(skcms_Matrix3x3 *toXYZD50) const
Convert primaries and a white point to a toXYZD50 matrix, the preferred color gamut representation of...