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