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.32 by greg, Thu Oct 28 11:39:59 1993 UTC vs.
Revision 2.71 by greg, Sun Jul 24 19:53:08 2005 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1993 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  x11image.c - driver for X-windows
6   *
# Line 21 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  "standard.h"
20  
21 + #include  <string.h>
22   #include  <signal.h>
23 + #include  <unistd.h>
24 + #include  <sys/types.h>
25 + #include  <sys/wait.h>
26   #include  <X11/Xlib.h>
27   #include  <X11/cursorfont.h>
28   #include  <X11/Xutil.h>
29   #include  <X11/Xatom.h>
30  
31   #include  "color.h"
32 + #include  "tonemap.h"
33 + #include  "clrtab.h"
34   #include  "view.h"
35   #include  "x11raster.h"
36   #include  "random.h"
34 #include  "resolu.h"
37  
36 #ifdef  __alpha
37 #define  int4           int
38 #endif
39 #ifndef  int4
40 #define  int4           long
41 #endif
42
38   #define  FONTNAME       "8x13"          /* text font we'll use */
39  
40   #define  CTRL(c)        ((c)-'@')
# Line 48 | Line 43 | static char SCCSid[] = "$SunId$ LBL";
43  
44   #define  ICONSIZ        (8*10)          /* maximum icon dimension (even 8) */
45  
46 + #define  FIXWEIGHT      20              /* weight to add for fixation points */
47 +
48   #define  ourscreen      DefaultScreen(thedisplay)
49   #define  ourroot        RootWindow(thedisplay,ourscreen)
50  
# Line 56 | Line 53 | static char SCCSid[] = "$SunId$ LBL";
53   #define  redraw(x,y,w,h) patch_raster(wind,(x)-xoff,(y)-yoff,x,y,w,h,ourras)
54  
55   double  gamcor = 2.2;                   /* gamma correction */
56 + char  *gamstr = NULL;                   /* gamma value override */
57  
58   int  dither = 1;                        /* dither colors? */
59   int  fast = 0;                          /* keep picture in Pixmap? */
# Line 73 | Line 71 | int  xoff = 0;                         /* x image offset */
71   int  yoff = 0;                          /* y image offset */
72  
73   int  parent = 0;                        /* number of children, -1 if child */
74 + int  sequential = 0;                    /* display images in sequence */
75  
76 + char  *tout = "od";                     /* output of 't' command */
77 + int  tinterv = 0;                       /* interval between mouse reports */
78 +
79 + int  tmflags = TM_F_LINEAR;             /* tone mapping flags */
80 +
81   VIEW  ourview = STDVIEW;                /* image view parameters */
82   int  gotview = 0;                       /* got parameters from file */
83  
84   COLR  *scanline;                        /* scan line buffer */
85 + TMbright  *lscan;                       /* encoded luminance scanline */
86 + BYTE  *cscan;                           /* encoded chroma scanline */
87 + BYTE  *pscan;                           /* compute pixel scanline */
88  
89   RESOLU  inpres;                         /* input resolution and ordering */
90   int  xmax, ymax;                        /* picture dimensions */
91   int  width, height;                     /* window size */
92   char  *fname = NULL;                    /* input file name */
93 < FILE  *fin = stdin;                     /* input file */
93 > FILE  *fin = NULL;                      /* input file */
94   long  *scanpos = NULL;                  /* scan line positions in file */
95   int  cury = 0;                          /* current scan location */
96  
# Line 91 | Line 98 | double  exposure = 1.0;                        /* exposure compensation use
98  
99   int  wrongformat = 0;                   /* input in another format? */
100  
101 + TMstruct        *tmGlobal;              /* base tone-mapping */
102 + TMstruct        *tmCurrent;             /* curren tone-mapping */
103 +
104   GC      ourgc;                          /* standard graphics context */
105   GC      revgc;                          /* graphics context with GXinvert */
106  
# Line 101 | Line 111 | unsigned char  *ourdata;               /* our image data */
111  
112   struct {
113          int  xmin, ymin, xsiz, ysiz;
114 < }  box = {0, 0, 0, 0};                  /* current box */
114 > }  bbox = {0, 0, 0, 0};                 /* current bbox */
115  
116   char  *geometry = NULL;                 /* geometry specification */
117  
# Line 112 | Line 122 | char  *progname;
122  
123   char  errmsg[128];
124  
125 < extern BYTE  clrtab[256][3];            /* global color map */
125 > BYTE  clrtab[256][3];                   /* global color map */
126  
117 extern long  ftell();
127  
128   Display  *thedisplay;
129   Atom  closedownAtom, wmProtocolsAtom;
130  
131   int  sigrecv;
132  
133 < int  onsig() { sigrecv++; }
133 > void  onsig(int i) { sigrecv++; }
134  
135 + typedef void doboxf_t(COLR *scn, int n, void *);
136  
137 < main(argc, argv)
138 < int  argc;
139 < char  *argv[];
137 > static gethfunc headline;
138 > static void init(int argc, char **argv);
139 > static void quiterr(char *err);
140 > static int viscmp(XVisualInfo *v1, XVisualInfo *v2);
141 > static void getbestvis(void);
142 > static void getras(void);
143 > static void getevent(void);
144 > static int traceray(int xpos, int ypos);
145 > static int docom(XKeyPressedEvent *ekey);
146 > static void moveimage(XButtonPressedEvent *ebut);
147 > static void getbox(XButtonPressedEvent *ebut);
148 > static void trackrays(XButtonPressedEvent *ebut);
149 > static void revbox(int x0, int y0, int x1, int y1);
150 > static doboxf_t colavg;
151 > static doboxf_t addfix;
152 > static int avgbox(COLOR cavg);
153 > static int dobox(doboxf_t *f, void *p);
154 > static void make_tonemap(void);
155 > static void tmap_colrs(COLR *scn, int len);
156 > static void getmono(void);
157 > static void add2icon(int y, COLR *scan);
158 > static void getfull(void);
159 > static void getgrey(void);
160 > static void getmapped(void);
161 > static void scale_rcolors(XRASTER *xr, double sf);
162 > static int getscan(int y);
163 >
164 >
165 > int
166 > main(int  argc, char  *argv[])
167   {
131        extern char  *getenv();
132        char  *gv;
133        int  headline();
168          int  i;
169          int  pid;
170          
171          progname = argv[0];
172 <        if ((gv = getenv("GAMMA")) != NULL)
139 <                gamcor = atof(gv);
172 >        fin = stdin;
173  
174          for (i = 1; i < argc; i++)
175                  if (argv[i][0] == '-')
176                          switch (argv[i][1]) {
177 <                        case 'c':
177 >                        case 'c':                       /* number of colors */
178                                  maxcolors = atoi(argv[++i]);
179                                  break;
180 <                        case 'b':
180 >                        case 'b':                       /* greyscale only */
181                                  greyscale = !greyscale;
182                                  break;
183 <                        case 'm':
183 >                        case 'm':                       /* monochrome */
184 >                                greyscale = 1;
185                                  maxcolors = 2;
186                                  break;
187 <                        case 'd':
187 >                        case 'd':                       /* display or dither */
188                                  if (argv[i][2] == 'i')
189                                          dispname = argv[++i];
190                                  else
191                                          dither = !dither;
192                                  break;
193 <                        case 'f':
193 >                        case 'f':                       /* save pixmap */
194                                  fast = !fast;
195                                  break;
196 <                        case 'e':
197 <                                if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
196 >                        case 's':                       /* one at a time */
197 >                                sequential = !sequential;
198 >                                break;
199 >                        case 'o':                       /* 't' output */
200 >                                tout = argv[i]+2;
201 >                                break;
202 >                        case 't':                       /* msec interval */
203 >                                tinterv = atoi(argv[++i]);
204 >                                break;
205 >                        case 'e':                       /* exposure comp. */
206 >                                i++;
207 >                                if (argv[i][0] == 'a') {
208 >                                        tmflags = TM_F_CAMERA;
209 >                                        break;
210 >                                }
211 >                                if (argv[i][0] == 'h') {
212 >                                        tmflags = TM_F_HUMAN;
213 >                                        break;
214 >                                }
215 >                                if (argv[i][0] != '+' && argv[i][0] != '-')
216                                          goto userr;
217 <                                scale = atoi(argv[++i]);
217 >                                scale = atoi(argv[i]);
218                                  break;
219 <                        case 'g':
219 >                        case 'g':                       /* gamma comp. */
220                                  if (argv[i][2] == 'e')
221                                          geometry = argv[++i];
222                                  else
223 <                                        gamcor = atof(argv[++i]);
223 >                                        gamstr = argv[++i];
224                                  break;
225                          default:
226                                  goto userr;
# Line 197 | Line 249 | char  *argv[];
249          if (i < argc) {                 /* open picture file */
250                  fname = argv[i];
251                  fin = fopen(fname, "r");
252 <                if (fin == NULL) {
253 <                        sprintf(errmsg, "cannot open file \"%s\"", fname);
202 <                        quiterr(errmsg);
203 <                }
252 >                if (fin == NULL)
253 >                        quiterr("cannot open picture file");
254          }
255                                  /* get header */
256          getheader(fin, headline, NULL);
# Line 217 | Line 267 | char  *argv[];
267  
268          init(argc, argv);                       /* get file and open window */
269  
220        if (parent < 0) {
221                kill(getppid(), SIGCONT);       /* signal parent if child */
222                sigrecv--;
223        }
270          for ( ; ; )
271                  getevent();             /* main loop */
272   userr:
273          fprintf(stderr,
274 < "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic ..\n",
274 > "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e spec][-g gamcor][-s][-ospec][-t intvl] pic ..\n",
275                          progname);
276          exit(1);
277   }
278  
279  
280 < headline(s)             /* get relevant info from header */
281 < char  *s;
280 > static int
281 > headline(               /* get relevant info from header */
282 >        char    *s,
283 >        void    *p
284 > )
285   {
286          char  fmt[32];
287  
288          if (isexpos(s))
289                  exposure *= exposval(s);
290 <        else if (isformat(s)) {
242 <                formatval(fmt, s);
290 >        else if (formatval(fmt, s))
291                  wrongformat = strcmp(fmt, COLRFMT);
292 <        } else if (isview(s) && sscanview(&ourview, s) > 0)
292 >        else if (isview(s) && sscanview(&ourview, s) > 0)
293                  gotview++;
294 +        return(0);
295   }
296  
297  
298 < init(argc, argv)                        /* get data and open window */
299 < int argc;
300 < char **argv;
298 > static void
299 > init(                   /* get data and open window */
300 >        int argc,
301 >        char **argv
302 > )
303   {
304          XSetWindowAttributes    ourwinattr;
305          XClassHint      xclshints;
# Line 275 | Line 326 | char **argv;
326          name += i+1;
327          if ((thedisplay = XOpenDisplay(dispname)) == NULL)
328                  quiterr("cannot open display");
329 +                                /* set gamma value */
330 +        if (gamstr == NULL)             /* get it from the X server */
331 +                gamstr = XGetDefault(thedisplay, "radiance", "gamma");
332 +        if (gamstr == NULL)             /* get it from the environment */
333 +                gamstr = getenv("DISPLAY_GAMMA");
334 +        if (gamstr != NULL)
335 +                gamcor = atof(gamstr);
336                                  /* get best visual for default screen */
337          getbestvis();
338                                  /* store image */
# Line 301 | Line 359 | char **argv;
359                  }
360          }
361          /* open window */
362 +        i = CWEventMask|CWCursor|CWBackPixel|CWBorderPixel;
363          ourwinattr.border_pixel = ourwhite;
364          ourwinattr.background_pixel = ourblack;
365 <        ourwinattr.colormap = XCreateColormap(thedisplay, ourroot,
366 <                        ourvis.visual, AllocNone);
365 >        if (ourvis.visual != DefaultVisual(thedisplay,ourscreen)) {
366 >                ourwinattr.colormap = newcmap(thedisplay, ourscreen, ourvis.visual);
367 >                i |= CWColormap;
368 >        }
369          ourwinattr.event_mask = ExposureMask|KeyPressMask|ButtonPressMask|
370                          ButtonReleaseMask|ButtonMotionMask|StructureNotifyMask;
371          ourwinattr.cursor = XCreateFontCursor(thedisplay, XC_diamond_cross);
372          wind = XCreateWindow(thedisplay, ourroot, xszhints.x, xszhints.y,
373                          xszhints.width, xszhints.height, BORWIDTH,
374 <                        ourvis.depth, InputOutput, ourvis.visual, CWEventMask|
375 <                        CWCursor|CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr);
374 >                        ourvis.depth, InputOutput, ourvis.visual,
375 >                        i, &ourwinattr);
376          if (wind == 0)
377                  quiterr("cannot create window");
378          width = xmax;
# Line 336 | Line 397 | char **argv;
397          windowName.encoding = iconName.encoding = XA_STRING;
398          windowName.format = iconName.format = 8;
399          windowName.value = (u_char *)name;
400 <        windowName.nitems = strlen(windowName.value);
400 >        windowName.nitems = strlen((char *)windowName.value);
401          iconName.value = (u_char *)name;
402 <        iconName.nitems = strlen(windowName.value);
402 >        iconName.nitems = strlen((char *)windowName.value);
403  
404          xclshints.res_name = NULL;
405          xclshints.res_class = "Ximage";
# Line 349 | Line 410 | char **argv;
410          XSetWMProtocols(thedisplay, wind, &closedownAtom, 1);
411  
412          XMapWindow(thedisplay, wind);
352        return;
413   } /* end of init */
414  
415  
416 < quiterr(err)            /* print message and exit */
417 < char  *err;
416 > static void
417 > quiterr(                /* print message and exit */
418 >        char  *err
419 > )
420   {
421          register int  es;
422          int  cs;
423  
424 <        if (es = err != NULL)
424 >        if ( (es = err != NULL) )
425                  fprintf(stderr, "%s: %s: %s\n", progname,
426                                  fname==NULL?"<stdin>":fname, err);
427 <        if (parent > 0 & wind != 0) {
428 <                XDestroyWindow(thedisplay, wind);
429 <                XFlush(thedisplay);
368 <        } else if (parent < 0 & sigrecv == 0)
427 >        if (thedisplay != NULL)
428 >                XCloseDisplay(thedisplay);
429 >        if ((parent < 0) & (sigrecv == 0))
430                  kill(getppid(), SIGCONT);
431          while (parent > 0 && wait(&cs) != -1) { /* wait for any children */
432                  if (es == 0)
# Line 377 | Line 438 | char  *err;
438  
439  
440   static int
441 < viscmp(v1,v2)           /* compare visual to see which is better, descending */
442 < register XVisualInfo    *v1, *v2;
441 > viscmp(         /* compare visual to see which is better, descending */
442 >        register XVisualInfo    *v1,
443 >        register XVisualInfo    *v2
444 > )
445   {
446          int     bad1 = 0, bad2 = 0;
447          register int  *rp;
# Line 390 | Line 453 | register XVisualInfo   *v1, *v2;
453                                  return(-1);
454                          if (v1->depth == 32 && v2->depth == 24)
455                                  return(1);
456 <                        return(0);
456 >                                        /* go for maximum depth otherwise */
457 >                        return(v2->depth - v1->depth);
458                  }
459                                          /* don't be too greedy */
460                  if (maxcolors <= 1<<v1->depth && maxcolors <= 1<<v2->depth)
461                          return(v1->depth - v2->depth);
462                  return(v2->depth - v1->depth);
463          }
464 <                                        /* prefer Pseudo when < 24-bit */
464 >                                        /* prefer Pseudo when < 15-bit */
465          if ((v1->class == TrueColor || v1->class == DirectColor) &&
466 <                        v1->depth < 24)
466 >                        v1->depth < 15)
467                  bad1 = 1;
468          if ((v2->class == TrueColor || v2->class == DirectColor) &&
469 <                        v2->depth < 24)
469 >                        v2->depth < 15)
470                  bad2 = -1;
471          if (bad1 | bad2)
472                  return(bad1+bad2);
# Line 417 | Line 481 | register XVisualInfo   *v1, *v2;
481   }
482  
483  
484 < getbestvis()                    /* get the best visual for this screen */
484 > static void
485 > getbestvis(void)                        /* get the best visual for this screen */
486   {
487   #ifdef DEBUG
488   static char  vistype[][12] = {
# Line 469 | Line 534 | static char  vistype[][12] = {
534          if (viscmp(&xvi[i],&ourvis) > 0)
535                  quiterr("inadequate visuals on this screen");
536                                          /* OK, we'll use it */
537 <        copystruct(&ourvis, &xvi[i]);
537 >        ourvis = xvi[i];
538   #ifdef DEBUG
539          fprintf(stderr, "Selected visual type %s, depth %d\n",
540                          vistype[ourvis.class], ourvis.depth);
# Line 499 | Line 564 | static char  vistype[][12] = {
564   }
565  
566  
567 < getras()                                /* get raster file */
567 > static void
568 > getras(void)                            /* get raster file */
569   {
504        XVisualInfo     vinfo;
505
570          if (maxcolors <= 2) {           /* monochrome */
571                  ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8));
572                  if (ourdata == NULL)
573                          goto fail;
574 <                ourras = make_raster(thedisplay, &ourvis, 1, ourdata,
574 >                ourras = make_raster(thedisplay, &ourvis, 1, (char *)ourdata,
575                                  xmax, ymax, 8);
576                  if (ourras == NULL)
577                          goto fail;
578                  getmono();
579 <        } else if (ourvis.class == TrueColor | ourvis.class == DirectColor) {
580 <                ourdata = (unsigned char *)malloc(sizeof(int4)*xmax*ymax);
579 >        } else if ((ourvis.class == TrueColor) | (ourvis.class == DirectColor)) {
580 >                int  datsiz = ourvis.depth>16 ? sizeof(int32) : sizeof(int16);
581 >                ourdata = (unsigned char *)malloc(datsiz*xmax*ymax);
582                  if (ourdata == NULL)
583                          goto fail;
584 <                ourras = make_raster(thedisplay, &ourvis, sizeof(int4)*8,
585 <                                ourdata, xmax, ymax, 32);
584 >                ourras = make_raster(thedisplay, &ourvis, datsiz*8,
585 >                                (char *)ourdata, xmax, ymax, datsiz*8);
586                  if (ourras == NULL)
587                          goto fail;
588                  getfull();
# Line 525 | Line 590 | getras()                               /* get raster file */
590                  ourdata = (unsigned char *)malloc(xmax*ymax);
591                  if (ourdata == NULL)
592                          goto fail;
593 <                ourras = make_raster(thedisplay, &ourvis, 8, ourdata,
593 >                ourras = make_raster(thedisplay, &ourvis, 8, (char *)ourdata,
594                                  xmax, ymax, 8);
595                  if (ourras == NULL)
596                          goto fail;
597 <                if (greyscale | ourvis.class == StaticGray)
597 >                if (greyscale)
598                          getgrey();
599                  else
600                          getmapped();
# Line 542 | Line 607 | fail:
607   }
608  
609  
610 < getevent()                              /* process the next event */
610 > static void
611 > getevent(void)                          /* process the next event */
612   {
613          XEvent xev;
614  
# Line 559 | Line 625 | getevent()                             /* process the next event */
625                  map_rcolors(ourras, wind);
626                  if (fast)
627                          make_rpixmap(ourras, wind);
628 +                if ((!sequential) & (parent < 0) & (sigrecv == 0)) {
629 +                        kill(getppid(), SIGCONT);
630 +                        sigrecv--;
631 +                }
632                  break;
633          case UnmapNotify:
634                  if (!fast)
# Line 571 | Line 641 | getevent()                             /* process the next event */
641          case ButtonPress:
642                  if (xev.xbutton.state & (ShiftMask|ControlMask))
643                          moveimage(&xev.xbutton);
574                else if (xev.xbutton.button == Button2)
575                        traceray(xev.xbutton.x, xev.xbutton.y);
644                  else
645 <                        getbox(&xev.xbutton);
645 >                        switch (xev.xbutton.button) {
646 >                        case Button1:
647 >                                getbox(&xev.xbutton);
648 >                                break;
649 >                        case Button2:
650 >                                traceray(xev.xbutton.x, xev.xbutton.y);
651 >                                break;
652 >                        case Button3:
653 >                                trackrays(&xev.xbutton);
654 >                                break;
655 >                        }
656                  break;
657          case ClientMessage:
658                  if ((xev.xclient.message_type == wmProtocolsAtom) &&
# Line 585 | Line 663 | getevent()                             /* process the next event */
663   }
664  
665  
666 < traceray(xpos, ypos)                    /* print ray corresponding to pixel */
667 < int  xpos, ypos;
666 > static int
667 > traceray(                       /* print requested pixel data */
668 >        int  xpos,
669 >        int  ypos
670 > )
671   {
672 <        FLOAT  hv[2];
672 >        RREAL  hv[2];
673          FVECT  rorg, rdir;
674 +        COLOR  cval;
675 +        register char  *cp;
676  
677 <        if (!gotview) {         /* no view, no can do */
678 <                XBell(thedisplay, 0);
679 <                return(-1);
680 <        }
677 >        bbox.xmin = xpos; bbox.xsiz = 1;
678 >        bbox.ymin = ypos; bbox.ysiz = 1;
679 >        avgbox(cval);
680 >        scalecolor(cval, 1./exposure);
681          pix2loc(hv, &inpres, xpos-xoff, ypos-yoff);
682 <        if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0)
683 <                return(-1);
684 <        printf("%e %e %e ", rorg[0], rorg[1], rorg[2]);
685 <        printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]);
682 >        if (!gotview || viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0)
683 >                rorg[0] = rorg[1] = rorg[2] =
684 >                rdir[0] = rdir[1] = rdir[2] = 0.;
685 >
686 >        for (cp = tout; *cp; cp++)      /* print what they asked for */
687 >                switch (*cp) {
688 >                case 'o':                       /* origin */
689 >                        printf("%e %e %e ", rorg[0], rorg[1], rorg[2]);
690 >                        break;
691 >                case 'd':                       /* direction */
692 >                        printf("%e %e %e ", rdir[0], rdir[1], rdir[2]);
693 >                        break;
694 >                case 'v':                       /* radiance value */
695 >                        printf("%e %e %e ", colval(cval,RED),
696 >                                        colval(cval,GRN), colval(cval,BLU));
697 >                        break;
698 >                case 'l':                       /* luminance */
699 >                        printf("%e ", luminance(cval));
700 >                        break;
701 >                case 'p':                       /* pixel position */
702 >                        printf("%d %d ", (int)(hv[0]*inpres.xr),
703 >                                        (int)(hv[1]*inpres.yr));
704 >                        break;
705 >                }
706 >        putchar('\n');
707          fflush(stdout);
708          return(0);
709   }
710  
711  
712 < docom(ekey)                             /* execute command */
713 < XKeyPressedEvent  *ekey;
712 > static int
713 > docom(                          /* execute command */
714 >        XKeyPressedEvent  *ekey
715 > )
716   {
717          char  buf[80];
718          COLOR  cval;
719          XColor  cvx;
720          int  com, n;
721          double  comp;
722 <        FLOAT  hv[2];
722 >        RREAL  hv[2];
723  
724          n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL);
725          if (n == 0)
# Line 628 | Line 734 | XKeyPressedEvent  *ekey;
734          case '\r':
735          case 'l':
736          case 'c':                               /* value */
737 <                if (avgbox(cval) == -1)
737 >                if (!avgbox(cval))
738                          return(-1);
739                  switch (com) {
740                  case '\n':
# Line 636 | Line 742 | XKeyPressedEvent  *ekey;
742                          sprintf(buf, "%.3f", intens(cval)/exposure);
743                          break;
744                  case 'l':                               /* luminance */
745 <                        sprintf(buf, "%.0fL", luminance(cval)/exposure);
745 >                        sprintf(buf, "%.1fL", luminance(cval)/exposure);
746                          break;
747                  case 'c':                               /* color */
748                          comp = pow(2.0, (double)scale);
# Line 647 | Line 753 | XKeyPressedEvent  *ekey;
753                          break;
754                  }
755                  XDrawImageString(thedisplay, wind, ourgc,
756 <                                box.xmin, box.ymin+box.ysiz, buf, strlen(buf));
756 >                                bbox.xmin, bbox.ymin+bbox.ysiz, buf, strlen(buf));
757                  return(0);
758          case 'i':                               /* identify (contour) */
759                  if (ourras->pixels == NULL)
# Line 670 | Line 776 | XKeyPressedEvent  *ekey;
776                  return(0);
777          case 't':                               /* trace */
778                  return(traceray(ekey->x, ekey->y));
779 +        case 'a':                               /* auto exposure */
780 +                if (fname == NULL)
781 +                        return(-1);
782 +                tmflags = TM_F_CAMERA;
783 +                strcpy(buf, "auto exposure...");
784 +                goto remap;
785 +        case 'h':                               /* human response */
786 +                if (fname == NULL)
787 +                        return(-1);
788 +                tmflags = TM_F_HUMAN;
789 +                strcpy(buf, "human exposure...");
790 +                goto remap;
791          case '=':                               /* adjust exposure */
792          case '@':                               /* adaptation level */
793 <                if (avgbox(cval) == -1)
793 >                if (!avgbox(cval))
794                          return(-1);
795 <                comp = com=='@'
796 <                ? 106./pow(1.219+pow(luminance(cval)/exposure,.4),2.5)/exposure
797 <                : .5/bright(cval) ;
795 >                comp = bright(cval);
796 >                if (comp < 1e-20) {
797 >                        XBell(thedisplay, 0);
798 >                        return(-1);
799 >                }
800 >                if (com == '@')
801 >                        comp = 106./exposure/
802 >                        pow(1.219+pow(comp*WHTEFFICACY/exposure,.4),2.5);
803 >                else
804 >                        comp = .5/comp;
805                  comp = log(comp)/.69315 - scale;
806                  n = comp < 0 ? comp-.5 : comp+.5 ;      /* round */
807 <                if (n == 0)
808 <                        return(0);
809 <                scale_rcolors(ourras, pow(2.0, (double)n));
807 >                if (tmflags != TM_F_LINEAR)
808 >                        tmflags = TM_F_LINEAR;  /* turn off tone mapping */
809 >                else {
810 >                        if (n == 0)             /* else check if any change */
811 >                                return(0);
812 >                        scale_rcolors(ourras, pow(2.0, (double)n));
813 >                }
814                  scale += n;
815                  sprintf(buf, "%+d", scale);
816 +        remap:
817                  XDrawImageString(thedisplay, wind, ourgc,
818 <                                box.xmin, box.ymin+box.ysiz, buf, strlen(buf));
818 >                                bbox.xmin, bbox.ymin+bbox.ysiz, buf, strlen(buf));
819                  XFlush(thedisplay);
820 <                free(ourdata);
820 >                /* free(ourdata);       This is done in XDestroyImage()! */
821                  free_raster(ourras);
822                  getras();
823          /* fall through */
# Line 709 | Line 839 | XKeyPressedEvent  *ekey;
839                  free_rpixmap(ourras);
840                  return(0);
841          case '0':                               /* recenter origin */
842 <                if (xoff == 0 & yoff == 0)
842 >                if ((xoff == 0) & (yoff == 0))
843                          return(0);
844                  xoff = yoff = 0;
845                  XClearWindow(thedisplay, wind);
846                  redraw(0, 0, width, height);
847                  return(0);
848          case ' ':                               /* clear */
849 <                redraw(box.xmin, box.ymin, box.xsiz, box.ysiz);
849 >                redraw(bbox.xmin, bbox.ymin, bbox.xsiz, bbox.ysiz);
850                  return(0);
851          default:
852                  XBell(thedisplay, 0);
# Line 725 | Line 855 | XKeyPressedEvent  *ekey;
855   }
856  
857  
858 < moveimage(ebut)                         /* shift the image */
859 < XButtonPressedEvent  *ebut;
858 > static void
859 > moveimage(                              /* shift the image */
860 >        XButtonPressedEvent  *ebut
861 > )
862   {
863          XEvent  e;
864          int     mxo, myo;
# Line 750 | Line 882 | XButtonPressedEvent  *ebut;
882   }
883  
884  
885 < getbox(ebut)                            /* get new box */
886 < XButtonPressedEvent  *ebut;
885 > static void
886 > getbox(                         /* get new bbox */
887 >        XButtonPressedEvent  *ebut
888 > )
889   {
890          XEvent  e;
891  
892          XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e);
893          while (e.type == MotionNotify) {
894 <                revbox(ebut->x, ebut->y, box.xmin = e.xmotion.x, box.ymin = e.xmotion.y);
894 >                revbox(ebut->x, ebut->y, bbox.xmin = e.xmotion.x, bbox.ymin = e.xmotion.y);
895                  XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e);
896 <                revbox(ebut->x, ebut->y, box.xmin, box.ymin);
896 >                revbox(ebut->x, ebut->y, bbox.xmin, bbox.ymin);
897          }
898 <        box.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x);
899 <        box.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y);
900 <        if (box.xmin > ebut->x) {
901 <                box.xsiz = box.xmin - ebut->x + 1;
902 <                box.xmin = ebut->x;
898 >        bbox.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x);
899 >        bbox.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y);
900 >        if (bbox.xmin > ebut->x) {
901 >                bbox.xsiz = bbox.xmin - ebut->x + 1;
902 >                bbox.xmin = ebut->x;
903          } else {
904 <                box.xsiz = ebut->x - box.xmin + 1;
904 >                bbox.xsiz = ebut->x - bbox.xmin + 1;
905          }
906 <        if (box.ymin > ebut->y) {
907 <                box.ysiz = box.ymin - ebut->y + 1;
908 <                box.ymin = ebut->y;
906 >        if (bbox.ymin > ebut->y) {
907 >                bbox.ysiz = bbox.ymin - ebut->y + 1;
908 >                bbox.ymin = ebut->y;
909          } else {
910 <                box.ysiz = ebut->y - box.ymin + 1;
910 >                bbox.ysiz = ebut->y - bbox.ymin + 1;
911          }
912   }
913  
914  
915 < revbox(x0, y0, x1, y1)                  /* draw box with reversed lines */
916 < int  x0, y0, x1, y1;
915 > static void
916 > trackrays(                              /* trace rays as mouse moves */
917 >        XButtonPressedEvent  *ebut
918 > )
919   {
920 +        XEvent  e;
921 +        unsigned long   lastrept;
922 +
923 +        traceray(ebut->x, ebut->y);
924 +        lastrept = ebut->time;
925 +        XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e);
926 +        while (e.type == MotionNotify) {
927 +                if (e.xmotion.time >= lastrept + tinterv) {
928 +                        traceray(e.xmotion.x, e.xmotion.y);
929 +                        lastrept = e.xmotion.time;
930 +                }
931 +                XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e);
932 +        }
933 + }
934 +
935 +
936 + static void
937 + revbox(                 /* draw bbox with reversed lines */
938 +        int  x0,
939 +        int  y0,
940 +        int  x1,
941 +        int  y1
942 + )
943 + {
944          revline(x0, y0, x1, y0);
945          revline(x0, y1, x1, y1);
946          revline(x0, y0, x0, y1);
# Line 788 | Line 948 | int  x0, y0, x1, y1;
948   }
949  
950  
951 < avgbox(clr)                             /* average color over current box */
952 < COLOR  clr;
951 > static void
952 > colavg(
953 >        register COLR   *scn,
954 >        register int    n,
955 >        void *cavg
956 > )
957   {
958 <        static COLOR  lc;
959 <        static int  ll, lr, lt, lb;
958 >        COLOR   col;
959 >
960 >        while (n--) {
961 >                colr_color(col, *scn++);
962 >                addcolor((COLORV*)cavg, col);
963 >        }
964 > }
965 >
966 >
967 > static int
968 > avgbox(                         /* average color over current bbox */
969 >        COLOR   cavg
970 > )
971 > {
972 >        double  d;
973 >        register int    rval;
974 >
975 >        setcolor(cavg, 0., 0., 0.);
976 >        rval = dobox(colavg, (void *)cavg);
977 >        if (rval > 0) {
978 >                d = 1./rval;
979 >                scalecolor(cavg, d);
980 >        }
981 >        return(rval);
982 > }
983 >
984 >
985 > static int
986 > dobox(                          /* run function over bbox */
987 >        //void  (*f)(),                 /* function to call for each subscan */
988 >        doboxf_t *f,                    /* function to call for each subscan */
989 >        void    *p                      /* pointer to private data */
990 > )
991 > {
992          int  left, right, top, bottom;
993          int  y;
798        double  d;
799        COLOR  ctmp;
800        register int  x;
994  
995 <        setcolor(clr, 0.0, 0.0, 0.0);
996 <        left = box.xmin - xoff;
804 <        right = left + box.xsiz;
995 >        left = bbox.xmin - xoff;
996 >        right = left + bbox.xsiz;
997          if (left < 0)
998                  left = 0;
999          if (right > xmax)
1000                  right = xmax;
1001          if (left >= right)
1002 <                return(-1);
1003 <        top = box.ymin - yoff;
1004 <        bottom = top + box.ysiz;
1002 >                return(0);
1003 >        top = bbox.ymin - yoff;
1004 >        bottom = top + bbox.ysiz;
1005          if (top < 0)
1006                  top = 0;
1007          if (bottom > ymax)
1008                  bottom = ymax;
1009          if (top >= bottom)
818                return(-1);
819        if (left == ll && right == lr && top == lt && bottom == lb) {
820                copycolor(clr, lc);
1010                  return(0);
822        }
1011          for (y = top; y < bottom; y++) {
1012                  if (getscan(y) == -1)
1013                          return(-1);
1014 <                for (x = left; x < right; x++) {
1015 <                        colr_color(ctmp, scanline[x]);
1016 <                        addcolor(clr, ctmp);
1014 >                (*f)(scanline+left, right-left, p);
1015 >        }
1016 >        return((right-left)*(bottom-top));
1017 > }
1018 >
1019 >
1020 > static void
1021 > addfix(                 /* add fixation points to histogram */
1022 >        COLR    *scn,
1023 >        int     n,
1024 >        void    *p
1025 > )
1026 > {
1027 >        TMstruct *      tms = (TMstruct *)p;
1028 >        
1029 >        if (tmCvColrs(tms, lscan, TM_NOCHROM, scn, n))
1030 >                goto tmerr;
1031 >        if (tmAddHisto(tms, lscan, n, FIXWEIGHT))
1032 >                goto tmerr;
1033 >        return;
1034 > tmerr:
1035 >        quiterr("tone mapping error");
1036 > }
1037 >
1038 >
1039 > static void
1040 > make_tonemap(void)                      /* initialize tone mapping */
1041 > {
1042 >        int  flags, y;
1043 >
1044 >        if (tmflags != TM_F_LINEAR && fname == NULL) {
1045 >                fprintf(stderr, "%s: cannot adjust tone of standard input\n",
1046 >                                progname);
1047 >                tmflags = TM_F_LINEAR;
1048 >        }
1049 >        if (tmflags == TM_F_LINEAR) {   /* linear with clamping */
1050 >                setcolrcor(pow, 1.0/gamcor);
1051 >                return;
1052 >        }
1053 >        flags = tmflags;                /* histogram adjustment */
1054 >        if (greyscale) flags |= TM_F_BW;
1055 >        if (tmGlobal != NULL) {         /* reuse old histogram if one */
1056 >                tmDone(tmCurrent); tmCurrent = NULL;
1057 >                tmGlobal->flags = flags;
1058 >        } else {                        /* else initialize */
1059 >                if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL)
1060 >                        goto memerr;
1061 >                if (greyscale) {
1062 >                        cscan = TM_NOCHROM;
1063 >                        if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL)
1064 >                                goto memerr;
1065 >                } else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax))
1066 >                                == NULL)
1067 >                        goto memerr;
1068 >                                                /* initialize tm library */
1069 >                tmGlobal = tmInit(flags, stdprims, gamcor);
1070 >                if (tmGlobal == NULL)
1071 >                        goto memerr;
1072 >                if (tmSetSpace(tmGlobal, stdprims, WHTEFFICACY/exposure, NULL))
1073 >                        goto tmerr;
1074 >                                                /* compute picture histogram */
1075 >                for (y = 0; y < ymax; y++) {
1076 >                        getscan(y);
1077 >                        if (tmCvColrs(tmGlobal, lscan, TM_NOCHROM,
1078 >                                        scanline, xmax))
1079 >                                goto tmerr;
1080 >                        if (tmAddHisto(tmGlobal, lscan, xmax, 1))
1081 >                                goto tmerr;
1082                  }
1083          }
1084 <        d = 1.0/((right-left)*(bottom-top));
1085 <        scalecolor(clr, d);
1086 <        ll = left; lr = right; lt = top; lb = bottom;
1087 <        copycolor(lc, clr);
1088 <        return(0);
1084 >        tmCurrent = tmDup(tmGlobal);    /* add fixations to duplicate map */
1085 >        dobox(addfix, (void *)tmCurrent);
1086 >                                        /* (re)compute tone mapping */
1087 >        if (tmComputeMapping(tmCurrent, gamcor, 0., 0.))
1088 >                goto tmerr;
1089 >        return;
1090 > memerr:
1091 >        quiterr("out of memory in make_tonemap");
1092 > tmerr:
1093 >        quiterr("tone mapping error");
1094   }
1095  
1096  
1097 < getmono()                       /* get monochrome data */
1097 > static void
1098 > tmap_colrs(             /* apply tone mapping to scanline */
1099 >        register COLR  *scn,
1100 >        int  len
1101 > )
1102   {
1103 +        register BYTE  *ps;
1104 +
1105 +        if (tmflags == TM_F_LINEAR) {
1106 +                if (scale)
1107 +                        shiftcolrs(scn, len, scale);
1108 +                colrs_gambs(scn, len);
1109 +                return;
1110 +        }
1111 +        if (len > xmax)
1112 +                quiterr("code error 1 in tmap_colrs");
1113 +        if (tmCvColrs(tmCurrent, lscan, cscan, scn, len))
1114 +                goto tmerr;
1115 +        if (tmMapPixels(tmCurrent, pscan, lscan, cscan, len))
1116 +                goto tmerr;
1117 +        ps = pscan;
1118 +        if (greyscale)
1119 +                while (len--) {
1120 +                        scn[0][RED] = scn[0][GRN] = scn[0][BLU] = *ps++;
1121 +                        scn[0][EXP] = COLXS;
1122 +                        scn++;
1123 +                }
1124 +        else
1125 +                while (len--) {
1126 +                        scn[0][RED] = *ps++;
1127 +                        scn[0][GRN] = *ps++;
1128 +                        scn[0][BLU] = *ps++;
1129 +                        scn[0][EXP] = COLXS;
1130 +                        scn++;
1131 +                }
1132 +        return;
1133 + tmerr:
1134 +        quiterr("tone mapping error");
1135 + }
1136 +
1137 +
1138 + static void
1139 + getmono(void)                   /* get monochrome data */
1140 + {
1141          register unsigned char  *dp;
1142          register int    x, err;
1143          int     y, errp;
# Line 864 | Line 1164 | getmono()                      /* get monochrome data */
1164                          cerr[x] = err + errp;
1165                  }
1166          }
1167 <        free((char *)cerr);
1167 >        free((void *)cerr);
1168   }
1169  
1170  
1171 < add2icon(y, scan)               /* add a scanline to our icon data */
1172 < int  y;
1173 < COLR  *scan;
1171 > static void
1172 > add2icon(               /* add a scanline to our icon data */
1173 >        int  y,
1174 >        COLR  *scan
1175 > )
1176   {
1177          static short  cerr[ICONSIZ];
1178          static int  ynext;
# Line 907 | Line 1209 | COLR  *scan;
1209                  errp = err;
1210                  ti = x*xmax/iconwidth;
1211                  copycolr(clr, scan[ti]);
1212 <                normcolrs(clr, 1, scale);
1212 >                normcolrs(&clr, 1, scale);
1213                  err += normbright(clr) + cerr[x];
1214                  if (err > 127)
1215                          err -= 255;
# Line 920 | Line 1222 | COLR  *scan;
1222   }
1223  
1224  
1225 < getfull()                       /* get full (24-bit) data */
1225 > static void
1226 > getfull(void)                   /* get full (24-bit) data */
1227   {
1228          int     y;
1229 <        register unsigned int4  *dp;
1229 >        register uint32 *dp;
1230 >        register uint16 *dph;
1231          register int    x;
1232 <                                        /* set gamma correction */
1233 <        setcolrgam(gamcor);
1232 >                                        /* initialize tone mapping */
1233 >        make_tonemap();
1234                                          /* read and convert file */
1235 <        dp = (unsigned int4 *)ourdata;
1235 >        dp = (uint32 *)ourdata;
1236 >        dph = (uint16 *)ourdata;
1237          for (y = 0; y < ymax; y++) {
1238                  getscan(y);
1239                  add2icon(y, scanline);
1240 <                if (scale)
1241 <                        shiftcolrs(scanline, xmax, scale);
1242 <                colrs_gambs(scanline, xmax);
938 <                if (ourras->image->blue_mask & 1)
1240 >                tmap_colrs(scanline, xmax);
1241 >                switch (ourras->image->blue_mask) {
1242 >                case 0xff:              /* 24-bit RGB */
1243                          for (x = 0; x < xmax; x++)
1244 <                                *dp++ = scanline[x][RED] << 16 |
1245 <                                        scanline[x][GRN] << 8 |
1246 <                                        scanline[x][BLU] ;
1247 <                else
1244 >                                *dp++ = (uint32)scanline[x][RED] << 16 |
1245 >                                        (uint32)scanline[x][GRN] << 8 |
1246 >                                        (uint32)scanline[x][BLU] ;
1247 >                        break;
1248 >                case 0xff0000:          /* 24-bit BGR */
1249                          for (x = 0; x < xmax; x++)
1250 <                                *dp++ = scanline[x][RED] |
1251 <                                        scanline[x][GRN] << 8 |
1252 <                                        scanline[x][BLU] << 16 ;
1250 >                                *dp++ = (uint32)scanline[x][RED] |
1251 >                                        (uint32)scanline[x][GRN] << 8 |
1252 >                                        (uint32)scanline[x][BLU] << 16 ;
1253 >                        break;
1254 > #if 0
1255 >                case 0x1f:              /* 15-bit RGB */
1256 >                        for (x = 0; x < xmax; x++)
1257 >                                *dph++ =        (scanline[x][RED] << 7 & 0x7c00) |
1258 >                                        (scanline[x][GRN] << 2 & 0x3e0) |
1259 >                                        (unsigned)scanline[x][BLU] >> 3 ;
1260 >                        break;
1261 >                case 0x7c00:            /* 15-bit BGR */
1262 >                        for (x = 0; x < xmax; x++)
1263 >                                *dph++ =        (unsigned)scanline[x][RED] >> 3 |
1264 >                                        (scanline[x][GRN] << 2 & 0x3e0) |
1265 >                                        (scanline[x][BLU] << 7 & 0x7c00) ;
1266 >                        break;
1267 > #endif
1268 >                default:                /* unknown */
1269 >                        if (ourvis.depth > 16)
1270 >                                for (x = 0; x < xmax; x++) {
1271 >                                        *dp = ourras->image->red_mask &
1272 >                                                ourras->image->red_mask*scanline[x][RED]/255;
1273 >                                        *dp |= ourras->image->green_mask &
1274 >                                                ourras->image->green_mask*scanline[x][GRN]/255;
1275 >                                        *dp++ |= ourras->image->blue_mask &
1276 >                                                ourras->image->blue_mask*scanline[x][BLU]/255;
1277 >                                }
1278 >                        else
1279 >                                for (x = 0; x < xmax; x++) {
1280 >                                        *dph = ourras->image->red_mask &
1281 >                                                ourras->image->red_mask*scanline[x][RED]/255;
1282 >                                        *dph |= ourras->image->green_mask &
1283 >                                                ourras->image->green_mask*scanline[x][GRN]/255;
1284 >                                        *dph++ |= ourras->image->blue_mask &
1285 >                                                ourras->image->blue_mask*scanline[x][BLU]/255;
1286 >                                }
1287 >                        break;
1288 >                }
1289          }
1290   }
1291  
1292  
1293 < getgrey()                       /* get greyscale data */
1293 > static void
1294 > getgrey(void)                   /* get greyscale data */
1295   {
1296          int     y;
1297          register unsigned char  *dp;
1298          register int    x;
1299 <                                        /* set gamma correction */
1300 <        setcolrgam(gamcor);
1299 >                                        /* initialize tone mapping */
1300 >        make_tonemap();
1301                                          /* read and convert file */
1302          dp = ourdata;
1303          for (y = 0; y < ymax; y++) {
1304                  getscan(y);
1305                  add2icon(y, scanline);
1306 <                if (scale)
965 <                        shiftcolrs(scanline, xmax, scale);
966 <                for (x = 0; x < xmax; x++)
967 <                        scanline[x][GRN] = normbright(scanline[x]);
968 <                colrs_gambs(scanline, xmax);
1306 >                tmap_colrs(scanline, xmax);
1307                  if (maxcolors < 256)
1308                          for (x = 0; x < xmax; x++)
1309 <                                *dp++ = ((long)scanline[x][GRN] *
1309 >                                *dp++ = ((int32)scanline[x][GRN] *
1310                                          maxcolors + maxcolors/2) >> 8;
1311                  else
1312                          for (x = 0; x < xmax; x++)
# Line 976 | Line 1314 | getgrey()                      /* get greyscale data */
1314          }
1315          for (x = 0; x < maxcolors; x++)
1316                  clrtab[x][RED] = clrtab[x][GRN] =
1317 <                        clrtab[x][BLU] = ((long)x*256 + 128)/maxcolors;
1317 >                        clrtab[x][BLU] = ((int32)x*256 + 128)/maxcolors;
1318   }
1319  
1320  
1321 < getmapped()                     /* get color-mapped data */
1321 > static void
1322 > getmapped(void)                 /* get color-mapped data */
1323   {
1324          int     y;
1325                                          /* make sure we can do it first */
1326          if (fname == NULL)
1327                  quiterr("cannot map colors from standard input");
1328 <                                        /* set gamma correction */
1329 <        setcolrgam(gamcor);
1328 >                                        /* initialize tone mapping */
1329 >        make_tonemap();
1330                                          /* make histogram */
1331 <        new_histo();
1331 >        if (new_histo((int32)xmax*ymax) == -1)
1332 >                quiterr("cannot initialize histogram");
1333          for (y = 0; y < ymax; y++) {
1334                  if (getscan(y) < 0)
1335                          break;
1336                  add2icon(y, scanline);
1337 <                if (scale)
998 <                        shiftcolrs(scanline, xmax, scale);
999 <                colrs_gambs(scanline, xmax);
1337 >                tmap_colrs(scanline, xmax);
1338                  cnt_colrs(scanline, xmax);
1339          }
1340                                          /* map pixels */
# Line 1004 | Line 1342 | getmapped()                    /* get color-mapped data */
1342                  quiterr("cannot create color map");
1343          for (y = 0; y < ymax; y++) {
1344                  getscan(y);
1345 <                if (scale)
1008 <                        shiftcolrs(scanline, xmax, scale);
1009 <                colrs_gambs(scanline, xmax);
1345 >                tmap_colrs(scanline, xmax);
1346                  if (dither)
1347                          dith_colrs(ourdata+y*xmax, scanline, xmax);
1348                  else
# Line 1015 | Line 1351 | getmapped()                    /* get color-mapped data */
1351   }
1352  
1353  
1354 < scale_rcolors(xr, sf)                   /* scale color map */
1355 < register XRASTER        *xr;
1356 < double  sf;
1354 > static void
1355 > scale_rcolors(                  /* scale color map */
1356 >        register XRASTER        *xr,
1357 >        double  sf
1358 > )
1359   {
1360          register int    i;
1361          long    maxv;
# Line 1043 | Line 1381 | double sf;
1381   }
1382  
1383  
1384 < getscan(y)
1385 < int  y;
1384 > static int
1385 > getscan(
1386 >        int  y
1387 > )
1388   {
1389          static int  trunced = -1;               /* truncated file? */
1390   skipit:
1391          if (trunced >= 0 && y >= trunced) {
1392 <                bzero(scanline, xmax*sizeof(COLR));
1392 >                memset(scanline, '\0', xmax*sizeof(COLR));
1393                  return(-1);
1394          }
1395          if (y != cury) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines