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 |
|
extern char *malloc(); |
22 |
|
extern float *matchlamp(); |
23 |
|
|
24 |
+ |
#define FEQ(a,b) ((a) >= .98*(b) && (a) <= 1.02*(b)) |
25 |
+ |
|
26 |
|
#define CHECKRAD 1.5 /* radius to check for filtering */ |
27 |
|
|
28 |
|
COLOR exposure = WHTCOLOR; /* exposure for the frame */ |
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 |
|
|
82 |
|
long fpos; |
83 |
|
double outaspect = 0.0; |
84 |
|
double d; |
85 |
< |
int i; |
85 |
> |
int i, j; |
86 |
|
|
87 |
|
if (signal(SIGINT, quit) == SIG_IGN) |
88 |
|
signal(SIGINT, SIG_IGN); |
128 |
|
d = pow(2.0, atof(argv[i+1])); |
129 |
|
else |
130 |
|
d = atof(argv[i+1]); |
131 |
+ |
if (d < 1e-20 || d > 1e20) { |
132 |
+ |
fprintf(stderr, |
133 |
+ |
"%s: exposure out of range\n", |
134 |
+ |
argv[0]); |
135 |
+ |
exit(1); |
136 |
+ |
} |
137 |
|
switch (argv[i][2]) { |
138 |
|
case '\0': |
139 |
|
scalecolor(exposure, d); |
199 |
|
fprintf(stderr, "%s: unknown lamp type\n", lamptype); |
200 |
|
quit(1); |
201 |
|
} |
202 |
< |
colval(exposure,RED) /= lampcolor[0]; |
203 |
< |
colval(exposure,GRN) /= lampcolor[1]; |
204 |
< |
colval(exposure,BLU) /= lampcolor[2]; |
202 |
> |
for (i = 0; i < 3; i++) |
203 |
> |
if (lampcolor[i] > 1e-4) |
204 |
> |
colval(exposure,i) /= lampcolor[i]; |
205 |
|
freelamps(); |
206 |
|
} |
207 |
|
/* open input file */ |
232 |
|
quit(1); |
233 |
|
} |
234 |
|
/* get header */ |
235 |
< |
getheader(fin, headline); |
235 |
> |
getheader(fin, headline, NULL); |
236 |
> |
if (wrongformat) { |
237 |
> |
fprintf(stderr, "%s: input must be a Radiance picture\n", |
238 |
> |
progname); |
239 |
> |
quit(1); |
240 |
> |
} |
241 |
|
/* add new header info. */ |
242 |
|
printargs(i, argv, stdout); |
243 |
|
/* get picture size */ |
244 |
< |
if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { |
244 |
> |
if ((order = fgetresolu(&xres, &yres, fin)) < 0) { |
245 |
|
fprintf(stderr, "%s: bad picture size\n", progname); |
246 |
|
quit(1); |
247 |
|
} |
248 |
+ |
if (!(order & YMAJOR)) |
249 |
+ |
inpaspect = 1.0/inpaspect; |
250 |
|
/* compute output resolution */ |
251 |
|
if (ncols <= 0) |
252 |
|
ncols = x_c*xres + .5; |
285 |
|
headline(s) /* process line from header */ |
286 |
|
char *s; |
287 |
|
{ |
288 |
+ |
char fmt[32]; |
289 |
+ |
|
290 |
|
fputs(s, stdout); /* copy to output */ |
291 |
|
if (isaspect(s)) /* get aspect ratio */ |
292 |
|
inpaspect *= aspectval(s); |
293 |
+ |
else if (isformat(s)) { |
294 |
+ |
formatval(fmt, s); |
295 |
+ |
wrongformat = strcmp(fmt, COLRFMT); |
296 |
+ |
} |
297 |
|
} |
298 |
|
|
299 |
|
|
392 |
|
|
393 |
|
scan2init() /* prepare scanline arrays */ |
394 |
|
{ |
395 |
+ |
COLOR ctmp; |
396 |
|
double d; |
397 |
|
register int i; |
398 |
|
|
408 |
|
|
409 |
|
initmask(); /* initialize filter table */ |
410 |
|
} |
411 |
< |
barsize = 2 * yrad; |
411 |
> |
barsize = 2*yrad + 1; |
412 |
|
scanin = (COLOR **)malloc(barsize*sizeof(COLOR *)); |
413 |
|
for (i = 0; i < barsize; i++) { |
414 |
|
scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR)); |
422 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
423 |
|
quit(1); |
424 |
|
} |
425 |
< |
/* record pixel aspect and exposure */ |
425 |
> |
/* record pixel aspect ratio */ |
426 |
|
if (!correctaspect) { |
427 |
< |
d = x_c / y_r; |
428 |
< |
if (d < .99 || d > 1.01) |
427 |
> |
d = order & YMAJOR ? x_c/y_r : y_r/x_c ; |
428 |
> |
if (!FEQ(d,1.0)) |
429 |
|
fputaspect(d, stdout); |
430 |
|
} |
431 |
+ |
/* record exposure */ |
432 |
|
d = bright(exposure); |
433 |
< |
if (d < .995 || d > 1.005) |
433 |
> |
if (!FEQ(d,1.0)) |
434 |
|
fputexpos(d, stdout); |
435 |
+ |
/* record color correction */ |
436 |
+ |
copycolor(ctmp, exposure); |
437 |
+ |
scalecolor(ctmp, 1.0/d); |
438 |
+ |
if (!FEQ(colval(ctmp,RED),colval(ctmp,GRN)) || |
439 |
+ |
!FEQ(colval(ctmp,GRN),colval(ctmp,BLU))) |
440 |
+ |
fputcolcor(ctmp, stdout); |
441 |
|
printf("\n"); |
442 |
< |
fputresolu(YMAJOR|YDECR, ncols, nrows, stdout); /* resolution */ |
442 |
> |
/* write out resolution */ |
443 |
> |
fputresolu(order, ncols, nrows, stdout); |
444 |
|
} |
445 |
|
|
446 |
|
|