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.8 by greg, Fri May 29 14:21:12 1992 UTC vs.
Revision 2.24 by greg, Tue Mar 30 14:39:29 1993 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1993 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 24 | Line 24 | static char SCCSid[] = "$SunId$ LBL";
24   #include  <X11/Xlib.h>
25   #include  <X11/cursorfont.h>
26   #include  <X11/Xutil.h>
27 + #include  <X11/Xatom.h>
28  
29   #include  "color.h"
30   #include  "view.h"
30 #include  "pic.h"
31   #include  "x11raster.h"
32   #include  "random.h"
33   #include  "resolu.h"
# Line 55 | Line 55 | int  fast = 0;                         /* keep picture in Pixmap? */
55   char    *dispname = NULL;               /* our display name */
56  
57   Window  wind = 0;                       /* our output window */
58 < unsigned long  ourblack=1, ourwhite=0;  /* black and white for this visual */
59 < Font  fontid;                           /* our font */
60 <
58 > unsigned long  ourblack=0, ourwhite=1;  /* black and white for this visual */
59   int  maxcolors = 0;                     /* maximum colors */
60   int  greyscale = 0;                     /* in grey */
61  
# Line 104 | Line 102 | char  *progname;
102  
103   char  errmsg[128];
104  
105 + extern BYTE  clrtab[256][3];            /* global color map */
106 +
107   extern long  ftell();
108  
109 extern char  *malloc(), *calloc();
110
111 extern double  pow(), log();
112
109   Display  *thedisplay;
110 + Atom  closedownAtom, wmProtocolsAtom;
111  
112 +
113   main(argc, argv)
114   int  argc;
115   char  *argv[];
116   {
117 +        extern char  *getenv();
118 +        char  *gv;
119          int  headline();
120          int  i;
121          
122          progname = argv[0];
123 +        if ((gv = getenv("GAMMA")) != NULL)
124 +                gamcor = atof(gv);
125  
126          for (i = 1; i < argc; i++)
127                  if (argv[i][0] == '-')
# Line 183 | Line 185 | char  *argv[];
185          if ((scanline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL)
186                  quiterr("out of memory");
187  
188 <        init();                 /* get file and open window */
188 >        init(argc, argv);                       /* get file and open window */
189  
190          for ( ; ; )
191                  getevent();             /* main loop */
192   userr:
193          fprintf(stderr,
194 <        "Usage: %s [-display disp][-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n",
194 > "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic\n",
195                          progname);
196 <        quit(1);
196 >        exit(1);
197   }
198  
199  
# Line 210 | Line 212 | char  *s;
212   }
213  
214  
215 < init()                  /* get data and open window */
215 > init(argc, argv)                        /* get data and open window */
216 > int argc;
217 > char **argv;
218   {
215        XWMHints        ourxwmhints;
219          XSetWindowAttributes    ourwinattr;
220 <        XSizeHints      oursizhints;
220 >        XClassHint      xclshints;
221 >        XWMHints        xwmhints;
222 >        XSizeHints      xszhints;
223 >        XTextProperty   windowName, iconName;
224 >        XGCValues       xgcv;
225 >        char    *name;
226          register int    i;
227          
228          if (fname != NULL) {
229                  scanpos = (long *)malloc(ymax*sizeof(long));
230                  if (scanpos == NULL)
231 <                        goto memerr;
231 >                        quiterr("out of memory");
232                  for (i = 0; i < ymax; i++)
233                          scanpos[i] = -1;
234 <        }
234 >                name = fname;
235 >        } else
236 >                name = progname;
237 >                                /* remove directory prefix from name */
238 >        for (i = strlen(name); i-- > 0; )
239 >                if (name[i] == '/')
240 >                        break;
241 >        name += i+1;
242          if ((thedisplay = XOpenDisplay(dispname)) == NULL)
243                  quiterr("cannot open display");
244                                  /* get best visual for default screen */
245          getbestvis();
246                                  /* store image */
247          getras();
248 <                                /* open window */
249 <        ourwinattr.border_pixel = ourblack;
250 <        ourwinattr.background_pixel = ourwhite;
236 <        ourwinattr.colormap = XCreateColormap(thedisplay, ourroot,
237 <                        ourvis.visual, AllocNone);
238 <        wind = XCreateWindow(thedisplay, ourroot, 0, 0, xmax, ymax, BORWIDTH,
239 <                        ourvis.depth, InputOutput, ourvis.visual,
240 <                        CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr);
241 <        if (wind == 0)
242 <                quiterr("cannot create window");
243 <        width = xmax;
244 <        height = ymax;
245 <        ourgc = XCreateGC(thedisplay, wind, 0, 0);
246 <        XSetState(thedisplay, ourgc, ourblack, ourwhite, GXcopy, AllPlanes);
247 <        revgc = XCreateGC(thedisplay, wind, 0, 0);
248 <        XSetFunction(thedisplay, revgc, GXinvert);
249 <        fontid = XLoadFont(thedisplay, FONTNAME);
250 <        if (fontid == 0)
251 <                quiterr("cannot get font");
252 <        XSetFont(thedisplay, ourgc, fontid);
253 <        XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay,
254 <                        XC_diamond_cross));
255 <        XStoreName(thedisplay, wind, fname == NULL ? progname : fname);
248 >                                /* get size and position */
249 >        xszhints.flags = 0;
250 >        xszhints.width = xmax; xszhints.height = ymax;
251          if (geometry != NULL) {
252 <                bzero((char *)&oursizhints, sizeof(oursizhints));
253 <                i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y,
254 <                                (unsigned *)&oursizhints.width,
260 <                                (unsigned *)&oursizhints.height);
252 >                i = XParseGeometry(geometry, &xszhints.x, &xszhints.y,
253 >                                (unsigned *)&xszhints.width,
254 >                                (unsigned *)&xszhints.height);
255                  if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue))
256 <                        oursizhints.flags |= USSize;
257 <                else {
258 <                        oursizhints.width = xmax;
265 <                        oursizhints.height = ymax;
266 <                        oursizhints.flags |= PSize;
267 <                }
256 >                        xszhints.flags |= USSize;
257 >                else
258 >                        xszhints.flags |= PSize;
259                  if ((i&(XValue|YValue)) == (XValue|YValue)) {
260 <                        oursizhints.flags |= USPosition;
260 >                        xszhints.flags |= USPosition;
261                          if (i & XNegative)
262 <                                oursizhints.x += DisplayWidth(thedisplay,
263 <                                ourscreen)-1-oursizhints.width-2*BORWIDTH;
262 >                                xszhints.x += DisplayWidth(thedisplay,
263 >                                ourscreen)-1-xszhints.width-2*BORWIDTH;
264                          if (i & YNegative)
265 <                                oursizhints.y += DisplayHeight(thedisplay,
266 <                                ourscreen)-1-oursizhints.height-2*BORWIDTH;
265 >                                xszhints.y += DisplayHeight(thedisplay,
266 >                                ourscreen)-1-xszhints.height-2*BORWIDTH;
267                  }
277                XSetNormalHints(thedisplay, wind, &oursizhints);
268          }
269 <        ourxwmhints.flags = InputHint|IconPixmapHint;
270 <        ourxwmhints.input = True;
271 <        ourxwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay,
269 >        /* open window */
270 >        ourwinattr.border_pixel = ourwhite;
271 >        ourwinattr.background_pixel = ourblack;
272 >        ourwinattr.colormap = XCreateColormap(thedisplay, ourroot,
273 >                        ourvis.visual, AllocNone);
274 >        ourwinattr.event_mask = ExposureMask|KeyPressMask|ButtonPressMask|
275 >                        ButtonReleaseMask|ButtonMotionMask|StructureNotifyMask;
276 >        ourwinattr.cursor = XCreateFontCursor(thedisplay, XC_diamond_cross);
277 >        wind = XCreateWindow(thedisplay, ourroot, xszhints.x, xszhints.y,
278 >                        xszhints.width, xszhints.height, BORWIDTH,
279 >                        ourvis.depth, InputOutput, ourvis.visual, CWEventMask|
280 >                        CWCursor|CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr);
281 >        if (wind == 0)
282 >                quiterr("cannot create window");
283 >        width = xmax;
284 >        height = ymax;
285 >        xgcv.foreground = ourblack;
286 >        xgcv.background = ourwhite;
287 >        if ((xgcv.font = XLoadFont(thedisplay, FONTNAME)) == 0)
288 >                quiterr("cannot get font");
289 >        ourgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground|
290 >                        GCFont, &xgcv);
291 >        xgcv.function = GXinvert;
292 >        revgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground|
293 >                        GCFunction, &xgcv);
294 >
295 >        /* set up the window manager */
296 >        xwmhints.flags = InputHint|IconPixmapHint;
297 >        xwmhints.input = True;
298 >        xwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay,
299                          wind, icondata, iconwidth, iconheight);
300 <        XSetWMHints(thedisplay, wind, &ourxwmhints);
301 <        XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask
302 <                        |ButtonMotionMask|StructureNotifyMask
303 <                        |KeyPressMask|ExposureMask);
300 >
301 >        windowName.encoding = iconName.encoding = XA_STRING;
302 >        windowName.format = iconName.format = 8;
303 >        windowName.value = (u_char *)name;
304 >        windowName.nitems = strlen(windowName.value);
305 >        iconName.value = (u_char *)name;
306 >        iconName.nitems = strlen(windowName.value);
307 >
308 >        xclshints.res_name = NULL;
309 >        xclshints.res_class = "Ximage";
310 >        XSetWMProperties(thedisplay, wind, &windowName, &iconName,
311 >                        argv, argc, &xszhints, &xwmhints, &xclshints);
312 >        closedownAtom = XInternAtom(thedisplay, "WM_DELETE_WINDOW", False);
313 >        wmProtocolsAtom = XInternAtom(thedisplay, "WM_PROTOCOLS", False);
314 >        XSetWMProtocols(thedisplay, wind, &closedownAtom, 1);
315 >
316          XMapWindow(thedisplay, wind);
317          return;
289 memerr:
290        quiterr("out of memory");
318   } /* end of init */
319  
320  
# Line 302 | Line 329 | char  *err;
329   }
330  
331  
305 eputs(s)
306 char    *s;
307 {
308        fputs(s, stderr);
309 }
310
311
312 quit(code)
313 int  code;
314 {
315        exit(code);
316 }
317
318
332   static int
333   viscmp(v1,v2)           /* compare visual to see which is better, descending */
334   register XVisualInfo    *v1, *v2;
# Line 419 | Line 432 | static char  vistype[][12] = {
432                  greyscale = 1;
433          if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors)
434                  maxcolors = ourvis.colormap_size;
422        if (maxcolors > 4)
423                maxcolors -= 2;
435          if (ourvis.class == StaticGray) {
436                  ourblack = 0;
437                  ourwhite = 255;
438          } else if (ourvis.class == PseudoColor) {
439                  ourblack = BlackPixel(thedisplay,ourscreen);
440                  ourwhite = WhitePixel(thedisplay,ourscreen);
441 +                if ((ourblack|ourwhite) & ~255L) {
442 +                        ourblack = 0;
443 +                        ourwhite = 1;
444 +                }
445 +                if (maxcolors > 4)
446 +                        maxcolors -= 2;
447          } else {
448                  ourblack = 0;
449 <                ourwhite = ~0;
449 >                ourwhite = ourvis.red_mask|ourvis.green_mask|ourvis.blue_mask;
450          }
451          XFree((char *)xvi);
452   }
# Line 437 | Line 454 | static char  vistype[][12] = {
454  
455   getras()                                /* get raster file */
456   {
440        colormap        ourmap;
457          XVisualInfo     vinfo;
458  
459          if (maxcolors <= 2) {           /* monochrome */
# Line 449 | Line 465 | getras()                               /* get raster file */
465                  if (ourras == NULL)
466                          goto fail;
467                  getmono();
468 <        } else if (ourvis.class == TrueColor || ourvis.class == DirectColor) {
468 >        } else if (ourvis.class == TrueColor | ourvis.class == DirectColor) {
469                  ourdata = (unsigned char *)malloc(4*xmax*ymax);
470                  if (ourdata == NULL)
471                          goto fail;
# Line 466 | Line 482 | getras()                               /* get raster file */
482                                  xmax, ymax, 8);
483                  if (ourras == NULL)
484                          goto fail;
485 <                if (ourvis.class == StaticGray)
485 >                if (greyscale | ourvis.class == StaticGray)
486                          getgrey();
487 <                else {
488 <                        if (greyscale)
489 <                                biq(dither,maxcolors,1,ourmap);
490 <                        else
475 <                                ciq(dither,maxcolors,1,ourmap);
476 <                        if (init_rcolors(ourras, ourmap[0],
477 <                                        ourmap[1], ourmap[2]) == 0)
478 <                                goto fail;
479 <                }
487 >                else
488 >                        getmapped();
489 >                if (ourvis.class != StaticGray && !init_rcolors(ourras,clrtab))
490 >                        goto fail;
491          }
492 <                return;
492 >        return;
493   fail:
494          quiterr("could not create raster image");
495   }
# Line 486 | Line 497 | fail:
497  
498   getevent()                              /* process the next event */
499   {
500 <        union {
490 <                XEvent  u;
491 <                XConfigureEvent  c;
492 <                XExposeEvent  e;
493 <                XButtonPressedEvent  b;
494 <                XKeyPressedEvent  k;
495 <        } e;
500 >        XEvent xev;
501  
502 <        XNextEvent(thedisplay, &e.u);
503 <        switch (e.u.type) {
502 >        XNextEvent(thedisplay, &xev);
503 >        switch ((int)xev.type) {
504          case KeyPress:
505 <                docom(&e.k);
505 >                docom(&xev.xkey);
506                  break;
507          case ConfigureNotify:
508 <                width = e.c.width;
509 <                height = e.c.height;
508 >                width = xev.xconfigure.width;
509 >                height = xev.xconfigure.height;
510                  break;
511          case MapNotify:
512                  map_rcolors(ourras, wind);
# Line 513 | Line 518 | getevent()                             /* process the next event */
518                          unmap_rcolors(ourras);
519                  break;
520          case Expose:
521 <                redraw(e.e.x, e.e.y, e.e.width, e.e.height);
521 >                redraw(xev.xexpose.x, xev.xexpose.y,
522 >                                xev.xexpose.width, xev.xexpose.height);
523                  break;
524          case ButtonPress:
525 <                if (e.b.state & (ShiftMask|ControlMask))
526 <                        moveimage(&e.b);
525 >                if (xev.xbutton.state & (ShiftMask|ControlMask))
526 >                        moveimage(&xev.xbutton);
527 >                else if (xev.xbutton.button == Button2)
528 >                        traceray(xev.xbutton.x, xev.xbutton.y);
529                  else
530 <                        getbox(&e.b);
530 >                        getbox(&xev.xbutton);
531                  break;
532 +   case ClientMessage:
533 +                if ((xev.xclient.message_type == wmProtocolsAtom) &&
534 +                                (xev.xclient.data.l[0] == closedownAtom))
535 +                        quiterr(NULL);
536 +                break;
537          }
538   }
539  
540  
541 < docom(ekey)                                     /* execute command */
541 > traceray(xpos, ypos)                    /* print ray corresponding to pixel */
542 > int  xpos, ypos;
543 > {
544 >        FLOAT  hv[2];
545 >        FVECT  rorg, rdir;
546 >
547 >        if (!gotview) {         /* no view, no can do */
548 >                XBell(thedisplay, 0);
549 >                return(-1);
550 >        }
551 >        pix2loc(hv, &inpres, xpos-xoff, ypos-yoff);
552 >        if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0)
553 >                return(-1);
554 >        printf("%e %e %e ", rorg[0], rorg[1], rorg[2]);
555 >        printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]);
556 >        fflush(stdout);
557 >        return(0);
558 > }
559 >
560 >
561 > docom(ekey)                             /* execute command */
562   XKeyPressedEvent  *ekey;
563   {
564          char  buf[80];
# Line 534 | Line 567 | XKeyPressedEvent  *ekey;
567          int  com, n;
568          double  comp;
569          FLOAT  hv[2];
537        FVECT  rorg, rdir;
570  
571          n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL);
572          if (n == 0)
# Line 542 | Line 574 | XKeyPressedEvent  *ekey;
574          com = buf[0];
575          switch (com) {                  /* interpret command */
576          case 'q':
577 +        case 'Q':
578          case CTRL('D'):                         /* quit */
579 <                quit(0);
579 >                quiterr(NULL);
580          case '\n':
581          case '\r':
582          case 'l':
# Line 589 | Line 622 | XKeyPressedEvent  *ekey;
622                                          buf, strlen(buf));
623                  return(0);
624          case 't':                               /* trace */
625 <                if (!gotview) {
593 <                        XBell(thedisplay, 0);
594 <                        return(-1);
595 <                }
596 <                pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff);
597 <                if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0)
598 <                        return(-1);
599 <                printf("%e %e %e ", rorg[0], rorg[1], rorg[2]);
600 <                printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]);
601 <                fflush(stdout);
602 <                return(0);
625 >                return(traceray(ekey->x, ekey->y));
626          case '=':                               /* adjust exposure */
627                  if (avgbox(cval) == -1)
628                          return(-1);
# Line 622 | Line 645 | XKeyPressedEvent  *ekey;
645                  XClearWindow(thedisplay, wind);
646                  map_rcolors(ourras, wind);
647                  if (fast)
648 <                        make_rpixmap(ourras);
648 >                        make_rpixmap(ourras, wind);
649                  redraw(0, 0, width, height);
650                  return(0);
651 +        case '0':                               /* recenter origin */
652 +                if (xoff == 0 & yoff == 0)
653 +                        return(0);
654 +                xoff = yoff = 0;
655 +                XClearWindow(thedisplay, wind);
656 +                redraw(0, 0, width, height);
657 +                return(0);
658          case ' ':                               /* clear */
659                  redraw(box.xmin, box.ymin, box.xsiz, box.ysiz);
660                  return(0);
# Line 638 | Line 668 | XKeyPressedEvent  *ekey;
668   moveimage(ebut)                         /* shift the image */
669   XButtonPressedEvent  *ebut;
670   {
671 <        union {
642 <                XEvent  u;
643 <                XButtonReleasedEvent  b;
644 <                XPointerMovedEvent  m;
645 <        }  e;
671 >        XEvent  e;
672          int     mxo, myo;
673  
674 <        XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u);
675 <        while (e.u.type == MotionNotify) {
676 <                mxo = e.m.x;
677 <                myo = e.m.y;
674 >        XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e);
675 >        while (e.type == MotionNotify) {
676 >                mxo = e.xmotion.x;
677 >                myo = e.xmotion.y;
678                  revline(ebut->x, ebut->y, mxo, myo);
679                  revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y,
680                                  xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax);
681 <                XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u);
681 >                XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e);
682                  revline(ebut->x, ebut->y, mxo, myo);
683                  revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y,
684                                  xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax);
685          }
686 <        xoff += e.b.x - ebut->x;
687 <        yoff += e.b.y - ebut->y;
686 >        xoff += e.xbutton.x - ebut->x;
687 >        yoff += e.xbutton.y - ebut->y;
688          XClearWindow(thedisplay, wind);
689          redraw(0, 0, width, height);
690   }
# Line 667 | Line 693 | XButtonPressedEvent  *ebut;
693   getbox(ebut)                            /* get new box */
694   XButtonPressedEvent  *ebut;
695   {
696 <        union {
671 <                XEvent  u;
672 <                XButtonReleasedEvent  b;
673 <                XPointerMovedEvent  m;
674 <        }  e;
696 >        XEvent  e;
697  
698 <        XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u);
699 <        while (e.u.type == MotionNotify) {
700 <                revbox(ebut->x, ebut->y, box.xmin = e.m.x, box.ymin = e.m.y);
701 <                XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u);
698 >        XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e);
699 >        while (e.type == MotionNotify) {
700 >                revbox(ebut->x, ebut->y, box.xmin = e.xmotion.x, box.ymin = e.xmotion.y);
701 >                XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e);
702                  revbox(ebut->x, ebut->y, box.xmin, box.ymin);
703          }
704 <        box.xmin = e.b.x<0 ? 0 : (e.b.x>=width ? width-1 : e.b.x);
705 <        box.ymin = e.b.y<0 ? 0 : (e.b.y>=height ? height-1 : e.b.y);
704 >        box.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x);
705 >        box.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y);
706          if (box.xmin > ebut->x) {
707                  box.xsiz = box.xmin - ebut->x + 1;
708                  box.xmin = ebut->x;
# Line 736 | Line 758 | COLOR  clr;
758                  return(-1);
759          if (left == ll && right == lr && top == lt && bottom == lb) {
760                  copycolor(clr, lc);
761 <                return;
761 >                return(0);
762          }
763          for (y = top; y < bottom; y++) {
764                  if (getscan(y) == -1)
# Line 765 | Line 787 | getmono()                      /* get monochrome data */
787                  quiterr("out of memory in getmono");
788          dp = ourdata - 1;
789          for (y = 0; y < ymax; y++) {
790 <                if (getscan(y) < 0)
769 <                        quiterr("seek error in getmono");
770 <                normcolrs(scanline, xmax, scale);
790 >                getscan(y);
791                  add2icon(y, scanline);
792 +                normcolrs(scanline, xmax, scale);
793                  err = 0;
794                  for (x = 0; x < xmax; x++) {
795                          if (!(x&7))
# Line 794 | Line 815 | COLR  *scan;
815          static short  cerr[ICONSIZ];
816          static int  ynext;
817          static char  *dp;
818 +        COLR  clr;
819          register int  err;
820          register int    x, ti;
821          int  errp;
# Line 824 | Line 846 | COLR  *scan;
846                          *++dp = 0;
847                  errp = err;
848                  ti = x*xmax/iconwidth;
849 <                err += normbright(scan[ti]) + cerr[x];
849 >                copycolr(clr, scan[ti]);
850 >                normcolrs(clr, 1, scale);
851 >                err += normbright(clr) + cerr[x];
852                  if (err > 127)
853                          err -= 255;
854                  else
# Line 846 | Line 870 | getfull()                      /* get full (24-bit) data */
870                                          /* read and convert file */
871          dp = (unsigned long *)ourdata;
872          for (y = 0; y < ymax; y++) {
873 <                if (getscan(y) < 0)
874 <                        quiterr("seek error in getfull");
873 >                getscan(y);
874 >                add2icon(y, scanline);
875                  if (scale)
876                          shiftcolrs(scanline, xmax, scale);
877                  colrs_gambs(scanline, xmax);
854                add2icon(y, scanline);
878                  if (ourras->image->blue_mask & 1)
879                          for (x = 0; x < xmax; x++)
880                                  *dp++ = scanline[x][RED] << 16 |
# Line 876 | Line 899 | getgrey()                      /* get greyscale data */
899                                          /* read and convert file */
900          dp = ourdata;
901          for (y = 0; y < ymax; y++) {
902 <                if (getscan(y) < 0)
903 <                        quiterr("seek error in getfull");
902 >                getscan(y);
903 >                add2icon(y, scanline);
904                  if (scale)
905                          shiftcolrs(scanline, xmax, scale);
906 +                for (x = 0; x < xmax; x++)
907 +                        scanline[x][GRN] = normbright(scanline[x]);
908                  colrs_gambs(scanline, xmax);
909 <                add2icon(y, scanline);
885 <                if (ourvis.colormap_size < 256)
909 >                if (maxcolors < 256)
910                          for (x = 0; x < xmax; x++)
911 <                                *dp++ = ((long)normbright(scanline[x]) *
912 <                                        ourvis.colormap_size + 128) >> 8;
911 >                                *dp++ = ((long)scanline[x][GRN] *
912 >                                        maxcolors + maxcolors/2) >> 8;
913                  else
914                          for (x = 0; x < xmax; x++)
915 <                                *dp++ = normbright(scanline[x]);
915 >                                *dp++ = scanline[x][GRN];
916          }
917 +        for (x = 0; x < maxcolors; x++)
918 +                clrtab[x][RED] = clrtab[x][GRN] =
919 +                        clrtab[x][BLU] = ((long)x*256 + 128)/maxcolors;
920   }
921  
922  
923 + getmapped()                     /* get color-mapped data */
924 + {
925 +        int     y;
926 +                                        /* set gamma correction */
927 +        setcolrgam(gamcor);
928 +                                        /* make histogram */
929 +        new_histo();
930 +        for (y = 0; y < ymax; y++) {
931 +                if (getscan(y) < 0)
932 +                        quiterr("seek error in getmapped");
933 +                add2icon(y, scanline);
934 +                if (scale)
935 +                        shiftcolrs(scanline, xmax, scale);
936 +                colrs_gambs(scanline, xmax);
937 +                cnt_colrs(scanline, xmax);
938 +        }
939 +                                        /* map pixels */
940 +        if (!new_clrtab(maxcolors))
941 +                quiterr("cannot create color map");
942 +        for (y = 0; y < ymax; y++) {
943 +                if (getscan(y) < 0)
944 +                        quiterr("seek error in getmapped");
945 +                if (scale)
946 +                        shiftcolrs(scanline, xmax, scale);
947 +                colrs_gambs(scanline, xmax);
948 +                if (dither)
949 +                        dith_colrs(ourdata+y*xmax, scanline, xmax);
950 +                else
951 +                        map_colrs(ourdata+y*xmax, scanline, xmax);
952 +        }
953 + }
954 +
955 +
956   scale_rcolors(xr, sf)                   /* scale color map */
957   register XRASTER        *xr;
958   double  sf;
# Line 930 | Line 990 | int  y;
990                  if (fseek(fin, scanpos[y], 0) == -1)
991                          quiterr("fseek error");
992                  cury = y;
993 <        } else if (scanpos != NULL)
993 >        } else if (scanpos != NULL && scanpos[y] == -1)
994                  scanpos[y] = ftell(fin);
995  
996          if (freadcolrs(scanline, xmax, fin) < 0)
# Line 938 | Line 998 | int  y;
998  
999          cury++;
1000          return(0);
941 }
942
943
944 picreadline3(y, l3)                     /* read in 3-byte scanline */
945 int  y;
946 register rgbpixel  *l3;
947 {
948        register int    i;
949                                                        /* read scanline */
950        if (getscan(y) < 0)
951                quiterr("cannot seek for picreadline");
952                                                        /* convert scanline */
953        normcolrs(scanline, xmax, scale);
954        add2icon(y, scanline);
955        for (i = 0; i < xmax; i++) {
956                l3[i].r = scanline[i][RED];
957                l3[i].g = scanline[i][GRN];
958                l3[i].b = scanline[i][BLU];
959        }
960 }
961
962
963 picwriteline(y, l)              /* add 8-bit scanline to image */
964 int  y;
965 pixel  *l;
966 {
967        bcopy((char *)l, (char *)ourdata+y*xmax, xmax);
968 }
969
970
971 picreadcm(map)                  /* do gamma correction */
972 colormap  map;
973 {
974        extern double  pow();
975        register int  i, val;
976
977        for (i = 0; i < 256; i++) {
978                val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0;
979                map[0][i] = map[1][i] = map[2][i] = val;
980        }
981 }
982
983
984 picwritecm(map)                 /* handled elsewhere */
985 colormap  map;
986 {
987 #if 0
988        register int i;
989
990        for (i = 0; i < 256; i++)
991                printf("%d %d %d\n", map[0][i],map[1][i],map[2][i]);
992 #endif
1001   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines