libexplain
1.4.D001
|
00001 /* 00002 * libexplain - a library of system-call-specific strerror replacements 00003 * Copyright (C) 2011, 2013 Peter Miller 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as 00007 * published by the Free Software Foundation; either version 3 of the 00008 * License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #include <libexplain/ac/ctype.h> 00020 #include <libexplain/ac/linux/videodev2.h> 00021 00022 #include <libexplain/buffer/v4l2_pixel_format.h> 00023 #include <libexplain/option.h> 00024 #include <libexplain/parse_bits.h> 00025 00026 00027 #ifdef HAVE_LINUX_VIDEODEV2_H 00028 00029 /* 00030 * awk '/#define V4L2_PIX_FMT_/{ 00031 * print "#ifdef " $2 00032 * print " { \"" $2 "\", " $2 " }," 00033 * print "#endif" 00034 * } 00035 * ' /usr/include/linux/videodev2.h 00036 */ 00037 static const explain_parse_bits_table_t table[] = 00038 { 00039 #ifdef V4L2_PIX_FMT_RGB332 00040 { "V4L2_PIX_FMT_RGB332", V4L2_PIX_FMT_RGB332 }, 00041 #endif 00042 #ifdef V4L2_PIX_FMT_RGB444 00043 { "V4L2_PIX_FMT_RGB444", V4L2_PIX_FMT_RGB444 }, 00044 #endif 00045 #ifdef V4L2_PIX_FMT_RGB555 00046 { "V4L2_PIX_FMT_RGB555", V4L2_PIX_FMT_RGB555 }, 00047 #endif 00048 #ifdef V4L2_PIX_FMT_RGB565 00049 { "V4L2_PIX_FMT_RGB565", V4L2_PIX_FMT_RGB565 }, 00050 #endif 00051 #ifdef V4L2_PIX_FMT_RGB555X 00052 { "V4L2_PIX_FMT_RGB555X", V4L2_PIX_FMT_RGB555X }, 00053 #endif 00054 #ifdef V4L2_PIX_FMT_RGB565X 00055 { "V4L2_PIX_FMT_RGB565X", V4L2_PIX_FMT_RGB565X }, 00056 #endif 00057 #ifdef V4L2_PIX_FMT_BGR666 00058 { "V4L2_PIX_FMT_BGR666", V4L2_PIX_FMT_BGR666 }, 00059 #endif 00060 #ifdef V4L2_PIX_FMT_BGR24 00061 { "V4L2_PIX_FMT_BGR24", V4L2_PIX_FMT_BGR24 }, 00062 #endif 00063 #ifdef V4L2_PIX_FMT_RGB24 00064 { "V4L2_PIX_FMT_RGB24", V4L2_PIX_FMT_RGB24 }, 00065 #endif 00066 #ifdef V4L2_PIX_FMT_BGR32 00067 { "V4L2_PIX_FMT_BGR32", V4L2_PIX_FMT_BGR32 }, 00068 #endif 00069 #ifdef V4L2_PIX_FMT_RGB32 00070 { "V4L2_PIX_FMT_RGB32", V4L2_PIX_FMT_RGB32 }, 00071 #endif 00072 #ifdef V4L2_PIX_FMT_GREY 00073 { "V4L2_PIX_FMT_GREY", V4L2_PIX_FMT_GREY }, 00074 #endif 00075 #ifdef V4L2_PIX_FMT_Y4 00076 { "V4L2_PIX_FMT_Y4", V4L2_PIX_FMT_Y4 }, 00077 #endif 00078 #ifdef V4L2_PIX_FMT_Y6 00079 { "V4L2_PIX_FMT_Y6", V4L2_PIX_FMT_Y6 }, 00080 #endif 00081 #ifdef V4L2_PIX_FMT_Y10 00082 { "V4L2_PIX_FMT_Y10", V4L2_PIX_FMT_Y10 }, 00083 #endif 00084 #ifdef V4L2_PIX_FMT_Y16 00085 { "V4L2_PIX_FMT_Y16", V4L2_PIX_FMT_Y16 }, 00086 #endif 00087 #ifdef V4L2_PIX_FMT_PAL8 00088 { "V4L2_PIX_FMT_PAL8", V4L2_PIX_FMT_PAL8 }, 00089 #endif 00090 #ifdef V4L2_PIX_FMT_YVU410 00091 { "V4L2_PIX_FMT_YVU410", V4L2_PIX_FMT_YVU410 }, 00092 #endif 00093 #ifdef V4L2_PIX_FMT_YVU420 00094 { "V4L2_PIX_FMT_YVU420", V4L2_PIX_FMT_YVU420 }, 00095 #endif 00096 #ifdef V4L2_PIX_FMT_YUYV 00097 { "V4L2_PIX_FMT_YUYV", V4L2_PIX_FMT_YUYV }, 00098 #endif 00099 #ifdef V4L2_PIX_FMT_YYUV 00100 { "V4L2_PIX_FMT_YYUV", V4L2_PIX_FMT_YYUV }, 00101 #endif 00102 #ifdef V4L2_PIX_FMT_YVYU 00103 { "V4L2_PIX_FMT_YVYU", V4L2_PIX_FMT_YVYU }, 00104 #endif 00105 #ifdef V4L2_PIX_FMT_UYVY 00106 { "V4L2_PIX_FMT_UYVY", V4L2_PIX_FMT_UYVY }, 00107 #endif 00108 #ifdef V4L2_PIX_FMT_VYUY 00109 { "V4L2_PIX_FMT_VYUY", V4L2_PIX_FMT_VYUY }, 00110 #endif 00111 #ifdef V4L2_PIX_FMT_YUV422P 00112 { "V4L2_PIX_FMT_YUV422P", V4L2_PIX_FMT_YUV422P }, 00113 #endif 00114 #ifdef V4L2_PIX_FMT_YUV411P 00115 { "V4L2_PIX_FMT_YUV411P", V4L2_PIX_FMT_YUV411P }, 00116 #endif 00117 #ifdef V4L2_PIX_FMT_Y41P 00118 { "V4L2_PIX_FMT_Y41P", V4L2_PIX_FMT_Y41P }, 00119 #endif 00120 #ifdef V4L2_PIX_FMT_YUV444 00121 { "V4L2_PIX_FMT_YUV444", V4L2_PIX_FMT_YUV444 }, 00122 #endif 00123 #ifdef V4L2_PIX_FMT_YUV555 00124 { "V4L2_PIX_FMT_YUV555", V4L2_PIX_FMT_YUV555 }, 00125 #endif 00126 #ifdef V4L2_PIX_FMT_YUV565 00127 { "V4L2_PIX_FMT_YUV565", V4L2_PIX_FMT_YUV565 }, 00128 #endif 00129 #ifdef V4L2_PIX_FMT_YUV32 00130 { "V4L2_PIX_FMT_YUV32", V4L2_PIX_FMT_YUV32 }, 00131 #endif 00132 #ifdef V4L2_PIX_FMT_YUV410 00133 { "V4L2_PIX_FMT_YUV410", V4L2_PIX_FMT_YUV410 }, 00134 #endif 00135 #ifdef V4L2_PIX_FMT_YUV420 00136 { "V4L2_PIX_FMT_YUV420", V4L2_PIX_FMT_YUV420 }, 00137 #endif 00138 #ifdef V4L2_PIX_FMT_HI240 00139 { "V4L2_PIX_FMT_HI240", V4L2_PIX_FMT_HI240 }, 00140 #endif 00141 #ifdef V4L2_PIX_FMT_HM12 00142 { "V4L2_PIX_FMT_HM12", V4L2_PIX_FMT_HM12 }, 00143 #endif 00144 #ifdef V4L2_PIX_FMT_NV12 00145 { "V4L2_PIX_FMT_NV12", V4L2_PIX_FMT_NV12 }, 00146 #endif 00147 #ifdef V4L2_PIX_FMT_NV21 00148 { "V4L2_PIX_FMT_NV21", V4L2_PIX_FMT_NV21 }, 00149 #endif 00150 #ifdef V4L2_PIX_FMT_NV16 00151 { "V4L2_PIX_FMT_NV16", V4L2_PIX_FMT_NV16 }, 00152 #endif 00153 #ifdef V4L2_PIX_FMT_NV61 00154 { "V4L2_PIX_FMT_NV61", V4L2_PIX_FMT_NV61 }, 00155 #endif 00156 #ifdef V4L2_PIX_FMT_SBGGR8 00157 { "V4L2_PIX_FMT_SBGGR8", V4L2_PIX_FMT_SBGGR8 }, 00158 #endif 00159 #ifdef V4L2_PIX_FMT_SGBRG8 00160 { "V4L2_PIX_FMT_SGBRG8", V4L2_PIX_FMT_SGBRG8 }, 00161 #endif 00162 #ifdef V4L2_PIX_FMT_SGRBG8 00163 { "V4L2_PIX_FMT_SGRBG8", V4L2_PIX_FMT_SGRBG8 }, 00164 #endif 00165 #ifdef V4L2_PIX_FMT_SRGGB8 00166 { "V4L2_PIX_FMT_SRGGB8", V4L2_PIX_FMT_SRGGB8 }, 00167 #endif 00168 #ifdef V4L2_PIX_FMT_SBGGR10 00169 { "V4L2_PIX_FMT_SBGGR10", V4L2_PIX_FMT_SBGGR10 }, 00170 #endif 00171 #ifdef V4L2_PIX_FMT_SGBRG10 00172 { "V4L2_PIX_FMT_SGBRG10", V4L2_PIX_FMT_SGBRG10 }, 00173 #endif 00174 #ifdef V4L2_PIX_FMT_SGRBG10 00175 { "V4L2_PIX_FMT_SGRBG10", V4L2_PIX_FMT_SGRBG10 }, 00176 #endif 00177 #ifdef V4L2_PIX_FMT_SRGGB10 00178 { "V4L2_PIX_FMT_SRGGB10", V4L2_PIX_FMT_SRGGB10 }, 00179 #endif 00180 #ifdef V4L2_PIX_FMT_SGRBG10DPCM8 00181 { "V4L2_PIX_FMT_SGRBG10DPCM8", V4L2_PIX_FMT_SGRBG10DPCM8 }, 00182 #endif 00183 #ifdef V4L2_PIX_FMT_SBGGR16 00184 { "V4L2_PIX_FMT_SBGGR16", V4L2_PIX_FMT_SBGGR16 }, 00185 #endif 00186 #ifdef V4L2_PIX_FMT_MJPEG 00187 { "V4L2_PIX_FMT_MJPEG", V4L2_PIX_FMT_MJPEG }, 00188 #endif 00189 #ifdef V4L2_PIX_FMT_JPEG 00190 { "V4L2_PIX_FMT_JPEG", V4L2_PIX_FMT_JPEG }, 00191 #endif 00192 #ifdef V4L2_PIX_FMT_DV 00193 { "V4L2_PIX_FMT_DV", V4L2_PIX_FMT_DV }, 00194 #endif 00195 #ifdef V4L2_PIX_FMT_MPEG 00196 { "V4L2_PIX_FMT_MPEG", V4L2_PIX_FMT_MPEG }, 00197 #endif 00198 #ifdef V4L2_PIX_FMT_CPIA1 00199 { "V4L2_PIX_FMT_CPIA1", V4L2_PIX_FMT_CPIA1 }, 00200 #endif 00201 #ifdef V4L2_PIX_FMT_WNVA 00202 { "V4L2_PIX_FMT_WNVA", V4L2_PIX_FMT_WNVA }, 00203 #endif 00204 #ifdef V4L2_PIX_FMT_SN9C10X 00205 { "V4L2_PIX_FMT_SN9C10X", V4L2_PIX_FMT_SN9C10X }, 00206 #endif 00207 #ifdef V4L2_PIX_FMT_SN9C20X_I420 00208 { "V4L2_PIX_FMT_SN9C20X_I420", V4L2_PIX_FMT_SN9C20X_I420 }, 00209 #endif 00210 #ifdef V4L2_PIX_FMT_PWC1 00211 { "V4L2_PIX_FMT_PWC1", V4L2_PIX_FMT_PWC1 }, 00212 #endif 00213 #ifdef V4L2_PIX_FMT_PWC2 00214 { "V4L2_PIX_FMT_PWC2", V4L2_PIX_FMT_PWC2 }, 00215 #endif 00216 #ifdef V4L2_PIX_FMT_ET61X251 00217 { "V4L2_PIX_FMT_ET61X251", V4L2_PIX_FMT_ET61X251 }, 00218 #endif 00219 #ifdef V4L2_PIX_FMT_SPCA501 00220 { "V4L2_PIX_FMT_SPCA501", V4L2_PIX_FMT_SPCA501 }, 00221 #endif 00222 #ifdef V4L2_PIX_FMT_SPCA505 00223 { "V4L2_PIX_FMT_SPCA505", V4L2_PIX_FMT_SPCA505 }, 00224 #endif 00225 #ifdef V4L2_PIX_FMT_SPCA508 00226 { "V4L2_PIX_FMT_SPCA508", V4L2_PIX_FMT_SPCA508 }, 00227 #endif 00228 #ifdef V4L2_PIX_FMT_SPCA561 00229 { "V4L2_PIX_FMT_SPCA561", V4L2_PIX_FMT_SPCA561 }, 00230 #endif 00231 #ifdef V4L2_PIX_FMT_PAC207 00232 { "V4L2_PIX_FMT_PAC207", V4L2_PIX_FMT_PAC207 }, 00233 #endif 00234 #ifdef V4L2_PIX_FMT_MR97310A 00235 { "V4L2_PIX_FMT_MR97310A", V4L2_PIX_FMT_MR97310A }, 00236 #endif 00237 #ifdef V4L2_PIX_FMT_SN9C2028 00238 { "V4L2_PIX_FMT_SN9C2028", V4L2_PIX_FMT_SN9C2028 }, 00239 #endif 00240 #ifdef V4L2_PIX_FMT_SQ905C 00241 { "V4L2_PIX_FMT_SQ905C", V4L2_PIX_FMT_SQ905C }, 00242 #endif 00243 #ifdef V4L2_PIX_FMT_PJPG 00244 { "V4L2_PIX_FMT_PJPG", V4L2_PIX_FMT_PJPG }, 00245 #endif 00246 #ifdef V4L2_PIX_FMT_OV511 00247 { "V4L2_PIX_FMT_OV511", V4L2_PIX_FMT_OV511 }, 00248 #endif 00249 #ifdef V4L2_PIX_FMT_OV518 00250 { "V4L2_PIX_FMT_OV518", V4L2_PIX_FMT_OV518 }, 00251 #endif 00252 #ifdef V4L2_PIX_FMT_STV0680 00253 { "V4L2_PIX_FMT_STV0680", V4L2_PIX_FMT_STV0680 }, 00254 #endif 00255 #ifdef V4L2_PIX_FMT_TM6000 00256 { "V4L2_PIX_FMT_TM6000", V4L2_PIX_FMT_TM6000 }, 00257 #endif 00258 #ifdef V4L2_PIX_FMT_CIT_YYVYUY 00259 { "V4L2_PIX_FMT_CIT_YYVYUY", V4L2_PIX_FMT_CIT_YYVYUY }, 00260 #endif 00261 #ifdef V4L2_PIX_FMT_KONICA420 00262 { "V4L2_PIX_FMT_KONICA420", V4L2_PIX_FMT_KONICA420 }, 00263 #endif 00264 }; 00265 00266 00267 void 00268 explain_buffer_v4l2_pixel_format(explain_string_buffer_t *sb, unsigned value) 00269 { 00270 const explain_parse_bits_table_t *tp; 00271 unsigned char cc[4]; 00272 00273 tp = explain_parse_bits_find_by_value(value, table, SIZEOF(table)); 00274 if (tp) 00275 { 00276 explain_string_buffer_puts(sb, tp->name); 00277 return; 00278 } 00279 00280 /* 00281 * if it consists of four printable characters, 00282 * it means the above table is probably incomplete 00283 */ 00284 cc[0] = value; 00285 cc[1] = value >> 8; 00286 cc[2] = value >> 16; 00287 cc[3] = value >> 24; 00288 if (isprint(cc[0]) && isprint(cc[1]) && isprint(cc[2]) && isprint(cc[3])) 00289 { 00290 explain_string_buffer_puts(sb, "v4l2_fourcc("); 00291 explain_string_buffer_putc_quoted(sb, cc[0]); 00292 explain_string_buffer_puts(sb, ", "); 00293 explain_string_buffer_putc_quoted(sb, cc[1]); 00294 explain_string_buffer_puts(sb, ", "); 00295 explain_string_buffer_putc_quoted(sb, cc[2]); 00296 explain_string_buffer_puts(sb, ", "); 00297 explain_string_buffer_putc_quoted(sb, cc[3]); 00298 explain_string_buffer_putc(sb, ')'); 00299 00300 if (explain_option_debug()) 00301 { 00302 explain_string_buffer_puts(sb->footnotes, "; "); 00303 explain_string_buffer_printf 00304 ( 00305 sb->footnotes, 00306 /* FIXME: i18n */ 00307 "the V4L2_PIX_FMT table in %s may be out of date", 00308 __FILE__ 00309 ); 00310 } 00311 return; 00312 } 00313 00314 /* 00315 * If all else fails, print it in hexadecimal. 00316 */ 00317 explain_string_buffer_printf(sb, "0x%08X", value); 00318 } 00319 00320 00321 enum explain_v4l2_pixel_format_check_t 00322 explain_v4l2_pixel_format_check(unsigned value) 00323 { 00324 if (explain_parse_bits_find_by_value(value, table, SIZEOF(table))) 00325 return explain_v4l2_pixel_format_check_ok; 00326 return explain_v4l2_pixel_format_check_nosuch; 00327 }; 00328 00329 #endif 00330 00331 /* vim: set ts=8 sw=4 et : */