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

Comparing ray/src/px/pinterp.c (file contents):
Revision 1.8 by greg, Wed Jan 3 09:37:16 1990 UTC vs.
Revision 1.10 by greg, Wed Jan 3 15:33:44 1990 UTC

# Line 32 | Line 32 | VIEW   theirview = STDVIEW(512);       /* input view */
32   int     gotview;                        /* got input view? */
33  
34   double  theirs2ours[4][4];              /* transformation matrix */
35 + int     regdist = 0;                    /* regular distance? */
36  
37  
38   main(argc, argv)                        /* interpolate pictures */
# Line 51 | Line 52 | char   *argv[];
52                          check(2,1);
53                          zeps = atof(argv[++i]);
54                          break;
55 +                case 'r':                               /* regular distance */
56 +                        check(2,0);
57 +                        regdist = !regdist;
58 +                        break;
59                  case 'x':                               /* x resolution */
60                          check(2,1);
61                          ourview.hresolu = atoi(argv[++i]);
# Line 109 | Line 114 | char   *argv[];
114                          break;
115                  default:
116                  badopt:
117 <                        fprintf(stderr, "%s: unknown option '%s'\n",
117 >                        fprintf(stderr, "%s: command line error at '%s'\n",
118                                          progname, argv[i]);
119 <                        exit(1);
119 >                        goto userr;
120                  }
121                                                  /* check arguments */
122 <        if (argc-i < 2 || (argc-i)%2) {
123 <                fprintf(stderr, "Usage: %s [view args] pfile zfile ..\n",
119 <                                progname);
120 <                exit(1);
121 <        }
122 >        if (argc-i < 2 || (argc-i)%2)
123 >                goto userr;
124                                                  /* set view */
125          if (err = setview(&ourview)) {
126                  fprintf(stderr, "%s: %s\n", progname, err);
# Line 148 | Line 150 | char   *argv[];
150          writepicture();
151  
152          exit(0);
153 + userr:
154 +        fprintf(stderr,
155 +        "Usage: %s [view opts][-t zthresh][-r] pfile zspec ..\n",
156 +                        progname);
157 +        exit(1);
158   #undef check
159   }
160  
# Line 169 | Line 176 | char   *s;
176   }
177  
178  
179 < addpicture(pfile, zfile)                /* add picture to output */
180 < char    *pfile, *zfile;
179 > addpicture(pfile, zspec)                /* add picture to output */
180 > char    *pfile, *zspec;
181   {
182 +        extern double   atof();
183          FILE    *pfp, *zfp;
184          char    *err;
185          COLR    *scanin;
186 <        float   *zin, *zout;
187 <        int     *pout;
180 <        int     xres, yres;
186 >        float   *zin, *zlast;
187 >        int     *plast;
188          int     y;
189 <                                        /* open input files */
189 >                                        /* open picture file */
190          if ((pfp = fopen(pfile, "r")) == NULL) {
191                  perror(pfile);
192                  exit(1);
193          }
187        if ((zfp = fopen(zfile, "r")) == NULL) {
188                perror(zfile);
189                exit(1);
190        }
194                                          /* get header and view */
195          printf("%s:\n", pfile);
196          gotview = 0;
197          getheader(pfp, headline);
198 <        if (!gotview || fgetresolu(&xres, &yres, pfp) != (YMAJOR|YDECR)) {
198 >        if (!gotview || fgetresolu(&theirview.hresolu, &theirview.vresolu, pfp)
199 >                        != (YMAJOR|YDECR)) {
200                  fprintf(stderr, "%s: picture view error\n", pfile);
201                  exit(1);
202          }
199        theirview.hresolu = xres;
200        theirview.vresolu = yres;
203          if (err = setview(&theirview)) {
204                  fprintf(stderr, "%s: %s\n", pfile, err);
205                  exit(1);
# Line 205 | Line 207 | char   *pfile, *zfile;
207                                          /* compute transformation */
208          pixform(theirs2ours, &theirview, &ourview);
209                                          /* allocate scanlines */
210 <        scanin = (COLR *)malloc(xres*sizeof(COLR));
211 <        zin = (float *)malloc(xres*sizeof(float));
212 <        zout = (float *)calloc(xres, sizeof(float));
213 <        pout = (int *)calloc(xres, sizeof(int));
214 <        if (scanin == NULL || zin == NULL || zout == NULL || pout == NULL) {
210 >        scanin = (COLR *)malloc(theirview.hresolu*sizeof(COLR));
211 >        zin = (float *)malloc(theirview.hresolu*sizeof(float));
212 >        plast = (int *)calloc(theirview.hresolu, sizeof(int));
213 >        zlast = (float *)calloc(theirview.hresolu, sizeof(float));
214 >        if (scanin == NULL || zin == NULL || plast == NULL || zlast == NULL) {
215                  perror(progname);
216                  exit(1);
217          }
218 +                                        /* get z specification or file */
219 +        if ((zfp = fopen(zspec, "r")) == NULL) {
220 +                double  zvalue;
221 +                register int    x;
222 +                if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) {
223 +                        perror(zspec);
224 +                        exit(1);
225 +                }
226 +                for (x = 0; x < theirview.hresolu; x++)
227 +                        zin[x] = zvalue;
228 +        }
229                                          /* load image */
230 <        for (y = yres-1; y >= 0; y--) {
231 <                if (freadcolrs(scanin, xres, pfp) < 0) {
230 >        for (y = theirview.vresolu-1; y >= 0; y--) {
231 >                if (freadcolrs(scanin, theirview.hresolu, pfp) < 0) {
232                          fprintf(stderr, "%s: read error\n", pfile);
233                          exit(1);
234                  }
235 <                if (fread(zin, sizeof(float), xres, zfp) < xres) {
236 <                        fprintf(stderr, "%s: read error\n", zfile);
235 >                if (zfp != NULL
236 >                        && fread(zin,sizeof(float),theirview.hresolu,zfp)
237 >                                < theirview.hresolu) {
238 >                        fprintf(stderr, "%s: read error\n", zspec);
239                          exit(1);
240                  }
241 <                addscanline(y, scanin, zin, pout, zout);
241 >                addscanline(y, scanin, zin, plast, zlast);
242          }
243                                          /* clean up */
244          free((char *)scanin);
245          free((char *)zin);
246 <        free((char *)pout);
247 <        free((char *)zout);
246 >        free((char *)plast);
247 >        free((char *)zlast);
248          fclose(pfp);
249 <        fclose(zfp);
249 >        if (zfp != NULL)
250 >                fclose(zfp);
251   }
252  
253  
# Line 275 | Line 291 | addscanline(y, pline, zline, lasty, lastyz)    /* add sca
291   int     y;
292   COLR    *pline;
293   float   *zline;
294 < int     *lasty;
295 < float   *lastyz;
294 > int     *lasty;                 /* input/output */
295 > float   *lastyz;                /* input/output */
296   {
297          extern double   sqrt(), fabs();
298          double  pos[3];
# Line 291 | Line 307 | float  *lastyz;
307                  pos[1] = y - .5*(theirview.vresolu-1);
308                  pos[2] = zline[x];
309                  if (theirview.type == VT_PER) {
310 <                        /*
311 <                         * The following (single) statement can go
296 <                         * if z is along the view direction rather
297 <                         * than an eye ray.
298 <                         */
299 <                        pos[2] /= sqrt( 1.
310 >                        if (!regdist)   /* adjust for eye-ray distance */
311 >                                pos[2] /= sqrt( 1.
312                                          + pos[0]*pos[0]*theirview.vhn2
313                                          + pos[1]*pos[1]*theirview.vvn2 );
314                          pos[0] *= pos[2];
# Line 439 | Line 451 | writepicture()                         /* write out picture */
451                          perror(progname);
452                          exit(1);
453                  }
454 + }
455 +
456 +
457 + isfloat(s)                              /* see if string is floating number */
458 + register char   *s;
459 + {
460 +        for ( ; *s; s++)
461 +                if ((*s < '0' || *s > '9') && *s != '.' && *s != '-'
462 +                                && *s != 'e' && *s != 'E' && *s != '+')
463 +                        return(0);
464 +        return(1);
465   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines