8 |
|
* 6/23/93 Added additional buffers for value spreading |
9 |
|
*/ |
10 |
|
|
11 |
< |
#include <signal.h> |
11 |
> |
#include "copyright.h" |
12 |
|
|
13 |
< |
#include "standard.h" |
14 |
< |
#include "color.h" |
15 |
< |
#include "view.h" |
13 |
> |
#include <signal.h> |
14 |
> |
#include "pfilt.h" |
15 |
> |
#include "platform.h" |
16 |
|
#include "paths.h" |
17 |
+ |
#include "view.h" |
18 |
|
|
18 |
– |
extern float *matchlamp(); |
19 |
– |
|
19 |
|
#define FEQ(a,b) ((a) >= .98*(b) && (a) <= 1.02*(b)) |
20 |
|
|
21 |
|
double CHECKRAD = 2.0; /* radius to check for filtering */ |
69 |
|
int ybrad; /* y box size */ |
70 |
|
|
71 |
|
int barsize; /* size of input scan bar */ |
72 |
< |
COLOR **scanin; /* input scan bar */ |
73 |
< |
COLOR *scanout; /* output scan line */ |
74 |
< |
COLOR **scoutbar; /* output scan bar (if thresh > 0) */ |
72 |
> |
COLORV **scanin; /* input scan bar */ |
73 |
> |
COLORV *scanout; /* output scan line */ |
74 |
> |
COLORV **scoutbar; /* output scan bar (if thresh > 0) */ |
75 |
|
float **greybar; /* grey-averaged input values */ |
76 |
|
int obarsize = 0; /* size of output scan bar */ |
77 |
|
int orad = 0; /* output window radius */ |
78 |
|
|
79 |
|
char *progname; |
80 |
|
|
81 |
+ |
static void copyfile(FILE *infp, FILE *out); |
82 |
+ |
static void pass1(FILE *infp); |
83 |
+ |
static void pass2(FILE *infp); |
84 |
+ |
static void scan2init(void); |
85 |
+ |
static void scan2sync(int r); |
86 |
+ |
static void scan2flush(void); |
87 |
|
|
88 |
< |
main(argc, argv) |
89 |
< |
int argc; |
90 |
< |
char **argv; |
88 |
> |
|
89 |
> |
static double |
90 |
> |
rgb_bright( |
91 |
> |
SCOLOR clr |
92 |
> |
) |
93 |
|
{ |
94 |
< |
extern int headline(); |
94 |
> |
return(bright(clr)); |
95 |
> |
} |
96 |
> |
|
97 |
> |
|
98 |
> |
static double |
99 |
> |
xyz_bright( |
100 |
> |
SCOLOR clr |
101 |
> |
) |
102 |
> |
{ |
103 |
> |
return(colval(clr,CIEY)); |
104 |
> |
} |
105 |
> |
|
106 |
> |
|
107 |
> |
static double |
108 |
> |
spec_bright( |
109 |
> |
SCOLOR clr |
110 |
> |
) |
111 |
> |
{ |
112 |
> |
return(pbright(clr)); |
113 |
> |
} |
114 |
> |
|
115 |
> |
|
116 |
> |
brightfunc_t *ourbright = rgb_bright; |
117 |
> |
|
118 |
> |
|
119 |
> |
static int |
120 |
> |
headline( /* process line from header */ |
121 |
> |
char *s, |
122 |
> |
void *p |
123 |
> |
) |
124 |
> |
{ |
125 |
> |
char fmt[MAXFMTLEN]; |
126 |
> |
|
127 |
> |
fputs(s, stdout); /* copy to output */ |
128 |
> |
if (isaspect(s)) /* get aspect ratio */ |
129 |
> |
inpaspect *= aspectval(s); |
130 |
> |
else if (isexpos(s)) /* get exposure */ |
131 |
> |
hotlvl *= exposval(s); |
132 |
> |
else if (isncomp(s)) /* get #components (spectral) */ |
133 |
> |
NCSAMP = ncompval(s); |
134 |
> |
else if (iswlsplit(s)) /* get wavelength partitions */ |
135 |
> |
wlsplitval(WLPART, s); |
136 |
> |
else if (formatval(fmt, s)) { /* get format */ |
137 |
> |
wrongformat = 0; |
138 |
> |
if (!strcmp(COLRFMT, fmt)) |
139 |
> |
ourbright = rgb_bright; |
140 |
> |
else if (!strcmp(CIEFMT, fmt)) |
141 |
> |
ourbright = xyz_bright; |
142 |
> |
else if (!strcmp(SPECFMT, fmt)) |
143 |
> |
ourbright = spec_bright; |
144 |
> |
else |
145 |
> |
wrongformat = !globmatch(PICFMT, fmt); |
146 |
> |
} else if (isview(s) && sscanview(&ourview, s) > 0) |
147 |
> |
gotview++; |
148 |
> |
return(0); |
149 |
> |
} |
150 |
> |
|
151 |
> |
|
152 |
> |
int |
153 |
> |
main( |
154 |
> |
int argc, |
155 |
> |
char **argv |
156 |
> |
) |
157 |
> |
{ |
158 |
|
FILE *fin; |
159 |
|
float *lampcolor; |
160 |
|
char *lamptype = NULL; |
167 |
|
SET_FILE_BINARY(stdout); |
168 |
|
if (signal(SIGINT, quit) == SIG_IGN) |
169 |
|
signal(SIGINT, SIG_IGN); |
170 |
+ |
#ifdef SIGHUP |
171 |
|
if (signal(SIGHUP, quit) == SIG_IGN) |
172 |
|
signal(SIGHUP, SIG_IGN); |
173 |
+ |
#endif |
174 |
|
signal(SIGTERM, quit); |
175 |
+ |
#ifdef SIGPIPE |
176 |
|
signal(SIGPIPE, quit); |
177 |
+ |
#endif |
178 |
|
#ifdef SIGXCPU |
179 |
|
signal(SIGXCPU, quit); |
180 |
|
signal(SIGXFSZ, quit); |
300 |
|
fin = stdin; |
301 |
|
else { |
302 |
|
tfname = mktemp(template); |
303 |
< |
if ((fin = fopen(tfname, "w+")) == NULL) { |
303 |
> |
if ((fin = fopen(tfname, "w+b")) == NULL) { |
304 |
|
fprintf(stderr, "%s: can't create ", progname); |
305 |
|
fprintf(stderr, "temp file \"%s\"\n", tfname); |
306 |
|
quit(1); |
312 |
|
} |
313 |
|
} |
314 |
|
} else if (i == argc-1) { |
315 |
< |
if ((fin = fopen(argv[i], "r")) == NULL) { |
315 |
> |
if ((fin = fopen(argv[i], "rb")) == NULL) { |
316 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
317 |
|
progname, argv[i]); |
318 |
|
quit(1); |
328 |
|
progname); |
329 |
|
quit(1); |
330 |
|
} |
331 |
+ |
if ((ourbright == spec_bright) ^ (NCSAMP > 3) || |
332 |
+ |
setspectrsamp(CNDX, WLPART) < 0) { |
333 |
+ |
fprintf(stderr, "%s: bad number of components\n", progname); |
334 |
+ |
quit(1); |
335 |
+ |
} |
336 |
|
/* add new header info. */ |
337 |
|
printargs(i, argv, stdout); |
338 |
|
/* get picture size */ |
377 |
|
pass2(fin); |
378 |
|
|
379 |
|
quit(estatus); |
380 |
+ |
return estatus; /* pro forma return */ |
381 |
|
} |
382 |
|
|
383 |
|
|
384 |
< |
double |
385 |
< |
rgb_bright(clr) |
386 |
< |
COLOR clr; |
384 |
> |
static void |
385 |
> |
copyfile( /* copy a file */ |
386 |
> |
FILE *infp, |
387 |
> |
FILE *out |
388 |
> |
) |
389 |
|
{ |
390 |
< |
return(bright(clr)); |
309 |
< |
} |
390 |
> |
int c; |
391 |
|
|
392 |
< |
|
312 |
< |
double |
313 |
< |
xyz_bright(clr) |
314 |
< |
COLOR clr; |
315 |
< |
{ |
316 |
< |
return(clr[CIEY]); |
317 |
< |
} |
318 |
< |
|
319 |
< |
|
320 |
< |
double (*ourbright)() = rgb_bright; |
321 |
< |
|
322 |
< |
|
323 |
< |
int |
324 |
< |
headline(s) /* process line from header */ |
325 |
< |
char *s; |
326 |
< |
{ |
327 |
< |
char fmt[32]; |
328 |
< |
|
329 |
< |
fputs(s, stdout); /* copy to output */ |
330 |
< |
if (isaspect(s)) /* get aspect ratio */ |
331 |
< |
inpaspect *= aspectval(s); |
332 |
< |
else if (isexpos(s)) /* get exposure */ |
333 |
< |
hotlvl *= exposval(s); |
334 |
< |
else if (formatval(fmt, s)) { /* get format */ |
335 |
< |
wrongformat = 0; |
336 |
< |
if (!strcmp(COLRFMT, fmt)) |
337 |
< |
ourbright = rgb_bright; |
338 |
< |
else if (!strcmp(CIEFMT, fmt)) |
339 |
< |
ourbright = xyz_bright; |
340 |
< |
else |
341 |
< |
wrongformat = !globmatch(PICFMT, fmt); |
342 |
< |
} else if (isview(s) && sscanview(&ourview, s) > 0) |
343 |
< |
gotview++; |
344 |
< |
return(0); |
345 |
< |
} |
346 |
< |
|
347 |
< |
|
348 |
< |
copyfile(in, out) /* copy a file */ |
349 |
< |
register FILE *in, *out; |
350 |
< |
{ |
351 |
< |
register int c; |
352 |
< |
|
353 |
< |
while ((c = getc(in)) != EOF) |
392 |
> |
while ((c = getc(infp)) != EOF) |
393 |
|
putc(c, out); |
394 |
|
|
395 |
|
if (ferror(out)) { |
399 |
|
} |
400 |
|
|
401 |
|
|
402 |
< |
pass1(in) /* first pass of picture file */ |
403 |
< |
FILE *in; |
402 |
> |
static void |
403 |
> |
pass1( /* first pass of picture file */ |
404 |
> |
FILE *infp |
405 |
> |
) |
406 |
|
{ |
407 |
|
int i; |
408 |
< |
COLOR *scan; |
408 |
> |
COLORV *scan; |
409 |
|
|
410 |
|
pass1init(); |
411 |
|
|
412 |
< |
scan = (COLOR *)malloc(xres*sizeof(COLOR)); |
412 |
> |
scan = (COLORV *)malloc(xres*NCSAMP*sizeof(COLORV)); |
413 |
|
if (scan == NULL) { |
414 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
415 |
|
quit(1); |
416 |
|
} |
417 |
|
for (i = 0; i < yres; i++) { |
418 |
< |
if (freadscan(scan, xres, in) < 0) { |
418 |
> |
if (freadsscan(scan, NCSAMP, xres, infp) < 0) { |
419 |
|
nrows = (long)nrows * i / yres; /* adjust frame */ |
420 |
|
if (nrows <= 0) { |
421 |
|
fprintf(stderr, "%s: empty frame\n", progname); |
430 |
|
} |
431 |
|
pass1scan(scan, i); |
432 |
|
} |
433 |
< |
free((void *)scan); |
433 |
> |
free(scan); |
434 |
|
} |
435 |
|
|
436 |
|
|
437 |
< |
pass2(in) /* last pass on file, write to stdout */ |
438 |
< |
FILE *in; |
437 |
> |
static void |
438 |
> |
pass2( /* last pass on file, write to stdout */ |
439 |
> |
FILE *infp |
440 |
> |
) |
441 |
|
{ |
442 |
|
int yread; |
443 |
|
int ycent, xcent; |
450 |
|
ycent = (r+.5)*yres/nrows; |
451 |
|
while (yread <= ycent+yrad) { |
452 |
|
if (yread < yres) { |
453 |
< |
if (freadscan(scanin[yread%barsize], |
454 |
< |
xres, in) < 0) { |
453 |
> |
if (freadsscan(scanin[yread%barsize], |
454 |
> |
NCSAMP, xres, infp) < 0) { |
455 |
|
fprintf(stderr, |
456 |
|
"%s: truncated input (y=%d)\n", |
457 |
|
progname, yres-1-yread); |
461 |
|
} |
462 |
|
yread++; |
463 |
|
} |
464 |
< |
if (obarsize > 0) |
464 |
> |
if (obarsize > 0) /* => thresh > FTINY */ |
465 |
|
scan2sync(r); |
466 |
|
for (c = 0; c < ncols; c++) { |
467 |
|
xcent = (c+.5)*xres/ncols; |
468 |
|
if (thresh > FTINY) |
469 |
|
dothresh(xcent, ycent, c, r); |
470 |
|
else if (rad > FTINY) |
471 |
< |
dogauss(scanout[c], xcent, ycent, c, r); |
471 |
> |
dogauss(scanout+c*NCSAMP, xcent, ycent, c, r); |
472 |
|
else |
473 |
< |
dobox(scanout[c], xcent, ycent, c, r); |
473 |
> |
dobox(scanout+c*NCSAMP, xcent, ycent, c, r); |
474 |
|
} |
475 |
< |
if (scanout != NULL && fwritescan(scanout, ncols, stdout) < 0) { |
475 |
> |
if (scanout != NULL && fwritesscan(scanout, NCSAMP, ncols, stdout) < 0) { |
476 |
|
fprintf(stderr, "%s: write error in pass2\n", progname); |
477 |
|
quit(1); |
478 |
|
} |
479 |
|
} |
480 |
|
/* skip leftover input */ |
481 |
|
while (yread < yres) { |
482 |
< |
if (freadscan(scanin[0], xres, in) < 0) |
482 |
> |
if (freadscolrs((uby8 *)tempbuffer(xres*(NCSAMP+1)), |
483 |
> |
NCSAMP, xres, infp) < 0) |
484 |
|
break; |
485 |
|
yread++; |
486 |
|
} |
488 |
|
} |
489 |
|
|
490 |
|
|
491 |
< |
scan2init() /* prepare scanline arrays */ |
491 |
> |
static void |
492 |
> |
scan2init(void) /* prepare scanline arrays */ |
493 |
|
{ |
494 |
|
COLOR ctmp; |
495 |
|
double d; |
496 |
< |
register int i; |
496 |
> |
int i; |
497 |
|
|
498 |
|
xbrad = xres/ncols/2 + 1; |
499 |
|
ybrad = yres/nrows/2 + 1; |
516 |
|
yrad = ybrad; |
517 |
|
} |
518 |
|
barsize = 2*yrad + 1; |
519 |
< |
scanin = (COLOR **)malloc(barsize*sizeof(COLOR *)); |
519 |
> |
scanin = (COLORV **)malloc(barsize*sizeof(COLORV *)); |
520 |
|
if (scanin == NULL) |
521 |
|
goto memerr; |
522 |
|
for (i = 0; i < barsize; i++) { |
523 |
< |
scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR)); |
523 |
> |
scanin[i] = (COLORV *)malloc(xres*NCSAMP*sizeof(COLORV)); |
524 |
|
if (scanin[i] == NULL) |
525 |
|
goto memerr; |
526 |
|
} |
527 |
|
if (obarsize > 0) { |
528 |
< |
scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *)); |
528 |
> |
scoutbar = (COLORV **)malloc(obarsize*sizeof(COLORV *)); |
529 |
|
greybar = (float **)malloc(obarsize*sizeof(float *)); |
530 |
< |
if (scoutbar == NULL | greybar == NULL) |
530 |
> |
if ((scoutbar == NULL) | (greybar == NULL)) |
531 |
|
goto memerr; |
532 |
|
for (i = 0; i < obarsize; i++) { |
533 |
< |
scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR)); |
533 |
> |
scoutbar[i] = (COLORV *)malloc(ncols*NCSAMP*sizeof(COLORV)); |
534 |
|
greybar[i] = (float *)malloc(ncols*sizeof(float)); |
535 |
< |
if (scoutbar[i] == NULL | greybar[i] == NULL) |
535 |
> |
if ((scoutbar[i] == NULL) | (greybar[i] == NULL)) |
536 |
|
goto memerr; |
537 |
|
} |
538 |
|
} else { |
539 |
< |
scanout = (COLOR *)malloc(ncols*sizeof(COLOR)); |
539 |
> |
scanout = (COLORV *)malloc(ncols*NCSAMP*sizeof(COLORV)); |
540 |
|
if (scanout == NULL) |
541 |
|
goto memerr; |
542 |
|
} |
547 |
|
fputaspect(d, stdout); |
548 |
|
} |
549 |
|
/* record exposure */ |
550 |
< |
d = (*ourbright)(exposure); |
550 |
> |
d = bright(exposure); |
551 |
|
if (!FEQ(d,1.0)) |
552 |
|
fputexpos(d, stdout); |
553 |
|
/* record color correction */ |
566 |
|
} |
567 |
|
|
568 |
|
|
569 |
< |
scan2sync(r) /* synchronize grey averages and output scan */ |
570 |
< |
int r; |
569 |
> |
static void |
570 |
> |
scan2sync( /* synchronize grey averages and output scan */ |
571 |
> |
int r |
572 |
> |
) |
573 |
|
{ |
574 |
|
static int nextrow = 0; |
575 |
< |
COLOR ctmp; |
575 |
> |
SCOLOR ctmp; |
576 |
|
int ybot; |
577 |
< |
register int c; |
577 |
> |
int c; |
578 |
|
/* average input scanlines */ |
579 |
|
while (nextrow <= r+orad && nextrow < nrows) { |
580 |
|
ybot = (nextrow+.5)*yres/nrows; |
583 |
|
greybar[nextrow%obarsize][c] = (*ourbright)(ctmp); |
584 |
|
} |
585 |
|
/* and zero output scanline */ |
586 |
< |
bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR)); |
586 |
> |
memset(scoutbar[nextrow%obarsize], 0, ncols*NCSAMP*sizeof(COLORV)); |
587 |
|
nextrow++; |
588 |
|
} |
589 |
|
/* point to top scanline for output */ |
594 |
|
} |
595 |
|
|
596 |
|
|
597 |
< |
scan2flush() /* flush output buffer */ |
597 |
> |
static void |
598 |
> |
scan2flush(void) /* flush output buffer */ |
599 |
|
{ |
600 |
< |
register int r; |
600 |
> |
int r; |
601 |
|
|
602 |
|
for (r = nrows-orad; r < nrows; r++) |
603 |
< |
if (fwritescan(scoutbar[r%obarsize], ncols, stdout) < 0) |
603 |
> |
if (fwritesscan(scoutbar[r%obarsize], NCSAMP, ncols, stdout) < 0) |
604 |
|
break; |
605 |
|
if (fflush(stdout) < 0) { |
606 |
|
fprintf(stderr, "%s: write error at end of pass2\n", progname); |