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.68 by greg, Tue Sep 28 17:54:18 2004 UTC vs.
Revision 2.80 by greg, Tue Jun 3 21:31:51 2025 UTC

# 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 115 | Line 118 | char  *geometry = NULL;                        /* geometry specification */
118   char  icondata[ICONSIZ*ICONSIZ/8];      /* icon bitmap data */
119   int  iconwidth = 0, iconheight = 0;
120  
118 char  *progname;
119
121   char  errmsg[128];
122  
123 < BYTE  clrtab[256][3];                   /* global color map */
123 > uby8  clrtab[256][3];                   /* global color map */
124  
125  
126   Display  *thedisplay;
# Line 165 | Line 166 | main(int  argc, char  *argv[])
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 268 | Line 269 | main(int  argc, 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   }
# Line 280 | Line 281 | headline(              /* get relevant info from header */
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  
# Line 305 | Line 310 | init(                  /* get data and open window */
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 394 | Line 399 | init(                  /* get data and open window */
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 415 | Line 420 | 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)
# Line 436 | Line 441 | quiterr(               /* print message and exit */
441  
442   static int
443   viscmp(         /* compare visual to see which is better, descending */
444 <        register XVisualInfo    *v1,
445 <        register XVisualInfo    *v2
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 498 | 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 568 | Line 573 | getras(void)                           /* get raster file */
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;
# Line 579 | Line 584 | getras(void)                           /* get raster file */
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 587 | Line 592 | getras(void)                           /* 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 669 | Line 674 | traceray(                      /* print requested pixel data */
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 947 | Line 952 | revbox(                        /* draw bbox with reversed lines */
952  
953   static void
954   colavg(
955 <        register COLR   *scn,
956 <        register int    n,
955 >        COLR    *scn,
956 >        int     n,
957          void *cavg
958   )
959   {
960          COLOR   col;
961  
962          while (n--) {
963 <                colr_color(col, *scn++);
963 >                colr_color(col, *scn);
964                  addcolor((COLORV*)cavg, col);
965 +                scn++;
966          }
967   }
968  
# Line 967 | Line 973 | avgbox(                                /* average color over current bbox */
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 981 | Line 987 | avgbox(                                /* average color over current bbox */
987  
988   static int
989   dobox(                          /* run function over bbox */
984        //void  (*f)(),                 /* function to call for each subscan */
990          doboxf_t *f,                    /* function to call for each subscan */
991          void    *p                      /* pointer to private data */
992   )
# Line 1006 | Line 1011 | dobox(                         /* run function over bbox */
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 1018 | Line 1023 | static void
1023   addfix(                 /* add fixation points to histogram */
1024          COLR    *scn,
1025          int     n,
1026 <        void    *p  /*NOTUSED*/
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 1047 | Line 1054 | make_tonemap(void)                     /* 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 1089 | Line 1098 | tmerr:
1098  
1099   static void
1100   tmap_colrs(             /* apply tone mapping to scanline */
1101 <        register COLR  *scn,
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 1103 | Line 1112 | tmap_colrs(            /* apply tone mapping to scanline */
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 1131 | Line 1140 | tmerr:
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 1157 | Line 1166 | getmono(void)                  /* get monochrome data */
1166                          cerr[x] = err + errp;
1167                  }
1168          }
1169 <        free((void *)cerr);
1169 >        free(cerr);
1170   }
1171  
1172  
# Line 1171 | Line 1180 | add2icon(              /* add a scanline to our icon data */
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 1219 | Line 1228 | static void
1228   getfull(void)                   /* get full (24-bit) data */
1229   {
1230          int     y;
1231 <        register uint32 *dp;
1232 <        register uint16 *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 */
# Line 1287 | Line 1296 | 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 1346 | Line 1355 | getmapped(void)                        /* get color-mapped data */
1355  
1356   static void
1357   scale_rcolors(                  /* scale color map */
1358 <        register XRASTER        *xr,
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 1381 | Line 1390 | getscan(
1390   {
1391          static int  trunced = -1;               /* truncated file? */
1392   skipit:
1393 <        if (trunced >= 0 && y >= trunced) {
1394 <                memset(scanline, '\0', 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