aboutsummaryrefslogtreecommitdiff
path: root/pkg/utilities/nttools/stxtools/copyimg.x
blob: 0248cfa9098b83225b228a83957ad56ede30a70a (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
include	<imhdr.h>

# COPYIMG -- Copy one image to another
#
# B.Simon	02-Mar-92	Original
# B.Simon	16-Mar-94	Delete fast copy, check for existing image

procedure copyimg (old, new)

char	old[ARB]	# i: old image
char	new[ARB]	# i: new image
#--
int	npix, junk
pointer	buf1, buf2, im1, im2
long	v1[IM_MAXDIM], v2[IM_MAXDIM]

int	imaccess()
int	imgnls(), imgnll(), imgnlr(), imgnld(), imgnlx()
int	impnls(), impnll(), impnlr(), impnld(), impnlx()
pointer	immap()

errchk	immap, imunmap

begin
	# Map the input and output images
	# Code adapted from iraf's imcopy task

	im1 = immap (old, READ_ONLY, 0)
	if (imaccess (new, READ_WRITE) == NO) {
	    im2 = immap (new, NEW_COPY, im1)
	} else {
	    im2 = immap (new, READ_WRITE, NULL)
	}

	# Setup start vector for sequential reads and writes

	call amovkl (long(1), v1, IM_MAXDIM)
	call amovkl (long(1), v2, IM_MAXDIM)

	# Copy the image.

	npix = IM_LEN(im1, 1)
	switch (IM_PIXTYPE(im1)) {
	case TY_SHORT:
	    while (imgnls (im1, buf1, v1) != EOF) {
		junk = impnls (im2, buf2, v2)
		call amovs (Mems[buf1], Mems[buf2], npix)
	    }
	case TY_USHORT, TY_INT, TY_LONG:
	    while (imgnll (im1, buf1, v1) != EOF) {
		junk = impnll (im2, buf2, v2)
		call amovl (Meml[buf1], Meml[buf2], npix)
	    }
	case TY_REAL:
	    while (imgnlr (im1, buf1, v1) != EOF) {
		junk = impnlr (im2, buf2, v2)
		call amovr (Memr[buf1], Memr[buf2], npix)
	    }
	case TY_DOUBLE:
	    while (imgnld (im1, buf1, v1) != EOF) {
		junk = impnld (im2, buf2, v2)
		call amovd (Memd[buf1], Memd[buf2], npix)
	    }
	case TY_COMPLEX:
	    while (imgnlx (im1, buf1, v1) != EOF) {
	        junk = impnlx (im2, buf2, v2)
		call amovx (Memx[buf1], Memx[buf2], npix)
	    }
	default:
	    call error (1, "unknown pixel datatype")
	}

	# Unmap the images

	call imunmap (im2)
	call imunmap (im1)

end