Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

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