1 |
+ |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
+ |
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
5 |
|
#endif |
18 |
|
|
19 |
|
#include "color.h" |
20 |
|
|
21 |
+ |
#include "resolu.h" |
22 |
+ |
|
23 |
|
#ifndef BSD |
24 |
|
#define vfork fork |
25 |
|
#endif |
61 |
|
|
62 |
|
VIEW theirview = STDVIEW; /* input view */ |
63 |
|
int gotview; /* got input view? */ |
64 |
< |
int thresolu, tvresolu; /* input resolution */ |
64 |
> |
int wrongformat = 0; /* input in another format? */ |
65 |
> |
RESOLU tresolu; /* input resolution */ |
66 |
|
double theirexp; /* input picture exposure */ |
67 |
|
double theirs2ours[4][4]; /* transformation matrix */ |
68 |
|
int hasmatrix = 0; /* has transformation matrix */ |
216 |
|
fputaspect(pixaspect, stdout); |
217 |
|
if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) |
218 |
|
fputexpos(ourexp, stdout); |
219 |
+ |
fputformat(COLRFMT, stdout); |
220 |
|
putc('\n', stdout); |
221 |
|
/* write picture */ |
222 |
|
writepicture(); |
239 |
|
{ |
240 |
|
static char *altname[] = {VIEWSTR,"rpict","rview","pinterp",NULL}; |
241 |
|
register char **an; |
242 |
+ |
char fmt[32]; |
243 |
|
|
244 |
+ |
if (isformat(s)) { |
245 |
+ |
formatval(fmt, s); |
246 |
+ |
wrongformat = strcmp(fmt, COLRFMT); |
247 |
+ |
return; |
248 |
+ |
} |
249 |
|
putc('\t', stdout); |
250 |
|
fputs(s, stdout); |
251 |
|
|
282 |
|
theirexp = 1.0; |
283 |
|
gotview = 0; |
284 |
|
printf("%s:\n", pfile); |
285 |
< |
getheader(pfp, headline); |
286 |
< |
if (!gotview || fgetresolu(&thresolu, &tvresolu, pfp) |
287 |
< |
!= (YMAJOR|YDECR)) { |
276 |
< |
fprintf(stderr, "%s: picture view error\n", pfile); |
285 |
> |
getheader(pfp, headline, NULL); |
286 |
> |
if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) { |
287 |
> |
fprintf(stderr, "%s: picture format error\n", pfile); |
288 |
|
exit(1); |
289 |
|
} |
290 |
|
if (ourexp <= 0) |
298 |
|
/* compute transformation */ |
299 |
|
hasmatrix = pixform(theirs2ours, &theirview, &ourview); |
300 |
|
/* allocate scanlines */ |
301 |
< |
scanin = (COLR *)malloc(thresolu*sizeof(COLR)); |
302 |
< |
zin = (float *)malloc(thresolu*sizeof(float)); |
303 |
< |
plast = (struct position *)calloc(thresolu, sizeof(struct position)); |
301 |
> |
scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); |
302 |
> |
zin = (float *)malloc(scanlen(&tresolu)*sizeof(float)); |
303 |
> |
plast = (struct position *)calloc(scanlen(&tresolu), |
304 |
> |
sizeof(struct position)); |
305 |
|
if (scanin == NULL || zin == NULL || plast == NULL) |
306 |
|
syserror(); |
307 |
|
/* get z specification or file */ |
312 |
|
perror(zspec); |
313 |
|
exit(1); |
314 |
|
} |
315 |
< |
for (x = 0; x < thresolu; x++) |
315 |
> |
for (x = scanlen(&tresolu); x-- > 0; ) |
316 |
|
zin[x] = zvalue; |
317 |
|
} |
318 |
|
/* load image */ |
319 |
< |
for (y = tvresolu-1; y >= 0; y--) { |
320 |
< |
if (freadcolrs(scanin, thresolu, pfp) < 0) { |
319 |
> |
for (y = 0; y < numscans(&tresolu); y++) { |
320 |
> |
if (freadcolrs(scanin, scanlen(&tresolu), pfp) < 0) { |
321 |
|
fprintf(stderr, "%s: read error\n", pfile); |
322 |
|
exit(1); |
323 |
|
} |
324 |
< |
if (zfd != -1 && read(zfd,(char *)zin,thresolu*sizeof(float)) |
325 |
< |
< thresolu*sizeof(float)) { |
324 |
> |
if (zfd != -1 && read(zfd,(char *)zin, |
325 |
> |
scanlen(&tresolu)*sizeof(float)) |
326 |
> |
< scanlen(&tresolu)*sizeof(float)) { |
327 |
|
fprintf(stderr, "%s: read error\n", zspec); |
328 |
|
exit(1); |
329 |
|
} |
392 |
|
register int x; |
393 |
|
|
394 |
|
lastx.z = 0; |
395 |
< |
for (x = thresolu-1; x >= 0; x--) { |
396 |
< |
pos[0] = (x+.5)/thresolu; |
384 |
< |
pos[1] = (y+.5)/tvresolu; |
395 |
> |
for (x = scanlen(&tresolu); x-- > 0; ) { |
396 |
> |
pix2loc(pos, &tresolu, x, y); |
397 |
|
pos[2] = zline[x]; |
398 |
|
if (movepixel(pos) < 0) { |
399 |
|
lasty[x].z = lastx.z = 0; /* mark invalid */ |
477 |
|
{ |
478 |
|
FVECT pt, direc; |
479 |
|
|
480 |
+ |
if (pos[2] <= 0) /* empty pixel */ |
481 |
+ |
return(-1); |
482 |
|
if (hasmatrix) { |
483 |
|
pos[0] += theirview.hoff - .5; |
484 |
|
pos[1] += theirview.voff - .5; |
506 |
|
pt[0] += direc[0]*pos[2]; |
507 |
|
pt[1] += direc[1]*pos[2]; |
508 |
|
pt[2] += direc[2]*pos[2]; |
509 |
< |
viewpixel(&pos[0], &pos[1], &pos[2], &ourview, pt); |
509 |
> |
viewloc(pos, &ourview, pt); |
510 |
|
if (pos[2] <= 0) |
511 |
|
return(-1); |
512 |
|
return(0); |
624 |
|
{ |
625 |
|
int y; |
626 |
|
|
627 |
< |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout); |
627 |
> |
fprtresolu(hresolu, vresolu, stdout); |
628 |
|
for (y = vresolu-1; y >= 0; y--) |
629 |
|
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
630 |
|
syserror(); |