"Fossies" - the Fresh Open Source Software Archive

Member "netpbm-10.91.01/converter/ppm/hpcdtoppm/pcdovtoppm" (22 Jul 2020, 6616 Bytes) of package /linux/misc/netpbm-10.91.01.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "pcdovtoppm": 10.91.00_vs_10.91.01.

    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 <93sam@debian.org>, 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 usage ()
   34 {
   35     echo "Usage: $0 [-m W] [-s S] [-a A] [-c N|n] [-f F] [-b|-w] <overview.pcd>"
   36     echo " with"
   37     echo "      W = maximum width of the result image   (default: $maxwidth)"
   38     echo "      S = maximum size of each of the images  (default: $size)"
   39     echo "      A = maximum number of images across     (default: $across)"
   40     echo "      N = maximum number of colors or noquant (default: $colors)"
   41     echo -n "   F = font to be used for annotation      (default: "
   42     if [ "$font" = " " ] ; then
   43                 echo "internal font)"
   44     else
   45                 echo "$font)"
   46     fi
   47     echo "      -b/-w = black/white background color    (default: $back)"
   48     echo " "
   49     echo " e.g.: $0 -m 768 -s 96 -f smallfont.pbm overview.pcd > overview.ppm"
   50     echo " or  : $0 /cdrom/photo_cd/overview.pcd | ppmtojpeg > overview.jpg"
   51     exit 1
   52 }
   53 
   54 version ()
   55 {
   56     # report version using pnmscale
   57     pnmscale -version $quietopt
   58     exit 0
   59 }
   60 
   61 # Parse the options
   62 while :; do
   63     case "$1" in 
   64         -m|-ma|-max|-maxw|-maxwi|-maxwid|-maxwidt|-maxwidth )
   65              if [ $# -lt 2 ] ; then usage; fi
   66              maxwidth="$2"
   67              shift
   68              shift
   69              ;;
   70 
   71         -s|-si|-siz|-size )
   72              if [ $# -lt 2 ] ; then usage; fi
   73              size="$2"
   74              shift
   75              shift
   76              ;;
   77 
   78          -a|-ac|-acr|-acro|-acros|-across )
   79              if [ $# -lt 2 ] ; then usage; fi
   80              across="$2"
   81              shift
   82              shift
   83              ;;
   84 
   85          -c|-co|-col|-colo|-color|-colors )
   86              if [ $# -lt 2 ] ; then usage; fi
   87              colors="$2"
   88              shift
   89              shift
   90              ;;
   91 
   92          -f|-fo|-fon|-font )
   93              if [ $# -lt 2 ] ; then usage; fi
   94              font="-font $2"
   95              shift
   96              shift
   97              ;;
   98 
   99          -b|-bl|-bla|-blac|-black )
  100              back="-black"
  101              shift
  102              ;;
  103 
  104          -w|-wh|-whi|-whit|-white )
  105              back="-white"
  106              shift
  107              ;;
  108              
  109          -p|-pl|-pla|-plai|-plain )
  110              plainopt="-plain"
  111              shift
  112              ;;
  113             
  114          -q|-qu|-qui|-quie|-quiet )
  115              quietopt="-quiet"
  116              shift
  117              ;;
  118              
  119          -v|-ve|-ver|-vers|-versi|-versio|-version )
  120              versionopt="1"
  121              shift
  122              ;;
  123                     
  124          -*)
  125              echo "$0 : Unknown option $1" 1>&2
  126              echo " " 1>&2
  127              usage
  128              ;;
  129 
  130          *)
  131              break
  132              ;;
  133 
  134     esac
  135 done
  136 
  137 if [ $versionopt -eq 1 ] ; then
  138     version
  139 elif [ $# -eq 0 ] ; then
  140     usage
  141 fi
  142 
  143 tempdir=$(mktemp -d "${TMPDIR:-/tmp}/pcdovtoppm.XXXXXXXX") ||
  144     { echo "Could not create temporary file. Exiting." 1>&2; exit 1; }
  145 trap 'rm -rf $tempdir' 0
  146 
  147 tmpfile=`tempfile -p pi -m 600`
  148 
  149 # Convert the PCD overview file to many PPM images
  150 if [ -f $1 ] ; then
  151     hpcdtoppm -Overview $1 $tmpfile ||
  152         { echo "$0: Hpcdtoppm failed. Exiting" 1>&2 ; exit 1; }
  153 else
  154     echo "$0 : Could not access $1" 1>&2
  155     echo " " 1>&2
  156     usage
  157 fi
  158 
  159 imagefiles=
  160 rowfiles=
  161 row=1
  162 col=1
  163 width=$size
  164 
  165 for i in "$tmpfile"* 
  166 do
  167     if [ -f $i ] ; then
  168         thiswidth=$(pamfile -machine $i | cut -f 4 -d ' ')
  169         thisheight=$(pamfile -machine $i | cut -f 5 -d ' ')
  170         if [ "$thiswidth" -le $size -a "$thisheight" -le $size ] ; then
  171             cat $i > $tmpfile
  172         else
  173             if [ "$colors" = "n" ] ; then
  174                 pnmscale -quiet -xysize $size $size $i > $tmpfile
  175             else
  176                 pnmscale -quiet -xysize $size $size $i | \
  177                 ppmquant -quiet $colors > $tmpfile
  178             fi
  179         fi
  180     fi
  181     imagefile=${tempdir}/pi.${row}.${col}
  182     rm -f $imagefile
  183     ttext="$i:t"
  184 
  185     if [ "$back" = "-white" ] ; then
  186         pbmtext $font "$ttext" | pnmcrop -quiet | pnmmargin -white 2| \
  187         pnmcat $back -tb $tmpfile - > $imagefile
  188     else
  189         pbmtext $font "$ttext" | pnmcrop -quiet | pnmmargin -white 2 | \
  190         pnminvert | pnmcat $back -tb $tmpfile - > $imagefile
  191     fi
  192 
  193     rm -f $tmpfile
  194     thisWidth=$(pamfile -machine $i | cut -f 4 -d ' ')
  195     width=$(( $width + $thisWidth ))
  196     imagefiles="$imagefiles $imagefile"
  197 
  198     if [ $col -ge $across -o $width -gt $maxwidth ] ; then
  199         rowfile=${tempdir}/pi.${row}
  200         rm -f $rowfile
  201     if [ "$colors" = "n" ] ; then
  202         pnmcat $back -lr -jbottom $imagefiles > $rowfile
  203     else
  204         pnmcat $back -lr -jbottom $imagefiles | \
  205         ppmquant -quiet $colors > $rowfile
  206     fi
  207     rm -f $imagefiles
  208     imagefiles=
  209     rowfiles="$rowfiles $rowfile"
  210     col=1
  211     row=$(( $row + 1 ))
  212     width=$size
  213     else
  214         col=$(( $col + 1 ))
  215     fi
  216 done
  217 
  218 if [ -n $imagefiles ] ; then
  219     rowfile=${tempdir}/pi.${row}
  220     rm -f $rowfile
  221     if [ "$colors" = "n" ] ; then
  222         pnmcat $back -lr -jbottom $imagefiles > $rowfile
  223     else
  224         pnmcat $back -lr -jbottom $imagefiles | \
  225         ppmquant -quiet $colors > $rowfile
  226     fi
  227     rm -f $imagefiles
  228     rowfiles="$rowfiles $rowfile"
  229 fi
  230 
  231 if [ $(echo $rowfiles|wc -w) -eq 1 ] ; then
  232     ppmtoppm $plainopt < $rowfiles
  233 else
  234     if [ "$colors" = "n" ] ; then
  235         pnmcat $back -tb $plainopt $rowfiles
  236     else
  237         pnmcat $back -tb $rowfiles | ppmquant $plainopt -quiet $colors
  238     fi
  239 fi
  240 
  241 rm -f $rowfiles
  242 
  243 exit 0
  244 
  245