386BSD 0.1 development
[unix-history] / usr / othersrc / public / ghostscript-2.4.1 / showpbm.ps
CommitLineData
1024c664
WJ
1% Copyright (C) 1992 Aladdin Enterprises. All rights reserved.
2% Distributed by Free Software Foundation, Inc.
3%
4% This file is part of Ghostscript.
5%
6% Ghostscript is distributed in the hope that it will be useful, but
7% WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
8% to anyone for the consequences of using it or for whether it serves any
9% particular purpose or works at all, unless he says so in writing. Refer
10% to the Ghostscript General Public License for full details.
11%
12% Everyone is granted permission to copy, modify and redistribute
13% Ghostscript, but only under the conditions described in the Ghostscript
14% General Public License. A copy of this license is supposed to have been
15% given to you along with Ghostscript so you can know your rights and
16% responsibilities. It should be in a file named COPYING. Among other
17% things, the copyright notice and this notice must be preserved on all
18% copies.
19
20% showpbm.ps
21% Display a PBM/PGM/PPM file. Currently only handles "raw" formats (P4-P6).
22
23/s 100 string def
24/readmaxv
25 { f s readline pop cvx exec /maxv exch def
26 } def
27/pdict 6 dict def
28pdict begin
29 /P1 [ { /rsize w 7 add 8 idiv def }
30 { }
31 ] def
32 /P2 [ { readmaxv /rsize w def }
33 { }
34 ] def
35 /P3 [ { readmaxv /rsize w 3 mul def }
36 { }
37 ] def
38 /P4 [ { /rsize w 7 add 8 idiv def }
39 { true exch { f row readstring pop } imagemask }
40 ] def
41 /P5 [ { readmaxv /rsize w def }
42 { 8 exch { f row readstring pop } image }
43 ] def
44 /P6 [ { readmaxv /rsize w 3 mul def }
45 { 8 exch { f row readstring pop } false 3 colorimage }
46 ] def
47end
48/showpbm % filename ->
49 { (r) file /f exch def
50 f s readline pop cvn /pn exch def % Pn
51 f s readline pop % check for comment
52 (#) anchorsearch
53 { pop pop f s readline pop }
54 if
55 cvx exec /h exch def /w exch def
56 pdict pn get dup /rprocs exch def
57 0 get exec
58 /row rsize string def
59 [1 0 0 -1 0 h] setmatrix
60 erasepage
61 0 setgray
62 w h [1 0 0 -1 0 h] rprocs 1 get exec
63 showpage
64 } def
65
66% If the program was invoked from the command line, run it now.
67[ shellarguments
68 { counttomark 1 eq
69 { showpbm
70 }
71 { cleartomark
72 (Usage: showpbm filename.p*m\n) print
73 ( e.g.: showpbm my.ppm\n) print flush
74 mark
75 }
76 ifelse
77 }
78if pop