5

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
5
  • Did you success on your work? means, had you able to send a framebuffer's raw data to server in video format?
    – user370305
    Jan 16, 2012 at 14:37
  • I was able to do my own sort of motion jpeg. The scripts i used while figuring this all out are available here: github.com/coolaj86/image-examples
    – coolaj86
    Jan 20, 2012 at 7:35
  • Hi, Thanks for your reply and help.. Also when I am trying to fetch framebuffer data for HD device it gives me 32-bit depth raw data so how can I convert it to appropriate image so I can view it?
    – user370305
    Jan 20, 2012 at 8:03
  • Take a look at these two: github.com/coolaj86/image-examples/blob/master/scripts/… github.com/coolaj86/image-examples/blob/master/scripts/… If you can find out what ffmpeg calls it you can adjust accordingly
    – coolaj86
    Jan 21, 2012 at 9:24
  • It might look something like this: ffmpeg -vcodec rawvideo -f rawvideo -pix_fmt rgb32 -s 2073600 -i data.raw -f image2 -vcodec mjpeg frame.jpeg
    – coolaj86
    Jan 21, 2012 at 9:27

2 Answers 2

5

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);
  }
}
2

I'm developing an embedded system with a 5:6:5 RGB format, and on occasion I've needed to capture raw framebuffer data and convert it to a viewable image. For experimentation, I wrote a bit of C code to convert the raw binary values to link text. The format is dumb, but easily readable - thus I found it convenient for hacking about. I then used Imagemagick display to view and convert to convert to JPG. (If I recall correctly, convert will accept raw binary images - but that assumes you know all the image parameters, i.e. 5:6:5 versus 5:5:5).

I can post sample C code to convert 5:6:5 to 8:8:8 RGB if needed.

4
  • That would be appreciated. I'm googling about convert right now.
    – coolaj86
    Sep 23, 2010 at 19:20
  • for (size_t i=0;i<num_pixels;i++) { fread(&pixel, sizeof(unsigned short), 1, infile); red = (unsigned short)((pixel & 0xF800) >> 11); green = (unsigned short)((pixel & 0x07E0) >> 5); blue = (unsigned short)(pixel & 0x001F); // Increase intensity red = red << 3; green = green << 2; blue = blue << 3; fprintf(outfile, "%d %d %d\n", red, green, blue); } Sep 23, 2010 at 19:28
  • Bummer - I forgot that comments cannot be formatted. The above code assumes a 565 pixel. This snippet reads a pixel from a binary file, separates the pixel values into RGB components, scales them appropriately, then writes them out as text. Sep 23, 2010 at 19:32
  • Do you know how I specify rgb as 5:6:5 with convert?
    – coolaj86
    Sep 23, 2010 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.