ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/image.c
(Generate patch)

Comparing ray/src/common/image.c (file contents):
Revision 2.7 by greg, Tue Dec 20 20:15:04 1994 UTC vs.
Revision 2.52 by greg, Fri Feb 12 00:47:08 2021 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1994 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  image.c - routines for image generation.
6   *
7 < *     10/17/85
7 > *  External symbols declared in view.h
8   */
9  
10 < #include  "standard.h"
10 > #include "copyright.h"
11  
12 + #include  <ctype.h>
13 + #include  "rtio.h"
14 + #include  "rtmath.h"
15 + #include  "paths.h"
16   #include  "view.h"
17  
17 #include  "resolu.h"
18
19 #include  "paths.h"
20
18   VIEW  stdview = STDVIEW;                /* default view parameters */
19  
20 + static gethfunc gethview;
21  
22 +
23   char *
24 < setview(v)              /* set hvec and vvec, return message on error */
25 < register VIEW  *v;
24 > setview(                /* set hvec and vvec, return message on error */
25 > VIEW  *v
26 > )
27   {
28          static char  ill_horiz[] = "illegal horizontal view size";
29          static char  ill_vert[] = "illegal vertical view size";
30          
31 <        if (v->vfore < -FTINY || v->vaft < -FTINY ||
32 <                        (v->vaft > FTINY && v->vaft <= v->vfore))
31 >        if ((v->vfore < -FTINY) | (v->vaft < -FTINY) ||
32 >                        (v->vaft > FTINY) & (v->vaft <= v->vfore))
33                  return("illegal fore/aft clipping plane");
34  
35 <        if (normalize(v->vdir) == 0.0)          /* normalize direction */
35 >        if (v->vdist <= FTINY)
36 >                return("illegal view distance");
37 >        v->vdist *= normalize(v->vdir);         /* normalize direction */
38 >        if (v->vdist == 0.0)
39                  return("zero view direction");
40  
41          if (normalize(v->vup) == 0.0)           /* normalize view up */
# Line 63 | Line 66 | register VIEW  *v;
66                  v->hn2 = 2.0 * tan(v->horiz*(PI/180.0/2.0));
67                  v->vn2 = 2.0 * tan(v->vert*(PI/180.0/2.0));
68                  break;
69 +        case VT_CYL:                            /* cylindrical panorama */
70 +                if (v->horiz > 360.0+FTINY)
71 +                        return(ill_horiz);
72 +                if (v->vert >= 180.0-FTINY)
73 +                        return(ill_vert);
74 +                v->hn2 = v->horiz * (PI/180.0);
75 +                v->vn2 = 2.0 * tan(v->vert*(PI/180.0/2.0));
76 +                break;
77          case VT_ANG:                            /* angular fisheye */
78                  if (v->horiz > 360.0+FTINY)
79                          return(ill_horiz);
80                  if (v->vert > 360.0+FTINY)
81                          return(ill_vert);
82 <                v->hn2 = v->horiz / 90.0;
83 <                v->vn2 = v->vert / 90.0;
82 >                v->hn2 = v->horiz * (PI/180.0);
83 >                v->vn2 = v->vert * (PI/180.0);
84                  break;
85          case VT_HEM:                            /* hemispherical fisheye */
86                  if (v->horiz > 180.0+FTINY)
# Line 79 | Line 90 | register VIEW  *v;
90                  v->hn2 = 2.0 * sin(v->horiz*(PI/180.0/2.0));
91                  v->vn2 = 2.0 * sin(v->vert*(PI/180.0/2.0));
92                  break;
93 +        case VT_PLS:                            /* planispheric fisheye */
94 +                if (v->horiz >= 360.0-FTINY)
95 +                        return(ill_horiz);
96 +                if (v->vert >= 360.0-FTINY)
97 +                        return(ill_vert);
98 +                v->hn2 = 2.*sin(v->horiz*(PI/180.0/2.0)) /
99 +                                (1.0 + cos(v->horiz*(PI/180.0/2.0)));
100 +                v->vn2 = 2.*sin(v->vert*(PI/180.0/2.0)) /
101 +                                (1.0 + cos(v->vert*(PI/180.0/2.0)));
102 +                break;
103          default:
104                  return("unknown view type");
105          }
106 <        if (v->type != VT_ANG) {
107 <                v->hvec[0] *= v->hn2;
108 <                v->hvec[1] *= v->hn2;
109 <                v->hvec[2] *= v->hn2;
106 >        if (v->type != VT_ANG && v->type != VT_PLS) {
107 >                if (v->type != VT_CYL) {
108 >                        v->hvec[0] *= v->hn2;
109 >                        v->hvec[1] *= v->hn2;
110 >                        v->hvec[2] *= v->hn2;
111 >                }
112                  v->vvec[0] *= v->vn2;
113                  v->vvec[1] *= v->vn2;
114                  v->vvec[2] *= v->vn2;
# Line 97 | Line 120 | register VIEW  *v;
120   }
121  
122  
123 < normaspect(va, ap, xp, yp)              /* fix pixel aspect or resolution */
124 < double  va;                     /* view aspect ratio */
125 < double  *ap;                    /* pixel aspect in (or out if 0) */
126 < int  *xp, *yp;                  /* x and y resolution in (or out if *ap!=0) */
123 > void
124 > normaspect(                             /* fix pixel aspect or resolution */
125 > double  va,                     /* view aspect ratio */
126 > double  *ap,                    /* pixel aspect in (or out if 0) */
127 > int  *xp,
128 > int  *yp                        /* x and y resolution in (or out if *ap!=0) */
129 > )
130   {
131          if (*ap <= FTINY)
132                  *ap = va * *xp / *yp;           /* compute pixel aspect */
# Line 112 | Line 138 | int  *xp, *yp;                 /* x and y resolution in (or out if *
138  
139  
140   double
141 < viewray(orig, direc, v, x, y)           /* compute ray origin and direction */
142 < FVECT  orig, direc;
143 < register VIEW  *v;
144 < double  x, y;
141 > viewray(                                /* compute ray origin and direction */
142 > FVECT  orig,
143 > FVECT  direc,
144 > VIEW  *v,
145 > double  x,
146 > double  y
147 > )
148   {
149          double  d, z;
150          
# Line 131 | Line 160 | double  x, y;
160                  orig[2] = v->vp[2] + v->vfore*v->vdir[2]
161                                  + x*v->hvec[2] + y*v->vvec[2];
162                  VCOPY(direc, v->vdir);
163 <                return(v->vaft - v->vfore);
163 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
164          case VT_PER:                    /* perspective view */
165                  direc[0] = v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
166                  direc[1] = v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
167                  direc[2] = v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
168 <                orig[0] = v->vp[0] + v->vfore*direc[0];
140 <                orig[1] = v->vp[1] + v->vfore*direc[1];
141 <                orig[2] = v->vp[2] + v->vfore*direc[2];
168 >                VSUM(orig, v->vp, direc, v->vfore);
169                  d = normalize(direc);
170 <                return((v->vaft - v->vfore)*d);
170 >                return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0);
171          case VT_HEM:                    /* hemispherical fisheye */
172                  z = 1.0 - x*x*v->hn2 - y*y*v->vn2;
173                  if (z < 0.0)
# Line 149 | Line 176 | double  x, y;
176                  direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
177                  direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
178                  direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
179 <                orig[0] = v->vp[0] + v->vfore*direc[0];
180 <                orig[1] = v->vp[1] + v->vfore*direc[1];
181 <                orig[2] = v->vp[2] + v->vfore*direc[2];
182 <                return(v->vaft - v->vfore);
179 >                VSUM(orig, v->vp, direc, v->vfore);
180 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
181 >        case VT_CYL:                    /* cylindrical panorama */
182 >                d = x * v->horiz * (PI/180.0);
183 >                z = cos(d);
184 >                x = sin(d);
185 >                direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
186 >                direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
187 >                direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
188 >                VSUM(orig, v->vp, direc, v->vfore);
189 >                d = normalize(direc);
190 >                return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0);
191          case VT_ANG:                    /* angular fisheye */
192 <                x *= v->horiz/180.0;
193 <                y *= v->vert/180.0;
192 >                x *= (1.0/180.0)*v->horiz;
193 >                y *= (1.0/180.0)*v->vert;
194                  d = x*x + y*y;
195                  if (d > 1.0)
196                          return(-1.0);
197                  d = sqrt(d);
198                  z = cos(PI*d);
199 <                d = d <= FTINY ? PI : sqrt(1 - z*z)/d;
199 >                d = d <= FTINY ? PI : sqrt(1.0 - z*z)/d;
200                  x *= d;
201                  y *= d;
202                  direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
203                  direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
204                  direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
205 <                orig[0] = v->vp[0] + v->vfore*direc[0];
206 <                orig[1] = v->vp[1] + v->vfore*direc[1];
207 <                orig[2] = v->vp[2] + v->vfore*direc[2];
208 <                return(v->vaft - v->vfore);
205 >                VSUM(orig, v->vp, direc, v->vfore);
206 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
207 >        case VT_PLS:                    /* planispheric fisheye */
208 >                x *= sqrt(v->hn2);
209 >                y *= sqrt(v->vn2);
210 >                d = x*x + y*y;
211 >                z = (1. - d)/(1. + d);
212 >                x *= (1. + z);
213 >                y *= (1. + z);
214 >                direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
215 >                direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
216 >                direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
217 >                VSUM(orig, v->vp, direc, v->vfore);
218 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
219          }
220          return(-1.0);
221   }
222  
223  
224 < viewloc(ip, v, p)               /* find image location for point */
225 < FVECT  ip;
226 < register VIEW  *v;
227 < FVECT  p;
224 > int
225 > viewloc(                        /* find image location for point */
226 > FVECT  ip,
227 > VIEW  *v,
228 > FVECT  p
229 > )       /* Use VL_* flags to interpret return value */
230   {
231 <        double  d;
231 >        int     rflags = VL_GOOD;
232 >        double  d, d2;
233          FVECT  disp;
234  
235 <        disp[0] = p[0] - v->vp[0];
188 <        disp[1] = p[1] - v->vp[1];
189 <        disp[2] = p[2] - v->vp[2];
235 >        VSUB(disp, p, v->vp);
236  
237          switch (v->type) {
238          case VT_PAR:                    /* parallel view */
# Line 194 | Line 240 | FVECT  p;
240                  break;
241          case VT_PER:                    /* perspective view */
242                  d = DOT(disp,v->vdir);
243 <                ip[2] = sqrt(DOT(disp,disp));
244 <                if (d < 0.0) {          /* fold pyramid */
243 >                if ((v->vaft > FTINY) & (d >= v->vaft))
244 >                        rflags |= VL_BEYOND;
245 >                ip[2] = VLEN(disp);
246 >                if (d < -FTINY) {       /* fold pyramid */
247                          ip[2] = -ip[2];
248                          d = -d;
249 <                }
250 <                if (d > FTINY) {
251 <                        d = 1.0/d;
252 <                        disp[0] *= d;
253 <                        disp[1] *= d;
254 <                        disp[2] *= d;
255 <                }
249 >                } else if (d <= FTINY)
250 >                        return(VL_BAD); /* at infinite edge */
251 >                d = 1.0/d;
252 >                disp[0] *= d;
253 >                disp[1] *= d;
254 >                disp[2] *= d;
255 >                if (ip[2] < 0.0) d = -d;
256                  ip[2] *= (1.0 - v->vfore*d);
257                  break;
258          case VT_HEM:                    /* hemispherical fisheye */
# Line 215 | Line 263 | FVECT  p;
263                          ip[2] = d;
264                  ip[2] -= v->vfore;
265                  break;
266 +        case VT_CYL:                    /* cylindrical panorama */
267 +                d = DOT(disp,v->hvec);
268 +                d2 = DOT(disp,v->vdir);
269 +                ip[0] = 180.0/PI * atan2(d,d2) / v->horiz + 0.5 - v->hoff;
270 +                d2 = d*d + d2*d2;
271 +                if (d2 <= FTINY*FTINY)
272 +                        return(VL_BAD); /* at pole */
273 +                if ((v->vaft > FTINY) & (d2 >= v->vaft*v->vaft))
274 +                        rflags |= VL_BEYOND;
275 +                d = 1.0/sqrt(d2);
276 +                ip[1] = DOT(disp,v->vvec)*d/v->vn2 + 0.5 - v->voff;
277 +                ip[2] = VLEN(disp);
278 +                ip[2] *= (1.0 - v->vfore*d);
279 +                goto gotall;
280          case VT_ANG:                    /* angular fisheye */
281                  ip[0] = 0.5 - v->hoff;
282                  ip[1] = 0.5 - v->voff;
283                  ip[2] = normalize(disp) - v->vfore;
284                  d = DOT(disp,v->vdir);
285                  if (d >= 1.0-FTINY)
286 <                        return;
286 >                        goto gotall;
287                  if (d <= -(1.0-FTINY)) {
288                          ip[0] += 180.0/v->horiz;
289 <                        ip[1] += 180.0/v->vert;
228 <                        return;
289 >                        goto gotall;
290                  }
291 <                d = acos(d)/PI / sqrt(1.0 - d*d);
292 <                ip[0] += DOT(disp,v->hvec)*d*180.0/v->horiz;
293 <                ip[1] += DOT(disp,v->vvec)*d*180.0/v->vert;
294 <                return;
291 >                d = (180.0/PI)*acos(d) / sqrt(1.0 - d*d);
292 >                ip[0] += DOT(disp,v->hvec)*d/v->horiz;
293 >                ip[1] += DOT(disp,v->vvec)*d/v->vert;
294 >                goto gotall;
295 >        case VT_PLS:                    /* planispheric fisheye */
296 >                ip[0] = 0.5 - v->hoff;
297 >                ip[1] = 0.5 - v->voff;
298 >                ip[2] = normalize(disp) - v->vfore;
299 >                d = DOT(disp,v->vdir);
300 >                if (d >= 1.0-FTINY)
301 >                        goto gotall;
302 >                if (d <= -(1.0-FTINY))
303 >                        return(VL_BAD);
304 >                ip[0] += DOT(disp,v->hvec)/((1. + d)*sqrt(v->hn2));
305 >                ip[1] += DOT(disp,v->vvec)/((1. + d)*sqrt(v->vn2));
306 >                goto gotall;
307 >        default:
308 >                return(VL_BAD);
309          }
310          ip[0] = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff;
311          ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
312 + gotall:                                 /* add appropriate return flags */
313 +        if (ip[2] <= 0.0)
314 +                rflags |= VL_BEHIND;
315 +        else if ((v->type != VT_PER) & (v->type != VT_CYL))
316 +                rflags |= VL_BEYOND*((v->vaft > FTINY) &
317 +                                        (ip[2] >= v->vaft - v->vfore));
318 +        rflags |= VL_OUTSIDE*((0.0 >= ip[0]) | (ip[0] >= 1.0) |
319 +                                (0.0 >= ip[1]) | (ip[1] >= 1.0));
320 +        return(rflags);
321   }
322  
323  
324 < pix2loc(loc, rp, px, py)        /* compute image location from pixel pos. */
325 < FLOAT  loc[2];
326 < register RESOLU  *rp;
327 < int  px, py;
324 > void
325 > pix2loc(                /* compute image location from pixel pos. */
326 > RREAL  loc[2],
327 > RESOLU  *rp,
328 > int  px,
329 > int  py
330 > )
331   {
332 <        register int  x, y;
332 >        int  x, y;
333  
334 <        if (rp->or & YMAJOR) {
334 >        if (rp->rt & YMAJOR) {
335                  x = px;
336                  y = py;
337          } else {
338                  x = py;
339                  y = px;
340          }
341 <        if (rp->or & XDECR)
341 >        if (rp->rt & XDECR)
342                  x = rp->xr-1 - x;
343 <        if (rp->or & YDECR)
343 >        if (rp->rt & YDECR)
344                  y = rp->yr-1 - y;
345          loc[0] = (x+.5)/rp->xr;
346          loc[1] = (y+.5)/rp->yr;
347   }
348  
349  
350 < loc2pix(pp, rp, lx, ly)         /* compute pixel pos. from image location */
351 < int  pp[2];
352 < register RESOLU  *rp;
353 < double  lx, ly;
350 > void
351 > loc2pix(                        /* compute pixel pos. from image location */
352 > int  pp[2],
353 > RESOLU  *rp,
354 > double  lx,
355 > double  ly
356 > )
357   {
358 <        register int  x, y;
358 >        int  x, y;
359  
360 <        x = lx * rp->xr;
361 <        y = ly * rp->yr;
362 <        if (rp->or & XDECR)
360 >        x = (int)(lx*rp->xr + .5 - (lx < 0.0));
361 >        y = (int)(ly*rp->yr + .5 - (ly < 0.0));
362 >
363 >        if (rp->rt & XDECR)
364                  x = rp->xr-1 - x;
365 <        if (rp->or & YDECR)
365 >        if (rp->rt & YDECR)
366                  y = rp->yr-1 - y;
367 <        if (rp->or & YMAJOR) {
367 >        if (rp->rt & YMAJOR) {
368                  pp[0] = x;
369                  pp[1] = y;
370          } else {
# Line 284 | Line 375 | double  lx, ly;
375  
376  
377   int
378 < getviewopt(v, ac, av)                   /* process view argument */
379 < register VIEW  *v;
380 < int  ac;
381 < register char  *av[];
378 > getviewopt(                             /* process view argument */
379 > VIEW  *v,
380 > int  ac,
381 > char  *av[]
382 > )
383   {
384 < #define check(c,l)      if ((av[0][c]&&av[0][c]!=' ') || \
384 > #define check(c,l)      if ((av[0][c]&&!isspace(av[0][c])) || \
385                          badarg(ac-1,av+1,l)) return(-1)
386  
387          if (ac <= 0 || av[0][0] != '-' || av[0][1] != 'v')
388                  return(-1);
389          switch (av[0][2]) {
390          case 't':                       /* type */
391 <                if (!av[0][3] || av[0][3]==' ')
391 >                if (!av[0][3] || isspace(av[0][3]))
392                          return(-1);
393                  check(4,"");
394                  v->type = av[0][3];
# Line 312 | Line 404 | register char  *av[];
404                  v->vdir[0] = atof(av[1]);
405                  v->vdir[1] = atof(av[2]);
406                  v->vdir[2] = atof(av[3]);
407 +                v->vdist = 1.;
408                  return(3);
409          case 'u':                       /* up */
410                  check(3,"fff");
# Line 351 | Line 444 | register char  *av[];
444  
445  
446   int
447 < sscanview(vp, s)                        /* get view parameters from string */
448 < VIEW  *vp;
449 < register char  *s;
447 > sscanview(                              /* get view parameters from string */
448 > VIEW  *vp,
449 > char  *s
450 > )
451   {
452          int  ac;
453          char  *av[4];
454          int  na;
455          int  nvopts = 0;
456  
457 <        if (*s != '-')
458 <                s = sskip(s);
457 >        while (isspace(*s))
458 >                if (!*s++)
459 >                        return(0);
460          while (*s) {
461                  ac = 0;
462                  do {
463 <                        av[ac++] = s;
464 <                        while (*s && *s != ' ')
463 >                        if (ac || *s == '-')
464 >                                av[ac++] = s;
465 >                        while (*s && !isspace(*s))
466                                  s++;
467 <                        while (*s == ' ')
467 >                        while (isspace(*s))
468                                  s++;
469                  } while (*s && ac < 4);
470                  if ((na = getviewopt(vp, ac, av)) >= 0) {
# Line 382 | Line 478 | register char  *s;
478   }
479  
480  
481 < fprintview(vp, fp)                      /* write out view parameters */
482 < register VIEW  *vp;
483 < FILE  *fp;
481 > void
482 > fprintview(                             /* write out view parameters */
483 > VIEW  *vp,
484 > FILE  *fp
485 > )
486   {
487          fprintf(fp, " -vt%c", vp->type);
488          fprintf(fp, " -vp %.6g %.6g %.6g", vp->vp[0], vp->vp[1], vp->vp[2]);
489 <        fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0], vp->vdir[1], vp->vdir[2]);
489 >        fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0]*vp->vdist,
490 >                                                vp->vdir[1]*vp->vdist,
491 >                                                vp->vdir[2]*vp->vdist);
492          fprintf(fp, " -vu %.6g %.6g %.6g", vp->vup[0], vp->vup[1], vp->vup[2]);
493          fprintf(fp, " -vh %.6g -vv %.6g", vp->horiz, vp->vert);
494          fprintf(fp, " -vo %.6g -va %.6g", vp->vfore, vp->vaft);
# Line 396 | Line 496 | FILE  *fp;
496   }
497  
498  
499 + char *
500 + viewopt(                                /* translate to minimal view string */
501 + VIEW  *vp
502 + )
503 + {
504 +        static char  vwstr[128];
505 +        char  *cp = vwstr;
506 +
507 +        *cp = '\0';
508 +        if (vp->type != stdview.type) {
509 +                sprintf(cp, " -vt%c", vp->type);
510 +                cp += strlen(cp);
511 +        }
512 +        if (!VABSEQ(vp->vp,stdview.vp)) {
513 +                sprintf(cp, " -vp %.6g %.6g %.6g",
514 +                                vp->vp[0], vp->vp[1], vp->vp[2]);
515 +                cp += strlen(cp);
516 +        }
517 +        if (!FABSEQ(vp->vdist,stdview.vdist) || !VABSEQ(vp->vdir,stdview.vdir)) {
518 +                sprintf(cp, " -vd %.6g %.6g %.6g",
519 +                                vp->vdir[0]*vp->vdist,
520 +                                vp->vdir[1]*vp->vdist,
521 +                                vp->vdir[2]*vp->vdist);
522 +                cp += strlen(cp);
523 +        }
524 +        if (!VABSEQ(vp->vup,stdview.vup)) {
525 +                sprintf(cp, " -vu %.6g %.6g %.6g",
526 +                                vp->vup[0], vp->vup[1], vp->vup[2]);
527 +                cp += strlen(cp);
528 +        }
529 +        if (!FABSEQ(vp->horiz,stdview.horiz)) {
530 +                sprintf(cp, " -vh %.6g", vp->horiz);
531 +                cp += strlen(cp);
532 +        }
533 +        if (!FABSEQ(vp->vert,stdview.vert)) {
534 +                sprintf(cp, " -vv %.6g", vp->vert);
535 +                cp += strlen(cp);
536 +        }
537 +        if (!FABSEQ(vp->vfore,stdview.vfore)) {
538 +                sprintf(cp, " -vo %.6g", vp->vfore);
539 +                cp += strlen(cp);
540 +        }
541 +        if (!FABSEQ(vp->vaft,stdview.vaft)) {
542 +                sprintf(cp, " -va %.6g", vp->vaft);
543 +                cp += strlen(cp);
544 +        }
545 +        if (!FABSEQ(vp->hoff,stdview.hoff)) {
546 +                sprintf(cp, " -vs %.6g", vp->hoff);
547 +                cp += strlen(cp);
548 +        }
549 +        if (!FABSEQ(vp->voff,stdview.voff)) {
550 +                sprintf(cp, " -vl %.6g", vp->voff);
551 +                cp += strlen(cp);
552 +        }
553 +        return(vwstr);
554 + }
555 +
556 +
557   int
558 < isview(s)                               /* is this a view string? */
559 < char  *s;
558 > isview(                                 /* is this a view string? */
559 > char  *s
560 > )
561   {
562 <        static char  *altname[]={NULL,VIEWSTR,"rpict","rview","pinterp",NULL};
562 >        static char  *altname[]={NULL,VIEWSTR,"rpict","rview","rvu","rpiece","pinterp",NULL};
563          extern char  *progname;
564 <        register char  *cp;
565 <        register char  **an;
564 >        char  *cp;
565 >        char  **an;
566                                          /* add program name to list */
567          if (altname[0] == NULL) {
568                  for (cp = progname; *cp; cp++)
# Line 414 | Line 573 | char  *s;
573          }
574                                          /* skip leading path */
575          cp = s;
576 <        while (*cp && *cp != ' ')
576 >        while (*cp && !isspace(*cp))
577                  cp++;
578          while (cp > s && !ISDIRSEP(cp[-1]))
579                  cp--;
# Line 431 | Line 590 | struct myview {
590   };
591  
592  
593 < static
594 < gethview(s, v)                          /* get view from header */
595 < char  *s;
596 < register struct myview  *v;
593 > static int
594 > gethview(                               /* get view from header */
595 >        char  *s,
596 >        void  *v
597 > )
598   {
599 <        if (isview(s) && sscanview(v->hv, s) > 0)
600 <                v->ok++;
599 >        if (isview(s) && sscanview(((struct myview*)v)->hv, s) > 0)
600 >                ((struct myview*)v)->ok++;
601 >        return(0);
602   }
603  
604  
605   int
606 < viewfile(fname, vp, rp)                 /* get view from file */
607 < char  *fname;
608 < VIEW  *vp;
609 < RESOLU  *rp;
606 > viewfile(                               /* get view from file */
607 > char  *fname,
608 > VIEW  *vp,
609 > RESOLU  *rp
610 > )
611   {
612          struct myview   mvs;
613          FILE  *fp;
614  
615 <        if ((fp = fopen(fname, "r")) == NULL)
615 >        if (fname == NULL || !strcmp(fname, "-"))
616 >                fp = stdin;
617 >        else if ((fp = fopen(fname, "r")) == NULL)
618                  return(-1);
619  
620          mvs.hv = vp;
# Line 461 | Line 625 | RESOLU  *rp;
625          if (rp != NULL && !fgetsresolu(rp, fp))
626                  mvs.ok = 0;
627  
628 <        fclose(fp);
628 >        if (fp != stdin)
629 >                fclose(fp);
630  
631          return(mvs.ok);
632   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines