| 32 |
|
int gotview; /* got input view? */ |
| 33 |
|
|
| 34 |
|
double theirs2ours[4][4]; /* transformation matrix */ |
| 35 |
+ |
int regdist = 0; /* regular distance? */ |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
main(argc, argv) /* interpolate pictures */ |
| 52 |
|
check(2,1); |
| 53 |
|
zeps = atof(argv[++i]); |
| 54 |
|
break; |
| 55 |
+ |
case 'r': /* regular distance */ |
| 56 |
+ |
check(2,0); |
| 57 |
+ |
regdist = !regdist; |
| 58 |
+ |
break; |
| 59 |
|
case 'x': /* x resolution */ |
| 60 |
|
check(2,1); |
| 61 |
|
ourview.hresolu = atoi(argv[++i]); |
| 114 |
|
break; |
| 115 |
|
default: |
| 116 |
|
badopt: |
| 117 |
< |
fprintf(stderr, "%s: unknown option '%s'\n", |
| 117 |
> |
fprintf(stderr, "%s: command line error at '%s'\n", |
| 118 |
|
progname, argv[i]); |
| 119 |
< |
exit(1); |
| 119 |
> |
goto userr; |
| 120 |
|
} |
| 121 |
|
/* check arguments */ |
| 122 |
< |
if (argc-i < 2 || (argc-i)%2) { |
| 123 |
< |
fprintf(stderr, "Usage: %s [view args] pfile zfile ..\n", |
| 119 |
< |
progname); |
| 120 |
< |
exit(1); |
| 121 |
< |
} |
| 122 |
> |
if (argc-i < 2 || (argc-i)%2) |
| 123 |
> |
goto userr; |
| 124 |
|
/* set view */ |
| 125 |
|
if (err = setview(&ourview)) { |
| 126 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
| 150 |
|
writepicture(); |
| 151 |
|
|
| 152 |
|
exit(0); |
| 153 |
+ |
userr: |
| 154 |
+ |
fprintf(stderr, |
| 155 |
+ |
"Usage: %s [view opts][-t zthresh][-r] pfile zspec ..\n", |
| 156 |
+ |
progname); |
| 157 |
+ |
exit(1); |
| 158 |
|
#undef check |
| 159 |
|
} |
| 160 |
|
|
| 176 |
|
} |
| 177 |
|
|
| 178 |
|
|
| 179 |
< |
addpicture(pfile, zfile) /* add picture to output */ |
| 180 |
< |
char *pfile, *zfile; |
| 179 |
> |
addpicture(pfile, zspec) /* add picture to output */ |
| 180 |
> |
char *pfile, *zspec; |
| 181 |
|
{ |
| 182 |
+ |
extern double atof(); |
| 183 |
|
FILE *pfp, *zfp; |
| 184 |
|
char *err; |
| 185 |
|
COLR *scanin; |
| 186 |
< |
float *zin, *zout; |
| 187 |
< |
int *pout; |
| 180 |
< |
int xres, yres; |
| 186 |
> |
float *zin, *zlast; |
| 187 |
> |
int *plast; |
| 188 |
|
int y; |
| 189 |
< |
/* open input files */ |
| 189 |
> |
/* open picture file */ |
| 190 |
|
if ((pfp = fopen(pfile, "r")) == NULL) { |
| 191 |
|
perror(pfile); |
| 192 |
|
exit(1); |
| 193 |
|
} |
| 187 |
– |
if ((zfp = fopen(zfile, "r")) == NULL) { |
| 188 |
– |
perror(zfile); |
| 189 |
– |
exit(1); |
| 190 |
– |
} |
| 194 |
|
/* get header and view */ |
| 195 |
|
printf("%s:\n", pfile); |
| 196 |
|
gotview = 0; |
| 197 |
|
getheader(pfp, headline); |
| 198 |
< |
if (!gotview || fgetresolu(&xres, &yres, pfp) != (YMAJOR|YDECR)) { |
| 198 |
> |
if (!gotview || fgetresolu(&theirview.hresolu, &theirview.vresolu, pfp) |
| 199 |
> |
!= (YMAJOR|YDECR)) { |
| 200 |
|
fprintf(stderr, "%s: picture view error\n", pfile); |
| 201 |
|
exit(1); |
| 202 |
|
} |
| 199 |
– |
theirview.hresolu = xres; |
| 200 |
– |
theirview.vresolu = yres; |
| 203 |
|
if (err = setview(&theirview)) { |
| 204 |
|
fprintf(stderr, "%s: %s\n", pfile, err); |
| 205 |
|
exit(1); |
| 207 |
|
/* compute transformation */ |
| 208 |
|
pixform(theirs2ours, &theirview, &ourview); |
| 209 |
|
/* allocate scanlines */ |
| 210 |
< |
scanin = (COLR *)malloc(xres*sizeof(COLR)); |
| 211 |
< |
zin = (float *)malloc(xres*sizeof(float)); |
| 212 |
< |
zout = (float *)calloc(xres, sizeof(float)); |
| 213 |
< |
pout = (int *)calloc(xres, sizeof(int)); |
| 214 |
< |
if (scanin == NULL || zin == NULL || zout == NULL || pout == NULL) { |
| 210 |
> |
scanin = (COLR *)malloc(theirview.hresolu*sizeof(COLR)); |
| 211 |
> |
zin = (float *)malloc(theirview.hresolu*sizeof(float)); |
| 212 |
> |
plast = (int *)calloc(theirview.hresolu, sizeof(int)); |
| 213 |
> |
zlast = (float *)calloc(theirview.hresolu, sizeof(float)); |
| 214 |
> |
if (scanin == NULL || zin == NULL || plast == NULL || zlast == NULL) { |
| 215 |
|
perror(progname); |
| 216 |
|
exit(1); |
| 217 |
|
} |
| 218 |
+ |
/* get z specification or file */ |
| 219 |
+ |
if ((zfp = fopen(zspec, "r")) == NULL) { |
| 220 |
+ |
double zvalue; |
| 221 |
+ |
register int x; |
| 222 |
+ |
if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) { |
| 223 |
+ |
perror(zspec); |
| 224 |
+ |
exit(1); |
| 225 |
+ |
} |
| 226 |
+ |
for (x = 0; x < theirview.hresolu; x++) |
| 227 |
+ |
zin[x] = zvalue; |
| 228 |
+ |
} |
| 229 |
|
/* load image */ |
| 230 |
< |
for (y = yres-1; y >= 0; y--) { |
| 231 |
< |
if (freadcolrs(scanin, xres, pfp) < 0) { |
| 230 |
> |
for (y = theirview.vresolu-1; y >= 0; y--) { |
| 231 |
> |
if (freadcolrs(scanin, theirview.hresolu, pfp) < 0) { |
| 232 |
|
fprintf(stderr, "%s: read error\n", pfile); |
| 233 |
|
exit(1); |
| 234 |
|
} |
| 235 |
< |
if (fread(zin, sizeof(float), xres, zfp) < xres) { |
| 236 |
< |
fprintf(stderr, "%s: read error\n", zfile); |
| 235 |
> |
if (zfp != NULL |
| 236 |
> |
&& fread(zin,sizeof(float),theirview.hresolu,zfp) |
| 237 |
> |
< theirview.hresolu) { |
| 238 |
> |
fprintf(stderr, "%s: read error\n", zspec); |
| 239 |
|
exit(1); |
| 240 |
|
} |
| 241 |
< |
addscanline(y, scanin, zin, pout, zout); |
| 241 |
> |
addscanline(y, scanin, zin, plast, zlast); |
| 242 |
|
} |
| 243 |
|
/* clean up */ |
| 244 |
|
free((char *)scanin); |
| 245 |
|
free((char *)zin); |
| 246 |
< |
free((char *)pout); |
| 247 |
< |
free((char *)zout); |
| 246 |
> |
free((char *)plast); |
| 247 |
> |
free((char *)zlast); |
| 248 |
|
fclose(pfp); |
| 249 |
< |
fclose(zfp); |
| 249 |
> |
if (zfp != NULL) |
| 250 |
> |
fclose(zfp); |
| 251 |
|
} |
| 252 |
|
|
| 253 |
|
|
| 291 |
|
int y; |
| 292 |
|
COLR *pline; |
| 293 |
|
float *zline; |
| 294 |
< |
int *lasty; |
| 295 |
< |
float *lastyz; |
| 294 |
> |
int *lasty; /* input/output */ |
| 295 |
> |
float *lastyz; /* input/output */ |
| 296 |
|
{ |
| 297 |
|
extern double sqrt(), fabs(); |
| 298 |
|
double pos[3]; |
| 307 |
|
pos[1] = y - .5*(theirview.vresolu-1); |
| 308 |
|
pos[2] = zline[x]; |
| 309 |
|
if (theirview.type == VT_PER) { |
| 310 |
< |
/* |
| 311 |
< |
* The following (single) statement can go |
| 296 |
< |
* if z is along the view direction rather |
| 297 |
< |
* than an eye ray. |
| 298 |
< |
*/ |
| 299 |
< |
pos[2] /= sqrt( 1. |
| 310 |
> |
if (!regdist) /* adjust for eye-ray distance */ |
| 311 |
> |
pos[2] /= sqrt( 1. |
| 312 |
|
+ pos[0]*pos[0]*theirview.vhn2 |
| 313 |
|
+ pos[1]*pos[1]*theirview.vvn2 ); |
| 314 |
|
pos[0] *= pos[2]; |
| 451 |
|
perror(progname); |
| 452 |
|
exit(1); |
| 453 |
|
} |
| 454 |
+ |
} |
| 455 |
+ |
|
| 456 |
+ |
|
| 457 |
+ |
isfloat(s) /* see if string is floating number */ |
| 458 |
+ |
register char *s; |
| 459 |
+ |
{ |
| 460 |
+ |
for ( ; *s; s++) |
| 461 |
+ |
if ((*s < '0' || *s > '9') && *s != '.' && *s != '-' |
| 462 |
+ |
&& *s != 'e' && *s != 'E' && *s != '+') |
| 463 |
+ |
return(0); |
| 464 |
+ |
return(1); |
| 465 |
|
} |