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.25 by greg, Sat Oct 13 21:31:45 1990 UTC vs.
Revision 2.12 by schorsch, Mon Jun 30 14:59:12 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 18 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
15   #include  <X/cursors/bcross_mask.cursor>
16  
17   #include  <sys/types.h>
18 <
18 > #include  <string.h>
19   #include  <ctype.h>
20 + #include  <time.h>
21  
22   #include  "color.h"
23 <
23 > #include  "resolu.h"
24   #include  "xraster.h"
27
25   #include  "view.h"
29
26   #include  "pic.h"
31
27   #include  "random.h"
28  
29   #define  controlshift(e)        (((XButtonEvent *)(e))->detail & (ShiftMask|ControlMask))
30  
31   #define  FONTNAME       "9x15"          /* text font we'll use */
32  
33 < #define  CTRL(c)        ('c'-'@')
33 > #define  CTRL(c)        ((c)-'@')
34  
35   #define  BORWIDTH       5               /* border width */
36   #define  BARHEIGHT      25              /* menu bar size */
# Line 72 | Line 67 | int  cury = 0;                         /* current scan location */
67  
68   double  exposure = 1.0;                 /* exposure compensation used */
69  
70 + int  wrongformat = 0;                   /* input in another format */
71 +
72   struct {
73          int  xmin, ymin, xsiz, ysiz;
74   }  box = {0, 0, 0, 0};                  /* current box */
# Line 82 | Line 79 | char  *progname;
79  
80   char  errmsg[128];
81  
85 extern long  ftell();
82  
87 extern char  *malloc(), *calloc();
88
89 extern double  atof(), pow(), log();
90
91
83   main(argc, argv)
84   int  argc;
85   char  *argv[];
86   {
87 +        extern char  *getenv();
88 +        char  *gv;
89          int  headline();
90          int  i;
91          
92          progname = argv[0];
93 +        if ((gv = getenv("DISPLAY_GAMMA")) != NULL)
94 +                gamcor = atof(gv);
95  
96          for (i = 1; i < argc; i++)
97                  if (argv[i][0] == '-')
# Line 141 | Line 136 | char  *argv[];
136                  }
137          }
138                                  /* get header */
139 <        getheader(fin, headline);
139 >        getheader(fin, headline, NULL);
140                                  /* get picture dimensions */
141 <        if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR))
141 >        if (wrongformat || fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR))
142                  quiterr("bad picture size");
143                                  /* set view parameters */
144          if (gotview && setview(&ourview) != NULL)
# Line 163 | Line 158 | userr:
158   }
159  
160  
161 + int
162   headline(s)             /* get relevant info from header */
163   char  *s;
164   {
165 <        static char  *altname[] = {"rview","rpict",VIEWSTR,NULL};
170 <        register char  **an;
165 >        char  fmt[32];
166  
167          if (isexpos(s))
168                  exposure *= exposval(s);
169 <        else
170 <                for (an = altname; *an != NULL; an++)
171 <                        if (!strncmp(*an, s, strlen(*an))) {
172 <                                if (sscanview(&ourview, s+strlen(*an)) > 0)
173 <                                        gotview++;
174 <                                return;
180 <                        }
169 >        else if (isformat(s)) {
170 >                formatval(fmt, s);
171 >                wrongformat = strcmp(fmt, COLRFMT);
172 >        } else if (isview(s) && sscanview(&ourview, s) > 0)
173 >                gotview++;
174 >        return(0);
175   }
176  
177  
# Line 246 | Line 240 | char  *err;
240   }
241  
242  
243 + void
244   eputs(s)
245   char    *s;
246   {
# Line 253 | Line 248 | char   *s;
248   }
249  
250  
251 + void
252   quit(code)
253   int  code;
254   {
# Line 287 | Line 283 | getras()                               /* get raster file */
283          }
284          return;
285   memerr:
286 <        quit("out of memory");
286 >        quiterr("out of memory");
287   }
288  
289  
# Line 359 | Line 355 | XKeyEvent  *ekey;
355                  return(0);
356          switch (*cp) {                  /* interpret command */
357          case 'q':
358 <        case CTRL(D):                           /* quit */
358 >        case CTRL('D'):                         /* quit */
359                  quit(0);
360          case '\n':
361          case '\r':
# Line 373 | Line 369 | XKeyEvent  *ekey;
369                          sprintf(buf, "%.3f", intens(cval)/exposure);
370                          break;
371                  case 'l':                               /* luminance */
372 <                        sprintf(buf, "%.0fn", bright(cval)*683.0/exposure);
372 >                        sprintf(buf, "%.0fL", luminance(cval)/exposure);
373                          break;
374                  case 'c':                               /* color */
375                          comp = pow(2.0, (double)scale);
# Line 429 | Line 425 | XKeyEvent  *ekey;
425                  free_raster(ourras);
426                  getras();
427          /* fall through */
428 <        case CTRL(R):                           /* redraw */
429 <        case CTRL(L):
428 >        case CTRL('R'):                         /* redraw */
429 >        case CTRL('L'):
430                  unmap_rcolors(ourras);
431                  XClear(wind);
432                  return(redraw(0, 0, width, height));
# Line 542 | Line 538 | getmono()                      /* get monochrome data */
538   {
539          register unsigned short *dp;
540          register int    x, err;
541 <        int     y;
541 >        int     y, errp;
542          rgbpixel        *inl;
543          short   *cerr;
544  
545          if ((inl = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL
546                          || (cerr = (short *)calloc(xmax,sizeof(short))) == NULL)
547 <                quit("out of memory in getmono");
547 >                quiterr("out of memory in getmono");
548          dp = ourras->data.m - 1;
549          for (y = 0; y < ymax; y++) {
550                  picreadline3(y, inl);
# Line 556 | Line 552 | getmono()                      /* get monochrome data */
552                  for (x = 0; x < xmax; x++) {
553                          if (!(x&0xf))
554                                  *++dp = 0;
555 +                        errp = err;
556                          err += rgb_bright(&inl[x]) + cerr[x];
557                          if (err > 127)
558                                  err -= 255;
559                          else
560                                  *dp |= 1<<(x&0xf);
561 <                        cerr[x] = err >>= 1;
561 >                        err /= 3;
562 >                        cerr[x] = err + errp;
563                  }
564          }
565 <        free((char *)inl);
566 <        free((char *)cerr);
565 >        free((void *)inl);
566 >        free((void *)cerr);
567   }
568  
569  
# Line 593 | Line 591 | colormap       cmap;
591                          xr->cdefs[xr->ncolors].pixel = *p;
592                          xr->pmap[*p] = xr->ncolors++;
593                  }
594 <        xr->cdefs = (Color *)realloc((char *)xr->cdefs, xr->ncolors*sizeof(Color));
594 >        xr->cdefs = (Color *)realloc((void *)xr->cdefs, xr->ncolors*sizeof(Color));
595          if (xr->cdefs == NULL)
596                  return(0);
597          return(1);
# Line 635 | Line 633 | int  y;
633                  if (scanpos == NULL || scanpos[y] == -1)
634                          return(-1);
635                  if (fseek(fin, scanpos[y], 0) == -1)
636 <                        quit("fseek error");
636 >                        quiterr("fseek error");
637                  cury = y;
638 <        } else if (scanpos != NULL)
638 >        } else if (scanpos != NULL && scanpos[y] == -1)
639                  scanpos[y] = ftell(fin);
640  
641          if (freadcolrs(scanline, xmax, fin) < 0)
# Line 670 | Line 668 | picwriteline(y, l)             /* add 8-bit scanline to image */
668   int  y;
669   pixel  *l;
670   {
671 <        bcopy((char *)l, (char *)ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1));
671 >        memcpy((void *)ourras->data.bz+BZPixmapSize(xmax,y), (void *)l, BZPixmapSize(xmax,1));
672   }
673  
674  
# Line 681 | Line 679 | colormap  map;
679          register int  i, val;
680  
681          for (i = 0; i < 256; i++) {
682 <                val = pow(i/256.0, 1.0/gamcor) * 256.0;
682 >                val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0;
683                  map[0][i] = map[1][i] = map[2][i] = val;
684          }
685   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines