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.12 by greg, Wed Jan 8 08:51:43 1997 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  
# Line 346 | Line 352 | pixtoval()                             /* convert picture to values */
352          int  dogamma;
353          COLOR  lastc;
354          FLOAT  hv[2];
355 +        int  startprim, endprim;
356 +        long  startpos;
357          int  y;
358          register int  x;
359  
# Line 355 | Line 363 | pixtoval()                             /* convert picture to values */
363                  quit(1);
364          }
365          dogamma = gamcor < .95 || gamcor > 1.05;
366 <        setcolor(lastc, 0.0, 0.0, 0.0);
367 <        for (y = 0; y < numscans(&picres); y++) {
368 <                if (freadscan(scanln, scanlen(&picres), fin) < 0) {
369 <                        fprintf(stderr, "%s: read error\n", progname);
366 >        if (putprim == ALL && !interleave) {
367 >                startprim = RED; endprim = BLU;
368 >                startpos = ftell(fin);
369 >        } else {
370 >                startprim = putprim; endprim = putprim;
371 >        }
372 >        for (putprim = startprim; putprim <= endprim; putprim++) {
373 >                if (putprim != startprim && fseek(fin, startpos, 0)) {
374 >                        fprintf(stderr, "%s: seek error on input file\n",
375 >                                        progname);
376                          quit(1);
377                  }
378 <                for (x = 0; x < scanlen(&picres); x++) {
379 <                        if (uniq)
380 <                                if (    colval(scanln[x],RED) ==
381 <                                                colval(lastc,RED) &&
382 <                                        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);
378 >                set_io();
379 >                setcolor(lastc, 0.0, 0.0, 0.0);
380 >                for (y = 0; y < numscans(&picres); y++) {
381 >                        if (freadscan(scanln, scanlen(&picres), fin) < 0) {
382 >                                fprintf(stderr, "%s: read error\n", progname);
383                                  quit(1);
384                          }
385 +                        for (x = 0; x < scanlen(&picres); x++) {
386 +                                if (uniq)
387 +                                        if (    colval(scanln[x],RED) ==
388 +                                                        colval(lastc,RED) &&
389 +                                                colval(scanln[x],GRN) ==
390 +                                                        colval(lastc,GRN) &&
391 +                                                colval(scanln[x],BLU) ==
392 +                                                        colval(lastc,BLU)       )
393 +                                                continue;
394 +                                        else
395 +                                                copycolor(lastc, scanln[x]);
396 +                                if (doexposure)
397 +                                        multcolor(scanln[x], exposure);
398 +                                if (dogamma)
399 +                                        setcolor(scanln[x],
400 +                                        pow(colval(scanln[x],RED), 1.0/gamcor),
401 +                                        pow(colval(scanln[x],GRN), 1.0/gamcor),
402 +                                        pow(colval(scanln[x],BLU), 1.0/gamcor));
403 +                                if (!dataonly) {
404 +                                        pix2loc(hv, &picres, x, y);
405 +                                        printf("%7d %7d ",
406 +                                                        (int)(hv[0]*picres.xr),
407 +                                                        (int)(hv[1]*picres.yr));
408 +                                }
409 +                                if ((*putval)(scanln[x]) < 0) {
410 +                                        fprintf(stderr, "%s: write error\n",
411 +                                                        progname);
412 +                                        quit(1);
413 +                                }
414 +                        }
415                  }
416          }
417          free((char *)scanln);
# Line 407 | Line 431 | valtopix()                     /* convert values to a pixel file */
431                  quit(1);
432          }
433          dogamma = gamcor < .95 || gamcor > 1.05;
434 +        set_io();
435          for (y = 0; y < numscans(&picres); y++) {
436                  for (x = 0; x < scanlen(&picres); x++) {
437                          if (!dataonly) {
# Line 800 | Line 825 | set_io()                       /* set put and get functions */
825                  } else {
826                          getval = getcascii;
827                          putval = putcascii;
828 +                        if (reverse && !interleave) {
829 +                                fprintf(stderr,
830 +                                "%s: ASCII input files must be interleaved\n",
831 +                                                progname);
832 +                                quit(1);
833 +                        }
834                  }
835                  return;
836          case 'f':                                       /* binary float */
# Line 812 | Line 843 | set_io()                       /* set put and get functions */
843                  } else {
844                          getval = getcfloat;
845                          putval = putcfloat;
846 +                        if (reverse && !interleave) {
847 +                                if (fin2 == NULL)
848 +                                        goto namerr;
849 +                                if (fseek(fin2,
850 +                                (long)sizeof(float)*picres.xr*picres.yr, 1))
851 +                                        goto seekerr;
852 +                                if (fseek(fin3,
853 +                                (long)sizeof(float)*2*picres.xr*picres.yr, 1))
854 +                                        goto seekerr;
855 +                        }
856                  }
857                  return;
858          case 'd':                                       /* binary double */
# Line 824 | Line 865 | set_io()                       /* set put and get functions */
865                  } else {
866                          getval = getcdouble;
867                          putval = putcdouble;
868 +                        if (reverse && !interleave) {
869 +                                if (fin2 == NULL)
870 +                                        goto namerr;
871 +                                if (fseek(fin2,
872 +                                (long)sizeof(double)*picres.xr*picres.yr, 1))
873 +                                        goto seekerr;
874 +                                if (fseek(fin3,
875 +                                (long)sizeof(double)*2*picres.xr*picres.yr, 1))
876 +                                        goto seekerr;
877 +                        }
878                  }
879                  return;
880          case 'i':                                       /* integer */
# Line 836 | Line 887 | set_io()                       /* set put and get functions */
887                  } else {
888                          getval = getcint;
889                          putval = putcint;
890 +                        if (reverse && !interleave) {
891 +                                fprintf(stderr,
892 +                                "%s: integer input files must be interleaved\n",
893 +                                                progname);
894 +                                quit(1);
895 +                        }
896                  }
897                  return;
898          case 'b':                                       /* byte */
# Line 848 | Line 905 | set_io()                       /* set put and get functions */
905                  } else {
906                          getval = getcbyte;
907                          putval = putcbyte;
908 +                        if (reverse && !interleave) {
909 +                                if (fin2 == NULL)
910 +                                        goto namerr;
911 +                                if (fseek(fin2,
912 +                                (long)sizeof(BYTE)*picres.xr*picres.yr, 1))
913 +                                        goto seekerr;
914 +                                if (fseek(fin3,
915 +                                (long)sizeof(BYTE)*2*picres.xr*picres.yr, 1))
916 +                                        goto seekerr;
917 +                        }
918                  }
919                  return;
920          }
921 + badopt:
922 +        fprintf(stderr, "%s: botched file type\n", progname);
923 +        quit(1);
924 + namerr:
925 +        fprintf(stderr, "%s: non-interleaved file(s) must be named\n",
926 +                        progname);
927 +        quit(1);
928 + seekerr:
929 +        fprintf(stderr, "%s: cannot seek on interleaved input file\n",
930 +                        progname);
931 +        quit(1);
932   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines