File: viewurf.ps

package info (click to toggle)
ghostscript 10.06.0~dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 96,296 kB
  • sloc: ansic: 944,438; python: 7,917; cpp: 6,534; cs: 6,457; sh: 6,168; java: 4,028; perl: 2,373; tcl: 1,639; makefile: 538; awk: 66; yacc: 18
file content (165 lines) | stat: -rw-r--r-- 4,756 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
% Copyright (C) 2017 Artifex Software, Inc.
% All Rights Reserved.
%
% This software is provided AS-IS with no warranty, either express or
% implied.
%
% This software is distributed under license and may not be copied,
% modified or distributed except as expressly authorized under the terms
% of the license contained in the file LICENSE in this distribution.
%
% Refer to licensing information at http://www.artifex.com or contact
% Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134, San Rafael,
% CA  94903, U.S.A., +1(415)492-9861, for further information.
%

% viewurf.ps
% Display a URF file.

% VURFDEBUG can be predefined to be true to get debugging.
% /VURFDEBUG false def
/VURFDEBUG where { pop } { /VURFDEBUG false def } ifelse

/read1			% <file> read1 <int>
 { read pop
 } bind def
/read2			% <file> read2 <int>
 { dup read1 exch read1 exch 8 bitshift add
 } bind def
/read4			% <file> read2 <int>
 { dup read2 exch read2 exch 16 bitshift add
 } bind def

/readURFheader		% <file> readURFheader <dict>
{ 20 dict begin
  dup 8 string readstring pop
  <554e495241535400> eq not
  { (Not a URF file.\n) print cleartomark stop
  } if
  dup read4 /Pages exch def
  pop
  currentdict end
} bind def

/readURFpageHeader	% <file> readURFpageHeader <dict>
                        % Note: URF header must be on dict stack
{ 10 dict begin
  dup read1 /BitsPerPixel exch def
  dup read1 /ColorSpace exch def
  dup read1 /DuplexMode exch def
  dup read1 /PrintQuality exch def
  dup read1 /MediaType exch def
  dup read1 /InputSlot exch def
  dup read1 /OutputBin exch def
  dup read1 /Copies exch def
  dup read1 /Finishings0 exch def
  dup read1 /Finishings1 exch def
  dup read1 /Finishings2 exch def
  dup read1 /Finishings3 exch def
  dup read4 /Width exch def
  dup read4 /Height exch def
  dup read4 /Resolution exch def
  dup read4 /Reserved0 exch def
  dup read4 /Reserved1 exch def
  pop
  currentdict end
} bind def

/viewURF		% <file|string> viewURF -
{ save 20 dict begin
  /saved exch def
  dup type /stringtype eq { (r) file } if
  /F exch def
  F readURFheader /Header exch def

  % We have a dictionary with /saved, /F and /Header on the stack.

  % Debug dump Header fields.
  VURFDEBUG { Header { exch == == } forall (----------------\n) print flush } if

  {
      % If we have no bytes left, stop
      F bytesavailable 0 le { exit } if

      % Read the page header.
      F readURFpageHeader /PageHeader exch def

      % Push PageHeader onto the dict stack.
      PageHeader begin

      % Debug dump the Page Header.
      VURFDEBUG { PageHeader { exch == == } forall (----------------\n) print flush } if

      % Define D to be the decoded data from F.
      /D F
      <</Width Width
        /BPP BitsPerPixel
        /CMYK ColorSpace 6 eq
      >> /URFDecode filter def

      % Set the Colorspace appropriately.
      ColorSpace dup 0 eq exch 4 eq or
      {%Luminance or DeviceW
        /DeviceGray setcolorspace
        /NumComponents 1 def
      }
      { ColorSpace dup 1 eq exch dup 3 eq exch 5 eq or or
        { % sRGB or AdobeRGB or DeviceRGB
          /DeviceRGB setcolorspace
          /NumComponents 3 def
        }
        { ColorSpace 6 eq
          { % DeviceCMYK
            /DeviceCMYK setcolorspace
            /NumComponents 4 def
          }
          { (Unknown colorspace in URF file.\n) print cleartomark stop
          }
          ifelse
        }
        ifelse
      }
      ifelse

      % Do some matrixy stuff I don't understand.
      matrix currentmatrix
      0 1 3 { 2 copy get dup 0 ne { dup abs div } if 3 copy put pop pop } for
      setmatrix

      <<
        /ImageType 1
        /ImageMatrix [1 0 0 -1 0 Height]
        /BitsPerComponent BitsPerPixel NumComponents div
        %/Decode [0 1] or [0 1 0 1 0 1] or [0 1 0 1 0 1 0 1]
        /Width Width
        /Height Height
        /DataSource D
      >> image

      % Bin the PageHeader dictionary
      end

      showpage
  }
  loop
  saved end restore
} bind def

% This lets you do stuff on the command line like:
% gs -sDEVICE=pdfwrite -o stuff%03d.pdf viewurf.ps -c "(image.urf) << /PageSize 2 index viewURFgetsize 2 array astore  >> setpagedevice viewURF"
% so the output size is influenced by the original image.
%/viewURFgetsize		% <file|string> ==> [width height]
%{
%  save 20 dict begin
%  /saved exch def
%  dup type /stringtype eq { (r) file } if
%  /F exch def
%  F readURFheader /Header exch def
%    currentdict Header end begin begin
%  VURFDEBUG { Header { exch == == } forall (----------------\n) print flush } if
%  F readURFimageHeader /ImageHeader exch def
%    currentdict ImageHeader end begin begin
%  F 0 setfileposition		% reset file pointer
%  Width Height
%  saved end end end restore
%} bind def