4 // Duplicate filename in guicast
11 // Compression coefficients straight out of jpeglib
12 #define R_TO_Y 0.29900
13 #define G_TO_Y 0.58700
14 #define B_TO_Y 0.11400
16 #define R_TO_U -0.16874
17 #define G_TO_U -0.33126
18 #define B_TO_U 0.50000
20 #define R_TO_V 0.50000
21 #define G_TO_V -0.41869
22 #define B_TO_V -0.08131
24 // Decompression coefficients straight out of jpeglib
25 #define V_TO_R 1.40200
26 #define V_TO_G -0.71414
28 #define U_TO_G -0.34414
29 #define U_TO_B 1.77200
38 inline void rgb_to_yuv_8(int &y
, int &u
, int &v
)
43 y
= (rtoy_tab_8
[r
] + gtoy_tab_8
[g
] + btoy_tab_8
[b
]) >> 8;
44 u
= (rtou_tab_8
[r
] + gtou_tab_8
[g
] + btou_tab_8
[b
]) >> 8;
45 v
= (rtov_tab_8
[r
] + gtov_tab_8
[g
] + btov_tab_8
[b
]) >> 8;
48 inline void rgb_to_yuv_8(int r
, int g
, int b
, int &y
, int &u
, int &v
)
50 y
= (rtoy_tab_8
[r
] + gtoy_tab_8
[g
] + btoy_tab_8
[b
]) >> 8;
51 u
= (rtou_tab_8
[r
] + gtou_tab_8
[g
] + btou_tab_8
[b
]) >> 8;
52 v
= (rtov_tab_8
[r
] + gtov_tab_8
[g
] + btov_tab_8
[b
]) >> 8;
55 inline void rgb_to_yuv_8(int r
, int g
, int b
, unsigned char &y
, unsigned char &u
, unsigned char &v
)
57 y
= (rtoy_tab_8
[r
] + gtoy_tab_8
[g
] + btoy_tab_8
[b
]) >> 8;
58 u
= (rtou_tab_8
[r
] + gtou_tab_8
[g
] + btou_tab_8
[b
]) >> 8;
59 v
= (rtov_tab_8
[r
] + gtov_tab_8
[g
] + btov_tab_8
[b
]) >> 8;
62 static inline void rgb_to_yuv_f(float r
, float g
, float b
, float &y
, float &u
, float &v
)
64 y
= r
* R_TO_Y
+ g
* G_TO_Y
+ b
* B_TO_Y
;
65 u
= r
* R_TO_U
+ g
* G_TO_U
+ b
* B_TO_U
;
66 v
= r
* R_TO_V
+ g
* G_TO_V
+ b
* B_TO_V
;
69 inline void rgb_to_yuv_16(int r
, int g
, int b
, int &y
, int &u
, int &v
)
71 y
= (rtoy_tab_16
[r
] + gtoy_tab_16
[g
] + btoy_tab_16
[b
]) >> 8;
72 u
= (rtou_tab_16
[r
] + gtou_tab_16
[g
] + btou_tab_16
[b
]) >> 8;
73 v
= (rtov_tab_16
[r
] + gtov_tab_16
[g
] + btov_tab_16
[b
]) >> 8;
76 // For easier programming. Doesn't do anything.
77 inline void rgb_to_yuv_8(float r
, float g
, float b
, float &y
, float &u
, float &v
)
81 inline void rgb_to_yuv_16(float r
, float g
, float b
, float &y
, float &u
, float &v
)
85 static inline void rgb_to_yuv_f(int r
, int g
, int b
, int &y
, int &u
, int &v
)
89 inline void yuv_to_rgb_8(int &r
, int &g
, int &b
)
95 r
= (y
+ vtor_tab_8
[v
]) >> 8;
96 g
= (y
+ utog_tab_8
[u
] + vtog_tab_8
[v
]) >> 8;
97 b
= (y
+ utob_tab_8
[u
]) >> 8;
103 inline void yuv_to_rgb_8(int &r
, int &g
, int &b
, int y
, int u
, int v
)
106 r
= (y
+ vtor_tab_8
[v
]) >> 8;
107 g
= (y
+ utog_tab_8
[u
] + vtog_tab_8
[v
]) >> 8;
108 b
= (y
+ utob_tab_8
[u
]) >> 8;
115 static inline void yuv_to_rgb_f(float &r
, float &g
, float &b
, float y
, float u
, float v
)
118 g
= y
+ U_TO_G
* u
+ V_TO_G
* v
;
122 inline void rgb_to_yuv_16(int r
, int g
, int b
, uint16_t &y
, uint16_t &u
, uint16_t &v
)
124 y
= (rtoy_tab_16
[r
] + gtoy_tab_16
[g
] + btoy_tab_16
[b
]) >> 8;
125 u
= (rtou_tab_16
[r
] + gtou_tab_16
[g
] + btou_tab_16
[b
]) >> 8;
126 v
= (rtov_tab_16
[r
] + gtov_tab_16
[g
] + btov_tab_16
[b
]) >> 8;
129 inline void yuv_to_rgb_16(int &r
, int &g
, int &b
, int y
, int u
, int v
)
132 r
= (y
+ vtor_tab_16
[v
]) >> 8;
133 g
= (y
+ utog_tab_16
[u
] + vtog_tab_16
[v
]) >> 8;
134 b
= (y
+ utob_tab_16
[u
]) >> 8;
141 // For easier programming. Doesn't do anything.
142 inline void yuv_to_rgb_8(float &r
, float &g
, float &b
, float y
, float u
, float v
)
146 // For easier programming. Doesn't do anything.
147 inline void yuv_to_rgb_16(float &r
, float &g
, float &b
, float y
, float u
, float v
)
151 static inline void yuv_to_rgb_f(int &r
, int &g
, int &b
, int y
, int u
, int v
)
156 int rtoy_tab_8
[0x100], gtoy_tab_8
[0x100], btoy_tab_8
[0x100];
157 int rtou_tab_8
[0x100], gtou_tab_8
[0x100], btou_tab_8
[0x100];
158 int rtov_tab_8
[0x100], gtov_tab_8
[0x100], btov_tab_8
[0x100];
160 int vtor_tab_8
[0x100], vtog_tab_8
[0x100];
161 int utog_tab_8
[0x100], utob_tab_8
[0x100];
162 int *vtor_8
, *vtog_8
, *utog_8
, *utob_8
;
164 int rtoy_tab_16
[0x10000], gtoy_tab_16
[0x10000], btoy_tab_16
[0x10000];
165 int rtou_tab_16
[0x10000], gtou_tab_16
[0x10000], btou_tab_16
[0x10000];
166 int rtov_tab_16
[0x10000], gtov_tab_16
[0x10000], btov_tab_16
[0x10000];
168 int vtor_tab_16
[0x10000], vtog_tab_16
[0x10000];
169 int utog_tab_16
[0x10000], utob_tab_16
[0x10000];
170 int *vtor_16
, *vtog_16
, *utog_16
, *utob_16
;
192 // All units are 0 - 1
193 static int rgb_to_hsv(float r
, float g
, float b
, float &h
, float &s
, float &v
);
194 static int hsv_to_rgb(float &r
, float &g
, float &b
, float h
, float s
, float v
);
196 // YUV units are 0 - max. HSV units are 0 - 1
197 static int yuv_to_hsv(int y
, int u
, int v
, float &h
, float &s
, float &va
, int max
);
198 static int hsv_to_yuv(int &y
, int &u
, int &v
, float h
, float s
, float va
, int max
);
199 // Dummies for macros
200 static int yuv_to_hsv(float y
, float u
, float v
, float &h
, float &s
, float &va
, float max
) { return 0; };
201 static int hsv_to_yuv(float &y
, float &u
, float &v
, float h
, float s
, float va
, float max
) { return 0; };
202 static YUV yuv_static
;