home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / gs252b.lzh / GS252B / SHOWPBM.PS < prev    next >
Text File  |  1993-07-30  |  2KB  |  81 lines

  1. %    Copyright (C) 1992 Aladdin Enterprises.  All rights reserved.
  2. %    Distributed by Free Software Foundation, Inc.
  3. %
  4. % This file is part of Ghostscript.
  5. %
  6. % Ghostscript is distributed in the hope that it will be useful, but
  7. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. % to anyone for the consequences of using it or for whether it serves any
  9. % particular purpose or works at all, unless he says so in writing.  Refer
  10. % to the Ghostscript General Public License for full details.
  11. %
  12. % Everyone is granted permission to copy, modify and redistribute
  13. % Ghostscript, but only under the conditions described in the Ghostscript
  14. % General Public License.  A copy of this license is supposed to have been
  15. % given to you along with Ghostscript so you can know your rights and
  16. % responsibilities.  It should be in a file named COPYING.  Among other
  17. % things, the copyright notice and this notice must be preserved on all
  18. % copies.
  19.  
  20. % showpbm.ps
  21. % Display a PBM/PGM/PPM file.  Currently only handles "raw" formats (P4-P6).
  22.  
  23. /s 100 string def
  24. /readmaxv
  25.  { f s readline pop cvx exec /maxv exch def
  26.  } def
  27. /pdict 6 dict def
  28. pdict begin
  29.   /P1 [ { /rsize w 7 add 8 idiv def }
  30.     { }
  31.       ] def
  32.   /P2 [ { readmaxv /rsize w def }
  33.     { }
  34.       ] def
  35.   /P3 [ { readmaxv /rsize w 3 mul def }
  36.     { }
  37.       ] def
  38.   /P4 [ { /rsize w 7 add 8 idiv def }
  39.     { true exch { f row readstring pop } imagemask }
  40.       ] def
  41.   /P5 [ { readmaxv /rsize w def }
  42.     { 8 exch { f row readstring pop } image }
  43.       ] def
  44.   /P6 [ { readmaxv /rsize w 3 mul def }
  45.     { 8 exch { f row readstring pop } false 3 colorimage }
  46.       ] def
  47. end
  48. /showpbm        % filename ->
  49.  { (r) file /f exch def
  50.    f s readline pop cvn /pn exch def        % Pn
  51.    f s readline pop        % check for comment
  52.    (#) anchorsearch
  53.     { pop pop f s readline pop }
  54.    if
  55.    cvx exec /h exch def /w exch def
  56.    pdict pn get dup /rprocs exch def
  57.      0 get exec
  58.    /row rsize string def
  59.    % Scale the image (uniformly) to fit the page.
  60.    clippath pathbbox
  61.      dtransform exch abs exch abs min dup scale pop pop
  62.    erasepage
  63.    0 setgray
  64.    w h [w 0 0 h neg 0 h] rprocs 1 get exec
  65.    showpage
  66.  } def
  67.  
  68. % If the program was invoked from the command line, run it now.
  69. [ shellarguments
  70.  { counttomark 1 eq
  71.     { showpbm
  72.     }
  73.     { cleartomark
  74.       (Usage: showpbm filename.p*m\n) print
  75.       ( e.g.: showpbm my.ppm\n) print flush
  76.       mark
  77.     }
  78.    ifelse
  79.  }
  80. if pop
  81.