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

Comparing ray/src/hd/rhpict.c (file contents):
Revision 3.4 by gwlarson, Tue Mar 9 10:55:24 1999 UTC vs.
Revision 3.18 by greg, Tue Jun 8 19:48:30 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1999 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Radiance holodeck picture generator
6   */
7  
8 + #include <string.h>
9 +
10 + #include "platform.h"
11 + #include "rterror.h"
12   #include "rholo.h"
12 #include "view.h"
13 #include "resolu.h"
13  
14   char    *progname;              /* our program name */
15   char    *hdkfile;               /* holodeck file name */
16 + char    gargc;                  /* global argc */
17 + char    **gargv;                /* global argv */
18  
19   VIEW    myview = STDVIEW;       /* current output view */
20   int     xres = 512, yres = 512; /* max. horizontal and vertical resolution */
21   char    *outspec = NULL;        /* output file specification */
22 + double  randfrac = -1.;         /* random resampling fraction */
23   double  pixaspect = 1.;         /* pixel aspect ratio */
24   int     seqstart = 0;           /* sequence start frame */
25   double  expval = 1.;            /* exposure value */
# Line 29 | Line 31 | int    hres, vres;             /* current horizontal and vertical re
31  
32   extern int      nowarn;         /* turn warnings off? */
33  
34 + static void dopicture(int fn);
35 + static void render_frame(PACKHEAD *bl, int nb);
36 + static void startpicture(int fn);
37 + static int endpicture(void);
38 + static void initialize(void);
39 + /* from rhpict2.c */
40 + extern void pixFinish(double ransamp);
41 + extern void pixBeam(BEAM *bp, HDBEAMI *hb);
42  
43 < main(argc, argv)
44 < int     argc;
45 < char    *argv[];
43 >
44 > int
45 > main(
46 > int     argc,
47 > char    *argv[]
48 > )
49   {
50          int     i, rval;
51  
52 +        gargc = argc; gargv = argv;
53          progname = argv[0];                     /* get arguments */
54          for (i = 1; i < argc && argv[i][0] == '-'; i++) {
55                  rval = getviewopt(&myview, argc-i, argv+i);
# Line 54 | Line 68 | char   *argv[];
68                                  pixaspect = atof(argv[++i]);
69                          else if (argv[i][2] == 'e') {
70                                  expval = atof(argv[++i]);
71 <                                if (argv[i][0] == '-' | argv[i][0] == '+')
71 >                                if ((argv[i][0] == '-') | (argv[i][0] == '+'))
72                                          expval = pow(2., expval);
73                          } else
74                                  goto userr;
# Line 74 | Line 88 | char   *argv[];
88                                  goto userr;
89                          outspec = argv[++i];
90                          break;
91 +                case 'r':                       /* random sampling */
92 +                        if (badarg(argc-i-1,argv+i+1,"f"))
93 +                                goto userr;
94 +                        randfrac = atof(argv[++i]);
95 +                        break;
96 +                case 's':                       /* smooth sampling */
97 +                        randfrac = -1.;
98 +                        break;
99                  case 'S':                       /* sequence start */
100                          if (badarg(argc-i-1,argv+i+1,"i"))
101                                  goto userr;
# Line 111 | Line 133 | char   *argv[];
133          quit(0);                                /* all done! */
134   userr:
135          fprintf(stderr,
136 < "Usage: %s [-w][-pa pa][-pe ex][-x hr][-y vr][-S stfn][-o outp][view] input.hdk\n",
136 > "Usage: %s [-w][-r rf][-pa pa][-pe ex][-x hr][-y vr][-S stfn][-o outp][view] input.hdk\n",
137                          progname);
138          quit(1);
139 +        return 1;  /* pro forma return */
140   }
141  
142  
143 < dopicture(fn)                   /* render view from holodeck */
144 < int     fn;
143 > static void
144 > dopicture(                      /* render view from holodeck */
145 >        int     fn
146 > )
147   {
148          char    *err;
149          int     rval;
# Line 135 | Line 160 | int    fn;
160                                          /* render image */
161          if (blist.nb > 0) {
162                  render_frame(blist.bl, blist.nb);
163 <                free((char *)blist.bl);
163 >                free((void *)blist.bl);
164          } else {
165                  sprintf(errmsg, "no section visible in frame %d", fn);
166                  error(WARNING, errmsg);
# Line 155 | Line 180 | int    fn;
180   }
181  
182  
183 < render_frame(bl, nb)            /* render frame from beam values */
184 < register PACKHEAD       *bl;
185 < int     nb;
183 > static void
184 > render_frame(           /* render frame from beam values */
185 >        register PACKHEAD       *bl,
186 >        int     nb
187 > )
188   {
162        extern int      pixBeam();
189          register HDBEAMI        *bil;
190          register int    i;
191  
# Line 171 | Line 197 | int    nb;
197                  bil[i].b = bl[i].bi;
198          }
199          hdloadbeams(bil, nb, pixBeam);
200 <        pixFlush();
201 <        free((char *)bil);
200 >        pixFinish(randfrac);
201 >        free((void *)bil);
202   }
203  
204  
205 < startpicture(fn)                /* initialize picture for rendering & output */
206 < int     fn;
205 > static void
206 > startpicture(           /* initialize picture for rendering & output */
207 >        int     fn
208 > )
209   {
210          extern char     VersionID[];
211          double  pa = pixaspect;
# Line 196 | Line 224 | int    fn;
224                                  /* write header */
225          newheader("RADIANCE", stdout);
226          printf("SOFTWARE= %s\n", VersionID);
227 <        printf("%s %s\n", progname, hdkfile);
227 >        printargs(gargc, gargv, stdout);
228          if (fn)
229                  printf("FRAME=%d\n", fn);
230          fputs(VIEWSTR, stdout);
231          fprintview(&myview, stdout);
232          fputc('\n', stdout);
233 <        if (pa < 0.99 | pa > 1.01)
233 >        if ((pa < 0.99) | (pa > 1.01))
234                  fputaspect(pa, stdout);
235 <        if (expval < 0.99 | expval > 1.01)
235 >        if ((expval < 0.99) | (expval > 1.01))
236                  fputexpos(expval, stdout);
237          fputformat(COLRFMT, stdout);
238          fputc('\n', stdout);
239                                  /* write resolution (standard order) */
240          fprtresolu(hres, vres, stdout);
241                                  /* prepare image buffers */
242 <        bzero((char *)mypixel, hres*vres*sizeof(COLOR));
243 <        bzero((char *)myweight, hres*vres*sizeof(float));
244 <        bzero((char *)mydepth, hres*vres*sizeof(float));
242 >        memset((char *)mypixel, '\0', hres*vres*sizeof(COLOR));
243 >        memset((char *)myweight, '\0', hres*vres*sizeof(float));
244 >        memset((char *)mydepth, '\0', hres*vres*sizeof(float));
245   }
246  
247  
248 < int
249 < endpicture()                    /* finish and write out pixels */
248 > static int
249 > endpicture(void)                        /* finish and write out pixels */
250   {
251          int     lastr = -1, nunrend = 0;
252 <        int4    lastp, lastrp;
253 <        register int4   p;
252 >        int32   lastp, lastrp;
253 >        register int32  p;
254          register double d;
255                                  /* compute final pixel values */
256          for (p = hres*vres; p--; ) {
257                  if (myweight[p] <= FTINY) {
258 <                        if (lastr >= 0)
258 >                        if (lastr >= 0) {
259                                  if (p/hres == lastp/hres)
260                                          copycolor(mypixel[p], mypixel[lastp]);
261                                  else
262                                          copycolor(mypixel[p], mypixel[lastrp]);
263 +                        }
264                          nunrend++;
265                          continue;
266                  }
# Line 250 | Line 279 | endpicture()                   /* finish and write out pixels */
279   }
280  
281  
282 < initialize()                    /* initialize holodeck and buffers */
282 > static void
283 > initialize(void)                        /* initialize holodeck and buffers */
284   {
255        extern long     ftell();
285          int     fd;
286          FILE    *fp;
287          int     n;
288 <        int4    nextloc;
288 >        int32   nextloc;
289                                          /* open holodeck file */
290          if ((fp = fopen(hdkfile, "r")) == NULL) {
291                  sprintf(errmsg, "cannot open \"%s\" for reading", hdkfile);
# Line 274 | Line 303 | initialize()                   /* initialize holodeck and buffers */
303          fd = dup(fileno(fp));                   /* dup file descriptor */
304          fclose(fp);                             /* done with stdio */
305          for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
306 <                lseek(fd, (long)nextloc, 0);
306 >                lseek(fd, (off_t)nextloc, SEEK_SET);
307                  read(fd, (char *)&nextloc, sizeof(nextloc));
308                  hdinit(fd, NULL);
309          }
# Line 282 | Line 311 | initialize()                   /* initialize holodeck and buffers */
311          mypixel = (COLOR *)bmalloc(xres*yres*sizeof(COLOR));
312          myweight = (float *)bmalloc(xres*yres*sizeof(float));
313          mydepth = (float *)bmalloc(xres*yres*sizeof(float));
314 <        if (mypixel == NULL | myweight == NULL | mydepth == NULL)
314 >        if ((mypixel == NULL) | (myweight == NULL) | (mydepth == NULL))
315                  error(SYSTEM, "out of memory in initialize");
316   }
317  
318  
319 + void
320   eputs(s)                        /* put error message to stderr */
321   register char  *s;
322   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines