ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ximage.c
(Generate patch)

Comparing ray/src/px/ximage.c (file contents):
Revision 1.1 by greg, Thu Feb 2 10:49:43 1989 UTC vs.
Revision 1.7 by greg, Tue May 23 10:46:32 1989 UTC

# Line 38 | Line 38 | static char SCCSid[] = "$SunId$ LBL";
38   #define  BORWIDTH       5               /* border width */
39   #define  BARHEIGHT      25              /* menu bar size */
40  
41 < double  gamcor = 2.0;                   /* gamcor correction */
41 > double  gamcor = 2.0;                   /* gamma correction */
42  
43 < XRASTER  ourras;                        /* our stored raster image */
43 > XRASTER  *ourras = NULL;                /* our stored raster image */
44  
45   int  dither = 1;                        /* dither colors? */
46   int  fast = 0;                          /* keep picture in Pixmap? */
# Line 51 | Line 51 | Font  fontid;                          /* our font */
51   int  maxcolors = 0;                     /* maximum colors */
52   int  greyscale = 0;                     /* in grey */
53  
54 + int  scale = 0;                         /* scalefactor; power of two */
55 +
56   int  xoff = 0;                          /* x image offset */
57   int  yoff = 0;                          /* y image offset */
58  
# Line 82 | Line 84 | extern long  ftell();
84  
85   extern char  *malloc(), *calloc();
86  
87 < extern double  atof();
87 > extern double  atof(), pow(), log();
88  
89  
90   main(argc, argv)
# Line 112 | Line 114 | char  *argv[];
114                          case 'f':
115                                  fast = !fast;
116                                  break;
117 +                        case 'e':
118 +                                if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
119 +                                        goto userr;
120 +                                scale = atoi(argv[++i]);
121 +                                break;
122                          case 'g':
123                                  gamcor = atof(argv[++i]);
124                                  break;
# Line 130 | Line 137 | char  *argv[];
137                          sprintf(errmsg, "can't open file \"%s\"", fname);
138                          quiterr(errmsg);
139                  }
140 <        } else
134 <                goto userr;
135 <
140 >        }
141                                  /* get header */
142          getheader(fin, headline);
143                                  /* get picture dimensions */
# Line 154 | Line 159 | char  *argv[];
159                  getevent();             /* main loop */
160   userr:
161          fprintf(stderr,
162 <        "Usage: %s [=geometry][-b][-m][-d][-f][-c ncolors] file\n",
162 >        "Usage: %s [=geometry][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n",
163                          progname);
164          quit(1);
165   }
# Line 163 | Line 168 | userr:
168   headline(s)             /* get relevant info from header */
169   char  *s;
170   {
171 <        static char  *altname[] = {"rview","rpict","VIEW=",NULL};
171 >        static char  *altname[] = {"rview","rpict",VIEWSTR,NULL};
172          register char  **an;
173  
174          if (!strncmp(s, "EXPOSURE=", 9))
# Line 191 | Line 196 | register char  *s;
196   init()                  /* get data and open window */
197   {
198          register int  i;
194        colormap  ourmap;
199          OpaqueFrame  mainframe;
200          char  defgeom[32];
201          
# Line 213 | Line 217 | init()                 /* get data and open window */
217                  maxcolors = 1<<DisplayPlanes();
218                  if (maxcolors > 4) maxcolors -= 2;
219          }
216        ourras.width = xmax;
217        ourras.height = ymax;
220                                  /* store image */
221 <        if (maxcolors <= 2) {           /* monochrome */
222 <                ourras.data.m = (unsigned short *)malloc(BitmapSize(xmax,ymax));
221 <                if (ourras.data.m == NULL)
222 <                        goto memerr;
223 <                getmono();
224 <        } else {
225 <                ourras.data.bz = (unsigned char *)malloc(BZPixmapSize(xmax,ymax));
226 <                if (ourras.data.bz == NULL)
227 <                        goto memerr;
228 <                if (greyscale)
229 <                        biq(dither,maxcolors,1,ourmap);
230 <                else
231 <                        ciq(dither,maxcolors,1,ourmap);
232 <                if (init_rcolors(&ourras, ourmap) == 0)
233 <                        goto memerr;
234 <        }
221 >        getras();
222 >
223          mainframe.bdrwidth = BORWIDTH;
224          mainframe.border = WhitePixmap;
225          mainframe.background = BlackPixmap;
# Line 284 | Line 272 | int  code;
272   }
273  
274  
275 + getras()                                /* get raster file */
276 + {
277 +        colormap        ourmap;
278 +
279 +        ourras = (XRASTER *)calloc(1, sizeof(XRASTER));
280 +        if (ourras == NULL)
281 +                goto memerr;
282 +        ourras->width = xmax;
283 +        ourras->height = ymax;
284 +        if (maxcolors <= 2) {           /* monochrome */
285 +                ourras->data.m = (unsigned short *)malloc(BitmapSize(xmax,ymax));
286 +                if (ourras->data.m == NULL)
287 +                        goto memerr;
288 +                getmono();
289 +        } else {
290 +                ourras->data.bz = (unsigned char *)malloc(BZPixmapSize(xmax,ymax));
291 +                if (ourras->data.bz == NULL)
292 +                        goto memerr;
293 +                if (greyscale)
294 +                        biq(dither,maxcolors,1,ourmap);
295 +                else
296 +                        ciq(dither,maxcolors,1,ourmap);
297 +                if (init_rcolors(ourras, ourmap) == 0)
298 +                        goto memerr;
299 +        }
300 +        return;
301 + memerr:
302 +        quit("out of memory");
303 + }
304 +
305 +
306   getevent()                              /* process the next event */
307   {
308          WindowInfo  info;
# Line 303 | Line 322 | getevent()                             /* process the next event */
322                  fixwindow(&e);
323                  break;
324          case UnmapWindow:
325 <                unmap_rcolors(&ourras);
325 >                unmap_rcolors(ourras);
326                  break;
327          case ButtonPressed:
328                  if (controlshift(&e))
# Line 326 | Line 345 | redraw(x, y, w, h)                     /* redraw section of window */
345   int  x, y;
346   int  w, h;
347   {
348 <        map_rcolors(&ourras);
348 >        if (ourras->ncolors && map_rcolors(ourras) == NULL) {
349 >                fprintf(stderr, "%s: cannot allocate colors\n", progname);
350 >                return(-1);
351 >        }
352          if (fast)
353 <                make_rpixmap(&ourras);
354 <        return(patch_raster(wind,x-xoff,y-yoff,x,y,w,h,&ourras) ? 0 : -1);
353 >                make_rpixmap(ourras);
354 >        return(patch_raster(wind,x-xoff,y-yoff,x,y,w,h,ourras) ? 0 : -1);
355   }
356  
357  
# Line 340 | Line 362 | XKeyEvent  *ekey;
362          COLOR  cval;
363          char  *cp;
364          int  n;
365 +        double  comp;
366          FVECT  rorg, rdir;
367  
368          cp = XLookupMapping(ekey, &n);
# Line 364 | Line 387 | XKeyEvent  *ekey;
387                          sprintf(buf, "%-3gL", bright(cval)*683.0/exposure);
388                          break;
389                  case 'c':                               /* color */
390 +                        comp = pow(2.0, (double)scale);
391                          sprintf(buf, "(%.2f,%.2f,%.2f)",
392 <                                        colval(cval,RED),
393 <                                        colval(cval,GRN),
394 <                                        colval(cval,BLU));
392 >                                        colval(cval,RED)*comp,
393 >                                        colval(cval,GRN)*comp,
394 >                                        colval(cval,BLU)*comp);
395                          break;
396                  }
397                  XText(wind, box.xmin, box.ymin, buf, strlen(buf),
# Line 389 | Line 413 | XKeyEvent  *ekey;
413                  printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]);
414                  fflush(stdout);
415                  return(0);
416 +        case '=':                               /* adjust exposure */
417 +                if (avgbox(cval) == -1)
418 +                        return(-1);
419 +                n = log(.5/bright(cval))/.69315 - scale;        /* truncate */
420 +                if (n == 0)
421 +                        return(0);
422 +                scale_rcolors(ourras, pow(2.0, (double)n));
423 +                scale += n;
424 +                sprintf(buf, "%+d", scale);
425 +                XText(wind, box.xmin, box.ymin, buf, strlen(buf),
426 +                                fontid, BlackPixel, WhitePixel);
427 +                XFlush();
428 +                free_raster(ourras);
429 +                getras();
430 +        /* fall through */
431          case CTRL(R):                           /* redraw */
432 +        case CTRL(L):
433                  XClear(wind);
434                  return(redraw(0, 0, width, height));
435          case ' ':                               /* clear */
# Line 507 | Line 547 | getmono()                      /* get monochrome data */
547          if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL
548                          || (cerr = (short *)calloc(xmax,sizeof(short))) == NULL)
549                  quit("out of memory in getmono");
550 <        dp = ourras.data.m - 1;
550 >        dp = ourras->data.m - 1;
551          for (y = 0; y < ymax; y++) {
552                  picreadline3(y, inline);
553                  err = 0;
# Line 527 | Line 567 | getmono()                      /* get monochrome data */
567   }
568  
569  
570 < init_rcolors(xr, cmap)                          /* assign color values */
570 > init_rcolors(xr, cmap)                          /* (re)assign color values */
571   register XRASTER        *xr;
572   colormap        cmap;
573   {
# Line 558 | Line 598 | colormap       cmap;
598   }
599  
600  
601 + scale_rcolors(xr, sf)                   /* scale color map */
602 + register XRASTER        *xr;
603 + double  sf;
604 + {
605 +        register int    i;
606 +        int     maxv;
607 +
608 +        sf = pow(sf, 1.0/gamcor);
609 +        maxv = (1<<16) / sf;
610 +
611 +        for (i = xr->ncolors; i--; ) {
612 +                xr->cdefs[i].red = xr->cdefs[i].red >= maxv ?
613 +                                (1<<16)-1 :
614 +                                xr->cdefs[i].red * sf;
615 +                xr->cdefs[i].green = xr->cdefs[i].green >= maxv ?
616 +                                (1<<16)-1 :
617 +                                xr->cdefs[i].green * sf;
618 +                xr->cdefs[i].blue = xr->cdefs[i].blue >= maxv ?
619 +                                (1<<16)-1 :
620 +                                xr->cdefs[i].blue * sf;
621 +        }
622 +        if (xr->pixels != NULL)
623 +                XStoreColors(xr->ncolors, xr->cdefs);
624 + }
625 +
626 +
627   getscan(y)
628   int  y;
629   {
# Line 590 | Line 656 | register rgbpixel  *l3;
656                  quiterr("cannot seek for picreadline");
657                                                          /* convert scanline */
658          for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) {
659 <                shift = l4[EXP] - COLXS;
659 >                shift = l4[EXP] - COLXS + scale;
660                  if (shift >= 8) {
661                          l3->r = l3->g = l3->b = 255;
662                  } else if (shift <= -8) {
# Line 619 | Line 685 | picwriteline(y, l)             /* add 8-bit scanline to image */
685   int  y;
686   pixel  *l;
687   {
688 <        bcopy(l, ourras.data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1));
688 >        bcopy(l, ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1));
689   }
690  
691  
# Line 639 | Line 705 | colormap  map;
705   picwritecm(map)                 /* handled elsewhere */
706   colormap  map;
707   {
708 + #ifdef DEBUG
709 +        register int i;
710 +
711 +        for (i = 0; i < 256; i++)
712 +                printf("%d %d %d\n", map[0][i],map[1][i],map[2][i]);
713 + #endif
714   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines