10 |
|
|
11 |
|
#include "pcond.h" |
12 |
|
|
13 |
– |
#include "random.h" |
13 |
|
|
15 |
– |
|
14 |
|
#define LDMAX 100 /* default max. display luminance */ |
15 |
|
#define LDMINF 0.01 /* default min. display lum. factor */ |
16 |
|
|
32 |
|
|
33 |
|
COLOR *fovimg; /* foveal (1 degree) averaged image */ |
34 |
|
short fvxr, fvyr; /* foveal image resolution */ |
35 |
< |
int bwhist[HISTRES]; /* luminance histogram */ |
36 |
< |
long histot; /* total count of histogram */ |
35 |
> |
float bwhist[HISTRES]; /* luminance histogram */ |
36 |
> |
double histot; /* total count of histogram */ |
37 |
|
double bwmin, bwmax; /* histogram limits */ |
38 |
|
double bwavg; /* mean brightness */ |
39 |
|
|
249 |
|
#ifdef DEBUG |
250 |
|
fprintf(stderr, "%s: generating histogram...", progname); |
251 |
|
#endif |
252 |
< |
fovhist(); /* generate adaptation histogram */ |
252 |
> |
getfovimg(); /* get foveal sample image */ |
253 |
> |
comphist(); /* generate adaptation histogram */ |
254 |
|
#ifdef DEBUG |
255 |
|
fputs("done\n", stderr); |
256 |
|
#endif |
308 |
|
centprob(x, y) /* center-weighting probability function */ |
309 |
|
int x, y; |
310 |
|
{ |
311 |
< |
double xr, yr; |
312 |
< |
|
313 |
< |
xr = (x+.5)/fvxr - .5; |
314 |
< |
yr = (y+.5)/fvyr - .5; |
315 |
< |
return(1. - xr*xr - yr*yr); /* radial, == 0.5 at corners */ |
311 |
> |
double xr, yr, p; |
312 |
> |
/* paraboloid, 0 at 90 degrees from center */ |
313 |
> |
xr = (x - .5*(fvxr-1))/90.; /* 180 degree fisheye has fv?r == 90 */ |
314 |
> |
yr = (y - .5*(fvyr-1))/90.; |
315 |
> |
p = 1. - xr*xr - yr*yr; |
316 |
> |
return(p < 0. ? 0. : p); |
317 |
|
} |
318 |
|
|
319 |
|
|
320 |
< |
fovhist() /* create foveal sampled image and histogram */ |
320 |
> |
getfovimg() /* load foveal sampled image */ |
321 |
|
{ |
322 |
|
extern FILE *popen(); |
323 |
|
char combuf[128]; |
324 |
– |
double l, b, lwmin, lwmax; |
324 |
|
FILE *fp; |
325 |
|
int x, y; |
326 |
< |
|
326 |
> |
/* compute image size */ |
327 |
|
fvxr = sqrt(ourview.hn2)/FOVDIA + 0.5; |
328 |
|
if (fvxr < 2) fvxr = 2; |
329 |
|
fvyr = sqrt(ourview.vn2)/FOVDIA + 0.5; |
345 |
|
if (freadscan(fovscan(y), fvxr, fp) < 0) |
346 |
|
goto readerr; |
347 |
|
pclose(fp); |
348 |
+ |
return; |
349 |
+ |
readerr: |
350 |
+ |
fprintf(stderr, "%s: error reading from pfilt process in fovimage\n", |
351 |
+ |
progname); |
352 |
+ |
exit(1); |
353 |
+ |
} |
354 |
+ |
|
355 |
+ |
|
356 |
+ |
comphist() /* create foveal sampled image and histogram */ |
357 |
+ |
{ |
358 |
+ |
double l, b, lwmin, lwmax; |
359 |
+ |
register int x, y; |
360 |
+ |
|
361 |
|
lwmin = 1e10; /* find extrema */ |
362 |
|
lwmax = 0.; |
363 |
|
for (y = 0; y < fvyr; y++) |
366 |
|
if (l < lwmin) lwmin = l; |
367 |
|
if (l > lwmax) lwmax = l; |
368 |
|
} |
369 |
+ |
lwmin -= FTINY; |
370 |
+ |
lwmax += FTINY; |
371 |
|
if (lwmin < LMIN) lwmin = LMIN; |
372 |
|
if (lwmax > LMAX) lwmax = LMAX; |
373 |
|
/* compute histogram */ |
376 |
|
bwavg = 0.; |
377 |
|
for (y = 0; y < fvyr; y++) |
378 |
|
for (x = 0; x < fvxr; x++) { |
365 |
– |
if (what2do & DO_CWEIGHT && |
366 |
– |
frandom() > centprob(x,y)) |
367 |
– |
continue; |
379 |
|
l = plum(fovscan(y)[x]); |
380 |
|
if (l < lwmin) continue; |
381 |
|
if (l > lwmax) continue; |
382 |
|
b = Bl(l); |
383 |
|
bwavg += b; |
384 |
< |
bwhc(b)++; |
385 |
< |
histot++; |
384 |
> |
l = what2do&DO_CWEIGHT ? centprob(x,y) : 1.; |
385 |
> |
bwhist[bwhi(b)] += l; |
386 |
> |
histot += l; |
387 |
|
} |
388 |
< |
bwavg /= (double)histot; |
377 |
< |
return; |
378 |
< |
readerr: |
379 |
< |
fprintf(stderr, "%s: error reading from pfilt process in fovimage\n", |
380 |
< |
progname); |
381 |
< |
exit(1); |
388 |
> |
bwavg /= histot; |
389 |
|
} |
390 |
|
|
391 |
|
|
392 |
|
check2do() /* check histogram to see what isn't worth doing */ |
393 |
|
{ |
394 |
< |
long sum; |
394 |
> |
double sum; |
395 |
|
double b, l; |
396 |
|
register int i; |
397 |
|
|
406 |
|
if (!(what2do & (DO_ACUITY|DO_COLOR))) |
407 |
|
return; |
408 |
|
/* find 5th percentile */ |
409 |
< |
sum = histot*0.05 + .5; |
409 |
> |
sum = histot*0.05; |
410 |
|
for (i = 0; i < HISTRES; i++) |
411 |
|
if ((sum -= bwhist[i]) <= 0) |
412 |
|
break; |