Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * yuv.h - YUV specific methods, macros and constants 00004 * 00005 * Created: Sat Aug 12 14:36:28 2006 00006 * based on colorspaces.h from Tue Feb 23 13:49:38 2005 00007 * Copyright 2005-2006 Tim Niemueller [www.niemueller.de] 00008 * 00009 ****************************************************************************/ 00010 00011 /* This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License as published by 00013 * the Free Software Foundation; either version 2 of the License, or 00014 * (at your option) any later version. A runtime exception applies to 00015 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU Library General Public License for more details. 00021 * 00022 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00023 */ 00024 00025 #ifndef __FIREVISION_UTILS_COLOR_YUV_H 00026 #define __FIREVISION_UTILS_COLOR_YUV_H 00027 00028 namespace firevision { 00029 #if 0 /* just to make Emacs auto-indent happy */ 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 /** YUV pixel. */ 00056 typedef struct YUV_t_struct{ 00057 unsigned char Y; /**< Y component */ 00058 unsigned char U; /**< U component */ 00059 unsigned char V; /**< V component */ 00060 00061 /** Standard constructor 00062 * @param y Y component 00063 * @param u U component 00064 * @param v V component 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); } /**< @return white color */ 00074 static YUV_t_struct black() { return YUV_t_struct( 0, 127, 127); } /**< @return black color */ 00075 static YUV_t_struct green() { return YUV_t_struct( 64, 95, 85); } /**< @return green color */ 00076 static YUV_t_struct cyan() { return YUV_t_struct(178, 170, 0); } /**< @return cyan color */ 00077 static YUV_t_struct magenta() { return YUV_t_struct(105, 212, 234); } /**< @return magenta color */ 00078 static YUV_t_struct gray() { return YUV_t_struct(127, 127, 127); } /**< @return gray color */ 00079 static YUV_t_struct orange() { return YUV_t_struct(150, 43, 202); } /**< @return orange color */ 00080 static YUV_t_struct yellow() { return YUV_t_struct(245, 0, 148); } /**< @return yellow color */ 00081 static YUV_t_struct blue() { return YUV_t_struct( 29, 255, 107); } /**< @return blue color */ 00082 static YUV_t_struct red() { return YUV_t_struct( 75, 85, 255); } /**< @return red color */ 00083 } YUV_t; 00084 00085 00086 /** Convert IYU1 to IYU2 00087 * @param src src buffer 00088 * @param dest destination buffer 00089 * @param width image width 00090 * @param height image height 00091 */ 00092 void iyu1_to_yuy2(const unsigned char *src, unsigned char *dest, 00093 unsigned int width, unsigned int height); 00094 00095 00096 /** 8-Bit gray to YUY2 conversion 00097 * This function takes the gray value as Y and sets U and V to 128. 00098 */ 00099 void gray8_to_yuy2(const unsigned char *src, unsigned char *dest, 00100 unsigned int width, unsigned int height); 00101 00102 00103 /** 8-Bit gray to YUV422_PLANAR 00104 */ 00105 void gray8_to_yuv422planar_plainc(const unsigned char *src, unsigned char *dst, 00106 unsigned int width, unsigned int height); 00107 00108 00109 /** Copy part of the U anv V planes of a YUV422planar image to another 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 /** Convert YUV422_PLANAR images to YUV422_PACKED 00119 */ 00120 void yuv422planar_to_yuv422packed(const unsigned char *planar, unsigned char *packed, 00121 unsigned int width, unsigned int height); 00122 00123 /** Convert YUV422_PLANAR_QUARTER images to YUV422_PACKED 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 /** Convert YUV422_PLANAR_QUARTER images to YUV422_PLANAR */ 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 /** Convert YUV422_PACKED images to YUV422_PLANAR 00138 */ 00139 void yuv422packed_to_yuv422planar(const unsigned char *packed, unsigned char *planar, 00140 unsigned int width, unsigned int height); 00141 00142 /** Convert YUY2 images to YUV422_PLANAR 00143 */ 00144 void yuy2_to_yuv422planar(const unsigned char *packed, unsigned char *planar, 00145 unsigned int width, unsigned int height); 00146 00147 /** Convert YUY2 images to quarter-sized YUV422_PLANAR buffer. 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 /** Convert YVY2 images to YUV422_PLANAR 00153 */ 00154 void yvy2_to_yuv422planar(const unsigned char *packed, unsigned char *planar, 00155 unsigned int width, unsigned int height); 00156 00157 /** Convert YUV444_PACKED images to YUV422_PLANAR 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 } // end namespace firevision 00224 00225 #endif