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
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <plset.h>
include <plio.h>
# PL_P2R -- Convert a pixel array to a range list. The length of the output
# range list is returned as the function value.
int procedure pl_p2rs (px_src, xs, rl, npix)
short px_src[ARB] #I input pixel array
int xs #I starting index in pixbuf
short rl[3,ARB] #O destination range list
int npix #I number of pixels to convert
short hi, pv, zero
int xe, x1, np, rn, nv, ip
define done_ 91
begin
# No input pixels?
if (npix <= 0)
return (0)
xe = xs + npix - 1
rn = RL_FIRST
# Pack the pixel array into a range list. This is done by scanning
# the pixel list for successive ranges of pixels of constant nonzero
# value, where each range is described as follows:
zero = 0
pv = max (zero, px_src[xs]) # pixel value of current range
x1 = xs # start index of current range
hi = 1 # current high value
# Process the data array.
do ip = xs, xe {
if (ip < xe) {
# Get the next pixel value, loop again if same as previous one.
nv = max (zero, px_src[ip+1])
if (nv == pv)
next
# If current range is zero, loop again to get nonzero range.
if (pv == 0) {
pv = nv
x1 = ip + 1
next
}
}
np = ip - x1 + 1
# Output the new range.
if (pv > 0) {
rl[1,rn] = x1
rl[2,rn] = np
rl[3,rn] = pv
rn = rn + 1
}
x1 = ip + 1
pv = nv
}
RL_LEN(rl) = rn - 1
RL_AXLEN(rl) = npix
return (rn - 1)
end
|