| 1 | #!/bin/sh |
| 2 | # |
| 3 | # pcdovtoppm - generate a single PPM file from a PCD overview file |
| 4 | # |
| 5 | # Based on pnmindex (PBMPLUS), which was written by Jef Poskanzer, |
| 6 | # this script makes also use of hpcdtoppm, written by Hadmut Danisch. |
| 7 | # |
| 8 | # Formerly called Pcdindex. |
| 9 | # |
| 10 | # A similar result can be achieved by using "hpcdtoppm -Overview" |
| 11 | # followed by "pnmindex -black" on the generated PPM images. |
| 12 | # This shell just makes it more convenient and transparent to |
| 13 | # convert from one PCD to one PPM overview file. |
| 14 | # |
| 15 | # Additional options (compared to pnmindex) are -maxwidth and |
| 16 | # -font <font>. See "man pbmtext" on how to create your own font. |
| 17 | # |
| 18 | # Pieter S. van der Meulen, 1992. |
| 19 | # Rewritten in sh by Steve McIntyre <[email protected]>, 2001 |
| 20 | |
| 21 | # You may want to change the default values in the next 6 lines: |
| 22 | maxwidth=1152 # maximum width of the index image |
| 23 | size=192 # make the images about this big |
| 24 | across=6 # show this many images per row |
| 25 | colors="noquant" # maximum amount of colors or noquant (no quantization) |
| 26 | back="-black" # default background color |
| 27 | font=" " # default font or none (pbmtext's internal font) |
| 28 | |
| 29 | plainopt="" # output plain ppm |
| 30 | quietopt="" # quiet operation (currently no effect) |
| 31 | versionopt=0 |
| 32 | |
| 33 | syntaxError () |
| 34 | { |
| 35 | echo "Syntax error: $1" 1>&2 |
| 36 | exit 5 |
| 37 | } |
| 38 | |
| 39 | version () |
| 40 | { |
| 41 | # report version using pamscale |
| 42 | pamscale -version $quietopt |
| 43 | exit 0 |
| 44 | } |
| 45 | |
| 46 | # Parse the options |
| 47 | while :; do |
| 48 | case "$1" in |
| 49 | -m|-ma|-max|-maxw|-maxwi|-maxwid|-maxwidt|-maxwidth ) |
| 50 | if [ $# -lt 2 ] ; then |
| 51 | syntaxError "-maxwidth requires an argument" |
| 52 | fi |
| 53 | maxwidth="$2" |
| 54 | shift |
| 55 | shift |
| 56 | ;; |
| 57 | |
| 58 | -s|-si|-siz|-size ) |
| 59 | if [ $# -lt 2 ] ; then |
| 60 | syntaxError "-size requires an argument" |
| 61 | fi |
| 62 | size="$2" |
| 63 | shift |
| 64 | shift |
| 65 | ;; |
| 66 | |
| 67 | -a|-ac|-acr|-acro|-acros|-across ) |
| 68 | if [ $# -lt 2 ] ; then |
| 69 | syntaxError "-across requires an argument" |
| 70 | fi |
| 71 | across="$2" |
| 72 | shift |
| 73 | shift |
| 74 | ;; |
| 75 | |
| 76 | -c|-co|-col|-colo|-color|-colors ) |
| 77 | if [ $# -lt 2 ] ; then |
| 78 | syntaxError "-colors requires an argument" |
| 79 | fi |
| 80 | colors="$2" |
| 81 | shift |
| 82 | shift |
| 83 | ;; |
| 84 | |
| 85 | -f|-fo|-fon|-font ) |
| 86 | if [ $# -lt 2 ] ; then |
| 87 | syntaxError "-font requires an argument" |
| 88 | fi |
| 89 | font="-font $2" |
| 90 | shift |
| 91 | shift |
| 92 | ;; |
| 93 | |
| 94 | -b|-bl|-bla|-blac|-black ) |
| 95 | back="-black" |
| 96 | shift |
| 97 | ;; |
| 98 | |
| 99 | -w|-wh|-whi|-whit|-white ) |
| 100 | back="-white" |
| 101 | shift |
| 102 | ;; |
| 103 | |
| 104 | -p|-pl|-pla|-plai|-plain ) |
| 105 | plainopt="-plain" |
| 106 | shift |
| 107 | ;; |
| 108 | |
| 109 | -q|-qu|-qui|-quie|-quiet ) |
| 110 | quietopt="-quiet" |
| 111 | shift |
| 112 | ;; |
| 113 | |
| 114 | -v|-ve|-ver|-vers|-versi|-versio|-version ) |
| 115 | versionopt="1" |
| 116 | shift |
| 117 | ;; |
| 118 | |
| 119 | -*) |
| 120 | syntaxError "$0 : Unknown option $1" |
| 121 | ;; |
| 122 | |
| 123 | *) |
| 124 | break |
| 125 | ;; |
| 126 | |
| 127 | esac |
| 128 | done |
| 129 | |
| 130 | if [ $versionopt -eq 1 ] ; then |
| 131 | version |
| 132 | fi |
| 133 | |
| 134 | tempdir=$(mktemp -d "${TMPDIR:-/tmp}/pcdovtoppm.XXXXXXXX") || |
| 135 | { echo "Could not create temporary file. Exiting." 1>&2; exit 1; } |
| 136 | trap 'rm -rf $tempdir' 0 |
| 137 | |
| 138 | tmpfile=$(mktemp --tmpdir piXXXXXX) |
| 139 | |
| 140 | # Convert the PCD overview file to many PPM images |
| 141 | if [ -f $1 ] ; then |
| 142 | hpcdtoppm -Overview $1 $tmpfile || |
| 143 | { echo "$0: Hpcdtoppm failed. Exiting" 1>&2 ; exit 1; } |
| 144 | else |
| 145 | echo "$0 : Could not access $1" 1>&2 |
| 146 | echo " " 1>&2 |
| 147 | usage |
| 148 | fi |
| 149 | |
| 150 | imagefiles= |
| 151 | rowfiles= |
| 152 | row=1 |
| 153 | col=1 |
| 154 | width=$size |
| 155 | |
| 156 | for i in "$tmpfile"* |
| 157 | do |
| 158 | if [ -f $i ] ; then |
| 159 | thiswidth=$(pamfile -machine $i | cut -f 4 -d ' ') |
| 160 | thisheight=$(pamfile -machine $i | cut -f 5 -d ' ') |
| 161 | if [ "$thiswidth" -le $size -a "$thisheight" -le $size ] ; then |
| 162 | cat $i > $tmpfile |
| 163 | else |
| 164 | if [ "$colors" = "n" ] ; then |
| 165 | pnmscale -quiet -xysize $size $size $i > $tmpfile |
| 166 | else |
| 167 | pnmscale -quiet -xysize $size $size $i | \ |
| 168 | ppmquant -quiet $colors > $tmpfile |
| 169 | fi |
| 170 | fi |
| 171 | fi |
| 172 | imagefile=${tempdir}/pi.${row}.${col} |
| 173 | rm -f $imagefile |
| 174 | ttext="$i:t" |
| 175 | |
| 176 | if [ "$back" = "-white" ] ; then |
| 177 | pbmtext $font "$ttext" | pnmcrop -quiet | pnmmargin -white 2 | \ |
| 178 | pamcat $back -topbottom $tmpfile - > $imagefile |
| 179 | else |
| 180 | pbmtext $font "$ttext" | pnmcrop -quiet | pnmmargin -white 2 | \ |
| 181 | pnminvert | \ |
| 182 | pamcat $back -topbottom $tmpfile - > $imagefile |
| 183 | fi |
| 184 | |
| 185 | rm -f $tmpfile |
| 186 | thisWidth=$(pamfile -machine $i | cut -f 4 -d ' ') |
| 187 | width=$(( $width + $thisWidth )) |
| 188 | imagefiles="$imagefiles $imagefile" |
| 189 | |
| 190 | if [ $col -ge $across -o $width -gt $maxwidth ] ; then |
| 191 | rowfile=${tempdir}/pi.${row} |
| 192 | rm -f $rowfile |
| 193 | if [ "$colors" = "n" ] ; then |
| 194 | pamcat $back -leftright -jbottom $imagefiles > $rowfile |
| 195 | else |
| 196 | pamcat $back -leftright -jbottom $imagefiles | \ |
| 197 | ppmquant -quiet $colors > $rowfile |
| 198 | fi |
| 199 | rm -f $imagefiles |
| 200 | imagefiles= |
| 201 | rowfiles="$rowfiles $rowfile" |
| 202 | col=1 |
| 203 | row=$(( $row + 1 )) |
| 204 | width=$size |
| 205 | else |
| 206 | col=$(( $col + 1 )) |
| 207 | fi |
| 208 | done |
| 209 | |
| 210 | if [ -n $imagefiles ] ; then |
| 211 | rowfile=${tempdir}/pi.${row} |
| 212 | rm -f $rowfile |
| 213 | if [ "$colors" = "n" ] ; then |
| 214 | pamcat $back -leftright -jbottom $imagefiles > $rowfile |
| 215 | else |
| 216 | pamcat $back -leftright -jbottom $imagefiles | \ |
| 217 | ppmquant -quiet $colors > $rowfile |
| 218 | fi |
| 219 | rm -f $imagefiles |
| 220 | rowfiles="$rowfiles $rowfile" |
| 221 | fi |
| 222 | |
| 223 | if [ $(echo $rowfiles|wc -w) -eq 1 ] ; then |
| 224 | ppmtoppm $plainopt < $rowfiles |
| 225 | else |
| 226 | if [ "$colors" = "n" ] ; then |
| 227 | pamcat $back -topbottom $rowfiles | \ |
| 228 | ppmtoppm $plainopt |
| 229 | else |
| 230 | pamcat $back -tb $rowfiles | \ |
| 231 | ppmquant $plainopt -quiet $colors |
| 232 | fi |
| 233 | fi |
| 234 | |
| 235 | rm -f $rowfiles |
| 236 | |
| 237 | exit 0 |
| 238 | |
| 239 |