如何将16位RGB帧缓冲区转换为可视格式? [英] how to convert 16-bit RGB Frame Buffer to a viewable format?

查看:272
本文介绍了如何将16位RGB帧缓冲区转换为可视格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个设备上的其他人的代码,可以将图像放在 / dev / fb / 0 中,并显示在视频中或通过网络到客户端应用程序。



我无法访问客户端应用程序的旧源,但我了解以下有关数据的信息:




  • 720x480

  • 16位

  • RGB(我不知道如果是5,5,5或5,6,5)

  • RAW(没有标题)

  • cat -able to / dev / fb / 0

  • 675kb



    • 如何给这个标题或将其转换为JPEG,BMP或RAW类型,然后我可以在桌面应用程序中查看?



      最终,我希望它在浏览器中是jpeg和可见的,但是我现在可以看到的任何东西现在都可以工作。



      成功



      (见下面的评论)

        ffmpeg \ 
      -vcodec rawvideo \
      -f rawvideo \
      -pix_fmt rgb565 \
      -s 720x480 \
      -i in-buffer.raw \
      \
      -f image2 \
      -vcodec mjpeg \\ \\
      out-buffer.jpg





      尝试失败



      没有颜色,垂直挤压:

        rawtoppm -rgb -interpixel 720 480 fb.raw> fb.ppm 

      显示图像,但条纹和垂直和不良颜色压缩:

        rawtoppm -rgb -interrow 720 480 fb.raw> fb.ppm 

      类似于上述

        convert -depth 16 -size 720x480 frame_buffer.rgb fb.jpeg 




      维护在 https://github.com/coolaj86/image-examples

        #include< stdio.h> 

      int main(int argc,char * argv []){

      FILE * infile; // fb.raw
      FILE * outfile; // fb.ppm
      unsigned char red,green,blue; // 8位每个
      无符号短像素; //每像素16位
      unsigned int maxval; // max color val
      unsigned short width,height;
      size_t i;

      infile = fopen(./ fb.raw,r);
      outfile = fopen(./ fb.ppm,wb);
      width = 720;
      height = 480;
      maxval = 255;

      // P3 - PPMplainheader
      fprintf(outfile,P3\\\
      #create with rgb2ppm\\\
      %d%d\\\
      %d\\\
      ,width,height,maxval); (i = 0; i< width * height; i + = 1){
      fread(&像素,sizeof(无符号短),1,infile);



      red =(无符号短)((像素& 0xF800)>> 11); // 5
      green =(无符号短)((像素& 0x07E0)>> 5); // 6
      blue =(unsigned short)(pixel& 0x001F); // 5

      //增加强度
      red = red<< 3;
      green = green<<< 2;
      blue = blue<<< 3;

      // P6 binary
      // fwrite(&(red | green | blue),1,sizeof(unsigned short),outfile);

      // P3plain
      fprintf(outfile,%d%d%d\\\
      ,red,green,blue);
      }
      }


      I'm working with someone else's code on a device which can put an image to /dev/fb/0 and show up on video out or send it over the network to a client application.

      I don't have access to the old source for the client app, but I know the following about the data:

      • 720x480
      • 16-bit
      • RGB (I'm no sure if it's 5,5,5 or 5,6,5)
      • RAW (no headers whatsoever)
      • cat-able to /dev/fb/0
      • 675kb

      How can I give this a header or convert it to JPEG, BMP, or a RAW type that I could then view in a desktop application?

      Ultimately, I want it to be jpeg and viewable in a browser, but anything I can see with my eyes will work for now.

      Success

      (see the comments below)

      ffmpeg \
        -vcodec rawvideo \
        -f rawvideo \
        -pix_fmt rgb565 \
        -s 720x480 \
        -i in-buffer.raw \
        \
        -f image2 \
        -vcodec mjpeg \
        out-buffer.jpg
      

      Failed Attempts

      Shows the image three times widthwise with almost no color, and squashed vertically:

      rawtoppm -rgb -interpixel 720 480 fb.raw > fb.ppm
      

      Shows the image, but with streaks and squashed vertically and bad color:

      rawtoppm -rgb -interrow 720 480 fb.raw > fb.ppm
      

      Similar to the above

      convert -depth 16 -size 720x480 frame_buffer.rgb fb.jpeg
      

      解决方案

      rgb to ppm: Just season to taste!

      maintained at https://github.com/coolaj86/image-examples

      #include <stdio.h>
      
      int main(int argc, char* argv[]) {
      
        FILE* infile; // fb.raw
        FILE* outfile; // fb.ppm
        unsigned char red, green, blue; // 8-bits each
        unsigned short pixel; // 16-bits per pixel
        unsigned int maxval; // max color val
        unsigned short width, height;
        size_t i;
      
        infile = fopen("./fb.raw", "r");
        outfile = fopen("./fb.ppm", "wb");
        width = 720;
        height = 480;
        maxval = 255;
      
        // P3 - PPM "plain" header
        fprintf(outfile, "P3\n#created with rgb2ppm\n%d %d\n%d\n", width, height, maxval);
      
        for (i = 0; i < width * height; i += 1) {
            fread(&pixel, sizeof(unsigned short), 1, infile);
      
            red = (unsigned short)((pixel & 0xF800) >> 11);  // 5
            green = (unsigned short)((pixel & 0x07E0) >> 5); // 6
            blue = (unsigned short)(pixel & 0x001F);         // 5
      
            // Increase intensity
            red = red << 3;
            green = green << 2;
            blue = blue << 3;
      
          // P6 binary
          //fwrite(&(red | green | blue), 1, sizeof(unsigned short), outfile);
      
          // P3 "plain"
          fprintf(outfile, "%d %d %d\n", red, green, blue);
        }
      }
      

      这篇关于如何将16位RGB帧缓冲区转换为可视格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

      查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆