Exemple #1
0
//! Writes the provided image to disk file
bool CNullDriver::writeImageToFile(IImage* image, const path& filename,u32 param)
{
	IWriteFile* file = FileSystem->createAndWriteFile(filename);
	if(!file)
		return false;

	bool result = writeImageToFile(image, file, param);
	file->releaseRef();

	return result;
}
Exemple #2
0
int main(int argc, char *argv[])
{
	struct timeval tv1;		//监控键盘输入的select时间参数
	unsigned long size;		//一帧画面的字节数
	int index=0;			//V4L2 input索引号
	struct v4l2_capability cap;		//V4L2设备功能结构体变量
	struct v4l2_input i;		//V4L2设备输入信息
	struct v4l2_framebuffer fb;		//V4L2的一帧设备缓存
	int on=1;				//控制V4L2设备overlay的参数
	int tmp;
	fd_set fds1;			//监控键盘输入的select fd_set变量
	int fd;				//监控键盘输入的select句柄
	char cmd[256];			//存储从键盘读入的字符串
	
	cam_fp = cam_init();		//获得摄像头句柄
	fb_fp = fb_init();			//获得帧缓冲句柄
	
	size=width*height*fb_bpp/8;

	if((tmp=ioctl(cam_fp, VIDIOC_QUERYCAP, &cap))<0) 
	{		//查询驱动功能
		printf("VIDIOC_QUERYCAP error, ret=0x%x\n",tmp);
		goto err;
	}
	printf("Driver:%s, Card:%s, cap=0x%x,bus info is %s\n",cap.driver,cap.card,cap.capabilities,cap.bus_info);
	
	memset(&i, 0, sizeof(i));
	i.index=index;
	if(ioctl(cam_fp, VIDIOC_ENUMINPUT, &i)<0)
	{//枚举输入源
		goto err;
	}
	printf("input name:%s\n",i.name);	
	
	index=0;
	if(ioctl(cam_fp, VIDIOC_S_INPUT, &index)<0)		//设置输入源
	{
	    printf("VIDIOC_S_INPUT failed\n");
		goto err;
    }
	if(ioctl(cam_fp, VIDIOC_S_OUTPUT, &index)<0)		//设置输出源
	{
	    
	    printf(" VIDIOC_S_OUTPUT failed\n");
	        goto err;
	}
	if(ioctl(cam_fp, VIDIOC_G_FBUF, &fb)<0)		//获取V4L2设备FB属性参数
	{
	    printf(" VIDIOC_G_FBUF failed\n");
		goto err;
	}

	printf("g_fbuf:capabilities=0x%x,flags=0x%x,width=%d,height=%d\n"
	       "pixelformat=0x%x,bytesperline=%d,colorspace=%d,base=0x%x\n",
		    fb.capability,fb.flags,fb.fmt.width,fb.fmt.height
		    ,fb.fmt.pixelformat,fb.fmt.bytesperline,fb.fmt.colorspace
		    ,fb.base);
		    
	fb.capability = cap.capabilities;	//V4L2设备功能赋值给V4L2的FB功能属性
	fb.fmt.width =width;				//LCD的FB宽度赋值给V4L2的FB宽度
	fb.fmt.height = height;				//LCD的FB高度赋值给V4L2的FB高度
	fb.fmt.pixelformat = (fb_bpp==32)?V4L2_PIX_FMT_BGR32:V4L2_PIX_FMT_RGB565;		//赋值V4L2的FB像素位数

	if(ioctl(cam_fp, VIDIOC_S_FBUF, &fb)<0)		//设置新的FB属性给摄像头
	{
	
        printf(" VIDIOC_S_FBUF failed\n");
   		goto err;
    }
    
	on = 1;
	if(ioctl(cam_fp, VIDIOC_OVERLAY, &on)<0)//使能摄像头的overlay
	{
	
        printf(" VIDIOC_OVERLAY failed\n");
		goto err;
	}
	
	vf_buff = (char*)malloc(size);
	if(vf_buff==NULL)
	{
		goto err;
	}

	if(fb_bpp==16)
	{	//16位BMP
	    *((unsigned int*)(bmp_head_t+18)) = width;
	    *((unsigned int*)(bmp_head_t+22)) = height;
	    *((unsigned short*)(bmp_head_t+28)) = 16;
	}
	else
	{
    	bmp_head[0] = 'B';
    	bmp_head[1] = 'M';
    	*((unsigned int*)(bmp_head+2)) = (width*fb_bpp/8)*height+54;		//整个位图大小
    	*((unsigned int*)(bmp_head+10)) = 54;				//从54字节开始存图像
    	*((unsigned int*)(bmp_head+14)) = 40;				//图像描述信息块的大小
    	*((unsigned int*)(bmp_head+18)) = width;
    	*((unsigned int*)(bmp_head+22)) = height;
    	*((unsigned short*)(bmp_head+26)) = 1;				//图像的plane总数
    	*((unsigned short*)(bmp_head+28)) = fb_bpp;
    	*((unsigned short*)(bmp_head+34)) = (width*fb_bpp/8)*height;		//图像数据区大小
	}
	
	while(1)
	{
	    if (!read_data(cam_fp, vf_buff, width, height, fb_bpp))		//读摄像头数据到vf_buff
	    {
		    printf("read error\n");
	    }
	    memcpy(fb_addr,vf_buff,width*height*fb_bpp/8);		//将读到的图像数据从内存拷贝到帧缓冲地址
	    fd=0;							//键盘句柄
	    tv1.tv_sec=0;
	    tv1.tv_usec=0;						//无限等待
	    FD_ZERO(&fds1);
	    FD_SET(fd,&fds1);					//绑定句柄跟监控对象
	    select(fd+1,&fds1,NULL,NULL,&tv1);			//监控键盘输入
	    if(FD_ISSET(fd,&fds1))					//如果键盘有输入
	    {
		    memset(cmd,0,sizeof(cmd));
		    read(fd,cmd,256);					//读取键盘输入的字符
		    if(strncmp(cmd,"quit",4)==0)
		    {			//如果键盘输入quit
    		    printf("-->quit\n");
    		    on=0;
    		    if(ioctl(cam_fp, VIDIOC_OVERLAY, &on)<0)//关掉V4L2设备的overlay
    		    {
    			    goto err;
    			}
    		    close(fb_fp);
    		    close(cam_fp);					//释放FB跟摄像头的句柄
    		    return 0;
		    }
		    else if(strncmp(cmd,"capt",4)==0)
		    {			//如果键盘输入capt
    		    printf("-->capture\n");
    		    printf("write to img --> ");
    		    writeImageToFile(size);				//把FB数据保存到位图中
    		    printf("OK\n");
		    }
	    }
	}

err:
	if (cam_fp)
		close(cam_fp);
	if (fb_fp)
		close(fb_fp);
	return 1;
}
Exemple #3
0
static void
shotPaintScreen (CompScreen   *s,
                 CompOutput   *outputs,
                 int          numOutput,
                 unsigned int mask)
{
	SHOT_SCREEN (s);

	UNWRAP (ss, s, paintScreen);
	(*s->paintScreen) (s, outputs, numOutput, mask);
	WRAP (ss, s, paintScreen, shotPaintScreen);

	if (ss->grab)
	{
		int x1, x2, y1, y2;

		x1 = MIN (ss->x1, ss->x2);
		y1 = MIN (ss->y1, ss->y2);
		x2 = MAX (ss->x1, ss->x2);
		y2 = MAX (ss->y1, ss->y2);
		
		if (!ss->grabIndex)
		{
			int w = x2 - x1;
			int h = y2 - y1;

			if (w && h)
			{
				GLubyte *buffer;

				const BananaValue *
				option_dir = bananaGetOption (bananaIndex, "directory", -1);

				char    *dir = option_dir->s;
				Bool    allocatedDir = FALSE;

				if (strlen (dir) == 0)
				{
					// If dir is empty, use user's desktop directory instead
					dir = shotGetXDGDesktopDir ();
					if (dir)
						allocatedDir = TRUE;
					else
						dir = "";
				}
				buffer = malloc (sizeof (GLubyte) * w * h * 4);
				if (buffer)
				{
					struct dirent **namelist;
					int           n;

					glReadPixels (x1, s->height - y2, w, h,
					           GL_RGBA, GL_UNSIGNED_BYTE,
					           (GLvoid *) buffer);

					n = scandir (dir, &namelist, shotFilter, shotSort);
					if (n >= 0)
					{
						char name[256];
						char *app;
						int  number = 0;

						if (n > 0)
							sscanf (namelist[n - 1]->d_name,
							        "screenshot%d.png",
							        &number);

						number++;

						if (n)
							free (namelist);

						sprintf (name, "screenshot%d.png", number);

						const BananaValue *
						option_launch_app = bananaGetOption (
						       bananaIndex, "launch_app", -1);

						app = option_launch_app->s;

						if (!writeImageToFile (dir, name, "png",
						                       w, h, buffer))
						{
							compLogMessage ("screenshot", CompLogLevelError,
							              "failed to write screenshot image");
						}
						else if (*app != '\0')
						{
							char *command;

							command = malloc (strlen (app) +
							          strlen (dir) +
							          strlen (name) + 3);
							if (command)
							{
								sprintf (command, "%s %s/%s", app, dir, name);

								runCommand (s, command);

								free (command);
							}
						}
					}
					else
					{
						perror (dir);
					}

					free (buffer);
				}
				if (allocatedDir)
					free (dir);
			}

			ss->grab = FALSE;
		}
	}
}
Exemple #4
0
bool Camera::dumpRawData(std::string filename) const {
    return writeImageToFile(sensor_, filename);
}