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.56 by greg, Sat Feb 22 02:07:28 2003 UTC vs.
Revision 2.80 by greg, Tue Jun 3 21:31:51 2025 UTC

# Line 1 | Line 1
1   #ifndef lint
2 < static const char       RCSid[] = "$Id$";
2 > static const char RCSid[] = "$Id$";
3   #endif
4   /*
5   *  x11image.c - driver for X-windows
# Line 18 | Line 18 | static const char      RCSid[] = "$Id$";
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>
# Line 26 | Line 30 | static const char      RCSid[] = "$Id$";
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"
# Line 78 | Line 83 | 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 */
86 > uby8  *cscan;                           /* encoded chroma scanline */
87 > uby8  *pscan;                           /* compute pixel scanline */
88  
89   RESOLU  inpres;                         /* input resolution and ordering */
90   int  xmax, ymax;                        /* picture dimensions */
# Line 93 | 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 110 | Line 118 | char  *geometry = NULL;                        /* geometry specification */
118   char  icondata[ICONSIZ*ICONSIZ/8];      /* icon bitmap data */
119   int  iconwidth = 0, iconheight = 0;
120  
113 char  *progname;
114
121   char  errmsg[128];
122  
123 < BYTE  clrtab[256][3];                   /* global color map */
123 > uby8  clrtab[256][3];                   /* global color map */
124  
119 extern long  ftell();
125  
121 extern char  *getenv();
122
126   Display  *thedisplay;
127   Atom  closedownAtom, wmProtocolsAtom;
128  
129   int  sigrecv;
130  
131 < int  onsig() { sigrecv++; }
131 > void  onsig(int i) { sigrecv++; }
132  
133 + typedef void doboxf_t(COLR *scn, int n, void *);
134  
135 < main(argc, argv)
136 < int  argc;
137 < char  *argv[];
135 > static gethfunc headline;
136 > static void init(int argc, char **argv);
137 > static void quiterr(char *err);
138 > static int viscmp(XVisualInfo *v1, XVisualInfo *v2);
139 > static void getbestvis(void);
140 > static void getras(void);
141 > static void getevent(void);
142 > static int traceray(int xpos, int ypos);
143 > static int docom(XKeyPressedEvent *ekey);
144 > static void moveimage(XButtonPressedEvent *ebut);
145 > static void getbox(XButtonPressedEvent *ebut);
146 > static void trackrays(XButtonPressedEvent *ebut);
147 > static void revbox(int x0, int y0, int x1, int y1);
148 > static doboxf_t colavg;
149 > static doboxf_t addfix;
150 > static int avgbox(COLOR cavg);
151 > static int dobox(doboxf_t *f, void *p);
152 > static void make_tonemap(void);
153 > static void tmap_colrs(COLR *scn, int len);
154 > static void getmono(void);
155 > static void add2icon(int y, COLR *scan);
156 > static void getfull(void);
157 > static void getgrey(void);
158 > static void getmapped(void);
159 > static void scale_rcolors(XRASTER *xr, double sf);
160 > static int getscan(int y);
161 >
162 >
163 > int
164 > main(int  argc, char  *argv[])
165   {
135        int  headline();
166          int  i;
167          int  pid;
168          
169 <        progname = argv[0];
169 >        fixargv0(argv[0]);              /* sets global progname */
170          fin = stdin;
171  
172          for (i = 1; i < argc; i++)
# Line 239 | Line 269 | char  *argv[];
269                  getevent();             /* main loop */
270   userr:
271          fprintf(stderr,
272 < "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e spec][-g gamcor][-s][-ospec][-t intvl] pic ..\n",
272 > "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e spec][-g gamcor][-s][-ospec][-t intvl] hdr ..\n",
273                          progname);
274          exit(1);
275   }
276  
277  
278 < int
279 < headline(s)             /* get relevant info from header */
280 < char  *s;
278 > static int
279 > headline(               /* get relevant info from header */
280 >        char    *s,
281 >        void    *p
282 > )
283   {
284 <        char  fmt[32];
284 >        char  fmt[MAXFMTLEN];
285  
286          if (isexpos(s))
287                  exposure *= exposval(s);
288          else if (formatval(fmt, s))
289 <                wrongformat = strcmp(fmt, COLRFMT);
290 <        else if (isview(s) && sscanview(&ourview, s) > 0)
291 <                gotview++;
289 >                wrongformat = strcmp(fmt, COLRFMT) && strcmp(fmt, SPECFMT);
290 >        else if (isview(s))
291 >                gotview += sscanview(&ourview, s);
292 >        else if (isncomp(s))
293 >                NCSAMP = ncompval(s);
294 >        else if (iswlsplit(s))
295 >                wlsplitval(WLPART, s);
296          return(0);
297   }
298  
299  
300 < init(argc, argv)                        /* get data and open window */
301 < int argc;
302 < char **argv;
300 > static void
301 > init(                   /* get data and open window */
302 >        int argc,
303 >        char **argv
304 > )
305   {
306          XSetWindowAttributes    ourwinattr;
307          XClassHint      xclshints;
# Line 272 | Line 310 | char **argv;
310          XTextProperty   windowName, iconName;
311          XGCValues       xgcv;
312          char    *name;
313 <        register int    i;
313 >        int     i;
314          
315          if (fname != NULL) {
316                  scanpos = (long *)malloc(ymax*sizeof(long));
# Line 361 | Line 399 | char **argv;
399          windowName.encoding = iconName.encoding = XA_STRING;
400          windowName.format = iconName.format = 8;
401          windowName.value = (u_char *)name;
402 <        windowName.nitems = strlen(windowName.value);
402 >        windowName.nitems = strlen((char *)windowName.value);
403          iconName.value = (u_char *)name;
404 <        iconName.nitems = strlen(windowName.value);
404 >        iconName.nitems = strlen((char *)windowName.value);
405  
406          xclshints.res_name = NULL;
407          xclshints.res_class = "Ximage";
# Line 377 | Line 415 | char **argv;
415   } /* end of init */
416  
417  
418 < quiterr(err)            /* print message and exit */
419 < char  *err;
418 > static void
419 > quiterr(                /* print message and exit */
420 >        char  *err
421 > )
422   {
423 <        register int  es;
423 >        int  es;
424          int  cs;
425  
426 <        if (es = err != NULL)
426 >        if ( (es = (err != NULL)) )
427                  fprintf(stderr, "%s: %s: %s\n", progname,
428                                  fname==NULL?"<stdin>":fname, err);
429          if (thedisplay != NULL)
430                  XCloseDisplay(thedisplay);
431 <        if (parent < 0 & sigrecv == 0)
431 >        if ((parent < 0) & (sigrecv == 0))
432                  kill(getppid(), SIGCONT);
433          while (parent > 0 && wait(&cs) != -1) { /* wait for any children */
434                  if (es == 0)
# Line 400 | Line 440 | char  *err;
440  
441  
442   static int
443 < viscmp(v1,v2)           /* compare visual to see which is better, descending */
444 < register XVisualInfo    *v1, *v2;
443 > viscmp(         /* compare visual to see which is better, descending */
444 >        XVisualInfo     *v1,
445 >        XVisualInfo     *v2
446 > )
447   {
448          int     bad1 = 0, bad2 = 0;
449 <        register int  *rp;
449 >        int  *rp;
450  
451          if (v1->class == v2->class) {
452 <                if (v1->class == TrueColor || v1->class == DirectColor) {
453 <                                        /* prefer 24-bit to 32-bit */
454 <                        if (v1->depth == 24 && v2->depth == 32)
452 >                if ((v1->class == TrueColor) | (v1->class == DirectColor)) {
453 >                                        /* prefer 24-bit */
454 >                        if ((v1->depth == 24) & (v2->depth > 24))
455                                  return(-1);
456 <                        if (v1->depth == 32 && v2->depth == 24)
456 >                        if ((v1->depth > 24) & (v2->depth == 24))
457                                  return(1);
458                                          /* go for maximum depth otherwise */
459                          return(v2->depth - v1->depth);
460                  }
461                                          /* don't be too greedy */
462 <                if (maxcolors <= 1<<v1->depth && maxcolors <= 1<<v2->depth)
462 >                if ((maxcolors <= 1<<v1->depth) & (maxcolors <= 1<<v2->depth))
463                          return(v1->depth - v2->depth);
464                  return(v2->depth - v1->depth);
465          }
466                                          /* prefer Pseudo when < 15-bit */
467 <        if ((v1->class == TrueColor || v1->class == DirectColor) &&
467 >        if ((v1->class == TrueColor) | (v1->class == DirectColor) &&
468                          v1->depth < 15)
469                  bad1 = 1;
470 <        if ((v2->class == TrueColor || v2->class == DirectColor) &&
470 >        if ((v2->class == TrueColor) | (v2->class == DirectColor) &&
471                          v2->depth < 15)
472                  bad2 = -1;
473          if (bad1 | bad2)
# Line 441 | Line 483 | register XVisualInfo   *v1, *v2;
483   }
484  
485  
486 < getbestvis()                    /* get the best visual for this screen */
486 > static void
487 > getbestvis(void)                        /* get the best visual for this screen */
488   {
489   #ifdef DEBUG
490   static char  vistype[][12] = {
# Line 460 | Line 503 | static char  vistype[][12] = {
503          };
504          XVisualInfo     *xvi;
505          int     vismatched;
506 <        register int    i, j;
506 >        int     i, j;
507  
508          if (greyscale) {
509                  ourrank = rankings[2];
# Line 493 | Line 536 | static char  vistype[][12] = {
536          if (viscmp(&xvi[i],&ourvis) > 0)
537                  quiterr("inadequate visuals on this screen");
538                                          /* OK, we'll use it */
539 <        copystruct(&ourvis, &xvi[i]);
539 >        ourvis = xvi[i];
540   #ifdef DEBUG
541          fprintf(stderr, "Selected visual type %s, depth %d\n",
542                          vistype[ourvis.class], ourvis.depth);
# Line 523 | Line 566 | static char  vistype[][12] = {
566   }
567  
568  
569 < getras()                                /* get raster file */
569 > static void
570 > getras(void)                            /* get raster file */
571   {
528        XVisualInfo     vinfo;
529
572          if (maxcolors <= 2) {           /* monochrome */
573                  ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8));
574                  if (ourdata == NULL)
575                          goto fail;
576 <                ourras = make_raster(thedisplay, &ourvis, 1, ourdata,
576 >                ourras = make_raster(thedisplay, &ourvis, 1, (char *)ourdata,
577                                  xmax, ymax, 8);
578                  if (ourras == NULL)
579                          goto fail;
580                  getmono();
581 <        } else if (ourvis.class == TrueColor | ourvis.class == DirectColor) {
582 <                int  datsiz = ourvis.depth>16 ? sizeof(int4) : sizeof(int2);
581 >        } else if ((ourvis.class == TrueColor) | (ourvis.class == DirectColor)) {
582 >                int  datsiz = ourvis.depth>16 ? sizeof(int32) : sizeof(int16);
583                  ourdata = (unsigned char *)malloc(datsiz*xmax*ymax);
584                  if (ourdata == NULL)
585                          goto fail;
586                  ourras = make_raster(thedisplay, &ourvis, datsiz*8,
587 <                                ourdata, xmax, ymax, datsiz*8);
587 >                                (char *)ourdata, xmax, ymax, datsiz*8);
588                  if (ourras == NULL)
589                          goto fail;
590                  getfull();
# Line 550 | Line 592 | getras()                               /* get raster file */
592                  ourdata = (unsigned char *)malloc(xmax*ymax);
593                  if (ourdata == NULL)
594                          goto fail;
595 <                ourras = make_raster(thedisplay, &ourvis, 8, ourdata,
595 >                ourras = make_raster(thedisplay, &ourvis, 8, (char *)ourdata,
596                                  xmax, ymax, 8);
597                  if (ourras == NULL)
598                          goto fail;
# Line 567 | Line 609 | fail:
609   }
610  
611  
612 < getevent()                              /* process the next event */
612 > static void
613 > getevent(void)                          /* process the next event */
614   {
615          XEvent xev;
616  
# Line 584 | Line 627 | getevent()                             /* process the next event */
627                  map_rcolors(ourras, wind);
628                  if (fast)
629                          make_rpixmap(ourras, wind);
630 <                if (!sequential & parent < 0 & sigrecv == 0) {
630 >                if ((!sequential) & (parent < 0) & (sigrecv == 0)) {
631                          kill(getppid(), SIGCONT);
632                          sigrecv--;
633                  }
# Line 622 | Line 665 | getevent()                             /* process the next event */
665   }
666  
667  
668 < traceray(xpos, ypos)                    /* print requested pixel data */
669 < int  xpos, ypos;
668 > static int
669 > traceray(                       /* print requested pixel data */
670 >        int  xpos,
671 >        int  ypos
672 > )
673   {
674 <        extern char  *index();
629 <        FLOAT  hv[2];
674 >        RREAL  hv[2];
675          FVECT  rorg, rdir;
676          COLOR  cval;
677 <        register char  *cp;
677 >        char  *cp;
678  
679          bbox.xmin = xpos; bbox.xsiz = 1;
680          bbox.ymin = ypos; bbox.ysiz = 1;
# Line 666 | Line 711 | int  xpos, ypos;
711   }
712  
713  
714 < docom(ekey)                             /* execute command */
715 < XKeyPressedEvent  *ekey;
714 > static int
715 > docom(                          /* execute command */
716 >        XKeyPressedEvent  *ekey
717 > )
718   {
719          char  buf[80];
720          COLOR  cval;
721          XColor  cvx;
722          int  com, n;
723          double  comp;
724 <        FLOAT  hv[2];
724 >        RREAL  hv[2];
725  
726          n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL);
727          if (n == 0)
# Line 794 | Line 841 | XKeyPressedEvent  *ekey;
841                  free_rpixmap(ourras);
842                  return(0);
843          case '0':                               /* recenter origin */
844 <                if (xoff == 0 & yoff == 0)
844 >                if ((xoff == 0) & (yoff == 0))
845                          return(0);
846                  xoff = yoff = 0;
847                  XClearWindow(thedisplay, wind);
# Line 810 | Line 857 | XKeyPressedEvent  *ekey;
857   }
858  
859  
860 < moveimage(ebut)                         /* shift the image */
861 < XButtonPressedEvent  *ebut;
860 > static void
861 > moveimage(                              /* shift the image */
862 >        XButtonPressedEvent  *ebut
863 > )
864   {
865          XEvent  e;
866          int     mxo, myo;
# Line 835 | Line 884 | XButtonPressedEvent  *ebut;
884   }
885  
886  
887 < getbox(ebut)                            /* get new bbox */
888 < XButtonPressedEvent  *ebut;
887 > static void
888 > getbox(                         /* get new bbox */
889 >        XButtonPressedEvent  *ebut
890 > )
891   {
892          XEvent  e;
893  
# Line 863 | Line 914 | XButtonPressedEvent  *ebut;
914   }
915  
916  
917 < trackrays(ebut)                         /* trace rays as mouse moves */
918 < XButtonPressedEvent  *ebut;
917 > static void
918 > trackrays(                              /* trace rays as mouse moves */
919 >        XButtonPressedEvent  *ebut
920 > )
921   {
922          XEvent  e;
923          unsigned long   lastrept;
# Line 882 | Line 935 | XButtonPressedEvent  *ebut;
935   }
936  
937  
938 < revbox(x0, y0, x1, y1)                  /* draw bbox with reversed lines */
939 < int  x0, y0, x1, y1;
938 > static void
939 > revbox(                 /* draw bbox with reversed lines */
940 >        int  x0,
941 >        int  y0,
942 >        int  x1,
943 >        int  y1
944 > )
945   {
946          revline(x0, y0, x1, y0);
947          revline(x0, y1, x1, y1);
# Line 892 | Line 950 | int  x0, y0, x1, y1;
950   }
951  
952  
953 < int
954 < colavg(scn, n, cavg)
955 < register COLR   *scn;
956 < register int    n;
957 < COLOR   cavg;
953 > static void
954 > colavg(
955 >        COLR    *scn,
956 >        int     n,
957 >        void *cavg
958 > )
959   {
960          COLOR   col;
961  
962          while (n--) {
963 <                colr_color(col, *scn++);
964 <                addcolor(cavg, col);
963 >                colr_color(col, *scn);
964 >                addcolor((COLORV*)cavg, col);
965 >                scn++;
966          }
967   }
968  
969  
970 < int
971 < avgbox(cavg)                            /* average color over current bbox */
972 < COLOR   cavg;
970 > static int
971 > avgbox(                         /* average color over current bbox */
972 >        COLOR   cavg
973 > )
974   {
975          double  d;
976 <        register int    rval;
976 >        int     rval;
977  
978          setcolor(cavg, 0., 0., 0.);
979 <        rval = dobox(colavg, (char *)cavg);
979 >        rval = dobox(colavg, cavg);
980          if (rval > 0) {
981                  d = 1./rval;
982                  scalecolor(cavg, d);
# Line 924 | Line 985 | COLOR  cavg;
985   }
986  
987  
988 < int
989 < dobox(f, p)                             /* run function over bbox */
990 < int     (*f)();                 /* function to call for each subscan */
991 < char    *p;                     /* pointer to private data */
988 > static int
989 > dobox(                          /* run function over bbox */
990 >        doboxf_t *f,                    /* function to call for each subscan */
991 >        void    *p                      /* pointer to private data */
992 > )
993   {
994          int  left, right, top, bottom;
995          int  y;
# Line 949 | Line 1011 | char   *p;                     /* pointer to private data */
1011          if (top >= bottom)
1012                  return(0);
1013          for (y = top; y < bottom; y++) {
1014 <                if (getscan(y) == -1)
1014 >                if (getscan(y) < 0)
1015                          return(-1);
1016                  (*f)(scanline+left, right-left, p);
1017          }
# Line 957 | Line 1019 | char   *p;                     /* pointer to private data */
1019   }
1020  
1021  
1022 < int
1023 < addfix(scn, n)                  /* add fixation points to histogram */
1024 < COLR    *scn;
1025 < int     n;
1022 > static void
1023 > addfix(                 /* add fixation points to histogram */
1024 >        COLR    *scn,
1025 >        int     n,
1026 >        void    *p
1027 > )
1028   {
1029 <        if (tmCvColrs(lscan, TM_NOCHROM, scn, n))
1029 >        TMstruct *      tms = (TMstruct *)p;
1030 >        
1031 >        if (tmCvColrs(tms, lscan, TM_NOCHROM, scn, n))
1032                  goto tmerr;
1033 <        if (tmAddHisto(lscan, n, FIXWEIGHT))
1033 >        if (tmAddHisto(tms, lscan, n, FIXWEIGHT))
1034                  goto tmerr;
1035          return;
1036   tmerr:
# Line 972 | Line 1038 | tmerr:
1038   }
1039  
1040  
1041 < make_tonemap()                  /* initialize tone mapping */
1041 > static void
1042 > make_tonemap(void)                      /* initialize tone mapping */
1043   {
1044          int  flags, y;
1045  
# Line 987 | Line 1054 | make_tonemap()                 /* initialize tone mapping */
1054          }
1055          flags = tmflags;                /* histogram adjustment */
1056          if (greyscale) flags |= TM_F_BW;
1057 <        if (tmTop != NULL) {            /* reuse old histogram if one */
1058 <                tmDone(tmTop);
1059 <                tmTop->flags = flags;
1057 >        if (tmGlobal != NULL) {         /* reuse old histogram if one */
1058 >                tmDone(tmCurrent); tmCurrent = NULL;
1059 >                tmGlobal->flags = flags;
1060          } else {                        /* else initialize */
1061                  if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL)
1062                          goto memerr;
1063                  if (greyscale) {
1064                          cscan = TM_NOCHROM;
1065 <                        if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL)
1065 >                        if ((pscan = (uby8 *)malloc(sizeof(uby8)*xmax)) == NULL)
1066                                  goto memerr;
1067 <                } else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax))
1067 >                } else if ((pscan=cscan = (uby8 *)malloc(3*sizeof(uby8)*xmax))
1068                                  == NULL)
1069                          goto memerr;
1070                                                  /* initialize tm library */
1071 <                if (tmInit(flags, stdprims, gamcor) == NULL)
1071 >                tmGlobal = tmInit(flags, stdprims, gamcor);
1072 >                if (tmGlobal == NULL)
1073                          goto memerr;
1074 <                if (tmSetSpace(stdprims, WHTEFFICACY/exposure))
1074 >                if (tmSetSpace(tmGlobal, stdprims, WHTEFFICACY/exposure))
1075                          goto tmerr;
1076                                                  /* compute picture histogram */
1077                  for (y = 0; y < ymax; y++) {
1078                          getscan(y);
1079 <                        if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax))
1079 >                        if (tmCvColrs(tmGlobal, lscan, TM_NOCHROM,
1080 >                                        scanline, xmax))
1081                                  goto tmerr;
1082 <                        if (tmAddHisto(lscan, xmax, 1))
1082 >                        if (tmAddHisto(tmGlobal, lscan, xmax, 1))
1083                                  goto tmerr;
1084                  }
1085          }
1086 <        tmDup();                        /* add fixations to duplicate map */
1087 <        dobox(addfix, NULL);
1086 >        tmCurrent = tmDup(tmGlobal);    /* add fixations to duplicate map */
1087 >        dobox(addfix, tmCurrent);
1088                                          /* (re)compute tone mapping */
1089 <        if (tmComputeMapping(gamcor, 0., 0.))
1089 >        if (tmComputeMapping(tmCurrent, gamcor, 0., 0.))
1090                  goto tmerr;
1091          return;
1092   memerr:
# Line 1027 | Line 1096 | tmerr:
1096   }
1097  
1098  
1099 < tmap_colrs(scn, len)            /* apply tone mapping to scanline */
1100 < register COLR  *scn;
1101 < int  len;
1099 > static void
1100 > tmap_colrs(             /* apply tone mapping to scanline */
1101 >        COLR  *scn,
1102 >        int  len
1103 > )
1104   {
1105 <        register BYTE  *ps;
1105 >        uby8  *ps;
1106  
1107          if (tmflags == TM_F_LINEAR) {
1108                  if (scale)
# Line 1041 | Line 1112 | int  len;
1112          }
1113          if (len > xmax)
1114                  quiterr("code error 1 in tmap_colrs");
1115 <        if (tmCvColrs(lscan, cscan, scn, len))
1115 >        if (tmCvColrs(tmCurrent, lscan, cscan, scn, len))
1116                  goto tmerr;
1117 <        if (tmMapPixels(pscan, lscan, cscan, len))
1117 >        if (tmMapPixels(tmCurrent, pscan, lscan, cscan, len))
1118                  goto tmerr;
1119          ps = pscan;
1120          if (greyscale)
# Line 1066 | Line 1137 | tmerr:
1137   }
1138  
1139  
1140 < getmono()                       /* get monochrome data */
1140 > static void
1141 > getmono(void)                   /* get monochrome data */
1142   {
1143 <        register unsigned char  *dp;
1144 <        register int    x, err;
1143 >        unsigned char   *dp;
1144 >        int     x, err;
1145          int     y, errp;
1146          short   *cerr;
1147  
# Line 1094 | Line 1166 | getmono()                      /* get monochrome data */
1166                          cerr[x] = err + errp;
1167                  }
1168          }
1169 <        free((void *)cerr);
1169 >        free(cerr);
1170   }
1171  
1172  
1173 < add2icon(y, scan)               /* add a scanline to our icon data */
1174 < int  y;
1175 < COLR  *scan;
1173 > static void
1174 > add2icon(               /* add a scanline to our icon data */
1175 >        int  y,
1176 >        COLR  *scan
1177 > )
1178   {
1179          static short  cerr[ICONSIZ];
1180          static int  ynext;
1181          static char  *dp;
1182          COLR  clr;
1183 <        register int  err;
1184 <        register int    x, ti;
1183 >        int  err;
1184 >        int     x, ti;
1185          int  errp;
1186  
1187          if (iconheight == 0) {          /* initialize */
# Line 1150 | Line 1224 | COLR  *scan;
1224   }
1225  
1226  
1227 < getfull()                       /* get full (24-bit) data */
1227 > static void
1228 > getfull(void)                   /* get full (24-bit) data */
1229   {
1230          int     y;
1231 <        register unsigned int4  *dp;
1232 <        register unsigned int2  *dph;
1233 <        register int    x;
1231 >        uint32  *dp;
1232 >        uint16  *dph;
1233 >        int     x;
1234                                          /* initialize tone mapping */
1235          make_tonemap();
1236                                          /* read and convert file */
1237 <        dp = (unsigned int4 *)ourdata;
1238 <        dph = (unsigned int2 *)ourdata;
1237 >        dp = (uint32 *)ourdata;
1238 >        dph = (uint16 *)ourdata;
1239          for (y = 0; y < ymax; y++) {
1240                  getscan(y);
1241                  add2icon(y, scanline);
# Line 1168 | Line 1243 | getfull()                      /* get full (24-bit) data */
1243                  switch (ourras->image->blue_mask) {
1244                  case 0xff:              /* 24-bit RGB */
1245                          for (x = 0; x < xmax; x++)
1246 <                                *dp++ = (unsigned int4)scanline[x][RED] << 16 |
1247 <                                        (unsigned int4)scanline[x][GRN] << 8 |
1248 <                                        (unsigned int4)scanline[x][BLU] ;
1246 >                                *dp++ = (uint32)scanline[x][RED] << 16 |
1247 >                                        (uint32)scanline[x][GRN] << 8 |
1248 >                                        (uint32)scanline[x][BLU] ;
1249                          break;
1250                  case 0xff0000:          /* 24-bit BGR */
1251                          for (x = 0; x < xmax; x++)
1252 <                                *dp++ = (unsigned int4)scanline[x][RED] |
1253 <                                        (unsigned int4)scanline[x][GRN] << 8 |
1254 <                                        (unsigned int4)scanline[x][BLU] << 16 ;
1252 >                                *dp++ = (uint32)scanline[x][RED] |
1253 >                                        (uint32)scanline[x][GRN] << 8 |
1254 >                                        (uint32)scanline[x][BLU] << 16 ;
1255                          break;
1256   #if 0
1257                  case 0x1f:              /* 15-bit RGB */
# Line 1217 | Line 1292 | getfull()                      /* get full (24-bit) data */
1292   }
1293  
1294  
1295 < getgrey()                       /* get greyscale data */
1295 > static void
1296 > getgrey(void)                   /* get greyscale data */
1297   {
1298          int     y;
1299 <        register unsigned char  *dp;
1300 <        register int    x;
1299 >        unsigned char   *dp;
1300 >        int     x;
1301                                          /* initialize tone mapping */
1302          make_tonemap();
1303                                          /* read and convert file */
# Line 1232 | Line 1308 | getgrey()                      /* get greyscale data */
1308                  tmap_colrs(scanline, xmax);
1309                  if (maxcolors < 256)
1310                          for (x = 0; x < xmax; x++)
1311 <                                *dp++ = ((int4)scanline[x][GRN] *
1311 >                                *dp++ = ((int32)scanline[x][GRN] *
1312                                          maxcolors + maxcolors/2) >> 8;
1313                  else
1314                          for (x = 0; x < xmax; x++)
# Line 1240 | Line 1316 | getgrey()                      /* get greyscale data */
1316          }
1317          for (x = 0; x < maxcolors; x++)
1318                  clrtab[x][RED] = clrtab[x][GRN] =
1319 <                        clrtab[x][BLU] = ((int4)x*256 + 128)/maxcolors;
1319 >                        clrtab[x][BLU] = ((int32)x*256 + 128)/maxcolors;
1320   }
1321  
1322  
1323 < getmapped()                     /* get color-mapped data */
1323 > static void
1324 > getmapped(void)                 /* get color-mapped data */
1325   {
1326          int     y;
1327                                          /* make sure we can do it first */
# Line 1253 | Line 1330 | getmapped()                    /* get color-mapped data */
1330                                          /* initialize tone mapping */
1331          make_tonemap();
1332                                          /* make histogram */
1333 <        if (new_histo((int4)xmax*ymax) == -1)
1333 >        if (new_histo((int32)xmax*ymax) == -1)
1334                  quiterr("cannot initialize histogram");
1335          for (y = 0; y < ymax; y++) {
1336                  if (getscan(y) < 0)
# Line 1276 | Line 1353 | getmapped()                    /* get color-mapped data */
1353   }
1354  
1355  
1356 < scale_rcolors(xr, sf)                   /* scale color map */
1357 < register XRASTER        *xr;
1358 < double  sf;
1356 > static void
1357 > scale_rcolors(                  /* scale color map */
1358 >        XRASTER *xr,
1359 >        double  sf
1360 > )
1361   {
1362 <        register int    i;
1362 >        int     i;
1363          long    maxv;
1364  
1365          if (xr->pixels == NULL)
# Line 1304 | Line 1383 | double sf;
1383   }
1384  
1385  
1386 < getscan(y)
1387 < int  y;
1386 > static int
1387 > getscan(
1388 >        int  y
1389 > )
1390   {
1391          static int  trunced = -1;               /* truncated file? */
1392   skipit:
1393 <        if (trunced >= 0 && y >= trunced) {
1394 <                bzero(scanline, xmax*sizeof(COLR));
1393 >        if (y == cury-1)                        /* already got it? */
1394 >                return(0);
1395 >        if ((trunced >= 0) & (y >= trunced)) {
1396 >                memset(scanline, 0, xmax*sizeof(COLR));
1397                  return(-1);
1398          }
1399          if (y != cury) {
1400 <                if (scanpos == NULL || scanpos[y] == -1)
1400 >                if (scanpos == NULL || scanpos[y] < 0)
1401                          return(-1);
1402 <                if (fseek(fin, scanpos[y], 0) == -1)
1402 >                if (fseek(fin, scanpos[y], 0) < 0)
1403                          quiterr("fseek error");
1404                  cury = y;
1405 <        } else if (scanpos != NULL && scanpos[y] == -1)
1405 >        } else if (scanpos != NULL && scanpos[y] < 0)
1406                  scanpos[y] = ftell(fin);
1407  
1408 <        if (freadcolrs(scanline, xmax, fin) < 0) {
1408 >        if (fread2colrs(scanline, xmax, fin, NCSAMP, WLPART) < 0) {
1409                  fprintf(stderr, "%s: %s: unfinished picture\n",
1410                                  progname, fname==NULL?"<stdin>":fname);
1411                  trunced = y;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines