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.20 by greg, Fri Feb 12 18:03:08 1993 UTC vs.
Revision 2.34 by greg, Mon Nov 15 10:55:33 1993 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 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 21 | Line 21 | static char SCCSid[] = "$SunId$ LBL";
21  
22   #include  "standard.h"
23  
24 + #include  <signal.h>
25   #include  <X11/Xlib.h>
26   #include  <X11/cursorfont.h>
27   #include  <X11/Xutil.h>
28 + #include  <X11/Xatom.h>
29  
30   #include  "color.h"
31   #include  "view.h"
# Line 31 | Line 33 | static char SCCSid[] = "$SunId$ LBL";
33   #include  "random.h"
34   #include  "resolu.h"
35  
36 + #ifdef  __alpha
37 + #define  int4           int
38 + #endif
39 + #ifndef  int4
40 + #define  int4           long
41 + #endif
42 +
43   #define  FONTNAME       "8x13"          /* text font we'll use */
44  
45   #define  CTRL(c)        ((c)-'@')
# Line 55 | Line 64 | char   *dispname = NULL;               /* our display name */
64  
65   Window  wind = 0;                       /* our output window */
66   unsigned long  ourblack=0, ourwhite=1;  /* black and white for this visual */
58 Font  fontid;                           /* our font */
59
67   int  maxcolors = 0;                     /* maximum colors */
68   int  greyscale = 0;                     /* in grey */
69  
# Line 65 | Line 72 | int  scale = 0;                                /* scalefactor; power of two */
72   int  xoff = 0;                          /* x image offset */
73   int  yoff = 0;                          /* y image offset */
74  
75 + int  parent = 0;                        /* number of children, -1 if child */
76 +
77   VIEW  ourview = STDVIEW;                /* image view parameters */
78   int  gotview = 0;                       /* got parameters from file */
79  
# Line 107 | Line 116 | extern BYTE  clrtab[256][3];           /* global color map */
116  
117   extern long  ftell();
118  
110 extern char  *malloc(), *calloc();
111
119   Display  *thedisplay;
120 + Atom  closedownAtom, wmProtocolsAtom;
121  
122 + int  sigrecv;
123  
124 + int  onsig() { sigrecv++; }
125 +
126 +
127   main(argc, argv)
128   int  argc;
129   char  *argv[];
# Line 120 | Line 132 | char  *argv[];
132          char  *gv;
133          int  headline();
134          int  i;
135 +        int  pid;
136          
137          progname = argv[0];
138          if ((gv = getenv("GAMMA")) != NULL)
# Line 165 | Line 178 | char  *argv[];
178                  else
179                          break;
180  
181 <        if (i == argc-1) {
181 >        if (i > argc)
182 >                goto userr;
183 >        while (i < argc-1) {
184 >                sigrecv = 0;
185 >                signal(SIGCONT, onsig);
186 >                if ((pid=fork()) == 0) {        /* a child for each picture */
187 >                        parent = -1;
188 >                        break;
189 >                }
190 >                if (pid < 0)
191 >                        quiterr("fork failed");
192 >                parent++;
193 >                while (!sigrecv)
194 >                        pause();        /* wait for wake-up call */
195 >                i++;
196 >        }
197 >        if (i < argc) {                 /* open picture file */
198                  fname = argv[i];
199                  fin = fopen(fname, "r");
200 <                if (fin == NULL) {
201 <                        sprintf(errmsg, "cannot open file \"%s\"", fname);
202 <                        quiterr(errmsg);
174 <                }
175 <        } else if (i != argc)
176 <                goto userr;
200 >                if (fin == NULL)
201 >                        quiterr("cannot open picture file");
202 >        }
203                                  /* get header */
204          getheader(fin, headline, NULL);
205                                  /* get picture dimensions */
# Line 187 | Line 213 | char  *argv[];
213          if ((scanline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL)
214                  quiterr("out of memory");
215  
216 <        init();                 /* get file and open window */
216 >        init(argc, argv);                       /* get file and open window */
217  
218 +        if (parent < 0) {
219 +                kill(getppid(), SIGCONT);       /* signal parent if child */
220 +                sigrecv--;
221 +        }
222          for ( ; ; )
223                  getevent();             /* main loop */
224   userr:
225          fprintf(stderr,
226 <        "Usage: %s [-display disp][-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n",
226 > "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic ..\n",
227                          progname);
228 <        quit(1);
228 >        exit(1);
229   }
230  
231  
# Line 214 | Line 244 | char  *s;
244   }
245  
246  
247 < init()                  /* get data and open window */
247 > init(argc, argv)                        /* get data and open window */
248 > int argc;
249 > char **argv;
250   {
219        XWMHints        ourxwmhints;
251          XSetWindowAttributes    ourwinattr;
252 <        XSizeHints      oursizhints;
252 >        XClassHint      xclshints;
253 >        XWMHints        xwmhints;
254 >        XSizeHints      xszhints;
255 >        XTextProperty   windowName, iconName;
256 >        XGCValues       xgcv;
257 >        char    *name;
258          register int    i;
259          
260          if (fname != NULL) {
261                  scanpos = (long *)malloc(ymax*sizeof(long));
262                  if (scanpos == NULL)
263 <                        goto memerr;
263 >                        quiterr("out of memory");
264                  for (i = 0; i < ymax; i++)
265                          scanpos[i] = -1;
266 <        }
266 >                name = fname;
267 >        } else
268 >                name = progname;
269 >                                /* remove directory prefix from name */
270 >        for (i = strlen(name); i-- > 0; )
271 >                if (name[i] == '/')
272 >                        break;
273 >        name += i+1;
274          if ((thedisplay = XOpenDisplay(dispname)) == NULL)
275                  quiterr("cannot open display");
276                                  /* get best visual for default screen */
# Line 235 | Line 278 | init()                 /* get data and open window */
278                                  /* store image */
279          getras();
280                                  /* get size and position */
281 <        bzero((char *)&oursizhints, sizeof(oursizhints));
282 <        oursizhints.width = xmax; oursizhints.height = ymax;
281 >        xszhints.flags = 0;
282 >        xszhints.width = xmax; xszhints.height = ymax;
283          if (geometry != NULL) {
284 <                i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y,
285 <                                (unsigned *)&oursizhints.width,
286 <                                (unsigned *)&oursizhints.height);
284 >                i = XParseGeometry(geometry, &xszhints.x, &xszhints.y,
285 >                                (unsigned *)&xszhints.width,
286 >                                (unsigned *)&xszhints.height);
287                  if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue))
288 <                        oursizhints.flags |= USSize;
288 >                        xszhints.flags |= USSize;
289                  else
290 <                        oursizhints.flags |= PSize;
290 >                        xszhints.flags |= PSize;
291                  if ((i&(XValue|YValue)) == (XValue|YValue)) {
292 <                        oursizhints.flags |= USPosition;
292 >                        xszhints.flags |= USPosition;
293                          if (i & XNegative)
294 <                                oursizhints.x += DisplayWidth(thedisplay,
295 <                                ourscreen)-1-oursizhints.width-2*BORWIDTH;
294 >                                xszhints.x += DisplayWidth(thedisplay,
295 >                                ourscreen)-1-xszhints.width-2*BORWIDTH;
296                          if (i & YNegative)
297 <                                oursizhints.y += DisplayHeight(thedisplay,
298 <                                ourscreen)-1-oursizhints.height-2*BORWIDTH;
297 >                                xszhints.y += DisplayHeight(thedisplay,
298 >                                ourscreen)-1-xszhints.height-2*BORWIDTH;
299                  }
300          }
301 <                                /* open window */
302 <        ourwinattr.border_pixel = ourblack;
303 <        ourwinattr.background_pixel = ourwhite;
301 >        /* open window */
302 >        ourwinattr.border_pixel = ourwhite;
303 >        ourwinattr.background_pixel = ourblack;
304          ourwinattr.colormap = XCreateColormap(thedisplay, ourroot,
305                          ourvis.visual, AllocNone);
306 <        wind = XCreateWindow(thedisplay, ourroot, oursizhints.x, oursizhints.y,
307 <                        oursizhints.width, oursizhints.height, BORWIDTH,
308 <                        ourvis.depth, InputOutput, ourvis.visual,
309 <                        CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr);
306 >        ourwinattr.event_mask = ExposureMask|KeyPressMask|ButtonPressMask|
307 >                        ButtonReleaseMask|ButtonMotionMask|StructureNotifyMask;
308 >        ourwinattr.cursor = XCreateFontCursor(thedisplay, XC_diamond_cross);
309 >        wind = XCreateWindow(thedisplay, ourroot, xszhints.x, xszhints.y,
310 >                        xszhints.width, xszhints.height, BORWIDTH,
311 >                        ourvis.depth, InputOutput, ourvis.visual, CWEventMask|
312 >                        CWCursor|CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr);
313          if (wind == 0)
314                  quiterr("cannot create window");
269        XFreeColormap(thedisplay, ourwinattr.colormap);
315          width = xmax;
316          height = ymax;
317 <        ourgc = XCreateGC(thedisplay, wind, 0, 0);
318 <        XSetState(thedisplay, ourgc, ourblack, ourwhite, GXcopy, AllPlanes);
274 <        revgc = XCreateGC(thedisplay, wind, 0, 0);
275 <        XSetFunction(thedisplay, revgc, GXinvert);
276 <        fontid = XLoadFont(thedisplay, FONTNAME);
277 <        if (fontid == 0)
317 >        /* prepare graphics drawing context */
318 >        if ((xgcv.font = XLoadFont(thedisplay, FONTNAME)) == 0)
319                  quiterr("cannot get font");
320 <        XSetFont(thedisplay, ourgc, fontid);
321 <        XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay,
322 <                        XC_diamond_cross));
323 <        XStoreName(thedisplay, wind, fname == NULL ? progname : fname);
324 <        if (oursizhints.flags)
325 <                XSetNormalHints(thedisplay, wind, &oursizhints);
326 <        ourxwmhints.flags = InputHint|IconPixmapHint;
327 <        ourxwmhints.input = True;
328 <        ourxwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay,
320 >        xgcv.foreground = ourblack;
321 >        xgcv.background = ourwhite;
322 >        ourgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground|
323 >                        GCFont, &xgcv);
324 >        xgcv.function = GXinvert;
325 >        revgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground|
326 >                        GCFunction, &xgcv);
327 >
328 >        /* set up the window manager */
329 >        xwmhints.flags = InputHint|IconPixmapHint;
330 >        xwmhints.input = True;
331 >        xwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay,
332                          wind, icondata, iconwidth, iconheight);
333 <        XSetWMHints(thedisplay, wind, &ourxwmhints);
334 <        XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask
335 <                        |ButtonMotionMask|StructureNotifyMask
336 <                        |KeyPressMask|ExposureMask);
333 >
334 >        windowName.encoding = iconName.encoding = XA_STRING;
335 >        windowName.format = iconName.format = 8;
336 >        windowName.value = (u_char *)name;
337 >        windowName.nitems = strlen(windowName.value);
338 >        iconName.value = (u_char *)name;
339 >        iconName.nitems = strlen(windowName.value);
340 >
341 >        xclshints.res_name = NULL;
342 >        xclshints.res_class = "Ximage";
343 >        XSetWMProperties(thedisplay, wind, &windowName, &iconName,
344 >                        argv, argc, &xszhints, &xwmhints, &xclshints);
345 >        closedownAtom = XInternAtom(thedisplay, "WM_DELETE_WINDOW", False);
346 >        wmProtocolsAtom = XInternAtom(thedisplay, "WM_PROTOCOLS", False);
347 >        XSetWMProtocols(thedisplay, wind, &closedownAtom, 1);
348 >
349          XMapWindow(thedisplay, wind);
350          return;
295 memerr:
296        quiterr("out of memory");
351   } /* end of init */
352  
353  
354   quiterr(err)            /* print message and exit */
355   char  *err;
356   {
357 <        if (err != NULL) {
358 <                fprintf(stderr, "%s: %s\n", progname, err);
359 <                exit(1);
357 >        register int  es;
358 >        int  cs;
359 >
360 >        if (es = err != NULL)
361 >                fprintf(stderr, "%s: %s: %s\n", progname,
362 >                                fname==NULL?"<stdin>":fname, err);
363 >        if (parent > 0 & wind != 0) {
364 >                XDestroyWindow(thedisplay, wind);
365 >                XFlush(thedisplay);
366 >        } else if (parent < 0 & sigrecv == 0)
367 >                kill(getppid(), SIGCONT);
368 >        while (parent > 0 && wait(&cs) != -1) { /* wait for any children */
369 >                if (es == 0)
370 >                        es = cs>>8 & 0xff;
371 >                parent--;
372          }
373 <        exit(0);
373 >        exit(es);
374   }
375  
376  
# Line 445 | Line 511 | getras()                               /* get raster file */
511                          goto fail;
512                  getmono();
513          } else if (ourvis.class == TrueColor | ourvis.class == DirectColor) {
514 <                ourdata = (unsigned char *)malloc(4*xmax*ymax);
514 >                ourdata = (unsigned char *)malloc(sizeof(int4)*xmax*ymax);
515                  if (ourdata == NULL)
516                          goto fail;
517 <                ourras = make_raster(thedisplay, &ourvis, 32,
517 >                ourras = make_raster(thedisplay, &ourvis, sizeof(int4)*8,
518                                  ourdata, xmax, ymax, 32);
519                  if (ourras == NULL)
520                          goto fail;
# Line 476 | Line 542 | fail:
542  
543   getevent()                              /* process the next event */
544   {
545 <        union {
480 <                XEvent  u;
481 <                XConfigureEvent  c;
482 <                XExposeEvent  e;
483 <                XButtonPressedEvent  b;
484 <                XKeyPressedEvent  k;
485 <        } e;
545 >        XEvent xev;
546  
547 <        XNextEvent(thedisplay, &e.u);
548 <        switch (e.u.type) {
547 >        XNextEvent(thedisplay, &xev);
548 >        switch ((int)xev.type) {
549          case KeyPress:
550 <                docom(&e.k);
550 >                docom(&xev.xkey);
551                  break;
552          case ConfigureNotify:
553 <                width = e.c.width;
554 <                height = e.c.height;
553 >                width = xev.xconfigure.width;
554 >                height = xev.xconfigure.height;
555                  break;
556          case MapNotify:
557                  map_rcolors(ourras, wind);
# Line 503 | Line 563 | getevent()                             /* process the next event */
563                          unmap_rcolors(ourras);
564                  break;
565          case Expose:
566 <                redraw(e.e.x, e.e.y, e.e.width, e.e.height);
566 >                redraw(xev.xexpose.x, xev.xexpose.y,
567 >                                xev.xexpose.width, xev.xexpose.height);
568                  break;
569          case ButtonPress:
570 <                if (e.b.state & (ShiftMask|ControlMask))
571 <                        moveimage(&e.b);
570 >                if (xev.xbutton.state & (ShiftMask|ControlMask))
571 >                        moveimage(&xev.xbutton);
572 >                else if (xev.xbutton.button == Button2)
573 >                        traceray(xev.xbutton.x, xev.xbutton.y);
574                  else
575 <                        getbox(&e.b);
575 >                        getbox(&xev.xbutton);
576                  break;
577 +        case ClientMessage:
578 +                if ((xev.xclient.message_type == wmProtocolsAtom) &&
579 +                                (xev.xclient.data.l[0] == closedownAtom))
580 +                        quiterr(NULL);
581 +                break;
582          }
583   }
584  
585  
586 < docom(ekey)                                     /* execute command */
586 > traceray(xpos, ypos)                    /* print ray corresponding to pixel */
587 > int  xpos, ypos;
588 > {
589 >        FLOAT  hv[2];
590 >        FVECT  rorg, rdir;
591 >
592 >        if (!gotview) {         /* no view, no can do */
593 >                XBell(thedisplay, 0);
594 >                return(-1);
595 >        }
596 >        pix2loc(hv, &inpres, xpos-xoff, ypos-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);
603 > }
604 >
605 >
606 > docom(ekey)                             /* execute command */
607   XKeyPressedEvent  *ekey;
608   {
609          char  buf[80];
# Line 524 | Line 612 | XKeyPressedEvent  *ekey;
612          int  com, n;
613          double  comp;
614          FLOAT  hv[2];
527        FVECT  rorg, rdir;
615  
616          n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL);
617          if (n == 0)
# Line 532 | Line 619 | XKeyPressedEvent  *ekey;
619          com = buf[0];
620          switch (com) {                  /* interpret command */
621          case 'q':
622 +        case 'Q':
623          case CTRL('D'):                         /* quit */
624 <                quit(0);
624 >                quiterr(NULL);
625          case '\n':
626          case '\r':
627          case 'l':
# Line 579 | Line 667 | XKeyPressedEvent  *ekey;
667                                          buf, strlen(buf));
668                  return(0);
669          case 't':                               /* trace */
670 <                if (!gotview) {
583 <                        XBell(thedisplay, 0);
584 <                        return(-1);
585 <                }
586 <                pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff);
587 <                if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0)
588 <                        return(-1);
589 <                printf("%e %e %e ", rorg[0], rorg[1], rorg[2]);
590 <                printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]);
591 <                fflush(stdout);
592 <                return(0);
670 >                return(traceray(ekey->x, ekey->y));
671          case '=':                               /* adjust exposure */
672 +        case '@':                               /* adaptation level */
673                  if (avgbox(cval) == -1)
674                          return(-1);
675 <                n = log(.5/bright(cval))/.69315 - scale;        /* truncate */
675 >                comp = bright(cval);
676 >                if (comp < 1e-20) {
677 >                        XBell(thedisplay, 0);
678 >                        return(-1);
679 >                }
680 >                if (com == '@')
681 >                        comp = 106./exposure/
682 >                        pow(1.219+pow(comp*WHTEFFICACY/exposure,.4),2.5);
683 >                else
684 >                        comp = .5/comp;
685 >                comp = log(comp)/.69315 - scale;
686 >                n = comp < 0 ? comp-.5 : comp+.5 ;      /* round */
687                  if (n == 0)
688                          return(0);
689                  scale_rcolors(ourras, pow(2.0, (double)n));
# Line 615 | Line 705 | XKeyPressedEvent  *ekey;
705                          make_rpixmap(ourras, wind);
706                  redraw(0, 0, width, height);
707                  return(0);
708 +        case 'f':                               /* turn on fast redraw */
709 +                fast = 1;
710 +                make_rpixmap(ourras, wind);
711 +                return(0);
712 +        case 'F':                               /* turn off fast redraw */
713 +                fast = 0;
714 +                free_rpixmap(ourras);
715 +                return(0);
716          case '0':                               /* recenter origin */
717                  if (xoff == 0 & yoff == 0)
718                          return(0);
# Line 635 | Line 733 | XKeyPressedEvent  *ekey;
733   moveimage(ebut)                         /* shift the image */
734   XButtonPressedEvent  *ebut;
735   {
736 <        union {
639 <                XEvent  u;
640 <                XButtonReleasedEvent  b;
641 <                XPointerMovedEvent  m;
642 <        }  e;
736 >        XEvent  e;
737          int     mxo, myo;
738  
739 <        XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u);
740 <        while (e.u.type == MotionNotify) {
741 <                mxo = e.m.x;
742 <                myo = e.m.y;
739 >        XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e);
740 >        while (e.type == MotionNotify) {
741 >                mxo = e.xmotion.x;
742 >                myo = e.xmotion.y;
743                  revline(ebut->x, ebut->y, mxo, myo);
744                  revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y,
745                                  xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax);
746 <                XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u);
746 >                XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e);
747                  revline(ebut->x, ebut->y, mxo, myo);
748                  revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y,
749                                  xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax);
750          }
751 <        xoff += e.b.x - ebut->x;
752 <        yoff += e.b.y - ebut->y;
751 >        xoff += e.xbutton.x - ebut->x;
752 >        yoff += e.xbutton.y - ebut->y;
753          XClearWindow(thedisplay, wind);
754          redraw(0, 0, width, height);
755   }
# Line 664 | Line 758 | XButtonPressedEvent  *ebut;
758   getbox(ebut)                            /* get new box */
759   XButtonPressedEvent  *ebut;
760   {
761 <        union {
668 <                XEvent  u;
669 <                XButtonReleasedEvent  b;
670 <                XPointerMovedEvent  m;
671 <        }  e;
761 >        XEvent  e;
762  
763 <        XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u);
764 <        while (e.u.type == MotionNotify) {
765 <                revbox(ebut->x, ebut->y, box.xmin = e.m.x, box.ymin = e.m.y);
766 <                XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u);
763 >        XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e);
764 >        while (e.type == MotionNotify) {
765 >                revbox(ebut->x, ebut->y, box.xmin = e.xmotion.x, box.ymin = e.xmotion.y);
766 >                XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e);
767                  revbox(ebut->x, ebut->y, box.xmin, box.ymin);
768          }
769 <        box.xmin = e.b.x<0 ? 0 : (e.b.x>=width ? width-1 : e.b.x);
770 <        box.ymin = e.b.y<0 ? 0 : (e.b.y>=height ? height-1 : e.b.y);
769 >        box.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x);
770 >        box.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y);
771          if (box.xmin > ebut->x) {
772                  box.xsiz = box.xmin - ebut->x + 1;
773                  box.xmin = ebut->x;
# Line 838 | Line 928 | COLR  *scan;
928   getfull()                       /* get full (24-bit) data */
929   {
930          int     y;
931 <        register unsigned long  *dp;
931 >        register unsigned int4  *dp;
932          register int    x;
933                                          /* set gamma correction */
934          setcolrgam(gamcor);
935                                          /* read and convert file */
936 <        dp = (unsigned long *)ourdata;
936 >        dp = (unsigned int4 *)ourdata;
937          for (y = 0; y < ymax; y++) {
938                  getscan(y);
939                  add2icon(y, scanline);
# Line 898 | Line 988 | getgrey()                      /* get greyscale data */
988   getmapped()                     /* get color-mapped data */
989   {
990          int     y;
991 +                                        /* make sure we can do it first */
992 +        if (fname == NULL)
993 +                quiterr("cannot map colors from standard input");
994                                          /* set gamma correction */
995          setcolrgam(gamcor);
996                                          /* make histogram */
997          new_histo();
998          for (y = 0; y < ymax; y++) {
999                  if (getscan(y) < 0)
1000 <                        quiterr("seek error in getmapped");
1000 >                        break;
1001                  add2icon(y, scanline);
1002                  if (scale)
1003                          shiftcolrs(scanline, xmax, scale);
# Line 915 | Line 1008 | getmapped()                    /* get color-mapped data */
1008          if (!new_clrtab(maxcolors))
1009                  quiterr("cannot create color map");
1010          for (y = 0; y < ymax; y++) {
1011 <                if (getscan(y) < 0)
919 <                        quiterr("seek error in getmapped");
1011 >                getscan(y);
1012                  if (scale)
1013                          shiftcolrs(scanline, xmax, scale);
1014                  colrs_gambs(scanline, xmax);
# Line 959 | Line 1051 | double sf;
1051   getscan(y)
1052   int  y;
1053   {
1054 +        static int  trunced = -1;               /* truncated file? */
1055 + skipit:
1056 +        if (trunced >= 0 && y >= trunced) {
1057 +                bzero(scanline, xmax*sizeof(COLR));
1058 +                return(-1);
1059 +        }
1060          if (y != cury) {
1061                  if (scanpos == NULL || scanpos[y] == -1)
1062                          return(-1);
# Line 968 | Line 1066 | int  y;
1066          } else if (scanpos != NULL && scanpos[y] == -1)
1067                  scanpos[y] = ftell(fin);
1068  
1069 <        if (freadcolrs(scanline, xmax, fin) < 0)
1070 <                quiterr("read error");
1071 <
1069 >        if (freadcolrs(scanline, xmax, fin) < 0) {
1070 >                fprintf(stderr, "%s: %s: unfinished picture\n",
1071 >                                progname, fname==NULL?"<stdin>":fname);
1072 >                trunced = y;
1073 >                goto skipit;
1074 >        }
1075          cury++;
1076          return(0);
1077   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines