aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-12-16 06:19:37 +0100
committerMattias Andrée <maandree@kth.se>2016-12-16 06:19:37 +0100
commitf2fcb2d3ddcb8177f820f964c6efc0a046d7cc8c (patch)
treefc1d44e9a6bcc1d3953ec9b162d49615a3f0a5ad /src
parentSplit out conversion to convert.c (diff)
downloadlibcolour-f2fcb2d3ddcb8177f820f964c6efc0a046d7cc8c.tar.gz
libcolour-f2fcb2d3ddcb8177f820f964c6efc0a046d7cc8c.tar.bz2
libcolour-f2fcb2d3ddcb8177f820f964c6efc0a046d7cc8c.tar.xz
srgb_to_srgb: use static inline version of libcolour_srgb_{encode,decode}
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--src/convert.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/convert.c b/src/convert.c
index 455d434..0ca9ef1 100644
--- a/src/convert.c
+++ b/src/convert.c
@@ -133,18 +133,28 @@ static void ciexyz_to_srgb(const libcolour_ciexyz_t* restrict from, libcolour_sr
to->B = 0.0556434 * X + -0.204026 * Y + 1.0572300 * Z;
}
+static inline double srgb_encode(double x)
+{
+ return x <= 0.0031306684425217108 ? 12.92 * x : 1.055 * pow(x, 1 / 2.4) - 0.055;
+}
+
+static inline double srgb_decode(double x)
+{
+ return x <= 0.040448236277380506 ? x / 12.92 : pow((x + 0.055) / 1.055, 2.4);
+}
+
static void srgb_to_srgb(const libcolour_srgb_t* restrict from, libcolour_srgb_t* restrict to)
{
if (from->with_gamma == to->with_gamma) {
*to = *from;
} else if (to->with_gamma) {
- to->R = libcolour_srgb_encode(from->R);
- to->G = libcolour_srgb_encode(from->G);
- to->B = libcolour_srgb_encode(from->B);
+ to->R = srgb_encode(from->R);
+ to->G = srgb_encode(from->G);
+ to->B = srgb_encode(from->B);
} else {
- to->R = libcolour_srgb_decode(from->R);
- to->G = libcolour_srgb_decode(from->G);
- to->B = libcolour_srgb_decode(from->B);
+ to->R = srgb_decode(from->R);
+ to->G = srgb_decode(from->G);
+ to->B = srgb_decode(from->B);
}
}