File: fbgrab

package info (click to toggle)
fbcat 0.5.1-1
  • links: PTS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 156 kB
  • sloc: ansic: 258; xml: 232; sh: 138; makefile: 46
file content (104 lines) | stat: -rwxr-xr-x 2,221 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/sh

# Copyright © 2009-2017 Jakub Wilk
# Copyright © 2017 Kaelin Laundry
#
# This package is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 dated June, 1991.

set -e

usage()
{
  cat <<EOF
Usage: $0 [option...] <filename.png|->

Options:
-c <N>      grab from /dev/ttyN
-C <N>      grab from /dev/ttyN, for slower devices
-d <dev>    use framebuffer device <dev>
-i          turn on PNG interlacing
-s <N>      sleep <N> seconds before making screenshot
-?          display this help and exit

If the specified destination is "-", the PNG output is piped to stdout.
EOF
  exit 1
}

not_supported_option()
{
  printf -- 'fbgrab: the %s option is not supported.\n' "$1" >&2
  exit 3
}

no_ppm2png()
{
  printf -- 'fbgrab: no PPM -> PNG conversion tool found.\nPlease install Netpbm or GraphicsMagick, or ImageMagick.\n' >&2
  exit 4
}

current_vt=''
grab_vt=''
wait_after_switch=0
wait_before_switch=0
device=${FRAMEBUFFER:-/dev/fb0}
interlace=''
while getopts 'b:c:C:d:f:h:is:w:?' arg
do
  case "$arg" in
    b) not_supported_option -b;;
    c) grab_vt="$OPTARG"; wait_after_switch=0;;
    C) grab_vt="$OPTARG"; wait_after_switch=3;;
    d) device="$OPTARG";;
    f) not_supported_option -f;;
    h) not_supported_option -h;;
    i) interlace=1;;
    s) wait_before_switch="$((OPTARG))";;
    w) not_supported_option "$OPTARG";;
    [?]) usage;;
  esac
done

shift $(($OPTIND - 1))

[ $# -ne 1 ] && usage

if command -v pnmtopng >/dev/null 2>/dev/null
then
  ppm2png()
  {
    [ "$1" = "-" ] || exec > "$1"
    pnmtopng ${interlace:+-interlace} -
  }
elif gm -version 2>/dev/null | grep -q -w GraphicsMagick
then
  ppm2png()
  {
    gm convert ${interlace:+-interlace Line} PPM:- "PNG:$1"
  }
elif convert -version 2>/dev/null | grep -q -w ImageMagick
then
  ppm2png()
  {
    convert ${interlace:+-interlace Line} PPM:- "PNG:$1"
  }
else
  no_ppm2png
fi

sleep "$wait_before_switch"
if [ -n "$grab_vt" ]
then
  current_vt=$(fgconsole)
  chvt "$grab_vt"
fi
sleep "$wait_after_switch"
fbcat "$device" | ppm2png "$1"
if [ -n "$current_vt" ]
then
  chvt "$current_vt"
fi

# vim:ts=2 sts=2 sw=2 et