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.16 by greg, Wed Nov 29 17:42:27 1989 UTC vs.
Revision 2.8 by gwlarson, Tue Oct 27 09:08:28 1998 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 58 | Line 60 | int  scale = 0;                                /* scalefactor; power of two */
60   int  xoff = 0;                          /* x image offset */
61   int  yoff = 0;                          /* y image offset */
62  
63 < VIEW  ourview = STDVIEW(0);             /* image view parameters */
63 > VIEW  ourview = STDVIEW;                /* image view parameters */
64   int  gotview = 0;                       /* got parameters from file */
65  
66   COLR  *scanline;                        /* scan line buffer */
# 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) {
158 <                ourview.hresolu = xmax;
151 <                ourview.vresolu = ymax;
152 <                if (setview(&ourview) != NULL)
153 <                        gotview = 0;
154 <        }
157 >        if (gotview && setview(&ourview) != NULL)
158 >                gotview = 0;
159          if ((scanline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL)
160                  quiterr("out of memory");
161  
# Line 167 | Line 171 | userr:
171   }
172  
173  
174 + int
175   headline(s)             /* get relevant info from header */
176   char  *s;
177   {
178 <        static char  *altname[] = {"rview","rpict",VIEWSTR,NULL};
174 <        register char  **an;
178 >        char  fmt[32];
179  
180 <        if (!strncmp(s, "EXPOSURE=", 9))
181 <                exposure *= atof(s+9);
182 <        else
183 <                for (an = altname; *an != NULL; an++)
184 <                        if (!strncmp(*an, s, strlen(*an))) {
185 <                                if (sscanview(&ourview, s+strlen(*an)) == 0)
186 <                                        gotview++;
187 <                                return;
184 <                        }
180 >        if (isexpos(s))
181 >                exposure *= exposval(s);
182 >        else if (isformat(s)) {
183 >                formatval(fmt, s);
184 >                wrongformat = strcmp(fmt, COLRFMT);
185 >        } else if (isview(s) && sscanview(&ourview, s) > 0)
186 >                gotview++;
187 >        return(0);
188   }
189  
190  
188 char *
189 sskip(s)                /* skip a word */
190 register char  *s;
191 {
192        while (isspace(*s)) s++;
193        while (*s && !isspace(*s)) s++;
194        return(s);
195 }
196
197
191   init()                  /* get data and open window */
192   {
193          register int  i;
# Line 301 | Line 294 | getras()                               /* get raster file */
294          }
295          return;
296   memerr:
297 <        quit("out of memory");
297 >        quiterr("out of memory");
298   }
299  
300  
# Line 373 | Line 366 | XKeyEvent  *ekey;
366                  return(0);
367          switch (*cp) {                  /* interpret command */
368          case 'q':
369 <        case CTRL(D):                           /* quit */
369 >        case CTRL('D'):                         /* quit */
370                  quit(0);
371          case '\n':
372          case '\r':
# Line 384 | Line 377 | XKeyEvent  *ekey;
377                  switch (*cp) {
378                  case '\n':
379                  case '\r':                              /* radiance */
380 <                        sprintf(buf, "%-3g", intens(cval)/exposure);
380 >                        sprintf(buf, "%.3f", intens(cval)/exposure);
381                          break;
382                  case 'l':                               /* luminance */
383 <                        sprintf(buf, "%-3gn", bright(cval)*683.0/exposure);
383 >                        sprintf(buf, "%.0fL", luminance(cval)/exposure);
384                          break;
385                  case 'c':                               /* color */
386                          comp = pow(2.0, (double)scale);
# Line 421 | Line 414 | XKeyEvent  *ekey;
414                          XFeep(0);
415                          return(-1);
416                  }
417 <                rayview(rorg, rdir, &ourview,
418 <                                ekey->x-xoff + .5, ymax-1-ekey->y+yoff + .5);
417 >                if (viewray(rorg, rdir, &ourview, (ekey->x-xoff+.5)/xmax,
418 >                                (ymax-1-ekey->y+yoff+.5)/ymax) < 0)
419 >                        return(-1);
420                  printf("%e %e %e ", rorg[0], rorg[1], rorg[2]);
421                  printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]);
422                  fflush(stdout);
# Line 442 | Line 436 | XKeyEvent  *ekey;
436                  free_raster(ourras);
437                  getras();
438          /* fall through */
439 <        case CTRL(R):                           /* redraw */
440 <        case CTRL(L):
439 >        case CTRL('R'):                         /* redraw */
440 >        case CTRL('L'):
441                  unmap_rcolors(ourras);
442                  XClear(wind);
443                  return(redraw(0, 0, width, height));
# Line 555 | Line 549 | getmono()                      /* get monochrome data */
549   {
550          register unsigned short *dp;
551          register int    x, err;
552 <        int     y;
553 <        rgbpixel        *inline;
552 >        int     y, errp;
553 >        rgbpixel        *inl;
554          short   *cerr;
555  
556 <        if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL
556 >        if ((inl = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL
557                          || (cerr = (short *)calloc(xmax,sizeof(short))) == NULL)
558 <                quit("out of memory in getmono");
558 >                quiterr("out of memory in getmono");
559          dp = ourras->data.m - 1;
560          for (y = 0; y < ymax; y++) {
561 <                picreadline3(y, inline);
561 >                picreadline3(y, inl);
562                  err = 0;
563                  for (x = 0; x < xmax; x++) {
564                          if (!(x&0xf))
565                                  *++dp = 0;
566 <                        err += rgb_bright(&inline[x]) + cerr[x];
566 >                        errp = err;
567 >                        err += rgb_bright(&inl[x]) + cerr[x];
568                          if (err > 127)
569                                  err -= 255;
570                          else
571                                  *dp |= 1<<(x&0xf);
572 <                        cerr[x] = err >>= 1;
572 >                        err /= 3;
573 >                        cerr[x] = err + errp;
574                  }
575          }
576 <        free((char *)inline);
576 >        free((char *)inl);
577          free((char *)cerr);
578   }
579  
# Line 648 | Line 644 | int  y;
644                  if (scanpos == NULL || scanpos[y] == -1)
645                          return(-1);
646                  if (fseek(fin, scanpos[y], 0) == -1)
647 <                        quit("fseek error");
647 >                        quiterr("fseek error");
648                  cury = y;
649 <        } else if (scanpos != NULL)
649 >        } else if (scanpos != NULL && scanpos[y] == -1)
650                  scanpos[y] = ftell(fin);
651  
652          if (freadcolrs(scanline, xmax, fin) < 0)
# Line 670 | Line 666 | register rgbpixel  *l3;
666          if (getscan(y) < 0)
667                  quiterr("cannot seek for picreadline");
668                                                          /* convert scanline */
669 <        if (scale != 0)
674 <                for (i = 0; i < xmax; i++)
675 <                        if (scanline[i][EXP]+scale >= 0)
676 <                                scanline[i][EXP] += scale;
677 <        normcolrs(scanline, xmax);
669 >        normcolrs(scanline, xmax, scale);
670          for (i = 0; i < xmax; i++) {
671                  l3[i].r = scanline[i][RED];
672                  l3[i].g = scanline[i][GRN];
# Line 687 | Line 679 | picwriteline(y, l)             /* add 8-bit scanline to image */
679   int  y;
680   pixel  *l;
681   {
682 <        bcopy(l, ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1));
682 >        bcopy((char *)l, (char *)ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1));
683   }
684  
685  
# Line 698 | Line 690 | colormap  map;
690          register int  i, val;
691  
692          for (i = 0; i < 256; i++) {
693 <                val = pow(i/256.0, 1.0/gamcor) * 256.0;
693 >                val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0;
694                  map[0][i] = map[1][i] = map[2][i] = val;
695          }
696   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines