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

📄 w3cam.c

📁 usb摄像头测试源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
		printf ("<option%s>SECAM</option>", norm == NORM_SECAM?" selected":"");		printf ("<option>off</option>");	/* hide gui entry */		printf ("</SELECT>\n");	}	if (freqs && (input == IN_TV)) {		int f;		printf ("Freq:<SELECT name=freq>\n");		printf ("<option value=0>default</option>\n");		while (*freqs) {			f = atoi(*freqs);			printf ("<option%s>%d</option>",  freq == f ? " selected": "", f);			freqs++;		}		printf ("</SELECT>\n");	}	printf ("Format:<SELECT name=format>\n");	printf ("<option%s>PPM", fmt == FMT_PPM? " selected":"");	printf ("<option%s>PNG", fmt == FMT_PNG? " selected":"");	printf ("<option%s>JPEG</SELECT>\n", fmt == FMT_JPEG? " selected":"");	printf ("Size:<SELECT name=size>\n");	printf ("<option%s>80x60\n", width == 80  ? " selected": "");	printf ("<option%s>160x120", width == 160 ? " selected": "");	printf ("<option%s>240x180", width == 240 ? " selected": "");	printf ("<option%s>320x240", width == 320 ? " selected": "");	printf ("<option%s>400x300", width == 400 ? " selected": "");	printf ("<option%s>480x360", width == 480 ? " selected": "");	printf ("<option%s>640x480", width == 640 ? " selected": "");	printf ("<option%s>720x540", width == 720 ? " selected": "");	printf ("<option%s>768x576</SELECT>\n", width == 768 ? " selected": "");	printf ("Refresh (sec.):<SELECT name=refresh>\n");	printf ("<OPTION value=\"-1\">off\n");	printf ("<OPTION>0.0<OPTION>0.1<OPTION>0.5<OPTION>1.0<OPTION>2.0\n");	printf ("<OPTION>3.0<OPTION>4.0<OPTION>5.0\n");	printf ("<OPTION>10<OPTION>20<OPTION>40<OPTION>80\n");	if (refresh != OFF)		printf ("<option selected>%1.2f</SELECT>\n", refresh);	else		printf ("</SELECT>\n");	printf ("<P><input type=submit value=Update></FORM></DIV><P>\n");	cgi_html_end ("<HR><DIV class=footer>w3cam, &copy; rasca</DIV>");}/* */voidon_signal (int signum){	exit (0);}#ifdef HAVE_LIBTTF#include "font.c"#endif/* * main() */intmain (int argc, char *argv[]){	int width = WIDTH_DEFAULT, height = HEIGHT_DEFAULT, dev = -1;	char *val = NULL, **form = NULL, *image;	char *boundary = "--w3cam-ns-boundary--may-not-work-with-ie--";	char *freqlist = FREQLIST_DEFAULT;	char **freqs = NULL;	char *device = VIDEO_DEV;	int max_try = MAX_TRY_OPEN;	/* we try 20 times (5 sec) to open the device */	int quality = QUALITY_DEFAULT;	/* default jpeg quality setting */	int input = INPUT_DEFAULT;	int norm  = NORM_DEFAULT;	int mode = MODE_DEFAULT;	int color = TRUE;	int swapRGB = FALSE;	int palette = VIDEO_PALETTE_RGB24;	float refresh = REFRESH_DEFAULT;	float min_refresh = MIN_REFRESH;	int format = FMT_DEFAULT;	int usec = USEC_DEFAULT;	int freq = 0;	int protected = 0;	char *mime = NULL;#ifdef HAVE_LIBTTF	char *font = NULL;	char *timestamp = NULL;	int font_size = 12;#define TS_MAX 128	/* timestamp string */	char ts_buff[TS_MAX+1];	int ts_len;	int border = 2;	int blend = 60;	int align = 1;	time_t t;	struct tm *tm;	TT_Engine engine;	TT_Face face;	TT_Face_Properties properties;	TT_Instance instance;	TT_Glyph *glyphs = NULL;	TT_Raster_Map bit;	TT_Raster_Map sbit;#endif#ifdef USE_SYSLOG	openlog (argv[0], LOG_PID, LOG_USER);#endif	cgi_init (argv[0]);	if (signal (SIGTERM, on_signal) == SIG_ERR) {		log ("couldn't register handler for SIGTERM");	}	if (signal (SIGPIPE, on_signal) == SIG_ERR) {		log ("couldn't register handler for SIGPIPE");	}	/* check some values from the config file	 */	val = cgi_cfg_value ("width");	if (val) width = atoi (val);	val = cgi_cfg_value ("height");	if (val) height = atoi (val);	val = cgi_cfg_value ("color");	if (val) {		if (strcasecmp (val, "yuv420p") == 0) {			color = 1;			palette = VIDEO_PALETTE_YUV420P;		} else if (strcasecmp (val, "yuv422p") == 0) {			color = 1;			palette = VIDEO_PALETTE_YUV422P;		} else if (*val == '0' || *val == 'g') {			color = 0;			palette = VIDEO_PALETTE_GREY;		} else {			color = 1;		}	}	val = cgi_cfg_value ("refresh");	if (val) refresh = atof (val);	val = cgi_cfg_value ("norm");	if (val) norm = atoi (val);	val = cgi_cfg_value ("input");	if (val) input = atoi (val);	val = cgi_cfg_value ("format");	if (val) format = atoi (val);	val = cgi_cfg_value ("quality");	if (val) quality = atoi (val);	val = cgi_cfg_value ("mode");	if (val) mode = atoi (val);	val = cgi_cfg_value ("usleep");	if (val) usec = atoi (val);	val = cgi_cfg_value ("freq");	if (val) freq = atoi (val);	val = cgi_cfg_value ("freqlist");	if (val) freqlist = val;	val = cgi_cfg_value ("protected");	if (val) protected = atoi (val);	val = cgi_cfg_value ("device");	if (val) device = val;	val = cgi_cfg_value ("bgr");	if (val) swapRGB = atoi (val);#ifdef HAVE_LIBTTF	val = cgi_cfg_value ("font");	if (val) font = val;	val = cgi_cfg_value ("font_size");	if (val) font_size = atoi (val);	val = cgi_cfg_value ("timestamp");	if (val) timestamp = val;	val = cgi_cfg_value ("timestamp_border");	if (val) border = atoi (val);	val = cgi_cfg_value ("timestamp_blend");	if (val) blend = atoi (val);	val = cgi_cfg_value ("timestamp_align");	if (val) align = atoi (val);#endif	/* parse the form, if there is any	 */	if (!protected)		form = cgi_parse_form ();	if (form && !protected) {		val = cgi_form_value ("help");		if (val) {			usage (argv[0], width, height, color, quality, usec);		}		val = cgi_form_value ("size");		if (val) {			sscanf (val, "%dx%d", &width, &height);		}		val = cgi_form_value ("color");		if (val) {			if (strcasecmp (val, "yuv420p") == 0) {				color = 1;				palette = VIDEO_PALETTE_YUV420P;			} else if (strcasecmp (val, "yuv422p") == 0) {				color = 1;				palette = VIDEO_PALETTE_YUV422P;			} else if (*val == '0' || *val == 'g') {				color = 0;				palette = VIDEO_PALETTE_GREY;			} else {				color = 1;				palette = VIDEO_PALETTE_RGB24;			}		}		val = cgi_form_value ("format");		if (val) {			if ((strcasecmp ("ppm", val) == 0) && color) {				format = FMT_PPM;			} else if (strcasecmp ("png", val) == 0) {				format = FMT_PNG;			} else if (strcasecmp ("jpeg", val) == 0) {				format = FMT_JPEG;			}		}		val = cgi_form_value ("refresh");		if (val) refresh = atof (val);		val = cgi_form_value ("quality");		if (val) quality = atoi (val);		val = cgi_form_value ("usleep");		if (val) usec = atoi (val);		val = cgi_form_value ("freq");		if (val) freq = atoi (val);		val = cgi_form_value ("mode");		if (val) {			if (strcmp ("gui", val) == 0)				mode = MODE_GUI;			else if (strcmp ("html", val) == 0)				mode = MODE_HTML;			else				mode = MODE_PLAIN;		}		val = cgi_form_value ("input");		if (val) {			if (strcasecmp ("tv", val) == 0) {				input = IN_TV;			} else if (strcasecmp ("composite", val) == 0) {				input = IN_COMP1;			} else if (strcasecmp ("composite2", val) ==0) {				input = IN_COMP2;			} else if (strcasecmp ("s-video", val) == 0) {				input = IN_SVIDEO;			} else {				input = INPUT_DEFAULT;			}		}		val = cgi_form_value ("norm");		if (val) {			if (strcasecmp ("pal", val) == 0) {				norm = NORM_PAL;			} else if (strcasecmp ("ntsc", val) == 0) {				norm = NORM_NTSC;			} else if (strcasecmp ("secam", val) == 0) {				norm = NORM_SECAM;			} else {				norm = OFF;			}		}		val = cgi_form_value ("bgr");		if (val) {			/* check for yes,true,1 */			if ((*val == '1') || (*val == 't') || (*val == 'y')) {				swapRGB = 1;			} else {				swapRGB = 0;			}		}	}	if ((refresh > OFF) && (refresh < min_refresh))		refresh = min_refresh;	if (!*freqlist)		freqlist = NULL;	if (mode == MODE_GUI) {		freqs = parse_list (freqlist);		make_gui (width, height, color, input, format, quality, refresh, usec,					norm,freq, freqs, palette, swapRGB);		return (0);	}	if (mode == MODE_HTML) {		freqs = parse_list (freqlist);		make_html (width, height, color, input, format, quality, refresh, usec,					norm,freq, freqs, palette, swapRGB);		return (0);	}	switch (format) {		case FMT_PPM:			mime = "image/ppm";			break;		case FMT_JPEG:			mime = "image/jpeg";			break;		case FMT_PNG:			mime = "image/png";			break;		default:			log ("unknown image format..!?");			break;	}#ifdef HAVE_LIBTTF	if (font && timestamp) {		if (TT_Init_FreeType (&engine)) {			font = NULL;			goto no_time_stamp;		}		if (Face_Open (font, engine, &face, &properties, &instance, font_size)){			TT_Done_FreeType (engine);			font = NULL;			goto no_time_stamp;		}	}no_time_stamp:#endif	if (!color) {		palette = VIDEO_PALETTE_GREY;	}	/* open the video4linux device */again:	while (max_try) {		dev = open (device, O_RDWR);		if (dev == -1) {			log2 (device, strerror(errno));			if (!--max_try) {				cgi_response (http_ok, "text/plain");				printf ("Can't open device %s: %s\n",device,strerror(errno));				exit (0);			}			/* sleep 1/4 second */			usleep (250000);		} else {			max_try = MAX_TRY_OPEN;	/* we may need it in a loop later .. */			break;		}	}	if (v4l_mute_sound (dev) == -1) {		perror ("mute sound");	}	if (v4l_set_input (dev, input, norm) == -1) {		return 1;	}	if (v4l_check_size (dev, &width, &height) == -1) {		return 1;	}	/* if (v4l_check_palette (dev, &palette) == -1) {		return 1;	} */again_without_open:	image = get_image (dev, width, height, input, usec,freq, palette);	if (image) {		if (swapRGB && (palette == VIDEO_PALETTE_RGB24)) {			int x,y;			unsigned char *p, pt;			p = image;			for (y = 0; y < height; y++) {				for (x = 0; x < width; x++) {					pt = *p;					*p = *(p+2);					*(p+2) = pt;					p += 3;				}			}		}		if (refresh != 0.0) {			close (dev);		}		if (refresh != OFF) {			cgi_multipart (boundary);			printf ("Content-Type: %s\n\n", mime);		} else {			cgi_response (http_ok, mime);		}#ifdef HAVE_LIBTTF	if (font && timestamp) {		time (&t);		tm = localtime (&t);		ts_buff[TS_MAX] = '\0';		strftime (ts_buff, TS_MAX, timestamp, tm);		ts_len = strlen (ts_buff);		glyphs = Glyphs_Load (face, &properties, instance, ts_buff, ts_len);		Raster_Init(face, &properties,instance,ts_buff,ts_len, border, glyphs, &bit);		Raster_Small_Init (&sbit, &instance);		Render_String (glyphs, ts_buff, ts_len, &bit, &sbit, border);		if (bit.bitmap) {			int x, y, psize, i, x_off, y_off;			unsigned char *p;			if (color)				psize = 3;			else				psize = 1;			switch (align) {				case 1:					x_off = (width - bit.width) * psize;					y_off = 0;					break;				case 2:					x_off = 0;					y_off = height - bit.rows;					break;				case 3:					x_off = (width - bit.width) * psize;					y_off = height - bit.rows;					break;				default:					x_off = y_off = 0;					break;			}			for (y = 0; y < bit.rows; y++) {				p = image + (y + y_off) * (width * psize) + x_off;				for (x = 0; x < bit.width; x++) {					switch (((unsigned char *)bit.bitmap)								[((bit.rows-y-1)*bit.cols)+x]) {						case 0:							for (i = 0; i < psize; i++) {								*p = (255 * blend + *p * (100 - blend))/100;								p++;							}							break;						case 1:							for (i = 0; i < psize; i++) {								*p = (220 * blend + *p * (100 - blend))/100;								p++;							}							break;						case 2:							for (i = 0; i < psize; i++) {								*p = (162 * blend + *p * (100 - blend))/100;								p++;							}							break;						case 3:							for (i = 0; i < psize; i++) {								*p = (64 * blend + *p * (100 - blend))/100;								p++;							}							break;						default:							for (i = 0; i < psize; i++) {								*p = (0 * blend + *p * (100 - blend))/100;								p++;							}							break;					}				}			}		}		Raster_Done (&sbit);		Raster_Done (&bit);		Glyphs_Done (glyphs);		glyphs = NULL;	}#endif		switch (format) {			case FMT_PPM:				put_image_ppm (image, width, height);				printf ("\n%s\n", boundary);				break;			case FMT_PNG:				put_image_png (image, width, height, color);				printf ("\n%s\n", boundary);				break;			case FMT_JPEG:				put_image_jpeg (image, width, height, quality, color);				printf ("\n%s\n", boundary);				break;			default:				/* should never be reached */				printf ("Unknown format (%d)\n", format);				printf ("\n%s\n", boundary);				break;		}		free (image);		if (refresh == 0.0) {			fflush (stdout);			/* wait ? */			goto again_without_open;		}		if (refresh != OFF) {			fflush (stdout);			usleep ((int)(refresh * 1000000));			goto again;		}	} else {		cgi_response (http_ok, "text/plain");		printf ("Error: Can't get image\n");		close (dev);	}#ifdef HAVE_LIBTTF	if (font && timestamp) {		Face_Done (instance, face);		TT_Done_FreeType (engine);	}#endif	return (0);}

⌨️ 快捷键说明

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