aboutsummaryrefslogtreecommitdiff
path: root/pkg/images/tv/iis/src/map.x
blob: 5ea7c2302531fd1281345f8af47e225aa6a66cf7 (plain) (blame)
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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<ctotok.h>
include	<ctype.h>
include	<gki.h>
include	"../lib/ids.h"

# MAP -- set fixed or variable LUT mapping

procedure map(command)

char	command[ARB]

char	token[SZ_LINE]
int	tok
short	frames[IDS_MAXIMPL+2]			# frames, graphics, EOD
short	colors[IDS_MAXGCOLOR]
int	device
short	pcolor[2]
real	limit
long	seed
real	urand(), xfactor
int	ctoi()
int	i, ip, iseed, level, nchar
bool	triangle
pointer	sp, rdata, gdata, bdata, rp, gp, bp

include "cv.com"

begin
	# Find out if want to change output tables
	call gargtok (tok, token, SZ_LINE)
	call strlwr (token)
	if (( tok == TOK_IDENTIFIER) && (token[1] == 'o' )) {
	        device = IDS_OUTPUT_LUT
	} else {
	    device = IDS_FRAME_LUT
	    # reset input pointers; same as having pushed back token
	    call reset_scan
	    call gargtok (tok, token, SZ_LINE)
	}

	# Default to all frames, all colors
	frames[1] = IDS_EOD
	colors[1] = IDS_EOD
	triangle = true		# default to simple three function type
	seed = -1
	level = 8

	# which frames to change, colors, etc

	repeat {
	    call gargtok (tok, token, SZ_LINE)
	    call strlwr (token)
	    if (tok == TOK_IDENTIFIER) {
	        if (token[1] == 'f') {
	            call cv_frame (token[2], frames)
	            if (frames[1] == ERR)
		        return
	        } else if (token[1] == 'c') {
		    call cv_color (token[2], colors)
		    if (colors[1] == ERR)
		        return
		} else if (token[1] == 'r') {	# (random) level count
		    ip = 2
		    nchar = ctoi (token, ip, level)
		    if (nchar <= 0) {
			call eprintf ("Incorrect random count: %s\n")
			    call pargstr (token[2])
			return
		    }
		    if (level < 4)
			level = 4
		    else if (level > 128)
			level = 128
		    triangle = false
		} else if (token[1] == 's') {	# seed
		    ip = 2
		    nchar = ctoi (token, ip, iseed)
		    if (nchar <= 0) {
			call eprintf ("Incorrect seed: %s\n")
			    call pargstr (token[2])
			return
		    }
		    seed = iseed
		    triangle = false
	        } else {
		    call eprintf ("Unknown map argument: %s\n")
			call pargstr (token)
		    return
		}
	    } else if (tok != TOK_NEWLINE) {
		call eprintf ("Unexpected map input: %s\n")
		    call pargstr (token)
		return
	    }
	} until ( tok == TOK_NEWLINE)

	pcolor[2] = IDS_EOD
	# Sorry, but we "know" that ofm shouldn't go beyond first
	# 256 for common NOAO use.
	if ( device == IDS_FRAME_LUT)
	    limit = 1.0
	else
	    limit = 0.25

	# Build the three functions and load them.
	# First, expand colors if using all

	if (colors[1] == IDS_EOD) {
	    colors[1] = IDS_RED
	    colors[2] = IDS_GREEN
	    colors[3] = IDS_BLUE
	    colors[4] = IDS_EOD
	}

	# if standard pseudocolor, let kodak do it

	if (triangle) {
	    call kodak (device, frames, colors, limit)
	    return
	}

	# Not standard pseudo color -- do random one
	# First, set up arrays

	call smark (sp)
	call salloc (rdata, level*4, TY_SHORT)
	call salloc (gdata, level*4, TY_SHORT)
	call salloc (bdata, level*4, TY_SHORT)

	if (seed == -1)
	    seed = level

	call aclrs (Mems[rdata], level*4)
	call aclrs (Mems[gdata], level*4)
	call aclrs (Mems[bdata], level*4)

	xfactor = real(GKI_MAXNDC)/level * limit

	# set first data points to zero (0,0) to (1/level,0)
	Mems[rdata+2] = xfactor
	Mems[gdata+2] = xfactor
	Mems[bdata+2] = xfactor
	# Set last segment to white ((level-1)/level,1.0) to (1.0,1.0)
	Mems[rdata+level*4-4] = real(level-1) * xfactor
	Mems[gdata+level*4-4] = real(level-1) * xfactor
	Mems[bdata+level*4-4] = real(level-1) * xfactor
	Mems[rdata+level*4-3] = GKI_MAXNDC
	Mems[gdata+level*4-3] = GKI_MAXNDC
	Mems[bdata+level*4-3] = GKI_MAXNDC
	Mems[rdata+level*4-2] = GKI_MAXNDC
	Mems[gdata+level*4-2] = GKI_MAXNDC
	Mems[bdata+level*4-2] = GKI_MAXNDC
	Mems[rdata+level*4-1] = GKI_MAXNDC
	Mems[gdata+level*4-1] = GKI_MAXNDC
	Mems[bdata+level*4-1] = GKI_MAXNDC

	# Do the intermediate ones
	do i=2, level-1 {
	    rp = rdata + (i-1)*4
	    gp = gdata + (i-1)*4
	    bp = bdata + (i-1)*4
	    Mems[rp] = real(i-1) * xfactor
	    Mems[gp] = real(i-1) * xfactor
	    Mems[bp] = real(i-1) * xfactor
	    Mems[rp+1] = urand(seed) * GKI_MAXNDC
	    Mems[gp+1] = urand(seed) * GKI_MAXNDC
	    Mems[bp+1] = urand(seed) * GKI_MAXNDC
	    Mems[rp+2] = real(i) * xfactor
	    Mems[gp+2] = real(i) * xfactor
	    Mems[bp+2] = real(i) * xfactor
	    Mems[rp+3] = Mems[rp+1]
	    Mems[gp+3] = Mems[gp+1]
	    Mems[bp+3] = Mems[bp+1]
	}

	# If color requested, do it
	for ( i = 1; colors[i] != IDS_EOD; i = i + 1 ) {
	    pcolor[1] = colors[i]
	    switch (colors[i]) {
		case IDS_RED:
	    	    call cvwlut (device, frames, pcolor, Mems[rdata], level*4)

		case IDS_GREEN:
	    	    call cvwlut (device, frames, pcolor, Mems[gdata], level*4)

		case IDS_BLUE:
	    	    call cvwlut (device, frames, pcolor, Mems[bdata], level*4)
	    }
	}

	call sfree (sp)
end

# KODAK -- provides three variable width and variable center triangular
# color mapping functions.

procedure kodak (device, frames, colors, limit)

int	device				# IDS_FRAME_LUT or IDS_OUTPUT_LUT
short	frames[ARB]			# frames to change
short	colors[ARB]			# colors to affect
real	limit				# factor to apply to limit x range

short	wdata[20], pcolor[2]
real	center, width
int	n, ksub(), button, i
int	cv_rdbut(), cv_wtbut()

begin
	pcolor[2] = IDS_EOD
	for (i = 1; colors[i] != IDS_EOD; i = i + 1) {
	    pcolor[1] = colors[i]
	    switch (colors[i]) {
		case IDS_RED:
		    n = ksub (1.0, 0.5, wdata, limit)

		case IDS_GREEN:
		    n = ksub (0.5, 0.5, wdata, limit)

		case IDS_BLUE:
		    n = ksub (0.0, 0.5, wdata, limit)
	    }

	    call cvwlut (device, frames, pcolor, wdata, n)
	}

	button = cv_rdbut()		# clear buttons
	repeat {
	    call eprintf ("Press A, B, C for red, green, blue; D to exit\n")
	    button = cv_wtbut()
	    if (button == 4)
		break
	    switch (button) {
		case 1:
	    	    pcolor[1] = IDS_RED

		case 2:
	    	    pcolor[1] = IDS_GREEN

		case 3:
	    	    pcolor[1] = IDS_BLUE
	    }
	    
	    # Loop, reading cursor and modifying the display for the
	    # selected color.

	    repeat {
		call cv_rcraw(center, width)
		width = width * 2.		# flatten it
		n = ksub (center, width, wdata, limit)
		call cvwlut (device, frames, pcolor, wdata, n)
		button = cv_rdbut()
	    } until (button != 0)
	}
end

# KSUB -- determines data points for a triangular mapping function
# Returns number of points in data array.

int procedure ksub (center, width, data, limit)

real	center, width, limit
short	data[ARB]

int	n
real	xs, xe, ys, ye, xscale

include "cv.com"

begin
	n = 0
	xscale = GKI_MAXNDC * limit
	if (width < (1.0/cv_yres))
	    width = 1.0/cv_yres
	
	if (center > 0.) {
	    xs = center - width
	    if (xs < 0.)
		xs = 0.
	    else if (xs > 0.) {
		data[1] = 0.
		data[2] = 0.
		n = n + 2
	    }
	    ys = (xs - center)/width + 1.0
	    data[n+1] = xs * xscale
	    data[n+2] = ys * GKI_MAXNDC
	    data[n+3] = center * xscale
	    data[n+4] = GKI_MAXNDC
	    n = n + 4
	}

	if (center < 1.0) {
	    xe = width + center
	    if (xe > 1.0)
		xe = 1.0
	    ye = (center - xe)/width + 1.0
	    data[n+1] = center * xscale
	    data[n+2] = GKI_MAXNDC
	    data[n+3] = xe * xscale
	    data[n+4] = ye * GKI_MAXNDC
	    n = n + 4
	    if (xe < 1.0) {
		data[n+1] = xscale
		data[n+2] = 0
		n = n + 2
	    }
	}

	# Extend last value to end
	if (limit != 1.0) {
	    data[n+1] = GKI_MAXNDC
	    data[n+2] = data[n]
	    n = n + 2
	}

	return (n)
end