world leader in high performance signal processing
Trace: » framebuffer

Working with Frame Buffers

A Frame Buffer is a graphical output device that drives a display (TFT, LCD, TV, CRT) from memory containing a complete frame of data.

Capturing screenshots

The first step is to capture the display on the board. This can be done with a simple two step process:

  1. On the target:
    root:/var> cat /dev/fb0 > screen.raw
  2. On the host, copy the data over from the board.
    host:~> rcp root@board.ip.number:/var/screen.raw .

Now the you need to take the raw image, and convert it to a standard image format. This step depends on what type of display is there (as it depends on the raw pixel format).

24-bit Displays (BF548)

To convert the raw rgb data extracted from /dev/fb0, we use the convert program from imagemagick.

$ convert -depth 8 -size 480x272 rgb:./screen.raw -channel RGB -separate -swap 0,2 -combine screen.png
  • This has a size of 480 x 272 pixels
  • the retrieved raw pixel format is in blue, green and red order, so the -channel RGB -separate -swap 0,2 -combine swaps the blue and red channels, necessary to make a png.

16-bit Displays (BF537)

To convert the raw rgb data extracted from /dev/fb0, use this shell script:

#!/usr/bin/perl -w
 
$w = shift || 240;
$h = shift || 320;
$pixels = $w * $h;
 
open OUT, "|pnmtopng" or die "Can't pipe pnmtopng: $!\n";
 
printf OUT "P6%d %d\n255\n", $w, $h;
 
while ((read STDIN, $raw, 2) and $pixels--) {
   $short = unpack('S', $raw);
   print OUT pack("C3",
      ($short & 0xf800) >> 8,
      ($short & 0x7e0) >> 3,
      ($short & 0x1f) << 3);
}
 
close OUT;

It's a good idea to save this code in a file say iraw2png. Using it is pretty simple. Then just convert it.

host:~> ./iraw2png < screen.raw > screen.png

The default script assumes a resolution of 240×320 so if your framebuffer is something else, you will need to tell iraw2png the details. Here we tell the script to use a 640×480 resolution.

host:~> ./iraw2png 640 480 < screen.raw > screen.png

More information