Add utilities for programmatically making profiles
These are trivial, but some image decoders or other code may need them.
Change-Id: Ia646711c85d2eac6eef3d90cc5c27df5afac930a
Reviewed-on: https://skia-review.googlesource.com/127120
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/skcms.h b/skcms.h
index 79d0abf..0451a58 100644
--- a/skcms.h
+++ b/skcms.h
@@ -16,6 +16,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
+#include <string.h>
#ifdef __cplusplus
extern "C" {
@@ -238,6 +239,28 @@
float wx, float wy,
skcms_Matrix3x3* toXYZD50);
+// Utilities for programmatically constructing profiles
+static inline void skcms_Init(skcms_ICCProfile* p) {
+ memset(p, 0, sizeof(*p));
+ p->data_color_space = skcms_Signature_RGB;
+ p->pcs = skcms_Signature_XYZ;
+}
+
+static inline void skcms_SetTransferFunction(skcms_ICCProfile* p,
+ const skcms_TransferFunction* tf) {
+ p->has_trc = true;
+ for (int i = 0; i < 3; ++i) {
+ p->trc[i].table_entries = 0;
+ p->trc[i].parametric = *tf;
+ p->has_poly_tf[i] = false;
+ }
+}
+
+static inline void skcms_SetXYZD50(skcms_ICCProfile* p, const skcms_Matrix3x3* m) {
+ p->has_toXYZD50 = true;
+ p->toXYZD50 = *m;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/tests.c b/tests.c
index 15d3c02..7a38533 100644
--- a/tests.c
+++ b/tests.c
@@ -1149,6 +1149,23 @@
}
}
+static void test_Programmatic_sRGB() {
+ skcms_Matrix3x3 srgb_to_xyz;
+ expect(skcms_PrimariesToXYZD50(0.64f, 0.33f,
+ 0.30f, 0.60f,
+ 0.15f, 0.06f,
+ 0.3127f, 0.3290f,
+ &srgb_to_xyz));
+ skcms_ICCProfile srgb = *skcms_sRGB_profile();
+
+ skcms_ICCProfile p;
+ skcms_Init(&p);
+ skcms_SetTransferFunction(&p, &srgb.trc[0].parametric);
+ skcms_SetXYZD50(&p, &srgb_to_xyz);
+
+ expect(skcms_ApproximatelyEqualProfiles(&p, &srgb));
+}
+
int main(int argc, char** argv) {
bool regenTestData = false;
for (int i = 1; i < argc; ++i) {
@@ -1180,6 +1197,7 @@
test_AlmostLinear2();
test_AlmostLinear3();
test_PrimariesToXYZ();
+ test_Programmatic_sRGB();
#if 0
test_CLUT();
#endif