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 
28 namespace firevision {
29 #if 0 /* just to make Emacs auto-indent happy */
30 }
31 #endif
32 
33 
34 #define YUV422PA_MACROPIXEL_AT(YUV, width, x, y) ((unsigned char*)YUV + (y)*(width)*2 + ((x)-((x)%2))*2)
35 
36 #define YUV422_PLANAR_Y_AT(YUV, width, x, y) \
37  *(YUV + (y) * (width) + (x))
38 
39 #define YUV422_PLANAR_U_AT(YUV, width, height, x, y) \
40  *(YUV + ((width) * (height)) + (((y) * (width) + (x))/ 2))
41 
42 #define YUV422_PLANAR_V_AT(YUV, width, height, x, y) \
43  *(YUV + ((width) * (height)) + (((width) * (height) + (y) * (width) + (x)) / 2))
44 
45 #define YUV422_PLANAR_YUV(YUV, width, height, x, y, yp, up, vp) \
46  { \
47  yp = YUV422_PLANAR_Y_AT(YUV, width, x, y); \
48  up = YUV422_PLANAR_U_AT(YUV, width, height, x, y); \
49  vp = YUV422_PLANAR_V_AT(YUV, width, height, x, y); \
50  }
51 
52 #define YUV422_PLANAR_U_PLANE(YUV, width, height) (YUV + (width) * (height))
53 #define YUV422_PLANAR_V_PLANE(YUV, width, height) (YUV + ((width) * (height)) + ((width) * (height) / 2))
54 
55 #define YUV420_PLANAR_U_PLANE(YUV, width, height) (YUV + (width) * (height))
56 #define YUV420_PLANAR_V_PLANE(YUV, width, height) (YUV + ((width) * (height)) + ((width) * (height) / 4))
57 
58 /** YUV pixel. */
59 typedef struct YUV_t_struct{
60  unsigned char Y; /**< Y component */
61  unsigned char U; /**< U component */
62  unsigned char V; /**< V component */
63 
64  /** Standard constructor
65  * @param y Y component
66  * @param u U component
67  * @param v V component
68  */
69  YUV_t_struct(unsigned char y = 127, unsigned char u = 127, unsigned char v = 127)
70  {
71  Y = y;
72  U = u;
73  V = v;
74  }
75 
76  static YUV_t_struct white() { return YUV_t_struct(255, 127, 127); } /**< @return white color */
77  static YUV_t_struct black() { return YUV_t_struct( 0, 127, 127); } /**< @return black color */
78  static YUV_t_struct green() { return YUV_t_struct( 64, 95, 85); } /**< @return green color */
79  static YUV_t_struct cyan() { return YUV_t_struct(178, 170, 0); } /**< @return cyan color */
80  static YUV_t_struct magenta() { return YUV_t_struct(105, 212, 234); } /**< @return magenta color */
81  static YUV_t_struct gray() { return YUV_t_struct(127, 127, 127); } /**< @return gray color */
82  static YUV_t_struct orange() { return YUV_t_struct(150, 43, 202); } /**< @return orange color */
83  static YUV_t_struct yellow() { return YUV_t_struct(245, 0, 148); } /**< @return yellow color */
84  static YUV_t_struct blue() { return YUV_t_struct( 29, 255, 107); } /**< @return blue color */
85  static YUV_t_struct red() { return YUV_t_struct( 75, 85, 255); } /**< @return red color */
86 } YUV_t;
87 
88 
89 /** Convert IYU1 to IYU2
90  * @param src src buffer
91  * @param dest destination buffer
92  * @param width image width
93  * @param height image height
94  */
95 void iyu1_to_yuy2(const unsigned char *src, unsigned char *dest,
96  unsigned int width, unsigned int height);
97 
98 
99 /** 8-Bit gray to YUY2 conversion
100  * This function takes the gray value as Y and sets U and V to 128.
101  */
102 void gray8_to_yuy2(const unsigned char *src, unsigned char *dest,
103  unsigned int width, unsigned int height);
104 
105 
106 /** 8-Bit gray to YUV422_PLANAR
107  */
108 void gray8_to_yuv422planar_plainc(const unsigned char *src, unsigned char *dst,
109  unsigned int width, unsigned int height);
110 void gray8_to_yuv422packed_plainc(const unsigned char *src, unsigned char *dst,
111  unsigned int width, unsigned int height);
112 
113 
114 void yuv420planar_to_yuv422planar(const unsigned char *src, unsigned char *dst,
115  unsigned int width, unsigned int height);
116 
117 /** Copy part of the U anv V planes of a YUV422planar image to another
118  */
119 void yuv422planar_copy_uv(const unsigned char *src, unsigned char *dst,
120  unsigned int width, unsigned int height,
121  unsigned int x, unsigned int y,
122  unsigned int copy_width, unsigned int copy_height);
123 
124 
125 
126 /** Convert YUV422_PLANAR images to YUV422_PACKED
127  */
128 void yuv422planar_to_yuv422packed(const unsigned char *planar, unsigned char *packed,
129  unsigned int width, unsigned int height);
130 
131 /** Convert YUV422_PLANAR_QUARTER images to YUV422_PACKED
132  */
133 void yuv422planar_quarter_to_yuv422packed(const unsigned char *planar,
134  unsigned char *packed,
135  const unsigned int width,
136  const unsigned int height);
137 
138 /** Convert YUV422_PLANAR_QUARTER images to YUV422_PLANAR */
139 void yuv422planar_quarter_to_yuv422planar(const unsigned char *planar,
140  unsigned char *packed,
141  const unsigned int width,
142  const unsigned int height);
143 
144 
145 /** Convert YUV422_PACKED images to YUV422_PLANAR
146  */
147 void yuv422packed_to_yuv422planar(const unsigned char *packed, unsigned char *planar,
148  unsigned int width, unsigned int height);
149 
150 /** Convert YUY2 images to YUV422_PLANAR
151  */
152 void yuy2_to_yuv422planar(const unsigned char *packed, unsigned char *planar,
153  unsigned int width, unsigned int height);
154 
155 /** Convert YUY2 images to quarter-sized YUV422_PLANAR buffer.
156  */
157 void yuy2_to_yuv422planar_quarter(const unsigned char *packed, unsigned char *planar,
158  const unsigned int width, const unsigned int height);
159 
160 /** Convert YVY2 images to YUV422_PLANAR
161  */
162 void yvy2_to_yuv422planar(const unsigned char *packed, unsigned char *planar,
163  unsigned int width, unsigned int height);
164 
165 /** Convert YUV444_PACKED images to YUV422_PLANAR
166  */
167 void yuv444packed_to_yuv422planar(const unsigned char *yuv444, unsigned char *yuv422,
168  unsigned int width, unsigned int height);
169 
170 void yuv444packed_to_yuv422packed(const unsigned char *yuv444, unsigned char *yuv422,
171  unsigned int width, unsigned int height);
172 
173 void yvu444packed_to_yuv422planar(const unsigned char *yuv444, unsigned char *yuv422,
174  unsigned int width, unsigned int height);
175 
176 void yvu444packed_to_yuv422packed(const unsigned char *yuv444, unsigned char *yuv422,
177  unsigned int width, unsigned int height);
178 
179 
180 
181 void yuv422planar_erase_y_plane(unsigned char *yuv, unsigned int width, unsigned int height);
182 
183 
184 void yuv422planar_erase_u_plane(unsigned char *yuv, unsigned int width, unsigned int height);
185 
186 
187 void yuv422planar_erase_v_plane(unsigned char *yuv, unsigned int width, unsigned int height);
188 
189 
190 void grayscale_yuv422packed(const unsigned char *src, unsigned char *dst,
191  unsigned int width, unsigned int height);
192 
193 
194 void grayscale_yuv422planar(const unsigned char *src, unsigned char *dst,
195  unsigned int width, unsigned int height);
196 
197 
198 inline void
199 convert_line_yuv422planar_to_yuv444packed(const unsigned char *src, unsigned char *dst,
200  unsigned int width, unsigned int height,
201  unsigned int src_line, unsigned int dst_line)
202 {
203  unsigned int i = 0;
204  YUV_t *y1, *y2;
205  const unsigned char *yp, *up, *vp;
206 
207  yp = src + (width * src_line);
208  up = YUV422_PLANAR_U_PLANE(src, width, height) + (width * src_line / 2);
209  vp = YUV422_PLANAR_V_PLANE(src, width, height) + (width * src_line / 2);
210 
211  dst += 3 * width * dst_line;
212 
213  while (i < width) {
214  y1 = (YUV_t *)dst;
215  dst += 3;
216  y2 = (YUV_t *)dst;
217  dst += 3;
218 
219  y1->Y = *yp++;
220  y1->U = *up;
221  y1->V = *vp;
222 
223  y2->Y = *yp++;
224  y2->U = *up++;
225  y2->V = *vp++;
226 
227  i += 2;
228  }
229 }
230 
231 } // end namespace firevision
232 
233 #endif
static YUV_t_struct yellow()
Definition: yuv.h:83
unsigned char V
V component.
Definition: yuv.h:62
static YUV_t_struct magenta()
Definition: yuv.h:80
static YUV_t_struct red()
Definition: yuv.h:85
YUV_t_struct(unsigned char y=127, unsigned char u=127, unsigned char v=127)
Standard constructor.
Definition: yuv.h:69
unsigned char Y
Y component.
Definition: yuv.h:60
static YUV_t_struct cyan()
Definition: yuv.h:79
static YUV_t_struct black()
Definition: yuv.h:77
static YUV_t_struct gray()
Definition: yuv.h:81
static YUV_t_struct orange()
Definition: yuv.h:82
static YUV_t_struct green()
Definition: yuv.h:78
unsigned char U
U component.
Definition: yuv.h:61
YUV pixel.
Definition: yuv.h:59
static YUV_t_struct blue()
Definition: yuv.h:84
static YUV_t_struct white()
Definition: yuv.h:76