zoukankan      html  css  js  c++  java
  • linux下的framebuffer显示图片

    void  showbmp2()
     {
         int x,y;
         unsigned char *p;
         int index=0;
         struct fb_var_screeninfo vinfo; 
         struct fb_fix_screeninfo finfo; 

         struct fb_bitfield red; 
         struct fb_bitfield green; 
         struct fb_bitfield blue; 

         //open the showdeviece
         fbfd = open("/dev/fb0", O_RDWR); 
         if (!fbfd) 
         { 
      printf("Error: cannot open framebuffer device. "); 
      exit(1); 
         } 
      
         if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) 
         { 
      printf("Error£ºreading fixed information. "); 
      exit(2); 
         } 
      
         if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) 
         { 
      printf("Error: reading variable information. "); 
      exit(3); 
         } 
      
         printf("R:%d,G:%d,B:%d ", vinfo.red, vinfo.green, vinfo.blue ); 
      
         printf("%dx%d, %dbpp ", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel ); 
         xres = vinfo.xres; 
         yres = vinfo.yres; 
         bits_per_pixel = vinfo.bits_per_pixel; 
      
         //ŒÆËãÆÁÄ»µÄ×ÜŽóС£š×֜ڣ©  
         screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; 
         printf("screensize=%d byte ",screensize); 
      
         //¶ÔÏóÓ³Éä  
         fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); 
         if ((int)fbp == -1) 
         { 
      printf("Error: failed to map framebuffer device to memory. "); 
      exit(4); 
         } 
      
         printf("sizeof file header=%d ", sizeof(BITMAPFILEHEADER)); 
      
         printf("into show_bmp function "); 
         FILE *fp[3];

      fp[0] = fopen("./333.bmp","rb+");
      fp[1] = fopen("./444.bmp","rb+");
      fp[2] = fopen("./555.bmp","rb+");

         fread(data,54,1,fp[0]);
         fread(data,WIDTH*HEIGHT*3,1,fp[0]);
         for(y=0;y<HEIGHT;y++)
         {
      for(x=0;x<WIDTH;x++)
      {
          //if(x<640)
          {
           buf[1][(((HEIGHT-1)-y)*WIDTH+x)*4 + 0] = data[((y*WIDTH) + x)*3 + 0];
              buf[1][(((HEIGHT-1)-y)*WIDTH+x)*4 + 1] = data[((y*WIDTH) + x)*3 + 1];
              buf[1][(((HEIGHT-1)-y)*WIDTH+x)*4 + 2] = data[((y*WIDTH) + x)*3 + 2];
              //buf[1][(479-y)*WIDTH+x)*4 + 3] = data[((y*640) + x)*3 + 0];
          }
      }
         }
     //
         fread(data,54,1,fp[1]);
         fread(data,WIDTH*HEIGHT*3,1,fp[1]);
         for(y=0;y<HEIGHT;y++)
         {
      for(x=0;x<WIDTH;x++)
      {
          //if(x<640)
          {
           buf[2][(((HEIGHT-1)-y)*WIDTH+x)*4 + 0] = data[((y*WIDTH) + x)*3 + 0];
              buf[2][(((HEIGHT-1)-y)*WIDTH+x)*4 + 1] = data[((y*WIDTH) + x)*3 + 1];
              buf[2][(((HEIGHT-1)-y)*WIDTH+x)*4 + 2] = data[((y*WIDTH) + x)*3 + 2];
              //buf[1][(479-y)*WIDTH+x)*4 + 3] = data[((y*640) + x)*3 + 0];
          }
      }
         }
     //
         fread(data,54,1,fp[2]);
         fread(data,WIDTH*HEIGHT*3,1,fp[2]);
         for(y=0;y<HEIGHT;y++)  
         {
      for(x=0;x<WIDTH;x++)
      {
         // if(x<640)
           {
           buf[3][(((HEIGHT-1)-y)*WIDTH+x)*4 + 0] = data[((y*WIDTH) + x)*3 + 0];
              buf[3][(((HEIGHT-1)-y)*WIDTH+x)*4 + 1] = data[((y*WIDTH) + x)*3 + 1];
              buf[3][(((HEIGHT-1)-y)*WIDTH+x)*4 + 2] = data[((y*WIDTH) + x)*3 + 2];
              //buf[1][(479-y)*WIDTH+x)*4 + 3] = data[((y*640) + x)*3 + 0];
          }
      }
         }
         fclose(fp[0]); fclose(fp[1]); fclose(fp[2]);
         //
         while(1)
         {

          memcpy(fbp,buf[index++%picindex + 1],WIDTH*HEIGHT*4);
          sleep(2);

         }   
         printf("/nover!/n");

         return ;
     }

  • 相关阅读:
    使用JDBC连接MySql时出现:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration
    Mysql Lost connection to MySQL server at ‘reading initial communication packet', system error: 0
    mysql-基本命令
    C# 监听值的变化
    DataGrid样式
    C# 获取当前日期时间
    C# 中生成随机数
    递归和迭代
    PHP 时间转几分几秒
    PHP 根据整数ID,生成唯一字符串
  • 原文地址:https://www.cnblogs.com/james1207/p/3253573.html
Copyright © 2011-2022 走看看