From 52bdacb940488a1e8d5182687ecc890d607e7a98 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 10 Jun 2017 14:48:58 +0200 Subject: m + add libcolour_convert_en_masse.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- README | 4 ++ en_masse-template.c | 32 ++++++---- libcolour.7.in | 4 ++ libcolour_convert.3 | 9 +-- libcolour_convert_en_masse.3 | 147 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 181 insertions(+), 15 deletions(-) create mode 100644 libcolour_convert_en_masse.3 diff --git a/README b/README index 010b0b9..f0e1455 100644 --- a/README +++ b/README @@ -224,6 +224,10 @@ FUNCTIONS libcolour_convert(3) Colour space and colour model conversion. + libcolour_convert_en_masse(3) + Colour space and colour model conversion for many + colours. + libcolour_srgb_encode(3) Apply the sRGB transfer function. diff --git a/en_masse-template.c b/en_masse-template.c index 127d766..7869d23 100644 --- a/en_masse-template.c +++ b/en_masse-template.c @@ -26,9 +26,9 @@ libcolour_convert_en_masse(const libcolour_colour_t *from, const libcolour_colou int on_cpu = mode & LIBCOLOUR_CONVERT_EN_MASSE_ON_CPU; int no_override = mode & LIBCOLOUR_CONVERT_EN_MASSE_NO_OVERRIDE; va_list args; - TYPE *in1, *in2, *in3; - TYPE *out1, *out2, *out3; - size_t width; + TYPE *in1, *in2, *in3, *in_alpha = NULL; + TYPE *out1, *out2, *out3, *out_alpha = NULL; + size_t width, i; if ((unsigned int)mode > 15U) { errno = EINVAL; @@ -47,15 +47,16 @@ libcolour_convert_en_masse(const libcolour_colour_t *from, const libcolour_colou in3 = in1 + 2; width = 3; } else if (alpha_mode == LIBCOLOUR_CONVERT_EN_MASSE_ALPHA_FIRST) { - in1 = va_arg(args, TYPE *); - in2 = in1 + 2; - in3 = in1 + 3; - in1 = in1 + 1; + in_alpha = va_arg(args, TYPE *); + in1 = in_alpha + 1; + in2 = in_alpha + 2; + in3 = in_alpha + 3; width = 4; } else if (alpha_mode == LIBCOLOUR_CONVERT_EN_MASSE_ALPHA_LAST) { in1 = va_arg(args, TYPE *); in2 = in1 + 1; in3 = in1 + 2; + in_alpha = in1 + 3; width = 4; } else { in1 = va_arg(args, TYPE *); @@ -73,14 +74,15 @@ libcolour_convert_en_masse(const libcolour_colour_t *from, const libcolour_colou out2 = out1 + 1; out3 = out1 + 2; } else if (alpha_mode == LIBCOLOUR_CONVERT_EN_MASSE_ALPHA_FIRST) { - out1 = va_arg(args, TYPE *); - out2 = out1 + 2; - out3 = out1 + 3; - out1 = out1 + 1; + out_alpha = va_arg(args, TYPE *); + out1 = out_alpha + 1; + out2 = out_alpha + 2; + out3 = out_alpha + 3; } else if (alpha_mode == LIBCOLOUR_CONVERT_EN_MASSE_ALPHA_LAST) { out1 = va_arg(args, TYPE *); out2 = out1 + 1; out3 = out1 + 2; + out_alpha = out1 + 3; } else { out1 = va_arg(args, TYPE *); out2 = va_arg(args, TYPE *); @@ -107,6 +109,14 @@ libcolour_convert_en_masse(const libcolour_colour_t *from, const libcolour_colou return -1; } + if (in_alpha != out_alpha) { + for (i = 0; i < n; i++) { + *out_alpha = *in_alpha; + in_alpha += width; + out_alpha += width; + } + } + while (n--) { tfrom.rgb.R = *in1; tfrom.rgb.G = *in2; diff --git a/libcolour.7.in b/libcolour.7.in index 2e0d385..57e2b40 100644 --- a/libcolour.7.in +++ b/libcolour.7.in @@ -366,6 +366,10 @@ Philips TL83, Ultralume 30. .BR libcolour_convert (3) Colour space and colour model conversion. .TP +.BR libcolour_convert_en_masse (3) +Colour space and colour model conversion +for many colours. +.TP .BR libcolour_srgb_encode (3) Apply the sRGB transfer function. .TP diff --git a/libcolour_convert.3 b/libcolour_convert.3 index 1dccc0a..ca9d598 100644 --- a/libcolour_convert.3 +++ b/libcolour_convert.3 @@ -14,9 +14,9 @@ int \fBlibcolour_convert_llf\fP(const libcolour_colour_llf_t *restrict \fIfrom\f #define \fBlibcolour_convert\fP(\fIfrom\fP, \fIto\fP)\\ (_Generic((\fIfrom\fP),\\ - libcolour_colour_f_t *: \fBlibcolour_convert_f\fP(\fIcolour\fP),\\ - libcolour_colour_lf_t *: \fBlibcolour_convert_lf\fP(\fIcolour\fP),\\ - libcolour_colour_llf_t *: \fBlibcolour_convert_llf\fP(\fIcolour\fP))) + libcolour_colour_f_t *: \fBlibcolour_convert_f\fP(\fIfrom\fP, \fIto\fP),\\ + libcolour_colour_lf_t *: \fBlibcolour_convert_lf\fP(\fIfrom\fP, \fIto\fP),\\ + libcolour_colour_llf_t *: \fBlibcolour_convert_llf\fP(\fIfrom\fP, \fIto\fP))) /* list is incomplete */ .fi .SH DESCRIPTION @@ -57,7 +57,8 @@ and .I to most use the same floating-point type. .SH SEE ALSO -.BR libcolour (7) +.BR libcolour (7), +.BR libcolour_convert_en_masse (3) .SH AUTHORS Mattias Andrée .RI < maandree@kth.se > diff --git a/libcolour_convert_en_masse.3 b/libcolour_convert_en_masse.3 new file mode 100644 index 0000000..011013a --- /dev/null +++ b/libcolour_convert_en_masse.3 @@ -0,0 +1,147 @@ +.TH LIBCOLOUR_CONVERT_EN_MASSE 3 libcolour +.SH NAME +libcolour_convert_en_masse - Colour space and colour model conversion for many colours +.SH SYNOPSIS +.nf +#include + +int \fBlibcolour_convert_en_masse_f\fP(const libcolour_colour_f_t *restrict \fIfrom\fP, + const libcolour_colour_f_t *restrict \fIto\fP, + libcolour_convert_en_masse_mode_t \fImode\fP, + size_t \fIn\fP, ...); +int \fBlibcolour_convert_en_masse_lf\fP(const libcolour_colour_lf_t *restrict \fIfrom\fP, + const libcolour_colour_lf_t *restrict \fIto\fP, + libcolour_convert_en_masse_mode_t \fImode\fP, + size_t \fIn\fP, ...); +int \fBlibcolour_convert_en_masse_llf\fP(const libcolour_colour_llf_t *restrict \fIfrom\fP, + const libcolour_colour_llf_t *restrict \fIto\fP, + libcolour_convert_en_masse_mode_t \fImode\fP, + size_t \fIn\fP, ...); + +#define \fBlibcolour_convert_en_masse\fP(\fIfrom\fP, \fIto\fP, \fImode\fP, \fIn\fP, ...)\\ + (_Generic((\fIfrom\fP),\\ + const libcolour_colour_f_t *:\\ + \fBlibcolour_convert_en_masse_f\fP(\fIfrom\fP, \fIto\fP, \fImode\fP, \fIn\fP, __VA_ARGS__),\\ + const libcolour_colour_lf_t *:\\ + \fBlibcolour_convert_en_masse_lf\fP(\fIfrom\fP, \fIto\fP, \fImode\fP, \fIn\fP, __VA_ARGS__),\\ + const libcolour_colour_llf_t *:\\ + \fBlibcolour_convert_en_masse_llf\fP(\fIfrom\fP, \fIto\fP, \fImode\fP, \fIn\fP, __VA_ARGS__))) + /* list is incomplete */ +.fi +.SH DESCRIPTION +.B libcolour_convert_en_masse +and its non-generic functions converts +.I n +colours from the colour space and transfer function +specified in +.I from +to the colour space and transfer function specified in +.IR to . +.I mode +specifies the behaviour of the functions. It shall +be the +.B OR +the any, or none, of the following values: +.TP +.B LIBCOLOUR_CONVERT_EN_MASSE_ON_CPU +Perform convertion on CPU rather than on GPU. +.TP +.B LIBCOLOUR_CONVERT_EN_MASSE_NO_OVERRIDE +Output parameters are listed after input parameters, +rather than using the input parametrs as the +output parameters. These will have the same type +as the input parameters. +.P +and one of the following values: +.TP +.B LIBCOLOUR_CONVERT_EN_MASSE_NO_ALPHA +The parameter after +.I n +is +.BR float\ * , +.BR double\ * , +or +.BR long\ double\ * , +depending of the which function is called. +The argument shall be the values of the colour, +without any alpha channel, repeated +.I n +times (once per colour). +For example, if +.BI ( from->model ==LIBCOLOUR_RGB) +and if +.BI ( n ==2) +the values in the pointer shall be +.BI { colour[0].red , +.IB colour[0].green , +.IB colour[0].blue , +.IB colour[1].red , +.IB colour[1].green , +.IB colour[1].blue } +for an imaginary +.BR libcolour_rgb_f_t \ \fIcolour[2]\fP, +.BR libcolour_rgb_lf_t \ \fIcolour[2]\fP, +or +.BR libcolour_rgb_llf_t \ \fIcolour[2]\fP, +depending on which function is called. +.TP +.B LIBCOLOUR_CONVERT_EN_MASSE_ALPHA_FIRST +Same as +.BR LIBCOLOUR_CONVERT_EN_MASSE_NO_ALPHA , +except before each red channel value (in the +case of RGB that is, the first channel value in +general) there is an alpha channel value that +will not be modified. +.TP +.B LIBCOLOUR_CONVERT_EN_MASSE_ALPHA_LAST +Same as +.BR LIBCOLOUR_CONVERT_EN_MASSE_NO_ALPHA , +except after each blue channel value (in the +case of RGB that is, the last cannel value in +general) there is an alpha channel value that +will not be modified. +.TP +.B LIBCOLOUR_CONVERT_EN_MASSE_SEPARATED +After the parameter +.I n +there is one parameter per channel, these +parameters are of the type +.BR float\ * , +.BR double\ * , +or +.BR long\ double\ * , +depending of the which function is called. +Each parameter shall be a pointer with +.I n +elements, one per colour to convert. +.SH RETURN VALUES +Upon successful completion, the functions returns 0. +Otherwise the function return -1 with +.I errno +set to indicate the error. +.SH ERRORS +.TP +.B EINVAL +.I from->model +or +.I to->model +does not refer to a recognised colour model. +.SH NOTES +.B libcolour_convert_en_masse +cannot convert between +.BR float , +.BR double , +and +.BR long\ double , +.I from +and +.I to +most use the same floating-point type. +.P +GPU acceleration is currently not implemented. +.SH SEE ALSO +.BR libcolour (7), +.BR libcolour_convert (3) +.SH AUTHORS +Mattias Andrée +.RI < maandree@kth.se > -- cgit v1.2.3-70-g09d2