aboutsummaryrefslogtreecommitdiff
path: root/include/core/SkColorSpace.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/core/SkColorSpace.h')
-rw-r--r--include/core/SkColorSpace.h65
1 files changed, 64 insertions, 1 deletions
diff --git a/include/core/SkColorSpace.h b/include/core/SkColorSpace.h
index 26771f3ce1..6013c2a308 100644
--- a/include/core/SkColorSpace.h
+++ b/include/core/SkColorSpace.h
@@ -8,13 +8,14 @@
#ifndef SkColorSpace_DEFINED
#define SkColorSpace_DEFINED
+#include "../private/SkFixed.h"
#include "../private/SkOnce.h"
+#include "../../third_party/skcms/skcms.h"
#include "SkMatrix44.h"
#include "SkRefCnt.h"
#include <memory>
class SkData;
-struct skcms_ICCProfile;
enum SkGammaNamed {
kLinear_SkGammaNamed,
@@ -41,6 +42,8 @@ struct SK_API SkColorSpacePrimaries {
* representation of SkColorSpace.
*/
bool toXYZD50(SkMatrix44* toXYZD50) const;
+
+ bool toXYZD50(skcms_Matrix3x3* toXYZD50) const;
};
/**
@@ -62,6 +65,56 @@ struct SK_API SkColorSpaceTransferFn {
float fF;
};
+namespace SkNamedTransferFn {
+
+// Like SkNamedGamut::kSRGB, keeping this bitwise exactly the same as skcms makes things fastest.
+static constexpr skcms_TransferFunction kSRGB =
+ { 2.4f, (float)(1/1.055), (float)(0.055/1.055), (float)(1/12.92), 0.04045f, 0.0f, 0.0f };
+
+static constexpr skcms_TransferFunction k2Dot2 =
+ { 2.2f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
+
+static constexpr skcms_TransferFunction kLinear =
+ { 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
+
+}
+
+namespace SkNamedGamut {
+
+static constexpr skcms_Matrix3x3 kSRGB = {{
+ // ICC fixed-point (16.16) representation, taken from skcms. Please keep them exactly in sync.
+ // 0.436065674f, 0.385147095f, 0.143066406f,
+ // 0.222488403f, 0.716873169f, 0.060607910f,
+ // 0.013916016f, 0.097076416f, 0.714096069f,
+ { SkFixedToFloat(0x6FA2), SkFixedToFloat(0x6299), SkFixedToFloat(0x24A0) },
+ { SkFixedToFloat(0x38F5), SkFixedToFloat(0xB785), SkFixedToFloat(0x0F84) },
+ { SkFixedToFloat(0x0390), SkFixedToFloat(0x18DA), SkFixedToFloat(0xB6CF) },
+}};
+
+static constexpr skcms_Matrix3x3 kAdobeRGB = {{
+ // ICC fixed-point (16.16) repesentation of:
+ // 0.60974, 0.20528, 0.14919,
+ // 0.31111, 0.62567, 0.06322,
+ // 0.01947, 0.06087, 0.74457,
+ { SkFixedToFloat(0x9c18), SkFixedToFloat(0x348d), SkFixedToFloat(0x2631) },
+ { SkFixedToFloat(0x4fa5), SkFixedToFloat(0xa02c), SkFixedToFloat(0x102f) },
+ { SkFixedToFloat(0x04fc), SkFixedToFloat(0x0f95), SkFixedToFloat(0xbe9c) },
+}};
+
+static constexpr skcms_Matrix3x3 kDCIP3 = {{
+ { 0.515102f, 0.291965f, 0.157153f },
+ { 0.241182f, 0.692236f, 0.0665819f },
+ { -0.00104941f, 0.0418818f, 0.784378f },
+}};
+
+static constexpr skcms_Matrix3x3 kRec2020 = {{
+ { 0.673459f, 0.165661f, 0.125100f, },
+ { 0.279033f, 0.675338f, 0.0456288f },
+ { -0.00193139f, 0.0299794f, 0.797162f },
+}};
+
+}
+
class SK_API SkColorSpace : public SkNVRefCnt<SkColorSpace> {
public:
/**
@@ -107,6 +160,12 @@ public:
static sk_sp<SkColorSpace> MakeRGB(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50);
/**
+ * Create an SkColorSpace from a transfer function and a row-major 3x3 transformation to XYZ.
+ */
+ static sk_sp<SkColorSpace> MakeRGB(const skcms_TransferFunction& transferFn,
+ const skcms_Matrix3x3& toXYZ);
+
+ /**
* Create an SkColorSpace from a parsed (skcms) ICC profile.
*/
static sk_sp<SkColorSpace> Make(const skcms_ICCProfile&);
@@ -136,12 +195,16 @@ public:
*/
bool isNumericalTransferFn(SkColorSpaceTransferFn* fn) const;
+ bool isNumericalTransferFn(skcms_TransferFunction* fn) const;
+
/**
* Returns true and sets |toXYZD50| if the color gamut can be described as a matrix.
* Returns false otherwise.
*/
bool toXYZD50(SkMatrix44* toXYZD50) const;
+ bool toXYZD50(skcms_Matrix3x3* toXYZD50) const;
+
/**
* Returns a hash of the gamut transformation to XYZ D50. Allows for fast equality checking
* of gamuts, at the (very small) risk of collision.