blob: 9b3328f79f3cbc0bc9ec3070f64cfe2230542de1 (
plain) (
blame)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
#!/bin/ash
# Wrapper around fbsplash to facilitate positioning images.
# Contains two different modes
# 1) Just display an image centered, or in one of the four
# corners. --center, --tl, --tr, --bl, --br
# 2) Display startup icons that signal initialization progress
# which will turn from inactive to active.
# Needs a directory tree where you have two dirs named
# inactive and active, with identically named *.ppm files
# in them. Call with "--reset [dir], so all images from
# the inactive subdir will be drawn in alphabetical order.
# Call with --icon [dir/active/xxx.ppm] to draw that
# specific icon in its active state. Will assume the
# screen stays intact between calls.
ICON_SIZE=64
unset mode ppm base index
count=0
while [ "$#" -gt 0 ]; do
case "$1" in
--center|--reset|--icon|--tl|--bl|--tr|--br)
mode="${1:2}"
;;
*) break ;;
esac
shift
done
ppm="$1"
shift
# remaining args go to fbsplash, except for icon and reset modes
if [ "$mode" = "reset" ]; then
base="$ppm/inactive"
elif [ "$mode" = "icon" ]; then
base="${ppm%/*}"
base="${base%/*}"
base="${base:-.}/inactive"
globname() (
IFS=
set -- $1
printf "%s" "$1"
)
ppm="$( globname "$ppm" )"
fi
if [ -n "$base" ]; then
# Need this for either reset (draw all as inactive), or icon (know how many icons)
if ! [ -d "$base" ]; then
echo "$base is not a directory" >&2
exit 1
fi
count=0
for i in "$base"/*.ppm*; do
count=$(( count + 1 ))
done
fi
draw () {
local ppm="$3"
local img_left="$1"
local img_top="$2"
shift 3
# See ift's an actual file
if ! [ -s "$ppm" ]; then
echo "$ppm not found" >&2
exit 1
fi
local cfg="/tmp/fbsplash.$$"
# just checking if nothing too weird is set
if [ -n "$img_left" ] && [ -n "$img_top" ] \
&& [ "$img_left" -ge 0 ] && [ "$img_left" -lt 8096 ] \
&& [ "$img_top" -ge 0 ] && [ "$img_top" -lt 8096 ]; then
printf "IMG_TOP=%d\nIMG_LEFT=%d\n" \
"$img_top" "$img_left" \
> "$cfg"
fbsplash "$@" -i "$cfg" -s "$ppm"
ret=$?
rm -f -- "$cfg"
elif [ "$mode" = "center" ]; then
# otherwise just use top left and be done with it
fbsplash "$@" -s "$ppm"
ret=$?
fi
return $ret
}
# Draw
screen_size="$(fbset | awk '$1 == "geometry" {print $2 " " $3; exit}')"
screen_width="${screen_size%% *}"
screen_height="${screen_size#* }"
if [ "$count" -gt 0 ]; then
# This is one of the icon modes
if ! [ "$screen_width" -gt 0 ] || ! [ "$screen_height" -gt 0 ]; then
echo "Unknown screen size ($screen_size)" >&2
exit 1
fi
xmargin=$(( screen_width - (ICON_SIZE * count) ))
if [ "$xmargin" -gt 300 ] && [ "$count" -gt 1 ]; then
xmargin=$(( (xmargin - 100) / (count - 1) ))
[ "$xmargin" -gt 24 ] && xmargin=24
else
xmargin=0
fi
xpos=$(( ( screen_width - (ICON_SIZE * count) - (xmargin * (count - 1)) ) / 2 ))
ypos=$(( screen_height - 256 ))
# Loop over all inactive icons
unset wantfile
if [ "$mode" = "icon" ]; then
wantfile="$( basename "$ppm" .gz )"
fi
for f in "$base"/*.ppm*; do
if [ "$mode" = "reset" ]; then
draw "$xpos" "$ypos" "$f"
elif [ "$( basename "$f" .gz )" = "$wantfile" ]; then
draw "$xpos" "$ypos" "$ppm"
fi
xpos=$(( xpos + ICON_SIZE + xmargin ))
done
else
# Normal mode
# getimgsize
if ! [ -s "${ppm}" ]; then
ppm="${ppm}.gz"
fi
if [ "${ppm%.gz}" != "${ppm}" ]; then
ppm_size="$( < "$ppm" zcat | head -n 5 | grep -a -v '^#' | sed -n 2p )"
else
ppm_size="$( < "$ppm" head -n 5 | grep -a -v '^#' | sed -n 2p )"
fi
if [ -z "$ppm_size" ]; then
echo "Invalid ppm? Could not extract dimensions" >&2
exit 1
fi
ppm_width="${ppm_size%% *}"
ppm_height="${ppm_size#* }"
ppm_height="${ppm_height%% *}" # make sure nothing weird is trailing
# pos
img_left=0
img_top=0
case "$mode" in
center|tr|br) img_left="$(( screen_width - ppm_width ))" ;;
esac
case "$mode" in
center|bl|br) img_top="$(( screen_height - ppm_height ))" ;;
esac
if [ "$mode" = "center" ]; then
img_left=$(( img_left / 2 ))
img_top=$(( img_top / 2 ))
fi
draw "$img_left" "$img_top" "$ppm" "$@"
fi
|