126 |
|
register int x, i; |
127 |
|
|
128 |
|
vy = dy = (y+.5)/numscans(&inpres)*fvyr - .5; |
129 |
< |
if (vy >= fvyr-1) vy--; |
129 |
> |
while (vy >= fvyr-1) vy--; |
130 |
|
dy -= (double)vy; |
131 |
|
for (x = 0; x < scanlen(&inpres); x++) { |
132 |
|
vx = dx = (x+.5)/scanlen(&inpres)*fvxr - .5; |
133 |
< |
if (vx >= fvxr-1) vx--; |
133 |
> |
while (vx >= fvxr-1) vx--; |
134 |
|
dx -= (double)vx; |
135 |
|
for (i = 0; i < 3; i++) { |
136 |
|
lv = (1.-dy)*colval(veilscan(vy)[vx],i) + |
146 |
|
|
147 |
|
/****************** ACUITY STUFF *******************/ |
148 |
|
|
149 |
< |
typedef struct scanbar { |
150 |
< |
short sampr; /* sample area size (power of 2) */ |
149 |
> |
typedef struct { |
150 |
> |
short sampe; /* sample area size (exponent of 2) */ |
151 |
|
short nscans; /* number of scanlines in this bar */ |
152 |
|
int len; /* individual scanline length */ |
153 |
– |
struct scanbar *next; /* next higher resolution scanbar */ |
153 |
|
int nread; /* number of scanlines loaded */ |
154 |
< |
/* followed by the scanline data */ |
154 |
> |
COLOR *sdata; /* scanbar data */ |
155 |
|
} SCANBAR; |
156 |
|
|
157 |
< |
#define bscan(sb,y) ((COLOR *)((sb)+1)+((y)%(sb)->nscans)*(sb)->len) |
157 |
> |
#define bscan(sb,y) ((COLOR *)(sb)->sdata+((y)%(sb)->nscans)*(sb)->len) |
158 |
|
|
159 |
|
SCANBAR *rootbar; /* root scan bar (lowest resolution) */ |
160 |
|
|
207 |
|
return(NULL); |
208 |
|
for ( ; y >= sb->nread; sb->nread++) { /* read as necessary */ |
209 |
|
mysl = bscan(sb, sb->nread); |
210 |
< |
if (sb->sampr == 1) { |
210 |
> |
if (sb->sampe == 0) { |
211 |
|
if (freadscan(mysl, sb->len, infp) < 0) { |
212 |
|
fprintf(stderr, "%s: %s: scanline read error\n", |
213 |
|
progname, infn); |
214 |
|
exit(1); |
215 |
|
} |
216 |
|
} else { |
217 |
< |
sl0 = getascan(sb->next, 2*y); |
217 |
> |
sl0 = getascan(sb+1, 2*y); |
218 |
|
if (sl0 == NULL) |
219 |
|
return(NULL); |
220 |
< |
sl1 = getascan(sb->next, 2*y+1); |
220 |
> |
sl1 = getascan(sb+1, 2*y+1); |
221 |
|
for (i = 0; i < sb->len; i++) { |
222 |
|
copycolor(mysl[i], sl0[2*i]); |
223 |
|
addcolor(mysl[i], sl0[2*i+1]); |
241 |
|
register int x; |
242 |
|
/* compute foveal y position */ |
243 |
|
iy = dy = (y+.5)/numscans(&inpres)*fvyr - .5; |
244 |
< |
if (iy >= fvyr-1) iy--; |
244 |
> |
while (iy >= fvyr-1) iy--; |
245 |
|
dy -= (double)iy; |
246 |
|
for (x = 0; x < scanlen(&inpres); x++) { |
247 |
|
/* compute foveal x position */ |
248 |
|
ix = dx = (x+.5)/scanlen(&inpres)*fvxr - .5; |
249 |
< |
if (ix >= fvxr-1) ix--; |
249 |
> |
while (ix >= fvxr-1) ix--; |
250 |
|
dx -= (double)ix; |
251 |
|
/* interpolate sample rate */ |
252 |
|
sr = (1.-dy)*((1.-dx)*tsampr(ix,iy) + dx*tsampr(ix+1,iy)) + |
266 |
|
double d; |
267 |
|
register SCANBAR *sb0; |
268 |
|
|
269 |
< |
for (sb0 = rootbar; sb0->next != NULL && sb0->next->sampr > sr; |
271 |
< |
sb0 = sb0->next) |
269 |
> |
for (sb0 = rootbar; sb0->sampe != 0 && 1<<sb0[1].sampe > sr; sb0++) |
270 |
|
; |
271 |
|
ascanval(col, x, y, sb0); |
272 |
< |
if (sb0->next == NULL) /* don't extrapolate highest */ |
272 |
> |
if (sb0->sampe == 0) /* don't extrapolate highest */ |
273 |
|
return; |
274 |
< |
ascanval(c1, x, y, sb0->next); |
275 |
< |
d = (sb0->sampr - sr)/(sb0->sampr - sb0->next->sampr); |
274 |
> |
ascanval(c1, x, y, sb0+1); |
275 |
> |
d = ((1<<sb0->sampe) - sr)/(1<<sb0[1].sampe); |
276 |
|
scalecolor(col, 1.-d); |
277 |
|
scalecolor(c1, d); |
278 |
|
addcolor(col, c1); |
288 |
|
double dx, dy; |
289 |
|
int ix, iy; |
290 |
|
|
291 |
< |
if (sb->sampr == 1) { /* no need to interpolate */ |
291 |
> |
if (sb->sampe == 0) { /* no need to interpolate */ |
292 |
|
sl0 = getascan(sb, y); |
293 |
|
copycolor(col, sl0[x]); |
294 |
|
return; |
295 |
|
} |
296 |
|
/* compute coordinates for sb */ |
297 |
< |
ix = dx = (x+.5)/sb->sampr - .5; |
298 |
< |
if (ix >= sb->len-1) ix--; |
297 |
> |
ix = dx = (x+.5)/(1<<sb->sampe) - .5; |
298 |
> |
while (ix >= sb->len-1) ix--; |
299 |
|
dx -= (double)ix; |
300 |
< |
iy = dy = (y+.5)/sb->sampr - .5; |
301 |
< |
if (iy >= numscans(&inpres)/sb->sampr-1) iy--; |
300 |
> |
iy = dy = (y+.5)/(1<<sb->sampe) - .5; |
301 |
> |
while (iy >= (numscans(&inpres)>>sb->sampe)-1) iy--; |
302 |
|
dy -= (double)iy; |
303 |
|
/* get scanlines */ |
304 |
|
sl0 = getascan(sb, iy); |
305 |
+ |
#ifdef DEBUG |
306 |
|
if (sl0 == NULL) { |
307 |
|
fprintf(stderr, "%s: internal - cannot backspace in ascanval\n", |
308 |
|
progname); |
309 |
< |
exit(1); |
309 |
> |
abort(); |
310 |
|
} |
311 |
+ |
#endif |
312 |
|
sl1 = getascan(sb, iy+1); |
313 |
|
/* 2D linear interpolation */ |
314 |
|
copycolor(col, sl0[ix]); |
324 |
|
scalecolor(col, 1.-dy); |
325 |
|
scalecolor(c1y, dy); |
326 |
|
addcolor(col, c1y); |
327 |
+ |
for (ix = 0; ix < 3; ix++) /* make sure no negative */ |
328 |
+ |
if (colval(col,ix) < 0.) |
329 |
+ |
colval(col,ix) = 0.; |
330 |
|
} |
331 |
|
|
332 |
|
|
333 |
|
SCANBAR * |
334 |
< |
sballoc(sr, ns, sl) /* allocate scanbar */ |
335 |
< |
int sr; /* sampling rate */ |
334 |
> |
sballoc(se, ns, sl) /* allocate scanbar */ |
335 |
> |
int se; /* sampling rate exponent */ |
336 |
|
int ns; /* number of scanlines */ |
337 |
|
int sl; /* original scanline length */ |
338 |
|
{ |
339 |
+ |
SCANBAR *sbarr; |
340 |
|
register SCANBAR *sb; |
341 |
|
|
342 |
< |
sb = (SCANBAR *)malloc(sizeof(SCANBAR)+(sl/sr)*ns*sizeof(COLOR)); |
342 |
> |
sbarr = sb = (SCANBAR *)malloc((se+1)*sizeof(SCANBAR)); |
343 |
|
if (sb == NULL) |
344 |
|
syserror("malloc"); |
345 |
< |
sb->nscans = ns; |
346 |
< |
sb->len = sl/sr; |
347 |
< |
sb->nread = 0; |
348 |
< |
if ((sb->sampr = sr) > 1) |
349 |
< |
sb->next = sballoc(sr/2, ns*2, sl); |
350 |
< |
else |
351 |
< |
sb->next = NULL; |
352 |
< |
return(sb); |
345 |
> |
do { |
346 |
> |
sb->sampe = se; |
347 |
> |
sb->len = sl>>se; |
348 |
> |
sb->nscans = ns; |
349 |
> |
sb->sdata = (COLOR *)malloc(sb->len*ns*sizeof(COLOR)); |
350 |
> |
if (sb->sdata == NULL) |
351 |
> |
syserror("malloc"); |
352 |
> |
sb->nread = 0; |
353 |
> |
ns <<= 1; |
354 |
> |
sb++; |
355 |
> |
} while (--se >= 0); |
356 |
> |
return(sbarr); |
357 |
|
} |
358 |
|
|
359 |
|
|
381 |
|
} |
382 |
|
fcross(cp, diffx, diffy); |
383 |
|
omega = 0.5 * sqrt(DOT(cp,cp)); |
384 |
< |
if (omega <= FTINY) |
384 |
> |
if (omega <= FTINY*FTINY) |
385 |
|
tsampr(x,y) = 1.; |
386 |
|
else if ((tsampr(x,y) = PI/180. / sqrt(omega) / |
387 |
|
hacuity(plum(fovscan(y)[x]))) > maxsr) |
393 |
|
tsampr(x,fvyr-1) = tsampr(x,fvyr-2); |
394 |
|
} |
395 |
|
for (y = 0; y < fvyr; y++) { |
396 |
< |
tsampr(y,0) = tsampr(y,1); |
397 |
< |
tsampr(y,fvxr-1) = tsampr(y,fvxr-2); |
396 |
> |
tsampr(0,y) = tsampr(1,y); |
397 |
> |
tsampr(fvxr-1,y) = tsampr(fvxr-2,y); |
398 |
|
} |
399 |
|
/* initialize with next power of two */ |
400 |
< |
rootbar = sballoc(2<<(int)(log(maxsr)/log(2.)), 2, scanlen(&inpres)); |
400 |
> |
rootbar = sballoc((int)(log(maxsr)/log(2.))+1, 2, scanlen(&inpres)); |
401 |
|
} |