1 % Copyright (C) 1997, 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: gs_dpnxt.ps,v 1.5 2002/08/22 07:12:28 henrys Exp $
18 % NeXT Display PostScript extensions
20 % Define the operation values for compositing. These must match the values
21 % in gsdpnext.h, which also are the ones from the NeXT documentation.
22 % We put them in systemdict, which seems like as good a place as any.
24 /Clear /Copy /Sover /Sin /Sout /Satop /Dover /Din /Dout /Datop /Xor
25 /PlusD /PlusL /Highlight % not sure about Highlight
26 counttomark { counttomark 1 sub def } repeat pop
28 % We implement readimage and sizeimage using the following 3 otherwise
29 % undocumented lower-level operators:
31 % <x> <y> <width> <height> <matrix> .sizeimagebox
32 % <dev_x> <dev_y> <dev_width> <dev_height> <matrix>
34 % - .sizeimageparams <bits/sample> <multiproc> <ncolors>
36 % <device> <x> <y> <width> <max_height> <alpha?> <std_depth|null>
37 % <string> .getbitsrect <height> <substring>
39 % NOTE: These operators are subject to change without notice!
41 % Implement readimage using .getbitsrect. Experimentation on a NeXT system
42 % shows that the data is always returned in order of increasing device Y,
43 % regardless of the CTM.
45 % Note that we can't make stack protection work for this operator,
46 % because it must remove its operands from the stack before calling
47 % the supplied procedure(s).
49 /readimage { % <x> <y> <width> <height> <proc> [... <procN-1>]
50 % <string> <alpha?> readimage -
51 .sizeimageparams exch {
52 % multiproc = true. If N > 1, store the procedures in an array.
53 exch pop 1 index { 1 add } if
54 % Stack: ... string alpha? nprocs
56 pop false % only 1 procedure, multiproc is irrelevant
58 dup array 4 1 roll 3 add 2 roll astore 3 1 roll true
64 % Map the rectangle to device coordinates.
65 % Stack: x y w h proc(s) str alpha? multi?
66 8 -4 roll matrix .sizeimagebox pop 8 4 roll
67 % Make sure we allocate the operand array in local VM
68 % to avoid a possible invalidaccess.
69 .currentglobal false .setglobal 9 1 roll
70 exch { 1 } { 0 } ifelse exch % alpha is last, if present
71 exch 4 1 roll 8 array astore exch .setglobal
72 { % Read out a block of scan lines and pass them to the procedure.
73 % Stack: [x y w h alpha? proc(s) str multi?] -- we must consume this.
74 dup 3 get 0 eq { pop exit } if
75 aload 9 1 roll pop exch pop currentdevice 7 1 roll
76 % Always read out the data as standard (not native) pixels.
77 .sizeimageparams pop pop exch .getbitsrect
78 % Stack: [x y w h alpha? proc(s) str multi?] hread substr
80 % Stack: hread substr [x y w h alpha? proc(s) str multi?]
81 dup 1 2 copy get 5 index add put
82 % Stack: hread substr [x y' w h alpha? proc(s) str multi?]
83 dup 3 2 copy get 6 -1 roll sub put
84 % Stack: substr [x y' w h' alpha? proc(s) str multi?]
85 dup 5 get exch 7 get {
86 % multiproc = true, pass each plane to a different procedure.
88 0 1 2 index length 1 sub {
89 % Push 1 plane and its procedure under the top 2 elements.
90 % Stack: ... substr procs plane#
91 2 index length 2 index length idiv % bytes per plane
93 % Stack: ... substr procs plane# start length
94 4 index 3 1 roll getinterval 4 1 roll
95 2 copy get 4 1 roll pop
97 exch pop length 2 mul .execn
99 % multiproc = false, just call the procedure.
102 } //systemdict /exec get 3 packedarray cvx loop
106 % <w> <h> <bpc> <mtx> <dsrc0> ... <multi> <ncomp> alphaimage -
112 currentglobal true setglobal
118 { /alphaimage load $error /errorname get signalerror }
121 .bind systemdict begin odef end
127 % Implement sizeimage using lower-level operators.
129 /sizeimage { % <x> <y> <width> <height> <matrix> sizeimage
130 % <devwidth> <devheight> <bits/sample> <matrix>
131 % <multiproc> <ncolors>
132 .sizeimagebox 5 -2 roll pop pop
133 .sizeimageparams 3 -1 roll 4 1 roll