Fawkes API Fawkes Development Version
yuv.h
1
2/***************************************************************************
3 * yuv.h - YUV specific methods, macros and constants
4 *
5 * Created: Sat Aug 12 14:36:28 2006
6 * based on colorspaces.h from Tue Feb 23 13:49:38 2005
7 * Copyright 2005-2006 Tim Niemueller [www.niemueller.de]
8 *
9 ****************************************************************************/
10
11/* This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. A runtime exception applies to
15 * this software (see LICENSE.GPL_WRE file mentioned below for details).
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
21 *
22 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
23 */
24
25#ifndef FIREVISION_UTILS_COLOR_YUV_H_
26#define FIREVISION_UTILS_COLOR_YUV_H_
27
28namespace firevision {
29
30#define YUV422PA_MACROPIXEL_AT(YUV, width, x, y) \
31 ((unsigned char *)YUV + (y) * (width)*2 + ((x) - ((x) % 2)) * 2)
32
33#define YUV422_PLANAR_Y_AT(YUV, width, x, y) *(YUV + (y) * (width) + (x))
34
35#define YUV422_PLANAR_U_AT(YUV, width, height, x, y) \
36 *(YUV + ((width) * (height)) + (((y) * (width) + (x)) / 2))
37
38#define YUV422_PLANAR_V_AT(YUV, width, height, x, y) \
39 *(YUV + ((width) * (height)) + (((width) * (height) + (y) * (width) + (x)) / 2))
40
41#define YUV422_PLANAR_YUV(YUV, width, height, x, y, yp, up, vp) \
42 { \
43 yp = YUV422_PLANAR_Y_AT(YUV, width, x, y); \
44 up = YUV422_PLANAR_U_AT(YUV, width, height, x, y); \
45 vp = YUV422_PLANAR_V_AT(YUV, width, height, x, y); \
46 }
47
48#define YUV422_PLANAR_U_PLANE(YUV, width, height) (YUV + (width) * (height))
49#define YUV422_PLANAR_V_PLANE(YUV, width, height) \
50 (YUV + ((width) * (height)) + ((width) * (height) / 2))
51
52#define YUV420_PLANAR_U_PLANE(YUV, width, height) (YUV + (width) * (height))
53#define YUV420_PLANAR_V_PLANE(YUV, width, height) \
54 (YUV + ((width) * (height)) + ((width) * (height) / 4))
55
56/** YUV pixel. */
57typedef struct YUV_t_struct
58{
59 unsigned char Y; /**< Y component */
60 unsigned char U; /**< U component */
61 unsigned char V; /**< V component */
62
63 /** Standard constructor
64 * @param y Y component
65 * @param u U component
66 * @param v V component
67 */
68 YUV_t_struct(unsigned char y = 127, unsigned char u = 127, unsigned char v = 127)
69 {
70 Y = y;
71 U = u;
72 V = v;
73 }
74
75 static YUV_t_struct
77 {
78 return YUV_t_struct(255, 127, 127);
79 } /**< @return white color */
80 static YUV_t_struct
82 {
83 return YUV_t_struct(0, 127, 127);
84 } /**< @return black color */
85 static YUV_t_struct
87 {
88 return YUV_t_struct(64, 95, 85);
89 } /**< @return green color */
90 static YUV_t_struct
92 {
93 return YUV_t_struct(178, 170, 0);
94 } /**< @return cyan color */
95 static YUV_t_struct
97 {
98 return YUV_t_struct(105, 212, 234);
99 } /**< @return magenta color */
100 static YUV_t_struct
102 {
103 return YUV_t_struct(127, 127, 127);
104 } /**< @return gray color */
105 static YUV_t_struct
107 {
108 return YUV_t_struct(150, 43, 202);
109 } /**< @return orange color */
110 static YUV_t_struct
112 {
113 return YUV_t_struct(245, 0, 148);
114 } /**< @return yellow color */
115 static YUV_t_struct
117 {
118 return YUV_t_struct(29, 255, 107);
119 } /**< @return blue color */
120 static YUV_t_struct
122 {
123 return YUV_t_struct(75, 85, 255);
124 } /**< @return red color */
125} YUV_t;
126
127/** Convert IYU1 to IYU2
128 * @param src src buffer
129 * @param dest destination buffer
130 * @param width image width
131 * @param height image height
132 */
133void iyu1_to_yuy2(const unsigned char *src,
134 unsigned char * dest,
135 unsigned int width,
136 unsigned int height);
137
138/** 8-Bit gray to YUY2 conversion
139 * This function takes the gray value as Y and sets U and V to 128.
140 */
141void gray8_to_yuy2(const unsigned char *src,
142 unsigned char * dest,
143 unsigned int width,
144 unsigned int height);
145
146/** 8-Bit gray to YUV422_PLANAR
147 */
148void gray8_to_yuv422planar_plainc(const unsigned char *src,
149 unsigned char * dst,
150 unsigned int width,
151 unsigned int height);
152void gray8_to_yuv422packed_plainc(const unsigned char *src,
153 unsigned char * dst,
154 unsigned int width,
155 unsigned int height);
156
157void yuv420planar_to_yuv422planar(const unsigned char *src,
158 unsigned char * dst,
159 unsigned int width,
160 unsigned int height);
161
162/** Copy part of the U anv V planes of a YUV422planar image to another
163 */
164void yuv422planar_copy_uv(const unsigned char *src,
165 unsigned char * dst,
166 unsigned int width,
167 unsigned int height,
168 unsigned int x,
169 unsigned int y,
170 unsigned int copy_width,
171 unsigned int copy_height);
172
173/** Convert YUV422_PLANAR images to YUV422_PACKED
174 */
175void yuv422planar_to_yuv422packed(const unsigned char *planar,
176 unsigned char * packed,
177 unsigned int width,
178 unsigned int height);
179
180/** Convert YUV422_PLANAR_QUARTER images to YUV422_PACKED
181 */
182void yuv422planar_quarter_to_yuv422packed(const unsigned char *planar,
183 unsigned char * packed,
184 const unsigned int width,
185 const unsigned int height);
186
187/** Convert YUV422_PLANAR_QUARTER images to YUV422_PLANAR */
188void yuv422planar_quarter_to_yuv422planar(const unsigned char *planar,
189 unsigned char * packed,
190 const unsigned int width,
191 const unsigned int height);
192
193/** Convert YUV422_PACKED images to YUV422_PLANAR
194 */
195void yuv422packed_to_yuv422planar(const unsigned char *packed,
196 unsigned char * planar,
197 unsigned int width,
198 unsigned int height);
199
200/** Convert YUY2 images to YUV422_PLANAR
201 */
202void yuy2_to_yuv422planar(const unsigned char *packed,
203 unsigned char * planar,
204 unsigned int width,
205 unsigned int height);
206
207/** Convert YUY2 images to quarter-sized YUV422_PLANAR buffer.
208 */
209void yuy2_to_yuv422planar_quarter(const unsigned char *packed,
210 unsigned char * planar,
211 const unsigned int width,
212 const unsigned int height);
213
214/** Convert YVY2 images to YUV422_PLANAR
215 */
216void yvy2_to_yuv422planar(const unsigned char *packed,
217 unsigned char * planar,
218 unsigned int width,
219 unsigned int height);
220
221/** Convert YUV444_PACKED images to YUV422_PLANAR
222 */
223void yuv444packed_to_yuv422planar(const unsigned char *yuv444,
224 unsigned char * yuv422,
225 unsigned int width,
226 unsigned int height);
227
228void yuv444packed_to_yuv422packed(const unsigned char *yuv444,
229 unsigned char * yuv422,
230 unsigned int width,
231 unsigned int height);
232
233void yvu444packed_to_yuv422planar(const unsigned char *yuv444,
234 unsigned char * yuv422,
235 unsigned int width,
236 unsigned int height);
237
238void yvu444packed_to_yuv422packed(const unsigned char *yuv444,
239 unsigned char * yuv422,
240 unsigned int width,
241 unsigned int height);
242
243void yuv422planar_erase_y_plane(unsigned char *yuv, unsigned int width, unsigned int height);
244
245void yuv422planar_erase_u_plane(unsigned char *yuv, unsigned int width, unsigned int height);
246
247void yuv422planar_erase_v_plane(unsigned char *yuv, unsigned int width, unsigned int height);
248
249void grayscale_yuv422packed(const unsigned char *src,
250 unsigned char * dst,
251 unsigned int width,
252 unsigned int height);
253
254void grayscale_yuv422planar(const unsigned char *src,
255 unsigned char * dst,
256 unsigned int width,
257 unsigned int height);
258
259inline void
260convert_line_yuv422planar_to_yuv444packed(const unsigned char *src,
261 unsigned char * dst,
262 unsigned int width,
263 unsigned int height,
264 unsigned int src_line,
265 unsigned int dst_line)
266{
267 unsigned int i = 0;
268 YUV_t * y1, *y2;
269 const unsigned char *yp, *up, *vp;
270
271 yp = src + (width * src_line);
272 up = YUV422_PLANAR_U_PLANE(src, width, height) + (width * src_line / 2);
273 vp = YUV422_PLANAR_V_PLANE(src, width, height) + (width * src_line / 2);
274
275 dst += 3 * width * dst_line;
276
277 while (i < width) {
278 y1 = (YUV_t *)dst;
279 dst += 3;
280 y2 = (YUV_t *)dst;
281 dst += 3;
282
283 y1->Y = *yp++;
284 y1->U = *up;
285 y1->V = *vp;
286
287 y2->Y = *yp++;
288 y2->U = *up++;
289 y2->V = *vp++;
290
291 i += 2;
292 }
293}
294
295} // end namespace firevision
296
297#endif
YUV pixel.
Definition: yuv.h:58
static YUV_t_struct gray()
Definition: yuv.h:101
unsigned char V
V component.
Definition: yuv.h:61
static YUV_t_struct cyan()
Definition: yuv.h:91
static YUV_t_struct green()
Definition: yuv.h:86
static YUV_t_struct orange()
Definition: yuv.h:106
YUV_t_struct(unsigned char y=127, unsigned char u=127, unsigned char v=127)
Standard constructor.
Definition: yuv.h:68
static YUV_t_struct blue()
Definition: yuv.h:116
static YUV_t_struct magenta()
Definition: yuv.h:96
static YUV_t_struct white()
Definition: yuv.h:76
unsigned char U
U component.
Definition: yuv.h:60
static YUV_t_struct yellow()
Definition: yuv.h:111
static YUV_t_struct black()
Definition: yuv.h:81
unsigned char Y
Y component.
Definition: yuv.h:59
static YUV_t_struct red()
Definition: yuv.h:121