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

📄 spcatools.c

📁 用于LINUX摄像头的相关程序
💻 C
📖 第 1 页 / 共 2 页
字号:
				size, OUTpict);			fclose(OUTpict);			}	}	/* All frame are extract now try to decode frame by frame*/	i = 0; run = 1;	printf("process frames %03d \n",i);	if (AVI_set_video_position (aviinput, i) < 0)	    printf ("error get video position\n");	sizein = AVI_frame_size (aviinput, i);	myframe->tmpbuffer = (unsigned char*) realloc( myframe->tmpbuffer,					(size_t) sizein);	if (AVI_read_frame			  (aviinput, (unsigned char *) myframe->tmpbuffer) < 0)			   printf ("Read error frames %d \n", i);#ifdef TGC	processFilter(myframe->tmpbuffer,myframe->data,sizein);	memcpy(myframe->tmpbuffer,myframe->data,sizein);#endif		   	spca50x_outpicture(myframe,force_rgb,ptmypict);	do {	quit1 = 1;	if (run) {	/* only refresh when change */		run = 0;		spca50x_outpicture(myframe,force_rgb,ptmypict);		if ( myframe->format == VIDEO_PALETTE_YUV420P) {		 	YUV420toRGB (myframe->data, pixels, myframe->width, myframe->height,	     			0,0);		} else {			memcpy (pixels,myframe->data,size);		}		editinfo( pscreen,Fontsmall, mypictChannel,		    ptmypict, myframe, i,1);						SDL_UpdateRect (pscreen, 0, 0, 0, 0);	}	if (SDL_PollEvent (&sdlevent) == 1) {				switch (sdlevent.type) {					case SDL_KEYDOWN:						switch (sdlevent.key.keysym.sym) {														case SDLK_RIGHT:								{ 									if ( i < (frames-1)) {									run = 1;									i++;									printf("process frames %03d \n",i);									if (AVI_set_video_position (aviinput, i) < 0)										printf ("error get video position\n");									sizein = AVI_frame_size (aviinput, i);									myframe->tmpbuffer = (unsigned char*) realloc( myframe->tmpbuffer,												 (size_t) sizein);									if (AVI_read_frame			    							(aviinput, (unsigned char *) myframe->tmpbuffer) < 0)											printf ("Read error frames %d \n", i);#ifdef TGC											processFilter(myframe->tmpbuffer,myframe->data,sizein);											memcpy(myframe->tmpbuffer,myframe->data,sizein);	#endif																		}																	}								break;							case SDLK_LEFT:								{ 									if (i > 0) {									run = 1;									i--;									printf("process frames %03d \n",i);									if (AVI_set_video_position (aviinput, i) < 0)										printf ("error get video position\n");									sizein = AVI_frame_size (aviinput, i);									myframe->tmpbuffer = (unsigned char*) realloc( myframe->tmpbuffer,												 (size_t) sizein);									if (AVI_read_frame			    							(aviinput, (unsigned char *) myframe->tmpbuffer) < 0)											printf ("Read error frames %d \n", i);#ifdef TGC																				processFilter(myframe->tmpbuffer,myframe->data,sizein);									memcpy(myframe->tmpbuffer,myframe->data,sizein);#endif																												}								}								break;							case SDLK_f:								printf ("bgr instead rgb asked, great about standard !!\n");								run = 1;								force_rgb = !force_rgb;																break;							case SDLK_s:								/* Reverse Red and Blue for Picture Thanks V4L*/								swapRB( pixels ,(myframe->width*myframe->height*3));								getPictureName (Picture, inputfile,"-F-", i, "pnm");								printf ("Get Picture %s!!\n",Picture);								OUTpict = fopen (Picture,"wb");									        fprintf (OUTpict, "P6\n%d %d\n255\n", myframe->width,										myframe->height);									fwrite (pixels , sizeof(char),									(myframe->width*myframe->height*3), OUTpict);								fclose(OUTpict);								swapRB( pixels ,(myframe->width*myframe->height*3));								break;							case SDLK_SPACE:								printf(" Edit Colors setting to Exit Press Space again \n");								run = 1;								while(quit1) {								if (run) {								/* only refresh when change */									run = 0;									//printf("Update screen Ask %d \n",ptmypict->change);									spca50x_outpicture(myframe,force_rgb,ptmypict);									if ( myframe->format == VIDEO_PALETTE_YUV420P) {		 							YUV420toRGB (myframe->data, pixels, myframe->width, myframe->height,	     										0,0);									} else {										memcpy (pixels,myframe->data,size);									}									editinfo( pscreen,Fontsmall, mypictChannel,		   							 ptmypict, myframe,j,0);									SDL_UpdateRect (pscreen, 0, 0, 0, 0);									//printf("Update screen done \n");								}								if (SDL_PollEvent (&sdledit) == 1) {									switch (sdledit.type) {									case SDL_KEYDOWN:										switch (sdledit.key.keysym.sym) {											case SDLK_F1:												run = 1;												if(mypict.gamma < 6) mypict.gamma++;												printf ("Gamma change to %d\n",mypict.gamma);												mypict.change = 0x01;																			break;											case SDLK_F2:												run = 1;												if(mypict.gamma > 0) mypict.gamma--;												printf ("Gamma change to %d\n",mypict.gamma);												mypict.change = 0x01;																			break;											case SDLK_r:																						 printf(" Edit Red Channel: \											 offset-> up || down | gain-> right || left \n");											 Offtemp = &mypict.OffRed;											 Gtemp = &mypict.GRed;											 change = 2;											 printf (" Offset: %d Gain: %1.3f \n",											 *Offtemp,(float)(*Gtemp)/ 255);																		break;											case SDLK_b:																						printf(" Edit Blue Channel: \											offset-> up || down | gain-> right ||left \n");											 Offtemp = &mypict.OffBlue;											 Gtemp = &mypict.GBlue;											printf (" Offset: %d Gain: %1.3f \n",											*Offtemp,(float)(*Gtemp)/ 255);											change = 8;											break;											case SDLK_g:																						 printf(" Edit Green Channel: \											 offset-> up || down | gain-> right || left \n");											 Offtemp = &mypict.OffGreen;											 Gtemp = &mypict.GGreen;											 printf (" Offset: %d Gain: %1.3f \n",											 *Offtemp,(float)(*Gtemp) /255);											change = 4 ;											break;											case SDLK_UP:											if ( Offtemp != NULL){											run =1;												if (*Offtemp < 128) *Offtemp += 1;;												printf(" Channel Offset %d \n",*Offtemp);												mypict.change |= change;											} else {											printf(" You need to ask a channel first \n");											}																						break;											case SDLK_DOWN:											if ( Offtemp != NULL){											run =1;												if (*Offtemp > -128) *Offtemp -= 1;												printf(" Channel Offset %d \n",*Offtemp);												mypict.change |= change;											} else {											printf(" You need to ask a channel first \n");											}											break;											case SDLK_RIGHT:											{ 											if ( Gtemp != NULL){											run =1;												if (*Gtemp < 512) *Gtemp += 10;												printf(" Channel Gain %1.3f \n",												(float)(*Gtemp) / 255);												mypict.change |=  change;											} else {											printf(" You need to ask a channel first \n");											}																				}											break;											case SDLK_LEFT:											{ 											if ( Gtemp != NULL){											run =1;												if (*Gtemp > 128 ) *Gtemp -=10;												printf(" Channel Gain %1.3f \n",												(float)(*Gtemp) /255);												mypict.change |= change;											} else {											printf(" You need to ask a channel first \n");											}											}											break;											case SDLK_s:											/* Reverse Red and Blue for Picture Thanks V4L*/												swapRB( pixels ,(myframe->width*myframe->height*3));												getPictureName (Picture,														inputfile,"-P-",j++, "pnm");												printf ("Get Picture %s!!\n",Picture);												OUTpict = fopen (Picture,"wb");									        			fprintf (OUTpict, "P6\n%d %d\n255\n", myframe->width,													myframe->height);												fwrite (pixels , sizeof(char),													(myframe->width*myframe->height*3), OUTpict);												fclose(OUTpict);												swapRB( pixels ,(myframe->width*myframe->height*3));											break;											case SDLK_f:												printf ("bgr instead rgb asked, great about standard !!\n");												run = 1;												force_rgb = !force_rgb;											break;											case SDLK_SPACE:											case SDLK_l:											/* Quit Edit Mode */												printf(" Edit Mode Exit !! \n");												run = 1;												quit1 = 0;											break;											default:											break;										}																		default:									break;									}									}								}								break;							case SDLK_q:								printf ("\nStop asked\n");								quitter = 0;							break;							default:								//quitter = 0;							break;						}						break;					case SDL_QUIT:												break;				}			}	} while (quitter == 1);		AVI_close (aviinput);	free(myframe->tmpbuffer);	free(myframe->data);	free(myframe);	SFont_FreeFont(Fontsmall);	SDL_Quit ();}#define CLIP(color) (unsigned char)((color>0xFF)?0xff:((color<0)?0:color))static voidYUV420toRGB (unsigned char *src, unsigned char *dst, int width, int height,	     int flipUV, int ColSpace){	unsigned char *Y;	unsigned char *V;	unsigned char *U;	int y1, y2, u, v;	int v1, v2, u1, u2;	unsigned char *pty1, *pty2;	int i, j;	unsigned char *RGB1, *RGB2;	int r, g, b;	//Initialization	Y = src;	V = Y + width * height;	U = Y + width * height + width * height / 4;	pty1 = Y;	pty2 = pty1 + width;	RGB1 = dst;	RGB2 = RGB1 + 3 * width;	for (j = 0; j < height; j += 2) {		//printf ("process line %d\n",j);		for (i = 0; i < width; i += 2) {			if (flipUV) {				u = (*V++) - 128;				v = (*U++) - 128;			} else {				v = (*V++) - 128;				u = (*U++) - 128;			}			switch (ColSpace) {					// M$ color space				case 0:{						v1 = ((v << 10) + (v << 9) + (v << 6) + (v << 5)) >> 10;	// 1.593						u1 = ((u << 8) + (u << 7) + (u << 4)) >> 10;	//         0.390						v2 = ((v << 9) + (v << 4)) >> 10;	//                0.515						u2 = ((u << 11) + (u << 4)) >> 10;	//               2.015					}					break;					// PAL specific				case 1:{						v1 = ((v << 10) + (v << 7) + (v << 4)) >> 10;	//      1.1406						u1 = ((u << 8) + (u << 7) + (u << 4) + (u << 3)) >> 10;	// 0.3984 						v2 = ((v << 9) + (v << 6) + (v << 4) + (v << 1)) >> 10;	// 0.5800						u2 = ((u << 11) + (u << 5)) >> 10;	//              2.0312					}					break;					// V4l2				case 2:{						v1 = ((v << 10) + (v << 8) + (v << 7) + (v << 5)) >> 10;	//       1.406						u1 = ((u << 8) + (u << 6) + (u << 5)) >> 10;	//                0.343						v2 = ((v << 9) + (v << 7) + (v << 6) + (v << 5)) >> 10;	//        0.718						u2 = ((u << 10) + (u << 9) + (u << 8) + (u << 4) + (u << 3)) >> 10;	// 1.773					}					break;				case 3:{						v1 = u1 = v2 = u2 = 0;					}					break;				default:					break;			}			//up-left			y1 = (*pty1++);			if (y1 > 0) {				r = y1 + (v1);				g = y1 - (u1) - (v2);				b = y1 + (u2);				r = CLIP (r);				g = CLIP (g);				b = CLIP (b);			} else {				r = g = b = 0;			}			*RGB1++ = r;			*RGB1++ = g;			*RGB1++ = b;			//down-left			y2 = (*pty2++);			if (y2 > 0) {				r = y2 + (v1);				g = y2 - (u1) - (v2);				b = y2 + (u2);				r = CLIP (r);				g = CLIP (g);				b = CLIP (b);			} else {				r = b = g = 0;			}			*RGB2++ = r;			*RGB2++ = g;			*RGB2++ = b;			//up-right			y1 = (*pty1++);			if (y1 > 0) {				r = y1 + (v1);				g = y1 - (u1) - (v2);				b = y1 + (u2);				r = CLIP (r);				g = CLIP (g);				b = CLIP (b);			} else {				r = g = b = 0;			}			*RGB1++ = r;			*RGB1++ = g;			*RGB1++ = b;			//down-right			y2 = (*pty2++);			if (y2 > 0) {				r = y2 + (v1);				g = y2 - (u1) - (v2);				b = y2 + (u2);				r = CLIP (r);				g = CLIP (g);				b = CLIP (b);			} else {				r = b = g = 0;			}			*RGB2++ = r;			*RGB2++ = g;			*RGB2++ = b;		}		RGB1 += 3 * width;		RGB2 += 3 * width;		pty1 += width;		pty2 += width;	}//printf ("done YUV420 -> RGB \n");}

⌨️ 快捷键说明

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