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.10 by greg, Wed Sep 13 15:41:52 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 */
144 <        if (fscanf(fin, "-Y %d +X %d\n", &ymax, &xmax) != 2)
144 >        if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR))
145                  quiterr("bad picture size");
146                                  /* set view parameters */
147 <        if (gotview) {
143 <                ourview.hresolu = xmax;
144 <                ourview.vresolu = ymax;
147 >        if (gotview)
148                  if (setview(&ourview) != NULL)
149                          gotview = 0;
150 <        }
150 >
151          if ((scanline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL)
152                  quiterr("out of memory");
153  
# Line 154 | Line 157 | char  *argv[];
157                  getevent();             /* main loop */
158   userr:
159          fprintf(stderr,
160 <        "Usage: %s [=geometry][-b][-m][-d][-f][-c ncolors] file\n",
160 >        "Usage: %s [=geometry][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n",
161                          progname);
162          quit(1);
163   }
# Line 163 | Line 166 | userr:
166   headline(s)             /* get relevant info from header */
167   char  *s;
168   {
169 <        static char  *altname[] = {"rview","rpict","VIEW=",NULL};
169 >        static char  *altname[] = {"rview","rpict",VIEWSTR,NULL};
170          register char  **an;
171  
172          if (!strncmp(s, "EXPOSURE=", 9))
# Line 191 | Line 194 | register char  *s;
194   init()                  /* get data and open window */
195   {
196          register int  i;
194        colormap  ourmap;
197          OpaqueFrame  mainframe;
198          char  defgeom[32];
199          
# Line 213 | Line 215 | init()                 /* get data and open window */
215                  maxcolors = 1<<DisplayPlanes();
216                  if (maxcolors > 4) maxcolors -= 2;
217          }
216        ourras.width = xmax;
217        ourras.height = ymax;
218                                  /* store image */
219 <        if (maxcolors <= 2) {           /* monochrome */
220 <                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 <        }
219 >        getras();
220 >
221          mainframe.bdrwidth = BORWIDTH;
222          mainframe.border = WhitePixmap;
223          mainframe.background = BlackPixmap;
# Line 284 | Line 270 | int  code;
270   }
271  
272  
273 + getras()                                /* get raster file */
274 + {
275 +        colormap        ourmap;
276 +
277 +        ourras = (XRASTER *)calloc(1, sizeof(XRASTER));
278 +        if (ourras == NULL)
279 +                goto memerr;
280 +        ourras->width = xmax;
281 +        ourras->height = ymax;
282 +        if (maxcolors <= 2) {           /* monochrome */
283 +                ourras->data.m = (unsigned short *)malloc(BitmapSize(xmax,ymax));
284 +                if (ourras->data.m == NULL)
285 +                        goto memerr;
286 +                getmono();
287 +        } else {
288 +                ourras->data.bz = (unsigned char *)malloc(BZPixmapSize(xmax,ymax));
289 +                if (ourras->data.bz == NULL)
290 +                        goto memerr;
291 +                if (greyscale)
292 +                        biq(dither,maxcolors,1,ourmap);
293 +                else
294 +                        ciq(dither,maxcolors,1,ourmap);
295 +                if (init_rcolors(ourras, ourmap) == 0)
296 +                        goto memerr;
297 +        }
298 +        return;
299 + memerr:
300 +        quit("out of memory");
301 + }
302 +
303 +
304   getevent()                              /* process the next event */
305   {
306          WindowInfo  info;
# Line 303 | Line 320 | getevent()                             /* process the next event */
320                  fixwindow(&e);
321                  break;
322          case UnmapWindow:
323 <                unmap_rcolors(&ourras);
323 >                unmap_rcolors(ourras);
324                  break;
325          case ButtonPressed:
326                  if (controlshift(&e))
# Line 326 | Line 343 | redraw(x, y, w, h)                     /* redraw section of window */
343   int  x, y;
344   int  w, h;
345   {
346 <        map_rcolors(&ourras);
346 >        if (ourras->ncolors && map_rcolors(ourras) == NULL) {
347 >                fprintf(stderr, "%s: cannot allocate colors\n", progname);
348 >                return(-1);
349 >        }
350          if (fast)
351 <                make_rpixmap(&ourras);
352 <        return(patch_raster(wind,x-xoff,y-yoff,x,y,w,h,&ourras) ? 0 : -1);
351 >                make_rpixmap(ourras);
352 >        return(patch_raster(wind,x-xoff,y-yoff,x,y,w,h,ourras) ? 0 : -1);
353   }
354  
355  
# Line 340 | Line 360 | XKeyEvent  *ekey;
360          COLOR  cval;
361          char  *cp;
362          int  n;
363 +        double  comp;
364          FVECT  rorg, rdir;
365  
366          cp = XLookupMapping(ekey, &n);
# Line 364 | Line 385 | XKeyEvent  *ekey;
385                          sprintf(buf, "%-3gL", bright(cval)*683.0/exposure);
386                          break;
387                  case 'c':                               /* color */
388 +                        comp = pow(2.0, (double)scale);
389                          sprintf(buf, "(%.2f,%.2f,%.2f)",
390 <                                        colval(cval,RED),
391 <                                        colval(cval,GRN),
392 <                                        colval(cval,BLU));
390 >                                        colval(cval,RED)*comp,
391 >                                        colval(cval,GRN)*comp,
392 >                                        colval(cval,BLU)*comp);
393                          break;
394                  }
395                  XText(wind, box.xmin, box.ymin, buf, strlen(buf),
# Line 389 | Line 411 | XKeyEvent  *ekey;
411                  printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]);
412                  fflush(stdout);
413                  return(0);
414 +        case '=':                               /* adjust exposure */
415 +                if (avgbox(cval) == -1)
416 +                        return(-1);
417 +                n = log(.5/bright(cval))/.69315 - scale;        /* truncate */
418 +                if (n == 0)
419 +                        return(0);
420 +                scale_rcolors(ourras, pow(2.0, (double)n));
421 +                scale += n;
422 +                sprintf(buf, "%+d", scale);
423 +                XText(wind, box.xmin, box.ymin, buf, strlen(buf),
424 +                                fontid, BlackPixel, WhitePixel);
425 +                XFlush();
426 +                free_raster(ourras);
427 +                getras();
428 +        /* fall through */
429          case CTRL(R):                           /* redraw */
430 +        case CTRL(L):
431                  XClear(wind);
432                  return(redraw(0, 0, width, height));
433          case ' ':                               /* clear */
# Line 507 | Line 545 | getmono()                      /* get monochrome data */
545          if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL
546                          || (cerr = (short *)calloc(xmax,sizeof(short))) == NULL)
547                  quit("out of memory in getmono");
548 <        dp = ourras.data.m - 1;
548 >        dp = ourras->data.m - 1;
549          for (y = 0; y < ymax; y++) {
550                  picreadline3(y, inline);
551                  err = 0;
# Line 527 | Line 565 | getmono()                      /* get monochrome data */
565   }
566  
567  
568 < init_rcolors(xr, cmap)                          /* assign color values */
568 > init_rcolors(xr, cmap)                          /* (re)assign color values */
569   register XRASTER        *xr;
570   colormap        cmap;
571   {
# Line 558 | Line 596 | colormap       cmap;
596   }
597  
598  
599 + scale_rcolors(xr, sf)                   /* scale color map */
600 + register XRASTER        *xr;
601 + double  sf;
602 + {
603 +        register int    i;
604 +        int     maxv;
605 +
606 +        sf = pow(sf, 1.0/gamcor);
607 +        maxv = (1<<16) / sf;
608 +
609 +        for (i = xr->ncolors; i--; ) {
610 +                xr->cdefs[i].red = xr->cdefs[i].red >= maxv ?
611 +                                (1<<16)-1 :
612 +                                xr->cdefs[i].red * sf;
613 +                xr->cdefs[i].green = xr->cdefs[i].green >= maxv ?
614 +                                (1<<16)-1 :
615 +                                xr->cdefs[i].green * sf;
616 +                xr->cdefs[i].blue = xr->cdefs[i].blue >= maxv ?
617 +                                (1<<16)-1 :
618 +                                xr->cdefs[i].blue * sf;
619 +        }
620 +        if (xr->pixels != NULL)
621 +                XStoreColors(xr->ncolors, xr->cdefs);
622 + }
623 +
624 +
625   getscan(y)
626   int  y;
627   {
# Line 590 | Line 654 | register rgbpixel  *l3;
654                  quiterr("cannot seek for picreadline");
655                                                          /* convert scanline */
656          for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) {
657 <                shift = l4[EXP] - COLXS;
657 >                shift = l4[EXP] - COLXS + scale;
658                  if (shift >= 8) {
659                          l3->r = l3->g = l3->b = 255;
660                  } else if (shift <= -8) {
# Line 619 | Line 683 | picwriteline(y, l)             /* add 8-bit scanline to image */
683   int  y;
684   pixel  *l;
685   {
686 <        bcopy(l, ourras.data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1));
686 >        bcopy(l, ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1));
687   }
688  
689  
690 < picreadcm(map)                  /* do gamcor correction */
690 > picreadcm(map)                  /* do gamma correction */
691   colormap  map;
692   {
693          extern double  pow();
# Line 639 | Line 703 | colormap  map;
703   picwritecm(map)                 /* handled elsewhere */
704   colormap  map;
705   {
706 + #ifdef DEBUG
707 +        register int i;
708 +
709 +        for (i = 0; i < 256; i++)
710 +                printf("%d %d %d\n", map[0][i],map[1][i],map[2][i]);
711 + #endif
712   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines