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

Comparing ray/src/px/ximage.c (file contents):
Revision 1.22 by greg, Thu Jan 18 23:58:26 1990 UTC vs.
Revision 2.7 by greg, Tue Sep 20 15:48:25 1994 UTC

# Line 23 | Line 23 | static char SCCSid[] = "$SunId$ LBL";
23  
24   #include  "color.h"
25  
26 + #include  "resolu.h"
27 +
28   #include  "xraster.h"
29  
30   #include  "view.h"
# Line 35 | Line 37 | static char SCCSid[] = "$SunId$ LBL";
37  
38   #define  FONTNAME       "9x15"          /* text font we'll use */
39  
40 < #define  CTRL(c)        ('c'-'@')
40 > #define  CTRL(c)        ((c)-'@')
41  
42   #define  BORWIDTH       5               /* border width */
43   #define  BARHEIGHT      25              /* menu bar size */
# Line 72 | Line 74 | int  cury = 0;                         /* current scan location */
74  
75   double  exposure = 1.0;                 /* exposure compensation used */
76  
77 + int  wrongformat = 0;                   /* input in another format */
78 +
79   struct {
80          int  xmin, ymin, xsiz, ysiz;
81   }  box = {0, 0, 0, 0};                  /* current box */
# Line 86 | Line 90 | extern long  ftell();
90  
91   extern char  *malloc(), *calloc();
92  
93 < extern double  atof(), pow(), log();
93 > extern double  pow(), log();
94  
95  
96   main(argc, argv)
97   int  argc;
98   char  *argv[];
99   {
100 +        extern char  *getenv();
101 +        char  *gv;
102          int  headline();
103          int  i;
104          
105          progname = argv[0];
106 +        if ((gv = getenv("DISPLAY_GAMMA")) != NULL)
107 +                gamcor = atof(gv);
108  
109          for (i = 1; i < argc; i++)
110                  if (argv[i][0] == '-')
# Line 141 | Line 149 | char  *argv[];
149                  }
150          }
151                                  /* get header */
152 <        getheader(fin, headline);
152 >        getheader(fin, headline, NULL);
153                                  /* get picture dimensions */
154 <        if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR))
154 >        if (wrongformat || fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR))
155                  quiterr("bad picture size");
156                                  /* set view parameters */
157          if (gotview && setview(&ourview) != NULL)
# Line 166 | Line 174 | userr:
174   headline(s)             /* get relevant info from header */
175   char  *s;
176   {
177 <        static char  *altname[] = {"rview","rpict",VIEWSTR,NULL};
170 <        register char  **an;
177 >        char  fmt[32];
178  
179          if (isexpos(s))
180                  exposure *= exposval(s);
181 <        else
182 <                for (an = altname; *an != NULL; an++)
183 <                        if (!strncmp(*an, s, strlen(*an))) {
184 <                                if (sscanview(&ourview, s+strlen(*an)) > 0)
185 <                                        gotview++;
179 <                                return;
180 <                        }
181 >        else if (isformat(s)) {
182 >                formatval(fmt, s);
183 >                wrongformat = strcmp(fmt, COLRFMT);
184 >        } else if (isview(s) && sscanview(&ourview, s) > 0)
185 >                gotview++;
186   }
187  
188  
# Line 287 | Line 292 | getras()                               /* get raster file */
292          }
293          return;
294   memerr:
295 <        quit("out of memory");
295 >        quiterr("out of memory");
296   }
297  
298  
# Line 359 | Line 364 | XKeyEvent  *ekey;
364                  return(0);
365          switch (*cp) {                  /* interpret command */
366          case 'q':
367 <        case CTRL(D):                           /* quit */
367 >        case CTRL('D'):                         /* quit */
368                  quit(0);
369          case '\n':
370          case '\r':
# Line 373 | Line 378 | XKeyEvent  *ekey;
378                          sprintf(buf, "%.3f", intens(cval)/exposure);
379                          break;
380                  case 'l':                               /* luminance */
381 <                        sprintf(buf, "%.0fn", bright(cval)*683.0/exposure);
381 >                        sprintf(buf, "%.0fL", luminance(cval)/exposure);
382                          break;
383                  case 'c':                               /* color */
384                          comp = pow(2.0, (double)scale);
# Line 407 | Line 412 | XKeyEvent  *ekey;
412                          XFeep(0);
413                          return(-1);
414                  }
415 <                viewray(rorg, rdir, &ourview, (ekey->x-xoff+.5)/xmax,
416 <                                (ymax-1-ekey->y+yoff+.5)/ymax);
415 >                if (viewray(rorg, rdir, &ourview, (ekey->x-xoff+.5)/xmax,
416 >                                (ymax-1-ekey->y+yoff+.5)/ymax) < 0)
417 >                        return(-1);
418                  printf("%e %e %e ", rorg[0], rorg[1], rorg[2]);
419                  printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]);
420                  fflush(stdout);
# Line 428 | Line 434 | XKeyEvent  *ekey;
434                  free_raster(ourras);
435                  getras();
436          /* fall through */
437 <        case CTRL(R):                           /* redraw */
438 <        case CTRL(L):
437 >        case CTRL('R'):                         /* redraw */
438 >        case CTRL('L'):
439                  unmap_rcolors(ourras);
440                  XClear(wind);
441                  return(redraw(0, 0, width, height));
# Line 541 | Line 547 | getmono()                      /* get monochrome data */
547   {
548          register unsigned short *dp;
549          register int    x, err;
550 <        int     y;
551 <        rgbpixel        *inline;
550 >        int     y, errp;
551 >        rgbpixel        *inl;
552          short   *cerr;
553  
554 <        if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL
554 >        if ((inl = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL
555                          || (cerr = (short *)calloc(xmax,sizeof(short))) == NULL)
556 <                quit("out of memory in getmono");
556 >                quiterr("out of memory in getmono");
557          dp = ourras->data.m - 1;
558          for (y = 0; y < ymax; y++) {
559 <                picreadline3(y, inline);
559 >                picreadline3(y, inl);
560                  err = 0;
561                  for (x = 0; x < xmax; x++) {
562                          if (!(x&0xf))
563                                  *++dp = 0;
564 <                        err += rgb_bright(&inline[x]) + cerr[x];
564 >                        errp = err;
565 >                        err += rgb_bright(&inl[x]) + cerr[x];
566                          if (err > 127)
567                                  err -= 255;
568                          else
569                                  *dp |= 1<<(x&0xf);
570 <                        cerr[x] = err >>= 1;
570 >                        err /= 3;
571 >                        cerr[x] = err + errp;
572                  }
573          }
574 <        free((char *)inline);
574 >        free((char *)inl);
575          free((char *)cerr);
576   }
577  
# Line 634 | Line 642 | int  y;
642                  if (scanpos == NULL || scanpos[y] == -1)
643                          return(-1);
644                  if (fseek(fin, scanpos[y], 0) == -1)
645 <                        quit("fseek error");
645 >                        quiterr("fseek error");
646                  cury = y;
647 <        } else if (scanpos != NULL)
647 >        } else if (scanpos != NULL && scanpos[y] == -1)
648                  scanpos[y] = ftell(fin);
649  
650          if (freadcolrs(scanline, xmax, fin) < 0)
# Line 656 | Line 664 | register rgbpixel  *l3;
664          if (getscan(y) < 0)
665                  quiterr("cannot seek for picreadline");
666                                                          /* convert scanline */
667 <        if (scale)
660 <                for (i = 0; i < xmax; i++)
661 <                        if (scanline[i][EXP])
662 <                                scanline[i][EXP] += scale;
663 <        normcolrs(scanline, xmax);
667 >        normcolrs(scanline, xmax, scale);
668          for (i = 0; i < xmax; i++) {
669                  l3[i].r = scanline[i][RED];
670                  l3[i].g = scanline[i][GRN];
# Line 684 | Line 688 | colormap  map;
688          register int  i, val;
689  
690          for (i = 0; i < 256; i++) {
691 <                val = pow(i/256.0, 1.0/gamcor) * 256.0;
691 >                val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0;
692                  map[0][i] = map[1][i] = map[2][i] = val;
693          }
694   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines