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

📄 h.c

📁 看名字就知道了
💻 C
📖 第 1 页 / 共 2 页
字号:
      location = (x + xoffset) * 2 +            (y + yoffset) * vd->finfo.line_length;        *((unsigned short int*)(vd->fbp + location )) = *img_ptr++;    }  }}*//*********************************************************************************************************** Function name: open_framebuffer** Descriptions: 该函数用于初始化FrameBuffer设备,在该函数中打开FrameBuffer设备,并将设备影射到内存** Input: *ptr,打开Framebuffer设备路径指针**        *vd ,参数指针** Output : 返回非0值表示出错** Created by:** Created Date:**-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date:**------------------------------------------------------------------------------------------------------********************************************************************************************************/int open_framebuffer(char *ptr,fb_v41 *vd){  int fbfd,screensize;     // Open the file for reading and writing    fbfd = open( ptr, O_RDWR);    if (fbfd < 0)    {    printf("Error: cannot open framebuffer device.%x\n",fbfd);    return ERR_FRAME_BUFFER;    }    printf("The framebuffer device was opened successfully.\n");    vd->fbfd = fbfd; // 保存打开FrameBuffer设备的句柄     // Get fixed screen information 获取FrameBuffer固定不变的信息    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &vd->finfo))    {    printf("Error reading fixed information.\n");    return ERR_FRAME_BUFFER;    }    // Get variable screen information 获取FrameBuffer屏幕可变的信息    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vd->vinfo))    {    printf("Error reading variable information.\n");    return ERR_FRAME_BUFFER;    }    printf("%dx%d, %dbpp, xoffset=%d ,yoffset=%d \n", vd->vinfo.xres,       vd->vinfo.yres, vd->vinfo.bits_per_pixel,vd->vinfo.xoffset,vd->vinfo.yoffset );    // Figure out the size of the screen in bytes    screensize = vd->vinfo.xres * vd->vinfo.yres * vd->vinfo.bits_per_pixel / 8;    // Map the device to memory    vd->fbp = (char *)mmap(0,screensize,PROT_READ|PROT_WRITE,MAP_SHARED,fbfd,0); // 影射Framebuffer设备到内存    if ((int)vd->fbp == -1)    {    printf("Error: failed to map framebuffer device to memory.\n");    return ERR_FRAME_BUFFER;    }    printf("The framebuffer device was mapped to memory successfully.\n");  return  0;}/*********************************************************************************************************** Function name: open_video** Descriptions: 通过该函数初始化视频设备** Input: *fileptr,打开的文件名指针**     *vd,参数指针**     dep,像素深度**     pal,调色板**     width,宽度**     height,高度** Output : 无** Created by:** Created Date:**-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date:**------------------------------------------------------------------------------------------------------********************************************************************************************************/int open_video( char *fileptr,fb_v41 *vd ,int dep,int pal,int width,int height){  // 打开视频设备   if ((vd->fd = open(fileptr, O_RDWR)) < 0)  {      perror("v4l_open:");      return ERR_VIDEO_OPEN;   }    printf("=============Open Video Success=======================");   // 获取设备   if (ioctl(vd->fd, VIDIOCGCAP, &(vd->capability)) < 0)   {      perror("v4l_get_capability:");      return ERR_VIDEO_GCAP;   }     printf("=============Get Device Success=======================");  // 获取图象    if (ioctl(vd->fd, VIDIOCGPICT, &(vd->picture)) < 0)   {      perror("v4l_get_picture");      return ERR_VIDEO_GPIC;   }      printf("=============Get Picture Success=======================");   // 设置图象   vd->picture.palette = pal;  // 调色板   vd->picture.depth = dep;   // 像素深度//printf("=====Capture depth:%d,Palette:%d================\n",vpic.depth,vpic.palette);   vd->mmap.format =pal;   if (ioctl(vd->fd, VIDIOCSPICT, &(vd->picture)) < 0)   {      perror("v4l_set_palette");      return ERR_VIDEO_SPIC;   }   //   vd->mmap.width = width;   // width;   vd->mmap.height = height;  // height;   vd->mmap.format = vd->picture.palette;   vd->frame_current = 0;   vd->frame_using[0] = 0;   vd->frame_using[1] = 0;     // 获取缓冲影射信息   if (ioctl(vd->fd, VIDIOCGMBUF, &(vd->mbuf)) < 0)   {      perror("v4l_get_mbuf");      return -1;   }     // 建立设备内存影射   vd->map = mmap(0, vd->mbuf.size, PROT_READ|PROT_WRITE, MAP_SHARED, vd->fd, 0);   if ( vd->map < 0)   {      perror("v4l_mmap_init:mmap");      return -1;   }       printf("The video device was opened successfully.\n");  // return get_first_frame(vd);  return 0;}/* int write_jpeg(char *filename,unsigned char *img,int widtd,int height,int quality,int gray){   struct jpeg_compress_struct jcfg;   struct ipeg_error_mgr jerr;   FILE *fp;   unsigned char*line;   int line_length;   int i;   if((fp=fopen(filename,"w"))==NULL) {      fprintf(stderr,"writg_jpeg:can't open %s:%s\n",filename,strerror(errno));      return -1;     }     jcfg.image_width=width;   jcfg.image_height=height;   jcfg.input_components=gray ? 1:3; //3 simple per pixel (RGB)   jcfg.in_color_space=gray ? JCS_GRAYSCALE:JCS_RGB;   jcfg.err=jpeg_std_error(&jerr);   jpeg_set_defaults(&jcfg);   jpeg_set_quality(&jcfg,quality,TRUE);   jpeg_start_compress(&jcfg,TRUE);   line_finish_compress(&jcfg);  for(i=0,line=img;i<height;i++,line+=line_length);            jpeg_write_scanlines(&jcfg,&line,1);   jpeg_finish_compress(&jcfg);   jpeg_destroy_compress(&jcfg);   fclose(fp);     return 0;}*//*********************************************************************************************************************************************************************************************************************************/int main( void ){  fb_v41 vd;  int ret,i;  unsigned short  *imageptr;  unsigned short  tempbuf[320*240*3];  ret = open_framebuffer(FB_FILE,&vd);  // 打开FrameBuffer设备  if( 0!= ret )              // 打开FrameBuffer设备  {    goto err;  }   for(i=0;i<320*240*3;i++)   tempbuf[i] = 0xffff;  rgb_to_framebuffer(&vd,320,240,0,0,tempbuf); // 填充FrameBuffer颜色至整个屏幕    ret = open_video( V4L_FILE, &vd ,                    32,             // 像素深度           VIDEO_PALETTE_RGB565,   // 设置调包板           320,240 );  if( 0!= ret )   // 打开视频设备失败  {    goto err;  }   printf(vd.capability.name);printf(", Type:%d\n",vd.capability.type);    printf("Maxwidth:%d,Maxheight:%d\n",vd.capability.maxwidth ,vd.capability.maxheight);    printf("Minwidth:%d,Minheight:%d\n",vd.capability.minwidth,vd.capability.minheight);    printf("Channels:%d,Audios:%d\n",vd.capability.channels,vd.capability.audios);    printf("------Pic Size:%d-------\n",vd.mbuf.size);    while(1)  {    imageptr = (unsigned short *) get_frame_address( &vd ); //    rgb_to_framebuffer(&vd,vd.mmap.width,vd.mmap.height,                       0,0,imageptr);   //    if(get_next_frame( &vd ) !=0 )     { // 获取图像数据出错     goto err;    }  } // write_jpeg("1.jpg",img,320,240,50,0); //  exit(0);err: if(vd.fbfd)  close(vd.fbfd);    // 关闭FrameBuffer设备  if(vd.fd)  close(vd.fd); exit(0); return 0;} 

⌨️ 快捷键说明

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