1 % Copyright (C) 1998 Aladdin Enterprises. All rights reserved.
3 % This software is provided AS-IS with no warranty, either express or
6 % This software is distributed under license and may not be copied,
7 % modified or distributed except as expressly authorized under the terms
8 % of the license contained in the file LICENSE in this distribution.
10 % For more information about licensing, please refer to
11 % http://www.ghostscript.com/licensing/. For information on
12 % commercial licensing, go to http://www.artifex.com/licensing/ or
13 % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
16 % $Id: viewmiff.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
18 % Display a MIFF file. You would think the 'display' command would do this,
19 % but many versions of 'display' either core-dump or require unacceptably
20 % large amounts of memory.
22 % Recognize MIFF keywords.
24 /class { cvn /class exch def }
25 /colors { cvi /colors exch def }
26 /columns { cvi /Width exch def }
27 /compression { cvn /compression exch def }
28 /depth { cvi /depth exch def }
29 /packets { cvi /packets exch def }
30 /rows { cvi /Height exch def }
31 .dicttomark readonly def
33 % Recognize MIFF image classes.
36 /DeviceRGB setcolorspace
37 /BitsPerComponent depth def
38 /Decode [ 0 1 0 1 0 1 ] def
42 % The MIFF documentation lies about the size of pixels
43 % for this case: the pixel size is determined only by
44 % the number of colors, and is not affected by the image
45 % depth. Specifically, if there are 256 or fewer colors
46 % but the depth (of color map entries) is 16, each pixel
47 % is still only 1 byte, not 2.
48 currentdict /colors known {
49 /DeviceRGB colors 1 sub
50 /BitsPerComponent colors 256 le { 8 } { 16 } ifelse def
51 colors 3 mul string depth 8 eq {
54 % 16-bit color map entries: take only the high-order byte.
55 0 1 2 index length 1 sub {
56 f read pop 2 index 3 1 roll put f read pop pop
62 256 string 0 1 255 { 1 index exch dup put } for
65 /Decode [ 0 1 BitsPerComponent bitshift 1 sub ] def
67 .dicttomark readonly def
69 % Recognize MIFF compression methods.
70 /rlstring 768 string def
72 % packets is not reliable -- disregard it.
73 dup rlstring 0 3 getinterval readstring {
74 pop read pop 3 mul 3 3 2 index {
75 rlstring exch rlstring 0 3 getinterval putinterval
77 rlstring 0 3 -1 roll 3 add getinterval
84 /RunLengthEncoded { { f rlread } }
85 /Zip { [ f /FlateDecode filter cvlit /rlread cvx ] cvx }
86 .dicttomark readonly def
88 % Read a MIFF file and display the image.
89 /viewmiff { % <filename> viewmiff -
95 /class /DirectClass def
96 /compression /Uncompressed def
98 /packets 16#7fffffff def
99 % Read and parse the header.
101 dup (:) eq { pop exit } if
102 dup type /nametype eq {
103 .namestring (=) search {
104 exch pop miffwords exch .knownget { exec } { pop } ifelse
109 pop % probably a comment in braces
112 % Read and display the image.
113 miffclasses class get exec
114 /DataSource miffcompress compression get exec def
115 /ImageMatrix [Width 0 0 Height neg 0 Height] def
116 currentpagedevice /PageSize get
117 dup 0 get exch 1 get scale
118 gsave 0.8 setgray 0 0 1 1 rectfill grestore % provide background