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.37 by greg, Fri Jun 10 12:51:21 1994 UTC vs.
Revision 2.55 by gwlarson, Tue Jul 20 14:07:38 1999 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1993 Regents of the University of California */
1 > /* Copyright (c) 1999 Regents of the University of California */
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 #ifdef  __alpha
37 #define  int4           int
38 #endif
39 #ifndef  int4
40 #define  int4           long
41 #endif
42
39   #define  FONTNAME       "8x13"          /* text font we'll use */
40  
41   #define  CTRL(c)        ((c)-'@')
# Line 48 | 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 74 | Line 72 | int  xoff = 0;                         /* x image offset */
72   int  yoff = 0;                          /* y image offset */
73  
74   int  parent = 0;                        /* number of children, -1 if child */
75 + int  sequential = 0;                    /* display images in sequence */
76  
77 + char  *tout = "od";                     /* output of 't' command */
78 + int  tinterv = 0;                       /* interval between mouse reports */
79 +
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 */
84  
85   COLR  *scanline;                        /* scan line buffer */
86 + TMbright  *lscan;                       /* encoded luminance scanline */
87 + BYTE  *cscan;                           /* encoded chroma scanline */
88 + BYTE  *pscan;                           /* compute pixel scanline */
89  
90   RESOLU  inpres;                         /* input resolution and ordering */
91   int  xmax, ymax;                        /* picture dimensions */
92   int  width, height;                     /* window size */
93   char  *fname = NULL;                    /* input file name */
94 < FILE  *fin = stdin;                     /* input file */
94 > FILE  *fin = NULL;                      /* input file */
95   long  *scanpos = NULL;                  /* scan line positions in file */
96   int  cury = 0;                          /* current scan location */
97  
# Line 136 | Line 143 | char  *argv[];
143          int  pid;
144          
145          progname = argv[0];
146 +        fin = stdin;
147  
148          for (i = 1; i < argc; i++)
149                  if (argv[i][0] == '-')
150                          switch (argv[i][1]) {
151 <                        case 'c':
151 >                        case 'c':                       /* number of colors */
152                                  maxcolors = atoi(argv[++i]);
153                                  break;
154 <                        case 'b':
154 >                        case 'b':                       /* greyscale only */
155                                  greyscale = !greyscale;
156                                  break;
157 <                        case 'm':
157 >                        case 'm':                       /* monochrome */
158 >                                greyscale = 1;
159                                  maxcolors = 2;
160                                  break;
161 <                        case 'd':
161 >                        case 'd':                       /* display or dither */
162                                  if (argv[i][2] == 'i')
163                                          dispname = argv[++i];
164                                  else
165                                          dither = !dither;
166                                  break;
167 <                        case 'f':
167 >                        case 'f':                       /* save pixmap */
168                                  fast = !fast;
169                                  break;
170 <                        case 'e':
171 <                                if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
170 >                        case 's':                       /* one at a time */
171 >                                sequential = !sequential;
172 >                                break;
173 >                        case 'o':                       /* 't' output */
174 >                                tout = argv[i]+2;
175 >                                break;
176 >                        case 't':                       /* msec interval */
177 >                                tinterv = atoi(argv[++i]);
178 >                                break;
179 >                        case 'e':                       /* exposure comp. */
180 >                                i++;
181 >                                if (argv[i][0] == 'a') {
182 >                                        tmflags = TM_F_CAMERA;
183 >                                        break;
184 >                                }
185 >                                if (argv[i][0] == 'h') {
186 >                                        tmflags = TM_F_HUMAN;
187 >                                        break;
188 >                                }
189 >                                if (argv[i][0] != '+' && argv[i][0] != '-')
190                                          goto userr;
191 <                                scale = atoi(argv[++i]);
191 >                                scale = atoi(argv[i]);
192                                  break;
193 <                        case 'g':
193 >                        case 'g':                       /* gamma comp. */
194                                  if (argv[i][2] == 'e')
195                                          geometry = argv[++i];
196                                  else
# Line 214 | Line 241 | char  *argv[];
241  
242          init(argc, argv);                       /* get file and open window */
243  
217        if (parent < 0) {
218                kill(getppid(), SIGCONT);       /* signal parent if child */
219                sigrecv--;
220        }
244          for ( ; ; )
245                  getevent();             /* main loop */
246   userr:
247          fprintf(stderr,
248 < "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops][-g gamcor] pic ..\n",
248 > "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e spec][-g gamcor][-s][-ospec][-t intvl] pic ..\n",
249                          progname);
250          exit(1);
251   }
252  
253  
254 + int
255   headline(s)             /* get relevant info from header */
256   char  *s;
257   {
# Line 235 | Line 259 | char  *s;
259  
260          if (isexpos(s))
261                  exposure *= exposval(s);
262 <        else if (isformat(s)) {
239 <                formatval(fmt, s);
262 >        else if (formatval(fmt, s))
263                  wrongformat = strcmp(fmt, COLRFMT);
264 <        } else if (isview(s) && sscanview(&ourview, s) > 0)
264 >        else if (isview(s) && sscanview(&ourview, s) > 0)
265                  gotview++;
266 +        return(0);
267   }
268  
269  
# Line 276 | Line 300 | char **argv;
300          if (gamstr == NULL)             /* get it from the X server */
301                  gamstr = XGetDefault(thedisplay, "radiance", "gamma");
302          if (gamstr == NULL)             /* get it from the environment */
303 <                gamstr = getenv("GAMMA");
303 >                gamstr = getenv("DISPLAY_GAMMA");
304          if (gamstr != NULL)
305                  gamcor = atof(gamstr);
306                                  /* get best visual for default screen */
# Line 305 | Line 329 | char **argv;
329                  }
330          }
331          /* open window */
332 +        i = CWEventMask|CWCursor|CWBackPixel|CWBorderPixel;
333          ourwinattr.border_pixel = ourwhite;
334          ourwinattr.background_pixel = ourblack;
335 <        ourwinattr.colormap = XCreateColormap(thedisplay, ourroot,
336 <                        ourvis.visual, AllocNone);
335 >        if (ourvis.visual != DefaultVisual(thedisplay,ourscreen)) {
336 >                ourwinattr.colormap = newcmap(thedisplay, ourscreen, ourvis.visual);
337 >                i |= CWColormap;
338 >        }
339          ourwinattr.event_mask = ExposureMask|KeyPressMask|ButtonPressMask|
340                          ButtonReleaseMask|ButtonMotionMask|StructureNotifyMask;
341          ourwinattr.cursor = XCreateFontCursor(thedisplay, XC_diamond_cross);
342          wind = XCreateWindow(thedisplay, ourroot, xszhints.x, xszhints.y,
343                          xszhints.width, xszhints.height, BORWIDTH,
344 <                        ourvis.depth, InputOutput, ourvis.visual, CWEventMask|
345 <                        CWCursor|CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr);
344 >                        ourvis.depth, InputOutput, ourvis.visual,
345 >                        i, &ourwinattr);
346          if (wind == 0)
347                  quiterr("cannot create window");
348          width = xmax;
# Line 353 | Line 380 | char **argv;
380          XSetWMProtocols(thedisplay, wind, &closedownAtom, 1);
381  
382          XMapWindow(thedisplay, wind);
356        return;
383   } /* end of init */
384  
385  
# Line 393 | Line 419 | register XVisualInfo   *v1, *v2;
419                                  return(-1);
420                          if (v1->depth == 32 && v2->depth == 24)
421                                  return(1);
422 <                        return(0);
422 >                                        /* go for maximum depth otherwise */
423 >                        return(v2->depth - v1->depth);
424                  }
425                                          /* don't be too greedy */
426                  if (maxcolors <= 1<<v1->depth && maxcolors <= 1<<v2->depth)
427                          return(v1->depth - v2->depth);
428                  return(v2->depth - v1->depth);
429          }
430 <                                        /* prefer Pseudo when < 24-bit */
430 >                                        /* prefer Pseudo when < 15-bit */
431          if ((v1->class == TrueColor || v1->class == DirectColor) &&
432 <                        v1->depth < 24)
432 >                        v1->depth < 15)
433                  bad1 = 1;
434          if ((v2->class == TrueColor || v2->class == DirectColor) &&
435 <                        v2->depth < 24)
435 >                        v2->depth < 15)
436                  bad2 = -1;
437          if (bad1 | bad2)
438                  return(bad1+bad2);
# Line 516 | Line 543 | getras()                               /* get raster file */
543                          goto fail;
544                  getmono();
545          } else if (ourvis.class == TrueColor | ourvis.class == DirectColor) {
546 <                ourdata = (unsigned char *)malloc(sizeof(int4)*xmax*ymax);
546 >                int  datsiz = ourvis.depth>16 ? sizeof(int4) : sizeof(int2);
547 >                ourdata = (unsigned char *)malloc(datsiz*xmax*ymax);
548                  if (ourdata == NULL)
549                          goto fail;
550 <                ourras = make_raster(thedisplay, &ourvis, sizeof(int4)*8,
551 <                                ourdata, xmax, ymax, 32);
550 >                ourras = make_raster(thedisplay, &ourvis, datsiz*8,
551 >                                ourdata, xmax, ymax, datsiz*8);
552                  if (ourras == NULL)
553                          goto fail;
554                  getfull();
# Line 532 | Line 560 | getras()                               /* get raster file */
560                                  xmax, ymax, 8);
561                  if (ourras == NULL)
562                          goto fail;
563 <                if (greyscale | ourvis.class == StaticGray)
563 >                if (greyscale)
564                          getgrey();
565                  else
566                          getmapped();
# Line 562 | Line 590 | getevent()                             /* process the next event */
590                  map_rcolors(ourras, wind);
591                  if (fast)
592                          make_rpixmap(ourras, wind);
593 +                if (!sequential & parent < 0 & sigrecv == 0) {
594 +                        kill(getppid(), SIGCONT);
595 +                        sigrecv--;
596 +                }
597                  break;
598          case UnmapNotify:
599                  if (!fast)
# Line 574 | Line 606 | getevent()                             /* process the next event */
606          case ButtonPress:
607                  if (xev.xbutton.state & (ShiftMask|ControlMask))
608                          moveimage(&xev.xbutton);
577                else if (xev.xbutton.button == Button2)
578                        traceray(xev.xbutton.x, xev.xbutton.y);
609                  else
610 <                        getbox(&xev.xbutton);
610 >                        switch (xev.xbutton.button) {
611 >                        case Button1:
612 >                                getbox(&xev.xbutton);
613 >                                break;
614 >                        case Button2:
615 >                                traceray(xev.xbutton.x, xev.xbutton.y);
616 >                                break;
617 >                        case Button3:
618 >                                trackrays(&xev.xbutton);
619 >                                break;
620 >                        }
621                  break;
622          case ClientMessage:
623                  if ((xev.xclient.message_type == wmProtocolsAtom) &&
# Line 588 | Line 628 | getevent()                             /* process the next event */
628   }
629  
630  
631 < traceray(xpos, ypos)                    /* print ray corresponding to pixel */
631 > traceray(xpos, ypos)                    /* print requested pixel data */
632   int  xpos, ypos;
633   {
634 +        extern char  *index();
635          FLOAT  hv[2];
636          FVECT  rorg, rdir;
637 +        COLOR  cval;
638 +        register char  *cp;
639  
640 <        if (!gotview) {         /* no view, no can do */
641 <                XBell(thedisplay, 0);
642 <                return(-1);
643 <        }
640 >        box.xmin = xpos; box.xsiz = 1;
641 >        box.ymin = ypos; box.ysiz = 1;
642 >        avgbox(cval);
643 >        scalecolor(cval, 1./exposure);
644          pix2loc(hv, &inpres, xpos-xoff, ypos-yoff);
645 <        if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0)
646 <                return(-1);
647 <        printf("%e %e %e ", rorg[0], rorg[1], rorg[2]);
648 <        printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]);
645 >        if (!gotview || viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0)
646 >                rorg[0] = rorg[1] = rorg[2] =
647 >                rdir[0] = rdir[1] = rdir[2] = 0.;
648 >
649 >        for (cp = tout; *cp; cp++)      /* print what they asked for */
650 >                switch (*cp) {
651 >                case 'o':                       /* origin */
652 >                        printf("%e %e %e ", rorg[0], rorg[1], rorg[2]);
653 >                        break;
654 >                case 'd':                       /* direction */
655 >                        printf("%e %e %e ", rdir[0], rdir[1], rdir[2]);
656 >                        break;
657 >                case 'v':                       /* radiance value */
658 >                        printf("%e %e %e ", colval(cval,RED),
659 >                                        colval(cval,GRN), colval(cval,BLU));
660 >                        break;
661 >                case 'l':                       /* luminance */
662 >                        printf("%e ", luminance(cval));
663 >                        break;
664 >                case 'p':                       /* pixel position */
665 >                        printf("%d %d ", (int)(hv[0]*inpres.xr),
666 >                                        (int)(hv[1]*inpres.yr));
667 >                        break;
668 >                }
669 >        putchar('\n');
670          fflush(stdout);
671          return(0);
672   }
# Line 631 | Line 695 | XKeyPressedEvent  *ekey;
695          case '\r':
696          case 'l':
697          case 'c':                               /* value */
698 <                if (avgbox(cval) == -1)
698 >                if (!avgbox(cval))
699                          return(-1);
700                  switch (com) {
701                  case '\n':
# Line 673 | Line 737 | XKeyPressedEvent  *ekey;
737                  return(0);
738          case 't':                               /* trace */
739                  return(traceray(ekey->x, ekey->y));
740 +        case 'a':                               /* auto exposure */
741 +                if (fname == NULL)
742 +                        return(-1);
743 +                tmflags = TM_F_CAMERA;
744 +                strcpy(buf, "auto exposure...");
745 +                goto remap;
746 +        case 'h':                               /* human response */
747 +                if (fname == NULL)
748 +                        return(-1);
749 +                tmflags = TM_F_HUMAN;
750 +                strcpy(buf, "human exposure...");
751 +                goto remap;
752          case '=':                               /* adjust exposure */
753          case '@':                               /* adaptation level */
754 <                if (avgbox(cval) == -1)
754 >                if (!avgbox(cval))
755                          return(-1);
756                  comp = bright(cval);
757                  if (comp < 1e-20) {
# Line 689 | Line 765 | XKeyPressedEvent  *ekey;
765                          comp = .5/comp;
766                  comp = log(comp)/.69315 - scale;
767                  n = comp < 0 ? comp-.5 : comp+.5 ;      /* round */
768 <                if (n == 0)
769 <                        return(0);
770 <                scale_rcolors(ourras, pow(2.0, (double)n));
768 >                if (tmflags != TM_F_LINEAR)
769 >                        tmflags = TM_F_LINEAR;  /* turn off tone mapping */
770 >                else {
771 >                        if (n == 0)             /* else check if any change */
772 >                                return(0);
773 >                        scale_rcolors(ourras, pow(2.0, (double)n));
774 >                }
775                  scale += n;
776                  sprintf(buf, "%+d", scale);
777 +        remap:
778                  XDrawImageString(thedisplay, wind, ourgc,
779                                  box.xmin, box.ymin+box.ysiz, buf, strlen(buf));
780                  XFlush(thedisplay);
# Line 788 | Line 869 | XButtonPressedEvent  *ebut;
869   }
870  
871  
872 + trackrays(ebut)                         /* trace rays as mouse moves */
873 + XButtonPressedEvent  *ebut;
874 + {
875 +        XEvent  e;
876 +        unsigned long   lastrept;
877 +
878 +        traceray(ebut->x, ebut->y);
879 +        lastrept = ebut->time;
880 +        XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e);
881 +        while (e.type == MotionNotify) {
882 +                if (e.xmotion.time >= lastrept + tinterv) {
883 +                        traceray(e.xmotion.x, e.xmotion.y);
884 +                        lastrept = e.xmotion.time;
885 +                }
886 +                XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e);
887 +        }
888 + }
889 +
890 +
891   revbox(x0, y0, x1, y1)                  /* draw box with reversed lines */
892   int  x0, y0, x1, y1;
893   {
# Line 798 | Line 898 | int  x0, y0, x1, y1;
898   }
899  
900  
901 < avgbox(clr)                             /* average color over current box */
902 < COLOR  clr;
901 > int
902 > colavg(scn, n, cavg)
903 > register COLR   *scn;
904 > register int    n;
905 > COLOR   cavg;
906   {
907 <        static COLOR  lc;
908 <        static int  ll, lr, lt, lb;
907 >        COLOR   col;
908 >
909 >        while (n--) {
910 >                colr_color(col, scn++);
911 >                addcolor(cavg, col);
912 >        }
913 > }
914 >
915 >
916 > int
917 > avgbox(cavg)                            /* average color over current box */
918 > COLOR   cavg;
919 > {
920 >        double  d;
921 >        register int    rval;
922 >
923 >        setcolor(cavg, 0., 0., 0.);
924 >        rval = dobox(colavg, (char *)cavg);
925 >        if (rval > 0) {
926 >                d = 1./rval;
927 >                scalecolor(cavg, d);
928 >        }
929 >        return(rval);
930 > }
931 >
932 >
933 > int
934 > dobox(f, p)                             /* run function over box */
935 > int     (*f)();                 /* function to call for each subscan */
936 > char    *p;                     /* pointer to private data */
937 > {
938          int  left, right, top, bottom;
939          int  y;
808        double  d;
809        COLOR  ctmp;
810        register int  x;
940  
812        setcolor(clr, 0.0, 0.0, 0.0);
941          left = box.xmin - xoff;
942          right = left + box.xsiz;
943          if (left < 0)
# Line 817 | Line 945 | COLOR  clr;
945          if (right > xmax)
946                  right = xmax;
947          if (left >= right)
948 <                return(-1);
948 >                return(0);
949          top = box.ymin - yoff;
950          bottom = top + box.ysiz;
951          if (top < 0)
# Line 825 | Line 953 | COLOR  clr;
953          if (bottom > ymax)
954                  bottom = ymax;
955          if (top >= bottom)
828                return(-1);
829        if (left == ll && right == lr && top == lt && bottom == lb) {
830                copycolor(clr, lc);
956                  return(0);
832        }
957          for (y = top; y < bottom; y++) {
958                  if (getscan(y) == -1)
959                          return(-1);
960 <                for (x = left; x < right; x++) {
961 <                        colr_color(ctmp, scanline[x]);
962 <                        addcolor(clr, ctmp);
960 >                (*f)(scanline+left, right-left, p);
961 >        }
962 >        return((right-left)*(bottom-top));
963 > }
964 >
965 >
966 > int
967 > addfix(scn, n)                  /* add fixation points to histogram */
968 > COLR    *scn;
969 > int     n;
970 > {
971 >        if (tmCvColrs(lscan, TM_NOCHROM, scn, n))
972 >                goto tmerr;
973 >        if (tmAddHisto(lscan, n, FIXWEIGHT))
974 >                goto tmerr;
975 >        return;
976 > tmerr:
977 >        quiterr("tone mapping error");
978 > }
979 >
980 >
981 > make_tonemap()                  /* initialize tone mapping */
982 > {
983 >        int  flags, y;
984 >
985 >        if (tmflags != TM_F_LINEAR && fname == NULL) {
986 >                fprintf(stderr, "%s: cannot adjust tone of standard input\n",
987 >                                progname);
988 >                tmflags = TM_F_LINEAR;
989 >        }
990 >        if (tmflags == TM_F_LINEAR) {   /* linear with clamping */
991 >                setcolrcor(pow, 1.0/gamcor);
992 >                return;
993 >        }
994 >        flags = tmflags;                /* histogram adjustment */
995 >        if (greyscale) flags |= TM_F_BW;
996 >        if (tmTop != NULL) {            /* reuse old histogram if one */
997 >                tmDone(tmTop);
998 >                tmTop->flags = flags;
999 >        } else {                        /* else initialize */
1000 >                if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL)
1001 >                        goto memerr;
1002 >                if (greyscale) {
1003 >                        cscan = TM_NOCHROM;
1004 >                        if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL)
1005 >                                goto memerr;
1006 >                } else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax))
1007 >                                == NULL)
1008 >                        goto memerr;
1009 >                                                /* initialize tm library */
1010 >                if (tmInit(flags, stdprims, gamcor) == NULL)
1011 >                        goto memerr;
1012 >                if (tmSetSpace(stdprims, WHTEFFICACY/exposure))
1013 >                        goto tmerr;
1014 >                                                /* compute picture histogram */
1015 >                for (y = 0; y < ymax; y++) {
1016 >                        getscan(y);
1017 >                        if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax))
1018 >                                goto tmerr;
1019 >                        if (tmAddHisto(lscan, xmax, 1))
1020 >                                goto tmerr;
1021                  }
1022          }
1023 <        d = 1.0/((right-left)*(bottom-top));
1024 <        scalecolor(clr, d);
1025 <        ll = left; lr = right; lt = top; lb = bottom;
1026 <        copycolor(lc, clr);
1027 <        return(0);
1023 >        tmDup();                        /* add fixations to duplicate map */
1024 >        dobox(addfix, NULL);
1025 >                                        /* (re)compute tone mapping */
1026 >        if (tmComputeMapping(gamcor, 0., 0.))
1027 >                goto tmerr;
1028 >        return;
1029 > memerr:
1030 >        quiterr("out of memory in make_tonemap");
1031 > tmerr:
1032 >        quiterr("tone mapping error");
1033   }
1034  
1035  
1036 + tmap_colrs(scn, len)            /* apply tone mapping to scanline */
1037 + register COLR  *scn;
1038 + int  len;
1039 + {
1040 +        register BYTE  *ps;
1041 +
1042 +        if (tmflags == TM_F_LINEAR) {
1043 +                if (scale)
1044 +                        shiftcolrs(scn, len, scale);
1045 +                colrs_gambs(scn, len);
1046 +                return;
1047 +        }
1048 +        if (len > xmax)
1049 +                quiterr("code error 1 in tmap_colrs");
1050 +        if (tmCvColrs(lscan, cscan, scn, len))
1051 +                goto tmerr;
1052 +        if (tmMapPixels(pscan, lscan, cscan, len))
1053 +                goto tmerr;
1054 +        ps = pscan;
1055 +        if (greyscale)
1056 +                while (len--) {
1057 +                        scn[0][RED] = scn[0][GRN] = scn[0][BLU] = *ps++;
1058 +                        scn[0][EXP] = COLXS;
1059 +                        scn++;
1060 +                }
1061 +        else
1062 +                while (len--) {
1063 +                        scn[0][RED] = *ps++;
1064 +                        scn[0][GRN] = *ps++;
1065 +                        scn[0][BLU] = *ps++;
1066 +                        scn[0][EXP] = COLXS;
1067 +                        scn++;
1068 +                }
1069 +        return;
1070 + tmerr:
1071 +        quiterr("tone mapping error");
1072 + }
1073 +
1074 +
1075   getmono()                       /* get monochrome data */
1076   {
1077          register unsigned char  *dp;
# Line 934 | Line 1160 | getfull()                      /* get full (24-bit) data */
1160   {
1161          int     y;
1162          register unsigned int4  *dp;
1163 +        register unsigned int2  *dph;
1164          register int    x;
1165 <                                        /* set gamma correction */
1166 <        setcolrgam(gamcor);
1165 >                                        /* initialize tone mapping */
1166 >        make_tonemap();
1167                                          /* read and convert file */
1168          dp = (unsigned int4 *)ourdata;
1169 +        dph = (unsigned int2 *)ourdata;
1170          for (y = 0; y < ymax; y++) {
1171                  getscan(y);
1172                  add2icon(y, scanline);
1173 <                if (scale)
1174 <                        shiftcolrs(scanline, xmax, scale);
1175 <                colrs_gambs(scanline, xmax);
948 <                if (ourras->image->blue_mask & 1)
1173 >                tmap_colrs(scanline, xmax);
1174 >                switch (ourras->image->blue_mask) {
1175 >                case 0xff:              /* 24-bit RGB */
1176                          for (x = 0; x < xmax; x++)
1177                                  *dp++ = (unsigned int4)scanline[x][RED] << 16 |
1178                                          (unsigned int4)scanline[x][GRN] << 8 |
1179                                          (unsigned int4)scanline[x][BLU] ;
1180 <                else
1180 >                        break;
1181 >                case 0xff0000:          /* 24-bit BGR */
1182                          for (x = 0; x < xmax; x++)
1183                                  *dp++ = (unsigned int4)scanline[x][RED] |
1184                                          (unsigned int4)scanline[x][GRN] << 8 |
1185                                          (unsigned int4)scanline[x][BLU] << 16 ;
1186 +                        break;
1187 + #if 0
1188 +                case 0x1f:              /* 15-bit RGB */
1189 +                        for (x = 0; x < xmax; x++)
1190 +                                *dph++ =        (scanline[x][RED] << 7 & 0x7c00) |
1191 +                                        (scanline[x][GRN] << 2 & 0x3e0) |
1192 +                                        (unsigned)scanline[x][BLU] >> 3 ;
1193 +                        break;
1194 +                case 0x7c00:            /* 15-bit BGR */
1195 +                        for (x = 0; x < xmax; x++)
1196 +                                *dph++ =        (unsigned)scanline[x][RED] >> 3 |
1197 +                                        (scanline[x][GRN] << 2 & 0x3e0) |
1198 +                                        (scanline[x][BLU] << 7 & 0x7c00) ;
1199 +                        break;
1200 + #endif
1201 +                default:                /* unknown */
1202 +                        if (ourvis.depth > 16)
1203 +                                for (x = 0; x < xmax; x++) {
1204 +                                        *dp = ourras->image->red_mask &
1205 +                                                ourras->image->red_mask*scanline[x][RED]/255;
1206 +                                        *dp |= ourras->image->green_mask &
1207 +                                                ourras->image->green_mask*scanline[x][GRN]/255;
1208 +                                        *dp++ |= ourras->image->blue_mask &
1209 +                                                ourras->image->blue_mask*scanline[x][BLU]/255;
1210 +                                }
1211 +                        else
1212 +                                for (x = 0; x < xmax; x++) {
1213 +                                        *dph = ourras->image->red_mask &
1214 +                                                ourras->image->red_mask*scanline[x][RED]/255;
1215 +                                        *dph |= ourras->image->green_mask &
1216 +                                                ourras->image->green_mask*scanline[x][GRN]/255;
1217 +                                        *dph++ |= ourras->image->blue_mask &
1218 +                                                ourras->image->blue_mask*scanline[x][BLU]/255;
1219 +                                }
1220 +                        break;
1221 +                }
1222          }
1223   }
1224  
# Line 964 | Line 1228 | getgrey()                      /* get greyscale data */
1228          int     y;
1229          register unsigned char  *dp;
1230          register int    x;
1231 <                                        /* set gamma correction */
1232 <        setcolrgam(gamcor);
1231 >                                        /* initialize tone mapping */
1232 >        make_tonemap();
1233                                          /* read and convert file */
1234          dp = ourdata;
1235          for (y = 0; y < ymax; y++) {
1236                  getscan(y);
1237                  add2icon(y, scanline);
1238 <                if (scale)
975 <                        shiftcolrs(scanline, xmax, scale);
976 <                for (x = 0; x < xmax; x++)
977 <                        scanline[x][GRN] = normbright(scanline[x]);
978 <                colrs_gambs(scanline, xmax);
1238 >                tmap_colrs(scanline, xmax);
1239                  if (maxcolors < 256)
1240                          for (x = 0; x < xmax; x++)
1241 <                                *dp++ = ((long)scanline[x][GRN] *
1241 >                                *dp++ = ((int4)scanline[x][GRN] *
1242                                          maxcolors + maxcolors/2) >> 8;
1243                  else
1244                          for (x = 0; x < xmax; x++)
# Line 986 | Line 1246 | getgrey()                      /* get greyscale data */
1246          }
1247          for (x = 0; x < maxcolors; x++)
1248                  clrtab[x][RED] = clrtab[x][GRN] =
1249 <                        clrtab[x][BLU] = ((long)x*256 + 128)/maxcolors;
1249 >                        clrtab[x][BLU] = ((int4)x*256 + 128)/maxcolors;
1250   }
1251  
1252  
# Line 996 | Line 1256 | getmapped()                    /* get color-mapped data */
1256                                          /* make sure we can do it first */
1257          if (fname == NULL)
1258                  quiterr("cannot map colors from standard input");
1259 <                                        /* set gamma correction */
1260 <        setcolrgam(gamcor);
1259 >                                        /* initialize tone mapping */
1260 >        make_tonemap();
1261                                          /* make histogram */
1262 <        if (new_histo((long)xmax*ymax) == -1)
1262 >        if (new_histo((int4)xmax*ymax) == -1)
1263                  quiterr("cannot initialize histogram");
1264          for (y = 0; y < ymax; y++) {
1265                  if (getscan(y) < 0)
1266                          break;
1267                  add2icon(y, scanline);
1268 <                if (scale)
1009 <                        shiftcolrs(scanline, xmax, scale);
1010 <                colrs_gambs(scanline, xmax);
1268 >                tmap_colrs(scanline, xmax);
1269                  cnt_colrs(scanline, xmax);
1270          }
1271                                          /* map pixels */
# Line 1015 | Line 1273 | getmapped()                    /* get color-mapped data */
1273                  quiterr("cannot create color map");
1274          for (y = 0; y < ymax; y++) {
1275                  getscan(y);
1276 <                if (scale)
1019 <                        shiftcolrs(scanline, xmax, scale);
1020 <                colrs_gambs(scanline, xmax);
1276 >                tmap_colrs(scanline, xmax);
1277                  if (dither)
1278                          dith_colrs(ourdata+y*xmax, scanline, xmax);
1279                  else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines