| 1 |
/*=========================================================================== |
| 2 |
Copyright (C) 1994-2009 European Southern Observatory (ESO) |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License as |
| 6 |
published by the Free Software Foundation; either version 2 of |
| 7 |
the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public |
| 15 |
License along with this program; if not, write to the Free |
| 16 |
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, |
| 17 |
MA 02139, USA. |
| 18 |
|
| 19 |
Correspondence concerning ESO-MIDAS should be addressed as follows: |
| 20 |
Internet e-mail: [email protected] |
| 21 |
Postal address: European Southern Observatory |
| 22 |
Data Management Division |
| 23 |
Karl-Schwarzschild-Strasse 2 |
| 24 |
D 85748 Garching bei Muenchen |
| 25 |
GERMANY |
| 26 |
===========================================================================*/ |
| 27 |
/* ++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 28 |
|
| 29 |
.IDENTIFICATION |
| 30 |
program SCANIMA version 1.00 940214 |
| 31 |
K. Banse ESO - Garching |
| 32 |
|
| 33 |
.KEYWORDS |
| 34 |
graphics, reconstruction |
| 35 |
|
| 36 |
.PURPOSE |
| 37 |
scan a 2-dim image which presents the graph of a 1-dim function |
| 38 |
and create a 1-dim image or a table as result |
| 39 |
|
| 40 |
.ALGORITHM |
| 41 |
get bottom/top pixel coords. in each column of input image |
| 42 |
(of pixel > threshold) |
| 43 |
|
| 44 |
.INPUT/OUTPUT |
| 45 |
the following keys are used: |
| 46 |
|
| 47 |
in_a/c/1/60 input frame |
| 48 |
out_a/c/1/60 result image or table |
| 49 |
p3/c/1/80 threshold or lo-,hiband |
| 50 |
p4/c/1/10 option: bottom/top |
| 51 |
p5/c/1/80 x1g,x1r,x2g,x2r |
| 52 |
p6/c/1/80 y1g,y1r,y2g,y2r |
| 53 |
p7/c/1/80 xa,ya:xb,yb |
| 54 |
p8/c/1/80 wsize,xpix1,ypix1 |
| 55 |
|
| 56 |
.VERSIONS |
| 57 |
|
| 58 |
090710 last modif |
| 59 |
-------------------------------------------------- */ |
| 60 |
|
| 61 |
#include <midas_def.h> |
| 62 |
|
| 63 |
#include <stdio.h> |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
static int kstart, sublo[2], subhi[2]; |
| 68 |
static int wsize, xpix1, ypix1; |
| 69 |
|
| 70 |
static char optio[8]; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
int main() |
| 75 |
|
| 76 |
{ |
| 77 |
int uni, iav, stat, jj; |
| 78 |
int tid, xcol, ycol; |
| 79 |
int imno, imnoc; |
| 80 |
int nulo, sizec, chunk; |
| 81 |
int naxis, npix[2], naxisc, npixc[2]; |
| 82 |
int ibuf[3], ll, ref_flag; |
| 83 |
|
| 84 |
register int nr; |
| 85 |
|
| 86 |
char *cpntr; |
| 87 |
char line[80], linea[80]; |
| 88 |
char frame[64], framec[64]; |
| 89 |
char cunit[64], ident[72]; |
| 90 |
|
| 91 |
char *osmmget(); |
| 92 |
|
| 93 |
double step[2], start[2]; |
| 94 |
double stepc[2], startc[2]; |
| 95 |
double ref[4], xg[2], xr[2], yg[2], yr[2]; |
| 96 |
|
| 97 |
float *pntr, *pntrc, *fpntr; |
| 98 |
float cuts[4], faux[5]; |
| 99 |
|
| 100 |
void mima(); |
| 101 |
|
| 102 |
int get_graph(); |
| 103 |
|
| 104 |
|
| 105 |
/* set up MIDAS environment + enable automatic error abort */ |
| 106 |
|
| 107 |
SCSPRO("scanima"); |
| 108 |
|
| 109 |
for (nr=0; nr<2; nr++) |
| 110 |
{ |
| 111 |
startc[nr] = 0.0; |
| 112 |
stepc[nr] = 1.0; |
| 113 |
npixc[nr] = 1; |
| 114 |
npix[nr] = 1; |
| 115 |
start[nr] = 0.0; |
| 116 |
step[nr] = 1.0; |
| 117 |
sublo[nr] = 0; |
| 118 |
} |
| 119 |
ref_flag = 0; |
| 120 |
yr[0] = yr[1] = yg[0] = yg[1] = xg[0] = xg[1] = 0.0; |
| 121 |
pntr = (float *) 0; |
| 122 |
|
| 123 |
/* get input frame, result frame, threshold(s), option and references */ |
| 124 |
|
| 125 |
stat = SCKGETC("IN_A",1,60,&iav,frame); |
| 126 |
stat = SCKGETC("OUT_A",1,60,&iav,framec); |
| 127 |
|
| 128 |
stat = SCFOPN(frame,D_R4_FORMAT,0,F_IMA_TYPE,&imno); |
| 129 |
stat = SCDRDI(imno,"NAXIS",1,1,&iav,&naxis,&uni,&nulo); |
| 130 |
stat = SCDRDI(imno,"NPIX",1,2,&iav,npix,&uni,&nulo); |
| 131 |
stat = SCDRDD(imno,"START",1,2,&iav,start,&uni,&nulo); |
| 132 |
stat = SCDRDD(imno,"STEP",1,2,&iav,step,&uni,&nulo); |
| 133 |
stat = SCDGETC(imno,"CUNIT",1,64,&iav,cunit); |
| 134 |
stat = SCDRDR(imno,"LHCUTS",1,2,&iav,cuts,&uni,&nulo); |
| 135 |
subhi[0] = npix[0] - 1; |
| 136 |
subhi[1] = npix[1] - 1; |
| 137 |
|
| 138 |
stat = SCKGETC("P3",1,80,&iav,line); |
| 139 |
if (line[0] == '+') /* no threshold given */ |
| 140 |
{ |
| 141 |
faux[0] = (cuts[0] + cuts[1]) / 2; |
| 142 |
faux[4] = 1; |
| 143 |
} |
| 144 |
else |
| 145 |
{ |
| 146 |
iav = CGN_CNVT(line,2,2,npixc,faux,step); |
| 147 |
if (iav < 1) |
| 148 |
SCETER(101,"invalid `threshold value' ..."); |
| 149 |
faux[4] = 2; |
| 150 |
} |
| 151 |
|
| 152 |
stat = SCKGETC("P4",1,4,&iav,line); |
| 153 |
CGN_UPCOPY(optio,line,4); |
| 154 |
|
| 155 |
jj = CGN_INDEXS(framec,",t"); /* check, if we should make a table */ |
| 156 |
if (jj < 0) |
| 157 |
jj = CGN_INDEXS(framec,",T"); |
| 158 |
if (jj > 0) |
| 159 |
{ |
| 160 |
framec[jj] = '\0'; |
| 161 |
optio[4] = 'T'; |
| 162 |
} |
| 163 |
else |
| 164 |
optio[4] = 'I'; |
| 165 |
|
| 166 |
|
| 167 |
stat = SCKGETC("p5",1,80,&iav,line); /* get x,y reference values */ |
| 168 |
stat = SCKGETC("p6",1,80,&iav,linea); |
| 169 |
if ((line[0] != '+') && (linea[0] != '+')) |
| 170 |
{ |
| 171 |
ref_flag = 1; |
| 172 |
iav = CGN_CNVT(line,4,4,npixc,cuts,ref); |
| 173 |
if (iav < 1) |
| 174 |
SCETER(101,"invalid `x-ref. values' ..."); |
| 175 |
xg[0] = ref[0]; |
| 176 |
xr[0] = ref[1]; |
| 177 |
xg[1] = ref[2]; |
| 178 |
xr[1] = ref[3]; |
| 179 |
iav = CGN_CNVT(linea,4,4,npixc,cuts,ref); |
| 180 |
if (iav < 1) |
| 181 |
SCETER(101,"invalid `y-ref. values' ..."); |
| 182 |
yg[0] = ref[0]; |
| 183 |
yr[0] = ref[1]; |
| 184 |
yg[1] = ref[2]; |
| 185 |
yr[1] = ref[3]; |
| 186 |
} |
| 187 |
stat = SCKGETC("p7",1,80,&iav,line); /* get subframe coords */ |
| 188 |
|
| 189 |
|
| 190 |
/* check if we have extraction coords. */ |
| 191 |
|
| 192 |
if (line[0] != '+') |
| 193 |
{ |
| 194 |
if (line[0] != '[') |
| 195 |
{ |
| 196 |
jj = strlen(line); |
| 197 |
for (nr=jj; nr>0; nr--) |
| 198 |
line[nr] = line[nr-1]; |
| 199 |
line[0] = '['; |
| 200 |
line[jj+1] = '\0'; |
| 201 |
} |
| 202 |
|
| 203 |
stat = Convcoo(1,imno,line,2,&jj,sublo,subhi); |
| 204 |
if (stat != 0) |
| 205 |
SCETER(102,"invalid coordinates for subframe boundaries..."); |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
if ((optio[1] == 'F') || (optio[1] == 'D')) |
| 210 |
{ |
| 211 |
xpix1 = 0; |
| 212 |
ypix1 = 0; |
| 213 |
wsize = subhi[1] - sublo[1] + 1; |
| 214 |
stat = SCKGETC("P8",1,80,&iav,line); /* get wsize,xpix1,ypix1 */ |
| 215 |
if (line[0] != '+') |
| 216 |
{ |
| 217 |
iav = CGN_CNVT(line,1,3,ibuf,cuts,ref); |
| 218 |
if (iav >= 1) |
| 219 |
{ |
| 220 |
wsize = ibuf[0]; |
| 221 |
if (wsize < 1) SCETER(105,"invalid window size ..."); |
| 222 |
if (iav == 3) |
| 223 |
{ |
| 224 |
xpix1 = ibuf[1] - 1; |
| 225 |
ypix1 = ibuf[2] - 1; |
| 226 |
if ((xpix1 < sublo[0]) || (xpix1 > subhi[0])) |
| 227 |
SCETER(106,"start x-pixel outside subframe ..."); |
| 228 |
if ((ypix1 < sublo[1]) || (ypix1 > subhi[1])) |
| 229 |
SCETER(106,"start y-pixel outside subframe ..."); |
| 230 |
} |
| 231 |
} |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
/* get virtual memory buffers */ |
| 237 |
|
| 238 |
chunk = npix[0]*npix[1]; |
| 239 |
ll = chunk * sizeof(float); |
| 240 |
cpntr = osmmget((unsigned int)ll); |
| 241 |
if (cpntr == (char *) 0) |
| 242 |
SCETER(103,"could not allocate virtual memory..."); |
| 243 |
else |
| 244 |
pntr = (float *) cpntr; |
| 245 |
|
| 246 |
stat = SCFGET(imno,1,chunk,&iav,(char *)pntr); |
| 247 |
|
| 248 |
|
| 249 |
/* the result frame may be created larger than necessary... */ |
| 250 |
|
| 251 |
if (optio[4] == 'I') |
| 252 |
{ |
| 253 |
stat = SCFCRE(framec,D_R4_FORMAT,F_O_MODE,F_IMA_TYPE,npix[0],&imnoc); |
| 254 |
stat = SCFMAP(imnoc,F_O_MODE,1,npix[0],&iav,&cpntr); |
| 255 |
} |
| 256 |
else |
| 257 |
{ |
| 258 |
stat = SCFCRE("for_table",D_R4_FORMAT,F_X_MODE,F_IMA_TYPE,npix[0],&imnoc); |
| 259 |
stat = SCFMAP(imnoc,F_X_MODE,1,npix[0],&iav,&cpntr); |
| 260 |
} |
| 261 |
pntrc =(float *) cpntr; |
| 262 |
|
| 263 |
fpntr = pntrc; /* initialize */ |
| 264 |
for (nr=0; nr<npix[0]; nr++) |
| 265 |
*fpntr++ = -1.0; |
| 266 |
|
| 267 |
|
| 268 |
/* now do it */ |
| 269 |
|
| 270 |
sizec = get_graph(faux,pntr,npix,pntrc); |
| 271 |
if (sizec < 1) |
| 272 |
SCETER(104,"no graph detected ..."); |
| 273 |
else if (sizec == 1) |
| 274 |
SCTPUT("Warning: graph collapsed to single point ..."); |
| 275 |
|
| 276 |
|
| 277 |
/* if reference values are given, calculate new start, stepsize */ |
| 278 |
|
| 279 |
if (ref_flag == 1) |
| 280 |
{ |
| 281 |
jj = xg[1] - xg[0]; |
| 282 |
if (jj == 0) goto after; |
| 283 |
stepc[0] = (xr[1]-xr[0])/jj; |
| 284 |
startc[0] = xr[0] - ((xg[0]-1)*stepc[0]); |
| 285 |
jj = yg[1] - yg[0]; |
| 286 |
if (jj == 0) goto after; |
| 287 |
stepc[1] = (yr[1]-yr[0])/jj; |
| 288 |
startc[1] = yr[0] - ((yg[0]-1)*stepc[1]); |
| 289 |
|
| 290 |
fpntr = pntrc; /* scale in y (intensity) */ |
| 291 |
for (nr=0; nr<sizec; nr++) |
| 292 |
{ |
| 293 |
*fpntr = startc[1] + (*fpntr * stepc[1]); |
| 294 |
fpntr ++; |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
/* prepare descriptors for output image/table */ |
| 300 |
|
| 301 |
after: |
| 302 |
naxisc = 1; |
| 303 |
npixc[0] = sizec; |
| 304 |
if (kstart > 0) /* x-start has been shifted */ |
| 305 |
startc[0] += (kstart*stepc[0]); |
| 306 |
|
| 307 |
if (optio[4] == 'T') |
| 308 |
{ |
| 309 |
stat = TCTINI(framec,F_RECORD,F_O_MODE,2,sizec,&tid); |
| 310 |
stat = TCCINI(tid,D_R8_FORMAT,1,"E22.12"," ","X",&xcol); |
| 311 |
stat = TCCINI(tid,D_R4_FORMAT,1,"F15.8"," ","Y",&ycol); |
| 312 |
|
| 313 |
*xr = startc[0]; |
| 314 |
fpntr = pntrc; |
| 315 |
for (nr=1; nr<(sizec+1); nr++) |
| 316 |
{ |
| 317 |
if (*fpntr >= 0.0) |
| 318 |
{ |
| 319 |
stat = TCEWRD(tid,nr,1,xr); |
| 320 |
stat = TCEWRR(tid,nr,2,fpntr); |
| 321 |
} |
| 322 |
*xr += stepc[0]; |
| 323 |
fpntr++; |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 327 |
else |
| 328 |
{ |
| 329 |
stat = SCDWRI(imnoc,"NAXIS",&naxisc,1,1,&uni); |
| 330 |
stat = SCDWRI(imnoc,"NPIX",npixc,1,naxisc,&uni); |
| 331 |
stat = SCDWRD(imnoc,"START",startc,1,naxisc,&uni); |
| 332 |
stat = SCDWRD(imnoc,"STEP",stepc,1,naxisc,&uni); |
| 333 |
strcpy(ident,"new frame "); |
| 334 |
stat = SCDWRC(imnoc,"IDENT",1,ident,1,72,&uni); |
| 335 |
jj = (naxisc+1) * 16; |
| 336 |
stat = SCDWRC(imnoc,"CUNIT",1,cunit,1,jj,&uni); |
| 337 |
|
| 338 |
mima(pntrc,sizec,cuts); |
| 339 |
cuts[2] = cuts[0]; |
| 340 |
cuts[3] = cuts[1]; |
| 341 |
cuts[1] = 0.0; |
| 342 |
cuts[2] = 0.0; |
| 343 |
stat = SCDWRR(imnoc,"LHCUTS",cuts,1,4,&uni); |
| 344 |
|
| 345 |
stat = CGN_DSCUPD(imno,imnoc," "); |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
SCSEPI(); |
| 350 |
|
| 351 |
return 0; |
| 352 |
} |
| 353 |
|
| 354 |
/* |
| 355 |
|
| 356 |
*/ |
| 357 |
|
| 358 |
void mima(pntri,npix,cuts) |
| 359 |
float *pntri, *cuts; |
| 360 |
int npix; |
| 361 |
|
| 362 |
{ |
| 363 |
|
| 364 |
register int nr; |
| 365 |
|
| 366 |
float fmi, fma; |
| 367 |
|
| 368 |
fmi = *pntri++; |
| 369 |
fma = fmi; |
| 370 |
|
| 371 |
for (nr=1; nr<npix; nr++) |
| 372 |
{ |
| 373 |
if (*pntri < fmi) |
| 374 |
fmi = *pntri; |
| 375 |
else if (*pntri > fma) |
| 376 |
fma = *pntri; |
| 377 |
pntri ++; |
| 378 |
} |
| 379 |
|
| 380 |
cuts[0] = fmi; |
| 381 |
cuts[1] = fma; |
| 382 |
} |
| 383 |
|
| 384 |
/* |
| 385 |
|
| 386 |
*/ |
| 387 |
|
| 388 |
int get_graph(fx,pntri,npix,pntro) |
| 389 |
float *fx, *pntri, *pntro; |
| 390 |
int *npix; |
| 391 |
|
| 392 |
{ |
| 393 |
|
| 394 |
register int nrx, nry; |
| 395 |
|
| 396 |
int end, mm, kk, kmax, count; |
| 397 |
int my, ky, ws2, fy, limi; |
| 398 |
|
| 399 |
char cbuf[64]; |
| 400 |
|
| 401 |
float val, valx, *lpntr, *inp, *inq, *outq, fmax; |
| 402 |
|
| 403 |
|
| 404 |
val = *fx; |
| 405 |
lpntr = pntro; |
| 406 |
end = 0; |
| 407 |
|
| 408 |
|
| 409 |
/* ---------------------------------------- |
| 410 |
first we work on the fixed WINDOW option |
| 411 |
---------------------------------------- */ |
| 412 |
|
| 413 |
if (optio[1] == 'F') |
| 414 |
{ |
| 415 |
ws2 = wsize / 2; |
| 416 |
|
| 417 |
|
| 418 |
/* and split for BOTTOM or TOP direction */ |
| 419 |
|
| 420 |
if (optio[0] == 'B') |
| 421 |
{ |
| 422 |
inp = pntri + (sublo[1]*npix[0]); |
| 423 |
|
| 424 |
|
| 425 |
/* final split for Maximum or Value option */ |
| 426 |
|
| 427 |
if (optio[2] == 'M') /* search for max value */ |
| 428 |
{ |
| 429 |
if (xpix1 < 1) /* no start pixel given */ |
| 430 |
{ |
| 431 |
fmax = val*0.99; |
| 432 |
fy = -1; |
| 433 |
for (nrx=sublo[0]; nrx<=subhi[0]; nrx++) |
| 434 |
{ |
| 435 |
outq = lpntr + nrx; |
| 436 |
inq = inp + nrx; |
| 437 |
for (nry=sublo[1]; nry<= subhi[1]; nry++) |
| 438 |
{ |
| 439 |
if (*inq > fmax) |
| 440 |
{ |
| 441 |
fy = nry; |
| 442 |
fmax = *inq; |
| 443 |
} |
| 444 |
inq += npix[0]; /* move to next line */ |
| 445 |
} |
| 446 |
if (fy > -1) |
| 447 |
{ |
| 448 |
*outq = fy; |
| 449 |
xpix1 = nrx; |
| 450 |
ypix1 = fy; |
| 451 |
goto win_1; |
| 452 |
} |
| 453 |
} |
| 454 |
SCETER(110,"no start pixel for window option found... "); |
| 455 |
} |
| 456 |
win_1: |
| 457 |
outq = lpntr + xpix1 + 1; /* point to next element */ |
| 458 |
for (nrx=xpix1+1;nrx<=subhi[0]; nrx++) |
| 459 |
{ |
| 460 |
fmax = val*0.99; |
| 461 |
fy = -1; |
| 462 |
my = ypix1 - ws2; |
| 463 |
if (my < sublo[1]) my = sublo[1]; |
| 464 |
ky = my + wsize; |
| 465 |
if (ky > subhi[1]) ky = subhi[1] + 1; |
| 466 |
inq = pntri + nrx + (my*npix[0]); /* point to low window start */ |
| 467 |
for (nry=my; nry<ky; nry++) |
| 468 |
{ |
| 469 |
if (*inq > fmax) |
| 470 |
{ |
| 471 |
fy = nry; |
| 472 |
fmax = *inq; |
| 473 |
} |
| 474 |
inq += npix[0]; |
| 475 |
} |
| 476 |
if (fy > -1) |
| 477 |
{ |
| 478 |
*outq = fy; |
| 479 |
ypix1 = fy; |
| 480 |
} |
| 481 |
|
| 482 |
outq ++; |
| 483 |
} |
| 484 |
} |
| 485 |
|
| 486 |
else |
| 487 |
{ |
| 488 |
if (xpix1 < 1) /* no start pixel given */ |
| 489 |
{ |
| 490 |
for (nrx=sublo[0]; nrx<=subhi[0]; nrx++) |
| 491 |
{ |
| 492 |
outq = lpntr + nrx; |
| 493 |
inq = inp + nrx; |
| 494 |
for (nry=sublo[1]; nry<= subhi[1]; nry++) |
| 495 |
{ |
| 496 |
if (*inq >= val) |
| 497 |
{ |
| 498 |
*outq = nry; |
| 499 |
xpix1 = nrx; |
| 500 |
ypix1 = nry; |
| 501 |
goto win_11; |
| 502 |
} |
| 503 |
inq += npix[0]; /* move to next line */ |
| 504 |
} |
| 505 |
} |
| 506 |
SCETER(110,"no start pixel for window option found... "); |
| 507 |
} |
| 508 |
win_11: |
| 509 |
outq = lpntr + xpix1 + 1; /* point to next element */ |
| 510 |
|
| 511 |
|
| 512 |
/* here we either have single value or band */ |
| 513 |
|
| 514 |
if (fx[4] > 1.0) |
| 515 |
{ |
| 516 |
valx = fx[1]; |
| 517 |
for (nrx=xpix1+1;nrx<=subhi[0]; nrx++) |
| 518 |
{ |
| 519 |
my = ypix1 - ws2; |
| 520 |
if (my < sublo[1]) my = sublo[1]; |
| 521 |
ky = my + wsize; |
| 522 |
if (ky > subhi[1]) ky = subhi[1] + 1; |
| 523 |
inq = pntri + nrx + (my*npix[0]); /* point to low w_start */ |
| 524 |
for (nry=my; nry<ky; nry++) |
| 525 |
{ |
| 526 |
if ((*inq >= val) && (*inq <= valx)) |
| 527 |
{ |
| 528 |
*outq = nry; |
| 529 |
ypix1 = nry; |
| 530 |
break; |
| 531 |
} |
| 532 |
inq += npix[0]; |
| 533 |
} |
| 534 |
outq ++; |
| 535 |
} |
| 536 |
} |
| 537 |
else |
| 538 |
{ |
| 539 |
for (nrx=xpix1+1;nrx<=subhi[0]; nrx++) |
| 540 |
{ |
| 541 |
my = ypix1 - ws2; |
| 542 |
if (my < sublo[1]) my = sublo[1]; |
| 543 |
ky = my + wsize; |
| 544 |
if (ky > subhi[1]) ky = subhi[1] + 1; |
| 545 |
inq = pntri + nrx + (my*npix[0]); /* point to low w_start */ |
| 546 |
for (nry=my; nry<ky; nry++) |
| 547 |
{ |
| 548 |
if (*inq >= val) |
| 549 |
{ |
| 550 |
*outq = nry; |
| 551 |
ypix1 = nry; |
| 552 |
break; |
| 553 |
} |
| 554 |
inq += npix[0]; |
| 555 |
} |
| 556 |
outq ++; |
| 557 |
} |
| 558 |
} |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
else |
| 563 |
{ |
| 564 |
inp = pntri + (subhi[1]*npix[0]); |
| 565 |
|
| 566 |
|
| 567 |
/* final split for Maximum or Value option */ |
| 568 |
|
| 569 |
if (optio[2] == 'M') /* search for max value */ |
| 570 |
{ |
| 571 |
if (xpix1 < 1) /* no start pixel given */ |
| 572 |
{ |
| 573 |
fmax = val*0.99; |
| 574 |
fy = -1; |
| 575 |
for (nrx=sublo[0]; nrx<=subhi[0]; nrx++) |
| 576 |
{ |
| 577 |
outq = lpntr + nrx; |
| 578 |
inq = inp + nrx; |
| 579 |
for (nry=subhi[1]; nry>= sublo[1]; nry--) |
| 580 |
{ |
| 581 |
if (*inq > fmax) |
| 582 |
{ |
| 583 |
fy = nry; |
| 584 |
fmax = *inq; |
| 585 |
} |
| 586 |
if (fy > -1) |
| 587 |
{ |
| 588 |
*outq = fy; |
| 589 |
xpix1 = nrx; |
| 590 |
ypix1 = fy; |
| 591 |
goto win_2; |
| 592 |
} |
| 593 |
inq -= npix[0]; /* move to previous line */ |
| 594 |
} |
| 595 |
} |
| 596 |
SCETER(110,"no start pixel for window option found... "); |
| 597 |
} |
| 598 |
win_2: |
| 599 |
outq = lpntr + xpix1 + 1; /* point to next element */ |
| 600 |
for (nrx=xpix1+1;nrx<=subhi[0]; nrx++) |
| 601 |
{ |
| 602 |
fmax = val*0.99; |
| 603 |
fy = -1; |
| 604 |
my = ypix1 + ws2; |
| 605 |
if (my > subhi[1]) my = subhi[1]; |
| 606 |
ky = my - wsize; |
| 607 |
if (ky < sublo[1]) ky = sublo[1] - 1; |
| 608 |
inq = pntri + nrx + (my*npix[0]); /* point to hi window start */ |
| 609 |
for (nry=my; nry>ky; nry--) |
| 610 |
{ |
| 611 |
if (*inq > fmax) |
| 612 |
{ |
| 613 |
fy = nry; |
| 614 |
fmax = *inq; |
| 615 |
} |
| 616 |
inq -= npix[0]; |
| 617 |
} |
| 618 |
if (fy > -1) |
| 619 |
{ |
| 620 |
*outq = fy; |
| 621 |
ypix1 = fy; |
| 622 |
} |
| 623 |
|
| 624 |
outq ++; |
| 625 |
} |
| 626 |
} |
| 627 |
else |
| 628 |
{ |
| 629 |
if (xpix1 < 1) /* no start pixel given */ |
| 630 |
{ |
| 631 |
for (nrx=sublo[0]; nrx<=subhi[0]; nrx++) |
| 632 |
{ |
| 633 |
outq = lpntr + nrx; |
| 634 |
inq = inp + nrx; |
| 635 |
for (nry=subhi[1]; nry>= sublo[1]; nry--) |
| 636 |
{ |
| 637 |
if (*inq >= val) |
| 638 |
{ |
| 639 |
*outq = nry; |
| 640 |
xpix1 = nrx; |
| 641 |
ypix1 = nry; |
| 642 |
goto win_22; |
| 643 |
} |
| 644 |
inq -= npix[0]; /* move to previous line */ |
| 645 |
} |
| 646 |
} |
| 647 |
SCETER(110,"no start pixel for window option found... "); |
| 648 |
} |
| 649 |
win_22: |
| 650 |
outq = lpntr + xpix1 + 1; /* point to next element */ |
| 651 |
|
| 652 |
|
| 653 |
/* here we either have single value or band */ |
| 654 |
|
| 655 |
if (fx[4] > 1.0) |
| 656 |
{ |
| 657 |
valx = fx[1]; |
| 658 |
for (nrx=xpix1+1;nrx<=subhi[0]; nrx++) |
| 659 |
{ |
| 660 |
my = ypix1 + ws2; |
| 661 |
if (my > subhi[1]) my = subhi[1]; |
| 662 |
ky = my - wsize; |
| 663 |
if (ky < sublo[1]) ky = sublo[1] - 1; |
| 664 |
inq = pntri + nrx + (my*npix[0]); /* point to hi w_start */ |
| 665 |
for (nry=my; nry>ky; nry--) |
| 666 |
{ |
| 667 |
if ((*inq >= val) && (*inq <= valx)) |
| 668 |
{ |
| 669 |
*outq = nry; |
| 670 |
ypix1 = nry; |
| 671 |
break; |
| 672 |
} |
| 673 |
inq -= npix[0]; |
| 674 |
} |
| 675 |
outq ++; |
| 676 |
} |
| 677 |
} |
| 678 |
else |
| 679 |
{ |
| 680 |
for (nrx=xpix1+1;nrx<=subhi[0]; nrx++) |
| 681 |
{ |
| 682 |
my = ypix1 + ws2; |
| 683 |
if (my > subhi[1]) my = subhi[1]; |
| 684 |
ky = my - wsize; |
| 685 |
if (ky < sublo[1]) ky = sublo[1] - 1; |
| 686 |
inq = pntri + nrx + (my*npix[0]); /* point to hi w_start */ |
| 687 |
for (nry=my; nry>ky; nry--) |
| 688 |
{ |
| 689 |
if (*inq >= val) |
| 690 |
{ |
| 691 |
*outq = nry; |
| 692 |
ypix1 = nry; |
| 693 |
break; |
| 694 |
} |
| 695 |
inq -= npix[0]; |
| 696 |
} |
| 697 |
outq ++; |
| 698 |
} |
| 699 |
} |
| 700 |
} |
| 701 |
} |
| 702 |
goto common_work; |
| 703 |
} |
| 704 |
|
| 705 |
|
| 706 |
/* ----------------------------------------- |
| 707 |
else we work on the dynamic WINDOW option |
| 708 |
----------------------------------------- */ |
| 709 |
|
| 710 |
if (optio[1] == 'D') |
| 711 |
{ |
| 712 |
ws2 = wsize / 2; |
| 713 |
|
| 714 |
|
| 715 |
/* and split for BOTTOM or TOP direction */ |
| 716 |
|
| 717 |
if (optio[0] == 'B') |
| 718 |
{ |
| 719 |
inp = pntri + (sublo[1]*npix[0]); |
| 720 |
|
| 721 |
if (xpix1 < 1) /* no start pixel given */ |
| 722 |
{ |
| 723 |
for (nrx=sublo[0]; nrx<=subhi[0]; nrx++) |
| 724 |
{ |
| 725 |
outq = lpntr + nrx; |
| 726 |
inq = inp + nrx; |
| 727 |
for (nry=sublo[1]; nry<= subhi[1]; nry++) |
| 728 |
{ |
| 729 |
if (*inq >= val) |
| 730 |
{ |
| 731 |
*outq = nry; |
| 732 |
xpix1 = nrx; |
| 733 |
ypix1 = nry; |
| 734 |
goto win_111; |
| 735 |
} |
| 736 |
inq += npix[0]; /* move to next line */ |
| 737 |
} |
| 738 |
} |
| 739 |
SCETER(110,"no start pixel for window option found... "); |
| 740 |
} |
| 741 |
win_111: |
| 742 |
outq = lpntr + xpix1 + 1; /* point to next element */ |
| 743 |
|
| 744 |
|
| 745 |
/* here we either have single value or band */ |
| 746 |
|
| 747 |
if (fx[4] > 1.0) |
| 748 |
{ |
| 749 |
valx = fx[1]; |
| 750 |
for (nrx=xpix1+1;nrx<=subhi[0]; nrx++) |
| 751 |
{ |
| 752 |
for (ky=0; ky<ws2; ky++) |
| 753 |
{ |
| 754 |
my = ypix1 - ky; |
| 755 |
if (my < sublo[1]) |
| 756 |
{ |
| 757 |
limi = 1; |
| 758 |
my = sublo[1]; |
| 759 |
} |
| 760 |
else |
| 761 |
limi = 0; |
| 762 |
if (my < sublo[1]) my = sublo[1]; |
| 763 |
inq = pntri + nrx + (my*npix[0]); /* move to lower end */ |
| 764 |
if ((*inq >= val) && (*inq <= valx)) |
| 765 |
{ |
| 766 |
win_1140: |
| 767 |
*outq = my; |
| 768 |
ypix1 = my; |
| 769 |
if (limi == 1) goto win_115; |
| 770 |
my --; |
| 771 |
if (my < sublo[1]) goto win_115; |
| 772 |
inq -= npix[0]; |
| 773 |
if ((*inq >= val) && (*inq <= valx)) |
| 774 |
goto win_1140; |
| 775 |
else |
| 776 |
goto win_115; |
| 777 |
} |
| 778 |
my = ypix1 + ky; |
| 779 |
if (my > subhi[1]) my = subhi[1]; |
| 780 |
inq = pntri + nrx + (my*npix[0]); /* move to upper end */ |
| 781 |
if ((*inq >= val) && (*inq <= valx)) |
| 782 |
{ |
| 783 |
*outq = my; |
| 784 |
ypix1 = my; |
| 785 |
goto win_115; |
| 786 |
} |
| 787 |
} |
| 788 |
win_115: |
| 789 |
outq ++; |
| 790 |
} |
| 791 |
} |
| 792 |
else |
| 793 |
{ |
| 794 |
for (nrx=xpix1+1;nrx<=subhi[0]; nrx++) |
| 795 |
{ |
| 796 |
for (ky=0; ky<ws2; ky++) |
| 797 |
{ |
| 798 |
my = ypix1 - ky; |
| 799 |
if (my < sublo[1]) |
| 800 |
{ |
| 801 |
limi = 1; |
| 802 |
my = sublo[1]; |
| 803 |
} |
| 804 |
else |
| 805 |
limi = 0; |
| 806 |
inq = pntri + nrx + (my*npix[0]); /* move to lower end */ |
| 807 |
if (*inq >= val) |
| 808 |
{ |
| 809 |
win_1150: |
| 810 |
*outq = my; |
| 811 |
ypix1 = my; |
| 812 |
if (limi == 1) goto win_116; |
| 813 |
my --; |
| 814 |
if (my < sublo[1]) goto win_116; |
| 815 |
inq -= npix[0]; |
| 816 |
if (*inq >= val) |
| 817 |
goto win_1150; |
| 818 |
else |
| 819 |
goto win_116; |
| 820 |
} |
| 821 |
my = ypix1 + ky; |
| 822 |
if (my > subhi[1]) my = subhi[1]; |
| 823 |
inq = pntri + nrx + (my*npix[0]); /* move to upper end */ |
| 824 |
if (*inq >= val) |
| 825 |
{ |
| 826 |
*outq = my; |
| 827 |
ypix1 = my; |
| 828 |
goto win_116; |
| 829 |
} |
| 830 |
} |
| 831 |
win_116: |
| 832 |
outq ++; |
| 833 |
} |
| 834 |
} |
| 835 |
} |
| 836 |
|
| 837 |
else /* first look up then down */ |
| 838 |
{ |
| 839 |
inp = pntri + (subhi[1]*npix[0]); |
| 840 |
if (xpix1 < 1) /* no start pixel given */ |
| 841 |
{ |
| 842 |
for (nrx=sublo[0]; nrx<=subhi[0]; nrx++) |
| 843 |
{ |
| 844 |
outq = lpntr + nrx; |
| 845 |
inq = inp + nrx; |
| 846 |
for (nry=subhi[1]; nry>= sublo[1]; nry--) |
| 847 |
{ |
| 848 |
if (*inq >= val) |
| 849 |
{ |
| 850 |
*outq = nry; |
| 851 |
xpix1 = nrx; |
| 852 |
ypix1 = nry; |
| 853 |
goto win_222; |
| 854 |
} |
| 855 |
inq -= npix[0]; /* move to previous line */ |
| 856 |
} |
| 857 |
} |
| 858 |
SCETER(110,"no start pixel for window option found... "); |
| 859 |
} |
| 860 |
win_222: |
| 861 |
outq = lpntr + xpix1 + 1; /* point to next element */ |
| 862 |
|
| 863 |
|
| 864 |
/* here we either have single value or band */ |
| 865 |
|
| 866 |
if (fx[4] > 1.0) |
| 867 |
{ |
| 868 |
valx = fx[1]; |
| 869 |
for (nrx=xpix1+1;nrx<=subhi[0]; nrx++) |
| 870 |
{ |
| 871 |
for (ky=0; ky<ws2; ky++) |
| 872 |
{ |
| 873 |
my = ypix1 + ky; |
| 874 |
if (my > subhi[1]) |
| 875 |
{ |
| 876 |
limi = 1; |
| 877 |
my = subhi[1]; |
| 878 |
} |
| 879 |
else |
| 880 |
limi = 0; |
| 881 |
inq = pntri + nrx + (my*npix[0]); /* move to upper end */ |
| 882 |
if ((*inq >= val) && (*inq <= valx)) |
| 883 |
{ |
| 884 |
win_2240: |
| 885 |
*outq = my; |
| 886 |
ypix1 = my; |
| 887 |
if (limi == 1) goto win_225; |
| 888 |
my++ ; |
| 889 |
if (my > subhi[1]) goto win_225; |
| 890 |
inq += npix[0]; |
| 891 |
if ((*inq >= val) && (*inq <= valx)) |
| 892 |
goto win_2240; |
| 893 |
else |
| 894 |
goto win_225; |
| 895 |
} |
| 896 |
my = ypix1 - ky; |
| 897 |
if (my < sublo[1]) my = sublo[1]; |
| 898 |
inq = pntri + nrx + (my*npix[0]); /* move to lower end */ |
| 899 |
if ((*inq >= val) && (*inq <= valx)) |
| 900 |
{ |
| 901 |
*outq = my; |
| 902 |
ypix1 = my; |
| 903 |
goto win_225; |
| 904 |
} |
| 905 |
} |
| 906 |
win_225: |
| 907 |
outq ++; |
| 908 |
} |
| 909 |
} |
| 910 |
else |
| 911 |
{ |
| 912 |
for (nrx=xpix1+1;nrx<=subhi[0]; nrx++) |
| 913 |
{ |
| 914 |
for (ky=0; ky<ws2; ky++) |
| 915 |
{ |
| 916 |
my = ypix1 + ky; |
| 917 |
if (my > subhi[1]) |
| 918 |
{ |
| 919 |
limi = 1; |
| 920 |
my = subhi[1]; |
| 921 |
} |
| 922 |
else |
| 923 |
limi = 0; |
| 924 |
inq = pntri + nrx + (my*npix[0]); /* move to upper end */ |
| 925 |
if (*inq >= val) |
| 926 |
{ |
| 927 |
win_2250: |
| 928 |
*outq = my; |
| 929 |
ypix1 = my; |
| 930 |
if (limi == 1) goto win_226; |
| 931 |
my++ ; |
| 932 |
if (my > subhi[1]) goto win_226; |
| 933 |
inq += npix[0]; |
| 934 |
if (*inq >= val) |
| 935 |
goto win_2250; |
| 936 |
else |
| 937 |
goto win_226; |
| 938 |
} |
| 939 |
my = ypix1 - ky; |
| 940 |
if (my < sublo[1]) my = sublo[1]; |
| 941 |
inq = pntri + nrx + (my*npix[0]); /* move to loer end */ |
| 942 |
if (*inq >= val) |
| 943 |
{ |
| 944 |
*outq = my; |
| 945 |
ypix1 = my; |
| 946 |
goto win_226; |
| 947 |
} |
| 948 |
} |
| 949 |
win_226: |
| 950 |
outq ++; |
| 951 |
} |
| 952 |
} |
| 953 |
} |
| 954 |
|
| 955 |
goto common_work; |
| 956 |
} |
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
/* --------------------------------- |
| 962 |
else we work on the GLOBAL option |
| 963 |
--------------------------------- */ |
| 964 |
|
| 965 |
inq = pntri + (sublo[1]*npix[0]); |
| 966 |
inp = inq; |
| 967 |
|
| 968 |
|
| 969 |
/* and split for BOTTOM or TOP direction */ |
| 970 |
|
| 971 |
if (optio[0] == 'B') |
| 972 |
{ |
| 973 |
|
| 974 |
|
| 975 |
/* split for Maximum or Value option */ |
| 976 |
|
| 977 |
if (optio[2] == 'M') /* search for max value */ |
| 978 |
{ |
| 979 |
inp = pntri + (sublo[1]*npix[0]); /* point to bottom line */ |
| 980 |
for (nrx=sublo[0]; nrx<subhi[0]; nrx++) |
| 981 |
{ |
| 982 |
fmax = val*0.99; |
| 983 |
fy = -1; |
| 984 |
outq = lpntr + nrx; |
| 985 |
inq = inp + nrx; |
| 986 |
for (nry=sublo[1]; nry<=subhi[1]; nry++) |
| 987 |
{ |
| 988 |
if (*inq > fmax) |
| 989 |
{ |
| 990 |
fy = nry; |
| 991 |
fmax = *inq; |
| 992 |
} |
| 993 |
inq += npix[0]; |
| 994 |
} |
| 995 |
if (fy > -1) *outq = fy; |
| 996 |
} |
| 997 |
} |
| 998 |
|
| 999 |
else |
| 1000 |
{ |
| 1001 |
if (fx[4] > 1.0) |
| 1002 |
{ |
| 1003 |
valx = fx[1]; |
| 1004 |
for (nry=sublo[1]; nry<=subhi[1]; nry++) |
| 1005 |
{ |
| 1006 |
inq = inp + sublo[0]; |
| 1007 |
for (nrx=sublo[0]; nrx<subhi[0]; nrx++) |
| 1008 |
{ |
| 1009 |
if ((*inq >= val) && (*inq <= valx)) |
| 1010 |
{ |
| 1011 |
outq = lpntr + nrx; |
| 1012 |
if (*outq < 0.0) *outq = nry; /* store lowest y-pos */ |
| 1013 |
} |
| 1014 |
inq ++; |
| 1015 |
} |
| 1016 |
inp += npix[0]; |
| 1017 |
} |
| 1018 |
} |
| 1019 |
else |
| 1020 |
{ |
| 1021 |
for (nry=sublo[1]; nry<=subhi[1]; nry++) |
| 1022 |
{ |
| 1023 |
inq = inp + sublo[0]; |
| 1024 |
for (nrx=sublo[0]; nrx<subhi[0]; nrx++) |
| 1025 |
{ |
| 1026 |
if (*inq >= val) |
| 1027 |
{ |
| 1028 |
outq = lpntr + nrx; |
| 1029 |
if (*outq < 0.0) *outq = nry; /* store lowest y-pos */ |
| 1030 |
} |
| 1031 |
inq ++; |
| 1032 |
} |
| 1033 |
inp += npix[0]; |
| 1034 |
} |
| 1035 |
} |
| 1036 |
} |
| 1037 |
} |
| 1038 |
|
| 1039 |
else |
| 1040 |
{ |
| 1041 |
|
| 1042 |
|
| 1043 |
/* split for Maximum or Value option */ |
| 1044 |
|
| 1045 |
if (optio[2] == 'M') /* search for max value */ |
| 1046 |
{ |
| 1047 |
inp = pntri + (subhi[1]*npix[0]); /* point to top line */ |
| 1048 |
inq = inp + sublo[0]; |
| 1049 |
outq = lpntr + sublo[0]; |
| 1050 |
for (nrx=sublo[0]; nrx<subhi[0]; nrx++) |
| 1051 |
{ |
| 1052 |
fmax = val*0.99; |
| 1053 |
fy = -1; |
| 1054 |
for (nry=subhi[1]; nry>=sublo[1]; nry--) |
| 1055 |
{ |
| 1056 |
if (*inq > fmax) |
| 1057 |
{ |
| 1058 |
fy = nry; |
| 1059 |
fmax = *inq; |
| 1060 |
} |
| 1061 |
inq -= npix[0]; |
| 1062 |
} |
| 1063 |
if (fy > -1) *outq = fy; |
| 1064 |
inp ++; |
| 1065 |
outq ++; |
| 1066 |
} |
| 1067 |
} |
| 1068 |
|
| 1069 |
else |
| 1070 |
{ |
| 1071 |
if (fx[4] > 1.0) |
| 1072 |
{ |
| 1073 |
valx = fx[1]; |
| 1074 |
for (nry=sublo[1]; nry<=subhi[1]; nry++) |
| 1075 |
{ |
| 1076 |
inq = inp + sublo[0]; |
| 1077 |
for (nrx=sublo[0]; nrx<subhi[0]; nrx++) |
| 1078 |
{ |
| 1079 |
if ((*inq >= val) && (*inq <= valx)) |
| 1080 |
{ |
| 1081 |
outq = lpntr + nrx; |
| 1082 |
*outq = nry; /* always store highest y-position */ |
| 1083 |
} |
| 1084 |
inq ++; |
| 1085 |
} |
| 1086 |
inp += npix[0]; |
| 1087 |
} |
| 1088 |
} |
| 1089 |
else |
| 1090 |
{ |
| 1091 |
for (nry=sublo[1]; nry<=subhi[1]; nry++) |
| 1092 |
{ |
| 1093 |
inq = inp + sublo[0]; |
| 1094 |
for (nrx=sublo[0]; nrx<subhi[0]; nrx++) |
| 1095 |
{ |
| 1096 |
if (*inq >= val) |
| 1097 |
{ |
| 1098 |
outq = lpntr + nrx; |
| 1099 |
*outq = nry; /* always store highest y-position */ |
| 1100 |
} |
| 1101 |
inq ++; |
| 1102 |
} |
| 1103 |
inp += npix[0]; |
| 1104 |
} |
| 1105 |
} |
| 1106 |
} |
| 1107 |
} |
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
common_work: |
| 1112 |
kstart = -1; /* get first pixel above threshold */ |
| 1113 |
outq = pntro; |
| 1114 |
for (nrx=0; nrx<npix[0]; nrx++) |
| 1115 |
{ |
| 1116 |
if (*outq > (-1.0)) |
| 1117 |
{ |
| 1118 |
kstart = nrx; |
| 1119 |
break; |
| 1120 |
} |
| 1121 |
outq ++; |
| 1122 |
} |
| 1123 |
|
| 1124 |
if (kstart < 0) return (-1); |
| 1125 |
|
| 1126 |
|
| 1127 |
outq = pntro + npix[0] - 1; |
| 1128 |
for (nrx=npix[0]; nrx>kstart; nrx--) |
| 1129 |
{ |
| 1130 |
if (*outq > (-1.0)) |
| 1131 |
{ |
| 1132 |
end = nrx-1; |
| 1133 |
break; |
| 1134 |
} |
| 1135 |
outq --; |
| 1136 |
} |
| 1137 |
|
| 1138 |
if (kstart == end) |
| 1139 |
{ |
| 1140 |
*pntro = *(pntro+kstart); |
| 1141 |
return (1); /* just 1 pixel... */ |
| 1142 |
} |
| 1143 |
|
| 1144 |
count = end - kstart + 1; /* no. of pixels */ |
| 1145 |
|
| 1146 |
|
| 1147 |
/* move to front, if necessary */ |
| 1148 |
|
| 1149 |
if (kstart > 0) |
| 1150 |
{ |
| 1151 |
inq = pntro; |
| 1152 |
outq = pntro + kstart; |
| 1153 |
for (nrx=0; nrx<count; nrx++) |
| 1154 |
{ |
| 1155 |
*inq++ = *outq++; |
| 1156 |
} |
| 1157 |
} |
| 1158 |
|
| 1159 |
|
| 1160 |
/* for tables we're already done */ |
| 1161 |
|
| 1162 |
if (optio[4] == 'T') return (count); |
| 1163 |
|
| 1164 |
|
| 1165 |
/* for image, look for holes + get max. hole size */ |
| 1166 |
|
| 1167 |
inq = pntro + 1; |
| 1168 |
kk = 0; kmax = 0; mm = 0; |
| 1169 |
for (nrx=1; nrx<count; nrx++) |
| 1170 |
{ |
| 1171 |
if (*inq < 0.0) |
| 1172 |
{ |
| 1173 |
mm ++; |
| 1174 |
kk ++; |
| 1175 |
} |
| 1176 |
else |
| 1177 |
{ |
| 1178 |
if (kk > kmax) kmax = kk; |
| 1179 |
kk = 0; |
| 1180 |
} |
| 1181 |
inq ++; |
| 1182 |
} |
| 1183 |
if (kk > kmax) kmax = kk; /* don't forget last */ |
| 1184 |
|
| 1185 |
|
| 1186 |
if (mm > 0) /* we must have at least 3 pixels */ |
| 1187 |
{ |
| 1188 |
(void) sprintf(cbuf,"%d holes of max. %d size detected ...",mm,kmax); |
| 1189 |
SCTPUT(cbuf); |
| 1190 |
|
| 1191 |
mm = 0; |
| 1192 |
inq = pntro + 1; |
| 1193 |
while(inq < (pntro+count)) |
| 1194 |
{ |
| 1195 |
if (*inq < 0.0) |
| 1196 |
{ |
| 1197 |
outq = inq + 1; /* inq-1 is != -1 ... */ |
| 1198 |
if (*outq < 0.0) |
| 1199 |
{ |
| 1200 |
loop: |
| 1201 |
inq ++ ; |
| 1202 |
outq = inq + 1; /* inq-1 is != -1 ... */ |
| 1203 |
if (*outq < 0.0) |
| 1204 |
goto loop; |
| 1205 |
else |
| 1206 |
goto next; |
| 1207 |
} |
| 1208 |
*inq = (*(inq-1)+*outq)/2; /* interpolate */ |
| 1209 |
} |
| 1210 |
next: |
| 1211 |
inq ++; |
| 1212 |
} |
| 1213 |
} |
| 1214 |
|
| 1215 |
return (count); |
| 1216 |
|
| 1217 |
} |