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.78 by greg, Thu Nov 21 17:15:54 2024 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 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 418 | Line 425 | quiterr(               /* print message and exit */
425          register 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 444 | Line 451 | viscmp(                /* compare visual to see which is better, des
451          register 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 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 970 | Line 977 | avgbox(                                /* average color over current bbox */
977          register int    rval;
978  
979          setcolor(cavg, 0., 0., 0.);
980 <        rval = dobox(colavg, (char *)cavg);
980 >        rval = dobox(colavg, (void *)cavg);
981          if (rval > 0) {
982                  d = 1./rval;
983                  scalecolor(cavg, d);
# 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, (void *)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 1093 | Line 1104 | tmap_colrs(            /* apply tone mapping to scanline */
1104          int  len
1105   )
1106   {
1107 <        register BYTE  *ps;
1107 >        register 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 1394 | Line 1405 | skipit:
1405          } else if (scanpos != NULL && scanpos[y] == -1)
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