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

  1. %    Copyright (C) 1996, 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: viewpcx.ps,v 1.5 2002/06/02 12:03:28 mpsuzuki Exp $
  14. % viewpcx.ps
  15. % Display a PCX 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. % ****NOTE: does not handle multi-plane images with palette.
  20.  
  21. /pcxbytes [
  22.   0 1 255 {
  23.     64 string exch 0 1 63 {
  24.       3 copy exch put pop
  25.     } for pop
  26.   } for
  27. ] readonly def
  28. /readpcx {            % - readpcx <str>
  29.   f                % gets replaced
  30.   dup read not {
  31.     pop ()
  32.   } {
  33.     dup 192 lt {
  34.       ( ) dup 0 4 -1 roll put exch pop
  35.     } {
  36.       192 sub //pcxbytes 3 -1 roll read pop get exch 0 exch getinterval
  37.     } ifelse
  38.   } ifelse
  39. } def
  40. /get2                % <string> <index> get2 <int>
  41.  { 2 copy get 3 1 roll 1 add get 8 bitshift add
  42.  } bind def
  43. /dsproc
  44.  { df s readstring pop        % s gets filled in
  45.    s1 () ne { df s1 readstring pop pop } if % discard padding bytes
  46.  } def                % don't bind, must be writable
  47. /viewpcx            % <filename> viewpcx -
  48.  { 100 dict begin
  49.    /fname 1 index def
  50.    /f exch (r) file def
  51.         % Read and unpack the header.
  52.    /header f 128 string readstring pop def
  53.    /version header 1 get def
  54.    /bpp header 3 get def
  55.    /w header 8 get2 header 4 get2 sub 1 add def
  56.    /h header 10 get2 header 6 get2 sub 1 add def
  57.    /nplanes header 65 get def
  58.    /bpl header 66 get2 def
  59.    /palinfo header 68 get2 def
  60.    /nbits bpp nplanes mul def
  61.    version 5 eq
  62.     { nbits 8 le
  63.        { /cspace
  64.        [/Indexed   /DeviceRGB   1 bpp bitshift 1 sub
  65.      f fileposition
  66.      1 nbits bitshift 3 mul string
  67.      fname status pop pop pop exch pop
  68.      1 index length sub f exch setfileposition
  69.      f exch readstring pop
  70.      exch f exch setfileposition
  71.        ] def
  72.      /decode [0 cspace 2 get] def
  73.        }
  74.        { /cspace /DeviceRGB def
  75.      /decode [0 1 0 1 0 1] def
  76.        }
  77.       ifelse
  78.     }
  79.     { /cspace
  80.     [/Indexed   /DeviceRGB   1 bpp bitshift 1 sub
  81.      header 16 1 nbits bitshift 16 .min 3 mul getinterval
  82.     ] def
  83.       /decode [0 cspace 2 get] def
  84.     }
  85.    ifelse
  86.         % Set up scaling.
  87.    /SCALE where
  88.     { pop
  89.     % Map pixels SCALE-for-1.  Assume orthogonal transformation.
  90.       w 1 0 dtransform add abs div SCALE mul
  91.       h 0 1 dtransform add abs div SCALE mul
  92.     }
  93.     {    % Scale the image (uniformly) to fit the page.
  94.       clippath pathbbox pop pop translate
  95.       pathbbox .min exch pop exch pop ceiling
  96.       dup h w gt { w mul h div exch } { h mul w div } ifelse
  97.     }
  98.    ifelse scale
  99.         % Since the number of bytes per line is always even,
  100.         % it may not match the width specification.
  101.    /wbpl w bpp mul 7 add 8 idiv def
  102.         % Define the data source procedure.
  103.    /s1 bpl wbpl sub string def
  104.    /df /readpcx load copyarray dup 0 f put cvx bind readonly
  105.      0 () /SubFileDecode filter def
  106.    /dsource [ nplanes
  107.     { /dsproc load copyarray
  108.       dup 1 wbpl string put
  109.       cvx bind readonly
  110.     }
  111.    repeat ] def
  112.         % Construct the image dictionary.
  113.    20 dict begin        % image dictionary
  114.      /ImageType 1 def
  115.      /Width w def
  116.      /Height h def
  117.      /ImageMatrix [w 0 0 h neg 0 h] def
  118.      /BitsPerComponent bpp def
  119.      /Decode decode def
  120.      /DataSource dsource dup length 1 gt
  121.       { /MultipleDataSources true def }
  122.       { 0 get }
  123.      ifelse def
  124.    currentdict end
  125.         % Finally, display the image.
  126.    cspace setcolorspace
  127.    image
  128.    showpage
  129.    df closefile
  130.    f closefile
  131.    end
  132.  } bind def
  133.  
  134. % If the program was invoked from the command line, run it now.
  135. [ shellarguments
  136.  { counttomark 1 ge
  137.     { ] { viewpcx } forall
  138.     }
  139.     { cleartomark
  140.       (Usage: gs -- viewpcx.ps filename.pcx ...\n) print
  141.       ( e.g.: gs -- viewpcx.ps my.pcx another.pcx\n) print flush
  142.     }
  143.    ifelse
  144.  }
  145.  { pop
  146.  }
  147. ifelse
  148.