20 |
|
|
21 |
|
#include "resolu.h" |
22 |
|
|
23 |
+ |
#define LOG2 0.69314718055994530942 |
24 |
+ |
|
25 |
|
#define pscan(y) (ourpict+(y)*hresolu) |
26 |
|
#define sscan(y) (ourspict+(y)*hresolu) |
27 |
|
#define wscan(y) (ourweigh+(y)*hresolu) |
68 |
|
COLOR backcolor = BLKCOLOR; /* background color (float) */ |
69 |
|
double backz = 0.0; /* background z value */ |
70 |
|
int normdist = 1; /* normalized distance? */ |
71 |
< |
double ourexp = -1; /* output picture exposure */ |
71 |
> |
double ourexp = -1; /* original picture exposure */ |
72 |
> |
int expadj = 0; /* exposure adjustment (f-stops) */ |
73 |
> |
double rexpadj = 1; /* real exposure adjustment */ |
74 |
|
|
75 |
|
VIEW theirview = STDVIEW; /* input view */ |
76 |
|
int gotview; /* got input view? */ |
99 |
|
int gotvfile = 0; |
100 |
|
int doavg = -1; |
101 |
|
char *zfile = NULL; |
102 |
+ |
char *expcomp = NULL; |
103 |
|
char *err; |
104 |
|
int i, rval; |
105 |
|
|
112 |
|
continue; |
113 |
|
} |
114 |
|
switch (argv[i][1]) { |
115 |
+ |
case 'e': /* exposure */ |
116 |
+ |
check(2,"f"); |
117 |
+ |
expcomp = argv[++i]; |
118 |
+ |
break; |
119 |
|
case 't': /* threshold */ |
120 |
|
check(2,"f"); |
121 |
|
zeps = atof(argv[++i]); |
223 |
|
fillo &= ~F_BACK; |
224 |
|
if (doavg < 0) |
225 |
|
doavg = (argc-i) > 2; |
226 |
+ |
if (expcomp != NULL) |
227 |
+ |
if (expcomp[0] == '+' | expcomp[0] == '-') { |
228 |
+ |
expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5); |
229 |
+ |
if (doavg) |
230 |
+ |
rexpadj = pow(2.0, atof(expcomp)); |
231 |
+ |
else |
232 |
+ |
rexpadj = pow(2.0, (double)expadj); |
233 |
+ |
} else { |
234 |
+ |
if (!isflt(expcomp)) |
235 |
+ |
goto userr; |
236 |
+ |
rexpadj = atof(expcomp); |
237 |
+ |
expadj = log(rexpadj)/LOG2 + (rexpadj>1 ? .5 : -.5); |
238 |
+ |
if (!doavg) |
239 |
+ |
rexpadj = pow(2.0, (double)expadj); |
240 |
+ |
} |
241 |
|
/* set view */ |
242 |
|
if ((err = setview(&ourview)) != NULL) { |
243 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
280 |
|
fprintview(&ourview, stdout); |
281 |
|
putc('\n', stdout); |
282 |
|
} |
283 |
< |
if (pixaspect < .99 || pixaspect > 1.01) |
283 |
> |
if (pixaspect < .99 | pixaspect > 1.01) |
284 |
|
fputaspect(pixaspect, stdout); |
285 |
< |
if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) |
285 |
> |
if (ourexp > 0) |
286 |
> |
ourexp *= rexpadj; |
287 |
> |
else |
288 |
> |
ourexp = rexpadj; |
289 |
> |
if (ourexp < .995 | ourexp > 1.005) |
290 |
|
fputexpos(ourexp, stdout); |
291 |
|
fputformat(COLRFMT, stdout); |
292 |
|
putc('\n', stdout); |
299 |
|
exit(0); |
300 |
|
userr: |
301 |
|
fprintf(stderr, |
302 |
< |
"Usage: %s [view opts][-t eps][-z zout][-fT][-n] pfile zspec ..\n", |
302 |
> |
"Usage: %s [view opts][-t eps][-z zout][-e spec][-a|-q][-fT][-n] pfile zspec ..\n", |
303 |
|
progname); |
304 |
|
exit(1); |
305 |
|
#undef check |
870 |
|
} |
871 |
|
|
872 |
|
|
873 |
< |
writepicture() /* write out picture */ |
873 |
> |
writepicture() /* write out picture (alters buffer) */ |
874 |
|
{ |
875 |
|
int y; |
876 |
|
register int x; |
880 |
|
for (y = vresolu-1; y >= 0; y--) |
881 |
|
if (averaging) { |
882 |
|
for (x = 0; x < hresolu; x++) { /* average pixels */ |
883 |
< |
d = 1./wscan(y)[x]; |
883 |
> |
d = rexpadj/wscan(y)[x]; |
884 |
|
scalecolor(sscan(y)[x], d); |
857 |
– |
wscan(y)[x] = 1; |
885 |
|
} |
886 |
|
if (fwritescan(sscan(y), hresolu, stdout) < 0) |
887 |
|
syserror(progname); |
888 |
< |
} else if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
889 |
< |
syserror(progname); |
888 |
> |
} else { |
889 |
> |
if (expadj) |
890 |
> |
shiftcolrs(pscan(y), hresolu, expadj); |
891 |
> |
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
892 |
> |
syserror(progname); |
893 |
> |
} |
894 |
|
} |
895 |
|
|
896 |
|
|
897 |
|
writedistance(fname) /* write out z file */ |
898 |
|
char *fname; |
899 |
|
{ |
900 |
< |
int donorm = normdist && ourview.type == VT_PER; |
900 |
> |
int donorm = normdist && ourview.type == VT_PER && |
901 |
> |
!averaging && hasmatrix; |
902 |
|
int fd; |
903 |
|
int y; |
904 |
|
float *zout; |