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 2.44 by greg, Tue Apr 15 16:53:58 1997 UTC vs.
Revision 2.52 by gwlarson, Mon Aug 17 18:00:11 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1997 Regents of the University of California */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4 < static char SCCSid[] = "$SunId$ LBL";
4 > static char SCCSid[] = "$SunId$ SGI";
5   #endif
6  
7   /*
# Line 27 | Line 27 | static char SCCSid[] = "$SunId$ LBL";
27   #include  <X11/Xutil.h>
28   #include  <X11/Xatom.h>
29  
30 + #undef  NOPROTO
31 + #define NOPROTO 1
32 + #include  "color.h"
33   #include  "tonemap.h"
34   #include  "view.h"
35   #include  "x11raster.h"
36   #include  "random.h"
37   #include  "resolu.h"
38  
36 #ifndef  int4
37 #define  int4           int             /* most int's are 32-bit */
38 #endif
39
39   #define  FONTNAME       "8x13"          /* text font we'll use */
40  
41   #define  CTRL(c)        ((c)-'@')
# Line 45 | Line 44 | static char SCCSid[] = "$SunId$ LBL";
44  
45   #define  ICONSIZ        (8*10)          /* maximum icon dimension (even 8) */
46  
47 + #define  FIXWEIGHT      20              /* weight to add for fixation points */
48 +
49   #define  ourscreen      DefaultScreen(thedisplay)
50   #define  ourroot        RootWindow(thedisplay,ourscreen)
51  
# Line 76 | Line 77 | int  sequential = 0;                   /* display images in sequence *
77   char  *tout = "od";                     /* output of 't' command */
78   int  tinterv = 0;                       /* interval between mouse reports */
79  
80 < int  tmflags = -1;                      /* tone mapping flags (-1 for none) */
80 > int  tmflags = TM_F_LINEAR;             /* tone mapping flags */
81  
82   VIEW  ourview = STDVIEW;                /* image view parameters */
83   int  gotview = 0;                       /* got parameters from file */
# Line 176 | Line 177 | char  *argv[];
177                                  break;
178                          case 'e':                       /* exposure comp. */
179                                  i++;
180 <                                if (!strcmp(argv[i], "auto")) {
180 >                                if (argv[i][0] == 'a') {
181                                          tmflags = TM_F_CAMERA;
182                                          break;
183                                  }
184 <                                if (!strcmp(argv[i], "human")) {
184 >                                if (argv[i][0] == 'h') {
185                                          tmflags = TM_F_HUMAN;
186                                          break;
187                                  }
# Line 689 | Line 690 | XKeyPressedEvent  *ekey;
690          case '\r':
691          case 'l':
692          case 'c':                               /* value */
693 <                if (avgbox(cval) == -1)
693 >                if (!avgbox(cval))
694                          return(-1);
695                  switch (com) {
696                  case '\n':
# Line 731 | Line 732 | XKeyPressedEvent  *ekey;
732                  return(0);
733          case 't':                               /* trace */
734                  return(traceray(ekey->x, ekey->y));
735 +        case 'a':                               /* auto exposure */
736 +                if (fname == NULL)
737 +                        return(-1);
738 +                tmflags = TM_F_CAMERA;
739 +                strcpy(buf, "auto exposure...");
740 +                goto remap;
741 +        case 'h':                               /* human response */
742 +                if (fname == NULL)
743 +                        return(-1);
744 +                tmflags = TM_F_HUMAN;
745 +                strcpy(buf, "human exposure...");
746 +                goto remap;
747          case '=':                               /* adjust exposure */
748          case '@':                               /* adaptation level */
749 <                if (avgbox(cval) == -1)
749 >                if (!avgbox(cval))
750                          return(-1);
751                  comp = bright(cval);
752                  if (comp < 1e-20) {
# Line 747 | Line 760 | XKeyPressedEvent  *ekey;
760                          comp = .5/comp;
761                  comp = log(comp)/.69315 - scale;
762                  n = comp < 0 ? comp-.5 : comp+.5 ;      /* round */
763 <                if (tmflags != -1)
764 <                        tmflags = -1;           /* turn off tone mapping */
763 >                if (tmflags != TM_F_LINEAR)
764 >                        tmflags = TM_F_LINEAR;  /* turn off tone mapping */
765                  else {
766                          if (n == 0)             /* else check if any change */
767                                  return(0);
# Line 756 | Line 769 | XKeyPressedEvent  *ekey;
769                  }
770                  scale += n;
771                  sprintf(buf, "%+d", scale);
772 +        remap:
773                  XDrawImageString(thedisplay, wind, ourgc,
774                                  box.xmin, box.ymin+box.ysiz, buf, strlen(buf));
775                  XFlush(thedisplay);
# Line 879 | Line 893 | int  x0, y0, x1, y1;
893   }
894  
895  
896 < avgbox(clr)                             /* average color over current box */
897 < COLOR  clr;
896 > int
897 > colavg(scn, n, cavg)
898 > register COLR   *scn;
899 > register int    n;
900 > COLOR   cavg;
901   {
902 <        static COLOR  lc;
903 <        static int  ll, lr, lt, lb;
902 >        COLOR   col;
903 >
904 >        while (n--) {
905 >                colr_color(col, scn++);
906 >                addcolor(cavg, col);
907 >        }
908 > }
909 >
910 >
911 > int
912 > avgbox(cavg)                            /* average color over current box */
913 > COLOR   cavg;
914 > {
915 >        double  d;
916 >        register int    rval;
917 >
918 >        setcolor(cavg, 0., 0., 0.);
919 >        rval = dobox(colavg, (char *)cavg);
920 >        if (rval > 0) {
921 >                d = 1./rval;
922 >                scalecolor(cavg, d);
923 >        }
924 >        return(rval);
925 > }
926 >
927 >
928 > int
929 > dobox(f, p)                             /* run function over box */
930 > int     (*f)();                 /* function to call for each subscan */
931 > char    *p;                     /* pointer to private data */
932 > {
933          int  left, right, top, bottom;
934          int  y;
889        double  d;
890        COLOR  ctmp;
891        register int  x;
935  
893        setcolor(clr, 0.0, 0.0, 0.0);
936          left = box.xmin - xoff;
937          right = left + box.xsiz;
938          if (left < 0)
# Line 898 | Line 940 | COLOR  clr;
940          if (right > xmax)
941                  right = xmax;
942          if (left >= right)
943 <                return(-1);
943 >                return(0);
944          top = box.ymin - yoff;
945          bottom = top + box.ysiz;
946          if (top < 0)
# Line 906 | Line 948 | COLOR  clr;
948          if (bottom > ymax)
949                  bottom = ymax;
950          if (top >= bottom)
909                return(-1);
910        if (left == ll && right == lr && top == lt && bottom == lb) {
911                copycolor(clr, lc);
951                  return(0);
913        }
952          for (y = top; y < bottom; y++) {
953                  if (getscan(y) == -1)
954                          return(-1);
955 <                for (x = left; x < right; x++) {
918 <                        colr_color(ctmp, scanline[x]);
919 <                        addcolor(clr, ctmp);
920 <                }
955 >                (*f)(scanline+left, right-left, p);
956          }
957 <        d = 1.0/((right-left)*(bottom-top));
923 <        scalecolor(clr, d);
924 <        ll = left; lr = right; lt = top; lb = bottom;
925 <        copycolor(lc, clr);
926 <        return(0);
957 >        return((right-left)*(bottom-top));
958   }
959  
960  
961 + int
962 + addfix(scn, n)                  /* add fixation points to histogram */
963 + COLR    *scn;
964 + int     n;
965 + {
966 +        if (tmCvColrs(lscan, TM_NOCHROM, scn, n))
967 +                goto tmerr;
968 +        if (tmAddHisto(lscan, n, FIXWEIGHT))
969 +                goto tmerr;
970 +        return;
971 + tmerr:
972 +        quiterr("tone mapping error");
973 + }
974 +
975 +
976   make_tonemap()                  /* initialize tone mapping */
977   {
978 <        int  y;
978 >        int  flags, y;
979  
980 <        if (tmflags != -1 && fname == NULL) {
980 >        if (tmflags != TM_F_LINEAR && fname == NULL) {
981                  fprintf(stderr, "%s: cannot adjust tone of standard input\n",
982                                  progname);
983 <                tmflags = -1;
983 >                tmflags = TM_F_LINEAR;
984          }
985 <        if (tmflags == -1) {
985 >        if (tmflags == TM_F_LINEAR) {   /* linear with clamping */
986                  setcolrcor(pow, 1.0/gamcor);
987                  return;
988          }
989 <        if (greyscale)
990 <                tmflags |= TM_F_BW;
991 <                                        /* initialize tm library */
992 <        if (tmInit(tmflags, stdprims, gamcor) == NULL)
993 <                goto memerr;
994 <        if (tmSetSpace(stdprims, WHTEFFICACY/exposure))
995 <                goto tmerr;
950 <                                        /* allocate encoding buffers */
951 <        if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL)
952 <                goto memerr;
953 <        if (tmflags & TM_F_BW) {
954 <                cscan = TM_NOCHROM;
955 <                if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL)
989 >        flags = tmflags;                /* histogram adjustment */
990 >        if (greyscale) flags |= TM_F_BW;
991 >        if (tmTop != NULL) {            /* reuse old histogram if one */
992 >                tmDone(tmTop);
993 >                tmTop->flags = flags;
994 >        } else {                        /* else initialize */
995 >                if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL)
996                          goto memerr;
997 <        } else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax)) == NULL)
998 <                goto memerr;
999 <                                        /* compute picture histogram */
1000 <        for (y = 0; y < ymax; y++) {
1001 <                getscan(y);
1002 <                if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax))
997 >                if (greyscale) {
998 >                        cscan = TM_NOCHROM;
999 >                        if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL)
1000 >                                goto memerr;
1001 >                } else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax))
1002 >                                == NULL)
1003 >                        goto memerr;
1004 >                                                /* initialize tm library */
1005 >                if (tmInit(flags, stdprims, gamcor) == NULL)
1006 >                        goto memerr;
1007 >                if (tmSetSpace(stdprims, WHTEFFICACY/exposure))
1008                          goto tmerr;
1009 <                if (tmAddHisto(lscan, xmax, 1))
1010 <                        goto tmerr;
1009 >                                                /* compute picture histogram */
1010 >                for (y = 0; y < ymax; y++) {
1011 >                        getscan(y);
1012 >                        if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax))
1013 >                                goto tmerr;
1014 >                        if (tmAddHisto(lscan, xmax, 1))
1015 >                                goto tmerr;
1016 >                }
1017          }
1018 <                                        /* compute tone mapping */
1018 >        tmDup();                        /* add fixations to duplicate map */
1019 >        dobox(addfix, NULL);
1020 >                                        /* (re)compute tone mapping */
1021          if (tmComputeMapping(gamcor, 0., 0.))
1022                  goto tmerr;
970        free((char *)lscan);
1023          return;
1024   memerr:
1025          quiterr("out of memory in make_tonemap");
# Line 982 | Line 1034 | int  len;
1034   {
1035          register BYTE  *ps;
1036  
1037 <        if (tmflags == -1) {
1037 >        if (tmflags == TM_F_LINEAR) {
1038                  if (scale)
1039                          shiftcolrs(scn, len, scale);
1040                  colrs_gambs(scn, len);
# Line 995 | Line 1047 | int  len;
1047          if (tmMapPixels(pscan, lscan, cscan, len))
1048                  goto tmerr;
1049          ps = pscan;
1050 <        if (tmflags & TM_F_BW)
1050 >        if (greyscale)
1051                  while (len--) {
1052                          scn[0][RED] = scn[0][GRN] = scn[0][BLU] = *ps++;
1053                          scn[0][EXP] = COLXS;
# Line 1015 | Line 1067 | tmerr:
1067   }
1068  
1069  
1018 done_tonemap()                  /* clean up after tone mapping is done */
1019 {
1020        if (tmflags == -1 || tmTop == NULL)
1021                return;
1022        tmDone(tmTop);                  /* clear old mapping */
1023        free((char *)lscan);            /* free memory */
1024        free((char *)pscan);
1025 }
1026
1027
1070   getmono()                       /* get monochrome data */
1071   {
1072          register unsigned char  *dp;
# Line 1133 | Line 1175 | getfull()                      /* get full (24-bit) data */
1175                                          (unsigned int4)scanline[x][GRN] << 8 |
1176                                          (unsigned int4)scanline[x][BLU] << 16 ;
1177          }
1136        done_tonemap();
1178   }
1179  
1180  
# Line 1161 | Line 1202 | getgrey()                      /* get greyscale data */
1202          for (x = 0; x < maxcolors; x++)
1203                  clrtab[x][RED] = clrtab[x][GRN] =
1204                          clrtab[x][BLU] = ((int4)x*256 + 128)/maxcolors;
1164        done_tonemap();
1205   }
1206  
1207  
# Line 1194 | Line 1234 | getmapped()                    /* get color-mapped data */
1234                  else
1235                          map_colrs(ourdata+y*xmax, scanline, xmax);
1236          }
1197        done_tonemap();
1237   }
1238  
1239  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines