DESK-MX6-L-AN-0004: Capturing framebuffer screenshots

From DAVE Developer's Wiki
Jump to: navigation, search
Info Box
200px-Emblem-important.svg.png

This application note has been validated using the kit version in the History table.

History
Issue Date Notes
2023/09/21 DESK-MX6L-L 4.0.1


Introduction[edit | edit source]

In certain situations, it is necessary and/or convenient to grab a screenshot of the full display from the framebuffer directly, for example for debugging purposes or documentation. By using the fbgrab (framebuffer device grabber), this job can be accomplished straightforwardly. This Application Note (AN) shows how to use it on a system running a DESK-MX6-L-based Yocto Linux distribution.

Installing fbgrab[edit | edit source]

Assuming that root file system provides the dnf tool and it is set up properly, the fbgrab package can be installed as follows:

root@desk-mx6:~# dnf install fbgrab
desk-mx6l-cortexa9hf                                                                                                                   379 kB/s |  76 kB     00:00
desk-mx6l-cortexa9t2hf_neon                                                                                                            5.1 MB/s | 7.3 MB     00:01
desk-mx6l-cortexa9t2hf_neon_mx6qdl                                                                                                     2.0 MB/s | 675 kB     00:00
desk-mx6l-noarch                                                                                                                       1.2 MB/s | 275 kB     00:00
Dependencies resolved.
=======================================================================================================================================================================
 Package                           Architecture                                 Version                             Repository                                    Size
=======================================================================================================================================================================
Installing:
 fbgrab                            cortexa9t2hf_neon                            1.5-r0                              cortexa9t2hf_neon                             12 k

Transaction Summary
=======================================================================================================================================================================
Install  1 Package

Total download size: 12 k
Installed size: 13 k
Is this ok [y/N]: y
Downloading Packages:
fbgrab-1.5-r0.cortexa9t2hf_neon.rpm                                                                                                    191 kB/s |  12 kB     00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                  165 kB/s |  12 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                               1/1
  Installing       : fbgrab-1.5-r0.cortexa9t2hf_neon                                                                                                               1/1
  Verifying        : fbgrab-1.5-r0.cortexa9t2hf_neon                                                                                                               1/1

Installed:
  fbgrab-1.5-r0.cortexa9t2hf_neon

Complete!
root@desk-mx6:~#

Capturing screenshots[edit | edit source]

The following examples refer to a system using the 800x480 16bpp framebuffer, as in the SBC AXEL Evaluation Kit, which is mapped to /dev/fb0.

When the display shows the image to be captured, to grab a screenshot and save it to a PNG file, issue the following command:

root@desk-mx6:~# fbgrab -d /dev/fb0 screen.png
Resolution: 800x480 depth 16
Converting image from 16
Now writing PNG file (compression -1)
root@desk-mx6:~#

It is also worth remembering that, if the screen parameters such as resolution or pixel depth are unknown, the fbset tool can be used to display them:

root@desk-mx6:~# fbset

mode "800x480-59"
        # D: 33.260 MHz, H: 31.201 kHz, V: 59.205 Hz
        geometry 800 480 800 480 16
        timings 30066 128 128 15 30 10 2
        accel false
        rgba 5/11,6/5,5/0,0/0
endmode

root@desk-mx6:~#

The numbers following geometry indicate the resolution (800x480) and the bits required to represent a pixel (16). The last line tells the pixel format (RGBA). In this case, the RGB565 format (reg, green, blue, and alpha) resulting in 16 bits combined.

Displaying the capture screenshot[edit | edit source]

The capture PNG screenshot can now be displayed:

root@desk-mx6:~# ls -la
total 28
drwx------ 2 root root  4096 Aug 25 09:38 .
drwxr-xr-x 3 root root  4096 Mar  9  2018 ..
-rw------- 1 root root   976 Aug 25 09:35 .viminfo
-rw-r--r-- 1 root root 15698 Aug 25 09:38 screen.png
root@desk-mx6:~#

For this purposes, the fbi utility - already installed in the root file system - can be used:

root@desk-mx6:~# fbi --help

This program displays images using the Linux framebuffer device.
Supported formats: PhotoCD, jpeg, ppm, gif, tiff, xwd, bmp, png,
webp. It tries to use ImageMagick's convert for unknown file formats.

usage: fbi [ options ] file1 file2 ... fileN

    -h  -help               print this help text
    -V  -version            print fbi version number
    -i  -info               print device info
        -store              write cmd line args to config file
    -l  -list <arg>         read image filelist from file <arg>
    -P  -text               switch into text reading mode
    -a  -autozoom           automagically pick useful zoom factor
        -(no)autoup           like the above, but upscale only
        -(no)autodown         like the above, but downscale only
    -w  -(no)fitwidth         use width only for autoscaling
    -v  -(no)verbose        show filenames all the time
    -u  -(no)random         show files in a random order
    -1  -(no)once           don't loop (for use with -t)
        -(no)comments       display image comments
    -e  -(no)edit           enable editing commands (see man page)
        -(no)backup           create backup files when editing
        -(no)preserve         preserve timestamps when editing
        -(no)readahead      read ahead images into cache
        -cachemem <arg>     image cache size in megabytes
        -blend <arg>        image blend time in miliseconds
    -T  -vt <arg>           start on virtual console <arg>
    -s  -scroll <arg>       scroll image by <arg> pixels
    -t  -timeout <arg>      load next image after <arg> sec without user input
    -r  -resolution <arg>   pick PhotoCD resolution (1..5)
    -f  -font <arg>         use font <arg> (anything fontconfig accepts)
    -d  -device <arg>       use framebuffer/drm device <arg>
    -o  -output <arg>       use drm output <arg> (try -info for a list)
        -(no)interactive    allow keyboard interaction
    -m  -mode <arg>         use video mode <arg> (from /etc/fb.modes)

Large images can be scrolled using the cursor keys.  Zoom in/out
works with '+' and '-'.  Use ESC or 'q' to quit.  Space and PgDn
show the next, PgUp shows the previous image. Jumping to a image
works with <i>g.  Return acts like Space but additionally prints
prints the filename of the currently displayed image to stdout.

root@desk-mx6:~#

As a first step, before displaying the PNG image, clean the framebuffer using dd:

root@desk-mx6:~# dd if=/dev/zero of=/dev/fb0
dd: writing to '/dev/fb0': No space left on device
4097+0 records in
4096+0 records out
2097152 bytes (2.1 MB, 2.0 MiB) copied, 0.022475 s, 93.3 MB/s
root@desk-mx6:~#

then, display the PNG screenshot:

root@desk-mx6:~# fbi --noverbose -T 1 screen.png
using "DejaVu Sans Mono-16", pixelsize=16.67 file=/usr/share/fonts/truetype/DejaVuSansMono.ttf
trying drm: /dev/dri/card0 ...
drm: no dumb buffer support
root@desk-mx6:~#

Please note the --noverbose parameter avoiding to display the PNG file info (in case of the pure image should be displayed).