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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
|
include <imhdr.h>
include "../lib/daophotdef.h"
include "../lib/allstardef.h"
# DP_GWT -- Return a pointer to the desired weights pixels. The weights buffer
# pointer is assumed to be NULL on the initial all. If the new line limits
# are totally contained within the old line limits no action is taken and
# the old line limits are returned. If the weights pixels are stored in a
# scratch image the pixels must be accessed sequentially, otherwise an
# error is returned.
pointer procedure dp_gwt (dao, im, line1, line2, mode, flush)
pointer dao # pointer to the daophot strucuture
pointer im # pointer to the input image
int line1 # the lower line limit
int line2 # the upper line limit
int mode # input / output mode
int flush # flush the output
int nx, ny, xoff, yoff, llast1, llast2
pointer allstar
begin
allstar = DP_ALLSTAR(dao)
if (DP_WBUF(allstar) == NULL) {
llast1 = 0
llast2 = 0
} else if (flush == YES) {
line1 = llast1
line2 = llast2
} else if ((line1 >= llast1) && (line2 <= llast2)) {
line1 = llast1
line2 = llast2
return (DP_WBUF(allstar))
} else if (line1 < llast1)
call error (0,
"ERROR: Attempting to access the weights pixels randomly")
# All the data is cached.
if (DP_CACHE (allstar, A_WEIGHT) == YES) {
nx = IM_LEN(im,1)
ny = IM_LEN(im,2)
xoff = 1
yoff = 1
DP_WBUF(allstar) = DP_WEIGHTS(allstar)
# Read in some new data.
} else if (mode == READ_ONLY) {
call dp_albufl2r (DP_WEIGHTS(allstar), DP_WBUF(allstar),
llast1, llast2, line1, line2, flush)
if (flush == NO) {
nx = IM_LEN(im,1)
ny = line2 - line1 + 1
xoff = 1
yoff = line1
} else {
nx = 0
ny = 0
xoff = 0
yoff = 0
}
# Write out the old data and read in some new data.
} else if (mode == READ_WRITE) {
call dp_albufl2rw (DP_WEIGHTS(allstar), DP_WEIGHTS(allstar),
DP_WBUF(allstar), llast1, llast2, line1, line2, flush)
if (flush == NO) {
nx = IM_LEN(im,1)
ny = line2 - line1 + 1
xoff = 1
yoff = line1
} else {
nx = 0
ny = 0
xoff = 0
yoff = 0
}
}
# Update the required buffer parameters.
DP_WNX(allstar) = nx
DP_WNY(allstar) = ny
DP_WXOFF(allstar) = xoff
DP_WYOFF(allstar) = yoff
# Update the buffer definition which is currently not used.
DP_WLX(allstar) = xoff
DP_WMX(allstar) = max (xoff + nx - 1, 0)
DP_WLY(allstar) = yoff
DP_WMY(allstar) = max (yoff + ny - 1, 0)
return (DP_WBUF(allstar))
end
# DP_GST -- Return a pointer to the scratch image pixels. The scratch image
# pointer is assumed to be NULL on the initial all. If the new line limits
# are totally contained within the old line limits no action is taken and
# the old line limits are returned. If the scratch image pixels are stored in a
# scratch image the pixels must be accessed sequentially, otherwise an
# error is returned.
pointer procedure dp_gst (dao, im, line1, line2, mode, flush)
pointer dao # pointer to the daophot structure
pointer im # pointer to the input image
int line1 # the lower line limit
int line2 # the upper line limit
int mode # input / output mode
int flush # flush the buffer
int nx, ny, xoff, yoff, llast1, llast2
pointer allstar
begin
allstar = DP_ALLSTAR(dao)
if (DP_SBUF(allstar) == NULL) {
llast1 = 0
llast2 = 0
} else if (flush == YES) {
line1 = llast1
line2 = llast2
} else if ((line1 >= llast1) && (line2 <= llast2)) {
line1 = llast1
line2 = llast2
return (DP_SBUF(allstar))
} else if (line1 < llast1)
call error (0,
"ERROR: Attempting to access scratch image pixels randomly")
# All the data is cached.
if (DP_CACHE (allstar, A_SUBT) == YES) {
nx = IM_LEN(im,1)
ny = IM_LEN(im,2)
xoff = 1
yoff = 1
DP_SBUF(allstar) = DP_SUBT(allstar)
# Read in some new data.
} else if (mode == READ_ONLY) {
call dp_albufl2r (DP_SUBT(allstar), DP_SBUF(allstar),
llast1, llast2, line1, line2, flush)
if (flush == NO) {
nx = IM_LEN(im,1)
ny = line2 - line1 + 1
xoff = 1
yoff = line1
} else {
nx = 0
ny = 0
xoff = 0
yoff = 0
}
# Write out the old data and read in some new data.
} else if (mode == READ_WRITE) {
call dp_albufl2rw (DP_SUBT(allstar), DP_SUBT(allstar),
DP_SBUF(allstar), llast1, llast2, line1, line2, flush)
if (flush == NO) {
nx = IM_LEN(im,1)
ny = line2 - line1 + 1
xoff = 1
yoff = line1
} else {
nx = 0
ny = 0
xoff = 0
yoff = 0
}
}
# Update the required buffer parameters.
DP_SNX(allstar) = nx
DP_SNY(allstar) = ny
DP_SXOFF(allstar) = xoff
DP_SYOFF(allstar) = yoff
# Update the buffer description which is not currently used.
DP_SLX(allstar) = xoff
DP_SMX(allstar) = max (xoff + nx - 1, 0)
DP_SLY(allstar) = yoff
DP_SMY(allstar) = max (yoff + ny - 1, 0)
return (DP_SBUF(allstar))
end
# DP_GDC -- Return a pointer to the subtracted image pixels. The subtracted
# image pixels pointer is assumed to be NULL on the initial all. If the new
# line limits are totally contained within the old line limits no action is
# taken and the old line limits are returned. If the subtracted image pixels are
# stored in a scratch image the pixels must be accessed sequentially,
# otherwise an error is returned.
pointer procedure dp_gdc (dao, im, line1, line2, mode, flush)
pointer dao # pointer to the daophot strucuture
pointer im # pointer to the input image
int line1, line2 # the upper and lower line limits
int mode # input / output mode
int flush # flush the input data
int nx, ny, xoff, yoff, llast1, llast2
pointer allstar
begin
allstar = DP_ALLSTAR(dao)
if (DP_DBUF(allstar) == NULL) {
llast1 = 0
llast2 = 0
} else if (flush == YES) {
line1 = llast1
line2 = llast2
} else if ((line1 >= llast1) && (line2 <= llast2)) {
line1 = llast1
line2 = llast2
return (DP_DBUF(allstar))
} else if (line1 < llast1)
call error (0,
"ERROR: Attempting to access subtracted image pixels randomly")
# All the data is cached.
if (DP_CACHE (allstar, A_DCOPY) == YES) {
nx = IM_LEN(im,1)
ny = IM_LEN(im,2)
xoff = 1
yoff = 1
DP_DBUF(allstar) = DP_DATA(allstar)
# Read in some new data.
} else if (mode == READ_ONLY) {
call dp_albufl2r (DP_DATA(allstar), DP_DBUF(allstar),
llast1, llast2, line1, line2, flush)
if (flush == NO) {
nx = IM_LEN(im,1)
ny = line2 - line1 + 1
xoff = 1
yoff = line1
} else {
nx = 0
ny = 0
xoff = 0
yoff = 0
}
# Write out the old data and read in some new data.
} else if (mode == READ_WRITE) {
call dp_albufl2rw (DP_DATA(allstar), DP_DATA(allstar),
DP_DBUF(allstar), llast1, llast2, line1, line2, flush)
if (flush == NO) {
nx = IM_LEN(im,1)
ny = line2 - line1 + 1
xoff = 1
yoff = line1
} else {
nx = 0
ny = 0
xoff = 0
yoff = 0
}
}
# Update the required buffer parameters.
DP_DNX(allstar) = nx
DP_DNY(allstar) = ny
DP_DXOFF(allstar) = xoff
DP_DYOFF(allstar) = yoff
# Update the buffer definition which is currently not used.
DP_DLX(allstar) = xoff
DP_DMX(allstar) = max (xoff + nx - 1, 0)
DP_DLY(allstar) = yoff
DP_DMY(allstar) = max (yoff + ny - 1, 0)
return (DP_DBUF(allstar))
end
# DP_ALBUFL2RW -- Maintain a buffer of image lines and which can be read from
# an input image and written to an output image. The input and output images
# may be the same but must have the same dimensions. A new buffer is created
# when the buffer pointer is null and reallocated when the buffer changes size.
procedure dp_albufl2rw (inim, outim, buf, llast1, llast2, line1, line2, flush)
pointer inim # the input image pointer
pointer outim # the output image pointer
pointer buf # pointer to the internal buffer
int llast1, llast2 # the line limits of the previous buffer
int line1, line2 # the line limits of the requested buffer
int flush # flush the output buffer
int i, ncols, nlines, nllast, lout, nmove
pointer buf1, buf2
pointer imgl2r(), impl2r()
define flush_ 11
begin
# Write the data in the buffer to the output image and free
# the buffer.
if (flush == YES)
go to flush_
# Define the size of the current buffer.
ncols = IM_LEN(inim,1)
nlines = line2 - line1 + 1
# If the buffer pointer is undefined then allocate memory for the
# buffer.
if (buf == NULL) {
call malloc (buf, ncols * nlines, TY_REAL)
llast1 = 0
llast2 = 0
nllast = 0
} else
nllast = llast2 - llast1 + 1
# Write out the lines that are not needed any more.
if ((line1 > llast1) && (llast1 > 0)) {
buf2 = buf
lout = min (llast2, line1 - 1)
do i = llast1, lout {
buf1 = impl2r (outim, i)
call amovr (Memr[buf2], Memr[buf1], ncols)
buf2 = buf2 + ncols
}
}
# Now move the remaining lines to the beginning of the buffer.
nmove = 0
if (llast2 >= line1) {
buf1 = buf
buf2 = buf + ncols * (line1 - llast1)
do i = line1, llast2 {
if (buf1 != buf2)
call amovr (Memr[buf2], Memr[buf1], ncols)
nmove = nmove + 1
buf2 = buf2 + ncols
buf1 = buf1 + ncols
}
}
# Resize the buffer if necessary.
if (nlines > nllast)
call realloc (buf, ncols * nlines, TY_REAL)
# Read only the image lines with are different from the last buffer.
if (line2 > llast2) {
buf1 = buf + ncols * nmove
lout = max (line1, llast2 + 1)
do i = lout, line2 {
buf2 = imgl2r (inim, i)
call amovr (Memr[buf2], Memr[buf1], ncols)
buf1 = buf1 + ncols
}
}
# Save the buffer parameters.
llast1 = line1
llast2 = line2
if (flush == NO)
return
flush_
# Flush the remaining portion of the buffer to the output image
# and free the buffer space.
if (buf != NULL) {
buf2 = buf
do i = llast1, llast2 {
buf1 = impl2r (outim, i)
call amovr (Memr[buf2], Memr[buf1], ncols)
buf2 = buf2 + ncols
}
call imflush (outim)
call mfree (buf, TY_REAL)
}
buf = NULL
end
# DP_ALBUFL2R -- Maintain a buffer of image lines which can be read
# sequentially from an input image. The buffer pointer must be initialized
# to NULL. A new buffer is created when the buffer pointer is null and
# reallocated when the buffer increases in size.
procedure dp_albufl2r (inim, buf, llast1, llast2, line1, line2, flush)
pointer inim # pointer to the input image
pointer buf # pointer to the internal buffer
int llast1, llast2 # the line limits of the previous buffer
int line1, line2 # the line limits of the requested buffer
int flush # flush the output buffer
int i, ncols, nlines, nllast, lout, nmove
pointer buf1, buf2
pointer imgl2r()
define flush_ 11
begin
# Write the data in the buffer to the output image and free
# the buffer.
if (flush == YES)
go to flush_
# Define the size parameters for the new buffer.
ncols = IM_LEN(inim,1)
nlines = line2 - line1 + 1
# If the buffer pointer is undefined then allocate memory for the
# buffer.
if (buf == NULL) {
call malloc (buf, ncols * nlines, TY_REAL)
llast1 = 0
llast2 = 0
nllast = 0
} else
nllast = llast2 - llast1 + 1
# Now move the remaining lines to the beginning of the buffer.
nmove = 0
if (llast2 >= line1) {
buf1 = buf
buf2 = buf + ncols * (line1 - llast1)
do i = line1, llast2 {
if (buf1 != buf2)
call amovr (Memr[buf2], Memr[buf1], ncols)
nmove = nmove + 1
buf2 = buf2 + ncols
buf1 = buf1 + ncols
}
}
# Resize the buffer if necessary.
if (nlines > nllast)
call realloc (buf, ncols * nlines, TY_REAL)
# Read only the image lines with are different from the last buffer.
if (line2 > llast2) {
buf1 = buf + ncols * nmove
lout = max (line1, llast2 + 1)
do i = lout, line2 {
buf2 = imgl2r (inim, i)
call amovr (Memr[buf2], Memr[buf1], ncols)
buf1 = buf1 + ncols
}
}
# Save the buffer parameters.
llast1 = line1
llast2 = line2
if (flush == NO)
return
flush_
# Free the buffer space.
if (buf != NULL)
call mfree (buf, TY_REAL)
buf = NULL
end
|