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

Comparing ray/src/px/pvalue.c (file contents):
Revision 2.11 by greg, Wed Jan 8 08:00:23 1997 UTC vs.
Revision 2.13 by gwlarson, Tue Oct 27 09:08:27 1998 UTC

# Line 43 | Line 43 | int  header = 1;               /* do header? */
43  
44   long  skipbytes = 0;            /* skip bytes in input? */
45  
46 + int  interleave = 1;            /* file is interleaved? */
47 +
48   int  resolution = 1;            /* put/get resolution string? */
49  
50   int  original = 0;              /* convert to original values? */
# Line 119 | Line 121 | char  **argv;
121                          case 'r':               /* reverse conversion */
122                                  reverse = argv[i][0] == '-';
123                                  break;
124 +                        case 'n':               /* non-interleaved RGB */
125 +                                interleave = argv[i][0] == '+';
126 +                                break;
127                          case 'b':               /* brightness values */
128                                  putprim = argv[i][0] == '-' ? BRIGHT : ALL;
129                                  break;
# Line 205 | Line 210 | unkopt:
210                                                  progname, argv[i]);
211                          quit(1);
212                  }
208                if (skipbytes && fseek(fin, skipbytes, 0))
209                        goto seekerr;
213                  if (reverse && !brightonly && i == argc-3) {
214                          if ((fin2 = fopen(argv[i+1], "r")) == NULL) {
215                                  fprintf(stderr, "%s: can't open file \"%s\"\n",
# Line 218 | Line 221 | unkopt:
221                                                  progname, argv[i+2]);
222                                  quit(1);
223                          }
224 <                        if (skipbytes && (fseek(fin2, skipbytes, 0) ||
222 <                                        fseek(fin3, skipbytes, 0)))
223 <                                goto seekerr;
224 >                        interleave = -1;
225                  } else if (i != argc-1)
226                          fin = NULL;
227 +                if (reverse && !brightonly && !interleave) {
228 +                        fin2 = fopen(argv[i], "r");
229 +                        fin3 = fopen(argv[i], "r");
230 +                }
231 +                if (skipbytes && (fseek(fin, skipbytes, 0) || (fin2 != NULL &&
232 +                                (fseek(fin2, skipbytes, 0) ||
233 +                                fseek(fin3, skipbytes, 0))))) {
234 +                        fprintf(stderr, "%s: cannot skip %ld bytes on input\n",
235 +                                        progname, skipbytes);
236 +                        quit(1);
237 +                }
238          }
239          if (fin == NULL) {
240                  fprintf(stderr, "%s: bad # file arguments\n", progname);
241                  quit(1);
242          }
243  
232        set_io();
233
244          if (reverse) {
245   #ifdef MSDOS
246                  setmode(fileno(stdout), O_BINARY);
# Line 309 | Line 319 | unkopt:
319          }
320  
321          quit(0);
312 seekerr:
313        fprintf(stderr, "%s: cannot skip %ld bytes on input\n",
314                        progname, skipbytes);
315        quit(1);
322   }
323  
324  
325 + int
326   checkhead(line)                         /* deal with line from header */
327   char  *line;
328   {
# Line 337 | Line 344 | char  *line;
344                  doexposure++;
345          } else if (header)
346                  fputs(line, stdout);
347 +        return(0);
348   }
349  
350  
# Line 346 | Line 354 | pixtoval()                             /* convert picture to values */
354          int  dogamma;
355          COLOR  lastc;
356          FLOAT  hv[2];
357 +        int  startprim, endprim;
358 +        long  startpos;
359          int  y;
360          register int  x;
361  
# Line 355 | Line 365 | pixtoval()                             /* convert picture to values */
365                  quit(1);
366          }
367          dogamma = gamcor < .95 || gamcor > 1.05;
368 <        setcolor(lastc, 0.0, 0.0, 0.0);
369 <        for (y = 0; y < numscans(&picres); y++) {
370 <                if (freadscan(scanln, scanlen(&picres), fin) < 0) {
371 <                        fprintf(stderr, "%s: read error\n", progname);
368 >        if (putprim == ALL && !interleave) {
369 >                startprim = RED; endprim = BLU;
370 >                startpos = ftell(fin);
371 >        } else {
372 >                startprim = putprim; endprim = putprim;
373 >        }
374 >        for (putprim = startprim; putprim <= endprim; putprim++) {
375 >                if (putprim != startprim && fseek(fin, startpos, 0)) {
376 >                        fprintf(stderr, "%s: seek error on input file\n",
377 >                                        progname);
378                          quit(1);
379                  }
380 <                for (x = 0; x < scanlen(&picres); x++) {
381 <                        if (uniq)
382 <                                if (    colval(scanln[x],RED) ==
383 <                                                colval(lastc,RED) &&
384 <                                        colval(scanln[x],GRN) ==
369 <                                                colval(lastc,GRN) &&
370 <                                        colval(scanln[x],BLU) ==
371 <                                                colval(lastc,BLU)       )
372 <                                        continue;
373 <                                else
374 <                                        copycolor(lastc, scanln[x]);
375 <                        if (doexposure)
376 <                                multcolor(scanln[x], exposure);
377 <                        if (dogamma)
378 <                                setcolor(scanln[x],
379 <                                pow(colval(scanln[x],RED), 1.0/gamcor),
380 <                                pow(colval(scanln[x],GRN), 1.0/gamcor),
381 <                                pow(colval(scanln[x],BLU), 1.0/gamcor));
382 <                        if (!dataonly) {
383 <                                pix2loc(hv, &picres, x, y);
384 <                                printf("%7d %7d ", (int)(hv[0]*picres.xr),
385 <                                                (int)(hv[1]*picres.yr));
386 <                        }
387 <                        if ((*putval)(scanln[x]) < 0) {
388 <                                fprintf(stderr, "%s: write error\n", progname);
380 >                set_io();
381 >                setcolor(lastc, 0.0, 0.0, 0.0);
382 >                for (y = 0; y < numscans(&picres); y++) {
383 >                        if (freadscan(scanln, scanlen(&picres), fin) < 0) {
384 >                                fprintf(stderr, "%s: read error\n", progname);
385                                  quit(1);
386                          }
387 +                        for (x = 0; x < scanlen(&picres); x++) {
388 +                                if (uniq)
389 +                                        if (    colval(scanln[x],RED) ==
390 +                                                        colval(lastc,RED) &&
391 +                                                colval(scanln[x],GRN) ==
392 +                                                        colval(lastc,GRN) &&
393 +                                                colval(scanln[x],BLU) ==
394 +                                                        colval(lastc,BLU)       )
395 +                                                continue;
396 +                                        else
397 +                                                copycolor(lastc, scanln[x]);
398 +                                if (doexposure)
399 +                                        multcolor(scanln[x], exposure);
400 +                                if (dogamma)
401 +                                        setcolor(scanln[x],
402 +                                        pow(colval(scanln[x],RED), 1.0/gamcor),
403 +                                        pow(colval(scanln[x],GRN), 1.0/gamcor),
404 +                                        pow(colval(scanln[x],BLU), 1.0/gamcor));
405 +                                if (!dataonly) {
406 +                                        pix2loc(hv, &picres, x, y);
407 +                                        printf("%7d %7d ",
408 +                                                        (int)(hv[0]*picres.xr),
409 +                                                        (int)(hv[1]*picres.yr));
410 +                                }
411 +                                if ((*putval)(scanln[x]) < 0) {
412 +                                        fprintf(stderr, "%s: write error\n",
413 +                                                        progname);
414 +                                        quit(1);
415 +                                }
416 +                        }
417                  }
418          }
419          free((char *)scanln);
# Line 407 | Line 433 | valtopix()                     /* convert values to a pixel file */
433                  quit(1);
434          }
435          dogamma = gamcor < .95 || gamcor > 1.05;
436 +        set_io();
437          for (y = 0; y < numscans(&picres); y++) {
438                  for (x = 0; x < scanlen(&picres); x++) {
439                          if (!dataonly) {
# Line 800 | Line 827 | set_io()                       /* set put and get functions */
827                  } else {
828                          getval = getcascii;
829                          putval = putcascii;
830 +                        if (reverse && !interleave) {
831 +                                fprintf(stderr,
832 +                                "%s: ASCII input files must be interleaved\n",
833 +                                                progname);
834 +                                quit(1);
835 +                        }
836                  }
837                  return;
838          case 'f':                                       /* binary float */
# Line 812 | Line 845 | set_io()                       /* set put and get functions */
845                  } else {
846                          getval = getcfloat;
847                          putval = putcfloat;
848 +                        if (reverse && !interleave) {
849 +                                if (fin2 == NULL)
850 +                                        goto namerr;
851 +                                if (fseek(fin2,
852 +                                (long)sizeof(float)*picres.xr*picres.yr, 1))
853 +                                        goto seekerr;
854 +                                if (fseek(fin3,
855 +                                (long)sizeof(float)*2*picres.xr*picres.yr, 1))
856 +                                        goto seekerr;
857 +                        }
858                  }
859                  return;
860          case 'd':                                       /* binary double */
# Line 824 | Line 867 | set_io()                       /* set put and get functions */
867                  } else {
868                          getval = getcdouble;
869                          putval = putcdouble;
870 +                        if (reverse && !interleave) {
871 +                                if (fin2 == NULL)
872 +                                        goto namerr;
873 +                                if (fseek(fin2,
874 +                                (long)sizeof(double)*picres.xr*picres.yr, 1))
875 +                                        goto seekerr;
876 +                                if (fseek(fin3,
877 +                                (long)sizeof(double)*2*picres.xr*picres.yr, 1))
878 +                                        goto seekerr;
879 +                        }
880                  }
881                  return;
882          case 'i':                                       /* integer */
# Line 836 | Line 889 | set_io()                       /* set put and get functions */
889                  } else {
890                          getval = getcint;
891                          putval = putcint;
892 +                        if (reverse && !interleave) {
893 +                                fprintf(stderr,
894 +                                "%s: integer input files must be interleaved\n",
895 +                                                progname);
896 +                                quit(1);
897 +                        }
898                  }
899                  return;
900          case 'b':                                       /* byte */
# Line 848 | Line 907 | set_io()                       /* set put and get functions */
907                  } else {
908                          getval = getcbyte;
909                          putval = putcbyte;
910 +                        if (reverse && !interleave) {
911 +                                if (fin2 == NULL)
912 +                                        goto namerr;
913 +                                if (fseek(fin2,
914 +                                (long)sizeof(BYTE)*picres.xr*picres.yr, 1))
915 +                                        goto seekerr;
916 +                                if (fseek(fin3,
917 +                                (long)sizeof(BYTE)*2*picres.xr*picres.yr, 1))
918 +                                        goto seekerr;
919 +                        }
920                  }
921                  return;
922          }
923 + badopt:
924 +        fprintf(stderr, "%s: botched file type\n", progname);
925 +        quit(1);
926 + namerr:
927 +        fprintf(stderr, "%s: non-interleaved file(s) must be named\n",
928 +                        progname);
929 +        quit(1);
930 + seekerr:
931 +        fprintf(stderr, "%s: cannot seek on interleaved input file\n",
932 +                        progname);
933 +        quit(1);
934   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines