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.57 by greg, Mon Mar 10 17:26:26 2003 UTC vs.
Revision 2.81 by greg, Sat Jun 7 05:09:46 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 19 | Line 19 | static const char RCSid[] = "$Id";
19   #include  "standard.h"
20  
21   #include  <signal.h>
22 + #include  <sys/wait.h>
23   #include  <X11/Xlib.h>
24   #include  <X11/cursorfont.h>
25   #include  <X11/Xutil.h>
26   #include  <X11/Xatom.h>
27  
28 + #include  "paths.h"
29   #include  "color.h"
30   #include  "tonemap.h"
31 + #include  "clrtab.h"
32   #include  "view.h"
33   #include  "x11raster.h"
34   #include  "random.h"
# Line 78 | Line 81 | int  gotview = 0;                      /* got parameters from file */
81  
82   COLR  *scanline;                        /* scan line buffer */
83   TMbright  *lscan;                       /* encoded luminance scanline */
84 < BYTE  *cscan;                           /* encoded chroma scanline */
85 < BYTE  *pscan;                           /* compute pixel scanline */
84 > uby8  *cscan;                           /* encoded chroma scanline */
85 > uby8  *pscan;                           /* compute pixel scanline */
86  
87   RESOLU  inpres;                         /* input resolution and ordering */
88   int  xmax, ymax;                        /* picture dimensions */
# Line 93 | Line 96 | double  exposure = 1.0;                        /* exposure compensation use
96  
97   int  wrongformat = 0;                   /* input in another format? */
98  
99 + TMstruct        *tmGlobal;              /* base tone-mapping */
100 + TMstruct        *tmCurrent;             /* curren tone-mapping */
101 +
102   GC      ourgc;                          /* standard graphics context */
103   GC      revgc;                          /* graphics context with GXinvert */
104  
# Line 110 | Line 116 | char  *geometry = NULL;                        /* geometry specification */
116   char  icondata[ICONSIZ*ICONSIZ/8];      /* icon bitmap data */
117   int  iconwidth = 0, iconheight = 0;
118  
113 char  *progname;
114
119   char  errmsg[128];
120  
121 < BYTE  clrtab[256][3];                   /* global color map */
121 > uby8  clrtab[256][3];                   /* global color map */
122  
119 extern long  ftell();
123  
121 extern char  *getenv();
122
124   Display  *thedisplay;
125   Atom  closedownAtom, wmProtocolsAtom;
126  
127   int  sigrecv;
128  
129 < int  onsig() { sigrecv++; }
129 > void  onsig(int i) { sigrecv++; }
130  
131 + typedef void doboxf_t(COLR *scn, int n, void *);
132  
133 < main(argc, argv)
134 < int  argc;
135 < char  *argv[];
133 > static gethfunc headline;
134 > static void init(int argc, char **argv);
135 > static void quiterr(char *err);
136 > static int viscmp(XVisualInfo *v1, XVisualInfo *v2);
137 > static void getbestvis(void);
138 > static void getras(void);
139 > static void getevent(void);
140 > static int traceray(int xpos, int ypos);
141 > static int docom(XKeyPressedEvent *ekey);
142 > static void moveimage(XButtonPressedEvent *ebut);
143 > static void getbox(XButtonPressedEvent *ebut);
144 > static void trackrays(XButtonPressedEvent *ebut);
145 > static void revbox(int x0, int y0, int x1, int y1);
146 > static doboxf_t colavg;
147 > static doboxf_t addfix;
148 > static int avgbox(COLOR cavg);
149 > static int dobox(doboxf_t *f, void *p);
150 > static void make_tonemap(void);
151 > static void tmap_colrs(COLR *scn, int len);
152 > static void getmono(void);
153 > static void add2icon(int y, COLR *scan);
154 > static void getfull(void);
155 > static void getgrey(void);
156 > static void getmapped(void);
157 > static void scale_rcolors(XRASTER *xr, double sf);
158 > static int getscan(int y);
159 >
160 >
161 > int
162 > main(int  argc, char  *argv[])
163   {
135        int  headline();
164          int  i;
165          int  pid;
166          
167 <        progname = argv[0];
167 >        fixargv0(argv[0]);              /* sets global progname */
168          fin = stdin;
169  
170          for (i = 1; i < argc; i++)
# Line 239 | Line 267 | char  *argv[];
267                  getevent();             /* main loop */
268   userr:
269          fprintf(stderr,
270 < "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e spec][-g gamcor][-s][-ospec][-t intvl] pic ..\n",
270 > "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e spec][-g gamcor][-s][-ospec][-t intvl] hdr ..\n",
271                          progname);
272          exit(1);
273   }
274  
275  
276 < int
277 < headline(s)             /* get relevant info from header */
278 < char  *s;
276 > static int
277 > headline(               /* get relevant info from header */
278 >        char    *s,
279 >        void    *p
280 > )
281   {
282 <        char  fmt[32];
282 >        char  fmt[MAXFMTLEN];
283  
284          if (isexpos(s))
285                  exposure *= exposval(s);
286          else if (formatval(fmt, s))
287 <                wrongformat = strcmp(fmt, COLRFMT);
288 <        else if (isview(s) && sscanview(&ourview, s) > 0)
289 <                gotview++;
287 >                wrongformat = strcmp(fmt, COLRFMT) && strcmp(fmt, SPECFMT);
288 >        else if (isview(s))
289 >                gotview += sscanview(&ourview, s);
290 >        else if (isncomp(s))
291 >                NCSAMP = ncompval(s);
292 >        else if (iswlsplit(s))
293 >                wlsplitval(WLPART, s);
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 272 | Line 308 | char **argv;
308          XTextProperty   windowName, iconName;
309          XGCValues       xgcv;
310          char    *name;
311 <        register int    i;
311 >        int     i;
312          
313          if (fname != NULL) {
314                  scanpos = (long *)malloc(ymax*sizeof(long));
# Line 361 | 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 377 | Line 413 | char **argv;
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;
421 >        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 (thedisplay != NULL)
428                  XCloseDisplay(thedisplay);
429 <        if (parent < 0 & sigrecv == 0)
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 400 | 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 >        XVisualInfo     *v1,
443 >        XVisualInfo     *v2
444 > )
445   {
446          int     bad1 = 0, bad2 = 0;
447 <        register int  *rp;
447 >        int  *rp;
448  
449          if (v1->class == v2->class) {
450 <                if (v1->class == TrueColor || v1->class == DirectColor) {
451 <                                        /* prefer 24-bit to 32-bit */
452 <                        if (v1->depth == 24 && v2->depth == 32)
450 >                if ((v1->class == TrueColor) | (v1->class == DirectColor)) {
451 >                                        /* prefer 24-bit */
452 >                        if ((v1->depth == 24) & (v2->depth > 24))
453                                  return(-1);
454 <                        if (v1->depth == 32 && v2->depth == 24)
454 >                        if ((v1->depth > 24) & (v2->depth == 24))
455                                  return(1);
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)
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 < 15-bit */
465 <        if ((v1->class == TrueColor || v1->class == DirectColor) &&
465 >        if ((v1->class == TrueColor) | (v1->class == DirectColor) &&
466                          v1->depth < 15)
467                  bad1 = 1;
468 <        if ((v2->class == TrueColor || v2->class == DirectColor) &&
468 >        if ((v2->class == TrueColor) | (v2->class == DirectColor) &&
469                          v2->depth < 15)
470                  bad2 = -1;
471          if (bad1 | bad2)
# Line 441 | 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 460 | Line 501 | static char  vistype[][12] = {
501          };
502          XVisualInfo     *xvi;
503          int     vismatched;
504 <        register int    i, j;
504 >        int     i, j;
505  
506          if (greyscale) {
507                  ourrank = rankings[2];
# Line 493 | 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 523 | Line 564 | static char  vistype[][12] = {
564   }
565  
566  
567 < getras()                                /* get raster file */
567 > static void
568 > getras(void)                            /* get raster file */
569   {
528        XVisualInfo     vinfo;
529
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 <                int  datsiz = ourvis.depth>16 ? sizeof(int4) : sizeof(int2);
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, datsiz*8,
585 <                                ourdata, xmax, ymax, datsiz*8);
585 >                                (char *)ourdata, xmax, ymax, datsiz*8);
586                  if (ourras == NULL)
587                          goto fail;
588                  getfull();
# Line 550 | 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;
# Line 567 | 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 584 | 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) {
628 >                if ((!sequential) & (parent < 0) & (sigrecv == 0)) {
629                          kill(getppid(), SIGCONT);
630                          sigrecv--;
631                  }
# Line 622 | Line 663 | getevent()                             /* process the next event */
663   }
664  
665  
666 < traceray(xpos, ypos)                    /* print requested pixel data */
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;
675 >        char  *cp;
676  
677          bbox.xmin = xpos; bbox.xsiz = 1;
678          bbox.ymin = ypos; bbox.ysiz = 1;
# Line 665 | Line 709 | int  xpos, ypos;
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 793 | 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);
# Line 809 | 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 834 | Line 882 | XButtonPressedEvent  *ebut;
882   }
883  
884  
885 < getbox(ebut)                            /* get new bbox */
886 < XButtonPressedEvent  *ebut;
885 > static void
886 > getbox(                         /* get new bbox */
887 >        XButtonPressedEvent  *ebut
888 > )
889   {
890          XEvent  e;
891  
# Line 862 | Line 912 | XButtonPressedEvent  *ebut;
912   }
913  
914  
915 < trackrays(ebut)                         /* trace rays as mouse moves */
916 < XButtonPressedEvent  *ebut;
915 > static void
916 > trackrays(                              /* trace rays as mouse moves */
917 >        XButtonPressedEvent  *ebut
918 > )
919   {
920          XEvent  e;
921          unsigned long   lastrept;
# Line 881 | Line 933 | XButtonPressedEvent  *ebut;
933   }
934  
935  
936 < revbox(x0, y0, x1, y1)                  /* draw bbox with reversed lines */
937 < int  x0, y0, x1, y1;
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);
# Line 891 | Line 948 | int  x0, y0, x1, y1;
948   }
949  
950  
951 < int
952 < colavg(scn, n, cavg)
953 < register COLR   *scn;
954 < register int    n;
955 < COLOR   cavg;
951 > static void
952 > colavg(
953 >        COLR    *scn,
954 >        int     n,
955 >        void *cavg
956 > )
957   {
958          COLOR   col;
959  
960          while (n--) {
961 <                colr_color(col, *scn++);
962 <                addcolor(cavg, col);
961 >                colr_color(col, *scn);
962 >                addcolor((COLORV*)cavg, col);
963 >                scn++;
964          }
965   }
966  
967  
968 < int
969 < avgbox(cavg)                            /* average color over current bbox */
970 < COLOR   cavg;
968 > static int
969 > avgbox(                         /* average color over current bbox */
970 >        COLOR   cavg
971 > )
972   {
973          double  d;
974 <        register int    rval;
974 >        int     rval;
975  
976          setcolor(cavg, 0., 0., 0.);
977 <        rval = dobox(colavg, (char *)cavg);
977 >        rval = dobox(colavg, cavg);
978          if (rval > 0) {
979                  d = 1./rval;
980                  scalecolor(cavg, d);
# Line 923 | Line 983 | COLOR  cavg;
983   }
984  
985  
986 < int
987 < dobox(f, p)                             /* run function over bbox */
988 < int     (*f)();                 /* function to call for each subscan */
989 < char    *p;                     /* pointer to private data */
986 > static int
987 > dobox(                          /* run function over bbox */
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;
# Line 948 | Line 1009 | char   *p;                     /* pointer to private data */
1009          if (top >= bottom)
1010                  return(0);
1011          for (y = top; y < bottom; y++) {
1012 <                if (getscan(y) == -1)
1012 >                if (getscan(y) < 0)
1013                          return(-1);
1014                  (*f)(scanline+left, right-left, p);
1015          }
# Line 956 | Line 1017 | char   *p;                     /* pointer to private data */
1017   }
1018  
1019  
1020 < int
1021 < addfix(scn, n)                  /* add fixation points to histogram */
1022 < COLR    *scn;
1023 < int     n;
1020 > static void
1021 > addfix(                 /* add fixation points to histogram */
1022 >        COLR    *scn,
1023 >        int     n,
1024 >        void    *p
1025 > )
1026   {
1027 <        if (tmCvColrs(lscan, TM_NOCHROM, scn, n))
1027 >        TMstruct *      tms = (TMstruct *)p;
1028 >        
1029 >        if (tmCvColrs(tms, lscan, TM_NOCHROM, scn, n))
1030                  goto tmerr;
1031 <        if (tmAddHisto(lscan, n, FIXWEIGHT))
1031 >        if (tmAddHisto(tms, lscan, n, FIXWEIGHT))
1032                  goto tmerr;
1033          return;
1034   tmerr:
# Line 971 | Line 1036 | tmerr:
1036   }
1037  
1038  
1039 < make_tonemap()                  /* initialize tone mapping */
1039 > static void
1040 > make_tonemap(void)                      /* initialize tone mapping */
1041   {
1042          int  flags, y;
1043  
# Line 986 | Line 1052 | make_tonemap()                 /* initialize tone mapping */
1052          }
1053          flags = tmflags;                /* histogram adjustment */
1054          if (greyscale) flags |= TM_F_BW;
1055 <        if (tmTop != NULL) {            /* reuse old histogram if one */
1056 <                tmDone(tmTop);
1057 <                tmTop->flags = flags;
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)
1063 >                        if ((pscan = (uby8 *)malloc(sizeof(uby8)*xmax)) == NULL)
1064                                  goto memerr;
1065 <                } else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax))
1065 >                } else if ((pscan=cscan = (uby8 *)malloc(3*sizeof(uby8)*xmax))
1066                                  == NULL)
1067                          goto memerr;
1068                                                  /* initialize tm library */
1069 <                if (tmInit(flags, stdprims, gamcor) == NULL)
1069 >                tmGlobal = tmInit(flags, stdprims, gamcor);
1070 >                if (tmGlobal == NULL)
1071                          goto memerr;
1072 <                if (tmSetSpace(stdprims, WHTEFFICACY/exposure))
1072 >                if (tmSetSpace(tmGlobal, stdprims, WHTEFFICACY/exposure))
1073                          goto tmerr;
1074                                                  /* compute picture histogram */
1075                  for (y = 0; y < ymax; y++) {
1076                          getscan(y);
1077 <                        if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax))
1077 >                        if (tmCvColrs(tmGlobal, lscan, TM_NOCHROM,
1078 >                                        scanline, xmax))
1079                                  goto tmerr;
1080 <                        if (tmAddHisto(lscan, xmax, 1))
1080 >                        if (tmAddHisto(tmGlobal, lscan, xmax, 1))
1081                                  goto tmerr;
1082                  }
1083          }
1084 <        tmDup();                        /* add fixations to duplicate map */
1085 <        dobox(addfix, NULL);
1084 >        tmCurrent = tmDup(tmGlobal);    /* add fixations to duplicate map */
1085 >        dobox(addfix, tmCurrent);
1086                                          /* (re)compute tone mapping */
1087 <        if (tmComputeMapping(gamcor, 0., 0.))
1087 >        if (tmComputeMapping(tmCurrent, gamcor, 0., 0.))
1088                  goto tmerr;
1089          return;
1090   memerr:
# Line 1026 | Line 1094 | tmerr:
1094   }
1095  
1096  
1097 < tmap_colrs(scn, len)            /* apply tone mapping to scanline */
1098 < register COLR  *scn;
1099 < int  len;
1097 > static void
1098 > tmap_colrs(             /* apply tone mapping to scanline */
1099 >        COLR  *scn,
1100 >        int  len
1101 > )
1102   {
1103 <        register BYTE  *ps;
1103 >        uby8  *ps;
1104  
1105          if (tmflags == TM_F_LINEAR) {
1106                  if (scale)
# Line 1040 | Line 1110 | int  len;
1110          }
1111          if (len > xmax)
1112                  quiterr("code error 1 in tmap_colrs");
1113 <        if (tmCvColrs(lscan, cscan, scn, len))
1113 >        if (tmCvColrs(tmCurrent, lscan, cscan, scn, len))
1114                  goto tmerr;
1115 <        if (tmMapPixels(pscan, lscan, cscan, len))
1115 >        if (tmMapPixels(tmCurrent, pscan, lscan, cscan, len))
1116                  goto tmerr;
1117          ps = pscan;
1118          if (greyscale)
# Line 1065 | Line 1135 | tmerr:
1135   }
1136  
1137  
1138 < getmono()                       /* get monochrome data */
1138 > static void
1139 > getmono(void)                   /* get monochrome data */
1140   {
1141 <        register unsigned char  *dp;
1142 <        register int    x, err;
1141 >        unsigned char   *dp;
1142 >        int     x, err;
1143          int     y, errp;
1144          short   *cerr;
1145  
# Line 1093 | Line 1164 | getmono()                      /* get monochrome data */
1164                          cerr[x] = err + errp;
1165                  }
1166          }
1167 <        free((void *)cerr);
1167 >        free(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;
1179          static char  *dp;
1180          COLR  clr;
1181 <        register int  err;
1182 <        register int    x, ti;
1181 >        int  err;
1182 >        int     x, ti;
1183          int  errp;
1184  
1185          if (iconheight == 0) {          /* initialize */
# Line 1149 | 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;
1230 <        register unsigned int2  *dph;
1231 <        register int    x;
1229 >        uint32  *dp;
1230 >        uint16  *dph;
1231 >        int     x;
1232                                          /* initialize tone mapping */
1233          make_tonemap();
1234                                          /* read and convert file */
1235 <        dp = (unsigned int4 *)ourdata;
1236 <        dph = (unsigned int2 *)ourdata;
1235 >        dp = (uint32 *)ourdata;
1236 >        dph = (uint16 *)ourdata;
1237          for (y = 0; y < ymax; y++) {
1238                  getscan(y);
1239                  add2icon(y, scanline);
# Line 1167 | Line 1241 | getfull()                      /* get full (24-bit) data */
1241                  switch (ourras->image->blue_mask) {
1242                  case 0xff:              /* 24-bit RGB */
1243                          for (x = 0; x < xmax; x++)
1244 <                                *dp++ = (unsigned int4)scanline[x][RED] << 16 |
1245 <                                        (unsigned int4)scanline[x][GRN] << 8 |
1246 <                                        (unsigned int4)scanline[x][BLU] ;
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++ = (unsigned int4)scanline[x][RED] |
1251 <                                        (unsigned int4)scanline[x][GRN] << 8 |
1252 <                                        (unsigned int4)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 */
# Line 1216 | Line 1290 | getfull()                      /* get full (24-bit) data */
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;
1297 >        unsigned char   *dp;
1298 >        int     x;
1299                                          /* initialize tone mapping */
1300          make_tonemap();
1301                                          /* read and convert file */
# Line 1231 | Line 1306 | getgrey()                      /* get greyscale data */
1306                  tmap_colrs(scanline, xmax);
1307                  if (maxcolors < 256)
1308                          for (x = 0; x < xmax; x++)
1309 <                                *dp++ = ((int4)scanline[x][GRN] *
1309 >                                *dp++ = ((int32)scanline[x][GRN] *
1310                                          maxcolors + maxcolors/2) >> 8;
1311                  else
1312                          for (x = 0; x < xmax; x++)
# Line 1239 | 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] = ((int4)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 */
# Line 1252 | Line 1328 | getmapped()                    /* get color-mapped data */
1328                                          /* initialize tone mapping */
1329          make_tonemap();
1330                                          /* make histogram */
1331 <        if (new_histo((int4)xmax*ymax) == -1)
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)
# Line 1275 | 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 >        XRASTER *xr,
1357 >        double  sf
1358 > )
1359   {
1360 <        register int    i;
1360 >        int     i;
1361          long    maxv;
1362  
1363          if (xr->pixels == NULL)
# Line 1303 | 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));
1391 >        if (y == cury-1)                        /* already got it? */
1392 >                return(0);
1393 >        if ((trunced >= 0) & (y >= trunced)) {
1394 >                memset(scanline, 0, xmax*sizeof(COLR));
1395                  return(-1);
1396          }
1397          if (y != cury) {
1398 <                if (scanpos == NULL || scanpos[y] == -1)
1398 >                if (scanpos == NULL || scanpos[y] < 0)
1399                          return(-1);
1400 <                if (fseek(fin, scanpos[y], 0) == -1)
1400 >                if (fseek(fin, scanpos[y], 0) < 0)
1401                          quiterr("fseek error");
1402                  cury = y;
1403 <        } else if (scanpos != NULL && scanpos[y] == -1)
1403 >        } else if (scanpos != NULL && scanpos[y] < 0)
1404                  scanpos[y] = ftell(fin);
1405  
1406 <        if (freadcolrs(scanline, xmax, fin) < 0) {
1406 >        if (fread2colrs(scanline, xmax, fin, NCSAMP, WLPART) < 0) {
1407                  fprintf(stderr, "%s: %s: unfinished picture\n",
1408                                  progname, fname==NULL?"<stdin>":fname);
1409                  trunced = y;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines