home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / hypertext / latex2html_1 / OtherStuff / pstoppm3_p < prev   
Text File  |  1996-01-12  |  8KB  |  278 lines

  1. %! PS-Adobe-2.0
  2. %% Program for reading a .ps file and writing out a PPM file.
  3. %% For Ghostscript versions 2.5.2 and later.
  4. %%
  5. %% Modified by Eric verbeek 12/9/94:
  6. %%   Added user-callable procedures to set the papersize.
  7. %% Modified by Nikos Drakos 30/8/94
  8. %%   just commented out the usage message
  9. %% Modified by Tom Shield 3/18/94:
  10. %%   added variable page size.
  11. %% Modified by L. Peter Deutsch 2/19/94:
  12. %%   added proper handling of local and global VM.
  13. %% Modified by L. Peter Deutsch 9/10/92:
  14. %%   internal procedures didn't use `bind';
  15. %%   grestoreall undid selection of PPM device.
  16. %% Modified by L. Peter Deutsch 4/6/92:
  17. %%   Ghostscript 2.4 requires all 8 primary colors to be in the palette.
  18. %% Modified by L. Peter Deutsch 1/17/92:
  19. %%   the palette for makeimagedevice is now a string, not an array.
  20. %% Modified by L. Peter Deutsch 9/24/91:
  21. %%   allow starting page number to be specified.
  22. %% Modified by L. Peter Deutsch 7/7/91 to keep track of page count
  23. %%   in a way that gets around save and restore.
  24. %% Modified by L. Peter Deutsch 11/07/90
  25. %%   to use filename.ppm for the first page, renamed to filename.1ppm
  26. %%   with subsequent pages .2ppm, etc. if more than one page.
  27. %% Modified by Henry Minsky 11/03/90
  28. %%   for each showpage, it writes out a ppm file with name filename.ppm.N
  29. %%   where N increments each showpage, starting at 1
  30. %% Modified by L. Peter Deutsch -- Aladdin Enterprises -- 08/25/90 --
  31. %%   converted from a one-shot program to a utility package,
  32. %%   designed to be used from an interactive terminal.
  33. %% Modified by L. Peter Deutsch -- Aladdin Enterprises -- 08/02/90
  34. %% Modified on 08/02/90 for using the CORRECT color map.
  35. %% Modified 06/26/90 for a color file
  36. %% Original version by Phillip Conrad - Perfect Byte, Inc.
  37. %%
  38. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  39.  
  40. %%%%%% Define the directory for holding the PPM information
  41.  
  42. /ppmdict 30 dict def
  43. ppmdict begin
  44.  
  45.   /Horz_dpi 72 def        % defaults to screen density
  46.   /Vert_dpi 72 def
  47.  
  48.   /Horz_size 8.5 def        % defaults to page size
  49.   /Vert_size 11 def
  50.  
  51.   /OutFilePrefix () def        % default to null (current directory)
  52.  
  53.   /FirstPageNumber 1 def    % any non-negative integer is OK
  54.  
  55.   /Palette1 <ff 00> def
  56.   /Palette8
  57. %========== Here we define all 256 color entries. ======
  58. %========== Colors were taken from the X Windows default colors, ======
  59. %========== hacked up a little so we get all 8 primaries. ======
  60. <
  61. 000000 ffffff a8a8a8 ebebeb 5c5c5c 373737 5f929e 85ccdd
  62. 345057 1f3034 729efe a0ddff 3f578c 263454 6186d8 2f2f64
  63. ffff00 b0e2ff ff0000 808080 efdf84 55fe55 fe0000 66fe57
  64. fe987a feca71 fefefe fe8d7c fea977 fec472 feb875 fe937b
  65. fe957a feb575 98fe5d fe8b7d fea677 feb276 feaf76 febe74
  66. fe837e fefc6a fe0c9a fe0350 fe08b5 6715fe fefb3f fe544b
  67. 00c000 20c000 40c000 60c000 80c000 a0c000 c0c000 e0c000
  68. 00ff00 20e000 40e000 60e000 80e000 a0e000 c0e000 e0e000
  69. 000040 200040 400040 600040 800040 a00040 c00040 e00040
  70. 002040 202040 402040 602040 802040 a02040 c02040 e02040
  71. 004040 204040 404040 604040 804040 a04040 c04040 e04040
  72. 006040 206040 406040 606040 806040 a06040 c06040 e06040
  73. 008040 208040 408040 608040 808040 a08040 c08040 e08040
  74. 00a040 20a040 40a040 60a040 80a040 a0a040 c0a040 e0a040
  75. 00c040 20c040 40c040 60c040 80c040 a0c040 c0c040 e0c040
  76. 00e040 20e040 40e040 60e040 80e040 a0e040 c0e040 e0e040
  77. 000080 200080 400080 600080 800080 a00080 c00080 e00080
  78. 002080 202080 402080 602080 802080 a02080 c02080 e02080
  79. 004080 204080 404080 604080 804080 a04080 c04080 e04080
  80. 006080 206080 406080 606080 806080 a06080 c06080 e06080
  81. 008080 208080 408080 608080 808080 a08080 c08080 e08080
  82. 00a080 20a080 40a080 60a080 80a080 a0a080 c0a080 e0a080
  83. 00c080 20c080 40c080 60c080 80c080 a0c080 c0c080 e0c080
  84. 00e080 20e080 40e080 60e080 80e080 a0e080 c0e080 e0e080
  85. 0000ff 2000c0 4000c0 6000c0 8000c0 a000c0 c000c0 ff00ff
  86. 0020c0 2020c0 4020c0 6020c0 8020c0 a020c0 c020c0 e020c0
  87. 0040c0 2040c0 4040c0 6040c0 8040c0 a040c0 c040c0 e040c0
  88. 0060c0 2060c0 4060c0 6060c0 8060c0 a060c0 c060c0 e060c0
  89. 0080c0 2080c0 4080c0 6080c0 8080c0 a080c0 c080c0 e080c0
  90. 00a0c0 20a0c0 40a0c0 60a0c0 80a0c0 a0a0c0 c0a0c0 e0a0c0
  91. 00c0c0 20c0c0 40c0c0 60c0c0 80c0c0 a0c0c0 c0c0c0 e0c0c0
  92. 00ffff 20e0c0 40e0c0 60e0c0 80e0c0 a0e0c0 c0e0c0 e0e0c0
  93. > def
  94.  
  95.   % Define a procedure for computing the output file name for a given page.
  96.   /pagefilename        % <int|null> pagefilename -> <string
  97.    { OutFilePrefix FileName concatstrings (.) concatstrings
  98.      exch dup null ne
  99.       { 1 sub FirstPageNumber add (xxxxxx) cvs concatstrings }
  100.       { pop }
  101.      ifelse (ppm) concatstrings
  102.    } bind def
  103.  
  104.   % Redefine copypage and showpage appropriately.
  105.  
  106.   /currentglobal where { pop currentglobal true .setglobal } { true } ifelse
  107.  
  108.   /copypage
  109.    { ppmdict begin
  110.  
  111.        /PageCount PageCountString cvi 100000 sub def
  112.        /PageCount PageCount 1 add def
  113.  
  114.        PageCount 1 eq
  115.     { null pagefilename            % first page
  116.     }
  117.     { PageCount 2 eq
  118.        {                    % second page, rename first
  119.          null pagefilename 1 pagefilename
  120.          (Renaming ) print 1 index print ( to ) print
  121.            dup print (\n) print
  122.          flush
  123.          renamefile
  124.        } if
  125.       PageCount pagefilename
  126.     } ifelse
  127.        /FileNameOut exch def
  128.  
  129.        FileNameOut (w) file
  130.          /FileDescOut exch def
  131.  
  132.        (Writing ) print FileNameOut print (\n) print
  133.        flush
  134.        FileDescOut Device writeppmfile
  135.        FileDescOut closefile
  136.  
  137.        WrotePage 0 1 put    % /WrotePage true def
  138.        PageCount 100000 add PageCountString cvs pop
  139.  
  140.      end
  141.    } bind userdict begin odef end
  142.   /showpage
  143.    { copypage erasepage initgraphics
  144.    } bind userdict begin odef end
  145.  
  146.   % Redefine grestoreall so it doesn't undo the device selection
  147.   /grestoreall /grestoreall load def
  148.   /grestoreall
  149.    { ppmdict begin   grestoreall   Device setdevice   end
  150.    } bind userdict begin odef end
  151.  
  152.   not { false .setglobal } if
  153.  
  154.   /Convert            % the main procedure
  155.                   % <filename> <palette> Convert -
  156.    { /Palette exch def
  157.      /FileName exch def
  158.  
  159.      % Save and restore don't save and restore the contents of strings.
  160.      % Therefore, we use strings to hold the two variables whose values
  161.      % must persist across page boundaries (PageCount and WrotePage).
  162.  
  163.      /PageCountString 6 string def
  164.      100000 PageCountString cvs pop
  165.      /WrotePage 1 string def
  166.  
  167.      /ScaleX Horz_dpi 72 div def
  168.      /ScaleY Vert_dpi 72 div def
  169.  
  170.      /Width Horz_size Horz_dpi mul round cvi def
  171.      /Height Vert_size Vert_dpi mul round cvi def
  172.  
  173.      FileName (.ps) concatstrings
  174.        /FileNameIn exch def        % file name with extension
  175.  
  176.      [ScaleX 0.0 0.0 ScaleY neg 0.0 Height]
  177.      Width Height Palette makeimagedevice
  178.        /Device exch def
  179.      Device setdevice
  180.  
  181.      % For running the file, remove ppmdict from the dict stack
  182.      FileNameIn end run        % ppmdict
  183.      ppmdict begin
  184.      WrotePage 0 get 0 eq { showpage } if % make sure the page got written
  185.      end            % ppmdict
  186.  
  187.    } bind def
  188.  
  189. end                % ppmdict
  190.  
  191. %%%%%% Define the user-callable procedures
  192. /ppmsetsize
  193.  { ppmdict begin
  194.    /Vert_size exch def
  195.    /Horz_size exch def
  196.    end
  197.  } bind def
  198.  
  199. /ppmsetsize2letter
  200.  { 612 792 ppmsetsize
  201.  } bind def
  202.  
  203. /ppmsetsize2legal
  204.  { 612 1008 ppmsetsize
  205.  } bind def
  206.  
  207. /ppmsetsize2a4
  208.  { 595 842 ppmsetsize
  209.  } bind def
  210.  
  211. /ppmsetsize2a3
  212.  { 842 1190 ppmsetsize
  213.  } bind def
  214.  
  215. /ppmsetsize2a2
  216.  { 1190 1684 ppmsetsize
  217.  } bind def
  218.  
  219. /ppmsetsize2a1
  220.  { 1684 2380 ppmsetsize
  221.  } bind def
  222.  
  223. /ppmsetsize2a0
  224.  { 2380 3368 ppmsetsize
  225.  } bind def
  226.  
  227. /ppmsetdensity
  228.  { ppmdict begin
  229.    /Vert_dpi exch def
  230.    /Horz_dpi exch def
  231.    end
  232.  } bind def
  233.  
  234. /ppmsetpagesize
  235.  { ppmdict begin
  236.    /Vert_size exch def
  237.    /Horz_size exch def
  238.    end
  239.  } bind def
  240.  
  241. /ppmsetprefix
  242.  { ppmdict begin
  243.    /OutFilePrefix exch def
  244.    end
  245.  } bind def
  246.  
  247. /ppmsetfirstpagenumber
  248.  { cvi
  249.    ppmdict begin
  250.    /FirstPageNumber exch def
  251.  } bind def
  252.  
  253. /ppm1run
  254.  { ppmdict begin   Palette1 Convert
  255.  } bind def
  256.  
  257. /ppm8run
  258.  { ppmdict begin   Palette8 Convert
  259.  } bind def
  260.  
  261. /ppm24run
  262.  { ppmdict begin   null Convert
  263.  } bind def
  264.  
  265. %%%%%% Display instructions for the user.
  266.  
  267. %(Usage: (file) ppmNrun\n) print
  268. %(   converts file.ps to file.ppm (single page),\n) print
  269. %(     or file.1ppm, file.2ppm, ... (multi page).\n) print
  270. %(   N is # of bits per pixel (1, 8, or 24).\n) print
  271. %(Examples: (golfer) ppm1run   ..or..   (escher) ppm8run\n) print
  272. %(Optional commands you can give first:\n) print
  273. %(   horiz_DPI vert_DPI ppmsetdensity\n) print
  274. %(   horiz_inches vert_inches ppmsetpagesize\n) print
  275. %(   (dirname/) ppmsetprefix\n) print
  276. %(   page_num ppmsetfirstpagenumber\n) print
  277. flush
  278.