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

Comparing ray/src/rt/rv2.c (file contents):
Revision 1.8 by greg, Thu Jun 8 17:04:40 1989 UTC vs.
Revision 2.64 by greg, Fri Oct 18 17:04:13 2013 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1987 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   *  rv2.c - command routines used in tracing a view.
6   *
7 < *     3/24/87
7 > *  External symbols declared in rpaint.h
8   */
9  
10 < #include  "ray.h"
10 > #include "copyright.h"
11  
12 < #include  "octree.h"
12 > #include  <ctype.h>
13 > #include  <string.h>
14  
15 + #include  "platform.h"
16 + #include  "rtprocess.h" /* win_popen() */
17 + #include  "paths.h"
18 + #include  "ray.h"
19 + #include  "source.h"
20 + #include  "ambient.h"
21   #include  "otypes.h"
18
22   #include  "rpaint.h"
23  
24 < #include  <ctype.h>
24 > extern int  psample;                    /* pixel sample size */
25 > extern double  maxdiff;                 /* max. sample difference */
26  
27 < #define  CTRL(c)        ('c'-'@')
27 > #define  CTRL(c)        ((c)-'@')
28  
29 + #ifdef  SMLFLT
30 + #define  sscanvec(s,v)  (sscanf(s,"%f %f %f",v,v+1,v+2)==3)
31 + #else
32 + #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
33 + #endif
34 +
35 + extern char  rifname[128];              /* rad input file name */
36 +
37   extern char  *progname;
38 + extern char  *octname;
39  
40  
41 < getframe(s)                             /* get a new frame */
42 < char  *s;
41 > void
42 > getframe(                               /* get a new frame */
43 >        char  *s
44 > )
45   {
46 <        int  x0, y0, x1, y1;
32 <
33 <        if (!strcmp("all", s)) {
34 <                pframe.l = pframe.d = 0;
35 <                pframe.r = ourview.hresolu;
36 <                pframe.u = ourview.vresolu;
37 <                pdepth = 0;
46 >        if (getrect(s, &pframe) < 0)
47                  return;
39        }
40        if (sscanf(s, "%d %d %d %d", &x0, &y0, &x1, &y1) != 4) {
41                if (dev->getcur == NULL)
42                        return;
43                (*dev->comout)("Pick first corner\n");
44                if ((*dev->getcur)(&x0, &y0) == ABORT)
45                        return;
46                (*dev->comout)("Pick second corner\n");
47                if ((*dev->getcur)(&x1, &y1) == ABORT)
48                        return;
49        }
50        if (x0 < x1) {
51                pframe.l = x0;
52                pframe.r = x1;
53        } else {
54                pframe.l = x1;
55                pframe.r = x0;
56        }
57        if (y0 < y1) {
58                pframe.d = y0;
59                pframe.u = y1;
60        } else {
61                pframe.d = y1;
62                pframe.u = y0;
63        }
64        if (pframe.l < 0) pframe.l = 0;
65        if (pframe.d < 0) pframe.d = 0;
66        if (pframe.r > ourview.hresolu) pframe.r = ourview.hresolu;
67        if (pframe.u > ourview.vresolu) pframe.u = ourview.vresolu;
48          pdepth = 0;
49   }
50  
51  
52 < getview(s)                              /* get/show view parameters */
53 < char  *s;
52 > void
53 > getrepaint(                             /* get area and repaint */
54 >        char  *s
55 > )
56   {
57 +        RECT  box;
58 +
59 +        if (getrect(s, &box) < 0)
60 +                return;
61 +        paintrect(&ptrunk, &box);
62 + }
63 +
64 +
65 + void
66 + getview(                                /* get/show/save view parameters */
67 +        char  *s
68 + )
69 + {
70          FILE  *fp;
71          char  buf[128];
72 <        char  *fname, *getpath();
72 >        char  *fname;
73          int  change = 0;
74 <        VIEW  nv;
74 >        VIEW  nv = ourview;
75  
76 <        if (sscanf(s, "%s", buf) == 1) {        /* write parameters to a file */
77 <                if ((fname = getpath(buf, NULL)) == NULL ||
76 >        while (isspace(*s))
77 >                s++;
78 >        if (*s == '-') {                        /* command line parameters */
79 >                if (sscanview(&nv, s))
80 >                        newview(&nv);
81 >                else
82 >                        error(COMMAND, "bad view option(s)");
83 >                return;
84 >        }
85 >        if (nextword(buf, sizeof(buf), s) != NULL) {    /* write to a file */
86 >                if ((fname = getpath(buf, NULL, 0)) == NULL ||
87                                  (fp = fopen(fname, "a")) == NULL) {
88                          sprintf(errmsg, "cannot open \"%s\"", buf);
89                          error(COMMAND, errmsg);
# Line 87 | Line 91 | char  *s;
91                  }
92                  fputs(progname, fp);
93                  fprintview(&ourview, fp);
94 <                fputs("\n", fp);
94 >                fputs(sskip(s), fp);
95 >                putc('\n', fp);
96                  fclose(fp);
97                  return;
98          }
99          sprintf(buf, "view type (%c): ", ourview.type);
100          (*dev->comout)(buf);
101 <        (*dev->comin)(buf);
102 <        if (buf[0] == CTRL(C)) return;
101 >        (*dev->comin)(buf, NULL);
102 >        if (buf[0] == CTRL('C')) return;
103          if (buf[0] && buf[0] != ourview.type) {
104                  nv.type = buf[0];
105                  change++;
106 <        } else
102 <                nv.type = ourview.type;
106 >        }
107          sprintf(buf, "view point (%.6g %.6g %.6g): ",
108                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
109          (*dev->comout)(buf);
110 <        (*dev->comin)(buf);
111 <        if (buf[0] == CTRL(C)) return;
112 <        if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3)
110 >        (*dev->comin)(buf, NULL);
111 >        if (buf[0] == CTRL('C')) return;
112 >        if (sscanvec(buf, nv.vp))
113                  change++;
110        else
111                VCOPY(nv.vp, ourview.vp);
114          sprintf(buf, "view direction (%.6g %.6g %.6g): ",
115 <                        ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
115 >                        ourview.vdir[0]*ourview.vdist,
116 >                        ourview.vdir[1]*ourview.vdist,
117 >                        ourview.vdir[2]*ourview.vdist);
118          (*dev->comout)(buf);
119 <        (*dev->comin)(buf);
120 <        if (buf[0] == CTRL(C)) return;
121 <        if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3)
119 >        (*dev->comin)(buf, NULL);
120 >        if (buf[0] == CTRL('C')) return;
121 >        if (sscanvec(buf, nv.vdir)) {
122 >                nv.vdist = 1.;
123                  change++;
124 <        else
120 <                VCOPY(nv.vdir, ourview.vdir);
124 >        }
125          sprintf(buf, "view up (%.6g %.6g %.6g): ",
126                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
127          (*dev->comout)(buf);
128 <        (*dev->comin)(buf);
129 <        if (buf[0] == CTRL(C)) return;
130 <        if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3)
128 >        (*dev->comin)(buf, NULL);
129 >        if (buf[0] == CTRL('C')) return;
130 >        if (sscanvec(buf, nv.vup))
131                  change++;
128        else
129                VCOPY(nv.vup, ourview.vup);
132          sprintf(buf, "view horiz and vert size (%.6g %.6g): ",
133                          ourview.horiz, ourview.vert);
134          (*dev->comout)(buf);
135 <        (*dev->comin)(buf);
136 <        if (buf[0] == CTRL(C)) return;
135 >        (*dev->comin)(buf, NULL);
136 >        if (buf[0] == CTRL('C')) return;
137          if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
138                  change++;
139 <        else {
140 <                nv.horiz = ourview.horiz; nv.vert = ourview.vert;
139 <        }
140 <        sprintf(buf, "x and y resolution (%d %d): ",
141 <                        ourview.hresolu, ourview.vresolu);
139 >        sprintf(buf, "fore and aft clipping plane (%.6g %.6g): ",
140 >                        ourview.vfore, ourview.vaft);
141          (*dev->comout)(buf);
142 <        (*dev->comin)(buf);
143 <        if (buf[0] == CTRL(C)) return;
144 <        if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) == 2)
142 >        (*dev->comin)(buf, NULL);
143 >        if (buf[0] == CTRL('C')) return;
144 >        if (sscanf(buf, "%lf %lf", &nv.vfore, &nv.vaft) == 2)
145                  change++;
146 <        else {
147 <                nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
148 <        }
146 >        sprintf(buf, "view shift and lift (%.6g %.6g): ",
147 >                        ourview.hoff, ourview.voff);
148 >        (*dev->comout)(buf);
149 >        (*dev->comin)(buf, NULL);
150 >        if (buf[0] == CTRL('C')) return;
151 >        if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
152 >                change++;
153          if (change)
154                  newview(&nv);
155   }
156  
157  
158 < lastview(s)                             /* return to a previous view */
159 < char  *s;
158 > void
159 > lastview(                               /* return to a previous view */
160 >        char  *s
161 > )
162   {
163          char  buf[128];
164 <        char  *fname, *getpath();
164 >        char  *fname;
165          int  success;
166          VIEW  nv;
167 <
168 <        if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
169 <                bcopy(&stdview, &nv, sizeof(VIEW));
170 <                if ((fname = getpath(buf, NULL)) == NULL ||
171 <                                (success = viewfile(fname, &nv)) == -1) {
167 >                                        /* get parameters from a file */
168 >        if (nextword(buf, sizeof(buf), s) != NULL) {
169 >                nv = stdview;
170 >                if ((fname = getpath(buf, "", R_OK)) == NULL ||
171 >                                (success = viewfile(fname, &nv, NULL)) == -1) {
172                          sprintf(errmsg, "cannot open \"%s\"", buf);
173                          error(COMMAND, errmsg);
174                          return;
# Line 174 | Line 179 | char  *s;
179                          newview(&nv);
180                  return;
181          }
182 <        if (oldview.hresolu == 0) {     /* no old view! */
182 >        if (oldview.type == 0) {        /* no old view! */
183                  error(COMMAND, "no previous view");
184                  return;
185          }
186 <        bcopy(&ourview, &nv, sizeof(VIEW));
187 <        bcopy(&oldview, &ourview, sizeof(VIEW));
188 <        bcopy(&nv, &oldview, sizeof(VIEW));
189 <        newimage();
186 >        nv = ourview;
187 >        ourview = oldview;
188 >        oldview = nv;
189 >        newimage(NULL);
190   }
191  
192  
193 < getinterest(s, direc, vec, mp)          /* get area of interest */
194 < char  *s;
195 < int  direc;
196 < FVECT  vec;
192 < double  *mp;
193 > void
194 > saveview(                               /* save view to rad file */
195 >        char  *s
196 > )
197   {
198 <        int  x, y;
199 <        RAY  thisray;
200 <        register int  i;
198 >        char  view[64];
199 >        char  *fname;
200 >        FILE  *fp;
201  
202 <        if (sscanf(s, "%lf", mp) != 1)
203 <                *mp = 1.0;
204 <        else if (*mp < -FTINY)          /* negative zoom is reduction */
205 <                *mp = -1.0 / *mp;
202 <        else if (*mp <= FTINY) {        /* too small */
203 <                error(COMMAND, "illegal magnification");
204 <                return(-1);
205 <        }
206 <        if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) {
207 <                if (dev->getcur == NULL)
208 <                        return(-1);
209 <                (*dev->comout)("Pick view center\n");
210 <                if ((*dev->getcur)(&x, &y) == ABORT)
211 <                        return(-1);
212 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
213 <                if (!direc || ourview.type == VT_PAR) {
214 <                        rayorigin(&thisray, NULL, PRIMARY, 1.0);
215 <                        if (!localhit(&thisray, &thescene)) {
216 <                                error(COMMAND, "not a local object");
217 <                                return(-1);
218 <                        }
202 >        if (*atos(view, sizeof(view), s)) {
203 >                if (isint(view)) {
204 >                        error(COMMAND, "cannot write view by number");
205 >                        return;
206                  }
207 <                if (direc)
208 <                        if (ourview.type == VT_PAR)
209 <                                for (i = 0; i < 3; i++)
210 <                                        vec[i] = thisray.rop[i] - ourview.vp[i];
211 <                        else
212 <                                VCOPY(vec, thisray.rdir);
213 <                else
214 <                        VCOPY(vec, thisray.rop);
215 <        } else if (direc)
216 <                        for (i = 0; i < 3; i++)
217 <                                vec[i] -= ourview.vp[i];
218 <        return(0);
207 >                s = sskip(s);
208 >        }
209 >        if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) {
210 >                error(COMMAND, "no previous rad file");
211 >                return;
212 >        }
213 >        if ((fname = getpath(rifname, NULL, 0)) == NULL ||
214 >                        (fp = fopen(fname, "a")) == NULL) {
215 >                sprintf(errmsg, "cannot open \"%s\"", rifname);
216 >                error(COMMAND, errmsg);
217 >                return;
218 >        }
219 >        fputs("view= ", fp);
220 >        fputs(view, fp);
221 >        fprintview(&ourview, fp);
222 >        putc('\n', fp);
223 >        fclose(fp);
224   }
225  
226  
227 < getaim(s)                               /* aim camera */
228 < char  *s;
227 > void
228 > loadview(                               /* load view from rad file */
229 >        char  *s
230 > )
231   {
232 <        extern double  tan(), atan();
233 <        double  zfact;
232 >        char  buf[512];
233 >        char  *fname;
234 >        FILE  *fp;
235          VIEW  nv;
236  
237 <        if (getinterest(s, 1, nv.vdir, &zfact) < 0)
237 >        strcpy(buf, "rad -n -s -V -v ");
238 >        if (sscanf(s, "%s", buf+strlen(buf)) == 1)
239 >                s = sskip(s);
240 >        else
241 >                strcat(buf, "1");
242 >        if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) {
243 >                error(COMMAND, "no previous rad file");
244                  return;
244        VCOPY(nv.vp, ourview.vp);
245        VCOPY(nv.vup, ourview.vup);
246        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
247        if ((nv.type = ourview.type) == VT_PAR) {
248                nv.horiz = ourview.horiz / zfact;
249                nv.vert = ourview.vert / zfact;
250        } else {
251                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
252                                (PI/180./2.);
253                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
254                                (PI/180./2.);
245          }
246 +        if ((fname = getpath(rifname, "", R_OK)) == NULL) {
247 +                sprintf(errmsg, "cannot access \"%s\"", rifname);
248 +                error(COMMAND, errmsg);
249 +                return;
250 +        }
251 +        sprintf(buf+strlen(buf), " %s", fname);
252 +        if ((fp = popen(buf, "r")) == NULL) {
253 +                error(COMMAND, "cannot run rad");
254 +                return;
255 +        }
256 +        buf[0] = '\0';
257 +        fgets(buf, sizeof(buf), fp);
258 +        pclose(fp);
259 +        nv = stdview;
260 +        if (!sscanview(&nv, buf)) {
261 +                error(COMMAND, "rad error -- no such view?");
262 +                return;
263 +        }
264          newview(&nv);
265   }
266  
267  
268 < getmove(s)                              /* move camera */
269 < char  *s;
268 > void
269 > getaim(                         /* aim camera */
270 >        char  *s
271 > )
272   {
273 +        VIEW  nv = ourview;
274 +        double  zfact;
275 +
276 +        if (getinterest(s, 1, nv.vdir, &zfact) < 0)
277 +                return;
278 +        zoomview(&nv, zfact);
279 +        newview(&nv);
280 + }
281 +
282 +
283 + void
284 + getfocus(                               /* set focus distance */
285 +        char *s
286 + )
287 + {
288 +        char  buf[64];
289 +        double  dist;
290 +
291 +        if (sscanf(s, "%lf", &dist) < 1) {
292 +                int     x, y;
293 +                RAY     thisray;
294 +                if (dev->getcur == NULL)
295 +                        return;
296 +                (*dev->comout)("Pick focus point\n");
297 +                if ((*dev->getcur)(&x, &y) == ABORT)
298 +                        return;
299 +                if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
300 +                        &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) {
301 +                        error(COMMAND, "not on image");
302 +                        return;
303 +                }
304 +                rayorigin(&thisray, PRIMARY, NULL, NULL);
305 +                if (!localhit(&thisray, &thescene)) {
306 +                        error(COMMAND, "not a local object");
307 +                        return;
308 +                }
309 +                dist = thisray.rot;
310 +        } else if (dist <= .0) {
311 +                error(COMMAND, "focus distance must be positive");
312 +                return;
313 +        }
314 +        ourview.vdist = dist;
315 +        sprintf(buf, "Focus distance set to %f\n", dist);
316 +        (*dev->comout)(buf);
317 + }
318 +
319 +
320 + void
321 + getmove(                                /* move camera */
322 +        char  *s
323 + )
324 + {
325          FVECT  vc;
326          double  mag;
327  
# Line 269 | Line 331 | char  *s;
331   }
332  
333  
334 < getrotate(s)                            /* rotate camera */
335 < char  *s;
334 > void
335 > getrotate(                              /* rotate camera */
336 >        char  *s
337 > )
338   {
339 <        extern double  normalize(), tan(), atan();
276 <        VIEW  nv;
277 <        FVECT  v1;
339 >        VIEW  nv = ourview;
340          double  angle, elev, zfact;
341          
342          elev = 0.0; zfact = 1.0;
# Line 282 | Line 344 | char  *s;
344                  error(COMMAND, "missing angle");
345                  return;
346          }
285        VCOPY(nv.vp, ourview.vp);
286        VCOPY(nv.vup, ourview.vup);
287        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
347          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
348 <        if (elev != 0.0) {
349 <                fcross(v1, nv.vdir, ourview.vup);
350 <                normalize(v1);
351 <                spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
293 <        }
294 <        if ((nv.type = ourview.type) == VT_PAR) {
295 <                nv.horiz = ourview.horiz / zfact;
296 <                nv.vert = ourview.vert / zfact;
297 <        } else {
298 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
299 <                                (PI/180./2.);
300 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
301 <                                (PI/180./2.);
302 <        }
348 >        if (elev != 0.0)
349 >                geodesic(nv.vdir, nv.vdir, nv.vup, elev*(PI/180.), GEOD_RAD);
350 >        
351 >        zoomview(&nv, zfact);
352          newview(&nv);
353   }
354  
355  
356 < getpivot(s)                             /* pivot viewpoint */
357 < register char  *s;
356 > void
357 > getpivot(                               /* pivot viewpoint */
358 >        char  *s
359 > )
360   {
361          FVECT  vc;
362          double  angle, elev, mag;
# Line 315 | Line 366 | register char  *s;
366                  error(COMMAND, "missing angle");
367                  return;
368          }
369 <        if (getinterest(sskip(sskip(s)), 0, vc, &mag) < 0)
369 >        if (getinterest(sskip2(s,2), 0, vc, &mag) < 0)
370                  return;
371          moveview(angle, elev, mag, vc);
372   }
373  
374  
375 < getexposure(s)                          /* get new exposure */
376 < char  *s;
375 > void
376 > getorigin(                              /* origin viewpoint */
377 >        char  *s
378 > )
379   {
380 <        double  atof(), pow(), fabs();
380 >        VIEW    nv = ourview;
381 >        double  d;
382 >                                        /* get new view origin */
383 >        if (!sscanvec(s, nv.vp)) {
384 >                int     x, y;
385 >                RAY     thisray;
386 >                if (dev->getcur == NULL)
387 >                        return;
388 >                (*dev->comout)("Pick point on surface for new origin\n");
389 >                if ((*dev->getcur)(&x, &y) == ABORT)
390 >                        return;
391 >                if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
392 >                        &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) {
393 >                        error(COMMAND, "not on image");
394 >                        return;
395 >                }
396 >                rayorigin(&thisray, PRIMARY, NULL, NULL);
397 >                if (!localhit(&thisray, &thescene)) {
398 >                        error(COMMAND, "not a local object");
399 >                        return;
400 >                }
401 >                if (thisray.rod < 0.0)  /* don't look through other side */
402 >                        flipsurface(&thisray);
403 >                VSUM(nv.vp, thisray.rop, thisray.ron, 2.0*FTINY);
404 >                VCOPY(nv.vdir, thisray.ron);
405 >        } else if (!sscanvec(sskip2(s,3), nv.vdir) || normalize(nv.vdir) == 0.0)
406 >                VCOPY(nv.vdir, ourview.vdir);
407 >
408 >        d = DOT(nv.vdir, nv.vup);       /* need different up vector? */
409 >        if (d*d >= 1.-2.*FTINY) {
410 >                int     i;
411 >                nv.vup[0] = nv.vup[1] = nv.vup[2] = 0.0;
412 >                for (i = 3; i--; )
413 >                        if (nv.vdir[i]*nv.vdir[i] < 0.34)
414 >                                break;
415 >                nv.vup[i] = 1.;
416 >        }
417 >        newview(&nv);
418 > }
419 >
420 >
421 > void
422 > getexposure(                            /* get new exposure */
423 >        char  *s
424 > )
425 > {
426          char  buf[128];
427 <        register char  *cp;
330 <        register PNODE  *p;
331 <        RECT  r;
427 >        char  *cp;
428          int  x, y;
429 <        double  e;
429 >        PNODE  *p = &ptrunk;
430 >        int  adapt = 0;
431 >        double  e = 1.0;
432  
433          for (cp = s; isspace(*cp); cp++)
434                  ;
435 +        if (*cp == '@') {
436 +                adapt++;
437 +                while (isspace(*++cp))
438 +                        ;
439 +        }
440          if (*cp == '\0') {              /* normalize to point */
441                  if (dev->getcur == NULL)
442                          return;
443                  (*dev->comout)("Pick point for exposure\n");
444                  if ((*dev->getcur)(&x, &y) == ABORT)
445                          return;
446 <                r.l = r.d = 0;
344 <                r.r = ourview.hresolu; r.u = ourview.vresolu;
345 <                p = findrect(x, y, &ptrunk, &r, -1);
346 <                e = 1.0;
446 >                p = findrect(x, y, &ptrunk, -1);
447          } else {
448                  if (*cp == '=') {       /* absolute setting */
449                          p = NULL;
# Line 351 | Line 451 | char  *s;
451                          for (cp++; isspace(*cp); cp++)
452                                  ;
453                          if (*cp == '\0') {      /* interactive */
454 <                                sprintf(buf, "exposure (%lf): ", exposure);
454 >                                sprintf(buf, "exposure (%f): ", exposure);
455                                  (*dev->comout)(buf);
456 <                                (*dev->comin)(buf);
456 >                                (*dev->comin)(buf, NULL);
457                                  for (cp = buf; isspace(*cp); cp++)
458                                          ;
459                                  if (*cp == '\0')
460                                          return;
461                          }
362                } else {                /* normalize to average */
363                        p = &ptrunk;
364                        e = 1.0;
462                  }
463                  if (*cp == '+' || *cp == '-')   /* f-stops */
464                          e *= pow(2.0, atof(cp));
# Line 369 | Line 466 | char  *s;
466                          e *= atof(cp);
467          }
468          if (p != NULL) {                /* relative setting */
469 <                if (bright(p->v) <= FTINY) {
469 >                compavg(p);
470 >                if (bright(p->v) < 1e-15) {
471                          error(COMMAND, "cannot normalize to zero");
472                          return;
473                  }
474 <                e *= 0.5 / bright(p->v);
474 >                if (adapt)
475 >                        e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure;
476 >                else
477 >                        e *= 0.5 / bright(p->v);
478          }
479          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
480                  return;
# Line 382 | Line 483 | char  *s;
483          redraw();
484   }
485  
486 + typedef union {int i; double d; COLOR C;}       *MyUptr;
487 + #define  FEQ(x,y)     (fabs((x)-(y)) <= FTINY)
488  
489 < setparam(s)                             /* get/set program parameter */
490 < register char  *s;
489 > int
490 > getparam(               /* get variable from user */
491 >        char  *str,
492 >        char  *dsc,
493 >        int  typ,
494 >        void  *p
495 > )
496   {
497 <        extern int  psample;
390 <        extern double  maxdiff;
391 <        extern double  minweight;
392 <        extern int  maxdepth;
393 <        extern double  dstrsrc;
394 <        extern double  shadthresh;
395 <        extern COLOR  ambval;
396 <        extern double  ambacc;
397 <        extern double  minarad;
398 <        extern int  ambres;
399 <        extern int  ambdiv;
400 <        extern int  ambssamp;
401 <        extern int  ambounce;
497 >        MyUptr  ptr = (MyUptr)p;
498          int  i0;
499          double  d0, d1, d2;
500 +        char  buf[48];
501 +
502 +        switch (typ) {
503 +        case 'i':                       /* integer */
504 +                if (sscanf(str, "%d", &i0) != 1) {
505 +                        (*dev->comout)(dsc);
506 +                        sprintf(buf, " (%d): ", ptr->i);
507 +                        (*dev->comout)(buf);
508 +                        (*dev->comin)(buf, NULL);
509 +                        if (sscanf(buf, "%d", &i0) != 1)
510 +                                return(0);
511 +                }
512 +                if (ptr->i == i0)
513 +                        return(0);
514 +                ptr->i = i0;
515 +                break;
516 +        case 'r':                       /* real */
517 +                if (sscanf(str, "%lf", &d0) != 1) {
518 +                        (*dev->comout)(dsc);
519 +                        sprintf(buf, " (%.6g): ", ptr->d);
520 +                        (*dev->comout)(buf);
521 +                        (*dev->comin)(buf, NULL);
522 +                        if (sscanf(buf, "%lf", &d0) != 1)
523 +                                return(0);
524 +                }
525 +                if (FEQ(ptr->d, d0))
526 +                        return(0);
527 +                ptr->d = d0;
528 +                break;
529 +        case 'b':                       /* boolean */
530 +                if (sscanf(str, "%1s", buf) != 1) {
531 +                        (*dev->comout)(dsc);
532 +                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
533 +                        (*dev->comout)(buf);
534 +                        (*dev->comin)(buf, NULL);
535 +                        if (buf[0] == '\0')
536 +                                return(0);
537 +                }
538 +                if (strchr("yY+1tTnN-0fF", buf[0]) == NULL)
539 +                        return(0);
540 +                i0 = strchr("yY+1tT", buf[0]) != NULL;
541 +                if (ptr->i == i0)
542 +                        return(0);
543 +                ptr->i = i0;
544 +                break;
545 +        case 'C':                       /* color */
546 +                if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
547 +                        (*dev->comout)(dsc);
548 +                        sprintf(buf, " (%.6g %.6g %.6g): ",
549 +                                        colval(ptr->C,RED),
550 +                                        colval(ptr->C,GRN),
551 +                                        colval(ptr->C,BLU));
552 +                        (*dev->comout)(buf);
553 +                        (*dev->comin)(buf, NULL);
554 +                        if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
555 +                                return(0);
556 +                }
557 +                if (FEQ(colval(ptr->C,RED), d0) &&
558 +                                FEQ(colval(ptr->C,GRN), d1) &&
559 +                                FEQ(colval(ptr->C,BLU), d2))
560 +                        return(0);
561 +                setcolor(ptr->C, d0, d1, d2);
562 +                break;
563 +        default:
564 +                return(0);              /* shouldn't happen */
565 +        }
566 +        newparam++;
567 +        return(1);
568 + }
569 +
570 +
571 + void
572 + setparam(                               /* get/set program parameter */
573 +        char  *s
574 + )
575 + {
576 +        int  prev_newp = newparam;
577          char  buf[128];
578          
579          if (s[0] == '\0') {
580 <                (*dev->comout)("aa ab ad ar as av dj dt lr lw sp st: ");
581 <                (*dev->comin)(buf);
580 >                (*dev->comout)(
581 >                "aa ab ad ar as av aw b bv dc dv dj ds dt i lr lw me ma mg ms ps pt ss st u: ");
582 >                (*dev->comin)(buf, NULL);
583                  s = buf;
584          }
585          switch (s[0]) {
586 +        case 'u':                       /* uncorrelated sampling */
587 +                getparam(s+1, "uncorrelated sampling", 'b',
588 +                                (void *)&rand_samp);
589 +                break;
590          case 'l':                       /* limit */
591                  switch (s[1]) {
592                  case 'w':                       /* weight */
593 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
594 <                                sprintf(buf, "limit weight (%.6g): ",
417 <                                                minweight);
418 <                                (*dev->comout)(buf);
419 <                                (*dev->comin)(buf);
420 <                                if (sscanf(buf, "%lf", &d0) != 1)
421 <                                        break;
422 <                        }
423 <                        minweight = d0;
593 >                        getparam(s+2, "limit weight", 'r',
594 >                                        (void *)&minweight);
595                          break;
596                  case 'r':                       /* reflection */
597 <                        if (sscanf(s+2, "%d", &i0) != 1) {
598 <                                sprintf(buf, "limit reflection (%d): ",
428 <                                                maxdepth);
429 <                                (*dev->comout)(buf);
430 <                                (*dev->comin)(buf);
431 <                                if (sscanf(buf, "%d", &i0) != 1)
432 <                                        break;
433 <                        }
434 <                        maxdepth = i0;
597 >                        getparam(s+2, "limit reflection", 'i',
598 >                                        (void *)&maxdepth);
599                          break;
600                  default:
601                          goto badparam;
# Line 440 | Line 604 | register char  *s;
604          case 'd':                       /* direct */
605                  switch (s[1]) {
606                  case 'j':                       /* jitter */
607 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
608 <                                sprintf(buf, "direct jitter (%.6g): ",
445 <                                                dstrsrc);
446 <                                (*dev->comout)(buf);
447 <                                (*dev->comin)(buf);
448 <                                if (sscanf(buf, "%lf", &d0) != 1)
449 <                                        break;
450 <                        }
451 <                        dstrsrc = d0;
607 >                        getparam(s+2, "direct jitter", 'r',
608 >                                        (void *)&dstrsrc);
609                          break;
610 +                case 'c':                       /* certainty */
611 +                        getparam(s+2, "direct certainty", 'r',
612 +                                        (void *)&shadcert);
613 +                        break;
614                  case 't':                       /* threshold */
615 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
616 <                                sprintf(buf, "direct threshold (%.6g): ",
456 <                                                shadthresh);
457 <                                (*dev->comout)(buf);
458 <                                (*dev->comin)(buf);
459 <                                if (sscanf(buf, "%lf", &d0) != 1)
460 <                                        break;
461 <                        }
462 <                        shadthresh = d0;
615 >                        getparam(s+2, "direct threshold", 'r',
616 >                                        (void *)&shadthresh);
617                          break;
618 +                case 'v':                       /* visibility */
619 +                        getparam(s+2, "direct visibility", 'b',
620 +                                        (void *)&directvis);
621 +                        break;
622 +                case 's':                       /* sampling */
623 +                        getparam(s+2, "direct sampling", 'r',
624 +                                        (void *)&srcsizerat);
625 +                        break;
626                  default:
627                          goto badparam;
628                  }
629                  break;
630 +        case 'b':                       /* back faces or black and white */
631 +                switch (s[1]) {
632 +                case 'v':                       /* back face visibility */
633 +                        getparam(s+2, "back face visibility", 'b',
634 +                                        (void *)&backvis);
635 +                        break;
636 +                case '\0':                      /* black and white */
637 +                case ' ':
638 +                case 'y': case 'Y': case 't': case 'T': case '1': case '+':
639 +                case 'n': case 'N': case 'f': case 'F': case '0': case '-':
640 +                        getparam(s+1, "black and white", 'b',
641 +                                        (void *)&greyscale);
642 +                        newparam = prev_newp;
643 +                        break;
644 +                default:
645 +                        goto badparam;
646 +                }
647 +                break;
648 +        case 'i':                       /* irradiance */
649 +                getparam(s+1, "irradiance", 'b',
650 +                                (void *)&do_irrad);
651 +                break;
652          case 'a':                       /* ambient */
653                  switch (s[1]) {
654                  case 'v':                       /* value */
655 <                        if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
656 <                                sprintf(buf,
473 <                                        "ambient value (%.6g %.6g %.6g): ",
474 <                                                colval(ambval,RED),
475 <                                                colval(ambval,GRN),
476 <                                                colval(ambval,BLU));
477 <                                (*dev->comout)(buf);
478 <                                (*dev->comin)(buf);
479 <                                if (sscanf(buf, "%lf %lf %lf",
480 <                                                &d0, &d1, &d2) != 3)
481 <                                        break;
482 <                        }
483 <                        setcolor(ambval, d0, d1, d2);
655 >                        getparam(s+2, "ambient value", 'C',
656 >                                        (void *)ambval);
657                          break;
658 +                case 'w':                       /* weight */
659 +                        getparam(s+2, "ambient value weight", 'i',
660 +                                        (void *)&ambvwt);
661 +                        break;
662                  case 'a':                       /* accuracy */
663 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
664 <                                sprintf(buf, "ambient accuracy (%.6g): ",
665 <                                                ambacc);
489 <                                (*dev->comout)(buf);
490 <                                (*dev->comin)(buf);
491 <                                if (sscanf(buf, "%lf", &d0) != 1)
492 <                                        break;
493 <                        }
494 <                        ambacc = d0;
663 >                        if (getparam(s+2, "ambient accuracy", 'r',
664 >                                        (void *)&ambacc))
665 >                                setambacc(ambacc);
666                          break;
667                  case 'd':                       /* divisions */
668 <                        if (sscanf(s+2, "%d", &i0) != 1) {
669 <                                sprintf(buf, "ambient divisions (%d): ",
499 <                                                ambdiv);
500 <                                (*dev->comout)(buf);
501 <                                (*dev->comin)(buf);
502 <                                if (sscanf(buf, "%d", &i0) != 1)
503 <                                        break;
504 <                        }
505 <                        ambdiv = i0;
668 >                        getparam(s+2, "ambient divisions", 'i',
669 >                                        (void *)&ambdiv);
670                          break;
671                  case 's':                       /* samples */
672 <                        if (sscanf(s+2, "%d", &i0) != 1) {
673 <                                sprintf(buf, "ambient super-samples (%d): ",
510 <                                                ambssamp);
511 <                                (*dev->comout)(buf);
512 <                                (*dev->comin)(buf);
513 <                                if (sscanf(buf, "%d", &i0) != 1)
514 <                                        break;
515 <                        }
516 <                        ambssamp = i0;
672 >                        getparam(s+2, "ambient super-samples", 'i',
673 >                                        (void *)&ambssamp);
674                          break;
675                  case 'b':                       /* bounces */
676 <                        if (sscanf(s+2, "%d", &i0) != 1) {
677 <                                sprintf(buf, "ambient bounces (%d): ",
521 <                                                ambounce);
522 <                                (*dev->comout)(buf);
523 <                                (*dev->comin)(buf);
524 <                                if (sscanf(buf, "%d", &i0) != 1)
525 <                                        break;
526 <                        }
527 <                        ambounce = i0;
676 >                        getparam(s+2, "ambient bounces", 'i',
677 >                                        (void *)&ambounce);
678                          break;
679                  case 'r':
680 <                        if (sscanf(s+2, "%d", &i0) != 1) {
681 <                                sprintf(buf, "ambient resolution (%d): ",
682 <                                                ambres);
533 <                                (*dev->comout)(buf);
534 <                                (*dev->comin)(buf);
535 <                                if (sscanf(buf, "%d", &i0) != 1)
536 <                                        break;
537 <                        }
538 <                        ambres = i0;
539 <                        minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
680 >                        if (getparam(s+2, "ambient resolution", 'i',
681 >                                        (void *)&ambres))
682 >                                setambres(ambres);
683                          break;
684                  default:
685                          goto badparam;
686                  }
687                  break;
688 <        case 's':                       /* sample */
688 >        case 'm':                       /* medium */
689                  switch (s[1]) {
690 <                case 'p':                       /* pixel */
691 <                        if (sscanf(s+2, "%d", &i0) != 1) {
692 <                                sprintf(buf, "sample pixel (%d): ", psample);
550 <                                (*dev->comout)(buf);
551 <                                (*dev->comin)(buf);
552 <                                if (sscanf(buf, "%d", &i0) != 1)
553 <                                        break;
554 <                        }
555 <                        psample = i0;
556 <                        pdepth = 0;
690 >                case 'e':                       /* extinction coefficient */
691 >                        getparam(s+2, "extinction coefficient", 'C',
692 >                                        (void *)cextinction);
693                          break;
694 +                case 'a':                       /* scattering albedo */
695 +                        getparam(s+2, "scattering albedo", 'C',
696 +                                        (void *)salbedo);
697 +                        break;
698 +                case 'g':                       /* scattering eccentricity */
699 +                        getparam(s+2, "scattering eccentricity", 'r',
700 +                                        (void *)&seccg);
701 +                        break;
702 +                case 's':                       /* sampling distance */
703 +                        getparam(s+2, "mist sampling distance", 'r',
704 +                                        (void *)&ssampdist);
705 +                        break;
706 +                default:
707 +                        goto badparam;
708 +                }
709 +                break;
710 +        case 'p':                       /* pixel */
711 +                switch (s[1]) {
712 +                case 's':                       /* sample */
713 +                        if (getparam(s+2, "pixel sample", 'i',
714 +                                        (void *)&psample))
715 +                                pdepth = 0;
716 +                        break;
717                  case 't':                       /* threshold */
718 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
719 <                                sprintf(buf, "sample threshold (%.6g): ",
720 <                                                maxdiff);
562 <                                (*dev->comout)(buf);
563 <                                (*dev->comin)(buf);
564 <                                if (sscanf(buf, "%lf", &d0) != 1)
565 <                                        break;
566 <                        }
567 <                        maxdiff = d0;
568 <                        pdepth = 0;
718 >                        if (getparam(s+2, "pixel threshold", 'r',
719 >                                        (void *)&maxdiff))
720 >                                pdepth = 0;
721                          break;
722                  default:
723                          goto badparam;
724                  }
725 +                newparam = prev_newp;
726                  break;
727 +        case 's':                       /* specular */
728 +                switch (s[1]) {
729 +                case 's':                       /* sampling */
730 +                        getparam(s+2, "specular sampling", 'r',
731 +                                        (void *)&specjitter);
732 +                        break;
733 +                case 't':                       /* threshold */
734 +                        getparam(s+2, "specular threshold", 'r',
735 +                                        (void *)&specthresh);
736 +                        break;
737 +                default:
738 +                        goto badparam;
739 +                }
740 +                break;
741          case '\0':                      /* nothing */
742                  break;
743          default:;
744   badparam:
745 +                *sskip(s) = '\0';
746                  sprintf(errmsg, "%s: unknown variable", s);
747                  error(COMMAND, errmsg);
748                  break;
# Line 582 | Line 750 | badparam:
750   }
751  
752  
753 < traceray(s)                             /* trace a single ray */
754 < char  *s;
753 > void
754 > traceray(                               /* trace a single ray */
755 >        char  *s
756 > )
757   {
758 <        char  buf[128];
759 <        int  x, y;
590 <        RAY  thisray;
758 >        RAY     thisray;
759 >        char    buf[512];
760  
761 <        if (sscanf(s, "%lf %lf %lf %lf %lf %lf",
593 <                &thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2],
594 <                &thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) {
761 >        thisray.rmax = 0.0;
762  
763 +        if (!sscanvec(s, thisray.rorg) ||
764 +                        !sscanvec(sskip2(s,3), thisray.rdir)) {
765 +                int  x, y;
766 +
767                  if (dev->getcur == NULL)
768                          return;
769                  (*dev->comout)("Pick ray\n");
770                  if ((*dev->getcur)(&x, &y) == ABORT)
771                          return;
772  
773 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
774 <                
773 >                if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
774 >                        &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) {
775 >                        error(COMMAND, "not on image");
776 >                        return;
777 >                }
778 >
779          } else if (normalize(thisray.rdir) == 0.0) {
780                  error(COMMAND, "zero ray direction");
781                  return;
782          }
783  
784 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
610 <        
611 <        rayvalue(&thisray);
784 >        ray_trace(&thisray);
785  
786          if (thisray.ro == NULL)
787                  (*dev->comout)("ray hit nothing");
788          else {
789 <                sprintf(buf, "ray hit %s %s \"%s\"",
790 <                                objptr(thisray.ro->omod)->oname,
789 >                OBJREC  *mat = NULL;
790 >                OBJREC  *mod = NULL;
791 >                char    matspec[256];
792 >                OBJREC  *ino;
793 >
794 >                matspec[0] = '\0';
795 >                if (thisray.ro->omod != OVOID) {
796 >                        mod = objptr(thisray.ro->omod);
797 >                        mat = findmaterial(mod);
798 >                }
799 >                if (thisray.rod < 0.0)
800 >                        strcpy(matspec, "back of ");
801 >                if (mod != NULL) {
802 >                        strcat(matspec, mod->oname);
803 >                        if (mat != mod && mat != NULL)
804 >                                sprintf(matspec+strlen(matspec),
805 >                                        " (%s)", mat->oname);
806 >                } else
807 >                        strcat(matspec, VOIDID);
808 >                sprintf(buf, "ray hit %s %s \"%s\"", matspec,
809                                  ofun[thisray.ro->otype].funame,
810                                  thisray.ro->oname);
811 +                if ((ino = objptr(thisray.robj)) != thisray.ro)
812 +                        sprintf(buf+strlen(buf), " in %s \"%s\"",
813 +                                        ofun[ino->otype].funame, ino->oname);
814                  (*dev->comout)(buf);
815 <                (*dev->comin)(buf);
815 >                (*dev->comin)(buf, NULL);
816                  if (thisray.rot >= FHUGE)
817                          (*dev->comout)("at infinity");
818                  else {
819 <                        sprintf(buf, "at (%.6g %.6g %.6g)", thisray.rop[0],
820 <                                        thisray.rop[1], thisray.rop[2]);
819 >                        sprintf(buf, "at (%.6g %.6g %.6g) (%.6g)",
820 >                                        thisray.rop[0], thisray.rop[1],
821 >                                        thisray.rop[2], thisray.rt);
822                          (*dev->comout)(buf);
823                  }
824 <                (*dev->comin)(buf);
825 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
824 >                (*dev->comin)(buf, NULL);
825 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.3gL)",
826                                  colval(thisray.rcol,RED),
827                                  colval(thisray.rcol,GRN),
828 <                                colval(thisray.rcol,BLU));
828 >                                colval(thisray.rcol,BLU),
829 >                                luminance(thisray.rcol));
830                  (*dev->comout)(buf);
831          }
832 <        (*dev->comin)(buf);
832 >        (*dev->comin)(buf, NULL);
833   }
834  
835  
836 < writepict(s)                            /* write the picture to a file */
837 < char  *s;
836 > void
837 > writepict(                              /* write the picture to a file */
838 >        char  *s
839 > )
840   {
841          static char  buf[128];
842 <        char  *fname, *getpath();
842 >        char  *fname;
843          FILE  *fp;
844          COLR  *scanline;
845          int  y;
846 <
847 <        if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') {
846 >                                /* XXX relies on words.c 2.11 behavior */
847 >        if (nextword(buf, sizeof(buf), s) == NULL && !buf[0]) {
848                  error(COMMAND, "no file");
849                  return;
850          }
851 <        if ((fname = getpath(buf, NULL)) == NULL ||
851 >        if ((fname = getpath(buf, NULL, 0)) == NULL ||
852                          (fp = fopen(fname, "w")) == NULL) {
853                  sprintf(errmsg, "cannot open \"%s\"", buf);
854                  error(COMMAND, errmsg);
855                  return;
856          }
857 +        SET_FILE_BINARY(fp);
858          (*dev->comout)("writing \"");
859          (*dev->comout)(fname);
860          (*dev->comout)("\"...\n");
861                                                  /* write header */
862 +        newheader("RADIANCE", fp);
863          fputs(progname, fp);
864          fprintview(&ourview, fp);
865 <        fputs("\n", fp);
865 >        if (octname != NULL)
866 >                fprintf(fp, " %s\n", octname);
867 >        else
868 >                putc('\n', fp);
869 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
870 >        fputnow(fp);
871          if (exposure != 1.0)
872 <                fprintf(fp, "EXPOSURE=%e\n", exposure);
873 <        fprintf(fp, "\n-Y %d +X %d\n", ourview.vresolu, ourview.hresolu);
872 >                fputexpos(exposure, fp);
873 >        if (dev->pixaspect != 1.0)
874 >                fputaspect(dev->pixaspect, fp);
875 >        fputformat(COLRFMT, fp);
876 >        putc('\n', fp);
877 >        fprtresolu(hresolu, vresolu, fp);
878  
879 <        scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
880 <        if (scanline == NULL)
881 <                error(SYSTEM, "out of memory in writepict");
882 <        for (y = ourview.vresolu-1; y >= 0; y--) {
883 <                getpictcolrs(y, scanline, &ptrunk,
884 <                                ourview.hresolu, ourview.vresolu);
885 <                if (fwritecolrs(scanline, ourview.hresolu, fp) < 0)
879 >        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
880 >        if (scanline == NULL) {
881 >                error(COMMAND, "not enough memory!");
882 >                fclose(fp);
883 >                unlink(fname);
884 >                return;
885 >        }
886 >        for (y = vresolu-1; y >= 0; y--) {
887 >                getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
888 >                if (fwritecolrs(scanline, hresolu, fp) < 0)
889                          break;
890          }
891 +        free((void *)scanline);
892          if (fclose(fp) < 0)
893                  error(COMMAND, "write error");
681        free((char *)scanline);
894   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines