aboutsummaryrefslogtreecommitdiffstats
path: root/color.h
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2017-09-12 11:09:32 -0700
committerH. Peter Anvin <hpa@zytor.com>2017-09-12 11:09:32 -0700
commitb92ea995371cec99e0366f6a341ca1e35e1f7211 (patch)
treef08e567905df6042e137faeb22f41ae3185eaa6b /color.h
downloadledcolor-b92ea995371cec99e0366f6a341ca1e35e1f7211.tar.gz
ledcolor-b92ea995371cec99e0366f6a341ca1e35e1f7211.tar.xz
ledcolor-b92ea995371cec99e0366f6a341ca1e35e1f7211.zip
Initial snapshot under version control
Diffstat (limited to 'color.h')
-rw-r--r--color.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/color.h b/color.h
new file mode 100644
index 0000000..e4811c4
--- /dev/null
+++ b/color.h
@@ -0,0 +1,62 @@
+#ifndef COLOR_H
+#define COLOR_H
+
+#include <stddef.h>
+#include <stdbool.h>
+#include <math.h>
+#include <inttypes.h>
+
+/*
+ * CIE xy is a chromatic-only colorspace without intensity
+ */
+struct cie_xy {
+ double x; /* x chromacity */
+ double y; /* y chromacity */
+};
+
+/*
+ * CIE XYZ is an intensity-weighted colorspace
+ */
+struct cie_XYZ {
+ double X; /* X weighted chromacity */
+ double Y; /* Intensity */
+ double Z; /* Z weighted chromacity */
+};
+
+/*
+ * CIE L*u*v* is close-to-linear-in-hue color space suitable for gradients;
+ * it is NOT additive for different intensities (Y coordinates)
+ */
+struct cie_Luv {
+ double L; /* L*, relative intensity, 0 ≤ L* ≤ 100 */
+ double u; /* u*, -100 ≤ u* ≤ 100 */
+ double v; /* v*, -100 ≤ v* ≤ 100 */
+};
+
+/*
+ * RGB as a floating-point vector
+ */
+struct RGB {
+ double R, G, B;
+};
+
+#ifdef __GNUC__
+# define const_func __attribute__((const))
+# define pure_func __attribute__((pure))
+#else
+# define const_func
+# define pure_func
+#endif
+
+struct cie_xy const_func XYZ_to_xy(struct cie_XYZ XYZ);
+struct cie_XYZ const_func xyY_to_XYZ(struct cie_xy xy, double Y);
+struct cie_Luv const_func XYZ_to_Luv(struct cie_XYZ XYZ, struct cie_XYZ white);
+struct cie_XYZ const_func Luv_to_XYZ(struct cie_Luv Luv, struct cie_XYZ white);
+struct cie_xy pure_func spectral(double nm);
+struct cie_XYZ pure_func planckian(double T);
+struct RGB const_func XYZ_to_RGB(struct cie_XYZ XYZ);
+struct cie_XYZ const_func RGB_to_XYZ(struct RGB RGB);
+struct RGB const_func XYZ_to_sRGB(struct cie_XYZ XYZ);
+struct cie_XYZ sRGB_to_XYZ(struct RGB sRGB);
+
+#endif /* COLOR_H */