more icons from sam, --with-git-ffmpeg=url
[goodguy/history.git] / cinelerra-5.1 / guicast / bccolors.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef __BCCOLORS_H__
23 #define __BCCOLORS_H__
24
25 // Duplicate filename in guicast
26
27 #include "clip.h"
28 #include "vframe.inc"
29
30 #include <stdint.h>
31
32 // Compression coefficients straight out of jpeglib
33 #define R_TO_Y    0.29900
34 #define G_TO_Y    0.58700
35 #define B_TO_Y    0.11400
36
37 #define R_TO_U    -0.16874
38 #define G_TO_U    -0.33126
39 #define B_TO_U    0.50000
40
41 #define R_TO_V    0.50000
42 #define G_TO_V    -0.41869
43 #define B_TO_V    -0.08131
44
45 // Decompression coefficients straight out of jpeglib
46 #define V_TO_R    1.40200
47 #define V_TO_G    -0.71414
48
49 #define U_TO_G    -0.34414
50 #define U_TO_B    1.77200
51
52
53 class YUV
54 {
55 public:
56         YUV();
57         ~YUV();
58         static YUV yuv;
59
60         inline void rgb_to_yuv_8(int &y, int &u, int &v)
61         {
62                 int r = y;
63                 int g = u;
64                 int b = v;
65                 y = (rtoy_tab_8[r] + gtoy_tab_8[g] + btoy_tab_8[b]) >> 8;
66                 u = (rtou_tab_8[r] + gtou_tab_8[g] + btou_tab_8[b]) >> 8;
67                 v = (rtov_tab_8[r] + gtov_tab_8[g] + btov_tab_8[b]) >> 8;
68         };
69
70         inline void rgb_to_yuv_8(int r, int g, int b, int &y, int &u, int &v)
71         {
72                 y = (rtoy_tab_8[r] + gtoy_tab_8[g] + btoy_tab_8[b]) >> 8;
73                 u = (rtou_tab_8[r] + gtou_tab_8[g] + btou_tab_8[b]) >> 8;
74                 v = (rtov_tab_8[r] + gtov_tab_8[g] + btov_tab_8[b]) >> 8;
75         };
76
77         inline void rgb_to_yuv_8(int r, int g, int b, unsigned char &y, unsigned char &u, unsigned char &v)
78         {
79                 y = (rtoy_tab_8[r] + gtoy_tab_8[g] + btoy_tab_8[b]) >> 8;
80                 u = (rtou_tab_8[r] + gtou_tab_8[g] + btou_tab_8[b]) >> 8;
81                 v = (rtov_tab_8[r] + gtov_tab_8[g] + btov_tab_8[b]) >> 8;
82         };
83
84         static inline void rgb_to_yuv_f(float r, float g, float b, float &y, float &u, float &v)
85         {
86                 y = r * R_TO_Y + g * G_TO_Y + b * B_TO_Y;
87                 u = r * R_TO_U + g * G_TO_U + b * B_TO_U;
88                 v = r * R_TO_V + g * G_TO_V + b * B_TO_V;
89         };
90
91         inline void rgb_to_yuv_16(int r, int g, int b, int &y, int &u, int &v)
92         {
93                 y = (rtoy_tab_16[r] + gtoy_tab_16[g] + btoy_tab_16[b]) >> 8;
94                 u = (rtou_tab_16[r] + gtou_tab_16[g] + btou_tab_16[b]) >> 8;
95                 v = (rtov_tab_16[r] + gtov_tab_16[g] + btov_tab_16[b]) >> 8;
96         };
97
98 // For easier programming.  Doesn't do anything.
99         inline void rgb_to_yuv_8(float r, float g, float b, float &y, float &u, float &v)
100         {
101         };
102
103         inline void rgb_to_yuv_16(float r, float g, float b, float &y, float &u, float &v)
104         {
105         };
106
107         static inline void rgb_to_yuv_f(int r, int g, int b, int &y, int &u, int &v)
108         {
109         };
110
111         inline void yuv_to_rgb_8(int &r, int &g, int &b)
112         {
113                 int y = r;
114                 int u = g;
115                 int v = b;
116                 y = (y << 8) | y;
117                 r = (y + vtor_tab_8[v]) >> 8;
118                 g = (y + utog_tab_8[u] + vtog_tab_8[v]) >> 8;
119                 b = (y + utob_tab_8[u]) >> 8;
120
121                 CLAMP(r, 0, 0xff);
122                 CLAMP(g, 0, 0xff);
123                 CLAMP(b, 0, 0xff);
124         };
125         inline void yuv_to_rgb_8(int &r, int &g, int &b, int y, int u, int v)
126         {
127                 y = (y << 8) | y;
128                 r = (y + vtor_tab_8[v]) >> 8;
129                 g = (y + utog_tab_8[u] + vtog_tab_8[v]) >> 8;
130                 b = (y + utob_tab_8[u]) >> 8;
131
132                 CLAMP(r, 0, 0xff);
133                 CLAMP(g, 0, 0xff);
134                 CLAMP(b, 0, 0xff);
135         };
136
137         static inline void yuv_to_rgb_f(float &r, float &g, float &b, float y, float u, float v)
138         {
139                 r = y + V_TO_R * v;
140                 g = y + U_TO_G * u + V_TO_G * v;
141                 b = y + U_TO_B * u;
142         };
143
144         inline void rgb_to_yuv_16(int r, int g, int b, uint16_t &y, uint16_t &u, uint16_t &v)
145         {
146                 y = (rtoy_tab_16[r] + gtoy_tab_16[g] + btoy_tab_16[b]) >> 8;
147                 u = (rtou_tab_16[r] + gtou_tab_16[g] + btou_tab_16[b]) >> 8;
148                 v = (rtov_tab_16[r] + gtov_tab_16[g] + btov_tab_16[b]) >> 8;
149         };
150
151         inline void yuv_to_rgb_16(int &r, int &g, int &b, int y, int u, int v)
152         {
153                 y = (y << 8) | y;
154                 r = (y + vtor_tab_16[v]) >> 8;
155                 g = (y + utog_tab_16[u] + vtog_tab_16[v]) >> 8;
156                 b = (y + utob_tab_16[u]) >> 8;
157
158                 CLAMP(r, 0, 0xffff);
159                 CLAMP(g, 0, 0xffff);
160                 CLAMP(b, 0, 0xffff);
161         };
162
163 // For easier programming.  Doesn't do anything.
164         inline void yuv_to_rgb_8(float &r, float &g, float &b, float y, float u, float v)
165         {
166         };
167
168 // For easier programming.  Doesn't do anything.
169         inline void yuv_to_rgb_16(float &r, float &g, float &b, float y, float u, float v)
170         {
171         };
172
173         static inline void yuv_to_rgb_f(int &r, int &g, int &b, int y, int u, int v)
174         {
175         };
176
177 private:
178         int rtoy_tab_8[0x100], gtoy_tab_8[0x100], btoy_tab_8[0x100];
179         int rtou_tab_8[0x100], gtou_tab_8[0x100], btou_tab_8[0x100];
180         int rtov_tab_8[0x100], gtov_tab_8[0x100], btov_tab_8[0x100];
181
182         int vtor_tab_8[0x100], vtog_tab_8[0x100];
183         int utog_tab_8[0x100], utob_tab_8[0x100];
184         int *vtor_8, *vtog_8, *utog_8, *utob_8;
185
186         int rtoy_tab_16[0x10000], gtoy_tab_16[0x10000], btoy_tab_16[0x10000];
187         int rtou_tab_16[0x10000], gtou_tab_16[0x10000], btou_tab_16[0x10000];
188         int rtov_tab_16[0x10000], gtov_tab_16[0x10000], btov_tab_16[0x10000];
189
190         int vtor_tab_16[0x10000], vtog_tab_16[0x10000];
191         int utog_tab_16[0x10000], utob_tab_16[0x10000];
192         int *vtor_16, *vtog_16, *utog_16, *utob_16;
193 };
194
195
196 class HSV
197 {
198 public:
199         HSV();
200     ~HSV();
201
202 // All units are 0 - 1
203         static int rgb_to_hsv(float r, float g, float b, float &h, float &s, float &v);
204         static int hsv_to_rgb(float &r, float &g, float &b, float h, float s, float v);
205
206 // YUV units are 0 - max.  HSV units are 0 - 1
207         static int yuv_to_hsv(int y, int u, int v, float &h, float &s, float &va, int max);
208         static int hsv_to_yuv(int &y, int &u, int &v, float h, float s, float va, int max);
209 // Dummies for macros
210         static int yuv_to_hsv(float y, float u, float v, float &h, float &s, float &va, float max) { return 0; };
211         static int hsv_to_yuv(float &y, float &u, float &v, float h, float s, float va, float max) { return 0; };
212 };
213
214
215 // standard colors
216 #define BLACK               0x000000
217 #define WHITE               0xFFFFFF
218
219 #define LTBLUE              0x9090FF
220 #define BLUE                0x0000FF
221 #define DKBLUE              0x000090
222
223 #define LTPINK              0xFFC0C0
224 #define PINK                0xFF8080
225 #define RED                 0xFF0000
226
227 #define LTGREEN             0xC0FFC0
228 #define GREEN               0x00FF00
229 #define DKGREEN             0x009000
230
231 #define YELLOW              0xFFFF00
232 #define LTYELLOW            0xFFFFA0
233 #define MEYELLOW            0xFFFF00
234 #define MDYELLOW            0xFFFFD2
235 #define DKYELLOW            0xFFFFB4
236
237 #define LTCYAN              0x00CBCB
238 #define MECYAN              0x009696
239 #define MDCYAN              0x007E7E
240 #define DKCYAN              0x004949
241
242 #define LTPURPLE            0xFFC0FF
243 #define MEPURPLE            0xFF00FF
244 #define MDPURPLE            0xC000C0
245 #define DKPURPLE            0xA000A0
246
247 #define LTGREY              0xE0E0E0
248 #define MEGREY              0xAFAFAF
249 #define DMGREY              0x999999
250 #define MDGREY              0x7D7D7D
251 #define DKGREY              0x4B4B4B
252
253 #define BLOND               0xb4b487
254 #define SLBLUE              0x6040c0
255
256 #define MNGREY              0xe6e6e6
257 #define FGGREY              0xe3e3e3
258 #define MNBLUE              0x003cff
259 #define ORANGE              0xffdd76
260 #define FTGREY              0xbcbcbc
261
262 #endif