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"; |
17 |
|
|
18 |
|
#include "color.h" |
19 |
|
|
20 |
+ |
#include "view.h" |
21 |
+ |
|
22 |
|
#include "resolu.h" |
23 |
|
|
24 |
|
#include "paths.h" |
55 |
|
|
56 |
|
char *tfname = NULL; |
57 |
|
|
58 |
+ |
char template[] = TEMPLATE; |
59 |
+ |
|
60 |
|
char *lampdat = "lamp.tab"; /* lamp data file */ |
61 |
|
|
62 |
|
int order; /* scanline ordering of input */ |
66 |
|
|
67 |
|
int wrongformat = 0; |
68 |
|
|
69 |
+ |
VIEW ourview = STDVIEW; |
70 |
+ |
int gotview = 0; |
71 |
+ |
int wrapfilt = 0; /* wrap filter horizontally? */ |
72 |
+ |
|
73 |
|
int xrad; /* x search radius */ |
74 |
|
int yrad; /* y search radius */ |
75 |
|
int xbrad; /* x box size */ |
108 |
|
if (signal(SIGINT, quit) == SIG_IGN) |
109 |
|
signal(SIGINT, SIG_IGN); |
110 |
|
if (signal(SIGHUP, quit) == SIG_IGN) |
111 |
< |
signal(SIGINT, SIG_IGN); |
111 |
> |
signal(SIGHUP, SIG_IGN); |
112 |
|
signal(SIGTERM, quit); |
113 |
|
signal(SIGPIPE, quit); |
114 |
|
#ifdef SIGXCPU |
225 |
|
fprintf(stderr, "%s: unknown lamp type\n", lamptype); |
226 |
|
quit(1); |
227 |
|
} |
228 |
< |
for (i = 0; i < 3; i++) |
229 |
< |
if (lampcolor[i] > 1e-4) |
230 |
< |
colval(exposure,i) /= lampcolor[i]; |
228 |
> |
for (j = 0; j < 3; j++) |
229 |
> |
if (lampcolor[j] > 1e-4) |
230 |
> |
colval(exposure,j) /= lampcolor[j]; |
231 |
|
freelamps(); |
232 |
|
} |
233 |
|
/* open input file */ |
235 |
|
if (singlepass) |
236 |
|
fin = stdin; |
237 |
|
else { |
238 |
< |
tfname = mktemp(TEMPLATE); |
238 |
> |
tfname = mktemp(template); |
239 |
|
if ((fin = fopen(tfname, "w+")) == NULL) { |
240 |
|
fprintf(stderr, "%s: can't create ", progname); |
241 |
|
fprintf(stderr, "temp file \"%s\"\n", tfname); |
273 |
|
} |
274 |
|
if (!(order & YMAJOR)) |
275 |
|
inpaspect = 1.0/inpaspect; |
276 |
+ |
/* wrap around for cylindrical view? */ |
277 |
+ |
wrapfilt = gotview && ourview.type == VT_CYL && |
278 |
+ |
ourview.horiz >= 360.-FTINY && order & YMAJOR; |
279 |
|
/* compute output resolution */ |
280 |
|
if (ncols <= 0) |
281 |
|
ncols = x_c*xres + .5; |
311 |
|
} |
312 |
|
|
313 |
|
|
314 |
+ |
double |
315 |
+ |
rgb_bright(clr) |
316 |
+ |
COLOR clr; |
317 |
+ |
{ |
318 |
+ |
return(bright(clr)); |
319 |
+ |
} |
320 |
+ |
|
321 |
+ |
|
322 |
+ |
double |
323 |
+ |
xyz_bright(clr) |
324 |
+ |
COLOR clr; |
325 |
+ |
{ |
326 |
+ |
return(clr[CIEY]); |
327 |
+ |
} |
328 |
+ |
|
329 |
+ |
|
330 |
+ |
double (*ourbright)() = rgb_bright; |
331 |
+ |
|
332 |
+ |
|
333 |
|
headline(s) /* process line from header */ |
334 |
|
char *s; |
335 |
|
{ |
338 |
|
fputs(s, stdout); /* copy to output */ |
339 |
|
if (isaspect(s)) /* get aspect ratio */ |
340 |
|
inpaspect *= aspectval(s); |
341 |
< |
else if (isexpos(s)) |
341 |
> |
else if (isexpos(s)) /* get exposure */ |
342 |
|
hotlvl *= exposval(s); |
343 |
< |
else if (isformat(s)) { |
344 |
< |
formatval(fmt, s); |
345 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
346 |
< |
} |
343 |
> |
else if (formatval(fmt, s)) { /* get format */ |
344 |
> |
wrongformat = 0; |
345 |
> |
if (!strcmp(COLRFMT, fmt)) |
346 |
> |
ourbright = rgb_bright; |
347 |
> |
else if (!strcmp(CIEFMT, fmt)) |
348 |
> |
ourbright = xyz_bright; |
349 |
> |
else |
350 |
> |
wrongformat = !globmatch(PICFMT, fmt); |
351 |
> |
} else if (isview(s) && sscanview(&ourview, s) > 0) |
352 |
> |
gotview++; |
353 |
|
} |
354 |
|
|
355 |
|
|
417 |
|
if (freadscan(scanin[yread%barsize], |
418 |
|
xres, in) < 0) { |
419 |
|
fprintf(stderr, |
420 |
< |
"%s: bad read (y=%d)\n", |
420 |
> |
"%s: truncated input (y=%d)\n", |
421 |
|
progname, yres-1-yread); |
422 |
|
quit(1); |
423 |
|
} |
464 |
|
rad *= (y_r + x_c)/2.0; |
465 |
|
|
466 |
|
if (thresh > FTINY) { |
431 |
– |
xrad = CHECKRAD*THRESHRAD*rad/x_c + xbrad; |
432 |
– |
yrad = CHECKRAD*THRESHRAD*rad/y_r + ybrad; |
467 |
|
orad = CHECKRAD*THRESHRAD*rad + 1; |
468 |
+ |
xrad = orad/x_c + xbrad; |
469 |
+ |
yrad = orad/y_r + ybrad; |
470 |
|
obarsize = 2*orad + 1; |
471 |
|
} else { |
472 |
|
xrad = CHECKRAD*rad/x_c + 1; |
479 |
|
} |
480 |
|
barsize = 2*yrad + 1; |
481 |
|
scanin = (COLOR **)malloc(barsize*sizeof(COLOR *)); |
482 |
+ |
if (scanin == NULL) |
483 |
+ |
goto memerr; |
484 |
|
for (i = 0; i < barsize; i++) { |
485 |
|
scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR)); |
486 |
< |
if (scanin[i] == NULL) { |
487 |
< |
fprintf(stderr, "%s: out of memory\n", progname); |
450 |
< |
quit(1); |
451 |
< |
} |
486 |
> |
if (scanin[i] == NULL) |
487 |
> |
goto memerr; |
488 |
|
} |
489 |
|
if (obarsize > 0) { |
490 |
|
scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *)); |
491 |
|
greybar = (float **)malloc(obarsize*sizeof(float *)); |
492 |
+ |
if (scoutbar == NULL | greybar == NULL) |
493 |
+ |
goto memerr; |
494 |
|
for (i = 0; i < obarsize; i++) { |
495 |
|
scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR)); |
496 |
|
greybar[i] = (float *)malloc(ncols*sizeof(float)); |
497 |
< |
if (scoutbar[i] == NULL | greybar[i] == NULL) { |
498 |
< |
fprintf(stderr, "%s: out of memory\n", |
461 |
< |
progname); |
462 |
< |
quit(1); |
463 |
< |
} |
497 |
> |
if (scoutbar[i] == NULL | greybar[i] == NULL) |
498 |
> |
goto memerr; |
499 |
|
} |
500 |
|
} else { |
501 |
|
scanout = (COLOR *)malloc(ncols*sizeof(COLOR)); |
502 |
< |
if (scanout == NULL) { |
503 |
< |
fprintf(stderr, "%s: out of memory\n", progname); |
469 |
< |
quit(1); |
470 |
< |
} |
502 |
> |
if (scanout == NULL) |
503 |
> |
goto memerr; |
504 |
|
} |
505 |
|
/* record pixel aspect ratio */ |
506 |
|
if (!correctaspect) { |
509 |
|
fputaspect(d, stdout); |
510 |
|
} |
511 |
|
/* record exposure */ |
512 |
< |
d = bright(exposure); |
512 |
> |
d = (*ourbright)(exposure); |
513 |
|
if (!FEQ(d,1.0)) |
514 |
|
fputexpos(d, stdout); |
515 |
|
/* record color correction */ |
521 |
|
printf("\n"); |
522 |
|
/* write out resolution */ |
523 |
|
fputresolu(order, ncols, nrows, stdout); |
524 |
+ |
return; |
525 |
+ |
memerr: |
526 |
+ |
fprintf(stderr, "%s: out of memory\n", progname); |
527 |
+ |
quit(1); |
528 |
|
} |
529 |
|
|
530 |
|
|
536 |
|
int ybot; |
537 |
|
register int c; |
538 |
|
/* average input scanlines */ |
539 |
< |
while (nextrow < r+orad && nextrow < nrows) { |
539 |
> |
while (nextrow <= r+orad && nextrow < nrows) { |
540 |
|
ybot = (long)nextrow*yres/nrows; |
541 |
|
for (c = 0; c < ncols; c++) { |
542 |
|
dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow); |
543 |
< |
greybar[nextrow%obarsize][c] = bright(ctmp); |
543 |
> |
greybar[nextrow%obarsize][c] = (*ourbright)(ctmp); |
544 |
|
} |
545 |
|
/* and zero output scanline */ |
546 |
|
bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR)); |