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.25 by greg, Sat Oct 13 21:31:45 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 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) {
150 <                ourview.hresolu = xmax;
151 <                ourview.vresolu = ymax;
152 <                if (setview(&ourview) != NULL)
153 <                        gotview = 0;
154 <        }
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 170 | Line 166 | userr:
166   headline(s)             /* get relevant info from header */
167   char  *s;
168   {
169 <        static char  *altname[] = {"rview","rpict","VIEW=",NULL};
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  
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
184   init()                  /* get data and open window */
185   {
186          register int  i;
# Line 347 | Line 333 | redraw(x, y, w, h)                     /* redraw section of window */
333   int  x, y;
334   int  w, h;
335   {
336 <        if (map_rcolors(ourras) == NULL) {
336 >        if (ourras->ncolors && map_rcolors(ourras) == NULL) {
337                  fprintf(stderr, "%s: cannot allocate colors\n", progname);
338                  return(-1);
339          }
# Line 362 | 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 372 | 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 383 | 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 399 | 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 409 | 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 >                if (viewray(rorg, rdir, &ourview, (ekey->x-xoff+.5)/xmax,
411 >                                (ymax-1-ekey->y+yoff+.5)/ymax) < 0)
412 >                        return(-1);
413                  printf("%e %e %e ", rorg[0], rorg[1], rorg[2]);
414                  printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]);
415                  fflush(stdout);
# Line 419 | Line 418 | XKeyEvent  *ekey;
418                  if (avgbox(cval) == -1)
419                          return(-1);
420                  n = log(.5/bright(cval))/.69315 - scale;        /* truncate */
421 <                if (n == 0) {
423 <                        XFeep(0);
421 >                if (n == 0)
422                          return(0);
425                }
423                  scale_rcolors(ourras, pow(2.0, (double)n));
424                  scale += n;
425                  sprintf(buf, "%+d", scale);
# Line 431 | Line 428 | XKeyEvent  *ekey;
428                  XFlush();
429                  free_raster(ourras);
430                  getras();
431 <                return(redraw(0, 0, width, height));
431 >        /* fall through */
432          case CTRL(R):                           /* redraw */
433 +        case CTRL(L):
434 +                unmap_rcolors(ourras);
435                  XClear(wind);
436                  return(redraw(0, 0, width, height));
437          case ' ':                               /* clear */
# Line 544 | Line 543 | getmono()                      /* get monochrome data */
543          register unsigned short *dp;
544          register int    x, err;
545          int     y;
546 <        rgbpixel        *inline;
546 >        rgbpixel        *inl;
547          short   *cerr;
548  
549 <        if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL
549 >        if ((inl = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL
550                          || (cerr = (short *)calloc(xmax,sizeof(short))) == NULL)
551                  quit("out of memory in getmono");
552          dp = ourras->data.m - 1;
553          for (y = 0; y < ymax; y++) {
554 <                picreadline3(y, inline);
554 >                picreadline3(y, inl);
555                  err = 0;
556                  for (x = 0; x < xmax; x++) {
557                          if (!(x&0xf))
558                                  *++dp = 0;
559 <                        err += rgb_bright(&inline[x]) + cerr[x];
559 >                        err += rgb_bright(&inl[x]) + cerr[x];
560                          if (err > 127)
561                                  err -= 255;
562                          else
# Line 565 | Line 564 | getmono()                      /* get monochrome data */
564                          cerr[x] = err >>= 1;
565                  }
566          }
567 <        free((char *)inline);
567 >        free((char *)inl);
568          free((char *)cerr);
569   }
570  
# Line 606 | Line 605 | register XRASTER       *xr;
605   double  sf;
606   {
607          register int    i;
608 <        int     maxv;
608 >        long    maxv;
609  
610 +        if (xr->pixels == NULL)
611 +                return;
612 +
613          sf = pow(sf, 1.0/gamcor);
614 <        maxv = (1<<16) / sf;
614 >        maxv = 65535/sf;
615  
616          for (i = xr->ncolors; i--; ) {
617 <                xr->cdefs[i].red = xr->cdefs[i].red >= maxv ?
618 <                                (1<<16)-1 :
617 >                xr->cdefs[i].red = xr->cdefs[i].red > maxv ?
618 >                                65535 :
619                                  xr->cdefs[i].red * sf;
620 <                xr->cdefs[i].green = xr->cdefs[i].green >= maxv ?
621 <                                (1<<16)-1 :
620 >                xr->cdefs[i].green = xr->cdefs[i].green > maxv ?
621 >                                65535 :
622                                  xr->cdefs[i].green * sf;
623 <                xr->cdefs[i].blue = xr->cdefs[i].blue >= maxv ?
624 <                                (1<<16)-1 :
623 >                xr->cdefs[i].blue = xr->cdefs[i].blue > maxv ?
624 >                                65535 :
625                                  xr->cdefs[i].blue * sf;
626          }
627 <        if (xr->pixels != NULL)
626 <                XStoreColors(xr->ncolors, xr->cdefs);
627 >        XStoreColors(xr->ncolors, xr->cdefs);
628   }
629  
630  
# Line 651 | Line 652 | picreadline3(y, l3)                    /* read in 3-byte scanline */
652   int  y;
653   register rgbpixel  *l3;
654   {
655 <        register BYTE   *l4;
656 <        register int    shift, c;
656 <        int     i;
657 <
655 >        register int    i;
656 >                                                        /* read scanline */
657          if (getscan(y) < 0)
658                  quiterr("cannot seek for picreadline");
659                                                          /* convert scanline */
660 <        for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) {
661 <                shift = l4[EXP] - COLXS + scale;
662 <                if (shift >= 8) {
663 <                        l3->r = l3->g = l3->b = 255;
664 <                } else if (shift <= -8) {
666 <                        l3->r = l3->g = l3->b = 0;
667 <                } else if (shift > 0) {
668 <                        c = l4[RED] << shift;
669 <                        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 <                }
660 >        normcolrs(scanline, xmax, scale);
661 >        for (i = 0; i < xmax; i++) {
662 >                l3[i].r = scanline[i][RED];
663 >                l3[i].g = scanline[i][GRN];
664 >                l3[i].b = scanline[i][BLU];
665          }
666   }
667  
# Line 688 | Line 670 | picwriteline(y, l)             /* add 8-bit scanline to image */
670   int  y;
671   pixel  *l;
672   {
673 <        bcopy(l, ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1));
673 >        bcopy((char *)l, (char *)ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1));
674   }
675  
676  
677 < picreadcm(map)                  /* do gamcor correction */
677 > picreadcm(map)                  /* do gamma correction */
678   colormap  map;
679   {
680          extern double  pow();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines