175 |
|
FILE *pfp, *zfp; |
176 |
|
char *err; |
177 |
|
COLR *scanin; |
178 |
< |
float *zin, *zout; |
179 |
< |
int *pout; |
180 |
< |
int xres, yres; |
178 |
> |
float *zin, *zlast; |
179 |
> |
int *plast; |
180 |
|
int y; |
181 |
|
/* open input files */ |
182 |
|
if ((pfp = fopen(pfile, "r")) == NULL) { |
191 |
|
printf("%s:\n", pfile); |
192 |
|
gotview = 0; |
193 |
|
getheader(pfp, headline); |
194 |
< |
if (!gotview || fgetresolu(&xres, &yres, pfp) != (YMAJOR|YDECR)) { |
194 |
> |
if (!gotview || fgetresolu(&theirview.hresolu, &theirview.vresolu, pfp) |
195 |
> |
!= (YMAJOR|YDECR)) { |
196 |
|
fprintf(stderr, "%s: picture view error\n", pfile); |
197 |
|
exit(1); |
198 |
|
} |
199 |
– |
theirview.hresolu = xres; |
200 |
– |
theirview.vresolu = yres; |
199 |
|
if (err = setview(&theirview)) { |
200 |
|
fprintf(stderr, "%s: %s\n", pfile, err); |
201 |
|
exit(1); |
203 |
|
/* compute transformation */ |
204 |
|
pixform(theirs2ours, &theirview, &ourview); |
205 |
|
/* allocate scanlines */ |
206 |
< |
scanin = (COLR *)malloc(xres*sizeof(COLR)); |
207 |
< |
zin = (float *)malloc(xres*sizeof(float)); |
208 |
< |
zout = (float *)calloc(xres, sizeof(float)); |
209 |
< |
pout = (int *)calloc(xres, sizeof(int)); |
210 |
< |
if (scanin == NULL || zin == NULL || zout == NULL || pout == NULL) { |
206 |
> |
scanin = (COLR *)malloc(theirview.hresolu*sizeof(COLR)); |
207 |
> |
zin = (float *)malloc(theirview.hresolu*sizeof(float)); |
208 |
> |
zlast = (float *)calloc(theirview.hresolu, sizeof(float)); |
209 |
> |
plast = (int *)calloc(theirview.hresolu, sizeof(int)); |
210 |
> |
if (scanin == NULL || zin == NULL || zlast == NULL || plast == NULL) { |
211 |
|
perror(progname); |
212 |
|
exit(1); |
213 |
|
} |
214 |
|
/* load image */ |
215 |
< |
for (y = yres-1; y >= 0; y--) { |
216 |
< |
if (freadcolrs(scanin, xres, pfp) < 0) { |
215 |
> |
for (y = theirview.vresolu-1; y >= 0; y--) { |
216 |
> |
if (freadcolrs(scanin, theirview.hresolu, pfp) < 0) { |
217 |
|
fprintf(stderr, "%s: read error\n", pfile); |
218 |
|
exit(1); |
219 |
|
} |
220 |
< |
if (fread(zin, sizeof(float), xres, zfp) < xres) { |
220 |
> |
if (fread(zin, sizeof(float), theirview.hresolu, zfp) |
221 |
> |
< theirview.hresolu) { |
222 |
|
fprintf(stderr, "%s: read error\n", zfile); |
223 |
|
exit(1); |
224 |
|
} |
225 |
< |
addscanline(y, scanin, zin, pout, zout); |
225 |
> |
addscanline(y, scanin, zin, plast, zlast); |
226 |
|
} |
227 |
|
/* clean up */ |
228 |
|
free((char *)scanin); |
229 |
|
free((char *)zin); |
230 |
< |
free((char *)pout); |
231 |
< |
free((char *)zout); |
230 |
> |
free((char *)plast); |
231 |
> |
free((char *)zlast); |
232 |
|
fclose(pfp); |
233 |
|
fclose(zfp); |
234 |
|
} |
274 |
|
int y; |
275 |
|
COLR *pline; |
276 |
|
float *zline; |
277 |
< |
int *lasty; |
278 |
< |
float *lastyz; |
277 |
> |
int *lasty; /* input/output */ |
278 |
> |
float *lastyz; /* input/output */ |
279 |
|
{ |
280 |
|
extern double sqrt(), fabs(); |
281 |
|
double pos[3]; |