aboutsummaryrefslogtreecommitdiff
path: root/pkg/images/tv/imexamine/iegdata.x
blob: 6e1f7e917324afd83097c05c9a97e3cc5eee05fb (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<imhdr.h>
 
# IE_GDATA -- Get image data with boundary checking.
 
pointer procedure ie_gdata (im, x1, x2, y1, y2)
 
pointer	im			# IMIO pointer
int	x1, x2, y1, y2		# Subraster limits (input and output)
 
int	i, nc, nl
pointer	imgs2r()
errchk	imgs2r
 
begin
	nc = IM_LEN(im,1)
	nl = IM_LEN(im,2)

	if (IS_INDEFI (x1))
	    x1 = 1
	if (IS_INDEFI (x2))
	    x2 = nc
	if (IS_INDEFI (y1))
	    y1 = 1
	if (IS_INDEFI (y2))
	    y2 = nl
 
	i = max (x1, x2)
	x1 = min (x1, x2)
	x2 = i
	i = max (y1, y2)
	y1 = min (y1, y2)
	y2 = i

	if (x2 < 1 || x1 > nc || y2 < 1 || y1 > nl)
	    call error (1, "Pixels out of bounds")
	
	x1 = max (1, x1)
	x2 = min (nc, x2)
	y1 = max (1, y1)
	y2 = min (nl, y2)

	return (imgs2r (im, x1, x2, y1, y2))
end