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

📄 show.c

📁 在Linux下用于webeye的摄像头的驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
	/* 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 {		write_rgb(cur_rgb+0,            bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		write_rgb(cur_rgb+bpp,          bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		write_rgb(cur_rgb+rgb_line,     bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		write_rgb(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 */		write_rgb(cur_rgb+0,            bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		write_rgb(cur_rgb+bpp,          bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		write_rgb(cur_rgb+rgb_line,     bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		write_rgb(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;			write_rgb(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;			write_rgb(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;			write_rgb(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;			write_rgb(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 */		write_rgb(cur_rgb+0,            bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		write_rgb(cur_rgb+bpp,          bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		write_rgb(cur_rgb+rgb_line,     bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		write_rgb(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 {		write_rgb(cur_rgb+0,            bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		write_rgb(cur_rgb+bpp,          bpp, cur_bay[1], cur_bay[0],          cur_bay[bay_line]);		write_rgb(cur_rgb+rgb_line,     bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]);		write_rgb(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);}/* Copy only those values into RGB image, which are in the Bayer image too, leave the rest zero */static inline void bayer_to_rgb_copyonly(unsigned char *bay, int bay_line,		   unsigned char *rgb, int rgb_line,		   int columns, int rows, int bpp){	unsigned char *cur_bay, *cur_rgb;	int bay_line2, rgb_line2;	int total_columns;	/* Process 2 lines and rows per each iteration */	total_columns = columns >> 1;	rows >>= 1;	bay_line2 = 2*bay_line;	rgb_line2 = 2*rgb_line;	do {		cur_bay = bay;		cur_rgb = rgb;		columns = total_columns;		do {			write_rgb(cur_rgb+0,            bpp, 0,          cur_bay[0],          0);			write_rgb(cur_rgb+bpp,          bpp, cur_bay[1], 0,                   0);			write_rgb(cur_rgb+rgb_line,     bpp, 0,          0,                   cur_bay[bay_line]);			write_rgb(cur_rgb+rgb_line+bpp, bpp, 0,          cur_bay[bay_line+1], 0);			cur_bay += 2;			cur_rgb += 2*bpp;		} while (--columns);		bay += bay_line2;		rgb += rgb_line2;	} while (--rows);}		  void bayer_to_rgb(unsigned char *bay, int bay_line, unsigned char *rgb, int rgb_line, int columns, int rows){	/* Measure 100 frames at highest optimization level, cycles per pixel *///	bayer_to_rgb_noip(bay, bay_line, rgb, rgb_line, columns, rows, 4);		/* 20.29 *///	bayer_to_rgb_horip(bay, bay_line, rgb, rgb_line, columns, rows, 4);		/* 21.77 *///	bayer_to_rgb_ip(bay, bay_line, rgb, rgb_line, columns, rows, 4);		/* 21.02 *///	bayer_to_rgb_cott(bay, bay_line, rgb, rgb_line, columns, rows, 4);		/* 21.25 *///	bayer_to_rgb_cottnoip(bay, bay_line, rgb, rgb_line, columns, rows, 4);		/* 21.35 *///	bayer_to_rgb_gptm(bay, bay_line, rgb, rgb_line, columns, rows, 4);		/* 42.85 (36.62 with unsigned multipliers) *///	bayer_to_rgb_gptm_fast(bay, bay_line, rgb, rgb_line, columns, rows, 4);		/* 37.44 */	bayer_to_rgb_copyonly(bay, bay_line, rgb, rgb_line, columns, rows, 4);		/* 20.48 */}static inline void grey_to_buffer(unsigned char *grey, int grey_line, unsigned char *rgb, int rgb_line, int columns, int rows, int bpp){	unsigned char *cur_grey, *cur_rgb;	int total_columns = columns;	do {		cur_grey = grey;		cur_rgb  = rgb;		columns  = total_columns;		do {			write_rgb(cur_rgb, bpp, *cur_grey, *cur_grey, *cur_grey);			cur_grey++;			cur_rgb += bpp;		} while (--columns);		grey += grey_line;		rgb  += rgb_line;	} while (--rows);}/* Copyright (c) 2000 Jeroen B. Vreeken (pe1rxq@amsat.org) from Endpoints (formerly known as AOX) se401 USB Camera Driver*//*        This shouldn't really be done in a v4l driver....        But it does make the image look a lot more usable.        Basically it lifts the dark pixels more than the light pixels.*//* 1195964 clock cycles on PIII, 4 times slower than LUT-approach */static inline void enhance_picture(unsigned char *frame, int len){        while (len--) {                *frame=(((*frame^255)*(*frame^255))/255)^255;                frame++;        }}/*-----------------------------------------------------------------*/void initializeX (int width, int height){	XGCValues *xgc;	if (dpy!=0) 		return;	xgc=( XGCValues *) malloc(sizeof(XGCValues) );	if (!(dpy = XOpenDisplay (""))) 	{		(void) fprintf (stderr, "Error:  Can't open display\n");		exit (1);	}	screen = DefaultScreen (dpy);   	win = XCreateSimpleWindow (dpy, DefaultRootWindow (dpy),				   0, 0, width, height, 1,				   WhitePixel (dpy, screen),				   BlackPixel (dpy, screen));	XSelectInput (dpy, win, 		      ExposureMask | StructureNotifyMask		      | KeyPressMask | ButtonPressMask		      |VisibilityChangeMask |PropertyChangeMask);	depth=DefaultDepth(dpy,screen);	if ((depth!=24)&&(depth!=16))	{		fprintf(stderr,"quickcam works only with 16/24Bit displays\n");		exit(0);	}		if (depth==24)		bypp=4;	else		bypp=2;	XStoreName (dpy, win, "QuickCam");	XMapWindow (dpy, win);	gc = XCreateGC (dpy, win, 0,  xgc);	for (;;) 	{				XEvent event;		XNextEvent(dpy, &event);		if (event.type == Expose) break;	}}/*-----------------------------------------------------------------*/void NewPictImage(int width, int height){       	img=NULL;  	img = XShmCreateImage(dpy, None, depth, ZPixmap, NULL,			      &shminfo, width, height+16);	if (img == NULL) 	{		fprintf(stderr, "Shared memory error.\n");		fprintf(stderr, "Ximage error.\n");		exit(0);	}	/* Success here, continue. */	shminfo.shmid = shmget(IPC_PRIVATE, (width*bypp*(height+16)), 			       IPC_CREAT|0777);    	if (shminfo.shmid < 0) 	{		XDestroyImage(img);		img = NULL;		fprintf(stderr, "Shared memory error.\n");		fprintf(stderr, "Seg. id. error.\n");		exit(0);	}	shminfo.shmaddr = (char *) shmat(shminfo.shmid, 0, 0);	if (shminfo.shmaddr == ((char *) -1)) 	{		XDestroyImage(img);		img = NULL;		fprintf(stderr, "Shared memory error.\n");		fprintf(stderr, "Address error.\n");		exit(0);	}	img->data = shminfo.shmaddr;	shminfo.readOnly = False;	XShmAttach(dpy, &(shminfo));	shmctl(shminfo.shmid,IPC_RMID,NULL);	XSync(dpy, False);	fprintf(stderr, "Sharing memory.\n");}void set_pixel24(int mode, int x, int y, int yy, int xxx, int width,		 long long *mid_valuer, long long *mid_valueg, long long *mid_valueb){	unsigned char *o;	o=((char*)shminfo.shmaddr)+4*x+(width*4*(yy)); 	if (!(y&1)) // even row	{		if ((x&1)) // odd column, red		{			*mid_valuer+=xxx;			*(o+2)=xxx;			*(o+2-4)=xxx;	      			if (!mode)			{				*(o+2+4*width)=xxx;				*(o+2-4+4*width)=xxx;			}		}		else  // green		{			*(o+1)=xxx;		     			*(o+1+4)=xxx;			*mid_valueg+=xxx;		}	}	else	{		if ((x&1)) // odd column green		{				*mid_valueg+=xxx;			*(o+1)=xxx;			*(o+1-4)=xxx;					}		else //blue		{			*mid_valueb+=xxx;			*(o)=xxx;			*(o+4)=xxx;			if (!mode)			{				*(o-4*width)=xxx;				*(o+4-4*width)=xxx;				}		}	}}void set_rgbpixel24(int x, int y, int r, int g, int b, int width){	unsigned char *o;	o=((char*)shminfo.shmaddr)+4*x+(width*4*y);	*(o+2) = r;	*(o+1) = g;	*(o  ) = b;}void set_rgbpixel16(int x, int y, int r, int g, int b, int width) {	unsigned short *o;	o = ((ushort*)shminfo.shmaddr)+x+(width*y);	*(o) = (r>>3) << 11 | (g >> 2) << 5 | (b >> 3);}/*-----------------------------------------------------------------*/// Byte 0:  GGGBBBBB// Byte 1:  RRRRRGGG// short :  RRRR RGGG GGGB BBBB#define SET_PIXR(addr, val) *(addr)=(*(addr)&~0xf800)|(((val)>>3)<<11)#define SET_PIXG(addr, val) *(addr)=(*(addr)&~0x07e0)|(((val)>>2)<<5)#define SET_PIXB(addr, val) *(addr)=(*(addr)&~0x001f)|(((val)>>3))#define WEIGHTING(x,y) 1void set_pixel16(int mode, int x, int y, int yy, int xxx, int width,		 long long *mid_valuer, long long *mid_valueg, long long *mid_valueb){	short *o;	o=(short*)((char*)shminfo.shmaddr+ 2*x+ width*2*yy); 	if (!(y&1)) // even row	{		if ((x&1)) // odd column, red		{			*mid_valuer+=xxx;#if 1			SET_PIXR(o,xxx);			SET_PIXR(o+1,xxx);			if (!mode)			{				SET_PIXR(o+width,xxx);

⌨️ 快捷键说明

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