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.9 by greg, Tue Sep 12 13:04:42 1989 UTC vs.
Revision 1.22 by greg, Thu Jan 18 23:58:26 1990 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 56 | Line 58 | int  scale = 0;                                /* scalefactor; power of two */
58   int  xoff = 0;                          /* x image offset */
59   int  yoff = 0;                          /* y image offset */
60  
61 < VIEW  ourview = STDVIEW(0);             /* image view parameters */
61 > VIEW  ourview = STDVIEW;                /* image view parameters */
62   int  gotview = 0;                       /* got parameters from file */
63  
64   COLR  *scanline;                        /* scan line buffer */
# Line 144 | Line 146 | char  *argv[];
146          if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR))
147                  quiterr("bad picture size");
148                                  /* set view parameters */
149 <        if (gotview) {
150 <                ourview.hresolu = xmax;
149 <                ourview.vresolu = ymax;
150 <                if (setview(&ourview) != NULL)
151 <                        gotview = 0;
152 <        }
149 >        if (gotview && setview(&ourview) != NULL)
150 >                gotview = 0;
151          if ((scanline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL)
152                  quiterr("out of memory");
153  
# Line 171 | Line 169 | char  *s;
169          static char  *altname[] = {"rview","rpict",VIEWSTR,NULL};
170          register char  **an;
171  
172 <        if (!strncmp(s, "EXPOSURE=", 9))
173 <                exposure *= atof(s+9);
172 >        if (isexpos(s))
173 >                exposure *= exposval(s);
174          else
175                  for (an = altname; *an != NULL; an++)
176                          if (!strncmp(*an, s, strlen(*an))) {
177 <                                if (sscanview(&ourview, s+strlen(*an)) == 0)
177 >                                if (sscanview(&ourview, s+strlen(*an)) > 0)
178                                          gotview++;
179                                  return;
180                          }
181   }
182  
183  
186 char *
187 sskip(s)                /* skip a word */
188 register char  *s;
189 {
190        while (isspace(*s)) s++;
191        while (*s && !isspace(*s)) s++;
192        return(s);
193 }
194
195
184   init()                  /* get data and open window */
185   {
186          register int  i;
# Line 360 | Line 348 | XKeyEvent  *ekey;
348   {
349          char  buf[80];
350          COLOR  cval;
351 +        Color  cvx;
352          char  *cp;
353          int  n;
354          double  comp;
# Line 370 | Line 359 | XKeyEvent  *ekey;
359                  return(0);
360          switch (*cp) {                  /* interpret command */
361          case 'q':
362 <        case CTRL(D):                           /* quiterr */
362 >        case CTRL(D):                           /* quit */
363                  quit(0);
364          case '\n':
365          case '\r':
# Line 381 | Line 370 | XKeyEvent  *ekey;
370                  switch (*cp) {
371                  case '\n':
372                  case '\r':                              /* radiance */
373 <                        sprintf(buf, "%-3g", intens(cval)/exposure);
373 >                        sprintf(buf, "%.3f", intens(cval)/exposure);
374                          break;
375                  case 'l':                               /* luminance */
376 <                        sprintf(buf, "%-3gL", bright(cval)*683.0/exposure);
376 >                        sprintf(buf, "%.0fn", bright(cval)*683.0/exposure);
377                          break;
378                  case 'c':                               /* color */
379                          comp = pow(2.0, (double)scale);
# Line 397 | Line 386 | XKeyEvent  *ekey;
386                  XText(wind, box.xmin, box.ymin, buf, strlen(buf),
387                                  fontid, BlackPixel, WhitePixel);
388                  return(0);
389 +        case 'i':                               /* identify (contour) */
390 +                if (ourras->pixels == NULL)
391 +                        return(-1);
392 +                n = ourras->data.bz[ekey->x-xoff+BZPixmapSize(xmax,ekey->y-yoff)];
393 +                n = ourras->pmap[n];
394 +                cvx.pixel = ourras->cdefs[n].pixel;
395 +                cvx.red = random() & 65535;
396 +                cvx.green = random() & 65535;
397 +                cvx.blue = random() & 65535;
398 +                XStoreColor(&cvx);
399 +                return(0);
400          case 'p':                               /* position */
401                  sprintf(buf, "(%d,%d)", ekey->x-xoff, ymax-1-ekey->y+yoff);
402                  XText(wind, ekey->x, ekey->y, buf, strlen(buf),
# Line 407 | Line 407 | XKeyEvent  *ekey;
407                          XFeep(0);
408                          return(-1);
409                  }
410 <                rayview(rorg, rdir, &ourview,
411 <                                ekey->x-xoff + .5, ymax-1-ekey->y+yoff + .5);
410 >                viewray(rorg, rdir, &ourview, (ekey->x-xoff+.5)/xmax,
411 >                                (ymax-1-ekey->y+yoff+.5)/ymax);
412                  printf("%e %e %e ", rorg[0], rorg[1], rorg[2]);
413                  printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]);
414                  fflush(stdout);
# Line 430 | Line 430 | XKeyEvent  *ekey;
430          /* fall through */
431          case CTRL(R):                           /* redraw */
432          case CTRL(L):
433 +                unmap_rcolors(ourras);
434                  XClear(wind);
435                  return(redraw(0, 0, width, height));
436          case ' ':                               /* clear */
# Line 603 | Line 604 | register XRASTER       *xr;
604   double  sf;
605   {
606          register int    i;
607 <        int     maxv;
607 >        long    maxv;
608  
609 +        if (xr->pixels == NULL)
610 +                return;
611 +
612          sf = pow(sf, 1.0/gamcor);
613 <        maxv = (1<<16) / sf;
613 >        maxv = 65535/sf;
614  
615          for (i = xr->ncolors; i--; ) {
616 <                xr->cdefs[i].red = xr->cdefs[i].red >= maxv ?
617 <                                (1<<16)-1 :
616 >                xr->cdefs[i].red = xr->cdefs[i].red > maxv ?
617 >                                65535 :
618                                  xr->cdefs[i].red * sf;
619 <                xr->cdefs[i].green = xr->cdefs[i].green >= maxv ?
620 <                                (1<<16)-1 :
619 >                xr->cdefs[i].green = xr->cdefs[i].green > maxv ?
620 >                                65535 :
621                                  xr->cdefs[i].green * sf;
622 <                xr->cdefs[i].blue = xr->cdefs[i].blue >= maxv ?
623 <                                (1<<16)-1 :
622 >                xr->cdefs[i].blue = xr->cdefs[i].blue > maxv ?
623 >                                65535 :
624                                  xr->cdefs[i].blue * sf;
625          }
626 <        if (xr->pixels != NULL)
623 <                XStoreColors(xr->ncolors, xr->cdefs);
626 >        XStoreColors(xr->ncolors, xr->cdefs);
627   }
628  
629  
# Line 648 | Line 651 | picreadline3(y, l3)                    /* read in 3-byte scanline */
651   int  y;
652   register rgbpixel  *l3;
653   {
654 <        register BYTE   *l4;
655 <        register int    shift, c;
653 <        int     i;
654 <
654 >        register int    i;
655 >                                                        /* read scanline */
656          if (getscan(y) < 0)
657                  quiterr("cannot seek for picreadline");
658                                                          /* convert scanline */
659 <        for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) {
660 <                shift = l4[EXP] - COLXS + scale;
661 <                if (shift >= 8) {
662 <                        l3->r = l3->g = l3->b = 255;
663 <                } else if (shift <= -8) {
664 <                        l3->r = l3->g = l3->b = 0;
665 <                } else if (shift > 0) {
666 <                        c = l4[RED] << shift;
667 <                        l3->r = c > 255 ? 255 : c;
667 <                        c = l4[GRN] << shift;
668 <                        l3->g = c > 255 ? 255 : c;
669 <                        c = l4[BLU] << shift;
670 <                        l3->b = c > 255 ? 255 : c;
671 <                } else if (shift < 0) {
672 <                        l3->r = l4[RED] >> -shift;
673 <                        l3->g = l4[GRN] >> -shift;
674 <                        l3->b = l4[BLU] >> -shift;
675 <                } else {
676 <                        l3->r = l4[RED];
677 <                        l3->g = l4[GRN];
678 <                        l3->b = l4[BLU];
679 <                }
659 >        if (scale)
660 >                for (i = 0; i < xmax; i++)
661 >                        if (scanline[i][EXP])
662 >                                scanline[i][EXP] += scale;
663 >        normcolrs(scanline, xmax);
664 >        for (i = 0; i < xmax; i++) {
665 >                l3[i].r = scanline[i][RED];
666 >                l3[i].g = scanline[i][GRN];
667 >                l3[i].b = scanline[i][BLU];
668          }
669   }
670  
# Line 685 | Line 673 | picwriteline(y, l)             /* add 8-bit scanline to image */
673   int  y;
674   pixel  *l;
675   {
676 <        bcopy(l, ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1));
676 >        bcopy((char *)l, (char *)ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1));
677   }
678  
679  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines