diff options
author | Mattias Andrée <maandree@kth.se> | 2016-12-11 00:45:07 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2016-12-11 01:26:12 +0100 |
commit | 4d029d3ee5f18e41610224f11436534364f81546 (patch) | |
tree | 0fe038bf37b49b5abb01df86e296321af9e0f01f /src | |
parent | misc (diff) | |
download | libcolour-4d029d3ee5f18e41610224f11436534364f81546.tar.gz libcolour-4d029d3ee5f18e41610224f11436534364f81546.tar.bz2 libcolour-4d029d3ee5f18e41610224f11436534364f81546.tar.xz |
Add libcolour_marshal and libcolour_unmarshal
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
-rw-r--r-- | src/libcolour.c | 84 | ||||
-rw-r--r-- | src/libcolour.h | 23 |
2 files changed, 104 insertions, 3 deletions
diff --git a/src/libcolour.c b/src/libcolour.c index 32ef6c8..5ed8ba8 100644 --- a/src/libcolour.c +++ b/src/libcolour.c @@ -24,6 +24,10 @@ +#define MARSHAL_VERSION 0 + + + #define WASDIV0(x) (isinf(x) || isnan(x)) @@ -1052,6 +1056,27 @@ static int invert(double **Minv, double **M, size_t n) } +static void get_transfer_function(libcolour_colour_t* cs) +{ + if (cs->model == LIBCOLOUR_RGB) { + switch (cs->rgb.colour_space) { + case LIBCOLOUR_RGB_COLOUR_SPACE_ECI_RGB_V2: /* TODO L* */ + break; + case LIBCOLOUR_RGB_COLOUR_SPACE_ITU_R_BT_2100_EOTF_PQ: + case LIBCOLOUR_RGB_COLOUR_SPACE_ITU_R_BT_2100_OOTF_PQ: + case LIBCOLOUR_RGB_COLOUR_SPACE_ITU_R_BT_2100_OETF_PQ: + case LIBCOLOUR_RGB_COLOUR_SPACE_ITU_R_BT_2100_EOTF_HLG: + case LIBCOLOUR_RGB_COLOUR_SPACE_ITU_R_BT_2100_OOTF_HLG: + case LIBCOLOUR_RGB_COLOUR_SPACE_ITU_R_BT_2100_OETF_HLG: + /* TODO http://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-0-201607-I!!PDF-E.pdf */ + break; + default: + break; + } + } +} + + int libcolour_get_rgb_colour_space(libcolour_colour_t* cs_, libcolour_rgb_colour_space_t space) { #define XYY(XVALUE, YVALUE) (libcolour_ciexyy_t){ .model = LIBCOLOUR_CIEXYY, .x = XVALUE, .y = YVALUE, .Y = 1} @@ -1181,7 +1206,7 @@ int libcolour_get_rgb_colour_space(libcolour_colour_t* cs_, libcolour_rgb_colour cs->green = XYY(0.2100, 0.7100); cs->blue = XYY(0.1400, 0.0800); cs->white = LIBCOLOUR_ILLUMINANT_D50; - cs->encoding_type = LIBCOLOUR_ENCODING_TYPE_CUSTOM; /* TODO L* */ + cs->encoding_type = LIBCOLOUR_ENCODING_TYPE_CUSTOM; break; case LIBCOLOUR_RGB_COLOUR_SPACE_EKTA_SPACE_PS5: @@ -1252,7 +1277,6 @@ int libcolour_get_rgb_colour_space(libcolour_colour_t* cs_, libcolour_rgb_colour cs->blue = XYY(0.1310, 0.0460); cs->white = LIBCOLOUR_ILLUMINANT_D65; cs->encoding_type = LIBCOLOUR_ENCODING_TYPE_CUSTOM; - /* TODO http://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-0-201607-I!!PDF-E.pdf */ break; case LIBCOLOUR_RGB_COLOUR_SPACE_LIGHTROOM_RGB: @@ -1348,7 +1372,63 @@ int libcolour_get_rgb_colour_space(libcolour_colour_t* cs_, libcolour_rgb_colour cs->white_r = cs->white_g = cs->white_b = 1; if (get_matrices(cs) || libcolour_proper(cs_)) return -1; + get_transfer_function(cs_); return 0; #undef XYY } + + +size_t libcolour_marshal(const libcolour_colour_t* colour, void* buf) +{ + if (buf) + *(int*)buf = MARSHAL_VERSION; + switch (colour->model) { +#define X(C, T)\ + case C:\ + if (buf)\ + memcpy((char*)buf + sizeof(int), colour, sizeof(T));\ + return sizeof(int) + sizeof(T); + LIBCOLOUR_LIST_MODELS +#undef X + default: + errno = EINVAL; + return 0; + } +} + + +size_t libcolour_unmarshal(libcolour_colour_t* colour, const void* buf) +{ + enum libcolour_model model; + size_t r; + int ver; + ver = *(int*)buf; + if (ver != MARSHAL_VERSION) { + errno = EINVAL; + return 0; + } + model = *(enum libcolour_model*)((char*)buf + sizeof(int)); + switch (model) { +#define X(C, T)\ + case C:\ + if (colour)\ + memcpy(colour, (char*)buf + sizeof(int), sizeof(T));\ + r = sizeof(int) + sizeof(T);\ + break; + LIBCOLOUR_LIST_MODELS +#undef X + default: + errno = EINVAL; + return 0; + } + if (colour) { + if (colour->model == LIBCOLOUR_RGB) { + colour->rgb.to_encoded_red = colour->rgb.to_encoded_green = colour->rgb.to_encoded_blue = NULL; + colour->rgb.to_decoded_red = colour->rgb.to_decoded_green = colour->rgb.to_decoded_blue = NULL; + } + get_transfer_function(colour); + } + return r; +} + diff --git a/src/libcolour.h b/src/libcolour.h index b780c71..2bc2f0e 100644 --- a/src/libcolour.h +++ b/src/libcolour.h @@ -18,6 +18,9 @@ #define LIBCOLOUR_H +#include <stddef.h> + + union libcolour_colour; @@ -44,6 +47,23 @@ union libcolour_colour; #define LIBCOLOUR_ILLUMINANT_F12 (libcolour_ciexyy_t){.model = LIBCOLOUR_CIEXYY, .x = 0.43695, .y = 0.40441, .Y = 1} +#define LIBCOLOUR_LIST_MODELS\ + X(LIBCOLOUR_RGB, libcolour_rgb_t)\ + X(LIBCOLOUR_SRGB, libcolour_srgb_t)\ + X(LIBCOLOUR_CIEXYY, libcolour_ciexyy_t)\ + X(LIBCOLOUR_CIEXYZ, libcolour_ciexyz_t)\ + X(LIBCOLOUR_CIELAB, libcolour_cielab_t)\ + X(LIBCOLOUR_CIELUV, libcolour_cieluv_t)\ + X(LIBCOLOUR_CIELCH, libcolour_cielch_t)\ + X(LIBCOLOUR_YIQ, libcolour_yiq_t)\ + X(LIBCOLOUR_YDBDR, libcolour_ydbdr_t)\ + X(LIBCOLOUR_YUV, libcolour_yuv_t)\ + X(LIBCOLOUR_YPBPR, libcolour_ypbpr_t)\ + X(LIBCOLOUR_YCGCO, libcolour_ycgco_t)\ + X(LIBCOLOUR_CIE1960UCS, libcolour_cie1960ucs_t)\ + X(LIBCOLOUR_CIEUVW, libcolour_cieuvw_t) + + typedef enum libcolour_model { LIBCOLOUR_RGB, LIBCOLOUR_SRGB, @@ -264,7 +284,8 @@ double libcolour_srgb_decode(double); int libcolour_delta_e(const libcolour_colour_t*, const libcolour_colour_t*, double*); int libcolour_proper(libcolour_colour_t*); int libcolour_get_rgb_colour_space(libcolour_colour_t*, libcolour_rgb_colour_space_t); -/* TODO (un)marshal */ +size_t libcolour_marshal(const libcolour_colour_t*, void*); +size_t libcolour_unmarshal(libcolour_colour_t*, const void*); |