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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <gset.h>
include <gki.h>
include <imhdr.h>
include "cv.h"
include "../lib/ids.h"
# CVUTIL -- utility control routines for cv package
############ CLEAR display ############
# CVCLEARG -- clear all of graphics (bit) planes
procedure cvclearg (frame, color)
short frame[ARB]
short color[ARB]
int count
int cv_move()
include "cv.com"
begin
count = cv_move (frame, Mems[cv_stack])
count = count + cv_move (color, Mems[cv_stack+count])
call gescape (cv_gp, IDS_SET_GP, Mems[cv_stack], count)
call gclear (cv_gp)
end
# CVCLEARI -- clear specified image frames
procedure cvcleari (frames)
short frames[ARB]
include "cv.com"
begin
call cv_iset (frames)
call gclear (cv_gp)
end
############ CURSOR and BUTTON ############
# CV_RDBUT -- read button on trackball (or whatever)
# if none pressed, will get zero back
int procedure cv_rdbut()
int oldcnum
real x, y
int button
int gstati
include "cv.com"
begin
oldcnum = gstati (cv_gp, G_CURSOR)
call gseti (cv_gp, G_CURSOR, IDS_BUT_RD)
call ggcur (cv_gp, x, y, button)
call gseti (cv_gp, G_CURSOR, oldcnum)
return(button)
end
# CV_WTBUT -- wait for button to be pressed, then read it
int procedure cv_wtbut()
int oldcnum
real x, y
int button
int gstati
include "cv.com"
begin
oldcnum = gstati (cv_gp, G_CURSOR)
call gseti (cv_gp, G_CURSOR, IDS_BUT_WT)
call ggcur (cv_gp, x, y, button)
call gseti (cv_gp, G_CURSOR, oldcnum)
return(button)
end
# CV_RCUR -- read cursor. The cursor read/set routines do not restore
# the cursor number...this to avoid numerous stati/seti calls that
# usually are not needed.
procedure cv_rcur (cnum, x, y)
int cnum
real x,y
int junk
include "cv.com"
begin
call gseti (cv_gp, G_CURSOR, cnum)
call ggcur (cv_gp, x, y, junk)
end
# CV_SCUR -- set cursor
procedure cv_scur (cnum, x, y)
int cnum
real x,y
include "cv.com"
begin
call gseti (cv_gp, G_CURSOR, cnum)
call gscur (cv_gp, x, y)
end
# CV_RCRAW -- read the raw cursor (return actual screen coordinates).
procedure cv_rcraw (x, y)
real x,y
include "cv.com"
begin
call cv_rcur (IDS_CRAW, x, y)
end
# CV_SCRAW -- set raw cursor
procedure cv_scraw (x, y)
real x,y
include "cv.com"
begin
call cv_scur (IDS_CRAW, x, y)
end
# cvcur -- turn cursor on or off
procedure cvcur (instruction)
int instruction
include "cv.com"
begin
Mems[cv_stack] = IDS_CURSOR
Mems[cv_stack+1] = IDS_WRITE
Mems[cv_stack+2] = 1
Mems[cv_stack+3] = IDS_EOD
Mems[cv_stack+4] = IDS_EOD
Mems[cv_stack+5] = 1
Mems[cv_stack+6] = instruction
call gescape (cv_gp, IDS_CONTROL, Mems[cv_stack], 7)
end
############ DISPLAY ############
# cvdisplay
procedure cvdisplay (instruction, device, frame, color, quad)
int instruction
int device
short frame, color, quad
int i
int cv_move()
include "cv.com"
begin
Mems[cv_stack] = instruction
i = cv_move (frame, Mems[cv_stack+1])
i = i + cv_move (color, Mems[cv_stack+1+i])
i = i + cv_move (quad, Mems[cv_stack+1+i])
call gescape (cv_gp, device, Mems[cv_stack], 1+i)
end
############ MATCH ############
# cvmatch -- build match escape sequence
procedure cvmatch (lt, fr, cr, frames, color)
int lt # type
short fr[ARB] # reference frame and color
short cr[ARB]
short frames[ARB] # frames to be changed
short color[ARB] # and colors
int count, n
int cv_move()
include "cv.com"
begin
Mems[cv_stack] = IDS_MATCH
Mems[cv_stack+1] = lt
count = cv_move (fr, Mems[cv_stack+3])
count = count + cv_move (cr, Mems[cv_stack+3+count])
n = count
Mems[cv_stack+count+3] = 0 # unused offset
count = count + cv_move (frames, Mems[cv_stack+4+count])
count = count + cv_move (color, Mems[cv_stack+4+count])
Mems[cv_stack+2] = count - n
call gescape (cv_gp, IDS_CONTROL, Mems[cv_stack], count+4)
end
############ OFFSET ############
# cvoffset -- set offset registers
procedure cvoffset( color, data)
short color[ARB]
short data[ARB]
int count, cv_move()
int i
include "cv.com"
begin
Mems[cv_stack] = IDS_OUT_OFFSET
Mems[cv_stack+1] = IDS_WRITE
Mems[cv_stack+3] = IDS_EOD # no-op the frames slot
count = cv_move (color, Mems[cv_stack+4])
Mems[cv_stack+4+count] = 1 # (unused) offset
i = cv_move (data, Mems[cv_stack+5+count])
i = i - 1 # don't include EOD of "data"
Mems[cv_stack+2] = i
call gescape (cv_gp, IDS_CONTROL, Mems[cv_stack], i+count+5)
end
############ PAN ############
# cvpan -- move the image(s) around
# The x,y coordinates are NDC that, it is assumed, came from a cursor
# read, and therefore are of the form
# ((one_based_pixel-1)/(resolution)) *(GKI_MAXNDC+1) / GKI_MAXNDC
# The division by GKI_MAXNDC turns into NDC what was GKI ranging from
# 0 through 511*64 (for IIS) which conforms to the notion of specifying
# each pixel by its left/bottom GKI boundary.
procedure cvpan (frames, x, y)
short frames[ARB]
real x,y # position in NDC
int count, cv_move()
include "cv.com"
begin
Mems[cv_stack] = IDS_SCROLL
Mems[cv_stack+1] = IDS_WRITE
Mems[cv_stack+2] = 3
count = cv_move (frames, Mems[cv_stack+3])
Mems[cv_stack+3+count] = IDS_EOD # all colors
Mems[cv_stack+4+count] = 1 # (unused) offset
Mems[cv_stack+5+count] = x * GKI_MAXNDC
Mems[cv_stack+6+count] = y * GKI_MAXNDC
Mems[cv_stack+7+count] = IDS_EOD # for all frames
call gescape (cv_gp, IDS_CONTROL, Mems[cv_stack], count+8)
end
############ RANGE ############
# cvrange -- scale ouput before final look up table
procedure cvrange ( color, range)
short color[ARB]
short range[ARB]
int cv_move(), count, i
include "cv.com"
begin
Mems[cv_stack] = IDS_RANGE
Mems[cv_stack+1] = IDS_WRITE
Mems[cv_stack+3] = IDS_EOD # all frames
count = cv_move (color, Mems[cv_stack+4])
Mems[cv_stack+4+count] = 1 # (unused) offset
i = cv_move (range, Mems[cv_stack+5+count])
i = i - 1 # don't include EOD of "range"
Mems[cv_stack+2] = i
call gescape (cv_gp, IDS_CONTROL, Mems[cv_stack], i+count+5)
end
############ RESET display ############
# cvreset -- reset display
# SOFT -- everything but lookup tables and image/graphics planes
# MEDIUM -- everything but image/graphics planes
# HARD -- everything...planes are cleared, all images OFF
procedure cvreset (hardness)
int hardness
include "cv.com"
begin
Mems[cv_stack] = hardness
call gescape (cv_gp, IDS_RESET, Mems[cv_stack], 1)
end
############ SNAP a picture ############
# cvsnap -- takes a full picture of image display
procedure cvsnap (fname, snap_color)
char fname[ARB] # image file name
int snap_color
pointer im, immap(), impl2s()
int i, factor
real y
include "cv.com"
begin
im = immap(fname, NEW_FILE, 0)
IM_PIXTYPE(im) = TY_SHORT
IM_LEN(im,1) = cv_xres
IM_LEN(im,2) = cv_yres
Mems[cv_stack] = IDS_SNAP
Mems[cv_stack+1] = IDS_WRITE
Mems[cv_stack+2] = 1 # frame, color are not relevant
Mems[cv_stack+3] = IDS_EOD
Mems[cv_stack+4] = IDS_EOD
Mems[cv_stack+5] = 0
Mems[cv_stack+6] = snap_color
call gescape (cv_gp, IDS_CONTROL, Mems[cv_stack], 7)
factor = cv_yres/10 + 1
call eprintf (" (%% done: ")
call flush (STDERR)
do i = 0, cv_yres-1 {
if ( mod(i,factor) == 0) {
call eprintf ("%d ")
call pargi (int(10*i/cv_yres)*10)
call flush (STDERR)
}
y = real(i)*cv_ycon / GKI_MAXNDC.
call ggcell (cv_gp, Mems[impl2s(im,i+1)], cv_xres, 1, 0.0,
y, 1.0, y)
}
call eprintf ("100)\n")
call imunmap(im)
Mems[cv_stack] = IDS_R_SNAPDONE
call gescape (cv_gp, IDS_RESET, Mems[cv_stack], 1)
end
############ SPLIT ############
# cvsplit -- set split screen position
procedure cvsplit (x, y)
real x,y # NDC coordinates
include "cv.com"
begin
Mems[cv_stack] = IDS_SPLIT
Mems[cv_stack+1] = IDS_WRITE
Mems[cv_stack+2] = 2
Mems[cv_stack+3] = IDS_EOD # no-op frame and color
Mems[cv_stack+4] = IDS_EOD
Mems[cv_stack+5] = 1 # (unused) offset
# NOTE multiplacation by MAXNDC+1 ... x, and y, are never == 1.0
# ( see split.x)
# and truncation effects will work out just right, given what the
# image display kernel does with these numbers
Mems[cv_stack+6] = x * (GKI_MAXNDC+1)
Mems[cv_stack+7] = y * (GKI_MAXNDC+1)
call gescape (cv_gp, IDS_CONTROL, Mems[cv_stack], 8)
end
############ TEXT ############
# Write text
procedure cvtext (x, y, text, size)
real x, y, size
char text[ARB]
char format[SZ_LINE]
include "cv.com"
begin
call sprintf (format, SZ_LINE, "s=%f")
call pargr (size)
call gtext (cv_gp, x, y, text, format)
end
############ WHICH ############
# Tell which frames are one. The best we can do now is
# tell if any, and if so, which is the "first"
procedure cvwhich (fr)
short fr[ARB]
real x,y
int cnum, oldcnum
int gstati
include "cv.com"
begin
# Use here the fact that if cursor number is zero, the
# kernel will return the number of the first displayed
# frame, or "ERR" if none.
oldcnum = gstati (cv_gp, G_CURSOR)
cnum = 0
call gseti (cv_gp, G_CURSOR, cnum)
call ggcur (cv_gp, x, y, cnum)
call gseti (cv_gp, G_CURSOR, oldcnum)
fr[1] = cnum
fr[2] = IDS_EOD
end
############ WLUT ############
# cvwlut ... change lookup tables
# the data is in form of line endpoints.
procedure cvwlut (device, frames, color, data, n)
int device
short frames[ARB]
short color[ARB]
short data[ARB]
int n
int count, cv_move()
include "cv.com"
begin
# Device had better refer to a look-up table, or who knows
# what will happen!
Mems[cv_stack] = device
Mems[cv_stack+1] = IDS_WRITE
Mems[cv_stack+2] = n
count = cv_move (frames, Mems[cv_stack+3])
count = count + cv_move (color, Mems[cv_stack+3+count])
Mems[cv_stack+3+count] = 1 # (unused) offset
call amovs (data, Mems[cv_stack+count+4],n)
call gescape (cv_gp, IDS_CONTROL, Mems[cv_stack], n+count+4)
end
############ ZOOM ############
# cvzoom -- zoom the image
# See comment under PAN about x and y.
procedure cvzoom (frames, power, x, y)
short frames[ARB]
int power
real x,y
int count, cv_move()
include "cv.com"
begin
Mems[cv_stack] = IDS_ZOOM
Mems[cv_stack+1] = IDS_WRITE
Mems[cv_stack+2] = 3
count = cv_move (frames, Mems[cv_stack+3])
Mems[cv_stack+3+count] = IDS_EOD # (unused) color
Mems[cv_stack+4+count] = IDS_EOD # (unused) offset
Mems[cv_stack+5+count] = power
Mems[cv_stack+6+count] = x * GKI_MAXNDC
Mems[cv_stack+7+count] = y * GKI_MAXNDC
call gescape (cv_gp, IDS_CONTROL, Mems[cv_stack], count+8)
end
############ SUBROUTINES ##############
# CV_MOVE -- transfer an array into the escape data array; returns number
# of items transfered.
int procedure cv_move (in, out)
short in[ARB]
short out[ARB]
int count
begin
count = 0
repeat {
count = count + 1
out[count] = in[count]
} until (in[count] == IDS_EOD)
return (count)
end
# CV_ISET -- Tell the image kernel that i/o is to be done for the
# specified frame/frames.
procedure cv_iset (frames)
short frames[ARB]
short idata[30]
int i, cv_move()
include "cv.com"
begin
i = cv_move (frames, idata)
idata[i+1] = IDS_EOD # all bit planes
call gescape (cv_gp, IDS_SET_IP, idata, i+1)
end
# CV_GSET -- Tell the image kernel that i/o is to be done for the
# specified colors.
procedure cv_gset (colors)
short colors[ARB]
short idata[30]
int i, cv_move()
include "cv.com"
begin
idata[1] = IDS_EOD # all "frames"
i = cv_move (colors, idata[2])
call gescape (cv_gp, IDS_SET_GP, idata, i+1)
end
|