10 |
|
|
11 |
|
#include "pcond.h" |
12 |
|
|
13 |
+ |
/************** VEILING STUFF *****************/ |
14 |
|
|
15 |
|
#define VADAPT 0.08 /* fraction of adaptation from veil */ |
16 |
|
|
138 |
|
(1.-dx)*lv + dx*uv; |
139 |
|
} |
140 |
|
} |
141 |
+ |
} |
142 |
+ |
|
143 |
+ |
|
144 |
+ |
/****************** ACUITY STUFF *******************/ |
145 |
+ |
|
146 |
+ |
typedef struct scanbar { |
147 |
+ |
short sampr; /* sample area size (power of 2) */ |
148 |
+ |
short nscans; /* number of scanlines in this bar */ |
149 |
+ |
int len; /* individual scanline length */ |
150 |
+ |
struct scanbar *next; /* next higher resolution scanbar */ |
151 |
+ |
int nread; /* number of scanlines loaded */ |
152 |
+ |
/* followed by the scanline data */ |
153 |
+ |
} SCANBAR; |
154 |
+ |
|
155 |
+ |
#define bscan(sb,y) ((COLOR *)((sb)+1)+((y)%(sb)->nscans)*(sb)->len) |
156 |
+ |
|
157 |
+ |
SCANBAR *rootbar; /* root scan bar (lowest resolution) */ |
158 |
+ |
|
159 |
+ |
float *inpacuD; /* input acuity data (cycles/degree) */ |
160 |
+ |
|
161 |
+ |
#define tsampr(x,y) inpacuD[(y)*fvxr+(x)] |
162 |
+ |
|
163 |
+ |
|
164 |
+ |
double |
165 |
+ |
hacuity(La) /* return visual acuity in cycles/degree */ |
166 |
+ |
double La; |
167 |
+ |
{ /* data due to S. Shaler (we should fit it!) */ |
168 |
+ |
#define NPOINTS 20 |
169 |
+ |
static float l10lum[NPOINTS] = { |
170 |
+ |
-3.10503,-2.66403,-2.37703,-2.09303,-1.64403,-1.35803, |
171 |
+ |
-1.07403,-0.67203,-0.38503,-0.10103,0.29397,0.58097,0.86497, |
172 |
+ |
1.25697,1.54397,1.82797,2.27597,2.56297,2.84697,3.24897 |
173 |
+ |
}; |
174 |
+ |
static float resfreq[NPOINTS] = { |
175 |
+ |
2.09,3.28,3.79,4.39,6.11,8.83,10.94,18.66,23.88,31.05,37.42, |
176 |
+ |
37.68,41.60,43.16,45.30,47.00,48.43,48.32,51.06,51.09 |
177 |
+ |
}; |
178 |
+ |
double l10La; |
179 |
+ |
register int i; |
180 |
+ |
/* interpolate/extrapolate data */ |
181 |
+ |
l10La = log10(La); |
182 |
+ |
for (i = 0; i < NPOINTS-2 && l10lum[i+1] <= l10La; i++) |
183 |
+ |
; |
184 |
+ |
return( ( (l10lum[i+1] - l10La)*resfreq[i] + |
185 |
+ |
(l10La - l10lum[i])*resfreq[i+1] ) / |
186 |
+ |
(l10lum[i+1] - l10lum[i]) ); |
187 |
+ |
#undef NPOINTS |
188 |
+ |
} |
189 |
+ |
|
190 |
+ |
|
191 |
+ |
COLOR * |
192 |
+ |
getascan(sb, y) /* find/read scanline y for scanbar sb */ |
193 |
+ |
register SCANBAR *sb; |
194 |
+ |
int y; |
195 |
+ |
{ |
196 |
+ |
register COLOR *sl0, *sl1, *mysl; |
197 |
+ |
register int i; |
198 |
+ |
|
199 |
+ |
if (y < sb->nread - sb->nscans) { |
200 |
+ |
fprintf(stderr, "%s: internal - cannot backspace in getascan\n", |
201 |
+ |
progname); |
202 |
+ |
exit(1); |
203 |
+ |
} |
204 |
+ |
for ( ; y >= sb->nread; sb->nread++) { /* read as necessary */ |
205 |
+ |
mysl = bscan(sb, sb->nread); |
206 |
+ |
if (sb->sampr == 1) { |
207 |
+ |
if (freadscan(mysl, sb->len, infp) < 0) { |
208 |
+ |
fprintf(stderr, "%s: %s: scanline read error\n", |
209 |
+ |
progname, infn); |
210 |
+ |
exit(1); |
211 |
+ |
} |
212 |
+ |
} else { |
213 |
+ |
sl0 = getascan(sb->next, 2*y); |
214 |
+ |
sl1 = getascan(sb->next, 2*y+1); |
215 |
+ |
for (i = 0; i < sb->len; i++) { |
216 |
+ |
copycolor(mysl[i], sl0[2*i]); |
217 |
+ |
addcolor(mysl[i], sl0[2*i+1]); |
218 |
+ |
addcolor(mysl[i], sl1[2*i]); |
219 |
+ |
addcolor(mysl[i], sl1[2*i+1]); |
220 |
+ |
scalecolor(mysl[i], 0.25); |
221 |
+ |
} |
222 |
+ |
} |
223 |
+ |
} |
224 |
+ |
return(bscan(sb, y)); |
225 |
+ |
} |
226 |
+ |
|
227 |
+ |
|
228 |
+ |
acuscan(scln, y) /* get acuity-sampled scanline */ |
229 |
+ |
COLOR *scln; |
230 |
+ |
int y; |
231 |
+ |
{ |
232 |
+ |
double sr; |
233 |
+ |
double dx, dy; |
234 |
+ |
int ix, iy; |
235 |
+ |
register int x; |
236 |
+ |
/* compute foveal y position */ |
237 |
+ |
iy = dy = (y+.5)/numscans(&inpres)*fvyr - .5; |
238 |
+ |
if (iy >= fvyr-1) iy--; |
239 |
+ |
dy -= (double)iy; |
240 |
+ |
for (x = 0; x < scanlen(&inpres); x++) { |
241 |
+ |
/* compute foveal x position */ |
242 |
+ |
ix = dx = (x+.5)/scanlen(&inpres)*fvxr - .5; |
243 |
+ |
if (ix >= fvxr-1) ix--; |
244 |
+ |
dx -= (double)ix; |
245 |
+ |
/* interpolate sample rate */ |
246 |
+ |
sr = (1.-dy)*((1.-dx)*tsampr(ix,iy) + dx*tsampr(ix+1,iy)) + |
247 |
+ |
dy*((1.-dx)*tsampr(ix,iy+1) + dx*tsampr(ix+1,iy+1)); |
248 |
+ |
|
249 |
+ |
acusample(scln[x], x, y, sr); /* compute sample */ |
250 |
+ |
} |
251 |
+ |
} |
252 |
+ |
|
253 |
+ |
|
254 |
+ |
acusample(col, x, y, sr) /* interpolate sample at (x,y) using rate sr */ |
255 |
+ |
COLOR col; |
256 |
+ |
int x, y; |
257 |
+ |
double sr; |
258 |
+ |
{ |
259 |
+ |
COLOR c1; |
260 |
+ |
double d; |
261 |
+ |
register SCANBAR *sb0; |
262 |
+ |
|
263 |
+ |
for (sb0 = rootbar; sb0->next != NULL && sb0->next->sampr > sr; |
264 |
+ |
sb0 = sb0->next) |
265 |
+ |
; |
266 |
+ |
ascanval(col, x, y, sb0); |
267 |
+ |
if (sb0->next == NULL) /* don't extrapolate highest */ |
268 |
+ |
return; |
269 |
+ |
ascanval(c1, x, y, sb0->next); |
270 |
+ |
d = (sb0->sampr - sr)/(sb0->sampr - sb0->next->sampr); |
271 |
+ |
scalecolor(col, 1.-d); |
272 |
+ |
scalecolor(c1, d); |
273 |
+ |
addcolor(col, c1); |
274 |
+ |
} |
275 |
+ |
|
276 |
+ |
|
277 |
+ |
ascanval(col, x, y, sb) /* interpolate scanbar at orig. coords (x,y) */ |
278 |
+ |
COLOR col; |
279 |
+ |
int x, y; |
280 |
+ |
SCANBAR *sb; |
281 |
+ |
{ |
282 |
+ |
COLOR *sl0, *sl1, c1, c1y; |
283 |
+ |
double dx, dy; |
284 |
+ |
int ix, iy; |
285 |
+ |
|
286 |
+ |
ix = dx = (x+.5)/sb->sampr - .5; |
287 |
+ |
if (ix >= sb->len-1) ix--; |
288 |
+ |
dx -= (double)ix; |
289 |
+ |
iy = dy = (y+.5)/sb->sampr - .5; |
290 |
+ |
if (iy >= numscans(&inpres)/sb->sampr-1) iy--; |
291 |
+ |
dy -= (double)iy; |
292 |
+ |
/* get scanlines */ |
293 |
+ |
sl0 = getascan(sb, iy); |
294 |
+ |
sl1 = getascan(sb, iy+1); |
295 |
+ |
/* 2D linear interpolation */ |
296 |
+ |
copycolor(col, sl0[ix]); |
297 |
+ |
scalecolor(col, 1.-dx); |
298 |
+ |
copycolor(c1, sl0[ix+1]); |
299 |
+ |
scalecolor(c1, dx); |
300 |
+ |
addcolor(col, c1); |
301 |
+ |
copycolor(c1y, sl1[ix]); |
302 |
+ |
scalecolor(c1y, 1.-dx); |
303 |
+ |
copycolor(c1, sl1[ix+1]); |
304 |
+ |
scalecolor(c1, dx); |
305 |
+ |
addcolor(c1y, c1); |
306 |
+ |
scalecolor(col, 1.-dy); |
307 |
+ |
scalecolor(c1y, dy); |
308 |
+ |
addcolor(col, c1y); |
309 |
+ |
} |
310 |
+ |
|
311 |
+ |
|
312 |
+ |
SCANBAR * |
313 |
+ |
sballoc(sr, ns, sl) /* allocate scanbar */ |
314 |
+ |
int sr; /* sampling rate */ |
315 |
+ |
int ns; /* number of scanlines */ |
316 |
+ |
int sl; /* original scanline length */ |
317 |
+ |
{ |
318 |
+ |
register SCANBAR *sb; |
319 |
+ |
|
320 |
+ |
sb = (SCANBAR *)malloc(sizeof(SCANBAR)+(sl/sr)*ns*sizeof(COLOR)); |
321 |
+ |
if (sb == NULL) |
322 |
+ |
syserror("malloc"); |
323 |
+ |
sb->nscans = ns; |
324 |
+ |
sb->len = sl/sr; |
325 |
+ |
sb->nread = 0; |
326 |
+ |
if ((sb->sampr = sr) > 1) |
327 |
+ |
sb->next = sballoc(sr/2, ns*2, sl); |
328 |
+ |
else |
329 |
+ |
sb->next = NULL; |
330 |
+ |
return(sb); |
331 |
+ |
} |
332 |
+ |
|
333 |
+ |
|
334 |
+ |
initacuity() /* initialize variable acuity sampling */ |
335 |
+ |
{ |
336 |
+ |
FVECT diffx, diffy, cp; |
337 |
+ |
double omega, maxsr; |
338 |
+ |
register int x, y, i; |
339 |
+ |
|
340 |
+ |
compraydir(); /* compute ray directions */ |
341 |
+ |
|
342 |
+ |
inpacuD = (float *)malloc(fvxr*fvyr*sizeof(float)); |
343 |
+ |
if (inpacuD == NULL) |
344 |
+ |
syserror("malloc"); |
345 |
+ |
maxsr = 1.; /* compute internal sample rates */ |
346 |
+ |
for (y = 1; y < fvyr-1; y++) |
347 |
+ |
for (x = 1; x < fvxr-1; x++) { |
348 |
+ |
for (i = 0; i < 3; i++) { |
349 |
+ |
diffx[i] = 0.5*fvxr/scanlen(&inpres) * |
350 |
+ |
(rdirscan(y)[x+1][i] - |
351 |
+ |
rdirscan(y)[x-1][i]); |
352 |
+ |
diffy[i] = 0.5*fvyr/numscans(&inpres) * |
353 |
+ |
(rdirscan(y+1)[x][i] - |
354 |
+ |
rdirscan(y-1)[x][i]); |
355 |
+ |
} |
356 |
+ |
fcross(cp, diffx, diffy); |
357 |
+ |
omega = 0.5 * sqrt(DOT(cp,cp)); |
358 |
+ |
tsampr(x,y) = PI/180. / sqrt(omega) / |
359 |
+ |
hacuity(plum(fovscan(y)[x])); |
360 |
+ |
if (tsampr(x,y) > maxsr) |
361 |
+ |
maxsr = tsampr(x,y); |
362 |
+ |
} |
363 |
+ |
/* copy perimeter (easier) */ |
364 |
+ |
for (x = 1; x < fvxr-1; x++) { |
365 |
+ |
tsampr(x,0) = tsampr(x,1); |
366 |
+ |
tsampr(x,fvyr-1) = tsampr(x,fvyr-2); |
367 |
+ |
} |
368 |
+ |
for (y = 0; y < fvyr; y++) { |
369 |
+ |
tsampr(y,0) = tsampr(y,1); |
370 |
+ |
tsampr(y,fvxr-1) = tsampr(y,fvxr-2); |
371 |
+ |
} |
372 |
+ |
/* initialize with next power of two */ |
373 |
+ |
rootbar = sballoc(2<<(int)(log(maxsr)/log(2.)), 2, scanlen(&inpres)); |
374 |
|
} |