00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __FIREVISION_UTILS_COLOR_YUV_H
00026 #define __FIREVISION_UTILS_COLOR_YUV_H
00027
00028 namespace firevision {
00029 #if 0
00030 }
00031 #endif
00032
00033
00034 #define YUV422PA_MACROPIXEL_AT(YUV, width, x, y) ((unsigned char*)YUV + (y)*(width)*2 + ((x)-((x)%2))*2)
00035
00036 #define YUV422_PLANAR_Y_AT(YUV, width, x, y) \
00037 *(YUV + (y) * (width) + (x));
00038
00039 #define YUV422_PLANAR_U_AT(YUV, width, height, x, y) \
00040 *(YUV + ((width) * (height)) + (((y) * (width) + (x))/ 2));
00041
00042 #define YUV422_PLANAR_V_AT(YUV, width, height, x, y) \
00043 *(YUV + ((width) * (height)) + (((width) * (height) + (y) * (width) + (x)) / 2)); \
00044
00045 #define YUV422_PLANAR_YUV(YUV, width, height, x, y, yp, up, vp) \
00046 { \
00047 yp = YUV422_PLANAR_Y_AT(YUV, width, x, y); \
00048 up = YUV422_PLANAR_U_AT(YUV, width, height, x, y); \
00049 vp = YUV422_PLANAR_V_AT(YUV, width, height, x, y); \
00050 }
00051
00052 #define YUV422_PLANAR_U_PLANE(YUV, width, height) (YUV + (width) * (height))
00053 #define YUV422_PLANAR_V_PLANE(YUV, width, height) (YUV + ((width) * (height)) + ((width) * (height) / 2))
00054
00055
00056 typedef struct YUV_t_struct{
00057 unsigned char Y;
00058 unsigned char U;
00059 unsigned char V;
00060
00061
00062
00063
00064
00065
00066 YUV_t_struct(unsigned char y = 127, unsigned char u = 127, unsigned char v = 127)
00067 {
00068 Y = y;
00069 U = u;
00070 V = v;
00071 }
00072
00073 static YUV_t_struct white() { return YUV_t_struct(255, 127, 127); }
00074 static YUV_t_struct black() { return YUV_t_struct( 0, 127, 127); }
00075 static YUV_t_struct green() { return YUV_t_struct( 64, 95, 85); }
00076 static YUV_t_struct cyan() { return YUV_t_struct(178, 170, 0); }
00077 static YUV_t_struct magenta() { return YUV_t_struct(105, 212, 234); }
00078 static YUV_t_struct gray() { return YUV_t_struct(127, 127, 127); }
00079 static YUV_t_struct orange() { return YUV_t_struct(150, 43, 202); }
00080 static YUV_t_struct yellow() { return YUV_t_struct(245, 0, 148); }
00081 static YUV_t_struct blue() { return YUV_t_struct( 29, 255, 107); }
00082 static YUV_t_struct red() { return YUV_t_struct( 75, 85, 255); }
00083 } YUV_t;
00084
00085
00086
00087
00088
00089
00090
00091
00092 void iyu1_to_yuy2(const unsigned char *src, unsigned char *dest,
00093 unsigned int width, unsigned int height);
00094
00095
00096
00097
00098
00099 void gray8_to_yuy2(const unsigned char *src, unsigned char *dest,
00100 unsigned int width, unsigned int height);
00101
00102
00103
00104
00105 void gray8_to_yuv422planar_plainc(const unsigned char *src, unsigned char *dst,
00106 unsigned int width, unsigned int height);
00107
00108
00109
00110
00111 void yuv422planar_copy_uv(const unsigned char *src, unsigned char *dst,
00112 unsigned int width, unsigned int height,
00113 unsigned int x, unsigned int y,
00114 unsigned int copy_width, unsigned int copy_height);
00115
00116
00117
00118
00119
00120 void yuv422planar_to_yuv422packed(const unsigned char *planar, unsigned char *packed,
00121 unsigned int width, unsigned int height);
00122
00123
00124
00125 void yuv422planar_quarter_to_yuv422packed(const unsigned char *planar,
00126 unsigned char *packed,
00127 const unsigned int width,
00128 const unsigned int height);
00129
00130
00131 void yuv422planar_quarter_to_yuv422planar(const unsigned char *planar,
00132 unsigned char *packed,
00133 const unsigned int width,
00134 const unsigned int height);
00135
00136
00137
00138
00139 void yuv422packed_to_yuv422planar(const unsigned char *packed, unsigned char *planar,
00140 unsigned int width, unsigned int height);
00141
00142
00143
00144 void yuy2_to_yuv422planar(const unsigned char *packed, unsigned char *planar,
00145 unsigned int width, unsigned int height);
00146
00147
00148
00149 void yuy2_to_yuv422planar_quarter(const unsigned char *packed, unsigned char *planar,
00150 const unsigned int width, const unsigned int height);
00151
00152
00153
00154 void yvy2_to_yuv422planar(const unsigned char *packed, unsigned char *planar,
00155 unsigned int width, unsigned int height);
00156
00157
00158
00159 void yuv444packed_to_yuv422planar(const unsigned char *yuv444, unsigned char *yuv422,
00160 unsigned int width, unsigned int height);
00161
00162 void yuv444packed_to_yuv422packed(const unsigned char *yuv444, unsigned char *yuv422,
00163 unsigned int width, unsigned int height);
00164
00165 void yvu444packed_to_yuv422planar(const unsigned char *yuv444, unsigned char *yuv422,
00166 unsigned int width, unsigned int height);
00167
00168 void yvu444packed_to_yuv422packed(const unsigned char *yuv444, unsigned char *yuv422,
00169 unsigned int width, unsigned int height);
00170
00171
00172
00173 void yuv422planar_erase_y_plane(unsigned char *yuv, unsigned int width, unsigned int height);
00174
00175
00176 void yuv422planar_erase_u_plane(unsigned char *yuv, unsigned int width, unsigned int height);
00177
00178
00179 void yuv422planar_erase_v_plane(unsigned char *yuv, unsigned int width, unsigned int height);
00180
00181
00182 void grayscale_yuv422packed(const unsigned char *src, unsigned char *dst,
00183 unsigned int width, unsigned int height);
00184
00185
00186 void grayscale_yuv422planar(const unsigned char *src, unsigned char *dst,
00187 unsigned int width, unsigned int height);
00188
00189
00190 inline void
00191 convert_line_yuv422planar_to_yuv444packed(const unsigned char *src, unsigned char *dst,
00192 unsigned int width, unsigned int height,
00193 unsigned int src_line, unsigned int dst_line)
00194 {
00195 register unsigned int i = 0;
00196 register YUV_t *y1, *y2;
00197 register const unsigned char *yp, *up, *vp;
00198
00199 yp = src + (width * src_line);
00200 up = YUV422_PLANAR_U_PLANE(src, width, height) + (width * src_line / 2);
00201 vp = YUV422_PLANAR_V_PLANE(src, width, height) + (width * src_line / 2);
00202
00203 dst += 3 * width * dst_line;
00204
00205 while (i < width) {
00206 y1 = (YUV_t *)dst;
00207 dst += 3;
00208 y2 = (YUV_t *)dst;
00209 dst += 3;
00210
00211 y1->Y = *yp++;
00212 y1->U = *up;
00213 y1->V = *vp;
00214
00215 y2->Y = *yp++;
00216 y2->U = *up++;
00217 y2->V = *vp++;
00218
00219 i += 2;
00220 }
00221 }
00222
00223 }
00224
00225 #endif