aboutsummaryrefslogtreecommitdiffstats
path: root/en_masse-template.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-06-14 21:04:36 +0200
committerMattias Andrée <maandree@kth.se>2017-06-14 21:04:36 +0200
commit2baa9bd9cd9a5365b6b826de2377a6a29ff1dd3b (patch)
tree8c8ab45dc0a1dd9f9127f40acd6626b1ca19235c /en_masse-template.c
parentUpdate todo (diff)
downloadlibcolour-2baa9bd9cd9a5365b6b826de2377a6a29ff1dd3b.tar.gz
libcolour-2baa9bd9cd9a5365b6b826de2377a6a29ff1dd3b.tar.bz2
libcolour-2baa9bd9cd9a5365b6b826de2377a6a29ff1dd3b.tar.xz
Add YES colour model, generate the conversion matrices, and add more direct conversions
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'en_masse-template.c')
-rw-r--r--en_masse-template.c154
1 files changed, 86 insertions, 68 deletions
diff --git a/en_masse-template.c b/en_masse-template.c
index b539328..e131188 100644
--- a/en_masse-template.c
+++ b/en_masse-template.c
@@ -55,6 +55,27 @@
}\
} while (0)
+#define DEFAULT_CONVERSION(FROM, TO)\
+ case LIBCOLOUR_##FROM:\
+ conversion_by_matrix(XARGUMENTS, FROM##_TO_##TO);\
+ break
+
+#define DEFAULT_CONVERSION_FROM_SRGB(TO)\
+ case LIBCOLOUR_SRGB:\
+ LINEAR_SRGB;\
+ conversion_by_matrix(XARGUMENTS, SRGB_TO_##TO);\
+ break
+
+#define DEFAULT_CONV_0(FROM, TO)\
+ case LIBCOLOUR_##FROM:\
+ CONV_0(FROM##_TO_##TO);\
+ break
+
+#define DEFAULT_CONV_N(FROM, TO, ...)\
+ case LIBCOLOUR_##FROM:\
+ CONV_N(FROM##_TO_##TO, __VA_ARGS__);\
+ break
+
#define X(C, T, N) static void to_##N(const libcolour_colour_t *from, const T *to, XPARAMETERS);
@@ -221,12 +242,16 @@ to_srgb(PARAMETERS(colour, srgb))
{
libcolour_srgb_t tmp;
switch (from->model) {
+ DEFAULT_CONVERSION(YCGCO, SRGB);
+ DEFAULT_CONVERSION(YDBDR, SRGB);
+ DEFAULT_CONVERSION(YES, SRGB);
+ DEFAULT_CONVERSION(YIQ, SRGB);
+ DEFAULT_CONVERSION(YUV, SRGB);
+ DEFAULT_CONV_0(YPBPR, SRGB);
default:
to_ciexyz(ARGUMENTS(from, NULL));
/* fall through */
- case LIBCOLOUR_CIEXYZ:
- conversion_by_matrix(XARGUMENTS, CIEXYZ_TO_SRGB);
- break;
+ DEFAULT_CONVERSION(CIEXYZ, SRGB);
case LIBCOLOUR_SRGB:
srgb_to_srgb:
if (from->srgb.with_transfer != to->with_transfer) {
@@ -241,21 +266,6 @@ to_srgb(PARAMETERS(colour, srgb))
}
}
return;
- case LIBCOLOUR_YIQ:
- conversion_by_matrix(XARGUMENTS, YIQ_TO_SRGB);
- break;
- case LIBCOLOUR_YDBDR:
- conversion_by_matrix(XARGUMENTS, YDBDR_TO_SRGB);
- break;
- case LIBCOLOUR_YPBPR:
- CONV_0(YPBPR_TO_SRGB);
- break;
- case LIBCOLOUR_YUV:
- conversion_by_matrix(XARGUMENTS, YUV_TO_SRGB);
- break;
- case LIBCOLOUR_YCGCO:
- conversion_by_matrix(XARGUMENTS, YCGCO_TO_SRGB);
- break;
}
if (to->with_transfer) {
tmp = *to;
@@ -317,6 +327,12 @@ to_ciexyz(PARAMETERS(colour, ciexyz))
{
libcolour_colour_t tmp;
switch (from->model) {
+ DEFAULT_CONVERSION(YCGCO, CIEXYZ);
+ DEFAULT_CONVERSION(YDBDR, CIEXYZ);
+ DEFAULT_CONVERSION(YES, CIEXYZ);
+ DEFAULT_CONVERSION(YIQ, CIEXYZ);
+ DEFAULT_CONVERSION(YPBPR, CIEXYZ);
+ DEFAULT_CONVERSION(YUV, CIEXYZ);
case LIBCOLOUR_RGB:
if (from->rgb.with_transfer) {
tmp.rgb = from->rgb;
@@ -331,10 +347,7 @@ to_ciexyz(PARAMETERS(colour, ciexyz))
to_srgb(ARGUMENTS(from, &tmp.srgb));
from = (const void *)&tmp.srgb;
/* fall through */
- case LIBCOLOUR_SRGB:
- LINEAR_SRGB;
- conversion_by_matrix(XARGUMENTS, SRGB_TO_CIEXYZ);
- break;
+ DEFAULT_CONVERSION_FROM_SRGB(CIEXYZ);
case LIBCOLOUR_CIEXYY:
CONV_0(CIEXYY_TO_CIEXYZ);
break;
@@ -352,21 +365,6 @@ to_ciexyz(PARAMETERS(colour, ciexyz))
case LIBCOLOUR_CIELUV:
CONV_N(CIELUV_TO_CIEXYZ, from->cieluv.white.X, from->cieluv.white.Y, from->cieluv.white.Z);
break;
- case LIBCOLOUR_YIQ:
- conversion_by_matrix(XARGUMENTS, YIQ_TO_CIEXYZ);
- break;
- case LIBCOLOUR_YDBDR:
- conversion_by_matrix(XARGUMENTS, YDBDR_TO_CIEXYZ);
- break;
- case LIBCOLOUR_YUV:
- conversion_by_matrix(XARGUMENTS, YUV_TO_CIEXYZ);
- break;
- case LIBCOLOUR_YPBPR:
- conversion_by_matrix(XARGUMENTS, YPBPR_TO_CIEXYZ);
- break;
- case LIBCOLOUR_YCGCO:
- conversion_by_matrix(XARGUMENTS, YCGCO_TO_CIEXYZ);
- break;
case LIBCOLOUR_CIEUVW:
tmp.cie1960ucs.model = LIBCOLOUR_CIE1960UCS;
to_cie1960ucs(ARGUMENTS(from, &tmp.cie1960ucs));
@@ -477,18 +475,18 @@ static void
to_yiq(PARAMETERS(colour, yiq))
{
switch (from->model) {
+ DEFAULT_CONVERSION_FROM_SRGB(YIQ);
+ DEFAULT_CONVERSION(YCGCO, YIQ);
+ DEFAULT_CONVERSION(YDBDR, YIQ);
+ DEFAULT_CONVERSION(YES, YIQ);
+ DEFAULT_CONVERSION(YPBPR, YIQ);
+ DEFAULT_CONVERSION(YUV, YIQ);
case LIBCOLOUR_YIQ:
break;
- case LIBCOLOUR_SRGB:
- LINEAR_SRGB;
- conversion_by_matrix(XARGUMENTS, SRGB_TO_YIQ);
- break;
default:
to_ciexyz(ARGUMENTS(from, NULL));
/* fall through */
- case LIBCOLOUR_CIEXYZ:
- conversion_by_matrix(XARGUMENTS, CIEXYZ_TO_YIQ);
- break;
+ DEFAULT_CONVERSION(CIEXYZ, YIQ);
}
}
@@ -497,21 +495,20 @@ static void
to_ydbdr(PARAMETERS(colour, ydbdr))
{
switch (from->model) {
+ DEFAULT_CONVERSION_FROM_SRGB(YDBDR);
+ DEFAULT_CONVERSION(YCGCO, YDBDR);
+ DEFAULT_CONVERSION(YES, YDBDR);
+ DEFAULT_CONVERSION(YIQ, YDBDR);
+ DEFAULT_CONVERSION(YPBPR, YDBDR);
case LIBCOLOUR_YDBDR:
break;
- case LIBCOLOUR_SRGB:
- LINEAR_SRGB;
- conversion_by_matrix(XARGUMENTS, SRGB_TO_YDBDR);
- break;
case LIBCOLOUR_YUV:
CONV_0(YUV_TO_YDBDR);
break;
default:
to_ciexyz(ARGUMENTS(from, NULL));
/* fall through */
- case LIBCOLOUR_CIEXYZ:
- conversion_by_matrix(XARGUMENTS, CIEXYZ_TO_YDBDR);
- break;
+ DEFAULT_CONVERSION(CIEXYZ, YDBDR);
}
}
@@ -520,21 +517,20 @@ static void
to_yuv(PARAMETERS(colour, yuv))
{
switch (from->model) {
+ DEFAULT_CONVERSION_FROM_SRGB(YUV);
+ DEFAULT_CONVERSION(YCGCO, YUV);
+ DEFAULT_CONVERSION(YES, YUV);
+ DEFAULT_CONVERSION(YIQ, YUV);
+ DEFAULT_CONVERSION(YPBPR, YUV);
case LIBCOLOUR_YUV:
break;
case LIBCOLOUR_YDBDR:
CONV_0(YDBDR_TO_YUV);
break;
- case LIBCOLOUR_SRGB:
- LINEAR_SRGB;
- conversion_by_matrix(XARGUMENTS, SRGB_TO_YUV);
- break;
default:
to_ciexyz(ARGUMENTS(from, NULL));
/* fall through */
- case LIBCOLOUR_CIEXYZ:
- conversion_by_matrix(XARGUMENTS, CIEXYZ_TO_YUV);
- break;
+ DEFAULT_CONVERSION(CIEXYZ, YUV);
}
}
@@ -543,6 +539,11 @@ static void
to_ypbpr(PARAMETERS(colour, ypbpr))
{
switch (from->model) {
+ DEFAULT_CONVERSION(YCGCO, YPBPR);
+ DEFAULT_CONVERSION(YDBDR, YPBPR);
+ DEFAULT_CONVERSION(YES, YPBPR);
+ DEFAULT_CONVERSION(YIQ, YPBPR);
+ DEFAULT_CONVERSION(YUV, YPBPR);
case LIBCOLOUR_YPBPR:
break;
case LIBCOLOUR_SRGB:
@@ -552,9 +553,7 @@ to_ypbpr(PARAMETERS(colour, ypbpr))
default:
to_ciexyz(ARGUMENTS(from, NULL));
/* fall through */
- case LIBCOLOUR_CIEXYZ:
- conversion_by_matrix(XARGUMENTS, CIEXYZ_TO_YPBPR);
- break;
+ DEFAULT_CONVERSION(CIEXYZ, YPBPR);
}
}
@@ -563,18 +562,18 @@ static void
to_ycgco(PARAMETERS(colour, ycgco))
{
switch (from->model) {
+ DEFAULT_CONVERSION_FROM_SRGB(YCGCO);
+ DEFAULT_CONVERSION(YDBDR, YCGCO);
+ DEFAULT_CONVERSION(YES, YCGCO);
+ DEFAULT_CONVERSION(YIQ, YCGCO);
+ DEFAULT_CONVERSION(YPBPR, YCGCO);
+ DEFAULT_CONVERSION(YUV, YCGCO);
case LIBCOLOUR_YCGCO:
break;
- case LIBCOLOUR_SRGB:
- LINEAR_SRGB;
- conversion_by_matrix(XARGUMENTS, SRGB_TO_YCGCO);
- break;
default:
to_ciexyz(ARGUMENTS(from, NULL));
/* fall through */
- case LIBCOLOUR_CIEXYZ:
- conversion_by_matrix(XARGUMENTS, CIEXYZ_TO_YCGCO);
- break;
+ DEFAULT_CONVERSION(CIEXYZ, YCGCO);
}
}
@@ -614,6 +613,25 @@ to_cieuvw(PARAMETERS(colour, cieuvw))
}
}
+static void
+to_yes(PARAMETERS(colour, yes))
+{
+ switch (from->model) {
+ DEFAULT_CONVERSION_FROM_SRGB(YES);
+ DEFAULT_CONVERSION(YCGCO, YES);
+ DEFAULT_CONVERSION(YDBDR, YES);
+ DEFAULT_CONVERSION(YIQ, YES);
+ DEFAULT_CONVERSION(YPBPR, YES);
+ DEFAULT_CONVERSION(YUV, YES);
+ case LIBCOLOUR_YES:
+ break;
+ default:
+ to_ciexyz(ARGUMENTS(from, NULL));
+ /* fall through */
+ DEFAULT_CONVERSION(CIEXYZ, YES);
+ }
+}
+
int
libcolour_convert_en_masse(const libcolour_colour_t *from, const libcolour_colour_t *to,