Screenshot

From OpenTom

Jump to: navigation, search

Contents

How to do screenshots?

You can copy the frame buffer (the raw display) to a file. You can do this directly from a shell (e.b. with TomTom Console) or shell script (in this case you can also introduce a delay (e.g. with sleep).

 cat /dev/fb > /mnt/sdcard/picture.raw

This raw file then need to be converted e.g. to .png. The color-words (16 Bit) have the format: 5:6:5 bits.

These Files, of course, can also been played back to the screen by:

 cat /mnt/sdcard/picture.raw > /dev/fb

A useful implementation on the TomTom

I Have following configuration:

/mnt/sdcard/bin/screenshot :

 #!/bin/sh
 
 (sleep $1 ; cat /dev/fb > $HOME/screenshot-`date +%F-%H-%M-%S`.raw) &

/mnt/sdcard/bin/snapshot :

 #!/bin/sh
 export HOME=/mnt/sdcard
 /mnt/sdcard/bin/screenshot 10

and in the SDKRegitry folder i have snapshot.cap

 Version|100|
 AppName|snapshot|
 AppPath|/mnt/sdcard/bin/|
 AppIconFile|snapshot.bmp|
 AppMainTitle|snapshot|
 AppPort|2001|
 COMMAND|CMD|test|snapshot.bmp|snapshot|

This configureation enables a application icon in the application menu. If you press snapshot, you have 10 seconds to go to the screen you want to be screenshotted. If you are using TomTom Console, you can invoke the snapshot by typing:

 screenshot 10

Instead of 10 you can specify any delay in seconds.

Converting the raw framebuffer images to other formats

Here is an X11-Basic program, which converts the framebuffer .raw files to .bmp. It is a bit slow, but it works. (Do not use it on the TomTom, but instead on a normal linux PC with X11-basic installed.)

 #!/usr/bin/xbasic
 ' raw2bmp   (c) Markus Hoffmann 200    V.1.00
 ' converts raw 16 Bit (5:6:5) images to .bmp files. These files can then 
 ' easily be convertet to png or whatever with convert.
 '
 
 ' the defaults
 
 w=320
 h=240
 idepth=16
 depth=24
 
 i=1
 CLR inputfile$,dyn,collect$
 outputfilename$="b.bmp"
 WHILE LEN(param$(i))
   IF LEFT$(param$(i))="-"
     IF param$(i)="--help" OR param$(i)="-h" 
       @intro
       @using
     ELSE IF param$(i)="--version"
       @intro
       QUIT
     ELSE IF param$(i)="-w"
       INC i
       IF LEN(param$(i))
         w=val(param$(i))
       ENDIF
     ELSE IF param$(i)="-o"
       INC i
       IF LEN(param$(i))
         outputfilename$=param$(i)
       ENDIF
     else 
       collect$=collect$+param$(i)+" " 
     ENDIF
   ELSE
     inputfile$=param$(i)
     IF NOT EXIST(inputfile$)
       PRINT "raw2bmp: "+inputfile$+": file or path not found"
       CLR inputfile$
     ENDIF
   ENDIF
   INC i
 WEND
 IF LEN(inputfile$)
   print "<-- (";inputfile$;
   open "I",#1,inputfile$
   l=lof(#1)
   h=l/w/idepth*8
   
   print
   print "The picture appears to contain ";h;" Scanlines."
 
   dim r(w,h),g(w,h),b(w,h)
   print ") [";
   for y=0 to h-1
     for x=0 to w-1
       a=cvi(input$(#1,2))
       r(x,y)=(shr(a,11) and 0x1f)*8
       g(x,y)=(shr(a,5) and 0x3f)*4
       b(x,y)=(a and 0x1f)*8
     next x    
     print ".";
     flush
   next y
   close 
   print "] ";h
 
   filesize=54+3*w*h
   print "--> (";outputfilename$;
   open "O",#1,outputfilename$
   print #1,"BM";              !0
   print #1,mkl$(filezize);    !2
   print #1,mki$(0);mki$(0);   !6
   print #1,mkl$(54);        !10
 
   print #1,mkl$(40);          !14
   print #1,mkl$(w);           !18
   print #1,mkl$(h);           !22
   print #1,mki$(1);           !24
   print #1,mki$(depth);       !26
   print #1,mkl$(0);           !30
   print #1,mkl$(0);           !34
   print #1,mkl$(0);           !38
   print #1,mkl$(0);           !42
   print #1,mkl$(0);           !46
   print #1,mkl$(0);           !50
   print ") [";
   for y=h-1 downto 0
     for x=0 to w-1
       r=r(x,y)
       g=g(x,y)
       b=b(x,y)
       print #1,chr$(b);chr$(g);chr$(r);
     next x
     print ".";
     flush
   next y
   close 
   print "] ";h
 else
   print "raw2bmp: No input files"
   @usage
 ENDIF
 quit
  
 PROCEDURE intro
   PRINT "Picture converter raw2bmp V.1.00 (c) Markus Hoffmann 2007-2008"
   VERSION
 RETURN
 PROCEDURE using
   PRINT "Usage: raw2bmp [options] file..."
   PRINT "Options:"
   PRINT "  -h, --help               Display this information"
   PRINT "  -o <file>                Place the output into <file>"
   PRINT "  -w <with>                specify width of image in pixels [";w;"]"
 RETURN

Converting the raw framebuffer images to PNG

#!/bin/sh

PROGNAME="$0"

usage() {
        cat <<EOF
NAME
    `basename $PROGNAME` - Convert TomTom screenshots to PNG format

SYNOPSIS
    `basename $PROGNAME` [options] file...

DESCRIPTION
    Convert TomTom screenshots to PNG format.

OPTIONS
    -D lvl      Debug level
EOF

        exit 1
}

#
#       Report an error and exit
#
error() {
        echo "`basename $PROGNAME`: $1" >&2
        exit 1
}

debug() {
        if [ $DEBUG -ge $1 ]; then
            echo "`basename $PROGNAME`: $2" >&2
        fi
}

#
#       Process the options
#
DEBUG=0
while getopts "D:h?" opt
do
        case $opt in
        D)      DEBUG="$OPTARG";;
        h|\?)   usage;;
        esac
done
shift `expr $OPTIND - 1`

if [ $# = 0 ]; then
    usage
fi

#
#       Main Program
#
trap "rm -f /tmp/raw2png$$*" 0
for i in $*; do
    size2=`stat -c %s $i`
    size=`dc -e "$size2 2/p"`
    dd bs=1c skip=$size <$i >/tmp/raw2png$$.tmp 2>/dev/null
    raw2bmp -o /tmp/raw2png$$.bmp /tmp/raw2png$$.tmp >/dev/null
    o=`echo "$i" | sed "s/.raw//"`
    convert /tmp/raw2png$$.bmp $o.png
done

See also: framebuffer, TomTom Console

Personal tools