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