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.51 by gwlarson, Mon Feb 9 14:37:09 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  "tonemap.h"
33   #include  "view.h"
34   #include  "x11raster.h"
# Line 45 | Line 47 | static char SCCSid[] = "$SunId$ LBL";
47  
48   #define  ICONSIZ        (8*10)          /* maximum icon dimension (even 8) */
49  
50 + #define  FIXWEIGHT      20              /* weight to add for fixation points */
51 +
52   #define  ourscreen      DefaultScreen(thedisplay)
53   #define  ourroot        RootWindow(thedisplay,ourscreen)
54  
# Line 76 | Line 80 | int  sequential = 0;                   /* display images in sequence *
80   char  *tout = "od";                     /* output of 't' command */
81   int  tinterv = 0;                       /* interval between mouse reports */
82  
83 < int  tmflags = -1;                      /* tone mapping flags (-1 for none) */
83 > int  tmflags = TM_F_LINEAR;             /* tone mapping flags */
84  
85   VIEW  ourview = STDVIEW;                /* image view parameters */
86   int  gotview = 0;                       /* got parameters from file */
# Line 176 | Line 180 | char  *argv[];
180                                  break;
181                          case 'e':                       /* exposure comp. */
182                                  i++;
183 <                                if (!strcmp(argv[i], "auto")) {
183 >                                if (argv[i][0] == 'a') {
184                                          tmflags = TM_F_CAMERA;
185                                          break;
186                                  }
187 <                                if (!strcmp(argv[i], "human")) {
187 >                                if (argv[i][0] == 'h') {
188                                          tmflags = TM_F_HUMAN;
189                                          break;
190                                  }
# Line 689 | Line 693 | XKeyPressedEvent  *ekey;
693          case '\r':
694          case 'l':
695          case 'c':                               /* value */
696 <                if (avgbox(cval) == -1)
696 >                if (!avgbox(cval))
697                          return(-1);
698                  switch (com) {
699                  case '\n':
# Line 731 | Line 735 | XKeyPressedEvent  *ekey;
735                  return(0);
736          case 't':                               /* trace */
737                  return(traceray(ekey->x, ekey->y));
738 +        case 'a':                               /* auto exposure */
739 +                if (fname == NULL)
740 +                        return(-1);
741 +                tmflags = TM_F_CAMERA;
742 +                strcpy(buf, "auto exposure...");
743 +                goto remap;
744 +        case 'h':                               /* human response */
745 +                if (fname == NULL)
746 +                        return(-1);
747 +                tmflags = TM_F_HUMAN;
748 +                strcpy(buf, "human exposure...");
749 +                goto remap;
750          case '=':                               /* adjust exposure */
751          case '@':                               /* adaptation level */
752 <                if (avgbox(cval) == -1)
752 >                if (!avgbox(cval))
753                          return(-1);
754                  comp = bright(cval);
755                  if (comp < 1e-20) {
# Line 747 | Line 763 | XKeyPressedEvent  *ekey;
763                          comp = .5/comp;
764                  comp = log(comp)/.69315 - scale;
765                  n = comp < 0 ? comp-.5 : comp+.5 ;      /* round */
766 <                if (tmflags != -1)
767 <                        tmflags = -1;           /* turn off tone mapping */
766 >                if (tmflags != TM_F_LINEAR)
767 >                        tmflags = TM_F_LINEAR;  /* turn off tone mapping */
768                  else {
769                          if (n == 0)             /* else check if any change */
770                                  return(0);
# Line 756 | Line 772 | XKeyPressedEvent  *ekey;
772                  }
773                  scale += n;
774                  sprintf(buf, "%+d", scale);
775 +        remap:
776                  XDrawImageString(thedisplay, wind, ourgc,
777                                  box.xmin, box.ymin+box.ysiz, buf, strlen(buf));
778                  XFlush(thedisplay);
# Line 879 | Line 896 | int  x0, y0, x1, y1;
896   }
897  
898  
899 < avgbox(clr)                             /* average color over current box */
900 < COLOR  clr;
899 > int
900 > colavg(scn, n, cavg)
901 > register COLR   *scn;
902 > register int    n;
903 > COLOR   cavg;
904   {
905 <        static COLOR  lc;
906 <        static int  ll, lr, lt, lb;
905 >        COLOR   col;
906 >
907 >        while (n--) {
908 >                colr_color(col, scn++);
909 >                addcolor(cavg, col);
910 >        }
911 > }
912 >
913 >
914 > int
915 > avgbox(cavg)                            /* average color over current box */
916 > COLOR   cavg;
917 > {
918 >        double  d;
919 >        register int    rval;
920 >
921 >        setcolor(cavg, 0., 0., 0.);
922 >        rval = dobox(colavg, (char *)cavg);
923 >        if (rval > 0) {
924 >                d = 1./rval;
925 >                scalecolor(cavg, d);
926 >        }
927 >        return(rval);
928 > }
929 >
930 >
931 > int
932 > dobox(f, p)                             /* run function over box */
933 > int     (*f)();                 /* function to call for each subscan */
934 > char    *p;                     /* pointer to private data */
935 > {
936          int  left, right, top, bottom;
937          int  y;
889        double  d;
890        COLOR  ctmp;
891        register int  x;
938  
893        setcolor(clr, 0.0, 0.0, 0.0);
939          left = box.xmin - xoff;
940          right = left + box.xsiz;
941          if (left < 0)
# Line 898 | Line 943 | COLOR  clr;
943          if (right > xmax)
944                  right = xmax;
945          if (left >= right)
946 <                return(-1);
946 >                return(0);
947          top = box.ymin - yoff;
948          bottom = top + box.ysiz;
949          if (top < 0)
# Line 906 | Line 951 | COLOR  clr;
951          if (bottom > ymax)
952                  bottom = ymax;
953          if (top >= bottom)
909                return(-1);
910        if (left == ll && right == lr && top == lt && bottom == lb) {
911                copycolor(clr, lc);
954                  return(0);
913        }
955          for (y = top; y < bottom; y++) {
956                  if (getscan(y) == -1)
957                          return(-1);
958 <                for (x = left; x < right; x++) {
918 <                        colr_color(ctmp, scanline[x]);
919 <                        addcolor(clr, ctmp);
920 <                }
958 >                (*f)(scanline+left, right-left, p);
959          }
960 <        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);
960 >        return((right-left)*(bottom-top));
961   }
962  
963  
964 + int
965 + addfix(scn, n)                  /* add fixation points to histogram */
966 + COLR    *scn;
967 + int     n;
968 + {
969 +        if (tmCvColrs(lscan, TM_NOCHROM, scn, n))
970 +                goto tmerr;
971 +        if (tmAddHisto(lscan, n, FIXWEIGHT))
972 +                goto tmerr;
973 +        return;
974 + tmerr:
975 +        quiterr("tone mapping error");
976 + }
977 +
978 +
979   make_tonemap()                  /* initialize tone mapping */
980   {
981 <        int  y;
981 >        int  flags, y;
982  
983 <        if (tmflags != -1 && fname == NULL) {
983 >        if (tmflags != TM_F_LINEAR && fname == NULL) {
984                  fprintf(stderr, "%s: cannot adjust tone of standard input\n",
985                                  progname);
986 <                tmflags = -1;
986 >                tmflags = TM_F_LINEAR;
987          }
988 <        if (tmflags == -1) {
988 >        if (tmflags == TM_F_LINEAR) {   /* linear with clamping */
989                  setcolrcor(pow, 1.0/gamcor);
990                  return;
991          }
992 <        if (greyscale)
993 <                tmflags |= TM_F_BW;
994 <                                        /* initialize tm library */
995 <        if (tmInit(tmflags, stdprims, gamcor) == NULL)
996 <                goto memerr;
997 <        if (tmSetSpace(stdprims, WHTEFFICACY/exposure))
998 <                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)
992 >        flags = tmflags;                /* histogram adjustment */
993 >        if (greyscale) flags |= TM_F_BW;
994 >        if (tmTop != NULL) {            /* reuse old histogram if one */
995 >                tmDone(tmTop);
996 >                tmTop->flags = flags;
997 >        } else {                        /* else initialize */
998 >                if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL)
999                          goto memerr;
1000 <        } else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax)) == NULL)
1001 <                goto memerr;
1002 <                                        /* compute picture histogram */
1003 <        for (y = 0; y < ymax; y++) {
1004 <                getscan(y);
1005 <                if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax))
1000 >                if (greyscale) {
1001 >                        cscan = TM_NOCHROM;
1002 >                        if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL)
1003 >                                goto memerr;
1004 >                } else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax))
1005 >                                == NULL)
1006 >                        goto memerr;
1007 >                                                /* initialize tm library */
1008 >                if (tmInit(flags, stdprims, gamcor) == NULL)
1009 >                        goto memerr;
1010 >                if (tmSetSpace(stdprims, WHTEFFICACY/exposure))
1011                          goto tmerr;
1012 <                if (tmAddHisto(lscan, xmax, 1))
1013 <                        goto tmerr;
1012 >                                                /* compute picture histogram */
1013 >                for (y = 0; y < ymax; y++) {
1014 >                        getscan(y);
1015 >                        if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax))
1016 >                                goto tmerr;
1017 >                        if (tmAddHisto(lscan, xmax, 1))
1018 >                                goto tmerr;
1019 >                }
1020          }
1021 <                                        /* compute tone mapping */
1021 >        tmDup();                        /* add fixations to duplicate map */
1022 >        dobox(addfix, NULL);
1023 >                                        /* (re)compute tone mapping */
1024          if (tmComputeMapping(gamcor, 0., 0.))
1025                  goto tmerr;
970        free((char *)lscan);
1026          return;
1027   memerr:
1028          quiterr("out of memory in make_tonemap");
# Line 982 | Line 1037 | int  len;
1037   {
1038          register BYTE  *ps;
1039  
1040 <        if (tmflags == -1) {
1040 >        if (tmflags == TM_F_LINEAR) {
1041                  if (scale)
1042                          shiftcolrs(scn, len, scale);
1043                  colrs_gambs(scn, len);
# Line 995 | Line 1050 | int  len;
1050          if (tmMapPixels(pscan, lscan, cscan, len))
1051                  goto tmerr;
1052          ps = pscan;
1053 <        if (tmflags & TM_F_BW)
1053 >        if (greyscale)
1054                  while (len--) {
1055                          scn[0][RED] = scn[0][GRN] = scn[0][BLU] = *ps++;
1056                          scn[0][EXP] = COLXS;
# Line 1015 | Line 1070 | tmerr:
1070   }
1071  
1072  
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
1073   getmono()                       /* get monochrome data */
1074   {
1075          register unsigned char  *dp;
# Line 1133 | Line 1178 | getfull()                      /* get full (24-bit) data */
1178                                          (unsigned int4)scanline[x][GRN] << 8 |
1179                                          (unsigned int4)scanline[x][BLU] << 16 ;
1180          }
1136        done_tonemap();
1181   }
1182  
1183  
# Line 1161 | Line 1205 | getgrey()                      /* get greyscale data */
1205          for (x = 0; x < maxcolors; x++)
1206                  clrtab[x][RED] = clrtab[x][GRN] =
1207                          clrtab[x][BLU] = ((int4)x*256 + 128)/maxcolors;
1164        done_tonemap();
1208   }
1209  
1210  
# Line 1194 | Line 1237 | getmapped()                    /* get color-mapped data */
1237                  else
1238                          map_colrs(ourdata+y*xmax, scanline, xmax);
1239          }
1197        done_tonemap();
1240   }
1241  
1242  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines