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.66 by schorsch, Sun Mar 28 20:33:14 2004 UTC vs.
Revision 2.79 by greg, Mon Apr 28 01:37:07 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 22 | Line 22 | static const char RCSid[] = "$Id";
22   #include  <signal.h>
23   #include  <unistd.h>
24   #include  <sys/types.h>
25 < #include  <wait.h>
25 > #include  <sys/wait.h>
26   #include  <X11/Xlib.h>
27   #include  <X11/cursorfont.h>
28   #include  <X11/Xutil.h>
# Line 83 | 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 98 | 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 119 | Line 122 | char  *progname;
122  
123   char  errmsg[128];
124  
125 < BYTE  clrtab[256][3];                   /* global color map */
125 > uby8  clrtab[256][3];                   /* global color map */
126  
127  
128   Display  *thedisplay;
# Line 268 | Line 271 | main(int  argc, char  *argv[])
271                  getevent();             /* main loop */
272   userr:
273          fprintf(stderr,
274 < "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e spec][-g gamcor][-s][-ospec][-t intvl] pic ..\n",
274 > "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e spec][-g gamcor][-s][-ospec][-t intvl] hdr ..\n",
275                          progname);
276          exit(1);
277   }
# Line 280 | Line 283 | headline(              /* get relevant info from header */
283          void    *p
284   )
285   {
286 <        char  fmt[32];
286 >        char  fmt[MAXFMTLEN];
287  
288          if (isexpos(s))
289                  exposure *= exposval(s);
290          else if (formatval(fmt, s))
291 <                wrongformat = strcmp(fmt, COLRFMT);
292 <        else if (isview(s) && sscanview(&ourview, s) > 0)
293 <                gotview++;
291 >                wrongformat = strcmp(fmt, COLRFMT) && strcmp(fmt, SPECFMT);
292 >        else if (isview(s))
293 >                gotview += sscanview(&ourview, s);
294 >        else if (isncomp(s))
295 >                NCSAMP = ncompval(s);
296 >        else if (iswlsplit(s))
297 >                wlsplitval(WLPART, s);
298          return(0);
299   }
300  
# Line 305 | Line 312 | init(                  /* get data and open window */
312          XTextProperty   windowName, iconName;
313          XGCValues       xgcv;
314          char    *name;
315 <        register int    i;
315 >        int     i;
316          
317          if (fname != NULL) {
318                  scanpos = (long *)malloc(ymax*sizeof(long));
# Line 394 | Line 401 | init(                  /* get data and open window */
401          windowName.encoding = iconName.encoding = XA_STRING;
402          windowName.format = iconName.format = 8;
403          windowName.value = (u_char *)name;
404 <        windowName.nitems = strlen(windowName.value);
404 >        windowName.nitems = strlen((char *)windowName.value);
405          iconName.value = (u_char *)name;
406 <        iconName.nitems = strlen(windowName.value);
406 >        iconName.nitems = strlen((char *)windowName.value);
407  
408          xclshints.res_name = NULL;
409          xclshints.res_class = "Ximage";
# Line 415 | Line 422 | quiterr(               /* print message and exit */
422          char  *err
423   )
424   {
425 <        register int  es;
425 >        int  es;
426          int  cs;
427  
428 <        if ( (es = err != NULL) )
428 >        if ( (es = (err != NULL)) )
429                  fprintf(stderr, "%s: %s: %s\n", progname,
430                                  fname==NULL?"<stdin>":fname, err);
431          if (thedisplay != NULL)
# Line 436 | Line 443 | quiterr(               /* print message and exit */
443  
444   static int
445   viscmp(         /* compare visual to see which is better, descending */
446 <        register XVisualInfo    *v1,
447 <        register XVisualInfo    *v2
446 >        XVisualInfo     *v1,
447 >        XVisualInfo     *v2
448   )
449   {
450          int     bad1 = 0, bad2 = 0;
451 <        register int  *rp;
451 >        int  *rp;
452  
453          if (v1->class == v2->class) {
454 <                if (v1->class == TrueColor || v1->class == DirectColor) {
455 <                                        /* prefer 24-bit to 32-bit */
456 <                        if (v1->depth == 24 && v2->depth == 32)
454 >                if ((v1->class == TrueColor) | (v1->class == DirectColor)) {
455 >                                        /* prefer 24-bit */
456 >                        if ((v1->depth == 24) & (v2->depth > 24))
457                                  return(-1);
458 <                        if (v1->depth == 32 && v2->depth == 24)
458 >                        if ((v1->depth > 24) & (v2->depth == 24))
459                                  return(1);
460                                          /* go for maximum depth otherwise */
461                          return(v2->depth - v1->depth);
462                  }
463                                          /* don't be too greedy */
464 <                if (maxcolors <= 1<<v1->depth && maxcolors <= 1<<v2->depth)
464 >                if ((maxcolors <= 1<<v1->depth) & (maxcolors <= 1<<v2->depth))
465                          return(v1->depth - v2->depth);
466                  return(v2->depth - v1->depth);
467          }
468                                          /* prefer Pseudo when < 15-bit */
469 <        if ((v1->class == TrueColor || v1->class == DirectColor) &&
469 >        if ((v1->class == TrueColor) | (v1->class == DirectColor) &&
470                          v1->depth < 15)
471                  bad1 = 1;
472 <        if ((v2->class == TrueColor || v2->class == DirectColor) &&
472 >        if ((v2->class == TrueColor) | (v2->class == DirectColor) &&
473                          v2->depth < 15)
474                  bad2 = -1;
475          if (bad1 | bad2)
# Line 498 | Line 505 | static char  vistype[][12] = {
505          };
506          XVisualInfo     *xvi;
507          int     vismatched;
508 <        register int    i, j;
508 >        int     i, j;
509  
510          if (greyscale) {
511                  ourrank = rankings[2];
# Line 568 | Line 575 | getras(void)                           /* get raster file */
575                  ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8));
576                  if (ourdata == NULL)
577                          goto fail;
578 <                ourras = make_raster(thedisplay, &ourvis, 1, ourdata,
578 >                ourras = make_raster(thedisplay, &ourvis, 1, (char *)ourdata,
579                                  xmax, ymax, 8);
580                  if (ourras == NULL)
581                          goto fail;
# Line 579 | Line 586 | getras(void)                           /* get raster file */
586                  if (ourdata == NULL)
587                          goto fail;
588                  ourras = make_raster(thedisplay, &ourvis, datsiz*8,
589 <                                ourdata, xmax, ymax, datsiz*8);
589 >                                (char *)ourdata, xmax, ymax, datsiz*8);
590                  if (ourras == NULL)
591                          goto fail;
592                  getfull();
# Line 587 | Line 594 | getras(void)                           /* get raster file */
594                  ourdata = (unsigned char *)malloc(xmax*ymax);
595                  if (ourdata == NULL)
596                          goto fail;
597 <                ourras = make_raster(thedisplay, &ourvis, 8, ourdata,
597 >                ourras = make_raster(thedisplay, &ourvis, 8, (char *)ourdata,
598                                  xmax, ymax, 8);
599                  if (ourras == NULL)
600                          goto fail;
# Line 669 | Line 676 | traceray(                      /* print requested pixel data */
676          RREAL  hv[2];
677          FVECT  rorg, rdir;
678          COLOR  cval;
679 <        register char  *cp;
679 >        char  *cp;
680  
681          bbox.xmin = xpos; bbox.xsiz = 1;
682          bbox.ymin = ypos; bbox.ysiz = 1;
# Line 947 | Line 954 | revbox(                        /* draw bbox with reversed lines */
954  
955   static void
956   colavg(
957 <        register COLR   *scn,
958 <        register int    n,
957 >        COLR    *scn,
958 >        int     n,
959          void *cavg
960   )
961   {
962          COLOR   col;
963  
964          while (n--) {
965 <                colr_color(col, *scn++);
965 >                colr_color(col, *scn);
966                  addcolor((COLORV*)cavg, col);
967 +                scn++;
968          }
969   }
970  
# Line 967 | Line 975 | avgbox(                                /* average color over current bbox */
975   )
976   {
977          double  d;
978 <        register int    rval;
978 >        int     rval;
979  
980          setcolor(cavg, 0., 0., 0.);
981 <        rval = dobox(colavg, (char *)cavg);
981 >        rval = dobox(colavg, cavg);
982          if (rval > 0) {
983                  d = 1./rval;
984                  scalecolor(cavg, d);
# Line 981 | Line 989 | avgbox(                                /* average color over current bbox */
989  
990   static int
991   dobox(                          /* run function over bbox */
984        //void  (*f)(),                 /* function to call for each subscan */
992          doboxf_t *f,                    /* function to call for each subscan */
993          void    *p                      /* pointer to private data */
994   )
# Line 1006 | Line 1013 | dobox(                         /* run function over bbox */
1013          if (top >= bottom)
1014                  return(0);
1015          for (y = top; y < bottom; y++) {
1016 <                if (getscan(y) == -1)
1016 >                if (getscan(y) < 0)
1017                          return(-1);
1018                  (*f)(scanline+left, right-left, p);
1019          }
# Line 1018 | Line 1025 | static void
1025   addfix(                 /* add fixation points to histogram */
1026          COLR    *scn,
1027          int     n,
1028 <        void    *p  /*NOTUSED*/
1028 >        void    *p
1029   )
1030   {
1031 <        if (tmCvColrs(lscan, TM_NOCHROM, scn, n))
1031 >        TMstruct *      tms = (TMstruct *)p;
1032 >        
1033 >        if (tmCvColrs(tms, lscan, TM_NOCHROM, scn, n))
1034                  goto tmerr;
1035 <        if (tmAddHisto(lscan, n, FIXWEIGHT))
1035 >        if (tmAddHisto(tms, lscan, n, FIXWEIGHT))
1036                  goto tmerr;
1037          return;
1038   tmerr:
# Line 1047 | Line 1056 | make_tonemap(void)                     /* initialize tone mapping */
1056          }
1057          flags = tmflags;                /* histogram adjustment */
1058          if (greyscale) flags |= TM_F_BW;
1059 <        if (tmTop != NULL) {            /* reuse old histogram if one */
1060 <                tmDone(tmTop);
1061 <                tmTop->flags = flags;
1059 >        if (tmGlobal != NULL) {         /* reuse old histogram if one */
1060 >                tmDone(tmCurrent); tmCurrent = NULL;
1061 >                tmGlobal->flags = flags;
1062          } else {                        /* else initialize */
1063                  if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL)
1064                          goto memerr;
1065                  if (greyscale) {
1066                          cscan = TM_NOCHROM;
1067 <                        if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL)
1067 >                        if ((pscan = (uby8 *)malloc(sizeof(uby8)*xmax)) == NULL)
1068                                  goto memerr;
1069 <                } else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax))
1069 >                } else if ((pscan=cscan = (uby8 *)malloc(3*sizeof(uby8)*xmax))
1070                                  == NULL)
1071                          goto memerr;
1072                                                  /* initialize tm library */
1073 <                if (tmInit(flags, stdprims, gamcor) == NULL)
1073 >                tmGlobal = tmInit(flags, stdprims, gamcor);
1074 >                if (tmGlobal == NULL)
1075                          goto memerr;
1076 <                if (tmSetSpace(stdprims, WHTEFFICACY/exposure))
1076 >                if (tmSetSpace(tmGlobal, stdprims, WHTEFFICACY/exposure))
1077                          goto tmerr;
1078                                                  /* compute picture histogram */
1079                  for (y = 0; y < ymax; y++) {
1080                          getscan(y);
1081 <                        if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax))
1081 >                        if (tmCvColrs(tmGlobal, lscan, TM_NOCHROM,
1082 >                                        scanline, xmax))
1083                                  goto tmerr;
1084 <                        if (tmAddHisto(lscan, xmax, 1))
1084 >                        if (tmAddHisto(tmGlobal, lscan, xmax, 1))
1085                                  goto tmerr;
1086                  }
1087          }
1088 <        tmDup();                        /* add fixations to duplicate map */
1089 <        dobox(addfix, NULL);
1088 >        tmCurrent = tmDup(tmGlobal);    /* add fixations to duplicate map */
1089 >        dobox(addfix, tmCurrent);
1090                                          /* (re)compute tone mapping */
1091 <        if (tmComputeMapping(gamcor, 0., 0.))
1091 >        if (tmComputeMapping(tmCurrent, gamcor, 0., 0.))
1092                  goto tmerr;
1093          return;
1094   memerr:
# Line 1089 | Line 1100 | tmerr:
1100  
1101   static void
1102   tmap_colrs(             /* apply tone mapping to scanline */
1103 <        register COLR  *scn,
1103 >        COLR  *scn,
1104          int  len
1105   )
1106   {
1107 <        register BYTE  *ps;
1107 >        uby8  *ps;
1108  
1109          if (tmflags == TM_F_LINEAR) {
1110                  if (scale)
# Line 1103 | Line 1114 | tmap_colrs(            /* apply tone mapping to scanline */
1114          }
1115          if (len > xmax)
1116                  quiterr("code error 1 in tmap_colrs");
1117 <        if (tmCvColrs(lscan, cscan, scn, len))
1117 >        if (tmCvColrs(tmCurrent, lscan, cscan, scn, len))
1118                  goto tmerr;
1119 <        if (tmMapPixels(pscan, lscan, cscan, len))
1119 >        if (tmMapPixels(tmCurrent, pscan, lscan, cscan, len))
1120                  goto tmerr;
1121          ps = pscan;
1122          if (greyscale)
# Line 1131 | Line 1142 | tmerr:
1142   static void
1143   getmono(void)                   /* get monochrome data */
1144   {
1145 <        register unsigned char  *dp;
1146 <        register int    x, err;
1145 >        unsigned char   *dp;
1146 >        int     x, err;
1147          int     y, errp;
1148          short   *cerr;
1149  
# Line 1157 | Line 1168 | getmono(void)                  /* get monochrome data */
1168                          cerr[x] = err + errp;
1169                  }
1170          }
1171 <        free((void *)cerr);
1171 >        free(cerr);
1172   }
1173  
1174  
# Line 1171 | Line 1182 | add2icon(              /* add a scanline to our icon data */
1182          static int  ynext;
1183          static char  *dp;
1184          COLR  clr;
1185 <        register int  err;
1186 <        register int    x, ti;
1185 >        int  err;
1186 >        int     x, ti;
1187          int  errp;
1188  
1189          if (iconheight == 0) {          /* initialize */
# Line 1219 | Line 1230 | static void
1230   getfull(void)                   /* get full (24-bit) data */
1231   {
1232          int     y;
1233 <        register uint32 *dp;
1234 <        register uint16 *dph;
1235 <        register int    x;
1233 >        uint32  *dp;
1234 >        uint16  *dph;
1235 >        int     x;
1236                                          /* initialize tone mapping */
1237          make_tonemap();
1238                                          /* read and convert file */
# Line 1287 | Line 1298 | static void
1298   getgrey(void)                   /* get greyscale data */
1299   {
1300          int     y;
1301 <        register unsigned char  *dp;
1302 <        register int    x;
1301 >        unsigned char   *dp;
1302 >        int     x;
1303                                          /* initialize tone mapping */
1304          make_tonemap();
1305                                          /* read and convert file */
# Line 1346 | Line 1357 | getmapped(void)                        /* get color-mapped data */
1357  
1358   static void
1359   scale_rcolors(                  /* scale color map */
1360 <        register XRASTER        *xr,
1360 >        XRASTER *xr,
1361          double  sf
1362   )
1363   {
1364 <        register int    i;
1364 >        int     i;
1365          long    maxv;
1366  
1367          if (xr->pixels == NULL)
# Line 1381 | Line 1392 | getscan(
1392   {
1393          static int  trunced = -1;               /* truncated file? */
1394   skipit:
1395 <        if (trunced >= 0 && y >= trunced) {
1396 <                memset(scanline, '\0', xmax*sizeof(COLR));
1395 >        if (y == cury-1)                        /* already got it? */
1396 >                return(0);
1397 >        if ((trunced >= 0) & (y >= trunced)) {
1398 >                memset(scanline, 0, xmax*sizeof(COLR));
1399                  return(-1);
1400          }
1401          if (y != cury) {
1402 <                if (scanpos == NULL || scanpos[y] == -1)
1402 >                if (scanpos == NULL || scanpos[y] < 0)
1403                          return(-1);
1404 <                if (fseek(fin, scanpos[y], 0) == -1)
1404 >                if (fseek(fin, scanpos[y], 0) < 0)
1405                          quiterr("fseek error");
1406                  cury = y;
1407 <        } else if (scanpos != NULL && scanpos[y] == -1)
1407 >        } else if (scanpos != NULL && scanpos[y] < 0)
1408                  scanpos[y] = ftell(fin);
1409  
1410 <        if (freadcolrs(scanline, xmax, fin) < 0) {
1410 >        if (fread2colrs(scanline, xmax, fin, NCSAMP, WLPART) < 0) {
1411                  fprintf(stderr, "%s: %s: unfinished picture\n",
1412                                  progname, fname==NULL?"<stdin>":fname);
1413                  trunced = y;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines