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.48 by greg, Tue Apr 22 10:01:43 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 29 | Line 29 | static char SCCSid[] = "$SunId$ LBL";
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  
38 #ifndef  int4
39 #define  int4           int             /* most int's are 32-bit */
40 #endif
41
39   #define  FONTNAME       "8x13"          /* text font we'll use */
40  
41   #define  CTRL(c)        ((c)-'@')
# Line 47 | 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 78 | 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 691 | 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 734 | Line 733 | XKeyPressedEvent  *ekey;
733          case 't':                               /* trace */
734                  return(traceray(ekey->x, ekey->y));
735          case 'a':                               /* auto exposure */
736 <                if (tmflags == TM_F_CAMERA)
737 <                        return(0);
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 (tmflags == TM_F_HUMAN)
743 <                        return(0);
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 761 | 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 894 | 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;
904        double  d;
905        COLOR  ctmp;
906        register int  x;
935  
908        setcolor(clr, 0.0, 0.0, 0.0);
936          left = box.xmin - xoff;
937          right = left + box.xsiz;
938          if (left < 0)
# Line 913 | 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 921 | Line 948 | COLOR  clr;
948          if (bottom > ymax)
949                  bottom = ymax;
950          if (top >= bottom)
924                return(-1);
925        if (left == ll && right == lr && top == lt && bottom == lb) {
926                copycolor(clr, lc);
951                  return(0);
928        }
952          for (y = top; y < bottom; y++) {
953                  if (getscan(y) == -1)
954                          return(-1);
955 <                for (x = left; x < right; x++) {
933 <                        colr_color(ctmp, scanline[x]);
934 <                        addcolor(clr, ctmp);
935 <                }
955 >                (*f)(scanline+left, right-left, p);
956          }
957 <        d = 1.0/((right-left)*(bottom-top));
938 <        scalecolor(clr, d);
939 <        ll = left; lr = right; lt = top; lb = bottom;
940 <        copycolor(lc, clr);
941 <        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  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 (tmTop != NULL)              /* already initialized? */
959 <                return;
960 <        flags = tmflags;
989 >        flags = tmflags;                /* histogram adjustment */
990          if (greyscale) flags |= TM_F_BW;
991 <                                        /* initialize tm library */
992 <        if (tmInit(flags, stdprims, gamcor) == NULL)
993 <                goto memerr;
994 <        if (tmSetSpace(stdprims, WHTEFFICACY/exposure))
995 <                goto tmerr;
967 <                                        /* allocate encoding buffers */
968 <        if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL)
969 <                goto memerr;
970 <        if (greyscale) {
971 <                cscan = TM_NOCHROM;
972 <                if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL)
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;
1023          return;
# Line 998 | 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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines