From 15e3ff763c33cb309dd07cfab98312de3375e630 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 4 Jan 2016 21:24:59 +0100 Subject: dedup ciexyy_to_srgb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blackbody.c | 5 ++++- src/parse_10deg.c | 33 +++------------------------------ 2 files changed, 7 insertions(+), 31 deletions(-) diff --git a/src/blackbody.c b/src/blackbody.c index 1fb3689..70b58db 100644 --- a/src/blackbody.c +++ b/src/blackbody.c @@ -14,6 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#ifndef LIBRED_COMPILING_PARSER #include "libred.h" #include "macros.h" #include @@ -21,7 +22,6 @@ #include - /** * The file descriptor to the colour lookup table. */ @@ -56,6 +56,7 @@ void libred_term_colour(void) } +#endif /** * Convert from CIE xyY to [0, 1] sRGB. * @@ -84,6 +85,7 @@ static void ciexyy_to_srgb(double x, double y, double Y, double *r, double *g, d /* Convert [0, 1] linear RGB to [0, 1] sRGB. */ SRGB(*r), SRGB(*g), SRGB(*b); } +#ifndef LIBRED_COMPILING_PARSER /** @@ -159,4 +161,5 @@ int libred_get_colour(long int temp, double *r, double *g, double *b) fail: return -1; } +#endif diff --git a/src/parse_10deg.c b/src/parse_10deg.c index f1e2c81..c78851e 100644 --- a/src/parse_10deg.c +++ b/src/parse_10deg.c @@ -29,36 +29,9 @@ -/** - * Convert from CIE xyY to [0, 1] sRGB. - * - * This function is identical to that in 'blackbody.c'. - * - * @param x The 'x' component. - * @param y The 'y' component. - * @param Y The 'Y' component. - * @param r Output parameter for the “red” value. - * (Seriously, sRGB red is orange, just look at it fullscreen.) - * @param g Output parameter for the green value. - * @param b Output parameter for the blue value. - */ -static void ciexyy_to_srgb(double x, double y, double Y, double *r, double *g, double *b) -{ -#define SRGB(C) (((C) <= 0.0031308) ? (12.92 * (C)) : ((1.0 + 0.055) * pow((C), 1.0 / 2.4) - 0.055)) - double X, Z; - - /* Convert CIE xyY to CIE XYZ. */ - X = Y * (y == 0.0 ? 0.0 : (x / y)); - Z = Y * (y == 0.0 ? 0.0 : ((1.0 - x - y) / y)); - - /* Convert CIE XYZ to [0, 1] linear RGB. (ciexyz_to_linear) */ - *r = ( 3.240450 * X) + (-1.537140 * Y) + (-0.4985320 * Z); - *g = (-0.969266 * X) + ( 1.876010 * Y) + ( 0.0415561 * Z); - *b = (0.0556434 * X) + (-0.204026 * Y) + ( 1.0572300 * Z); - - /* Convert [0, 1] linear RGB to [0, 1] sRGB. */ - SRGB(*r), SRGB(*g), SRGB(*b); -} +#define LIBRED_COMPILING_PARSER +#include "blackbody.c" + /** -- cgit v1.2.3-70-g09d2