| 1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 16 |
|
|
| 17 |
|
#include "color.h" |
| 18 |
|
|
| 19 |
+ |
#include "resolu.h" |
| 20 |
+ |
|
| 21 |
+ |
#include "paths.h" |
| 22 |
+ |
|
| 23 |
|
extern char *malloc(); |
| 24 |
|
extern float *matchlamp(); |
| 25 |
|
|
| 26 |
+ |
#define FEQ(a,b) ((a) >= .98*(b) && (a) <= 1.02*(b)) |
| 27 |
+ |
|
| 28 |
|
#define CHECKRAD 1.5 /* radius to check for filtering */ |
| 29 |
|
|
| 30 |
|
COLOR exposure = WHTCOLOR; /* exposure for the frame */ |
| 47 |
|
|
| 48 |
|
double spread = 1e-4; /* spread for star points */ |
| 49 |
|
|
| 44 |
– |
#define TEMPLATE "/usr/tmp/pfXXXXXX" |
| 45 |
– |
|
| 50 |
|
char *tfname = NULL; |
| 51 |
|
|
| 52 |
|
char *lampdat = "lamp.tab"; /* lamp data file */ |
| 53 |
|
|
| 54 |
+ |
int order; /* scanline ordering of input */ |
| 55 |
|
int xres, yres; /* resolution of input */ |
| 56 |
|
double inpaspect = 1.0; /* pixel aspect ratio of input */ |
| 57 |
|
int correctaspect = 0; /* aspect ratio correction? */ |
| 58 |
|
|
| 59 |
+ |
int wrongformat = 0; |
| 60 |
+ |
|
| 61 |
|
int xrad; /* x window size */ |
| 62 |
|
int yrad; /* y window size */ |
| 63 |
|
|
| 72 |
|
int argc; |
| 73 |
|
char **argv; |
| 74 |
|
{ |
| 75 |
< |
extern char *mktemp(); |
| 69 |
< |
extern double atof(), pow(); |
| 75 |
> |
extern double pow(); |
| 76 |
|
extern long ftell(); |
| 77 |
|
extern int quit(), headline(); |
| 78 |
|
FILE *fin; |
| 81 |
|
long fpos; |
| 82 |
|
double outaspect = 0.0; |
| 83 |
|
double d; |
| 84 |
< |
int i; |
| 84 |
> |
int i, j; |
| 85 |
|
|
| 86 |
|
if (signal(SIGINT, quit) == SIG_IGN) |
| 87 |
|
signal(SIGINT, SIG_IGN); |
| 127 |
|
d = pow(2.0, atof(argv[i+1])); |
| 128 |
|
else |
| 129 |
|
d = atof(argv[i+1]); |
| 130 |
+ |
if (d < 1e-20 || d > 1e20) { |
| 131 |
+ |
fprintf(stderr, |
| 132 |
+ |
"%s: exposure out of range\n", |
| 133 |
+ |
argv[0]); |
| 134 |
+ |
exit(1); |
| 135 |
+ |
} |
| 136 |
|
switch (argv[i][2]) { |
| 137 |
|
case '\0': |
| 138 |
|
scalecolor(exposure, d); |
| 190 |
|
} |
| 191 |
|
else |
| 192 |
|
break; |
| 193 |
< |
|
| 193 |
> |
/* get lamp data (if necessary) */ |
| 194 |
> |
if (lamptype != NULL) { |
| 195 |
> |
if (loadlamps(lampdat) < 0) |
| 196 |
> |
quit(1); |
| 197 |
> |
if ((lampcolor = matchlamp(lamptype)) == NULL) { |
| 198 |
> |
fprintf(stderr, "%s: unknown lamp type\n", lamptype); |
| 199 |
> |
quit(1); |
| 200 |
> |
} |
| 201 |
> |
for (i = 0; i < 3; i++) |
| 202 |
> |
if (lampcolor[i] > 1e-4) |
| 203 |
> |
colval(exposure,i) /= lampcolor[i]; |
| 204 |
> |
freelamps(); |
| 205 |
> |
} |
| 206 |
> |
/* open input file */ |
| 207 |
|
if (i == argc) { |
| 208 |
|
if (singlepass) |
| 209 |
|
fin = stdin; |
| 230 |
|
fprintf(stderr, "%s: bad # file arguments\n", progname); |
| 231 |
|
quit(1); |
| 232 |
|
} |
| 208 |
– |
/* get lamp data (if necessary) */ |
| 209 |
– |
if (lamptype != NULL) { |
| 210 |
– |
if (loadlamps(lampdat) < 0) |
| 211 |
– |
quit(1); |
| 212 |
– |
if ((lampcolor = matchlamp(lamptype)) == NULL) { |
| 213 |
– |
fprintf(stderr, "%s: unknown lamp type\n", lamptype); |
| 214 |
– |
quit(1); |
| 215 |
– |
} |
| 216 |
– |
colval(exposure,RED) /= lampcolor[0]; |
| 217 |
– |
colval(exposure,GRN) /= lampcolor[1]; |
| 218 |
– |
colval(exposure,BLU) /= lampcolor[2]; |
| 219 |
– |
freelamps(); |
| 220 |
– |
} |
| 233 |
|
/* get header */ |
| 234 |
< |
getheader(fin, headline); |
| 234 |
> |
getheader(fin, headline, NULL); |
| 235 |
> |
if (wrongformat) { |
| 236 |
> |
fprintf(stderr, "%s: input must be a Radiance picture\n", |
| 237 |
> |
progname); |
| 238 |
> |
quit(1); |
| 239 |
> |
} |
| 240 |
|
/* add new header info. */ |
| 241 |
|
printargs(i, argv, stdout); |
| 242 |
|
/* get picture size */ |
| 243 |
< |
if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { |
| 243 |
> |
if ((order = fgetresolu(&xres, &yres, fin)) < 0) { |
| 244 |
|
fprintf(stderr, "%s: bad picture size\n", progname); |
| 245 |
|
quit(1); |
| 246 |
|
} |
| 247 |
+ |
if (!(order & YMAJOR)) |
| 248 |
+ |
inpaspect = 1.0/inpaspect; |
| 249 |
|
/* compute output resolution */ |
| 250 |
|
if (ncols <= 0) |
| 251 |
|
ncols = x_c*xres + .5; |
| 284 |
|
headline(s) /* process line from header */ |
| 285 |
|
char *s; |
| 286 |
|
{ |
| 287 |
+ |
char fmt[32]; |
| 288 |
+ |
|
| 289 |
|
fputs(s, stdout); /* copy to output */ |
| 290 |
|
if (isaspect(s)) /* get aspect ratio */ |
| 291 |
|
inpaspect *= aspectval(s); |
| 292 |
+ |
else if (isformat(s)) { |
| 293 |
+ |
formatval(fmt, s); |
| 294 |
+ |
wrongformat = strcmp(fmt, COLRFMT); |
| 295 |
+ |
} |
| 296 |
|
} |
| 297 |
|
|
| 298 |
|
|
| 391 |
|
|
| 392 |
|
scan2init() /* prepare scanline arrays */ |
| 393 |
|
{ |
| 394 |
+ |
COLOR ctmp; |
| 395 |
|
double d; |
| 396 |
|
register int i; |
| 397 |
|
|
| 407 |
|
|
| 408 |
|
initmask(); /* initialize filter table */ |
| 409 |
|
} |
| 410 |
< |
barsize = 2 * yrad; |
| 410 |
> |
barsize = 2*yrad + 1; |
| 411 |
|
scanin = (COLOR **)malloc(barsize*sizeof(COLOR *)); |
| 412 |
|
for (i = 0; i < barsize; i++) { |
| 413 |
|
scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR)); |
| 421 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
| 422 |
|
quit(1); |
| 423 |
|
} |
| 424 |
< |
/* record pixel aspect and exposure */ |
| 424 |
> |
/* record pixel aspect ratio */ |
| 425 |
|
if (!correctaspect) { |
| 426 |
< |
d = x_c / y_r; |
| 427 |
< |
if (d < .99 || d > 1.01) |
| 426 |
> |
d = order & YMAJOR ? x_c/y_r : y_r/x_c ; |
| 427 |
> |
if (!FEQ(d,1.0)) |
| 428 |
|
fputaspect(d, stdout); |
| 429 |
|
} |
| 430 |
+ |
/* record exposure */ |
| 431 |
|
d = bright(exposure); |
| 432 |
< |
if (d < .995 || d > 1.005) |
| 432 |
> |
if (!FEQ(d,1.0)) |
| 433 |
|
fputexpos(d, stdout); |
| 434 |
+ |
/* record color correction */ |
| 435 |
+ |
copycolor(ctmp, exposure); |
| 436 |
+ |
scalecolor(ctmp, 1.0/d); |
| 437 |
+ |
if (!FEQ(colval(ctmp,RED),colval(ctmp,GRN)) || |
| 438 |
+ |
!FEQ(colval(ctmp,GRN),colval(ctmp,BLU))) |
| 439 |
+ |
fputcolcor(ctmp, stdout); |
| 440 |
|
printf("\n"); |
| 441 |
< |
fputresolu(YMAJOR|YDECR, ncols, nrows, stdout); /* resolution */ |
| 441 |
> |
/* write out resolution */ |
| 442 |
> |
fputresolu(order, ncols, nrows, stdout); |
| 443 |
|
} |
| 444 |
|
|
| 445 |
|
|