1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
53 |
|
|
54 |
|
char *tfname = NULL; |
55 |
|
|
56 |
+ |
char template[] = TEMPLATE; |
57 |
+ |
|
58 |
|
char *lampdat = "lamp.tab"; /* lamp data file */ |
59 |
|
|
60 |
|
int order; /* scanline ordering of input */ |
102 |
|
if (signal(SIGINT, quit) == SIG_IGN) |
103 |
|
signal(SIGINT, SIG_IGN); |
104 |
|
if (signal(SIGHUP, quit) == SIG_IGN) |
105 |
< |
signal(SIGINT, SIG_IGN); |
105 |
> |
signal(SIGHUP, SIG_IGN); |
106 |
|
signal(SIGTERM, quit); |
107 |
|
signal(SIGPIPE, quit); |
108 |
|
#ifdef SIGXCPU |
219 |
|
fprintf(stderr, "%s: unknown lamp type\n", lamptype); |
220 |
|
quit(1); |
221 |
|
} |
222 |
< |
for (i = 0; i < 3; i++) |
223 |
< |
if (lampcolor[i] > 1e-4) |
224 |
< |
colval(exposure,i) /= lampcolor[i]; |
222 |
> |
for (j = 0; j < 3; j++) |
223 |
> |
if (lampcolor[j] > 1e-4) |
224 |
> |
colval(exposure,j) /= lampcolor[j]; |
225 |
|
freelamps(); |
226 |
|
} |
227 |
|
/* open input file */ |
229 |
|
if (singlepass) |
230 |
|
fin = stdin; |
231 |
|
else { |
232 |
< |
tfname = mktemp(TEMPLATE); |
232 |
> |
tfname = mktemp(template); |
233 |
|
if ((fin = fopen(tfname, "w+")) == NULL) { |
234 |
|
fprintf(stderr, "%s: can't create ", progname); |
235 |
|
fprintf(stderr, "temp file \"%s\"\n", tfname); |
302 |
|
} |
303 |
|
|
304 |
|
|
305 |
+ |
double |
306 |
+ |
rgb_bright(clr) |
307 |
+ |
COLOR clr; |
308 |
+ |
{ |
309 |
+ |
return(bright(clr)); |
310 |
+ |
} |
311 |
+ |
|
312 |
+ |
|
313 |
+ |
double |
314 |
+ |
xyz_bright(clr) |
315 |
+ |
COLOR clr; |
316 |
+ |
{ |
317 |
+ |
return(clr[CIEY]); |
318 |
+ |
} |
319 |
+ |
|
320 |
+ |
|
321 |
+ |
double (*ourbright)() = rgb_bright; |
322 |
+ |
|
323 |
+ |
|
324 |
|
headline(s) /* process line from header */ |
325 |
|
char *s; |
326 |
|
{ |
329 |
|
fputs(s, stdout); /* copy to output */ |
330 |
|
if (isaspect(s)) /* get aspect ratio */ |
331 |
|
inpaspect *= aspectval(s); |
332 |
< |
else if (isexpos(s)) |
332 |
> |
else if (isexpos(s)) /* get exposure */ |
333 |
|
hotlvl *= exposval(s); |
334 |
< |
else if (isformat(s)) { |
335 |
< |
formatval(fmt, s); |
336 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
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 |
|
} |
343 |
|
} |
344 |
|
|
407 |
|
if (freadscan(scanin[yread%barsize], |
408 |
|
xres, in) < 0) { |
409 |
|
fprintf(stderr, |
410 |
< |
"%s: bad read (y=%d)\n", |
410 |
> |
"%s: truncated input (y=%d)\n", |
411 |
|
progname, yres-1-yread); |
412 |
|
quit(1); |
413 |
|
} |
454 |
|
rad *= (y_r + x_c)/2.0; |
455 |
|
|
456 |
|
if (thresh > FTINY) { |
431 |
– |
xrad = CHECKRAD*THRESHRAD*rad/x_c + xbrad; |
432 |
– |
yrad = CHECKRAD*THRESHRAD*rad/y_r + ybrad; |
457 |
|
orad = CHECKRAD*THRESHRAD*rad + 1; |
458 |
+ |
xrad = orad/x_c + xbrad; |
459 |
+ |
yrad = orad/y_r + ybrad; |
460 |
|
obarsize = 2*orad + 1; |
461 |
|
} else { |
462 |
|
xrad = CHECKRAD*rad/x_c + 1; |
469 |
|
} |
470 |
|
barsize = 2*yrad + 1; |
471 |
|
scanin = (COLOR **)malloc(barsize*sizeof(COLOR *)); |
472 |
+ |
if (scanin == NULL) |
473 |
+ |
goto memerr; |
474 |
|
for (i = 0; i < barsize; i++) { |
475 |
|
scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR)); |
476 |
< |
if (scanin[i] == NULL) { |
477 |
< |
fprintf(stderr, "%s: out of memory\n", progname); |
450 |
< |
quit(1); |
451 |
< |
} |
476 |
> |
if (scanin[i] == NULL) |
477 |
> |
goto memerr; |
478 |
|
} |
479 |
|
if (obarsize > 0) { |
480 |
|
scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *)); |
481 |
|
greybar = (float **)malloc(obarsize*sizeof(float *)); |
482 |
+ |
if (scoutbar == NULL | greybar == NULL) |
483 |
+ |
goto memerr; |
484 |
|
for (i = 0; i < obarsize; i++) { |
485 |
|
scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR)); |
486 |
|
greybar[i] = (float *)malloc(ncols*sizeof(float)); |
487 |
< |
if (scoutbar[i] == NULL | greybar[i] == NULL) { |
488 |
< |
fprintf(stderr, "%s: out of memory\n", |
461 |
< |
progname); |
462 |
< |
quit(1); |
463 |
< |
} |
487 |
> |
if (scoutbar[i] == NULL | greybar[i] == NULL) |
488 |
> |
goto memerr; |
489 |
|
} |
490 |
|
} else { |
491 |
|
scanout = (COLOR *)malloc(ncols*sizeof(COLOR)); |
492 |
< |
if (scanout == NULL) { |
493 |
< |
fprintf(stderr, "%s: out of memory\n", progname); |
469 |
< |
quit(1); |
470 |
< |
} |
492 |
> |
if (scanout == NULL) |
493 |
> |
goto memerr; |
494 |
|
} |
495 |
|
/* record pixel aspect ratio */ |
496 |
|
if (!correctaspect) { |
499 |
|
fputaspect(d, stdout); |
500 |
|
} |
501 |
|
/* record exposure */ |
502 |
< |
d = bright(exposure); |
502 |
> |
d = (*ourbright)(exposure); |
503 |
|
if (!FEQ(d,1.0)) |
504 |
|
fputexpos(d, stdout); |
505 |
|
/* record color correction */ |
511 |
|
printf("\n"); |
512 |
|
/* write out resolution */ |
513 |
|
fputresolu(order, ncols, nrows, stdout); |
514 |
+ |
return; |
515 |
+ |
memerr: |
516 |
+ |
fprintf(stderr, "%s: out of memory\n", progname); |
517 |
+ |
quit(1); |
518 |
|
} |
519 |
|
|
520 |
|
|
526 |
|
int ybot; |
527 |
|
register int c; |
528 |
|
/* average input scanlines */ |
529 |
< |
while (nextrow < r+orad && nextrow < nrows) { |
529 |
> |
while (nextrow <= r+orad && nextrow < nrows) { |
530 |
|
ybot = (long)nextrow*yres/nrows; |
531 |
|
for (c = 0; c < ncols; c++) { |
532 |
|
dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow); |
533 |
< |
greybar[nextrow%obarsize][c] = bright(ctmp); |
533 |
> |
greybar[nextrow%obarsize][c] = (*ourbright)(ctmp); |
534 |
|
} |
535 |
|
/* and zero output scanline */ |
536 |
|
bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR)); |