| 14 |
|
|
| 15 |
|
#define VADAPT 0.08 /* fraction of adaptation from veil */ |
| 16 |
|
|
| 17 |
< |
extern COLOR *fovimg; /* foveal (1 degree) averaged image */ |
| 18 |
< |
extern short fvxr, fvyr; /* foveal image resolution */ |
| 17 |
> |
static COLOR *veilimg = NULL; /* veiling image */ |
| 18 |
|
|
| 20 |
– |
#define fovscan(y) (fovimg+(y)*fvxr) |
| 21 |
– |
|
| 22 |
– |
static COLOR *veilimg; /* veiling image */ |
| 23 |
– |
|
| 19 |
|
#define veilscan(y) (veilimg+(y)*fvxr) |
| 20 |
|
|
| 21 |
|
static float (*raydir)[3] = NULL; /* ray direction for each pixel */ |
| 78 |
|
COLOR ctmp, vsum; |
| 79 |
|
int px, py; |
| 80 |
|
register int x, y; |
| 81 |
+ |
|
| 82 |
+ |
if (veilimg != NULL) /* already done? */ |
| 83 |
+ |
return; |
| 84 |
|
/* compute ray directions */ |
| 85 |
|
compraydir(); |
| 86 |
|
/* compute veil image */ |
| 97 |
|
t2 = DOT(rdirscan(py)[px], |
| 98 |
|
rdirscan(y)[x]); |
| 99 |
|
if (t2 <= FTINY) continue; |
| 100 |
< |
t2 = acos(t2); |
| 101 |
< |
t2 = 1./(t2*t2); |
| 100 |
> |
/* use approximation instead |
| 101 |
> |
t3 = acos(t2); |
| 102 |
> |
t2 = t2/(t3*t3); |
| 103 |
> |
*/ |
| 104 |
> |
t2 *= .5 / (1. - t2); |
| 105 |
|
copycolor(ctmp, fovscan(y)[x]); |
| 106 |
|
scalecolor(ctmp, t2); |
| 107 |
|
addcolor(vsum, ctmp); |
| 111 |
|
scalecolor(vsum, VADAPT/t2sum); |
| 112 |
|
copycolor(veilscan(py)[px], vsum); |
| 113 |
|
} |
| 114 |
+ |
/* modify FOV sample image */ |
| 115 |
+ |
for (y = 0; y < fvyr; y++) |
| 116 |
+ |
for (x = 0; x < fvxr; x++) { |
| 117 |
+ |
scalecolor(fovscan(y)[x], 1.-VADAPT); |
| 118 |
+ |
addcolor(fovscan(y)[x], veilscan(y)[x]); |
| 119 |
+ |
} |
| 120 |
+ |
comphist(); /* recompute histogram */ |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
|
| 131 |
|
register int x, i; |
| 132 |
|
|
| 133 |
|
vy = dy = (y+.5)/numscans(&inpres)*fvyr - .5; |
| 134 |
< |
if (vy >= fvyr-1) vy--; |
| 134 |
> |
while (vy >= fvyr-1) vy--; |
| 135 |
|
dy -= (double)vy; |
| 136 |
|
for (x = 0; x < scanlen(&inpres); x++) { |
| 137 |
|
vx = dx = (x+.5)/scanlen(&inpres)*fvxr - .5; |
| 138 |
< |
if (vx >= fvxr-1) vx--; |
| 138 |
> |
while (vx >= fvxr-1) vx--; |
| 139 |
|
dx -= (double)vx; |
| 140 |
|
for (i = 0; i < 3; i++) { |
| 141 |
|
lv = (1.-dy)*colval(veilscan(vy)[vx],i) + |
| 151 |
|
|
| 152 |
|
/****************** ACUITY STUFF *******************/ |
| 153 |
|
|
| 154 |
< |
typedef struct scanbar { |
| 155 |
< |
short sampr; /* sample area size (power of 2) */ |
| 154 |
> |
typedef struct { |
| 155 |
> |
short sampe; /* sample area size (exponent of 2) */ |
| 156 |
|
short nscans; /* number of scanlines in this bar */ |
| 157 |
|
int len; /* individual scanline length */ |
| 150 |
– |
struct scanbar *next; /* next higher resolution scanbar */ |
| 158 |
|
int nread; /* number of scanlines loaded */ |
| 159 |
< |
/* followed by the scanline data */ |
| 159 |
> |
COLOR *sdata; /* scanbar data */ |
| 160 |
|
} SCANBAR; |
| 161 |
|
|
| 162 |
< |
#define bscan(sb,y) ((COLOR *)((sb)+1)+((y)%(sb)->nscans)*(sb)->len) |
| 162 |
> |
#define bscan(sb,y) ((COLOR *)(sb)->sdata+((y)%(sb)->nscans)*(sb)->len) |
| 163 |
|
|
| 164 |
|
SCANBAR *rootbar; /* root scan bar (lowest resolution) */ |
| 165 |
|
|
| 184 |
|
}; |
| 185 |
|
double l10La; |
| 186 |
|
register int i; |
| 187 |
< |
/* interpolate/extrapolate data */ |
| 187 |
> |
/* check limits */ |
| 188 |
> |
if (La <= 7.85e-4) |
| 189 |
> |
return(resfreq[0]); |
| 190 |
> |
if (La >= 1.78e3) |
| 191 |
> |
return(resfreq[NPOINTS-1]); |
| 192 |
> |
/* interpolate data */ |
| 193 |
|
l10La = log10(La); |
| 194 |
|
for (i = 0; i < NPOINTS-2 && l10lum[i+1] <= l10La; i++) |
| 195 |
|
; |
| 208 |
|
register COLOR *sl0, *sl1, *mysl; |
| 209 |
|
register int i; |
| 210 |
|
|
| 211 |
< |
if (y < sb->nread - sb->nscans) { |
| 212 |
< |
fprintf(stderr, "%s: internal - cannot backspace in getascan\n", |
| 201 |
< |
progname); |
| 202 |
< |
exit(1); |
| 203 |
< |
} |
| 211 |
> |
if (y < sb->nread - sb->nscans) /* too far back? */ |
| 212 |
> |
return(NULL); |
| 213 |
|
for ( ; y >= sb->nread; sb->nread++) { /* read as necessary */ |
| 214 |
|
mysl = bscan(sb, sb->nread); |
| 215 |
< |
if (sb->sampr == 1) { |
| 215 |
> |
if (sb->sampe == 0) { |
| 216 |
|
if (freadscan(mysl, sb->len, infp) < 0) { |
| 217 |
|
fprintf(stderr, "%s: %s: scanline read error\n", |
| 218 |
|
progname, infn); |
| 219 |
|
exit(1); |
| 220 |
|
} |
| 221 |
|
} else { |
| 222 |
< |
sl0 = getascan(sb->next, 2*y); |
| 223 |
< |
sl1 = getascan(sb->next, 2*y+1); |
| 222 |
> |
sl0 = getascan(sb+1, 2*y); |
| 223 |
> |
if (sl0 == NULL) |
| 224 |
> |
return(NULL); |
| 225 |
> |
sl1 = getascan(sb+1, 2*y+1); |
| 226 |
|
for (i = 0; i < sb->len; i++) { |
| 227 |
|
copycolor(mysl[i], sl0[2*i]); |
| 228 |
|
addcolor(mysl[i], sl0[2*i+1]); |
| 246 |
|
register int x; |
| 247 |
|
/* compute foveal y position */ |
| 248 |
|
iy = dy = (y+.5)/numscans(&inpres)*fvyr - .5; |
| 249 |
< |
if (iy >= fvyr-1) iy--; |
| 249 |
> |
while (iy >= fvyr-1) iy--; |
| 250 |
|
dy -= (double)iy; |
| 251 |
|
for (x = 0; x < scanlen(&inpres); x++) { |
| 252 |
|
/* compute foveal x position */ |
| 253 |
|
ix = dx = (x+.5)/scanlen(&inpres)*fvxr - .5; |
| 254 |
< |
if (ix >= fvxr-1) ix--; |
| 254 |
> |
while (ix >= fvxr-1) ix--; |
| 255 |
|
dx -= (double)ix; |
| 256 |
|
/* interpolate sample rate */ |
| 257 |
|
sr = (1.-dy)*((1.-dx)*tsampr(ix,iy) + dx*tsampr(ix+1,iy)) + |
| 271 |
|
double d; |
| 272 |
|
register SCANBAR *sb0; |
| 273 |
|
|
| 274 |
< |
for (sb0 = rootbar; sb0->next != NULL && sb0->next->sampr > sr; |
| 264 |
< |
sb0 = sb0->next) |
| 274 |
> |
for (sb0 = rootbar; sb0->sampe != 0 && 1<<sb0[1].sampe > sr; sb0++) |
| 275 |
|
; |
| 276 |
|
ascanval(col, x, y, sb0); |
| 277 |
< |
if (sb0->next == NULL) /* don't extrapolate highest */ |
| 277 |
> |
if (sb0->sampe == 0) /* don't extrapolate highest */ |
| 278 |
|
return; |
| 279 |
< |
ascanval(c1, x, y, sb0->next); |
| 280 |
< |
d = (sb0->sampr - sr)/(sb0->sampr - sb0->next->sampr); |
| 279 |
> |
ascanval(c1, x, y, sb0+1); |
| 280 |
> |
d = ((1<<sb0->sampe) - sr)/(1<<sb0[1].sampe); |
| 281 |
|
scalecolor(col, 1.-d); |
| 282 |
|
scalecolor(c1, d); |
| 283 |
|
addcolor(col, c1); |
| 293 |
|
double dx, dy; |
| 294 |
|
int ix, iy; |
| 295 |
|
|
| 296 |
< |
ix = dx = (x+.5)/sb->sampr - .5; |
| 297 |
< |
if (ix >= sb->len-1) ix--; |
| 296 |
> |
if (sb->sampe == 0) { /* no need to interpolate */ |
| 297 |
> |
sl0 = getascan(sb, y); |
| 298 |
> |
copycolor(col, sl0[x]); |
| 299 |
> |
return; |
| 300 |
> |
} |
| 301 |
> |
/* compute coordinates for sb */ |
| 302 |
> |
ix = dx = (x+.5)/(1<<sb->sampe) - .5; |
| 303 |
> |
while (ix >= sb->len-1) ix--; |
| 304 |
|
dx -= (double)ix; |
| 305 |
< |
iy = dy = (y+.5)/sb->sampr - .5; |
| 306 |
< |
if (iy >= numscans(&inpres)/sb->sampr-1) iy--; |
| 305 |
> |
iy = dy = (y+.5)/(1<<sb->sampe) - .5; |
| 306 |
> |
while (iy >= (numscans(&inpres)>>sb->sampe)-1) iy--; |
| 307 |
|
dy -= (double)iy; |
| 308 |
|
/* get scanlines */ |
| 309 |
|
sl0 = getascan(sb, iy); |
| 310 |
+ |
#ifdef DEBUG |
| 311 |
+ |
if (sl0 == NULL) { |
| 312 |
+ |
fprintf(stderr, "%s: internal - cannot backspace in ascanval\n", |
| 313 |
+ |
progname); |
| 314 |
+ |
abort(); |
| 315 |
+ |
} |
| 316 |
+ |
#endif |
| 317 |
|
sl1 = getascan(sb, iy+1); |
| 318 |
|
/* 2D linear interpolation */ |
| 319 |
|
copycolor(col, sl0[ix]); |
| 329 |
|
scalecolor(col, 1.-dy); |
| 330 |
|
scalecolor(c1y, dy); |
| 331 |
|
addcolor(col, c1y); |
| 332 |
+ |
for (ix = 0; ix < 3; ix++) /* make sure no negative */ |
| 333 |
+ |
if (colval(col,ix) < 0.) |
| 334 |
+ |
colval(col,ix) = 0.; |
| 335 |
|
} |
| 336 |
|
|
| 337 |
|
|
| 338 |
|
SCANBAR * |
| 339 |
< |
sballoc(sr, ns, sl) /* allocate scanbar */ |
| 340 |
< |
int sr; /* sampling rate */ |
| 339 |
> |
sballoc(se, ns, sl) /* allocate scanbar */ |
| 340 |
> |
int se; /* sampling rate exponent */ |
| 341 |
|
int ns; /* number of scanlines */ |
| 342 |
|
int sl; /* original scanline length */ |
| 343 |
|
{ |
| 344 |
+ |
SCANBAR *sbarr; |
| 345 |
|
register SCANBAR *sb; |
| 346 |
|
|
| 347 |
< |
sb = (SCANBAR *)malloc(sizeof(SCANBAR)+(sl/sr)*ns*sizeof(COLOR)); |
| 347 |
> |
sbarr = sb = (SCANBAR *)malloc((se+1)*sizeof(SCANBAR)); |
| 348 |
|
if (sb == NULL) |
| 349 |
|
syserror("malloc"); |
| 350 |
< |
sb->nscans = ns; |
| 351 |
< |
sb->len = sl/sr; |
| 352 |
< |
sb->nread = 0; |
| 353 |
< |
if ((sb->sampr = sr) > 1) |
| 354 |
< |
sb->next = sballoc(sr/2, ns*2, sl); |
| 355 |
< |
else |
| 356 |
< |
sb->next = NULL; |
| 357 |
< |
return(sb); |
| 350 |
> |
do { |
| 351 |
> |
sb->sampe = se; |
| 352 |
> |
sb->len = sl>>se; |
| 353 |
> |
sb->nscans = ns; |
| 354 |
> |
sb->sdata = (COLOR *)malloc(sb->len*ns*sizeof(COLOR)); |
| 355 |
> |
if (sb->sdata == NULL) |
| 356 |
> |
syserror("malloc"); |
| 357 |
> |
sb->nread = 0; |
| 358 |
> |
ns <<= 1; |
| 359 |
> |
sb++; |
| 360 |
> |
} while (--se >= 0); |
| 361 |
> |
return(sbarr); |
| 362 |
|
} |
| 363 |
|
|
| 364 |
|
|
| 386 |
|
} |
| 387 |
|
fcross(cp, diffx, diffy); |
| 388 |
|
omega = 0.5 * sqrt(DOT(cp,cp)); |
| 389 |
< |
tsampr(x,y) = PI/180. / sqrt(omega) / |
| 390 |
< |
hacuity(plum(fovscan(y)[x])); |
| 391 |
< |
if (tsampr(x,y) > maxsr) |
| 389 |
> |
if (omega <= FTINY*FTINY) |
| 390 |
> |
tsampr(x,y) = 1.; |
| 391 |
> |
else if ((tsampr(x,y) = PI/180. / sqrt(omega) / |
| 392 |
> |
hacuity(plum(fovscan(y)[x]))) > maxsr) |
| 393 |
|
maxsr = tsampr(x,y); |
| 394 |
|
} |
| 395 |
|
/* copy perimeter (easier) */ |
| 398 |
|
tsampr(x,fvyr-1) = tsampr(x,fvyr-2); |
| 399 |
|
} |
| 400 |
|
for (y = 0; y < fvyr; y++) { |
| 401 |
< |
tsampr(y,0) = tsampr(y,1); |
| 402 |
< |
tsampr(y,fvxr-1) = tsampr(y,fvxr-2); |
| 401 |
> |
tsampr(0,y) = tsampr(1,y); |
| 402 |
> |
tsampr(fvxr-1,y) = tsampr(fvxr-2,y); |
| 403 |
|
} |
| 404 |
|
/* initialize with next power of two */ |
| 405 |
< |
rootbar = sballoc(2<<(int)(log(maxsr)/log(2.)), 2, scanlen(&inpres)); |
| 405 |
> |
rootbar = sballoc((int)(log(maxsr)/log(2.))+1, 2, scanlen(&inpres)); |
| 406 |
|
} |