home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Actualizar / Impressora_PDF / converter.exe / GPLGS / viewpbm.ps < prev    next >
Text File  |  2002-06-03  |  5KB  |  185 lines

  1. %    Copyright (C) 1992, 1995, 1996, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: viewpbm.ps,v 1.5 2002/06/02 12:03:28 mpsuzuki Exp $
  14. % viewpbm.ps
  15. % Display a PBM/PGM/PPM file.
  16. % Requires the Level 2 `image' operator (to handle variable pixel widths).
  17. % If SCALE is defined, maps input pixels to output pixels with that scale;
  18. % if SCALE is undefined, scales the image to fit the page.
  19.  
  20. /s 100 string def
  21. /readmaxv {        % <file> readmaxv -
  22.   10 string readline pop cvx exec /maxv exch def
  23. } bind def
  24. /readrow {        % <file> <row> readrow <row>
  25.   0 1 2 index length 1 sub {
  26.     1 index exch 3 index token pop put
  27.   } for exch pop
  28. } bind def
  29. /read01 {        % <file> <count> read01 <byte>
  30.   0 exch {
  31.     1 index read pop 48 xor dup 1 le { exch dup add add } { pop } ifelse
  32.   } repeat
  33. } bind def
  34. /readrow01 {        % <file> <row> readrow01 <row>
  35.   0 1 w 8 idiv {
  36.     1 index exch 3 index 8 read01 put
  37.   } for
  38.   wrem 0 ne {
  39.      dup rsize 1 sub wrem read01 8 wrem sub bitshift put
  40.   } if
  41.   exch pop
  42. } bind def
  43. /readwh {        % <file> readwh <w> <h>
  44.  dup s readline pop        % check for comment
  45.  (#) anchorsearch {
  46.    pop pop dup s readline pop
  47.  } if
  48.  cvx exec
  49. } bind def
  50. /pbmtypes mark
  51. % The procedures in this dictionary are called as
  52. %    <file> Pn <w> <h> <readproc>
  53. /P1 {            % ASCII 1-bit white/black
  54.   /bpc 1 def /maxv 1 def /rsize w 7 add 8 idiv def
  55.   /wrem w 8 mod def
  56.   /ncomp 1 def /invert true def /DeviceGray setcolorspace
  57.   readwh
  58.     { readrow01 }
  59. } bind
  60. /P2 {            % ASCII 8-bit gray
  61.   readwh
  62.   /bpc 8 def 2 index readmaxv /rsize 2 index def
  63.   /ncomp 1 def /invert false def /DeviceGray setcolorspace
  64.     { readrow }
  65. } bind
  66. /P3 {            % ASCII 8-bit RGB
  67.   readwh
  68.   /bpc 8 def 2 index readmaxv /rsize 2 index 3 mul def
  69.   /ncomp 3 def /invert false def /DeviceRGB setcolorspace
  70.     { readrow }
  71. } bind
  72. /P4 {            % Binary 1-bit white/black
  73.   readwh
  74.   /bpc 1 def /maxv 1 def /rsize 2 index 7 add 8 idiv def
  75.   /ncomp 1 def /invert true def /DeviceGray setcolorspace
  76.     { readstring pop }
  77. } bind
  78. /P5 {            % Binary 8-bit gray
  79.   readwh
  80.   /bpc 8 def 2 index readmaxv /rsize 2 index def
  81.   /ncomp 1 def /invert false def /DeviceGray setcolorspace
  82.     { readstring pop }
  83. } bind
  84. /P6 {            % Binary 8-bit RGB
  85.   readwh
  86.   /bpc 8 def 2 index readmaxv /rsize 2 index 3 mul def
  87.   /ncomp 3 def /invert false def /DeviceRGB setcolorspace
  88.     { readstring pop }
  89. } bind
  90. .dicttomark readonly def
  91. /pbmsetup {            % <file> <w> <h> <readproc> runpbm -
  92.    /readproc exch def
  93.    /h exch def
  94.    /w exch def
  95.    /f exch def
  96.    20 dict begin        % image dictionary
  97.      /ImageType 1 def
  98.      /Width w def
  99.      /Height h def
  100.      /ImageMatrix [w 0 0 h neg 0 h] def
  101.      /BitsPerComponent bpc def
  102.      /Decode [ 0 255 maxv div invert { exch } if ncomp 1 sub { 2 copy } repeat ] def
  103.      /DataSource [ f rsize string /readproc load /exec load ] cvx def
  104.    currentdict end
  105. } def
  106. /imagescale {            % <imagedict> imagescale -
  107.   begin
  108.     /SCALE where {
  109.       pop
  110.     % Map pixels SCALE-for-1.  Assume orthogonal transformation.
  111.       Width 1 0 dtransform add abs div SCALE mul
  112.       Height 0 1 dtransform add abs div SCALE mul
  113.     } {
  114.     % Scale the image (uniformly) to fit the page.
  115.       clippath pathbbox pop pop translate
  116.       pathbbox .min exch pop exch pop ceiling
  117.       dup Height Width gt {
  118.     Width mul Height div exch
  119.       } {
  120.     Height mul Width div
  121.       } ifelse
  122.     }
  123.     ifelse scale
  124.   end
  125. } def
  126.  
  127. % Image a PBM file page by page.
  128. /viewpbm {            % <filename> viewpbm -
  129.   20 dict begin
  130.     (r) file /pf exch def {
  131.       pf token not { exit } if
  132.       pbmtypes exch get pf exch exec pbmsetup
  133.       dup imagescale image showpage
  134.     } loop
  135.   end
  136. } def
  137.  
  138. % Reassemble a composite PBM file from the CMYK separations.
  139. /viewpsm {
  140.   20 dict begin
  141.     /fname exch def
  142.     /sources [ 0 1 3 {
  143.       /plane exch def 
  144.       /pf fname (r) file def
  145.       pf pbmtypes pf token pop get exec
  146.         % Stack: pf w h readproc
  147.       plane {
  148.     /readproc exch def /h exch def /w exch def pop
  149.     /row rsize string def
  150.     h { pf row readproc pop } repeat
  151.     pf pbmtypes pf token pop get exec
  152.       } repeat
  153.       pbmsetup
  154.     } for ] def
  155.     /datas [ sources { /DataSource get 0 get } forall ] def
  156.     /decode sources 0 get /Decode get
  157.       dup 0 get exch 1 get add cvi 0 exch
  158.       2 copy 4 copy 8 array astore def
  159.     sources 0 get
  160.       dup /MultipleDataSources true put
  161.       dup /DataSource datas put
  162.       dup /Decode decode put
  163.     /DeviceCMYK setcolorspace
  164.     dup imagescale image showpage
  165.   end
  166. } def
  167.  
  168. % If the program was invoked from the command line, run it now.
  169. [ shellarguments
  170.  { counttomark 1 ge
  171.     { ] { viewpbm } forall
  172.     }
  173.     { cleartomark
  174.       (Usage: gs [--] viewpbm.ps filename.p*m ...\n) print
  175.       ( e.g.: gs [--] viewpbm.ps my.ppm another.ppm\n) print flush
  176.     }
  177.    ifelse
  178.  }
  179.  { pop
  180.  }
  181. ifelse
  182.