aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/apphot/aputil/apmapr.x
blob: 0d4159abaf9baf143da6c40c9866d0c4ce9d1306 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# APMAPR -- Vector linear transformation.  Map the range of pixel values
# a1, a2 from a into the range b1, b2 into b.  It is assumed that a1 < a2
# and b1 < b2.

real procedure apmapr (a, a1, a2, b1, b2)

real	a		# the value to be mapped
real	a1, a2		# the numbers specifying the input data range
real	b1, b2		# the numbers specifying the output data range

real	minout, maxout, aoff, boff
real	scalar

begin
	scalar = (real (b2) - real (b1)) / (real (a2) - real (a1))
	minout = min (b1, b2)
	maxout = max (b1, b2)
	aoff = a1
	boff = b1
	return (max(minout, min(maxout, real((a - aoff) * scalar) + boff)))
end