home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / netpbma.zip / pnm / pnmindex.cmd < prev    next >
OS/2 REXX Batch file  |  1997-04-20  |  4KB  |  159 lines

  1. extproc csh
  2.  
  3. #!/bin/csh -f
  4. #
  5. # pnmindex - build a visual index of a bunch of anymaps
  6. #
  7. # Copyright (C) 1991 by Jef Poskanzer.
  8. #
  9. # Permission to use, copy, modify, and distribute this software and its
  10. # documentation for any purpose and without fee is hereby granted, provided
  11. # that the above copyright notice appear in all copies and that both that
  12. # copyright notice and this permission notice appear in supporting
  13. # documentation.  This software is provided "as is" without express or
  14. # implied warranty.
  15.  
  16. set size=100            # make the images about this big
  17. set across=6            # show this many images per row
  18. set colors=256          # quantize results to this many colors
  19. set back="-white"       # default background color
  20.  
  21. while ( 1 )
  22.     switch ( "$1" )
  23.  
  24.         case -s*:
  25.         if ( $#argv < 2 ) goto usage
  26.         set size="$2"
  27.         shift
  28.         shift
  29.         breaksw
  30.  
  31.         case -a*:
  32.         if ( $#argv < 2 ) goto usage
  33.         set across="$2"
  34.         shift
  35.         shift
  36.         breaksw
  37.  
  38.         case -c*:
  39.         set colors="$2"
  40.         shift
  41.         shift
  42.         breaksw
  43.  
  44.         case -b*:
  45.         set back="-black"
  46.         shift
  47.         breaksw
  48.  
  49.         case -w*:
  50.         set back="-white"
  51.         shift
  52.         breaksw
  53.  
  54.         case -*:
  55.         goto usage
  56.         breaksw
  57.  
  58.         default:
  59.         break
  60.         breaksw
  61.  
  62.     endsw
  63. end
  64.  
  65. if ( $#argv == 0 ) then
  66.     goto usage
  67. endif
  68.  
  69. set tmpfile=/tmp/pi.tmp.$$
  70. rm -f $tmpfile
  71. set maxformat=PBM
  72.  
  73. set rowfiles=()
  74. set imagefiles=()
  75. @ row = 1
  76. @ col = 1
  77.  
  78. foreach i ( $argv )
  79.  
  80.     set description=`pnmfile $i`
  81.     if ( $description[4] <= $size && $description[6] <= $size ) then
  82.         cat $i > $tmpfile
  83.     else
  84.         switch ( $description[2] )
  85.             case PBM:
  86.             pnmscale -quiet -xysize $size $size $i | pgmtopbm > $tmpfile
  87.             breaksw
  88.  
  89.             case PGM:
  90.             pnmscale -quiet -xysize $size $size $i > $tmpfile
  91.             if ( $maxformat == PBM ) then
  92.                 set maxformat=PGM
  93.             endif
  94.             breaksw
  95.  
  96.             default:
  97.             pnmscale -quiet -xysize $size $size $i | ppmquant -quiet $colors > $tmpfile
  98.             set maxformat=PPM
  99.             breaksw
  100.         endsw
  101.     endif
  102.     set imagefile=/tmp/pi.${row}.${col}.$$
  103.     rm -f $imagefile
  104.     if ( "$back" == "-white" ) then
  105.         pbmtext "$i" | pnmcat $back -tb $tmpfile - > $imagefile
  106.     else
  107.         pbmtext "$i" | pnminvert | pnmcat $back -tb $tmpfile - > $imagefile
  108.     endif
  109.     rm -f $tmpfile
  110.     set imagefiles=( $imagefiles $imagefile )
  111.  
  112.     if ( $col >= $across ) then
  113.         set rowfile=/tmp/pi.${row}.$$
  114.         rm -f $rowfile
  115.         if ( $maxformat != PPM ) then
  116.             pnmcat $back -lr -jbottom $imagefiles > $rowfile
  117.         else
  118.             pnmcat $back -lr -jbottom $imagefiles | ppmquant -quiet $colors > $rowfile
  119.         endif
  120.         rm -f $imagefiles
  121.         set imagefiles=()
  122.         set rowfiles=( $rowfiles $rowfile )
  123.         @ col = 1
  124.         @ row += 1
  125.     else
  126.         @ col += 1
  127.     endif
  128.  
  129. end
  130.  
  131. if ( $#imagefiles > 0 ) then
  132.     set rowfile=/tmp/pi.${row}.$$
  133.     rm -f $rowfile
  134.     if ( $maxformat != PPM ) then
  135.         pnmcat $back -lr -jbottom $imagefiles > $rowfile
  136.     else
  137.         pnmcat $back -lr -jbottom $imagefiles | ppmquant -quiet $colors > $rowfile
  138.     endif
  139.     rm -f $imagefiles
  140.     set rowfiles=( $rowfiles $rowfile )
  141. endif
  142.  
  143. if ( $#rowfiles == 1 ) then
  144.     cat $rowfiles
  145. else
  146.     if ( $maxformat != PPM ) then
  147.         pnmcat $back -tb $rowfiles
  148.     else
  149.         pnmcat $back -tb $rowfiles | ppmquant -quiet $colors
  150.     endif
  151. endif
  152. rm -f $rowfiles
  153.  
  154. exit 0
  155.  
  156. usage:
  157. echo "usage: $0 [-size N] [-across N] [-colors N] [-black] pnmfile ..."
  158. exit 1
  159.