home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / viewmiff.ps < prev    next >
Text File  |  2002-02-22  |  4KB  |  125 lines

  1. %    Copyright (C) 1998 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: viewmiff.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
  14. % viewmiff.ps
  15. % Display a MIFF file.  You would think the 'display' command would do this,
  16. % but many versions of 'display' either core-dump or require unacceptably
  17. % large amounts of memory.
  18.  
  19. % Recognize MIFF keywords.
  20. /miffwords mark
  21.   /class { cvn /class exch def }
  22.   /colors { cvi /colors exch def }
  23.   /columns { cvi /Width exch def }
  24.   /compression { cvn /compression exch def }
  25.   /depth { cvi /depth exch def }
  26.   /packets { cvi /packets exch def }
  27.   /rows { cvi /Height exch def }
  28. .dicttomark readonly def
  29.  
  30. % Recognize MIFF image classes.
  31. /miffclasses mark
  32.   /DirectClass {
  33.     /DeviceRGB setcolorspace
  34.     /BitsPerComponent depth def
  35.     /Decode [ 0 1 0 1 0 1 ] def
  36.   }
  37.   /PseudoClass {
  38.     [ /Indexed
  39.         % The MIFF documentation lies about the size of pixels
  40.         % for this case: the pixel size is determined only by
  41.         % the number of colors, and is not affected by the image
  42.         % depth.  Specifically, if there are 256 or fewer colors
  43.         % but the depth (of color map entries) is 16, each pixel
  44.         % is still only 1 byte, not 2.
  45.       currentdict /colors known {
  46.     /DeviceRGB colors 1 sub
  47.     /BitsPerComponent colors 256 le { 8 } { 16 } ifelse def
  48.     colors 3 mul string depth 8 eq {
  49.       f exch readstring pop
  50.     } {
  51.         % 16-bit color map entries: take only the high-order byte.
  52.       0 1 2 index length 1 sub {
  53.         f read pop 2 index 3 1 roll put f read pop pop
  54.       } for
  55.     } ifelse
  56.       } {
  57.     /colors 256 def
  58.     /DeviceGray 255
  59.     256 string 0 1 255 { 1 index exch dup put } for
  60.       } ifelse
  61.     ] setcolorspace
  62.     /Decode [ 0 1 BitsPerComponent bitshift 1 sub ] def
  63.   }
  64. .dicttomark readonly def
  65.  
  66. % Recognize MIFF compression methods.
  67. /rlstring 768 string def
  68. /rlread {
  69.         % packets is not reliable -- disregard it.
  70.   dup rlstring 0 3 getinterval readstring {
  71.     pop read pop 3 mul 3 3 2 index {
  72.       rlstring exch rlstring 0 3 getinterval putinterval
  73.     } for
  74.     rlstring 0 3 -1 roll 3 add getinterval
  75.   } {
  76.     pop pop ()
  77.   } ifelse
  78. } bind def
  79. /miffcompress mark
  80.   /Uncompressed { f }
  81.   /RunLengthEncoded { { f rlread } }
  82.   /Zip { [ f /FlateDecode filter cvlit /rlread cvx ] cvx }
  83. .dicttomark readonly def
  84.  
  85. % Read a MIFF file and display the image.
  86. /viewmiff {        % <filename> viewmiff -
  87.   50 dict begin
  88.   /fname 1 index def
  89.   /f exch (r) file def
  90.         % Set defaults.
  91.   /ImageType 1 def
  92.   /class /DirectClass def
  93.   /compression /Uncompressed def
  94.   /depth 8 def
  95.   /packets 16#7fffffff def
  96.         % Read and parse the header.
  97.   { f token pop
  98.     dup (:) eq { pop exit } if
  99.     dup type /nametype eq {
  100.       .namestring (=) search {
  101.     exch pop miffwords exch .knownget { exec } { pop } ifelse
  102.       } {
  103.     pop    % who knows?
  104.       } ifelse
  105.     } {
  106.       pop    % probably a comment in braces
  107.     } ifelse
  108.   } loop
  109.         % Read and display the image.
  110.   miffclasses class get exec
  111.   /DataSource miffcompress compression get exec def
  112.   /ImageMatrix [Width 0 0 Height neg 0 Height] def
  113.   currentpagedevice /PageSize get
  114.     dup 0 get exch 1 get scale
  115.   gsave 0.8 setgray 0 0 1 1 rectfill grestore    % provide background
  116.   currentdict image
  117.   showpage
  118.         % Clean up.
  119.   f closefile
  120.   end
  121. } bind def
  122.