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.21 by greg, Mon Jan 8 14:47:11 1990 UTC vs.
Revision 2.10 by greg, Wed Apr 23 00:52:34 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1987 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  ximage.c - driver for X-windows
6   *
# Line 21 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  <ctype.h>
20  
21 + #include  <time.h>
22 +
23   #include  "color.h"
24  
25 + #include  "resolu.h"
26 +
27   #include  "xraster.h"
28  
29   #include  "view.h"
# Line 35 | Line 36 | static char SCCSid[] = "$SunId$ LBL";
36  
37   #define  FONTNAME       "9x15"          /* text font we'll use */
38  
39 < #define  CTRL(c)        ('c'-'@')
39 > #define  CTRL(c)        ((c)-'@')
40  
41   #define  BORWIDTH       5               /* border width */
42   #define  BARHEIGHT      25              /* menu bar size */
# Line 72 | Line 73 | int  cury = 0;                         /* current scan location */
73  
74   double  exposure = 1.0;                 /* exposure compensation used */
75  
76 + int  wrongformat = 0;                   /* input in another format */
77 +
78   struct {
79          int  xmin, ymin, xsiz, ysiz;
80   }  box = {0, 0, 0, 0};                  /* current box */
# Line 82 | Line 85 | char  *progname;
85  
86   char  errmsg[128];
87  
85 extern long  ftell();
88  
87 extern char  *malloc(), *calloc();
88
89 extern double  atof(), pow(), log();
90
91
89   main(argc, argv)
90   int  argc;
91   char  *argv[];
92   {
93 +        extern char  *getenv();
94 +        char  *gv;
95          int  headline();
96          int  i;
97          
98          progname = argv[0];
99 +        if ((gv = getenv("DISPLAY_GAMMA")) != NULL)
100 +                gamcor = atof(gv);
101  
102          for (i = 1; i < argc; i++)
103                  if (argv[i][0] == '-')
# Line 141 | Line 142 | char  *argv[];
142                  }
143          }
144                                  /* get header */
145 <        getheader(fin, headline);
145 >        getheader(fin, headline, NULL);
146                                  /* get picture dimensions */
147 <        if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR))
147 >        if (wrongformat || fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR))
148                  quiterr("bad picture size");
149                                  /* set view parameters */
150          if (gotview && setview(&ourview) != NULL)
# Line 163 | Line 164 | userr:
164   }
165  
166  
167 + int
168   headline(s)             /* get relevant info from header */
169   char  *s;
170   {
171 <        static char  *altname[] = {"rview","rpict",VIEWSTR,NULL};
170 <        register char  **an;
171 >        char  fmt[32];
172  
173          if (isexpos(s))
174                  exposure *= exposval(s);
175 <        else
176 <                for (an = altname; *an != NULL; an++)
177 <                        if (!strncmp(*an, s, strlen(*an))) {
178 <                                if (sscanview(&ourview, s+strlen(*an)) > 0)
179 <                                        gotview++;
180 <                                return;
180 <                        }
175 >        else if (isformat(s)) {
176 >                formatval(fmt, s);
177 >                wrongformat = strcmp(fmt, COLRFMT);
178 >        } else if (isview(s) && sscanview(&ourview, s) > 0)
179 >                gotview++;
180 >        return(0);
181   }
182  
183  
# Line 246 | Line 246 | char  *err;
246   }
247  
248  
249 + void
250   eputs(s)
251   char    *s;
252   {
# Line 253 | Line 254 | char   *s;
254   }
255  
256  
257 + void
258   quit(code)
259   int  code;
260   {
# Line 287 | Line 289 | getras()                               /* get raster file */
289          }
290          return;
291   memerr:
292 <        quit("out of memory");
292 >        quiterr("out of memory");
293   }
294  
295  
# Line 359 | Line 361 | XKeyEvent  *ekey;
361                  return(0);
362          switch (*cp) {                  /* interpret command */
363          case 'q':
364 <        case CTRL(D):                           /* quit */
364 >        case CTRL('D'):                         /* quit */
365                  quit(0);
366          case '\n':
367          case '\r':
# Line 373 | Line 375 | XKeyEvent  *ekey;
375                          sprintf(buf, "%.3f", intens(cval)/exposure);
376                          break;
377                  case 'l':                               /* luminance */
378 <                        sprintf(buf, "%.0fn", bright(cval)*683.0/exposure);
378 >                        sprintf(buf, "%.0fL", luminance(cval)/exposure);
379                          break;
380                  case 'c':                               /* color */
381                          comp = pow(2.0, (double)scale);
# Line 407 | Line 409 | XKeyEvent  *ekey;
409                          XFeep(0);
410                          return(-1);
411                  }
412 <                viewray(rorg, rdir, &ourview, (ekey->x-xoff+.5)/xmax,
413 <                                (ymax-1-ekey->y+yoff+.5)/ymax);
412 >                if (viewray(rorg, rdir, &ourview, (ekey->x-xoff+.5)/xmax,
413 >                                (ymax-1-ekey->y+yoff+.5)/ymax) < 0)
414 >                        return(-1);
415                  printf("%e %e %e ", rorg[0], rorg[1], rorg[2]);
416                  printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]);
417                  fflush(stdout);
# Line 428 | Line 431 | XKeyEvent  *ekey;
431                  free_raster(ourras);
432                  getras();
433          /* fall through */
434 <        case CTRL(R):                           /* redraw */
435 <        case CTRL(L):
434 >        case CTRL('R'):                         /* redraw */
435 >        case CTRL('L'):
436                  unmap_rcolors(ourras);
437                  XClear(wind);
438                  return(redraw(0, 0, width, height));
# Line 541 | Line 544 | getmono()                      /* get monochrome data */
544   {
545          register unsigned short *dp;
546          register int    x, err;
547 <        int     y;
548 <        rgbpixel        *inline;
547 >        int     y, errp;
548 >        rgbpixel        *inl;
549          short   *cerr;
550  
551 <        if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL
551 >        if ((inl = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL
552                          || (cerr = (short *)calloc(xmax,sizeof(short))) == NULL)
553 <                quit("out of memory in getmono");
553 >                quiterr("out of memory in getmono");
554          dp = ourras->data.m - 1;
555          for (y = 0; y < ymax; y++) {
556 <                picreadline3(y, inline);
556 >                picreadline3(y, inl);
557                  err = 0;
558                  for (x = 0; x < xmax; x++) {
559                          if (!(x&0xf))
560                                  *++dp = 0;
561 <                        err += rgb_bright(&inline[x]) + cerr[x];
561 >                        errp = err;
562 >                        err += rgb_bright(&inl[x]) + cerr[x];
563                          if (err > 127)
564                                  err -= 255;
565                          else
566                                  *dp |= 1<<(x&0xf);
567 <                        cerr[x] = err >>= 1;
567 >                        err /= 3;
568 >                        cerr[x] = err + errp;
569                  }
570          }
571 <        free((char *)inline);
572 <        free((char *)cerr);
571 >        free((void *)inl);
572 >        free((void *)cerr);
573   }
574  
575  
# Line 592 | Line 597 | colormap       cmap;
597                          xr->cdefs[xr->ncolors].pixel = *p;
598                          xr->pmap[*p] = xr->ncolors++;
599                  }
600 <        xr->cdefs = (Color *)realloc((char *)xr->cdefs, xr->ncolors*sizeof(Color));
600 >        xr->cdefs = (Color *)realloc((void *)xr->cdefs, xr->ncolors*sizeof(Color));
601          if (xr->cdefs == NULL)
602                  return(0);
603          return(1);
# Line 634 | Line 639 | int  y;
639                  if (scanpos == NULL || scanpos[y] == -1)
640                          return(-1);
641                  if (fseek(fin, scanpos[y], 0) == -1)
642 <                        quit("fseek error");
642 >                        quiterr("fseek error");
643                  cury = y;
644 <        } else if (scanpos != NULL)
644 >        } else if (scanpos != NULL && scanpos[y] == -1)
645                  scanpos[y] = ftell(fin);
646  
647          if (freadcolrs(scanline, xmax, fin) < 0)
# Line 656 | Line 661 | register rgbpixel  *l3;
661          if (getscan(y) < 0)
662                  quiterr("cannot seek for picreadline");
663                                                          /* convert scanline */
664 <        if (scale)
660 <                for (i = 0; i < xmax; i++)
661 <                        if (scanline[i][EXP])
662 <                                scanline[i][EXP] += scale;
663 <        normcolrs(scanline, xmax);
664 >        normcolrs(scanline, xmax, scale);
665          for (i = 0; i < xmax; i++) {
666                  l3[i].r = scanline[i][RED];
667                  l3[i].g = scanline[i][GRN];
# Line 673 | Line 674 | picwriteline(y, l)             /* add 8-bit scanline to image */
674   int  y;
675   pixel  *l;
676   {
677 <        bcopy(l, ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1));
677 >        bcopy((char *)l, (char *)ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1));
678   }
679  
680  
# Line 684 | Line 685 | colormap  map;
685          register int  i, val;
686  
687          for (i = 0; i < 256; i++) {
688 <                val = pow(i/256.0, 1.0/gamcor) * 256.0;
688 >                val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0;
689                  map[0][i] = map[1][i] = map[2][i] = val;
690          }
691   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines