aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-12-03 00:33:38 +0100
committerMattias Andrée <maandree@kth.se>2016-12-03 00:34:45 +0100
commite3a73188e077bdbb713843baa628ea0d4ffd28ee (patch)
treee61755118f12e4de6a56b284fd58c7168857520f /src
parentAdd libclut_model_rgb_to_ciexyz and libclut_model_ciexyz_to_rgb (diff)
downloadlibclut-e3a73188e077bdbb713843baa628ea0d4ffd28ee.tar.gz
libclut-e3a73188e077bdbb713843baa628ea0d4ffd28ee.tar.bz2
libclut-e3a73188e077bdbb713843baa628ea0d4ffd28ee.tar.xz
Fix bugs
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
-rw-r--r--src/libclut.h46
-rw-r--r--src/test.c86
2 files changed, 91 insertions, 41 deletions
diff --git a/src/libclut.h b/src/libclut.h
index 7c0dcd8..dbf3a00 100644
--- a/src/libclut.h
+++ b/src/libclut.h
@@ -2091,8 +2091,8 @@ void (libclut_model_cielch_to_cieluv)(double, double, double*, double*);
do \
{ \
double h__ = (h), C__ = (C); \
- *(u) = sin(h__) * C__; \
- *(v) = cos(h__) * C__; \
+ *(v) = sin(h__) * C__; \
+ *(u) = cos(h__) * C__; \
} \
while (0)
@@ -2112,9 +2112,9 @@ void (libclut_model_cieluv_to_cielch)(double, double, double*, double*);
#define libclut_model_cieluv_to_cielch(u, v, C, h) \
do \
{ \
- double u__ = (u), v__ = (v__); \
+ double u__ = (u), v__ = (v); \
*(C) = sqrt(u__ * u__ + v__ * v__); \
- *(h) = atan2(u__, v__); \
+ *(h) = atan2(v__, u__); \
} \
while (0)
@@ -2134,16 +2134,16 @@ void (libclut_model_cieluv_to_cielch)(double, double, double*, double*);
*/
LIBCLUT_GCC_ONLY__(__attribute__((__leaf__)))
void (libclut_model_srgb_to_yiq)(double, double, double, double*, double*, double*);
-#define libclut_model_srgb_to_yiq(r, g, b, y, i, q) \
- do \
- { \
- double r__ = libclut_model_standard_to_linear1(r); \
- double g__ = libclut_model_standard_to_linear1(g); \
- double b__ = libclut_model_standard_to_linear1(b); \
- *(y) = r__ * 299 / 1000 + g__ * 587 / 1000 + b__ * 114 / 1000; \
- *(i) = r__ * 596 / 1000 - g__ * 247 / 1000 - b__ * 322 / 1000; \
- *(q) = r__ * 211 / 1000 - g__ * 523 / 1000 + b__ * 312 / 1000; \
- } \
+#define libclut_model_srgb_to_yiq(r, g, b, y, i, q) \
+ do \
+ { \
+ double r__ = libclut_model_standard_to_linear1(r) / 100000000000000000ULL; \
+ double g__ = libclut_model_standard_to_linear1(g) / 10000000000000000ULL; \
+ double b__ = libclut_model_standard_to_linear1(b) / 100000000000000000ULL; \
+ *(y) = r__ * 29893602129377540ULL + g__ * 5870430744511212ULL + b__ * 11402090425510336ULL; \
+ *(i) = r__ * 59594574307079930ULL - g__ * 2743886357457892ULL - b__ * 32155710732501010ULL; \
+ *(q) = r__ * 21149734030682846ULL - g__ * 5229106903029739ULL + b__ * 31141334999614540ULL; \
+ } \
while (0)
@@ -2166,7 +2166,7 @@ void (libclut_model_yiq_to_srgb)(double, double, double, double*, double*, doubl
do \
{ \
double y__ = (y), i__ = (i), q__ = (q), r__, g__, b__; \
- r__ = y__ + i__ * 596 / 1000 + q__ * 621 / 1000; \
+ r__ = y__ + i__ * 956 / 1000 + q__ * 621 / 1000; \
g__ = y__ - i__ * 272 / 1000 - q__ * 647 / 1000; \
b__ = y__ - i__ * 1106 / 1000 + q__ * 1703 / 1000; \
*(r) = libclut_model_linear_to_standard1(r__); \
@@ -2404,14 +2404,14 @@ void (libclut_model_ycgco_to_srgb)(double, double, double, double*, double*, dou
*/
LIBCLUT_GCC_ONLY__(__attribute__((__leaf__)))
void (libclut_model_cie_1960_ucs_to_ciexyz)(double, double, double, double*, double*, double*);
-#define libclut_model_cie_1960_ucs_to_ciexyz(u, v, Y, x, y, z) \
- do \
- { \
- double u__ = (u), v__ = (v), y__ = (Y); \
- *(y) = y__; \
- *(x) = 3 * y__ * u__ / (2 * v__); \
- *(z) = y__ * ((4 - u__) / (2 * v__) - 1) / 5; \
- } \
+#define libclut_model_cie_1960_ucs_to_ciexyz(u, v, Y, x, y, z) \
+ do \
+ { \
+ double u__ = (u), v__ = (v), y__ = (Y); \
+ *(y) = y__; \
+ *(x) = 3 * y__ * u__ / (2 * v__); \
+ *(z) = (4 * y__ - y__ * u__ - 10 * y__ * v__) / (2 * v__); \
+ } \
while (0)
diff --git a/src/test.c b/src/test.c
index 28e8e7d..970780f 100644
--- a/src/test.c
+++ b/src/test.c
@@ -438,24 +438,74 @@ int main(int argc, char *argv[])
rgb_conversion_done:
- libclut_model_ciexyz_to_cieluv(1, 1, 1, 1, 1, 1, &r, &g, &b); /* TODO test */
- libclut_model_cieluv_to_ciexyz(1, 1, 1, 1, 1, 1, &r, &g, &b); /* TODO test */
- libclut_model_cielch_to_cieluv(1, 1, &r, &g); /* TODO test */
- libclut_model_cieluv_to_cielch(1, 1, &r, &g); /* TODO test */
- libclut_model_srgb_to_yiq(1, 1, 1, &r, &g, &b); /* TODO test */
- libclut_model_yiq_to_srgb(1, 1, 1, &r, &g, &b); /* TODO test */
- libclut_model_srgb_to_ydbdr(1, 1, 1, &r, &g, &b); /* TODO test */
- libclut_model_ydbdr_to_srgb(1, 1, 1, &r, &g, &b); /* TODO test */
- libclut_model_yuv_to_ydbdr(1, 1, &r, &g); /* TODO test */
- libclut_model_ydbdr_to_yuv(1, 1, &r, &g); /* TODO test */
- libclut_model_srgb_to_ypbpr(1, 1, 1, &r, &g, &b); /* TODO test */
- libclut_model_ypbpr_to_srgb(1, 1, 1, &r, &g, &b); /* TODO test */
- libclut_model_srgb_to_ycgco(1, 1, 1, &r, &g, &b); /* TODO test */
- libclut_model_ycgco_to_srgb(1, 1, 1, &r, &g, &b); /* TODO test */
- libclut_model_cie_1960_ucs_to_ciexyz(1, 1, 1, &r, &g, &b); /* TODO test */
- libclut_model_ciexyz_to_cie_1960_ucs(1, 1, 1, &r, &g, &b); /* TODO test */
- libclut_model_cieuvw_to_cie_1960_ucs(1, 1, 1, 1, 1, &r, &g, &b); /* TODO test */
- libclut_model_cie_1960_ucs_to_cieuvw(1, 1, 1, 1, 1, &r, &g, &b); /* TODO test */
+ libclut_model_ciexyz_to_cieluv(0.4, 1.0, 0.7, 0.33, 1, 0.32, &x, &y, &z); /* TODO test */
+ libclut_model_cieluv_to_ciexyz(x, y, z, 0.33, 1, 0.32, &x, &y, &z);
+ if (0.3999 > x || x > 0.4001 ||
+ 0.9999 > y || y > 1.0001 ||
+ 0.6999 > z || z > 0.7001)
+ printf("libclut_model_cieluv_to_ciexyz failed\n"), rc = 1;
+
+
+ libclut_model_cieluv_to_cielch(0.5, 0.6, &r, &g); /* TODO test */
+ libclut_model_cielch_to_cieluv(r, g, &r, &g);
+ if (0.4999 > r || r > 0.5001 ||
+ 0.5999 > g || g > 0.6001)
+ printf("libclut_model_cielch_to_cieluv failed\n"), rc = 1;
+
+
+ libclut_model_srgb_to_yiq(0.1, 0.6, 0.9, &r, &g, &b); /* TODO test */
+ libclut_model_yiq_to_srgb(r, g, b, &r, &g, &b);
+ if (0.0999 > r || r > 0.1001 ||
+ 0.5999 > g || g > 0.6001 ||
+ 0.8999 > b || b > 0.9001)
+ printf("libclut_model_yiq_to_srgb failed\n"), rc = 1;
+
+
+ libclut_model_srgb_to_ydbdr(0.1, 0.6, 0.9, &r, &g, &b); /* TODO test */
+ libclut_model_ydbdr_to_srgb(r, g, b, &r, &g, &b);
+ if (0.0999 > r || r > 0.1001 ||
+ 0.5999 > g || g > 0.6001 ||
+ 0.8999 > b || b > 0.9001)
+ printf("libclut_model_ydbdr_to_srgb failed\n"), rc = 1;
+
+
+ libclut_model_ydbdr_to_yuv(0.1, 0.6, &r, &g); /* TODO test */
+ libclut_model_yuv_to_ydbdr(r, g, &r, &g);
+ if (0.0999 > r || r > 0.1001 ||
+ 0.5999 > g || g > 0.6001)
+ printf("libclut_model_yuv_to_ydbdr failed\n"), rc = 1;
+
+
+ libclut_model_srgb_to_ypbpr(0.1, 0.6, 0.9, &r, &g, &b); /* TODO test */
+ libclut_model_ypbpr_to_srgb(r, g, b, &r, &g, &b);
+ if (0.0999 > r || r > 0.1001 ||
+ 0.5999 > g || g > 0.6001 ||
+ 0.8999 > b || b > 0.9001)
+ printf("libclut_model_ypbpr_to_srgb failed\n"), rc = 1;
+
+
+ libclut_model_srgb_to_ycgco(0.1, 0.6, 0.9, &r, &g, &b); /* TODO test */
+ libclut_model_ycgco_to_srgb(r, g, b, &r, &g, &b);
+ if (0.0999 > r || r > 0.1001 ||
+ 0.5999 > g || g > 0.6001 ||
+ 0.8999 > b || b > 0.9001)
+ printf("libclut_model_ycgco_to_srgb failed\n"), rc = 1;
+
+
+ libclut_model_ciexyz_to_cie_1960_ucs(0.4, 0.7, 0.6, &x, &y, &z); /* TODO test */
+ libclut_model_cie_1960_ucs_to_ciexyz(x, y, z, &x, &y, &z);
+ if (0.3999 > x || x > 0.4001 ||
+ 0.6999 > y || y > 0.7001 ||
+ 0.5999 > z || z > 0.6001)
+ printf("libclut_model_cie_1960_ucs_to_ciexyz failed\n"), rc = 1;
+
+
+ libclut_model_cie_1960_ucs_to_cieuvw(0.1, 0.7, 0.9, 0.3, 0.4, &x, &y, &z); /* TODO test */
+ libclut_model_cieuvw_to_cie_1960_ucs(x, y, z, 0.3, 0.4, &x, &y, &z);
+ if (0.0999 > x || x > 0.1001 ||
+ 0.6999 > y || y > 0.7001 ||
+ 0.8999 > z || z > 0.9001)
+ printf("libclut_model_cieuvw_to_cie_1960_ucs failed\n"), rc = 1;
if (!rc)