aboutsummaryrefslogtreecommitdiff
path: root/sys/imio/imbtran.x
blob: bf3ec20171fc911d96521a25ef4c0220b48cb90c (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<imhdr.h>
include	<imset.h>
include	<imio.h>

# IMBTRAN -- Transform a point (x,y), possibly lying outside the boundary of
# the N-dimensional image, back into the image using the current boundary
# extension technique.

procedure imbtran (im, v1, v2, ndim)

pointer	im			# image descriptor
long	v1[IM_MAXDIM]		# input, out of bounds point
long	v2[IM_MAXDIM]		# transformed point (output)
int	ndim			# number of dimensions to transform

int	i
long	vin, vmax

begin
	switch (IM_VTYBNDRY(im)) {
	case BT_NEAREST:
	    do i = 1, ndim {
		vmax = IM_SVLEN(im,i)
		vin  = v1[i]

		if (vin < 1)
		    v2[i] = 1
		else if (vin > vmax)
		    v2[i] = vmax
		else
		    v2[i] = vin
	    }

	case BT_REFLECT:
	    do i = 1, ndim {
		vmax = IM_SVLEN(im,i)
		vin  = v1[i]

		if (vin < 1)
		    v2[i] = 1 + (1 - vin)
		else if (vin > vmax)
		    v2[i] = vmax - (vin - vmax)
		else
		    v2[i] = vin
	    }

	case BT_WRAP:
	    do i = 1, ndim {
		vmax = IM_SVLEN(im,i)
		vin  = v1[i]

		while (vin < 1)
		    vin = vin + vmax
		while (vin > vmax)
		    vin = vin - vmax
		v2[i] = vin
	    }

	default:
	    do i = 1, ndim
		v2[i] = v1[i]
	}
end