File: fbgrab

package info (click to toggle)
fbcat 0.3-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 124 kB
  • sloc: xml: 213; ansic: 175; sh: 101; makefile: 29
file content (108 lines) | stat: -rwxr-xr-x 2,256 bytes parent folder | download | duplicates (2)
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
105
106
107
108
#!/bin/sh

# Copyright © 2009, 2011 Jakub Wilk
#
# 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
EOF
  exit 1
}

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

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

internal_error()
{
  printf -- 'Internal error!\n' >&2
  exit 42
}

current_vt=''
grab_vt=''
wait_after_switch=0
wait_before_switch=0
device=${FRAMEBUFFER:-/dev/fb0}
opts=$(getopt -o 'b:c:C:d:f:h:is:w:?' -- "$@")
interlace=''
eval set -- "$opts"
while true
do
  case "$1" in
    -b) not_supported_option "$1"; shift 2;;
    -c) grab_vt="$2"; wait_after_switch=0; shift 2;;
    -C) grab_vt="$2"; wait_after_switch=3; shift 2;;
    -d) device="$2"; shift 2;;
    -f) not_supported_option "$1"; shift 2;;
    -h) not_supported_option "$1"; shift 2;;
    -i) interlace=1; shift;;
    -s) wait_before_switch="$(($2))"; shift 2;;
    -w) not_supported_option "$1"; shift 2;;
    -[?]) usage;;
    --) shift; break;;
    *) internal_error;
  esac
done

[ $# -ne 1 ] && usage

if command -v pnmtopng >/dev/null 2>/dev/null
then
  ppm2png()
  {
    pnmtopng ${interlace:+-interlace} - > "$1"
  }
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 sw=2 et