aboutsummaryrefslogtreecommitdiff
path: root/pkg/proto/vol/src/i2sun/cnvimage.x
blob: 59bd465568579e7becc39ca984f2d5226201da11 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
include <imhdr.h>
include <mach.h>
include "i2sun.h"


# CNV_IMAGE -- Read each line of the input image, apply ztransform, convert
# to rasterfile form, and write to rasterfile.

procedure cnv_image (im, slice, tr, uptr, rfd)
pointer	im		# input image
int	slice		# current slice if n>2 image
pointer	tr		# spatial & greyscale transform structure
pointer	uptr		# pointer to user-specified transfer lut
pointer rfd		# output rasterfile

real	z1, z2, rz1, rz2
int	ztrans, row, xblk, yblk, ocols, olines
real	px1, px2, py1, py2	# image coords in fractional image pixels
pointer	sp, si, bufptr, out, rtemp, packed
short	z1_s, z2_s, rz1_s, rz2_s
bool	unitary_greyscale_transformation

bool	fp_equalr()
pointer	siglns(), siglnr(), sigln_setup()
errchk	siglns(), siglnr(), sigln_setup()

begin
	# Set up for scaled image input.
	px1 = 1
	px2 = IM_LEN(im,COL)
	py1 = 1
	py2 = IM_LEN(im,LINE)
	ocols = TR_XE(tr) - TR_XS(tr) + 1
	olines = TR_YE(tr) - TR_YS(tr) + 1

	# Round odd-numbered numbers of columns up due to restrictions on
	# IRAF binary byte i/o (number of bytes of image data must match
	# that specified in rasterfile header).
	if (mod (ocols, 2) == 1)
	    ocols = ocols + 1

	xblk = INDEFI
	yblk = INDEFI
	si = sigln_setup (im, px1,px2,ocols,xblk, py1,py2,olines,yblk, 
	    TR_ORDER(tr))

	# Type short pixels are treated as a special case to minimize vector
	# operations for such images (which are common).  If unity mapping is
	# employed the data is simply copied, i.e., floor ceiling constraints
	# are not applied.  This is very fast and will produce a contoured
	# image on the display which will be adequate for some applications.

	z1 = TR_Z1(tr)
	z2 = TR_Z2(tr)
	ztrans = TR_ZTRANS(tr)
	rz1 = COLORSTART
	rz2 = COLOREND
	if (ztrans == Z_UNITARY) {
	    unitary_greyscale_transformation = true
	} else if (ztrans == Z_LINEAR) {
	    unitary_greyscale_transformation =
		((fp_equalr(z1,rz1) && fp_equalr(z2,rz2)) || fp_equalr(z1,z2))
	} else
	    unitary_greyscale_transformation = false

	if (IM_PIXTYPE(im) == TY_SHORT && ztrans != Z_LOG) {

	    call smark (sp)
	    call salloc (out, ocols, TY_SHORT)
	    call salloc (packed, ocols, TY_CHAR)
	    z1_s = z1;  z2_s = z2

	    for (row=olines;  row >= 1;  row=row-1) {
		bufptr = siglns (si, row, TR_SLICEAXIS(tr), slice)

		if (unitary_greyscale_transformation) {
		    call amovs (Mems[bufptr], Mems[out], ocols)
		} else if (ztrans == Z_USER) {
		    rz1_s = U_Z1; rz2_s = U_Z2
		    call amaps (Mems[bufptr], Mems[out], ocols, z1_s, z2_s,
			rz1_s, rz2_s)
		    call aluts (Mems[out], Mems[out], ocols, Mems[uptr])
		} else {
		    rz1_s = rz1; rz2_s = rz2
		    call amaps (Mems[bufptr], Mems[out], ocols, z1_s, z2_s,
			rz1_s, rz2_s)
		}

		# Pack to unsigned byte and write to file.
		call achtsc (Mems[out], Memc[packed], ocols)
		call chrpak (Memc[packed], 1, Memc[packed], 1, ocols)
		call write (rfd, Memc[packed], ocols / SZB_CHAR)
	    }
	    call sfree (sp)

	} else if (ztrans == Z_USER) {
	    call smark (sp)
	    call salloc (rtemp, ocols, TY_REAL)
	    call salloc (out, ocols, TY_SHORT)
	    call salloc (packed, ocols, TY_CHAR)

	    for (row=olines;  row >= 1;  row=row-1) {
		bufptr = siglnr (si, row, TR_SLICEAXIS(tr), slice)
		call amapr (Memr[bufptr], Memr[rtemp], ocols, z1, z2, 
		    real(U_Z1), real(U_Z2))
		call achtrs (Memr[rtemp], Mems[out], ocols)
		call aluts (Mems[out], Mems[out], ocols, Mems[uptr])
		call achtsc (Mems[out], Memc[packed], ocols)
		call chrpak (Memc[packed], 1, Memc[packed], 1, ocols)
		call write (rfd, Memc[packed], ocols / SZB_CHAR)
	    }
	    call sfree (sp)

	} else {
	    call smark (sp)
	    call salloc (rtemp, ocols, TY_REAL)
	    call salloc (packed, ocols, TY_CHAR)

	    for (row=olines;  row >= 1;  row=row-1) {
		bufptr = siglnr (si, row, TR_SLICEAXIS(tr), slice)

		if (unitary_greyscale_transformation)  {
		    call amovr (Memr[bufptr], Memr[rtemp], ocols)
		} else if (ztrans == Z_LOG) {
		    call amapr (Memr[bufptr], Memr[rtemp], ocols,
			z1, z2, 1.0, 10.0 ** MAXLOG)
		    call alogr (Memr[rtemp], Memr[rtemp], ocols)
		    call amapr (Memr[rtemp], Memr[rtemp], ocols,
			1.0, real(MAXLOG), rz1, rz2)
		} else
		    call amapr (Memr[bufptr], Memr[rtemp], ocols, z1, z2,
			rz1, rz2)
		call achtrc (Memr[rtemp], Memc[packed], ocols)
		call chrpak (Memc[packed], 1, Memc[packed], 1, ocols)
		call write (rfd, Memc[packed], ocols / SZB_CHAR)
	    }
	    call sfree (sp)
	}

	call sigln_free (si)
end