1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
16 |
|
|
17 |
|
#include "resolu.h" |
18 |
|
|
19 |
< |
#define min(a,b) ((a)<(b)?(a):(b)) |
19 |
> |
#define min(a,b) ((a)<(b)?(a):(b)) |
20 |
|
|
21 |
< |
RESOLU picres; /* resolution of picture */ |
21 |
> |
RESOLU picres; /* resolution of picture */ |
22 |
|
|
23 |
|
int uniq = 0; /* print only unique values? */ |
24 |
|
|
25 |
< |
int original = 0; /* convert back to original values? */ |
25 |
> |
int doexposure = 0; /* exposure change? (>100 to print) */ |
26 |
|
|
27 |
|
int dataonly = 0; /* data only format? */ |
28 |
|
|
37 |
|
|
38 |
|
int resolution = 1; /* put/get resolution string? */ |
39 |
|
|
40 |
+ |
int original = 0; /* convert to original values? */ |
41 |
+ |
|
42 |
|
int wrongformat = 0; /* wrong input format? */ |
43 |
|
|
44 |
< |
double gamcor = 1.0; /* gamma correction */ |
44 |
> |
double gamcor = 1.0; /* gamma correction */ |
45 |
|
|
46 |
|
int ord[3] = {RED, GRN, BLU}; /* RGB ordering */ |
47 |
|
int rord[4]; /* reverse ordering */ |
60 |
|
char **argv; |
61 |
|
{ |
62 |
|
extern int checkhead(); |
63 |
+ |
double d, expval = 1.0; |
64 |
|
int i; |
65 |
|
|
66 |
|
progname = argv[0]; |
81 |
|
original = argv[i][0] == '-'; |
82 |
|
break; |
83 |
|
case 'g': /* gamma correction */ |
84 |
< |
gamcor = atof(argv[++i]); |
84 |
> |
gamcor = atof(argv[i+1]); |
85 |
|
if (argv[i][0] == '+') |
86 |
|
gamcor = 1.0/gamcor; |
87 |
+ |
i++; |
88 |
|
break; |
89 |
+ |
case 'e': /* exposure correction */ |
90 |
+ |
d = atof(argv[i+1]); |
91 |
+ |
if (argv[i+1][0] == '-' || argv[i+1][0] == '+') |
92 |
+ |
d = pow(2.0, d); |
93 |
+ |
if (argv[i][0] == '-') |
94 |
+ |
doexposure = 100; |
95 |
+ |
scalecolor(exposure, d); |
96 |
+ |
expval *= d; |
97 |
+ |
doexposure++; |
98 |
+ |
i++; |
99 |
+ |
break; |
100 |
|
case 'R': /* reverse byte sequence */ |
101 |
|
if (argv[i][0] == '-') { |
102 |
|
ord[0]=BLU; ord[1]=GRN; ord[2]=RED; |
142 |
|
} |
143 |
|
break; |
144 |
|
case 'x': /* x resolution */ |
145 |
+ |
case 'X': /* x resolution */ |
146 |
|
resolution = 0; |
147 |
|
if (argv[i][0] == '-') |
148 |
|
picres.or |= XDECR; |
149 |
|
picres.xr = atoi(argv[++i]); |
150 |
|
break; |
151 |
|
case 'y': /* y resolution */ |
152 |
+ |
case 'Y': /* y resolution */ |
153 |
|
resolution = 0; |
154 |
|
if (argv[i][0] == '-') |
155 |
|
picres.or |= YDECR; |
193 |
|
set_io(); |
194 |
|
|
195 |
|
if (reverse) { |
196 |
+ |
#ifdef MSDOS |
197 |
+ |
setmode(fileno(stdout), O_BINARY); |
198 |
+ |
if (format != 'a' && format != 'i') |
199 |
+ |
setmode(fileno(fin), O_BINARY); |
200 |
+ |
#endif |
201 |
|
/* get header */ |
202 |
< |
if (header && checkheader(fin, fmtid, stdout) < 0) { |
203 |
< |
fprintf(stderr, "%s: wrong input format\n", progname); |
204 |
< |
quit(1); |
205 |
< |
} |
202 |
> |
if (header) { |
203 |
> |
if (checkheader(fin, fmtid, stdout) < 0) { |
204 |
> |
fprintf(stderr, "%s: wrong input format\n", |
205 |
> |
progname); |
206 |
> |
quit(1); |
207 |
> |
} |
208 |
> |
} else |
209 |
> |
newheader("RADIANCE", stdout); |
210 |
|
/* get resolution */ |
211 |
|
if ((resolution && !fgetsresolu(&picres, fin)) || |
212 |
|
picres.xr <= 0 || picres.yr <= 0) { |
215 |
|
} |
216 |
|
/* add to header */ |
217 |
|
printargs(i, argv, stdout); |
218 |
+ |
if (doexposure > 100) |
219 |
+ |
fputexpos(expval, stdout); |
220 |
|
fputformat(COLRFMT, stdout); |
221 |
|
putchar('\n'); |
222 |
|
fputsresolu(&picres, stdout); /* always put resolution */ |
223 |
|
valtopix(); |
224 |
|
} else { |
225 |
+ |
#ifdef MSDOS |
226 |
+ |
setmode(fileno(fin), O_BINARY); |
227 |
+ |
if (format != 'a' && format != 'i') |
228 |
+ |
setmode(fileno(stdout), O_BINARY); |
229 |
+ |
#endif |
230 |
|
/* get header */ |
231 |
|
getheader(fin, checkhead, NULL); |
232 |
|
if (wrongformat) { |
240 |
|
} |
241 |
|
if (header) { |
242 |
|
printargs(i, argv, stdout); |
243 |
+ |
if (doexposure > 100) |
244 |
+ |
fputexpos(expval, stdout); |
245 |
|
fputformat(fmtid, stdout); |
246 |
|
putchar('\n'); |
247 |
|
} |
261 |
|
double d; |
262 |
|
COLOR ctmp; |
263 |
|
|
264 |
< |
if (isformat(line)) { |
230 |
< |
formatval(fmt, line); |
264 |
> |
if (formatval(fmt, line)) |
265 |
|
wrongformat = strcmp(fmt, COLRFMT); |
266 |
< |
} else if (original && isexpos(line)) { |
266 |
> |
else if (original && isexpos(line)) { |
267 |
|
d = 1.0/exposval(line); |
268 |
|
scalecolor(exposure, d); |
269 |
+ |
doexposure++; |
270 |
|
} else if (original && iscolcor(line)) { |
271 |
|
colcorval(ctmp, line); |
272 |
|
setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED), |
273 |
|
colval(exposure,GRN)/colval(ctmp,GRN), |
274 |
|
colval(exposure,BLU)/colval(ctmp,BLU)); |
275 |
+ |
doexposure++; |
276 |
|
} else if (header) |
277 |
|
fputs(line, stdout); |
278 |
|
} |
280 |
|
|
281 |
|
pixtoval() /* convert picture to values */ |
282 |
|
{ |
283 |
< |
register COLOR *scanln; |
283 |
> |
register COLOR *scanln; |
284 |
|
int dogamma; |
285 |
|
COLOR lastc; |
286 |
|
FLOAT hv[2]; |
310 |
|
continue; |
311 |
|
else |
312 |
|
copycolor(lastc, scanln[x]); |
313 |
< |
if (original) |
313 |
> |
if (doexposure) |
314 |
|
multcolor(scanln[x], exposure); |
315 |
|
if (dogamma) |
316 |
|
setcolor(scanln[x], |
335 |
|
valtopix() /* convert values to a pixel file */ |
336 |
|
{ |
337 |
|
int dogamma; |
338 |
< |
register COLOR *scanln; |
338 |
> |
register COLOR *scanln; |
339 |
|
int y; |
340 |
|
register int x; |
341 |
|
|
358 |
|
pow(colval(scanln[x],RED), gamcor), |
359 |
|
pow(colval(scanln[x],GRN), gamcor), |
360 |
|
pow(colval(scanln[x],BLU), gamcor)); |
361 |
+ |
if (doexposure) |
362 |
+ |
multcolor(scanln[x], exposure); |
363 |
|
} |
364 |
|
if (fwritescan(scanln, scanlen(&picres), stdout) < 0) { |
365 |
|
fprintf(stderr, "%s: write error\n", progname); |
381 |
|
COLOR col; |
382 |
|
FILE *fp; |
383 |
|
{ |
384 |
< |
double vd[3]; |
384 |
> |
double vd[3]; |
385 |
|
|
386 |
|
if (fscanf(fp, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3) |
387 |
|
return(-1); |
394 |
|
COLOR col; |
395 |
|
FILE *fp; |
396 |
|
{ |
397 |
< |
double vd[3]; |
397 |
> |
double vd[3]; |
398 |
|
|
399 |
|
if (fread((char *)vd, sizeof(double), 3, fp) != 3) |
400 |
|
return(-1); |
448 |
|
COLOR col; |
449 |
|
FILE *fp; |
450 |
|
{ |
451 |
< |
double vd; |
451 |
> |
double vd; |
452 |
|
|
453 |
|
if (fscanf(fp, "%lf", &vd) != 1) |
454 |
|
return(-1); |
461 |
|
COLOR col; |
462 |
|
FILE *fp; |
463 |
|
{ |
464 |
< |
double vd; |
464 |
> |
double vd; |
465 |
|
|
466 |
|
if (fread((char *)&vd, sizeof(double), 1, fp) != 1) |
467 |
|
return(-1); |
488 |
|
FILE *fp; |
489 |
|
{ |
490 |
|
int vi; |
491 |
< |
double d; |
491 |
> |
double d; |
492 |
|
|
493 |
|
if (fscanf(fp, "%d", &vi) != 1) |
494 |
|
return(-1); |
503 |
|
FILE *fp; |
504 |
|
{ |
505 |
|
BYTE vb; |
506 |
< |
double d; |
506 |
> |
double d; |
507 |
|
|
508 |
|
if (fread((char *)&vb, sizeof(BYTE), 1, fp) != 1) |
509 |
|
return(-1); |
545 |
|
COLOR col; |
546 |
|
FILE *fp; |
547 |
|
{ |
548 |
< |
double vd[3]; |
548 |
> |
double vd[3]; |
549 |
|
|
550 |
|
vd[0] = colval(col,ord[0]); |
551 |
|
vd[1] = colval(col,ord[1]); |
615 |
|
COLOR col; |
616 |
|
FILE *fp; |
617 |
|
{ |
618 |
< |
double vd; |
618 |
> |
double vd; |
619 |
|
|
620 |
|
vd = bright(col); |
621 |
|
fwrite((char *)&vd, sizeof(double), 1, fp); |