Debian Codegraph @

editor/pnmmargin

raw
1 #!/bin/sh
2 #
3 # ppmmargin - add a margin to a PNM image
4 #
5 # Copyright (C) 1991 by Jef Poskanzer.
6 #
7 # Permission to use, copy, modify, and distribute this software and its
8 # documentation for any purpose and without fee is hereby granted, provided
9 # that the above copyright notice appear in all copies and that both that
10 # copyright notice and this permission notice appear in supporting
11 # documentation. This software is provided "as is" without express or
12 # implied warranty.
13
14 color=""
15 plainopt=""
16
17 # Parse args.
18 while true ; do
19 case "$1" in
20 -version|--version )
21 pnmpad --version; exit $?;
22 ;;
23 -p|-pl|-pla|-plai|-plain )
24 plainopt="-plain"
25 shift
26 ;;
27 -w|-wh|-whi|-whit|-white )
28 color="rgbi:1/1/1"
29 shift
30 ;;
31 -b|-bl|-bla|-blac|-black )
32 color="rgbi:0/0/0"
33 shift
34 ;;
35 -c|-co|-col|-colo|-color )
36 shift
37 if [ ! ${1-""} ] ; then
38 echo "-color requires a value" 1>&2
39 exit 1
40 fi
41 color="$1"
42 shift
43 ;;
44 -* )
45 echo "unrecognized option '$1'. Valid options are -color, -white, and -black" 1>&2
46 exit 1
47 ;;
48 * )
49 break
50 ;;
51 esac
52 done
53
54 if [ ! ${1-""} ] ; then
55 echo "missing size argument" 1>&2
56 exit 1
57 fi
58 size="$1"
59 shift
60
61 case $size in
62 ''|*[!0-9]*)
63 echo "Size argument '$size' is not a whole number" 1>&2
64 exit 1
65 ;;
66 esac
67
68 if [ ${2-""} ] ; then
69 echo "too many arguments" 1>&2
70 exit 1
71 fi
72
73 # TODO: This code does not consider the case when the input file is specified
74 # and there is also input coming in from a pipe.
75
76 if [ $size -eq 0 ] ; then
77 # Zero margin; just copy input to output
78 pamtopnm $plainopt $@;
79 else
80 if test "$color" = ''; then
81 pnmpad $plainopt -detect-background \
82 -left=$size -right=$size -top=$size -bottom=$size $@
83 else
84 pnmpad $plainopt -color $color \
85 -left=$size -right=$size -top=$size -bottom=$size $@
86 fi
87 fi
88
89
90