⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qc-formats.c

📁 在Linux下用于webeye的摄像头的驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
	cur_bay = bay;	cur_rgb = rgb;	columns = total_columns + 2;	do {		qc_imag_writergb(cur_rgb+0,            bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+bpp,          bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line,     bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line+bpp, bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		cur_bay += 2;		cur_rgb += 2*bpp;	} while (--columns);	bay += bay_line2;	rgb += rgb_line2;	do {		cur_bay = bay;		cur_rgb = rgb;		columns = total_columns;				/* Process first 2x2 pixel block in a row here */		qc_imag_writergb(cur_rgb+0,            bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+bpp,          bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line,     bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line+bpp, bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		cur_bay += 2;		cur_rgb += 2*bpp;		do {			w = 4*cur_bay[0] - (cur_bay[-bay_line-1] + cur_bay[-bay_line+1] + cur_bay[bay_line-1] + cur_bay[bay_line+1]);			r = (2*(cur_bay[-1] + cur_bay[1]) + w) >> 2;			b = (2*(cur_bay[-bay_line] + cur_bay[bay_line]) + w) >> 2;			qc_imag_writergb(cur_rgb+0, bpp, CLIP(r,0,255), cur_bay[0], CLIP(b,0,255));			w = 4*cur_bay[1] - (cur_bay[-bay_line2+1] + cur_bay[-1] + cur_bay[3] + cur_bay[bay_line2+1]);			g = (2*(cur_bay[-bay_line+1] + cur_bay[0] + cur_bay[2] + cur_bay[bay_line+1]) + w) >> 3;			b = (2*(cur_bay[-bay_line] + cur_bay[-bay_line+2] + cur_bay[bay_line] + cur_bay[bay_line+2]) + w) >> 3;			qc_imag_writergb(cur_rgb+bpp, bpp, cur_bay[1], CLIP(g,0,255), CLIP(b,0,255));			w = 4*cur_bay[bay_line] - (cur_bay[-bay_line] + cur_bay[bay_line-2] + cur_bay[bay_line+2] + cur_bay[bay_line3]);			r = ((cur_bay[-1] + cur_bay[1] + cur_bay[bay_line2-1] + cur_bay[bay_line2+1]) + w) >> 2;			g = ((cur_bay[0] + cur_bay[bay_line-1] + cur_bay[bay_line+1] + cur_bay[bay_line2]) + w) >> 2;			qc_imag_writergb(cur_rgb+rgb_line, bpp, CLIP(r,0,255), CLIP(g,0,255), cur_bay[bay_line]);			w = 4*cur_bay[bay_line+1] - (cur_bay[0] + cur_bay[2] + cur_bay[bay_line2] + cur_bay[bay_line2+2]);			r = (2*(cur_bay[1] + cur_bay[bay_line2+1]) + w) >> 2;			b = (2*(cur_bay[bay_line] + cur_bay[bay_line+2]) + w) >> 2;			qc_imag_writergb(cur_rgb+rgb_line+bpp, bpp, CLIP(r,0,255), cur_bay[bay_line+1], CLIP(b,0,255));			cur_bay += 2;			cur_rgb += 2*bpp;		} while (--columns);		/* Process last 2x2 pixel block in a row here */		qc_imag_writergb(cur_rgb+0,            bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+bpp,          bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line,     bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line+bpp, bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		bay += bay_line2;		rgb += rgb_line2;	} while (--rows);	/* Process last two pixel rows here */	cur_bay = bay;	cur_rgb = rgb;	columns = total_columns + 2;	do {		qc_imag_writergb(cur_rgb+0,            bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+bpp,          bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line,     bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line+bpp, bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		cur_bay += 2;		cur_rgb += 2*bpp;	} while (--columns);}/* }}} *//* {{{ [fold] qc_imag_bay2rgb_gptm(unsigned char *bay, int bay_line, unsigned char *rgb, int rgb_line, int columns, int rows, int bpp, int sharpness) *//* Convert Bayer image to RGB image using Generalized Pei-Tam method (See: * "Effective Color Interpolation in CCD Color Filter Arrays Using Signal Correlation" * IEEE Transactions on Circuits and Systems for Video Technology, vol. 13, no. 6, June 2003. * Note that this is much improved version of the algorithm described in the paper) * bay = points to the bayer image data (upper left pixel is green) * bay_line = bytes between the beginnings of two consecutive rows * rgb = points to the rgb image data that is written * rgb_line = bytes between the beginnings of two consecutive rows * columns, rows = bayer image size (both must be even) * bpp = number of bytes in each pixel in the RGB image (should be 3 or 4) * sharpness = how sharp the image should be, between 0..65535 inclusive. *             23170 gives in theory image that corresponds to the original *             best, but human eye likes slightly sharper picture... 32768 is a good bet. *             When sharpness = 0, this routine is same as bilinear interpolation. *//* Execution time: 4344042 clock cycles for CIF image (Pentium II) */static inline void qc_imag_bay2rgb_gptm(unsigned char *bay, int bay_line,		   unsigned char *rgb, int rgb_line,		   int columns, int rows, int bpp, unsigned int sharpness){	/* 0.8 fixed point weights, should be between 0-256. Larger value = sharper, zero corresponds to bilinear interpolation. */	/* Best PSNR with sharpness = 23170 */	static const int wrg0 = 144;		/* Weight for Red on Green */	static const int wbg0 = 160;	static const int wgr0 = 120;	static const int wbr0 = 192;	static const int wgb0 = 120;	static const int wrb0 = 168;	int wrg;	int wbg;	int wgr;	int wbr;	int wgb;	int wrb;	unsigned int wu;	int r,g,b,w;	unsigned char *cur_bay, *cur_rgb;	int bay_line2, bay_line3, rgb_line2;	int total_columns;	/* Compute weights */	wu = (sharpness * sharpness) >> 16; 	wu = (wu * wu) >> 16;	wrg = (wrg0 * wu) >> 10;	wbg = (wbg0 * wu) >> 10;	wgr = (wgr0 * wu) >> 10;	wbr = (wbr0 * wu) >> 10;	wgb = (wgb0 * wu) >> 10;	wrb = (wrb0 * wu) >> 10;	/* Process 2 lines and rows per each iteration, but process the first and last two columns and rows separately */	total_columns = (columns>>1) - 2;	rows = (rows>>1) - 2;	bay_line2 = 2*bay_line;	bay_line3 = 3*bay_line;	rgb_line2 = 2*rgb_line;	/* Process first two pixel rows here */	cur_bay = bay;	cur_rgb = rgb;	columns = total_columns + 2;	do {		qc_imag_writergb(cur_rgb+0,            bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+bpp,          bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line,     bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line+bpp, bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		cur_bay += 2;		cur_rgb += 2*bpp;	} while (--columns);	bay += bay_line2;	rgb += rgb_line2;	do {		cur_bay = bay;		cur_rgb = rgb;		columns = total_columns;				/* Process first 2x2 pixel block in a row here */		qc_imag_writergb(cur_rgb+0,            bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+bpp,          bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line,     bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line+bpp, bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		cur_bay += 2;		cur_rgb += 2*bpp;		do {			w = 4*cur_bay[0] - (cur_bay[-bay_line-1] + cur_bay[-bay_line+1] + cur_bay[bay_line-1] + cur_bay[bay_line+1]);			r = (512*(cur_bay[-1] + cur_bay[1]) + w*wrg) >> 10;			b = (512*(cur_bay[-bay_line] + cur_bay[bay_line]) + w*wbg) >> 10;			qc_imag_writergb(cur_rgb+0, bpp, CLIP(r,0,255), cur_bay[0], CLIP(b,0,255));			w = 4*cur_bay[1] - (cur_bay[-bay_line2+1] + cur_bay[-1] + cur_bay[3] + cur_bay[bay_line2+1]);			g = (256*(cur_bay[-bay_line+1] + cur_bay[0] + cur_bay[2] + cur_bay[bay_line+1]) + w*wgr) >> 10;			b = (256*(cur_bay[-bay_line] + cur_bay[-bay_line+2] + cur_bay[bay_line] + cur_bay[bay_line+2]) + w*wbr) >> 10;			qc_imag_writergb(cur_rgb+bpp, bpp, cur_bay[1], CLIP(g,0,255), CLIP(b,0,255));			w = 4*cur_bay[bay_line] - (cur_bay[-bay_line] + cur_bay[bay_line-2] + cur_bay[bay_line+2] + cur_bay[bay_line3]);			r = (256*(cur_bay[-1] + cur_bay[1] + cur_bay[bay_line2-1] + cur_bay[bay_line2+1]) + w*wrb) >> 10;			g = (256*(cur_bay[0] + cur_bay[bay_line-1] + cur_bay[bay_line+1] + cur_bay[bay_line2]) + w*wgb) >> 10;			qc_imag_writergb(cur_rgb+rgb_line, bpp, CLIP(r,0,255), CLIP(g,0,255), cur_bay[bay_line]);			w = 4*cur_bay[bay_line+1] - (cur_bay[0] + cur_bay[2] + cur_bay[bay_line2] + cur_bay[bay_line2+2]);			r = (512*(cur_bay[1] + cur_bay[bay_line2+1]) + w*wrg) >> 10;			b = (512*(cur_bay[bay_line] + cur_bay[bay_line+2]) + w*wbg) >> 10;			qc_imag_writergb(cur_rgb+rgb_line+bpp, bpp, CLIP(r,0,255), cur_bay[bay_line+1], CLIP(b,0,255));			cur_bay += 2;			cur_rgb += 2*bpp;		} while (--columns);		/* Process last 2x2 pixel block in a row here */		qc_imag_writergb(cur_rgb+0,            bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+bpp,          bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line,     bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line+bpp, bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		bay += bay_line2;		rgb += rgb_line2;	} while (--rows);	/* Process last two pixel rows here */	cur_bay = bay;	cur_rgb = rgb;	columns = total_columns + 2;	do {		qc_imag_writergb(cur_rgb+0,            bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+bpp,          bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line,     bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		qc_imag_writergb(cur_rgb+rgb_line+bpp, bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		cur_bay += 2;		cur_rgb += 2*bpp;	} while (--columns);}/* }}} *//* {{{ [fold] qc_imag_rgbbgr(unsigned char *dst, int pixels, int bpp) *//* Convert RGB image to BGR or vice versa with the given number of pixels and * bytes per pixel */static void inline qc_imag_rgbbgr(unsigned char *dst, int pixels, int bpp){	unsigned char r,b;	do {		r = dst[0];		b = dst[2];		dst[0] = b;		dst[2] = r;		dst += bpp;	} while (--pixels);}/* }}} *//* }}} *//* {{{ [fold] **** qc_fmt:  Start of generic format query functions ********************** *//* {{{ [fold] struct qc_fmt_format: a format definition */struct qc_fmt_format {	u32 fcc;		/* M$ defined fourcc code, see http://www.fourcc.org */	signed char bpp;	/* 0=variable, -1=unknown (FIXME:what bpps do AVIs use here?) */	char order;		/* 'R' = RGB, 'B'=BGR, 0=not specified */	unsigned char nr, ng, nb;	/* Number of red, green, blue levels (0=256 levels) */	char *name;		/* Human-readable name */	Bool supported;		/* Can be converted to? */	/* Here we could add a pointer to list containing conversion routines to other fourcc's */	/* Then write code to create minimum spanning tree of format conversions */	/* Include estimated cost per pixel to apply a conversion routine to weight edges */};/* }}} *//* {{{ [fold] List of supported formats */#define BF_RGB(r,g,b)	'R', (b)&0xFF, (g)&0xFF, (r)&0xFF#define BF_BGR(r,g,b)	'B', (b)&0xFF, (g)&0xFF, (r)&0xFF#define NO_BF		0, 0, 0, 0#define FORMAT(ID,FCC1,FCC2,FCC3,FCC4,BPP,BF,NAME,SUPP) \static const struct qc_fmt_format qc_fmt_formats_##ID = { v4l2_fourcc(FCC1,FCC2,FCC3,FCC4), BPP, BF, NAME, SUPP }FORMAT(Y800,     'Y','8','0','0',   8, NO_BF,                 "GREY",   TRUE);FORMAT(RGB_HI,   'q','c','R','B',   8, BF_RGB(6, 6, 6),       "HI240",  FALSE);	/* Not sure: BF_RGB or BF_BGR? Same as BT20? Don't think so */FORMAT(RGB_332,  3,0,0,0,           8, BF_RGB(8, 8, 4),       "RGB332", FALSE);/* Little endian RGB formats (least significant byte at lowest address) */FORMAT(RGB_555L, 3,0,0,0,          16, BF_RGB(32, 32, 32),    "RGB555L",TRUE);	/* Should this be 15 or 16 bpp? Is this same as RGB2? */FORMAT(RGB_565L, 3,0,0,0,          16, BF_RGB(32, 64, 32),    "RGB565L",TRUE);	/* Is this same as RGB2? */FORMAT(RGB_24L,  'R','G','B','2',  24, BF_RGB(256, 256, 256), "RGB24L", TRUE);FORMAT(BGR_24L,  'R','G','B','2',  24, BF_BGR(256, 256, 256), "BGR24L", TRUE);FORMAT(RGB_32L,  'R','G','B','2',  32, BF_RGB(256, 256, 256), "RGB32L", TRUE);FORMAT(BGR_32L,  'R','G','B','2',  32, BF_BGR(256, 256, 256), "BGR32L", TRUE);/* Big endian RGB formats (most significant byte at lowest address) */FORMAT(RGB_555B, 'q','c','R','B',  16, BF_RGB(32, 32, 32),    "RGB555B",FALSE);FORMAT(RGB_565B, 'q','c','R','B',  16, BF_RGB(32, 64, 32),    "RGB565B",FALSE);/* Component YUV formats */FORMAT(YUY2,     'Y','U','Y','2',  16, NO_BF, "YUV422",    TRUE);		/* 4:2:2 packed pixel YUYV */FORMAT(UYVY,     'U','Y','V','Y',  16, NO_BF, "UYVY",      FALSE);FORMAT(IYUV,     'I','Y','U','V',  12, NO_BF, "YUV420",    FALSE);/* Planar YUV formats */FORMAT(YV12,     'Y','V','1','2',  12, NO_BF, "YV12",      FALSE);FORMAT(YVU9,     'Y','V','U','9',   9, NO_BF, "YVU9",      FALSE);FORMAT(Y41P,     'Y','4','1','P',  12, NO_BF, "Y41P",      FALSE);		/* 4:1:1 packed pixel UYVY UYVY YYYY */FORMAT(qcY1,     'q','c','Y','1',  12, NO_BF, "YUV411P",   FALSE);		/* Like Y41P but planar and Y, U and V planes are in this order */FORMAT(qcY2,     'q','c','Y','2',  16, NO_BF, "YUV422P",   TRUE);		/* Like YUY2 but planar */FORMAT(qcV1,     'q','c','V','1',  12, NO_BF, "YVU411P",   FALSE);		/* Like qcY1 but V and U planes are in this order */FORMAT(qcV2,     'q','c','V','2',  16, NO_BF, "YVU422P",   FALSE);		/* Like qcY2 but V and U planes are in this order */FORMAT(qcU9,     'q','c','U','9',   9, NO_BF, "YUV410P",   TRUE);		/* Like YVU9 but U and V planes are in this order */FORMAT(qcYY,     'q','c','Y','Y',  12, NO_BF, "YYUV",      FALSE);		/* Packed 4:2:2 sampling, Y, Y, U, V  */FORMAT(NV12,     'N','V','1','2',  12, NO_BF, "NV12",      FALSE);FORMAT(NV21,     'N','V','2','1',  12, NO_BF, "NV21",      FALSE);/* Special formats */FORMAT(qcBT,     'q','c','B','T',  -1, NO_BF, "BT848 RAW", FALSE);		/* RAW is raw scanline data sampled (before PAL decoding) */FORMAT(qcBR,     'q','c','B','R',   8, NO_BF, "BAYER",     TRUE);		/* Same as STVA? */FORMAT(qcMJ,     'q','c','M','J',   0, NO_BF, "MJPEG",     TRUE);		/* Same as MJPG? */FORMAT(qcWN,     'q','c','W','N',  -1, NO_BF, "Winnov hw", FALSE);		/* Same as WNV1 (or CHAM, WINX, YUV8)? *//* }}} *//* {{{ [fold] struct qc_fmt_alias: Alias fourcc codes for above formats */static struct qc_fmt_alias {	u32 fcc;	struct qc_fmt_format const *format;} const qc_fmt_aliases[] = {	{ v4l2_fourcc(0,0,0,0),         &qc_fmt_formats_RGB_24L },	/* Could be any format with fourcc 'RGB2' */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -