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

# IMAFLP -- Flip a vector end for end.  Optimized for the usual pixel types.
# Pretty slow for DOUBLE and COMPLEX on byte machines, but it is not worth
# optimizing for those cases.

procedure imaflp (a, npix, sz_pixel)

char	a[ARB], temp
int	npix, sz_pixel
int	i, left, right, pixel

begin
	switch (sz_pixel) {
	case SZ_SHORT:
	    call imflps (a, npix)
	case SZ_LONG:
	    call imflpl (a, npix)

	default:				# flip odd sized elements
	    left = 1
	    right = ((npix-1) * sz_pixel) + 1

	    do pixel = 1, (npix + 1) / 2 {
		do i = 0, sz_pixel-1 {
		    temp = a[right+i]
		    a[right+i] = a[left+i]
		    a[left+i] = temp
		}
		left = left + sz_pixel
		right = right - sz_pixel
	    }
	}
end


# IMFLPS -- Flip an array of SHORT sized elements.

procedure imflps (a, npix)

short	a[npix], temp
int	npix, i, right

begin
	right = npix + 1

	do i = 1, (npix + 1) / 2 {
	    temp = a[right-i]
	    a[right-i] = a[i]
	    a[i] = temp
	}
end


# IMFLPL -- Flip an array of LONG sized elements.

procedure imflpl (a, npix)

long	a[npix], temp
int	npix, i, right

begin
	right = npix + 1

	do i = 1, (npix + 1) / 2 {
	    temp = a[right-i]
	    a[right-i] = a[i]
	    a[i] = temp
	}
end