aboutsummaryrefslogtreecommitdiff
path: root/sys/pmio/pmglr.gx
blob: 9c2e2606f984cc3a4d756e20fa5863ce3e842efe (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<imhdr.h>
include	<pmset.h>
include	<plio.h>

# PM_GLR -- Get a line segment as a range list, applying the given ROP to
# combine the pixels with those of the output line list.  Note that this
# operator uses IMIO if a section transformation is needed, hence if the 
# application also uses IMIO to directly access the mask image, care must
# be taken to avoid confusion over the use of IMIO allocated pixel buffers.

procedure pm_glr$t (pl, v, rl_dst, rl_depth, npix, rop)

pointer	pl			#I mask descriptor
long	v[PL_MAXDIM]		#I vector coords of line segment
PIXEL	rl_dst[3,ARB]		#O output line list
int	rl_depth		#I line list depth, bits
int	npix			#I number of pixels desired
int	rop			#I rasterop

int	rl_len, temp, step, xstep, np
pointer	sp, px_src, rl_src, rl_out, im
include	"../pmio.com"
int	pl_p2r$t()

begin
	im = PM_REFIM(pl)
	if (PM_MAPXY(pl) == NO) {
	    call pl_glr$t (pl, v, rl_dst, rl_depth, npix, rop)
	    return
	}

	call smark (sp)
	call salloc (rl_src, RL_MAXLEN(pl), TY_PIXEL)

	# Determine physical coords of line segment.
	call amovl (v, v3, PM_MAXDIM)
	call imaplv (im, v3, v1, PM_MAXDIM)
	v3[1] = v3[1] + npix - 1
	call imaplv (im, v3, v2, PM_MAXDIM)

	# Get line scaling parameters.
	if (npix <= 1)
	    xstep = 1
	else
	    xstep = (v2[1] - v1[1]) / (npix - 1)
	step = xstep
	if (xstep < 0) {
	    temp = v1[1];  v1[1] = v2[1];  v2[1] = temp
	    step = -step
	}

	# Extract the pixels.
	np = (npix - 1) * step + 1
	call salloc (px_src, np, TY_PIXEL)
	call pl_glp$t (pl, v1, Mem$t[px_src], 0, np, PIX_SRC)

	# Subsample and flip if necessary.
	if (step > 1)
	    call imsamp (Mem$t[px_src], Mem$t[px_src], npix, SZ_PIXEL, step)
	if (xstep < 0)
	    call imaflp (Mem$t[px_src], npix, SZ_PIXEL)

	# Convert to a range list.
	rl_len = pl_p2r$t (Mem$t[px_src], 1, Mem$t[rl_src], npix)

	# Copy to or combine with destination.
	if (!R_NEED_DST(rop)) {
	    rl_len = RLI_LEN(rl_src) * RL_LENELEM
	    call amov$t (Mem$t[rl_src], rl_dst, rl_len)
	} else {
	    call salloc (rl_out, RL_MAXLEN(pl), TY_PIXEL)
	    call pl_rangerop$t (Mem$t[rl_src], 1, PL_MAXVAL(pl), rl_dst, 1,
		MV(rl_depth), Mem$t[rl_out], npix, rop)
	    $if (datatype == s)
		rl_len = RLS_LEN(rl_out) * RL_LENELEM
	    $else
		rl_len = RLI_LEN(rl_out) * RL_LENELEM
	    $endif
	    call amov$t (Mem$t[rl_out], rl_dst, rl_len)
	}

	call sfree (sp)
end