31 |
|
|
32 |
|
int fromstdin = 0; |
33 |
|
|
34 |
+ |
int unbuffered = 0; |
35 |
+ |
|
36 |
+ |
int repeatcnt = 1; |
37 |
+ |
|
38 |
|
char *progname; |
39 |
|
|
40 |
|
|
46 |
|
{ |
47 |
|
char *err; |
48 |
|
int rval, getdim = 0; |
49 |
< |
register int i; |
49 |
> |
int i; |
50 |
|
|
51 |
|
progname = argv[0]; |
52 |
|
if (argc < 2) |
105 |
|
exit(1); |
106 |
|
} |
107 |
|
break; |
108 |
+ |
case 'c': /* repeat count */ |
109 |
+ |
repeatcnt = atoi(argv[++i]); |
110 |
+ |
break; |
111 |
|
case 'p': /* pixel aspect or jitter */ |
112 |
|
if (argv[i][2] == 'a') |
113 |
|
pa = atof(argv[++i]); |
114 |
|
else if (argv[i][2] == 'j') |
115 |
< |
pj= atof(argv[++i]); |
115 |
> |
pj = atof(argv[++i]); |
116 |
|
else |
117 |
|
goto userr; |
118 |
|
break; |
119 |
|
case 'i': /* get pixels from stdin */ |
120 |
|
fromstdin = 1; |
121 |
|
break; |
122 |
+ |
case 'u': /* unbuffered output */ |
123 |
+ |
unbuffered = 1; |
124 |
+ |
break; |
125 |
|
default: |
126 |
|
goto userr; |
127 |
|
} |
161 |
|
exit(0); |
162 |
|
userr: |
163 |
|
fprintf(stderr, |
164 |
< |
"Usage: %s [ -i -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n", |
164 |
> |
"Usage: %s [ -i -u -f{a|f|d} -c rept | -d ] { view opts .. | picture [zbuf] }\n", |
165 |
|
progname); |
166 |
|
exit(1); |
167 |
|
} |
190 |
|
RREAL loc[2]; |
191 |
|
int pp[2]; |
192 |
|
double d; |
193 |
< |
register int i; |
193 |
> |
int i; |
194 |
|
|
195 |
|
while (fscanf(fp, "%lf %lf", &px, &py) == 2) { |
196 |
|
px += .5; py += .5; |
197 |
|
loc[0] = px/rs.xr; loc[1] = py/rs.yr; |
198 |
|
if (zfd >= 0) { |
199 |
+ |
if ((loc[0] < 0) | (loc[0] >= 1) | |
200 |
+ |
(loc[1] < 0) | (loc[1] >= 1)) { |
201 |
+ |
fprintf(stderr, "%s: input pixel outside image\n", |
202 |
+ |
progname); |
203 |
+ |
exit(1); |
204 |
+ |
} |
205 |
|
loc2pix(pp, &rs, loc[0], loc[1]); |
206 |
|
if (lseek(zfd, |
207 |
|
(pp[1]*scanlen(&rs)+pp[0])*sizeof(float), |
227 |
|
rdir[0] *= d; rdir[1] *= d; rdir[2] *= d; |
228 |
|
} |
229 |
|
(*putr)(rorg, rdir); |
230 |
+ |
if (unbuffered) |
231 |
+ |
fflush(stdout); |
232 |
|
} |
233 |
|
if (!feof(fp)) { |
234 |
|
fprintf(stderr, "%s: expected px py on input\n", progname); |
245 |
|
float *zbuf = NULL; |
246 |
|
int sc; |
247 |
|
double d; |
248 |
< |
register int si, i; |
248 |
> |
int si, i, c; |
249 |
|
|
250 |
|
if (zfd >= 0) { |
251 |
|
zbuf = (float *)malloc(scanlen(&rs)*sizeof(float)); |
264 |
|
} |
265 |
|
} |
266 |
|
for (si = 0; si < scanlen(&rs); si++) { |
267 |
+ |
for (c = repeatcnt; c-- > 0; ) { |
268 |
|
pix2loc(loc, &rs, si, sc); |
269 |
|
jitterloc(loc); |
270 |
|
d = viewray(rorg, rdir, &vw, loc[0], loc[1]); |
280 |
|
rdir[0] *= d; rdir[1] *= d; rdir[2] *= d; |
281 |
|
} |
282 |
|
(*putr)(rorg, rdir); |
283 |
+ |
} |
284 |
|
} |
285 |
|
} |
286 |
|
if (zfd >= 0) |
310 |
|
|
311 |
|
v[0] = ro[0]; v[1] = ro[1]; v[2] = ro[2]; |
312 |
|
v[3] = rd[0]; v[4] = rd[1]; v[5] = rd[2]; |
313 |
< |
fwrite(v, sizeof(float), 6, stdout); |
313 |
> |
putbinary(v, sizeof(float), 6, stdout); |
314 |
|
} |
315 |
|
|
316 |
|
|
324 |
|
|
325 |
|
v[0] = ro[0]; v[1] = ro[1]; v[2] = ro[2]; |
326 |
|
v[3] = rd[0]; v[4] = rd[1]; v[5] = rd[2]; |
327 |
< |
fwrite(v, sizeof(double), 6, stdout); |
327 |
> |
putbinary(v, sizeof(double), 6, stdout); |
328 |
|
} |