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.30 by greg, Mon Feb 7 20:13:55 2005 UTC vs.
Revision 2.53 by greg, Wed Jan 12 21:07:39 2022 UTC

# Line 9 | Line 9 | static const char      RCSid[] = "$Id$";
9  
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
18 #define  FEQ(x,y)       (fabs((x)-(y)) <= FTINY)
19 #define  VEQ(v,w)       (FEQ((v)[0],(w)[0]) && FEQ((v)[1],(w)[1]) \
20                                && FEQ((v)[2],(w)[2]))
21
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->vaft < -FTINY || (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 (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");
# Line 63 | Line 63 | register VIEW  *v;
63                          return(ill_horiz);
64                  if (v->vert >= 180.0-FTINY)
65                          return(ill_vert);
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));
66 >                v->hn2 = 2.0 * tan(v->horiz*(PI/360.));
67 >                v->vn2 = 2.0 * tan(v->vert*(PI/360.));
68                  break;
69          case VT_CYL:                            /* cylindrical panorama */
70                  if (v->horiz > 360.0+FTINY)
# Line 72 | Line 72 | register VIEW  *v;
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));
75 >                v->vn2 = 2.0 * tan(v->vert*(PI/360.));
76                  break;
77          case VT_ANG:                            /* angular fisheye */
78                  if (v->horiz > 360.0+FTINY)
# Line 87 | Line 87 | register VIEW  *v;
87                          return(ill_horiz);
88                  if (v->vert > 180.0+FTINY)
89                          return(ill_vert);
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));
90 >                v->hn2 = 2.0 * sin(v->horiz*(PI/360.));
91 >                v->vn2 = 2.0 * sin(v->vert*(PI/360.));
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/360.)) /
99 +                                (1.0 + cos(v->horiz*(PI/360.)));
100 +                v->vn2 = 2.*sin(v->vert*(PI/360.)) /
101 +                                (1.0 + cos(v->vert*(PI/360.)));
102 +                break;
103          default:
104                  return("unknown view type");
105          }
106 <        if (v->type != VT_ANG) {
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;
# Line 110 | Line 120 | register VIEW  *v;
120   }
121  
122  
123 + char *
124 + cropview(                       /* crop a view to the indicated bounds */
125 + VIEW *v,
126 + double x0,
127 + double y0,
128 + double x1,
129 + double y1
130 + )
131 + {
132 +        static char     ill_crop[] = "zero crop area";
133 +        static char     ill_hemi[] = "illegal crop for hemispherical view";
134 +        double  d;
135 +                                        /* order crop extrema */
136 +        if (x0 > x1) { d=x0; x0=x1; x1=d; }
137 +        if (y0 > y1) { d=y0; y0=y1; y1=d; }
138 +
139 +        d = x1 - x0;
140 +        if (d == .0)
141 +                return(ill_crop);
142 +        if (!FABSEQ(d, 1.))             /* adjust horizontal size? */
143 +                switch (v->type) {
144 +                case VT_PER:
145 +                        v->horiz = 360./PI*atan( d*tan(PI/360.*v->horiz) );
146 +                        break;
147 +                case VT_PAR:
148 +                case VT_ANG:
149 +                case VT_CYL:
150 +                        v->horiz *= d;
151 +                        break;
152 +                case VT_HEM:
153 +                        d *= sin(PI/360.*v->horiz);
154 +                        if (d > 1.)
155 +                                return(ill_hemi);
156 +                        v->horiz = 360./PI*asin( d );
157 +                        break;
158 +                case VT_PLS:
159 +                        d *= sin(PI/360.*v->horiz) /
160 +                                        (1. + cos(PI/360.*v->horiz));
161 +                        v->horiz = 360./PI*acos( (1. - d*d) / (1. + d*d) );
162 +                        break;
163 +                }
164 +        d = y1 - y0;
165 +        if (d == .0)
166 +                return(ill_crop);
167 +        if (!FABSEQ(d, 1.))             /* adjust vertical size? */
168 +                switch (v->type) {
169 +                case VT_PER:
170 +                case VT_CYL:
171 +                        v->vert = 360./PI*atan( d*tan(PI/360.*v->vert) );
172 +                        break;
173 +                case VT_PAR:
174 +                case VT_ANG:
175 +                        v->vert *= d;
176 +                        break;
177 +                case VT_HEM:
178 +                        d *= sin(PI/360.*v->vert);
179 +                        if (d > 1.)
180 +                                return(ill_hemi);
181 +                        v->vert = 360./PI*asin( d );
182 +                        break;
183 +                case VT_PLS:
184 +                        d *= sin(PI/360.*v->vert) /
185 +                                        (1. + cos(PI/360.*v->vert));
186 +                        v->vert = 360./PI*acos( (1. - d*d) / (1. + d*d) );
187 +                        break;
188 +                }
189 +                                        /* fix offsets */
190 +        v->hoff = ((x0 + x1)*.5 - .5 + v->hoff) / (x1 - x0);
191 +        v->voff = ((y0 + y1)*.5 - .5 + v->voff) / (y1 - y0);
192 +
193 +        return(setview(v));             /* final error checks & set-up */
194 + }
195 +
196 +
197   void
198 < normaspect(va, ap, xp, yp)              /* fix pixel aspect or resolution */
199 < double  va;                     /* view aspect ratio */
200 < double  *ap;                    /* pixel aspect in (or out if 0) */
201 < int  *xp, *yp;                  /* x and y resolution in (or out if *ap!=0) */
198 > normaspect(                             /* fix pixel aspect or resolution */
199 > double  va,                     /* view aspect ratio */
200 > double  *ap,                    /* pixel aspect in (or out if 0) */
201 > int  *xp,
202 > int  *yp                        /* x and y resolution in (or out if *ap!=0) */
203 > )
204   {
205          if (*ap <= FTINY)
206                  *ap = va * *xp / *yp;           /* compute pixel aspect */
# Line 126 | Line 212 | int  *xp, *yp;                 /* x and y resolution in (or out if *
212  
213  
214   double
215 < viewray(orig, direc, v, x, y)           /* compute ray origin and direction */
216 < FVECT  orig, direc;
217 < register VIEW  *v;
218 < double  x, y;
215 > viewray(                                /* compute ray origin and direction */
216 > FVECT  orig,
217 > FVECT  direc,
218 > VIEW  *v,
219 > double  x,
220 > double  y
221 > )
222   {
223          double  d, z;
224          
# Line 150 | Line 239 | double  x, y;
239                  direc[0] = v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
240                  direc[1] = v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
241                  direc[2] = v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
242 <                orig[0] = v->vp[0] + v->vfore*direc[0];
154 <                orig[1] = v->vp[1] + v->vfore*direc[1];
155 <                orig[2] = v->vp[2] + v->vfore*direc[2];
242 >                VSUM(orig, v->vp, direc, v->vfore);
243                  d = normalize(direc);
244                  return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0);
245          case VT_HEM:                    /* hemispherical fisheye */
# Line 163 | Line 250 | double  x, y;
250                  direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
251                  direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
252                  direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
253 <                orig[0] = v->vp[0] + v->vfore*direc[0];
167 <                orig[1] = v->vp[1] + v->vfore*direc[1];
168 <                orig[2] = v->vp[2] + v->vfore*direc[2];
253 >                VSUM(orig, v->vp, direc, v->vfore);
254                  return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
255          case VT_CYL:                    /* cylindrical panorama */
256                  d = x * v->horiz * (PI/180.0);
# Line 174 | Line 259 | double  x, y;
259                  direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
260                  direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
261                  direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
262 <                orig[0] = v->vp[0] + v->vfore*direc[0];
178 <                orig[1] = v->vp[1] + v->vfore*direc[1];
179 <                orig[2] = v->vp[2] + v->vfore*direc[2];
262 >                VSUM(orig, v->vp, direc, v->vfore);
263                  d = normalize(direc);
264                  return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0);
265          case VT_ANG:                    /* angular fisheye */
266 <                x *= v->horiz/180.0;
267 <                y *= v->vert/180.0;
266 >                x *= (1.0/180.0)*v->horiz;
267 >                y *= (1.0/180.0)*v->vert;
268                  d = x*x + y*y;
269                  if (d > 1.0)
270                          return(-1.0);
271                  d = sqrt(d);
272                  z = cos(PI*d);
273 <                d = d <= FTINY ? PI : sqrt(1 - z*z)/d;
273 >                d = d <= FTINY ? PI : sqrt(1.0 - z*z)/d;
274                  x *= d;
275                  y *= d;
276                  direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
277                  direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
278                  direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
279 <                orig[0] = v->vp[0] + v->vfore*direc[0];
197 <                orig[1] = v->vp[1] + v->vfore*direc[1];
198 <                orig[2] = v->vp[2] + v->vfore*direc[2];
279 >                VSUM(orig, v->vp, direc, v->vfore);
280                  return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
281 +        case VT_PLS:                    /* planispheric fisheye */
282 +                x *= sqrt(v->hn2);
283 +                y *= sqrt(v->vn2);
284 +                d = x*x + y*y;
285 +                z = (1. - d)/(1. + d);
286 +                x *= (1. + z);
287 +                y *= (1. + z);
288 +                direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
289 +                direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
290 +                direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
291 +                VSUM(orig, v->vp, direc, v->vfore);
292 +                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
293          }
294          return(-1.0);
295   }
296  
297  
298 < void
299 < viewloc(ip, v, p)               /* find image location for point */
300 < FVECT  ip;
301 < register VIEW  *v;
302 < FVECT  p;
298 > int
299 > viewloc(                        /* find image location for point */
300 > FVECT  ip,
301 > VIEW  *v,
302 > FVECT  p
303 > )       /* Use VL_* flags to interpret return value */
304   {
305 +        int     rflags = VL_GOOD;
306          double  d, d2;
307          FVECT  disp;
308  
309 <        disp[0] = p[0] - v->vp[0];
215 <        disp[1] = p[1] - v->vp[1];
216 <        disp[2] = p[2] - v->vp[2];
309 >        VSUB(disp, p, v->vp);
310  
311          switch (v->type) {
312          case VT_PAR:                    /* parallel view */
# Line 221 | Line 314 | FVECT  p;
314                  break;
315          case VT_PER:                    /* perspective view */
316                  d = DOT(disp,v->vdir);
317 +                if ((v->vaft > FTINY) & (d >= v->vaft))
318 +                        rflags |= VL_BEYOND;
319                  ip[2] = VLEN(disp);
320 <                if (d < 0.0) {          /* fold pyramid */
320 >                if (d < -FTINY) {       /* fold pyramid */
321                          ip[2] = -ip[2];
322                          d = -d;
323 <                }
324 <                if (d > FTINY) {
325 <                        d = 1.0/d;
326 <                        disp[0] *= d;
327 <                        disp[1] *= d;
328 <                        disp[2] *= d;
329 <                }
323 >                } else if (d <= FTINY)
324 >                        return(VL_BAD); /* at infinite edge */
325 >                d = 1.0/d;
326 >                disp[0] *= d;
327 >                disp[1] *= d;
328 >                disp[2] *= d;
329 >                if (ip[2] < 0.0) d = -d;
330                  ip[2] *= (1.0 - v->vfore*d);
331                  break;
332          case VT_HEM:                    /* hemispherical fisheye */
# Line 246 | Line 341 | FVECT  p;
341                  d = DOT(disp,v->hvec);
342                  d2 = DOT(disp,v->vdir);
343                  ip[0] = 180.0/PI * atan2(d,d2) / v->horiz + 0.5 - v->hoff;
344 <                d = 1.0/sqrt(d*d + d2*d2);
344 >                d2 = d*d + d2*d2;
345 >                if (d2 <= FTINY*FTINY)
346 >                        return(VL_BAD); /* at pole */
347 >                if ((v->vaft > FTINY) & (d2 >= v->vaft*v->vaft))
348 >                        rflags |= VL_BEYOND;
349 >                d = 1.0/sqrt(d2);
350                  ip[1] = DOT(disp,v->vvec)*d/v->vn2 + 0.5 - v->voff;
351                  ip[2] = VLEN(disp);
352                  ip[2] *= (1.0 - v->vfore*d);
353 <                return;
353 >                goto gotall;
354          case VT_ANG:                    /* angular fisheye */
355                  ip[0] = 0.5 - v->hoff;
356                  ip[1] = 0.5 - v->voff;
357                  ip[2] = normalize(disp) - v->vfore;
358                  d = DOT(disp,v->vdir);
359                  if (d >= 1.0-FTINY)
360 <                        return;
360 >                        goto gotall;
361                  if (d <= -(1.0-FTINY)) {
362                          ip[0] += 180.0/v->horiz;
363 <                        return;
363 >                        goto gotall;
364                  }
365 <                d = acos(d)/PI / sqrt(1.0 - d*d);
366 <                ip[0] += DOT(disp,v->hvec)*d*180.0/v->horiz;
367 <                ip[1] += DOT(disp,v->vvec)*d*180.0/v->vert;
368 <                return;
365 >                d = (180.0/PI)*acos(d) / sqrt(1.0 - d*d);
366 >                ip[0] += DOT(disp,v->hvec)*d/v->horiz;
367 >                ip[1] += DOT(disp,v->vvec)*d/v->vert;
368 >                goto gotall;
369 >        case VT_PLS:                    /* planispheric fisheye */
370 >                ip[0] = 0.5 - v->hoff;
371 >                ip[1] = 0.5 - v->voff;
372 >                ip[2] = normalize(disp) - v->vfore;
373 >                d = DOT(disp,v->vdir);
374 >                if (d >= 1.0-FTINY)
375 >                        goto gotall;
376 >                if (d <= -(1.0-FTINY))
377 >                        return(VL_BAD);
378 >                ip[0] += DOT(disp,v->hvec)/((1. + d)*sqrt(v->hn2));
379 >                ip[1] += DOT(disp,v->vvec)/((1. + d)*sqrt(v->vn2));
380 >                goto gotall;
381 >        default:
382 >                return(VL_BAD);
383          }
384          ip[0] = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff;
385          ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
386 + gotall:                                 /* add appropriate return flags */
387 +        if (ip[2] <= 0.0)
388 +                rflags |= VL_BEHIND;
389 +        else if ((v->type != VT_PER) & (v->type != VT_CYL))
390 +                rflags |= VL_BEYOND*((v->vaft > FTINY) &
391 +                                        (ip[2] >= v->vaft - v->vfore));
392 +        rflags |= VL_OUTSIDE*((0.0 >= ip[0]) | (ip[0] >= 1.0) |
393 +                                (0.0 >= ip[1]) | (ip[1] >= 1.0));
394 +        return(rflags);
395   }
396  
397  
398   void
399 < pix2loc(loc, rp, px, py)        /* compute image location from pixel pos. */
400 < RREAL  loc[2];
401 < register RESOLU  *rp;
402 < int  px, py;
399 > pix2loc(                /* compute image location from pixel pos. */
400 > RREAL  loc[2],
401 > RESOLU  *rp,
402 > int  px,
403 > int  py
404 > )
405   {
406 <        register int  x, y;
406 >        int  x, y;
407  
408          if (rp->rt & YMAJOR) {
409                  x = px;
# Line 297 | Line 422 | int  px, py;
422  
423  
424   void
425 < loc2pix(pp, rp, lx, ly)         /* compute pixel pos. from image location */
426 < int  pp[2];
427 < register RESOLU  *rp;
428 < double  lx, ly;
425 > loc2pix(                        /* compute pixel pos. from image location */
426 > int  pp[2],
427 > RESOLU  *rp,
428 > double  lx,
429 > double  ly
430 > )
431   {
432 <        register int  x, y;
432 >        int  x, y;
433  
434 <        x = lx * rp->xr;
435 <        y = ly * rp->yr;
434 >        x = (int)(lx*rp->xr + .5 - (lx < 0.0));
435 >        y = (int)(ly*rp->yr + .5 - (ly < 0.0));
436 >
437          if (rp->rt & XDECR)
438                  x = rp->xr-1 - x;
439          if (rp->rt & YDECR)
# Line 321 | Line 449 | double  lx, ly;
449  
450  
451   int
452 < getviewopt(v, ac, av)                   /* process view argument */
453 < register VIEW  *v;
454 < int  ac;
455 < register char  *av[];
452 > getviewopt(                             /* process view argument */
453 > VIEW  *v,
454 > int  ac,
455 > char  *av[]
456 > )
457   {
458 < #define check(c,l)      if ((av[0][c]&&av[0][c]!=' ') || \
458 > #define check(c,l)      if ((av[0][c]&&!isspace(av[0][c])) || \
459                          badarg(ac-1,av+1,l)) return(-1)
460  
461          if (ac <= 0 || av[0][0] != '-' || av[0][1] != 'v')
462                  return(-1);
463          switch (av[0][2]) {
464          case 't':                       /* type */
465 <                if (!av[0][3] || av[0][3]==' ')
465 >                if (!av[0][3] || isspace(av[0][3]))
466                          return(-1);
467                  check(4,"");
468                  v->type = av[0][3];
# Line 389 | Line 518 | register char  *av[];
518  
519  
520   int
521 < sscanview(vp, s)                        /* get view parameters from string */
522 < VIEW  *vp;
523 < register char  *s;
521 > sscanview(                              /* get view parameters from string */
522 > VIEW  *vp,
523 > char  *s
524 > )
525   {
526          int  ac;
527          char  *av[4];
528          int  na;
529          int  nvopts = 0;
530  
531 <        while (*s == ' ')
532 <                s++;
533 <        if (*s != '-')
404 <                s = sskip2(s,1);
531 >        while (isspace(*s))
532 >                if (!*s++)
533 >                        return(0);
534          while (*s) {
535                  ac = 0;
536                  do {
537                          if (ac || *s == '-')
538                                  av[ac++] = s;
539 <                        while (*s && *s != ' ')
539 >                        while (*s && !isspace(*s))
540                                  s++;
541 <                        while (*s == ' ')
541 >                        while (isspace(*s))
542                                  s++;
543                  } while (*s && ac < 4);
544                  if ((na = getviewopt(vp, ac, av)) >= 0) {
# Line 424 | Line 553 | register char  *s;
553  
554  
555   void
556 < fprintview(vp, fp)                      /* write out view parameters */
557 < register VIEW  *vp;
558 < FILE  *fp;
556 > fprintview(                             /* write out view parameters */
557 > VIEW  *vp,
558 > FILE  *fp
559 > )
560   {
561          fprintf(fp, " -vt%c", vp->type);
562          fprintf(fp, " -vp %.6g %.6g %.6g", vp->vp[0], vp->vp[1], vp->vp[2]);
# Line 441 | Line 571 | FILE  *fp;
571  
572  
573   char *
574 < viewopt(vp)                             /* translate to minimal view string */
575 < register VIEW  *vp;
574 > viewopt(                                /* translate to minimal view string */
575 > VIEW  *vp
576 > )
577   {
578          static char  vwstr[128];
579 <        register char  *cp = vwstr;
579 >        char  *cp = vwstr;
580  
581 +        *cp = '\0';
582          if (vp->type != stdview.type) {
583                  sprintf(cp, " -vt%c", vp->type);
584                  cp += strlen(cp);
585          }
586 <        if (!VEQ(vp->vp,stdview.vp)) {
586 >        if (!VABSEQ(vp->vp,stdview.vp)) {
587                  sprintf(cp, " -vp %.6g %.6g %.6g",
588                                  vp->vp[0], vp->vp[1], vp->vp[2]);
589                  cp += strlen(cp);
590          }
591 <        if (!FEQ(vp->vdist,stdview.vdist) || !VEQ(vp->vdir,stdview.vdir)) {
591 >        if (!FABSEQ(vp->vdist,stdview.vdist) || !VABSEQ(vp->vdir,stdview.vdir)) {
592                  sprintf(cp, " -vd %.6g %.6g %.6g",
593                                  vp->vdir[0]*vp->vdist,
594                                  vp->vdir[1]*vp->vdist,
595                                  vp->vdir[2]*vp->vdist);
596                  cp += strlen(cp);
597          }
598 <        if (!VEQ(vp->vup,stdview.vup)) {
598 >        if (!VABSEQ(vp->vup,stdview.vup)) {
599                  sprintf(cp, " -vu %.6g %.6g %.6g",
600                                  vp->vup[0], vp->vup[1], vp->vup[2]);
601                  cp += strlen(cp);
602          }
603 <        if (!FEQ(vp->horiz,stdview.horiz)) {
603 >        if (!FABSEQ(vp->horiz,stdview.horiz)) {
604                  sprintf(cp, " -vh %.6g", vp->horiz);
605                  cp += strlen(cp);
606          }
607 <        if (!FEQ(vp->vert,stdview.vert)) {
607 >        if (!FABSEQ(vp->vert,stdview.vert)) {
608                  sprintf(cp, " -vv %.6g", vp->vert);
609                  cp += strlen(cp);
610          }
611 <        if (!FEQ(vp->vfore,stdview.vfore)) {
611 >        if (!FABSEQ(vp->vfore,stdview.vfore)) {
612                  sprintf(cp, " -vo %.6g", vp->vfore);
613                  cp += strlen(cp);
614          }
615 <        if (!FEQ(vp->vaft,stdview.vaft)) {
615 >        if (!FABSEQ(vp->vaft,stdview.vaft)) {
616                  sprintf(cp, " -va %.6g", vp->vaft);
617                  cp += strlen(cp);
618          }
619 <        if (!FEQ(vp->hoff,stdview.hoff)) {
619 >        if (!FABSEQ(vp->hoff,stdview.hoff)) {
620                  sprintf(cp, " -vs %.6g", vp->hoff);
621                  cp += strlen(cp);
622          }
623 <        if (!FEQ(vp->voff,stdview.voff)) {
623 >        if (!FABSEQ(vp->voff,stdview.voff)) {
624                  sprintf(cp, " -vl %.6g", vp->voff);
625                  cp += strlen(cp);
626          }
# Line 497 | Line 629 | register VIEW  *vp;
629  
630  
631   int
632 < isview(s)                               /* is this a view string? */
633 < char  *s;
632 > isview(                                 /* is this a view string? */
633 > char  *s
634 > )
635   {
636          static char  *altname[]={NULL,VIEWSTR,"rpict","rview","rvu","rpiece","pinterp",NULL};
637          extern char  *progname;
638 <        register char  *cp;
639 <        register char  **an;
638 >        char  *cp;
639 >        char  **an;
640                                          /* add program name to list */
641          if (altname[0] == NULL) {
642                  for (cp = progname; *cp; cp++)
# Line 514 | Line 647 | char  *s;
647          }
648                                          /* skip leading path */
649          cp = s;
650 <        while (*cp && *cp != ' ')
650 >        while (*cp && !isspace(*cp))
651                  cp++;
652          while (cp > s && !ISDIRSEP(cp[-1]))
653                  cp--;
# Line 544 | Line 677 | gethview(                              /* get view from header */
677  
678  
679   int
680 < viewfile(fname, vp, rp)                 /* get view from file */
681 < char  *fname;
682 < VIEW  *vp;
683 < RESOLU  *rp;
680 > viewfile(                               /* get view from file */
681 > char  *fname,
682 > VIEW  *vp,
683 > RESOLU  *rp
684 > )
685   {
686          struct myview   mvs;
687          FILE  *fp;
# Line 565 | Line 699 | RESOLU  *rp;
699          if (rp != NULL && !fgetsresolu(rp, fp))
700                  mvs.ok = 0;
701  
702 <        fclose(fp);
702 >        if (fp != stdin)
703 >                fclose(fp);
704  
705          return(mvs.ok);
706   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines