summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlgs/lib/viewrgb.ps
blob: c2c34fec635a8df6d5276de0852d184f33332300 (plain)
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
% Copyright (C) 2001-2021 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.,  1305 Grant Avenue - Suite 200, Novato,
% CA 94945, U.S.A., +1(415)492-9861, for further information.
%


% viewrgb.ps
% Display a raw RGB file created by  -sDEVICE=bitrgb.
% If SCALE is defined, maps input pixels to output pixels with that scale;
% if SCALE is undefined, scales the image to fit the page.
% If BITS is defined, it is the number of bits per sample (1,2,8,12).
% NB: BITS=4 (corresponding to -dGrayValues=16) is not supported.
% if BITS is undefined, its default value is 1.

/viewrgb {			% <filename> <width> viewrgb -
  20 dict begin
  /w exch def
  /fname exch def
  /bpc /BITS where { pop BITS } { 1 } ifelse def
  /f fname (r) file def
  mark fname status pop pop pop /flen exch def cleartomark
  /h flen
  w [ 0 4 8 0 0 0 0 0 24 ] bpc get
  dup 0 eq {
    (*** -dBITS=) print bpc =print ( is not supported. ***) = flush
    quit
  } if
  mul 7 add 8 idiv idiv def
  QUIET not { (Dimensions: ) print [w h] == flush } if
                % Set up scaling.
  /SCALE where {
    pop
        % Map pixels SCALE-for-1.  Assume orthogonal transformation.
    SCALE 1 0 dtransform add abs div
    SCALE 0 1 dtransform add abs div
  } {
        % Scale the image (uniformly) to fit the page.
    clippath pathbbox pop pop translate
    pathbbox 3 -1 roll sub h div
    3 1 roll exch sub w div .min dup
  } ifelse scale
  bpc 1 eq {
    [ /Indexed /DeviceRGB 15 <
        000000
        0000FF
        00FF00
        00FFFF
        FF0000
        FF00FF
        FFFF00
        FFFFFF
        000000
        0000FF
        00FF00
        00FFFF
        FF0000
        FF00FF
        FFFF00
        FFFFFF
      >
    ] setcolorspace
    /BPC 4 def			% change to 4 bit indexed
  } {
    bpc 2 eq {
    [ /Indexed /DeviceRGB 255 <
        000000 000055 0000AA 0000FF
        005500 005555 0055AA 0055FF
        00AA00 00AA55 00AAAA 00AAFF
        00FF00 00FF55 00FFAA 00FFFF
        550000 550055 5500AA 5500FF
        555500 555555 5555AA 5555FF
        55AA00 55AA55 55AAAA 55AAFF
        55FF00 55FF55 55FFAA 55FFFF
        AA0000 AA0055 AA00AA AA00FF
        AA5500 AA5555 AA55AA AA55FF
        AAAA00 AAAA55 AAAAAA AAAAFF
        AAFF00 AAFF55 AAFFAA AAFFFF
        FF0000 FF0055 FF00AA FF00FF
        FF5500 FF5555 FF55AA FF55FF
        FFAA00 FFAA55 FFAAAA FFAAFF
        FFFF00 FFFF55 FFFFAA FFFFFF

        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000

        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000

        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000

        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
        000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
      >
    ] setcolorspace
    /BPC 8 def			% change to 4 bit indexed
    } {
      /DeviceRGB setcolorspace
      /BPC bpc def
    }
    ifelse
  }
  ifelse
  << 	/ImageType 1
        /Width w
        /Height h
        /BitsPerComponent BPC
        /ImageMatrix [1 0 0 -1 0 h]
        /DataSource f
        /MultipleDataSources false
        bpc 4 lt { /Decode [ 0 [ 0 15 255 ] bpc get ] } { /Decode [ 0 1 0 1 0 1 ] } ifelse
  >> image
  showpage
  f closefile
  end
} bind def

% If the program was invoked from the command line, run it now.
[ .shellarguments {
  counttomark 2 eq {
    cvi viewrgb
  } {
    cleartomark
    (\nUsage: gs -- viewrgb.ps filename.rgb width\n) print
    ( e.g.: gs -- viewrgb.ps my.rgb 2550\n) print flush
    (  -dSCALE=### sets specific scaling \(default = 1.0\)) = flush
    (  -dBITS=# sets the BitsPerComponent \(1, 2, 8, 12] \(default = 1\)) = flush
    (From version 9.50 you must supply permissions for this program to read the input file(s)\n) print flush
    (either by using -dNOSAFER or by supplying --permit-file-read=<filename>\n) = flush
  } ifelse
} {
  pop
} ifelse