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.2 by greg, Fri Apr 7 16:36:10 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 154 | Line 161 | char  *argv[];
161                  getevent();             /* main loop */
162   userr:
163          fprintf(stderr,
164 <        "Usage: %s [=geometry][-b][-m][-d][-f][-c ncolors] file\n",
164 >        "Usage: %s [=geometry][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n",
165                          progname);
166          quit(1);
167   }
# Line 191 | Line 198 | register char  *s;
198   init()                  /* get data and open window */
199   {
200          register int  i;
194        colormap  ourmap;
201          OpaqueFrame  mainframe;
202          char  defgeom[32];
203          
# Line 213 | Line 219 | init()                 /* get data and open window */
219                  maxcolors = 1<<DisplayPlanes();
220                  if (maxcolors > 4) maxcolors -= 2;
221          }
216        ourras.width = xmax;
217        ourras.height = ymax;
222                                  /* store image */
223 <        if (maxcolors <= 2) {           /* monochrome */
224 <                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 <        }
223 >        getras();
224 >
225          mainframe.bdrwidth = BORWIDTH;
226          mainframe.border = WhitePixmap;
227          mainframe.background = BlackPixmap;
# Line 284 | Line 274 | int  code;
274   }
275  
276  
277 + getras()                                /* get raster file */
278 + {
279 +        colormap        ourmap;
280 +
281 +        ourras = (XRASTER *)calloc(1, sizeof(XRASTER));
282 +        if (ourras == NULL)
283 +                goto memerr;
284 +        ourras->width = xmax;
285 +        ourras->height = ymax;
286 +        if (maxcolors <= 2) {           /* monochrome */
287 +                ourras->data.m = (unsigned short *)malloc(BitmapSize(xmax,ymax));
288 +                if (ourras->data.m == NULL)
289 +                        goto memerr;
290 +                getmono();
291 +        } else {
292 +                ourras->data.bz = (unsigned char *)malloc(BZPixmapSize(xmax,ymax));
293 +                if (ourras->data.bz == NULL)
294 +                        goto memerr;
295 +                if (greyscale)
296 +                        biq(dither,maxcolors,1,ourmap);
297 +                else
298 +                        ciq(dither,maxcolors,1,ourmap);
299 +                if (init_rcolors(ourras, ourmap) == 0)
300 +                        goto memerr;
301 +        }
302 +        return;
303 + memerr:
304 +        quit("out of memory");
305 + }
306 +
307 +
308   getevent()                              /* process the next event */
309   {
310          WindowInfo  info;
# Line 303 | Line 324 | getevent()                             /* process the next event */
324                  fixwindow(&e);
325                  break;
326          case UnmapWindow:
327 <                unmap_rcolors(&ourras);
327 >                unmap_rcolors(ourras);
328                  break;
329          case ButtonPressed:
330                  if (controlshift(&e))
# Line 326 | Line 347 | redraw(x, y, w, h)                     /* redraw section of window */
347   int  x, y;
348   int  w, h;
349   {
350 <        map_rcolors(&ourras);
350 >        if (map_rcolors(ourras) == NULL) {
351 >                fprintf(stderr, "%s: cannot allocate colors\n", progname);
352 >                return(-1);
353 >        }
354          if (fast)
355 <                make_rpixmap(&ourras);
356 <        return(patch_raster(wind,x-xoff,y-yoff,x,y,w,h,&ourras) ? 0 : -1);
355 >                make_rpixmap(ourras);
356 >        return(patch_raster(wind,x-xoff,y-yoff,x,y,w,h,ourras) ? 0 : -1);
357   }
358  
359  
# Line 340 | Line 364 | XKeyEvent  *ekey;
364          COLOR  cval;
365          char  *cp;
366          int  n;
367 +        double  comp;
368          FVECT  rorg, rdir;
369  
370          cp = XLookupMapping(ekey, &n);
# Line 364 | Line 389 | XKeyEvent  *ekey;
389                          sprintf(buf, "%-3gL", bright(cval)*683.0/exposure);
390                          break;
391                  case 'c':                               /* color */
392 +                        comp = pow(2.0, (double)scale);
393                          sprintf(buf, "(%.2f,%.2f,%.2f)",
394 <                                        colval(cval,RED),
395 <                                        colval(cval,GRN),
396 <                                        colval(cval,BLU));
394 >                                        colval(cval,RED)*comp,
395 >                                        colval(cval,GRN)*comp,
396 >                                        colval(cval,BLU)*comp);
397                          break;
398                  }
399                  XText(wind, box.xmin, box.ymin, buf, strlen(buf),
# Line 389 | Line 415 | XKeyEvent  *ekey;
415                  printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]);
416                  fflush(stdout);
417                  return(0);
418 +        case '=':                               /* adjust exposure */
419 +                if (avgbox(cval) == -1)
420 +                        return(-1);
421 +                n = log(.5/bright(cval))/.69315 - scale;        /* truncate */
422 +                if (n == 0) {
423 +                        XFeep(0);
424 +                        return(0);
425 +                }
426 +                scale_rcolors(ourras, pow(2.0, (double)n));
427 +                scale += n;
428 +                sprintf(buf, "%+d", scale);
429 +                XText(wind, box.xmin, box.ymin, buf, strlen(buf),
430 +                                fontid, BlackPixel, WhitePixel);
431 +                XFlush();
432 +                free_raster(ourras);
433 +                getras();
434 +                return(redraw(0, 0, width, height));
435          case CTRL(R):                           /* redraw */
436                  XClear(wind);
437                  return(redraw(0, 0, width, height));
# Line 507 | Line 550 | getmono()                      /* get monochrome data */
550          if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL
551                          || (cerr = (short *)calloc(xmax,sizeof(short))) == NULL)
552                  quit("out of memory in getmono");
553 <        dp = ourras.data.m - 1;
553 >        dp = ourras->data.m - 1;
554          for (y = 0; y < ymax; y++) {
555                  picreadline3(y, inline);
556                  err = 0;
# Line 527 | Line 570 | getmono()                      /* get monochrome data */
570   }
571  
572  
573 < init_rcolors(xr, cmap)                          /* assign color values */
573 > init_rcolors(xr, cmap)                          /* (re)assign color values */
574   register XRASTER        *xr;
575   colormap        cmap;
576   {
# Line 558 | Line 601 | colormap       cmap;
601   }
602  
603  
604 + scale_rcolors(xr, sf)                   /* scale color map */
605 + register XRASTER        *xr;
606 + double  sf;
607 + {
608 +        register int    i;
609 +        int     maxv;
610 +
611 +        sf = pow(sf, 1.0/gamcor);
612 +        maxv = (1<<16) / sf;
613 +
614 +        for (i = xr->ncolors; i--; ) {
615 +                xr->cdefs[i].red = xr->cdefs[i].red >= maxv ?
616 +                                (1<<16)-1 :
617 +                                xr->cdefs[i].red * sf;
618 +                xr->cdefs[i].green = xr->cdefs[i].green >= maxv ?
619 +                                (1<<16)-1 :
620 +                                xr->cdefs[i].green * sf;
621 +                xr->cdefs[i].blue = xr->cdefs[i].blue >= maxv ?
622 +                                (1<<16)-1 :
623 +                                xr->cdefs[i].blue * sf;
624 +        }
625 +        if (xr->pixels != NULL)
626 +                XStoreColors(xr->ncolors, xr->cdefs);
627 + }
628 +
629 +
630   getscan(y)
631   int  y;
632   {
# Line 590 | Line 659 | register rgbpixel  *l3;
659                  quiterr("cannot seek for picreadline");
660                                                          /* convert scanline */
661          for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) {
662 <                shift = l4[EXP] - COLXS;
662 >                shift = l4[EXP] - COLXS + scale;
663                  if (shift >= 8) {
664                          l3->r = l3->g = l3->b = 255;
665                  } else if (shift <= -8) {
# Line 619 | Line 688 | picwriteline(y, l)             /* add 8-bit scanline to image */
688   int  y;
689   pixel  *l;
690   {
691 <        bcopy(l, ourras.data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1));
691 >        bcopy(l, ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1));
692   }
693  
694  
# Line 639 | Line 708 | colormap  map;
708   picwritecm(map)                 /* handled elsewhere */
709   colormap  map;
710   {
711 + #ifdef DEBUG
712 +        register int i;
713 +
714 +        for (i = 0; i < 256; i++)
715 +                printf("%d %d %d\n", map[0][i],map[1][i],map[2][i]);
716 + #endif
717   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines