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.2 by greg, Fri Apr 7 16:36:10 1989 UTC vs.
Revision 1.15 by greg, Wed Nov 29 16:50:39 1989 UTC

# Line 29 | Line 29 | static char SCCSid[] = "$SunId$ LBL";
29  
30   #include  "pic.h"
31  
32 + #include  "random.h"
33 +
34   #define  controlshift(e)        (((XButtonEvent *)(e))->detail & (ShiftMask|ControlMask))
35  
36   #define  FONTNAME       "9x15"          /* text font we'll use */
# Line 38 | Line 40 | static char SCCSid[] = "$SunId$ LBL";
40   #define  BORWIDTH       5               /* border width */
41   #define  BARHEIGHT      25              /* menu bar size */
42  
43 < double  gamcor = 2.0;                   /* gamma correction */
43 > double  gamcor = 2.2;                   /* gamma correction */
44  
45   XRASTER  *ourras = NULL;                /* our stored raster image */
46  
# Line 137 | Line 139 | char  *argv[];
139                          sprintf(errmsg, "can't open file \"%s\"", fname);
140                          quiterr(errmsg);
141                  }
142 <        } else
141 <                goto userr;
142 <
142 >        }
143                                  /* get header */
144          getheader(fin, headline);
145                                  /* get picture dimensions */
146 <        if (fscanf(fin, "-Y %d +X %d\n", &ymax, &xmax) != 2)
146 >        if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR))
147                  quiterr("bad picture size");
148                                  /* set view parameters */
149          if (gotview) {
# Line 170 | Line 170 | userr:
170   headline(s)             /* get relevant info from header */
171   char  *s;
172   {
173 <        static char  *altname[] = {"rview","rpict","VIEW=",NULL};
173 >        static char  *altname[] = {"rview","rpict",VIEWSTR,NULL};
174          register char  **an;
175  
176          if (!strncmp(s, "EXPOSURE=", 9))
# Line 347 | Line 347 | redraw(x, y, w, h)                     /* redraw section of window */
347   int  x, y;
348   int  w, h;
349   {
350 <        if (map_rcolors(ourras) == NULL) {
350 >        if (ourras->ncolors && map_rcolors(ourras) == NULL) {
351                  fprintf(stderr, "%s: cannot allocate colors\n", progname);
352                  return(-1);
353          }
# Line 362 | Line 362 | XKeyEvent  *ekey;
362   {
363          char  buf[80];
364          COLOR  cval;
365 +        Color  cvx;
366          char  *cp;
367          int  n;
368          double  comp;
# Line 372 | Line 373 | XKeyEvent  *ekey;
373                  return(0);
374          switch (*cp) {                  /* interpret command */
375          case 'q':
376 <        case CTRL(D):                           /* quiterr */
376 >        case CTRL(D):                           /* quit */
377                  quit(0);
378          case '\n':
379          case '\r':
# Line 399 | Line 400 | XKeyEvent  *ekey;
400                  XText(wind, box.xmin, box.ymin, buf, strlen(buf),
401                                  fontid, BlackPixel, WhitePixel);
402                  return(0);
403 +        case 'i':                               /* identify (contour) */
404 +                if (ourras->ncolors == 0)
405 +                        return(-1);
406 +                n = ourras->data.bz[ekey->x-xoff+BZPixmapSize(xmax,ekey->y-yoff)];
407 +                n = ourras->pmap[n];
408 +                cvx.pixel = ourras->cdefs[n].pixel;
409 +                cvx.red = random() & 65535;
410 +                cvx.green = random() & 65535;
411 +                cvx.blue = random() & 65535;
412 +                XStoreColor(&cvx);
413 +                return(0);
414          case 'p':                               /* position */
415                  sprintf(buf, "(%d,%d)", ekey->x-xoff, ymax-1-ekey->y+yoff);
416                  XText(wind, ekey->x, ekey->y, buf, strlen(buf),
# Line 419 | Line 431 | XKeyEvent  *ekey;
431                  if (avgbox(cval) == -1)
432                          return(-1);
433                  n = log(.5/bright(cval))/.69315 - scale;        /* truncate */
434 <                if (n == 0) {
423 <                        XFeep(0);
434 >                if (n == 0)
435                          return(0);
425                }
436                  scale_rcolors(ourras, pow(2.0, (double)n));
437                  scale += n;
438                  sprintf(buf, "%+d", scale);
# Line 431 | Line 441 | XKeyEvent  *ekey;
441                  XFlush();
442                  free_raster(ourras);
443                  getras();
444 <                return(redraw(0, 0, width, height));
444 >        /* fall through */
445          case CTRL(R):                           /* redraw */
446 +        case CTRL(L):
447                  XClear(wind);
448 +                XStoreColors(ourras->ncolors, ourras->cdefs);
449                  return(redraw(0, 0, width, height));
450          case ' ':                               /* clear */
451                  return(redraw(box.xmin, box.ymin, box.xsiz, box.ysiz));
# Line 651 | Line 663 | picreadline3(y, l3)                    /* read in 3-byte scanline */
663   int  y;
664   register rgbpixel  *l3;
665   {
666 <        register BYTE   *l4;
667 <        register int    shift, c;
656 <        int     i;
657 <
666 >        register int    i;
667 >                                                        /* read scanline */
668          if (getscan(y) < 0)
669                  quiterr("cannot seek for picreadline");
670                                                          /* convert scanline */
671 <        for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) {
672 <                shift = l4[EXP] - COLXS + scale;
673 <                if (shift >= 8) {
674 <                        l3->r = l3->g = l3->b = 255;
675 <                } else if (shift <= -8) {
676 <                        l3->r = l3->g = l3->b = 0;
677 <                } else if (shift > 0) {
678 <                        c = l4[RED] << shift;
679 <                        l3->r = c > 255 ? 255 : c;
670 <                        c = l4[GRN] << shift;
671 <                        l3->g = c > 255 ? 255 : c;
672 <                        c = l4[BLU] << shift;
673 <                        l3->b = c > 255 ? 255 : c;
674 <                } else if (shift < 0) {
675 <                        l3->r = l4[RED] >> -shift;
676 <                        l3->g = l4[GRN] >> -shift;
677 <                        l3->b = l4[BLU] >> -shift;
678 <                } else {
679 <                        l3->r = l4[RED];
680 <                        l3->g = l4[GRN];
681 <                        l3->b = l4[BLU];
682 <                }
671 >        if (scale != 0)
672 >                for (i = 0; i < xmax; i++)
673 >                        if (scanline[i][EXP]+scale >= 0)
674 >                                scanline[i][EXP] += scale;
675 >        normcolrs(scanline, xmax);
676 >        for (i = 0; i < xmax; i++) {
677 >                l3[i].r = scanline[i][RED];
678 >                l3[i].g = scanline[i][GRN];
679 >                l3[i].b = scanline[i][BLU];
680          }
681   }
682  
# Line 692 | Line 689 | pixel  *l;
689   }
690  
691  
692 < picreadcm(map)                  /* do gamcor correction */
692 > picreadcm(map)                  /* do gamma correction */
693   colormap  map;
694   {
695          extern double  pow();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines