home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / PSCRIPT / GS23A.ZIP / PSTOPPM.PS < prev    next >
Encoding:
Text File  |  1991-08-22  |  13.0 KB  |  413 lines

  1. %! PS-Adobe-2.0
  2. %% Program for reading a .ps file and writing out a PPM file.
  3. %% For Ghostscript 2.3
  4. %%
  5. %% Modified by L. Peter Deutsch 7/7/91 to keep track of page count
  6. %%   in a way that gets around save and restore.
  7. %% Modified by L. Peter Deutsch 11/07/90
  8. %%   to use filename.ppm for the first page, renamed to filename.1ppm
  9. %%   with subsequent pages .2ppm, etc. if more than one page.
  10. %% Modified by Henry Minsky 11/03/90
  11. %%   for each showpage, it writes out a ppm file with name filename.ppm.N
  12. %%   where N increments each showpage, starting at 1
  13. %% Modified by L. Peter Deutsch -- Aladdin Enterprises -- 08/25/90 --
  14. %%   converted from a one-shot program to a utility package,
  15. %%   designed to be used from an interactive terminal.
  16. %% Modified by L. Peter Deutsch -- Aladdin Enterprises -- 08/02/90
  17. %% Modified on 08/02/90 for using the CORRECT color map.
  18. %% Modified 06/26/90 for a color file
  19. %% Original version by Phillip Conrad - Perfect Byte, Inc.
  20. %%
  21. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  22.  
  23. %%%%%% Define the directory for holding the PPM information
  24.  
  25. /ppmdict 30 dict def
  26. ppmdict begin
  27.  
  28.   /Horz_dpi 72 def        % defaults to screen density
  29.   /Vert_dpi 72 def
  30.  
  31.   /OutFilePrefix () def        % default to null (current directory)
  32.  
  33.   /Palette1 [1 1 1 rgbcolor 0 0 0 rgbcolor] def
  34.   /Palette8
  35.     [
  36. %========== Here we define all 256 color entries as color objects. ======
  37. %========== Colors were taken from the W Xindows default colors. ======
  38. 0.000   0.000   0.000   rgbcolor
  39. 1.000   1.000   1.000   rgbcolor
  40. 0.659   0.659   0.659   rgbcolor
  41. 0.922   0.922   0.922   rgbcolor
  42. 0.361   0.361   0.361   rgbcolor
  43. 0.216   0.216   0.216   rgbcolor
  44. 0.373   0.573   0.620   rgbcolor
  45. 0.522   0.800   0.867   rgbcolor
  46. 0.204   0.314   0.341   rgbcolor
  47. 0.122   0.188   0.204   rgbcolor
  48. 0.447   0.620   0.996   rgbcolor
  49. 0.627   0.867   1.000   rgbcolor
  50. 0.247   0.341   0.549   rgbcolor
  51. 0.149   0.204   0.329   rgbcolor
  52. 0.380   0.525   0.847   rgbcolor
  53. 0.184   0.184   0.392   rgbcolor
  54. 1.000   1.000   0.000   rgbcolor
  55. 0.690   0.886   1.000   rgbcolor
  56. 1.000   0.000   0.000   rgbcolor
  57. 0.502   0.502   0.502   rgbcolor
  58. 0.937   0.875   0.518   rgbcolor
  59. 0.333   0.996   0.333   rgbcolor
  60. 0.996   0.000   0.000   rgbcolor
  61. 0.400   0.996   0.341   rgbcolor
  62. 0.996   0.596   0.478   rgbcolor
  63. 0.996   0.792   0.443   rgbcolor
  64. 0.996   0.996   0.996   rgbcolor
  65. 0.996   0.553   0.486   rgbcolor
  66. 0.996   0.663   0.467   rgbcolor
  67. 0.996   0.769   0.447   rgbcolor
  68. 0.996   0.722   0.459   rgbcolor
  69. 0.996   0.576   0.482   rgbcolor
  70. 0.996   0.584   0.478   rgbcolor
  71. 0.996   0.710   0.459   rgbcolor
  72. 0.596   0.996   0.365   rgbcolor
  73. 0.996   0.545   0.490   rgbcolor
  74. 0.996   0.651   0.467   rgbcolor
  75. 0.996   0.698   0.463   rgbcolor
  76. 0.996   0.686   0.463   rgbcolor
  77. 0.996   0.745   0.455   rgbcolor
  78. 0.996   0.514   0.494   rgbcolor
  79. 0.996   0.988   0.416   rgbcolor
  80. 0.996   0.047   0.604   rgbcolor
  81. 0.996   0.012   0.314   rgbcolor
  82. 0.996   0.031   0.710   rgbcolor
  83. 0.404   0.082   0.996   rgbcolor
  84. 0.996   0.984   0.247   rgbcolor
  85. 0.996   0.329   0.294   rgbcolor
  86. 0.000   0.753   0.000   rgbcolor
  87. 0.125   0.753   0.000   rgbcolor
  88. 0.251   0.753   0.000   rgbcolor
  89. 0.376   0.753   0.000   rgbcolor
  90. 0.502   0.753   0.000   rgbcolor
  91. 0.627   0.753   0.000   rgbcolor
  92. 0.753   0.753   0.000   rgbcolor
  93. 0.878   0.753   0.000   rgbcolor
  94. 0.000   0.878   0.000   rgbcolor
  95. 0.125   0.878   0.000   rgbcolor
  96. 0.251   0.878   0.000   rgbcolor
  97. 0.376   0.878   0.000   rgbcolor
  98. 0.502   0.878   0.000   rgbcolor
  99. 0.627   0.878   0.000   rgbcolor
  100. 0.753   0.878   0.000   rgbcolor
  101. 0.878   0.878   0.000   rgbcolor
  102. 0.000   0.000   0.251   rgbcolor
  103. 0.125   0.000   0.251   rgbcolor
  104. 0.251   0.000   0.251   rgbcolor
  105. 0.376   0.000   0.251   rgbcolor
  106. 0.502   0.000   0.251   rgbcolor
  107. 0.627   0.000   0.251   rgbcolor
  108. 0.753   0.000   0.251   rgbcolor
  109. 0.878   0.000   0.251   rgbcolor
  110. 0.000   0.125   0.251   rgbcolor
  111. 0.125   0.125   0.251   rgbcolor
  112. 0.251   0.125   0.251   rgbcolor
  113. 0.376   0.125   0.251   rgbcolor
  114. 0.502   0.125   0.251   rgbcolor
  115. 0.627   0.125   0.251   rgbcolor
  116. 0.753   0.125   0.251   rgbcolor
  117. 0.878   0.125   0.251   rgbcolor
  118. 0.000   0.251   0.251   rgbcolor
  119. 0.125   0.251   0.251   rgbcolor
  120. 0.251   0.251   0.251   rgbcolor
  121. 0.376   0.251   0.251   rgbcolor
  122. 0.502   0.251   0.251   rgbcolor
  123. 0.627   0.251   0.251   rgbcolor
  124. 0.753   0.251   0.251   rgbcolor
  125. 0.878   0.251   0.251   rgbcolor
  126. 0.000   0.376   0.251   rgbcolor
  127. 0.125   0.376   0.251   rgbcolor
  128. 0.251   0.376   0.251   rgbcolor
  129. 0.376   0.376   0.251   rgbcolor
  130. 0.502   0.376   0.251   rgbcolor
  131. 0.627   0.376   0.251   rgbcolor
  132. 0.753   0.376   0.251   rgbcolor
  133. 0.878   0.376   0.251   rgbcolor
  134. 0.000   0.502   0.251   rgbcolor
  135. 0.125   0.502   0.251   rgbcolor
  136. 0.251   0.502   0.251   rgbcolor
  137. 0.376   0.502   0.251   rgbcolor
  138. 0.502   0.502   0.251   rgbcolor
  139. 0.627   0.502   0.251   rgbcolor
  140. 0.753   0.502   0.251   rgbcolor
  141. 0.878   0.502   0.251   rgbcolor
  142. 0.000   0.627   0.251   rgbcolor
  143. 0.125   0.627   0.251   rgbcolor
  144. 0.251   0.627   0.251   rgbcolor
  145. 0.376   0.627   0.251   rgbcolor
  146. 0.502   0.627   0.251   rgbcolor
  147. 0.627   0.627   0.251   rgbcolor
  148. 0.753   0.627   0.251   rgbcolor
  149. 0.878   0.627   0.251   rgbcolor
  150. 0.000   0.753   0.251   rgbcolor
  151. 0.125   0.753   0.251   rgbcolor
  152. 0.251   0.753   0.251   rgbcolor
  153. 0.376   0.753   0.251   rgbcolor
  154. 0.502   0.753   0.251   rgbcolor
  155. 0.627   0.753   0.251   rgbcolor
  156. 0.753   0.753   0.251   rgbcolor
  157. 0.878   0.753   0.251   rgbcolor
  158. 0.000   0.878   0.251   rgbcolor
  159. 0.125   0.878   0.251   rgbcolor
  160. 0.251   0.878   0.251   rgbcolor
  161. 0.376   0.878   0.251   rgbcolor
  162. 0.502   0.878   0.251   rgbcolor
  163. 0.627   0.878   0.251   rgbcolor
  164. 0.753   0.878   0.251   rgbcolor
  165. 0.878   0.878   0.251   rgbcolor
  166. 0.000   0.000   0.502   rgbcolor
  167. 0.125   0.000   0.502   rgbcolor
  168. 0.251   0.000   0.502   rgbcolor
  169. 0.376   0.000   0.502   rgbcolor
  170. 0.502   0.000   0.502   rgbcolor
  171. 0.627   0.000   0.502   rgbcolor
  172. 0.753   0.000   0.502   rgbcolor
  173. 0.878   0.000   0.502   rgbcolor
  174. 0.000   0.125   0.502   rgbcolor
  175. 0.125   0.125   0.502   rgbcolor
  176. 0.251   0.125   0.502   rgbcolor
  177. 0.376   0.125   0.502   rgbcolor
  178. 0.502   0.125   0.502   rgbcolor
  179. 0.627   0.125   0.502   rgbcolor
  180. 0.753   0.125   0.502   rgbcolor
  181. 0.878   0.125   0.502   rgbcolor
  182. 0.000   0.251   0.502   rgbcolor
  183. 0.125   0.251   0.502   rgbcolor
  184. 0.251   0.251   0.502   rgbcolor
  185. 0.376   0.251   0.502   rgbcolor
  186. 0.502   0.251   0.502   rgbcolor
  187. 0.627   0.251   0.502   rgbcolor
  188. 0.753   0.251   0.502   rgbcolor
  189. 0.878   0.251   0.502   rgbcolor
  190. 0.000   0.376   0.502   rgbcolor
  191. 0.125   0.376   0.502   rgbcolor
  192. 0.251   0.376   0.502   rgbcolor
  193. 0.376   0.376   0.502   rgbcolor
  194. 0.502   0.376   0.502   rgbcolor
  195. 0.627   0.376   0.502   rgbcolor
  196. 0.753   0.376   0.502   rgbcolor
  197. 0.878   0.376   0.502   rgbcolor
  198. 0.000   0.502   0.502   rgbcolor
  199. 0.125   0.502   0.502   rgbcolor
  200. 0.251   0.502   0.502   rgbcolor
  201. 0.376   0.502   0.502   rgbcolor
  202. 0.502   0.502   0.502   rgbcolor
  203. 0.627   0.502   0.502   rgbcolor
  204. 0.753   0.502   0.502   rgbcolor
  205. 0.878   0.502   0.502   rgbcolor
  206. 0.000   0.627   0.502   rgbcolor
  207. 0.125   0.627   0.502   rgbcolor
  208. 0.251   0.627   0.502   rgbcolor
  209. 0.376   0.627   0.502   rgbcolor
  210. 0.502   0.627   0.502   rgbcolor
  211. 0.627   0.627   0.502   rgbcolor
  212. 0.753   0.627   0.502   rgbcolor
  213. 0.878   0.627   0.502   rgbcolor
  214. 0.000   0.753   0.502   rgbcolor
  215. 0.125   0.753   0.502   rgbcolor
  216. 0.251   0.753   0.502   rgbcolor
  217. 0.376   0.753   0.502   rgbcolor
  218. 0.502   0.753   0.502   rgbcolor
  219. 0.627   0.753   0.502   rgbcolor
  220. 0.753   0.753   0.502   rgbcolor
  221. 0.878   0.753   0.502   rgbcolor
  222. 0.000   0.878   0.502   rgbcolor
  223. 0.125   0.878   0.502   rgbcolor
  224. 0.251   0.878   0.502   rgbcolor
  225. 0.376   0.878   0.502   rgbcolor
  226. 0.502   0.878   0.502   rgbcolor
  227. 0.627   0.878   0.502   rgbcolor
  228. 0.753   0.878   0.502   rgbcolor
  229. 0.878   0.878   0.502   rgbcolor
  230. 0.000   0.000   0.753   rgbcolor
  231. 0.125   0.000   0.753   rgbcolor
  232. 0.251   0.000   0.753   rgbcolor
  233. 0.376   0.000   0.753   rgbcolor
  234. 0.502   0.000   0.753   rgbcolor
  235. 0.627   0.000   0.753   rgbcolor
  236. 0.753   0.000   0.753   rgbcolor
  237. 0.878   0.000   0.753   rgbcolor
  238. 0.000   0.125   0.753   rgbcolor
  239. 0.125   0.125   0.753   rgbcolor
  240. 0.251   0.125   0.753   rgbcolor
  241. 0.376   0.125   0.753   rgbcolor
  242. 0.502   0.125   0.753   rgbcolor
  243. 0.627   0.125   0.753   rgbcolor
  244. 0.753   0.125   0.753   rgbcolor
  245. 0.878   0.125   0.753   rgbcolor
  246. 0.000   0.251   0.753   rgbcolor
  247. 0.125   0.251   0.753   rgbcolor
  248. 0.251   0.251   0.753   rgbcolor
  249. 0.376   0.251   0.753   rgbcolor
  250. 0.502   0.251   0.753   rgbcolor
  251. 0.627   0.251   0.753   rgbcolor
  252. 0.753   0.251   0.753   rgbcolor
  253. 0.878   0.251   0.753   rgbcolor
  254. 0.000   0.376   0.753   rgbcolor
  255. 0.125   0.376   0.753   rgbcolor
  256. 0.251   0.376   0.753   rgbcolor
  257. 0.376   0.376   0.753   rgbcolor
  258. 0.502   0.376   0.753   rgbcolor
  259. 0.627   0.376   0.753   rgbcolor
  260. 0.753   0.376   0.753   rgbcolor
  261. 0.878   0.376   0.753   rgbcolor
  262. 0.000   0.502   0.753   rgbcolor
  263. 0.125   0.502   0.753   rgbcolor
  264. 0.251   0.502   0.753   rgbcolor
  265. 0.376   0.502   0.753   rgbcolor
  266. 0.502   0.502   0.753   rgbcolor
  267. 0.627   0.502   0.753   rgbcolor
  268. 0.753   0.502   0.753   rgbcolor
  269. 0.878   0.502   0.753   rgbcolor
  270. 0.000   0.627   0.753   rgbcolor
  271. 0.125   0.627   0.753   rgbcolor
  272. 0.251   0.627   0.753   rgbcolor
  273. 0.376   0.627   0.753   rgbcolor
  274. 0.502   0.627   0.753   rgbcolor
  275. 0.627   0.627   0.753   rgbcolor
  276. 0.753   0.627   0.753   rgbcolor
  277. 0.878   0.627   0.753   rgbcolor
  278. 0.000   0.753   0.753   rgbcolor
  279. 0.125   0.753   0.753   rgbcolor
  280. 0.251   0.753   0.753   rgbcolor
  281. 0.376   0.753   0.753   rgbcolor
  282. 0.502   0.753   0.753   rgbcolor
  283. 0.627   0.753   0.753   rgbcolor
  284. 0.753   0.753   0.753   rgbcolor
  285. 0.878   0.753   0.753   rgbcolor
  286. 0.000   0.878   0.753   rgbcolor
  287. 0.125   0.878   0.753   rgbcolor
  288. 0.251   0.878   0.753   rgbcolor
  289. 0.376   0.878   0.753   rgbcolor
  290. 0.502   0.878   0.753   rgbcolor
  291. 0.627   0.878   0.753   rgbcolor
  292. 0.753   0.878   0.753   rgbcolor
  293. 0.878   0.878   0.753   rgbcolor
  294.     ] def
  295.  
  296.   % Redefine copypage and showpage appropriately
  297.   /copypage
  298.    { ppmdict begin
  299.  
  300.        /PageCount PageCountString cvi 100000 sub def
  301.        /PageCount PageCount 1 add def
  302.  
  303.        OutFilePrefix FileName concatstrings
  304.        PageCount 1 eq
  305.     { (.ppm) concatstrings            % first page
  306.     }
  307.     { PageCount 2 eq
  308.        {                    % second page, rename first
  309.          dup dup (.ppm) concatstrings
  310.          exch (.1ppm) concatstrings
  311.          (Renaming ) print 1 index print ( to ) print
  312.            dup print (\n) print
  313.          flush
  314.          renamefile
  315.        } if
  316.       (.) PageCount (xxxxxx) cvs concatstrings
  317.       (ppm) concatstrings concatstrings
  318.     } ifelse
  319.        /FileNameOut exch def
  320.  
  321.        FileNameOut (w) file
  322.          /FileDescOut exch def
  323.  
  324.        (Writing ) print FileNameOut print (\n) print
  325.        flush
  326.        FileDescOut Device writeppmfile
  327.        FileDescOut closefile
  328.  
  329.        WrotePage 0 1 put    % /WrotePage true def
  330.        PageCount 100000 add PageCountString cvs pop
  331.  
  332.      end
  333.    } userdict begin def end
  334.   /showpage
  335.    { copypage erasepage initgraphics
  336.    } userdict begin def end
  337.  
  338.   /Convert            % the main procedure
  339.                   % <filename> <palette> Convert -
  340.    { /Palette exch def
  341.      /FileName exch def
  342.  
  343.      % Save and restore don't save and restore the contents of strings.
  344.      % Therefore, we use strings to hold the two variables whose values
  345.      % must persist across page boundaries (PageCount and WrotePage).
  346.  
  347.      /PageCountString 6 string def
  348.      100000 PageCountString cvs pop
  349.      /WrotePage 1 string def
  350.  
  351.      /ScaleX Horz_dpi 72 div def
  352.      /ScaleY Vert_dpi 72 div def
  353.  
  354.      /Width 85 Horz_dpi mul 5 add 10 div cvi def % add 5 to round up!
  355.      /Height 11 Vert_dpi mul def
  356.  
  357.      FileName (.ps) concatstrings
  358.        /FileNameIn exch def        % file name with extension
  359.  
  360.      [ScaleX 0.0 0.0 ScaleY neg 0.0 Height]
  361.      Width Height Palette makeimagedevice
  362.        /Device exch def
  363.      Device setdevice
  364.  
  365.      % For running the file, remove ppmdict from the dict stack
  366.      FileNameIn end run        % ppmdict
  367.      ppmdict begin
  368.      WrotePage 0 get 0 eq { showpage } if % make sure the page got written
  369.      end            % ppmdict
  370.  
  371.    } def
  372.  
  373. end                % ppmdict
  374.  
  375. %%%%%% Define the user-callable procedures
  376.  
  377. /ppmsetdensity
  378.  { ppmdict begin
  379.    /Vert_dpi exch def
  380.    /Horz_dpi exch def
  381.    end
  382.  } def
  383.  
  384. /ppmsetprefix
  385.  { ppmdict begin
  386.    /OutFilePrefix exch def
  387.    end
  388.  } def
  389.  
  390. /ppm1run
  391.  { ppmdict begin   Palette1 Convert
  392.  } def
  393.  
  394. /ppm8run
  395.  { ppmdict begin   Palette8 Convert
  396.  } def
  397.  
  398. /ppm24run
  399.  { ppmdict begin   null Convert
  400.  } def
  401.  
  402. %%%%%% Display instructions for the user.
  403.  
  404. (Usage: (file) ppmNrun\n) print
  405. (   converts file.ps to file.ppm (single page),\n) print
  406. (     or file.1ppm, file.2ppm, ... (multi page).\n) print
  407. (   N is # of bits per pixel (1, 8, or 24).\n) print
  408. (Examples: (golfer) ppm1run   ..or..   (escher) ppm8run\n) print
  409. (Optional commands you can give first:\n) print
  410. (   horiz_DPI vert_DPI ppmsetdensity\n) print
  411. (   (dirname/) ppmsetprefix\n) print
  412. flush
  413.