-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcolor_math.h
52 lines (37 loc) · 1.52 KB
/
color_math.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef _COLOR_MATH_H_
#define _COLOR_MATH_H_
#include <math.h>
// should be defined math.h but sometimes isn't
#ifndef M_PI
#define M_PI 3.1415926535
#endif
#define DEG2RAD(angle) ((angle) * (M_PI / 180.0))
#define RAD2DEG(angle) ((angle) * (180.0 / M_PI))
#ifndef MIN_VAL
#define MIN_VAL(a, b) ({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; \
})
#endif
#ifndef MAX_VAL
#define MAX_VAL(a, b) ({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; \
})
#endif
#define RGB_FLOAT(_r, _g, _b) ((rgb_t) { _r, _g, _b })
#define RGB_R(_rgb) (_rgb[0])
#define RGB_G(_rgb) (_rgb[1])
#define RGB_B(_rgb) (_rgb[2])
typedef float rgb_t[3];
// converts RGB values to CIELAB2000 values
void rgb2lab(rgb_t rgb, float *l, float *a, float *b);
// converts RGB values to Hue, Luminosity, Saturation values
void rgb2hsl(rgb_t rgb, float *h, float *l, float *s);
// converts HSL values to Red, Green, Blue values
void hsl2rgb(float h, float s, float l, float *r, float *g, float *b);
// compute the distance between to CIELAB colors using 1976 method
float cie76_delta(float l1, float a1, float b1, float l2, float a2, float b2);
#endif