ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/x11image.c
(Generate patch)

Comparing ray/src/px/x11image.c (file contents):
Revision 1.14 by greg, Thu Apr 18 14:35:49 1991 UTC vs.
Revision 2.2 by greg, Thu Dec 19 14:52:27 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1990 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 30 | Line 30 | static char SCCSid[] = "$SunId$ LBL";
30   #include  "pic.h"
31   #include  "x11raster.h"
32   #include  "random.h"
33 + #include  "resolu.h"
34  
35   #define  FONTNAME       "8x13"          /* text font we'll use */
36  
# Line 37 | Line 38 | static char SCCSid[] = "$SunId$ LBL";
38  
39   #define  BORWIDTH       5               /* border width */
40  
41 + #define  ICONSIZ        (8*10)          /* maximum icon dimension (even 8) */
42 +
43   #define  ourscreen      DefaultScreen(thedisplay)
44   #define  ourblack       BlackPixel(thedisplay,ourscreen)
45   #define  ourwhite       WhitePixel(thedisplay,ourscreen)
# Line 68 | Line 71 | int  gotview = 0;                      /* got parameters from file */
71  
72   COLR  *scanline;                        /* scan line buffer */
73  
74 < int  xmax, ymax;                        /* picture resolution */
74 > RESOLU  inpres;                         /* input resolution and ordering */
75 > int  xmax, ymax;                        /* picture dimensions */
76   int  width, height;                     /* window size */
77   char  *fname = NULL;                    /* input file name */
78   FILE  *fin = stdin;                     /* input file */
# Line 90 | Line 94 | struct {
94  
95   char  *geometry = NULL;                 /* geometry specification */
96  
97 + char  icondata[ICONSIZ*ICONSIZ/8];      /* icon bitmap data */
98 + int  iconwidth = 0, iconheight = 0;
99 +
100   char  *progname;
101  
102   char  errmsg[128];
# Line 98 | Line 105 | extern long  ftell();
105  
106   extern char  *malloc(), *calloc();
107  
108 < extern double  atof(), pow(), log();
108 > extern double  pow(), log();
109  
110   Display  *thedisplay;
111  
# Line 160 | Line 167 | char  *argv[];
167                                  /* get header */
168          getheader(fin, headline, NULL);
169                                  /* get picture dimensions */
170 <        if (wrongformat || fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR))
170 >        if (wrongformat || !fgetsresolu(&inpres, fin))
171                  quiterr("bad picture format");
172 +        xmax = scanlen(&inpres);
173 +        ymax = numscans(&inpres);
174                                  /* set view parameters */
175          if (gotview && setview(&ourview) != NULL)
176                  gotview = 0;
# Line 204 | Line 213 | char  *s;
213  
214   init()                  /* get data and open window */
215   {
216 +        XWMHints        ourxwmhints;
217          XSetWindowAttributes    ourwinattr;
218          XSizeHints  oursizhints;
219          register int  i;
# Line 240 | Line 250 | init()                 /* get data and open window */
250          XSetFont(thedisplay, ourgc, fontid);
251          revgc = XCreateGC(thedisplay, wind, 0, 0);
252          XSetFunction(thedisplay, revgc, GXinvert);
243        XStoreName(thedisplay, wind, fname == NULL ? progname : fname);
253          XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay,
254                          XC_diamond_cross));
255 +        XStoreName(thedisplay, wind, fname == NULL ? progname : fname);
256          if (geometry != NULL) {
257                  bzero((char *)&oursizhints, sizeof(oursizhints));
258                  i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y,
# Line 266 | Line 276 | init()                 /* get data and open window */
276                  }
277                  XSetNormalHints(thedisplay, wind, &oursizhints);
278          }
279 +        ourxwmhints.flags = InputHint|IconPixmapHint;
280 +        ourxwmhints.input = True;
281 +        ourxwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay,
282 +                        wind, icondata, iconwidth, iconheight);
283 +        XSetWMHints(thedisplay, wind, &ourxwmhints);
284          XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask
285                          |ButtonMotionMask|StructureNotifyMask
286                          |KeyPressMask|ExposureMask);
# Line 395 | Line 410 | XKeyPressedEvent  *ekey;
410          XColor  cvx;
411          int  com, n;
412          double  comp;
413 +        FLOAT  hv[2];
414          FVECT  rorg, rdir;
415  
416          n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL);
# Line 417 | Line 433 | XKeyPressedEvent  *ekey;
433                          sprintf(buf, "%.3f", intens(cval)/exposure);
434                          break;
435                  case 'l':                               /* luminance */
436 <                        sprintf(buf, "%.0fn", luminance(cval)/exposure);
436 >                        sprintf(buf, "%.0fL", luminance(cval)/exposure);
437                          break;
438                  case 'c':                               /* color */
439                          comp = pow(2.0, (double)scale);
# Line 443 | Line 459 | XKeyPressedEvent  *ekey;
459                  XStoreColor(thedisplay, ourras->cmap, &cvx);
460                  return(0);
461          case 'p':                               /* position */
462 <                sprintf(buf, "(%d,%d)", ekey->x-xoff, ymax-1-ekey->y+yoff);
462 >                pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff);
463 >                sprintf(buf, "(%d,%d)", (int)(hv[0]*inpres.xr),
464 >                                (int)(hv[1]*inpres.yr));
465                  XDrawImageString(thedisplay, wind, ourgc, ekey->x, ekey->y,
466                                          buf, strlen(buf));
467                  return(0);
# Line 452 | Line 470 | XKeyPressedEvent  *ekey;
470                          XBell(thedisplay, 0);
471                          return(-1);
472                  }
473 <                if (viewray(rorg, rdir, &ourview,
474 <                                (ekey->x-xoff+.5)/xmax,
457 <                                (ymax-1-ekey->y+yoff+.5)/ymax) < 0)
473 >                pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff);
474 >                if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0)
475                          return(-1);
476                  printf("%e %e %e ", rorg[0], rorg[1], rorg[2]);
477                  printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]);
# Line 569 | Line 586 | int  x0, y0, x1, y1;
586   avgbox(clr)                             /* average color over current box */
587   COLOR  clr;
588   {
589 +        static COLOR  lc;
590 +        static int  ll, lr, lt, lb;
591          int  left, right, top, bottom;
592          int  y;
593          double  d;
# Line 592 | Line 611 | COLOR  clr;
611                  bottom = ymax;
612          if (top >= bottom)
613                  return(-1);
614 +        if (left == ll && right == lr && top == lt && bottom == lb) {
615 +                copycolor(clr, lc);
616 +                return;
617 +        }
618          for (y = top; y < bottom; y++) {
619                  if (getscan(y) == -1)
620                          return(-1);
# Line 602 | Line 625 | COLOR  clr;
625          }
626          d = 1.0/((right-left)*(bottom-top));
627          scalecolor(clr, d);
628 +        ll = left; lr = right; lt = top; lb = bottom;
629 +        copycolor(lc, clr);
630          return(0);
631   }
632  
# Line 610 | Line 635 | getmono()                      /* get monochrome data */
635   {
636          register unsigned char  *dp;
637          register int    x, err;
638 <        int     y;
638 >        int     y, errp;
639          short   *cerr;
640  
641          if ((cerr = (short *)calloc(xmax,sizeof(short))) == NULL)
# Line 620 | Line 645 | getmono()                      /* get monochrome data */
645                  if (getscan(y) < 0)
646                          quiterr("seek error in getmono");
647                  normcolrs(scanline, xmax, scale);
648 +                add2icon(y, scanline);
649                  err = 0;
650                  for (x = 0; x < xmax; x++) {
651                          if (!(x&7))
652                                  *++dp = 0;
653 +                        errp = err;
654                          err += normbright(scanline[x]) + cerr[x];
655                          if (err > 127)
656                                  err -= 255;
657                          else
658                                  *dp |= 1<<(7-(x&07));
659 <                        cerr[x] = err >>= 1;
659 >                        err /= 3;
660 >                        cerr[x] = err + errp;
661                  }
662          }
663          free((char *)cerr);
664   }
665  
666  
667 + add2icon(y, scan)               /* add a scanline to our icon data */
668 + int  y;
669 + COLR  *scan;
670 + {
671 +        static short  cerr[ICONSIZ];
672 +        static int  ynext;
673 +        static char  *dp;
674 +        register int  err;
675 +        register int    x, ti;
676 +        int  errp;
677 +
678 +        if (iconheight == 0) {          /* initialize */
679 +                if (xmax <= ICONSIZ && ymax <= ICONSIZ) {
680 +                        iconwidth = xmax;
681 +                        iconheight = ymax;
682 +                } else if (xmax > ymax) {
683 +                        iconwidth = ICONSIZ;
684 +                        iconheight = ICONSIZ*ymax/xmax;
685 +                        if (iconheight < 1)
686 +                                iconheight = 1;
687 +                } else {
688 +                        iconwidth = ICONSIZ*xmax/ymax;
689 +                        if (iconwidth < 1)
690 +                                iconwidth = 1;
691 +                        iconheight = ICONSIZ;
692 +                }
693 +                ynext = 0;
694 +                dp = icondata - 1;
695 +        }
696 +        if (y < ynext*ymax/iconheight)  /* skip this one */
697 +                return;
698 +        err = 0;
699 +        for (x = 0; x < iconwidth; x++) {
700 +                if (!(x&7))
701 +                        *++dp = 0;
702 +                errp = err;
703 +                ti = x*xmax/iconwidth;
704 +                err += normbright(scan[ti]) + cerr[x];
705 +                if (err > 127)
706 +                        err -= 255;
707 +                else
708 +                        *dp |= 1<<(x&07);
709 +                err /= 3;
710 +                cerr[x] = err + errp;
711 +        }
712 +        ynext++;
713 + }
714 +
715 +
716   getfull()                       /* get full (24-bit) data */
717   {
718          int     y;
# Line 651 | Line 728 | getfull()                      /* get full (24-bit) data */
728                  if (scale)
729                          shiftcolrs(scanline, xmax, scale);
730                  colrs_gambs(scanline, xmax);
731 +                add2icon(y, scanline);
732                  for (x = 0; x < xmax; x++) {
733                          *dp++ = scanline[x][RED];
734                          *dp++ = scanline[x][GRN];
# Line 718 | Line 796 | register rgbpixel  *l3;
796                  quiterr("cannot seek for picreadline");
797                                                          /* convert scanline */
798          normcolrs(scanline, xmax, scale);
799 +        add2icon(y, scanline);
800          for (i = 0; i < xmax; i++) {
801                  l3[i].r = scanline[i][RED];
802                  l3[i].g = scanline[i][GRN];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines