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

📄 vdc.c

📁 linux 嵌入式原代码
💻 C
📖 第 1 页 / 共 3 页
字号:
			*up++ = p2.r;			*up++ = p2.g;			*up++ = p2.b;			pix_rgb2yuv(yuv_buf, ubuf);			break;				}	case PIXUT_RGB_NOPACK:	case PIXUT_RGB_PACK:		pix_set(&p2);		p2.x++;		pix_set(&p2);		break;	}}static voidpix_hline(struct pix_prm *p){	struct pix_prm p2, p3;	int sz, i;	char *src, *dst;	p2 = *p;	sz = pix_sz(p->pix_type);	switch(p->pix_type){	case PIXUT_YUV:		if(p2.x & 1){			pix_set(&p2);			p2.x++;			p2.w--;		}		p3 = p2;		p3.x = p2.x + p2.w - 1;		if((p3.x & 1) == 0){			pix_set(&p3);			p2.w--;		}		if(p2.w <= 0) break;		src = pix_buf_posi(&p2);		pix_set2(&p2);		p2.x += 2;		p2.w -= 2;		sz *= 2;		dst = src + sz;		for(i=2; i<p2.w; i+=2){			bcopy(src, dst, sz);			dst += sz;		}		break;	case PIXUT_RGB_NOPACK:	case PIXUT_RGB_PACK:		src = pix_buf_posi(&p2);		pix_set(&p2);		dst = src + sz;		for(i=1; i<p2.w; i++){			bcopy(src, dst, sz);			dst += sz;		}		break;	}}static voidpix_box(struct pix_prm *p){	struct pix_prm p2;	int i;	p2 = *p;	for(i=0; i<p->h; i++){		pix_hline(&p2);		p2.y++;	}}static voidpix_pat_grad_inner(struct pix_prm *p,		   int rx, int ry, int rc, 		   int gx, int gy, int gc, 		   int bx, int by, int bc){	struct pix_prm p2;	int x, y, w2, h2, r, g, b, dx;	p2 = *p;	p2.r = p2.g = p2.b = 0;	w2 = p->w - 1;	h2 = p->h - 1;	if(p->pix_type == PIXUT_YUV){		for(y=0; y<p->h; y++){			for(x=0; x<p->w; x+=2){				r = rx * x / w2 + ry * y / h2 + rc;				g = gx * x / w2 + gy * y / h2 + gc;				b = bx * x / w2 + by * y / h2 + bc;				r &= 0xff;				g &= 0xff;				b &= 0xff;				p2.x = p->x + x;				p2.y = p->y + y;				p2.r = r;				p2.g = g;				p2.b = b;				pix_set2(&p2);			}		}	}else{		for(y=0; y<p->h; y++){			for(x=0; x<p->w; x++){				r = rx * x / w2 + ry * y / h2 + rc;				g = gx * x / w2 + gy * y / h2 + gc;				b = bx * x / w2 + by * y / h2 + bc;				r &= 0xff;				g &= 0xff;				b &= 0xff;				p2.x = p->x + x;				p2.y = p->y + y;				p2.r = r;				p2.g = g;				p2.b = b;				pix_set(&p2);			}		}	}}static voidpix_pat_grad(struct pix_prm *p){	pix_pat_grad_inner(p, 255,0,0 , 0,255,0 , 0,0,128);}static voidpix_pat_bw(struct pix_prm *p){	struct pix_prm p2;	int x2, y2;	p2 = *p;	x2 = p->w * 2 / 3;	y2 = p->h * 1 / 5;	p2.w = x2;	p2.h = y2;		p2.r = p2.g = p2.b = 0;	pix_box(&p2);	p2.x = p->x + x2;	p2.y = p->y;	p2.w = p->w - x2;	p2.h = y2;	p2.r = p2.g = p2.b = 255;	pix_box(&p2);	p2.x = p->x;	p2.y = p->y + y2;	p2.w = x2;	p2.h = p->h - y2;	p2.r = p2.g = p2.b = 255;	pix_box(&p2);	p2.x = p->x + x2;	p2.y = p->y + y2;	p2.w = p->w-x2;	p2.h = p->h-y2;	p2.r = p2.g = p2.b = 0;	pix_box(&p2);}static voidpix_pat_cbar(struct pix_prm *p){	struct pix_prm p2;	int i, n, r, g, b, x1, x2, y1, ww, hh;	p2 = *p;	n = 6;	hh = p->h * 3 / 4;	p2.h = hh;	for(i=0; i<n; i++){		x1 = p->w * i / n;		x2 = p->w * (i+1) / n;		p2.w = x2 - x1;		p2.x = p->x + x1;		p2.b = ((i + 1) & 1) ? 255 : 0;		p2.r = ((i + 1) & 2) ? 255 : 0;		p2.g = ((i + 1) & 4) ? 255 : 0;		pix_box(&p2);	}	p2.x = p->x;	y1 = p->h * 3 / 4;	p2.y = p->y + y1;	p2.h = p->h - y1;	p2.w = p->w / 2;	p2.r = p2.g = p2.b = 0;	pix_box(&p2);	x1 = p->w / 2;	p2.x = p->x + x1;	p2.w = p->w - x1;	p2.r = p2.g = p2.b = 255;	pix_box(&p2);}static voidpix_pat_mix(struct pix_prm *p){	struct pix_prm p2;	p2 = *p;	p2.w /= 2;	p2.h /= 2;	pix_pat_grad(&p2);	p2.x = p2.w;	pix_pat_cbar(&p2);	p2.x = 0;	p2.y = p2.h;	pix_pat_bw(&p2);	p2.x = p2.w;	pix_pat_grad_inner(&p2,			   14, 14, 120 , 0,-255,512 , 255,0,0);}#define PIXUT_PAT_BW	(-1)#define PIXUT_PAT_GRAD	(-2)#define PIXUT_PAT_CBAR	(-3)#define PIXUT_PAT_MIX	(-4)static intpix_pat_arg2type(int ac, char **av){	if(opt_chk(ac, av, "-bw")) return PIXUT_PAT_BW;	if(opt_chk(ac, av, "-grad")) return PIXUT_PAT_GRAD;	if(opt_chk(ac, av, "-cbar")) return PIXUT_PAT_CBAR;	if(opt_chk(ac, av, "-mix")) return PIXUT_PAT_MIX;	return 0;}static intpix_pat_by_type(int type, struct pix_prm *p){	switch(type){	case PIXUT_PAT_BW:		pix_pat_bw(p);		return 0;	case PIXUT_PAT_GRAD:		pix_pat_grad(p);		return 0;	case PIXUT_PAT_CBAR:		pix_pat_cbar(p);		return 0;	case PIXUT_PAT_MIX:		pix_pat_mix(p);		return 0;	}	return -1;}static intpix_pat(int ac, char **av, int w, int h, char *buf, int pix_type, int dflt_pat, int interlace){	struct pix_prm p;	bzero(&p, sizeof(p));	p.w = w;	p.h = h;	p.buf = buf;	p.pix_type = pix_type;	p.interlace = interlace;	if(ac < 0){		if(pix_pat_by_type(ac, &p) != 0){			if(pix_pat_by_type(dflt_pat, &p) != 0) return -1;		}	}else{		if(pix_pat_by_type(pix_pat_arg2type(ac, av), &p) != 0){			if(pix_pat_by_type(dflt_pat, &p) != 0) return -1;		}	}	return 0;}#endif /* PIXUT */static voiddata_set(unsigned char *src, int sidx, 	 unsigned char *dst, int didx){	int sz;	sz = cfg.buf_unit_sz;	bcopy(src + sz * sidx, dst + sz * didx, sz);}static intselect_ut(int fd, int sec){	fd_set setr;	int x;	struct timeval *tm, tmo;	FD_ZERO(&setr);	FD_SET(fd, &setr);	tm = NULL;	if(sec >= 0){		tm = &tmo;		tm->tv_sec = sec;		tm->tv_usec = 0;	}	x = select(fd+1, &setr, NULL, NULL, tm);	if(x < 0){		perror("select_ut");		return x;	}	if(FD_ISSET(fd, &setr)) return 0; /* OK */	return 1; /* yet */}static voidwait_ut(int fd, int sec){	struct timeval tm_sta, tm_now, tm_tmp;	struct fr400vdc_read rd;	int run, sz, x;	gettimeofday(&tm_sta, NULL);	run = 1;	while(run){		x = select_ut(fd, 1);		if(x == 0){ /* OK readable */			sz = sizeof(rd);			x = read(fd, (void*)&rd, sz);			if(x >= sz){				switch(rd.type){				case FR400CC_VDC_RTYPE_ERR_UNDERFLOW:					printf("err underflow\n");				}			}		}		gettimeofday(&tm_now, NULL);		tm_dif(&tm_now, &tm_sta, &tm_tmp);		if(tm_tmp.tv_sec >= sec) run = 0;	}}#if RGB_DBLstatic voidwait_ut_dbl(int fd, int sec, int pack){	struct timeval tm_sta, tm_now, tm_tmp;	struct fr400vdc_read rd;	int run, sz, x;#if PIXUT#else	static void rgb_test_data_set_grad(char *buf, int pack);	static void rgb_test_data_set_bw(char *buf, int pack);#endif	gettimeofday(&tm_sta, NULL);	run = 1;	while(run){		x = select_ut(fd, 1);		if(x == 0){ /* OK readable */			sz = sizeof(rd);			x = read(fd, (void*)&rd, sz);			if(x >= sz){				switch(rd.type){				case FR400CC_VDC_RTYPE_ERR_UNDERFLOW:					printf("err underflow\n");					break;				case FR400CC_VDC_RTYPE_FRAME_FIN:					if(rd.count == 0){#if PIXUT						pix_pat(PIXUT_PAT_GRAD, NULL, cfg.pix_x, cfg.pix_y, mmap_area, pix_type_rgb(pack), 0, 0);#else						rgb_test_data_set_grad(mmap_area, pack);#endif					}else{#if PIXUT						pix_pat(PIXUT_PAT_BW, NULL, cfg.pix_x, cfg.pix_y, mmap_area, pix_type_rgb(pack), 0, 0);#else						rgb_test_data_set_bw(mmap_area + cfg.buf_unit_sz, pack);#endif					}					ioctl(fd, VDCIOCSDAT, rd.count);					break;				}			}		}		gettimeofday(&tm_now, NULL);		tm_dif(&tm_now, &tm_sta, &tm_tmp);		if(tm_tmp.tv_sec >= sec) run = 0;	}}#endif#if RGB#if PIXUT	/* cut */#elsestatic voidrgb_test_data_set_grad(char *buf, int pack){	int x, y;	unsigned char r, g, b;	for(y=0; y<cfg.pix_y; y++){		for(x=0; x<cfg.pix_x; x++){	r = (unsigned char)(255 * y / (cfg.pix_y - 1));	g = (unsigned char)(255 * x / (cfg.pix_x - 1));	b = (unsigned char)(128);			if(!pack) *buf++ = 0;			*buf++ = r;			*buf++ = g;			*buf++ = b;		}	}}static voidrgb_test_data_set_bw(char *buf, int pack){	int x, y;	unsigned char bw;	for(y=0; y<cfg.pix_y; y++){		for(x=0; x<cfg.pix_x; x++){			if(!pack) *buf++ = 0;			bw = (x < cfg.pix_x*2/3) ^ (y < cfg.pix_y*1/5);			bw *= 255;			*buf++ = bw;			*buf++ = bw;			*buf++ = bw;		}	}}static voidpix_set(int x, int y, int r, int g, int b, char *buf, int pack){	buf += (y * cfg.pix_x + x) * (pack ? 3 : 4);	if(!pack) *buf++ = 0;	*buf++ = (unsigned char)r;	*buf++ = (unsigned char)g;	*buf++ = (unsigned char)b;}static voidhline(int x1, int x2, int y, int r, int g, int b, char *buf, int pack){	int ix;	buf += (y * cfg.pix_x + x1) * (pack ? 3 : 4);	for(ix=x1; ix<=x2; ix++){		if(!pack) *buf++ = 0;		*buf++ = (unsigned char)r;		*buf++ = (unsigned char)g;		*buf++ = (unsigned char)b;	}}static voidbox(int x, int y, int w, int h, int r, int g, int b, char *buf, int pack){	int x2, y2, iy;	x2 = x + w - 1;		y2 = y + h - 1;	for(iy=y; iy<=y2; iy++){		hline(x, x2, iy, r, g, b, buf, pack);	}}static voidrgb_test_data_set_cbar(char *buf, int pack){	int i, n, r, g, b, x1, x2, y1, w, h;	n = 6;	h = cfg.pix_y * 3 / 4;	for(i=0; i<n; i++){		x1 = cfg.pix_x * i / n;		x2 = cfg.pix_x * (i+1) / n;		w = x2 - x1;		b = ((i + 1) & 1) ? 255 : 0;		r = ((i + 1) & 2) ? 255 : 0;		g = ((i + 1) & 4) ? 255 : 0;		box(x1, 0, w, h, r, g, b, buf, pack);	}	y1 = cfg.pix_y * 3 / 4;	h = cfg.pix_y - y1;	w = cfg.pix_x / 2;	box(0, y1, w, h, 0, 0, 0, buf, pack);	x1 = cfg.pix_x / 2;	w = cfg.pix_x - x1;	box(x1, y1, w, h, 255, 255, 255, buf, pack);}#endif /* PIXUT */#if YUV_TEST_DATA#if PIXUT	/* cut */#elsestatic voidrgb2yuv(unsigned char *src, unsigned char *dst){	unsigned int r1, r2, g1, g2, b1, b2;	double R, G, B;	double Y1, Y2, U, V;	unsigned int y1, y2, u, v;	r1 = *src++;	g1 = *src++;	b1 = *src++;	r2 = *src++;	g2 = *src++;	b2 = *src++;	Y1 = 0.2989*r1 + 0.5866*g1 + 0.1145*b1;	Y2 = 0.2989*r2 + 0.5866*g2 + 0.1145*b2;	R = (r1 + r2) / 2.0;	G = (g1 + g2) / 2.0;	B = (b1 + b2) / 2.0;	U = -0.1684*R -0.3311*G + 0.4997*B;	V = 0.4998*R - 0.4187*G - 0.0813*B;	y1 = Y1;	y2 = Y2;	u = U + 128;	v = V + 128;	*dst++ = y1;	*dst++ = u;	*dst++ = y1;	*dst++ = v;}static voidyuv_test_data_set_grad(char *buf){	int x, y;	unsigned char r, g, b;	char lbuf[10], *lbufp;	lbufp = lbuf;	for(y=0; y<cfg.pix_y; y++){		for(x=0; x<cfg.pix_x; x++){	r = (unsigned char)(255 * y / (cfg.pix_y - 1));	g = (unsigned char)(255 * x / (cfg.pix_x - 1));	b = (unsigned char)(128);			*lbufp++ = r;			*lbufp++ = g;			*lbufp++ = b;			if(x & 1){				rgb2yuv(lbuf, buf);				lbufp = lbuf;				buf += 4;			}		}	}}static voidyuv_test_data_set_bw(char *buf){	int x, y;	unsigned char bw;	char lbuf[10], *lbufp;	lbufp = lbuf;	for(y=0; y<cfg.pix_y; y++){		for(x=0; x<cfg.pix_x; x++){			bw = (x < cfg.pix_x*2/3) ^ (y < cfg.pix_y*1/5);			bw *= 255;			*lbufp++ = bw;			*lbufp++ = bw;			*lbufp++ = bw;			if(x & 1){				rgb2yuv(lbuf, buf);				lbufp = lbuf;				buf += 4;			}		}	}}#endif /* PIXUT */#endif /* YUV_TEST_DATA */static intrgb_test(int ac, char **av, int sec){	static int prm[13] = {		0, /* htc */		640, /* hdc */ /* 320..1920 */		18, /* hfp */ /* 1..96 */		48, /* hsc */ /* 1..192 */		56, /* hbp */ /* 1..312 */		0, /* vtc */		480, /* vdc */ /* 240..1200 */		8, /* vfp */ /* 1..37 */		4, /* vsc */ /* 1..25 */		33, /* vbp */ /* 1..60 */		0, /* hip */ /* 0..10 */		0, /* vip */ /* 0..4 */		2, /* rck */	};	static int prm_xga[13] = {		0, /* htc */		1024, /* hdc */ /* 320..1920 */		10, /* hfp */ /* 1..96 */		16, /* hsc */ /* 1..192 */		16, /* hbp */ /* 1..312 */		0, /* vtc */		768, /* vdc */ /* 240..1200 */		2, /* vfp */ /* 1..37 */		4, /* vsc */ /* 1..25 */		4, /* vbp */ /* 1..60 */		0, /* hip */ /* 0..10 */		0, /* vip */ /* 0..4 */		2, /* rck */	};	static int prm_lcd[13] = {		0, /* htc */		320, /* hdc */ /* 320..1920 */		1, /* hfp */ /* 1..96 */		1, /* hsc */ /* 1..192 */		1, /* hbp */ /* 1..312 */		0, /* vtc */		242, /* vdc */ /* 240..1200 */		1, /* vfp */ /* 1..37 */		1, /* vsc */ /* 1..25 */		1, /* vbp */ /* 1..60 */		0, /* hip */ /* 0..10 */		0, /* vip */ /* 0..4 */		6, /* rck */	};	int pack;#if RGB_DBL	int rgb_dbl;#endif	if(opt_chk(ac,av,"-xga")){		bcopy(prm_xga, prm, 4*13);	}	if(opt_chk(ac,av,"-h320")){		prm[12] *= 2;	/* rck */		prm[1] /= 2;	/* hdc */		prm[2] /= 2;	/* hfs */		prm[3] /= 2;	/* hsc */		prm[4] /= 2;	/* hbp */		prm[10] /= 2;	/* hip */	}	if(opt_chk(ac,av,"-lcd")){		bcopy(prm_lcd, prm, 4*13);	}	opt_chk_int(ac,av,"-rck", &prm[12]);	opt_chk_int(ac,av,"-hdc", &prm[1]);		opt_chk_int(ac,av,"-hfp", &prm[2]);	opt_chk_int(ac,av,"-hsc", &prm[3]);	opt_chk_int(ac,av,"-hbp", &prm[4]);	opt_chk_int(ac,av,"-vdc", &prm[6]);	opt_chk_int(ac,av,"-vfp", &prm[7]);	opt_chk_int(ac,av,"-vsc", &prm[8]);	opt_chk_int(ac,av,"-vbp", &prm[9]);	opt_chk_int(ac,av,"-hip", &prm[10]);	opt_chk_int(ac,av,"-vip", &prm[11]);	bcopy(prm, cfg.prm, 4*13);	cfg.pix_x = cfg.prm[1];	cfg.pix_y = cfg.prm[6];	pack = opt_chk(ac,av,"-pack");#if VDC_CFG_MOD	cfg.pix_sz = pack ? 3 : 4;#endif#if YUV_TEST_DATA	if(opt_chk(ac,av,"-yuv")){		cfg.pix_sz = 2;fprintf(stderr, "--> yuv data set\n");#if PIXUT		pix_pat(ac, av, cfg.pix_x, cfg.pix_y, mmap_area, PIXUT_YUV, PIXUT_PAT_BW, 1);#else		if(opt_chk(ac,av,"-grad")){			yuv_test_data_set_grad(mmap_area);		}else{			yuv_test_data_set_bw(mmap_area);		}#endiffprintf(stderr, "<-- yuv data set\n");	}else{#endif#if RGB_DBL    rgb_dbl = opt_chk(ac,av,"-dbl");    if(rgb_dbl){	if(cfg.buf_num < 2){		fprintf(stderr, "(buf_num=%d)<2\n", cfg.buf_num);		close(fd);		return -1;

⌨️ 快捷键说明

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