--- ray/src/px/x11image.c 1992/10/22 17:51:05 2.16 +++ ray/src/px/x11image.c 1994/06/10 12:51:21 2.37 @@ -1,4 +1,4 @@ -/* Copyright (c) 1992 Regents of the University of California */ +/* Copyright (c) 1993 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -21,9 +21,11 @@ static char SCCSid[] = "$SunId$ LBL"; #include "standard.h" +#include #include #include #include +#include #include "color.h" #include "view.h" @@ -31,6 +33,13 @@ static char SCCSid[] = "$SunId$ LBL"; #include "random.h" #include "resolu.h" +#ifdef __alpha +#define int4 int +#endif +#ifndef int4 +#define int4 long +#endif + #define FONTNAME "8x13" /* text font we'll use */ #define CTRL(c) ((c)-'@') @@ -47,6 +56,7 @@ static char SCCSid[] = "$SunId$ LBL"; #define redraw(x,y,w,h) patch_raster(wind,(x)-xoff,(y)-yoff,x,y,w,h,ourras) double gamcor = 2.2; /* gamma correction */ +char *gamstr = NULL; /* gamma value override */ int dither = 1; /* dither colors? */ int fast = 0; /* keep picture in Pixmap? */ @@ -55,8 +65,6 @@ char *dispname = NULL; /* our display name */ Window wind = 0; /* our output window */ unsigned long ourblack=0, ourwhite=1; /* black and white for this visual */ -Font fontid; /* our font */ - int maxcolors = 0; /* maximum colors */ int greyscale = 0; /* in grey */ @@ -65,6 +73,8 @@ int scale = 0; /* scalefactor; power of two */ int xoff = 0; /* x image offset */ int yoff = 0; /* y image offset */ +int parent = 0; /* number of children, -1 if child */ + VIEW ourview = STDVIEW; /* image view parameters */ int gotview = 0; /* got parameters from file */ @@ -103,27 +113,29 @@ char *progname; char errmsg[128]; -extern BYTE clrtab[256][3]; /* global color map */ +BYTE clrtab[256][3]; /* global color map */ extern long ftell(); -extern char *malloc(), *calloc(); +extern char *getenv(); Display *thedisplay; +Atom closedownAtom, wmProtocolsAtom; +int sigrecv; +int onsig() { sigrecv++; } + + main(argc, argv) int argc; char *argv[]; { - extern char *getenv(); - char *gv; int headline(); int i; + int pid; progname = argv[0]; - if ((gv = getenv("GAMMA")) != NULL) - gamcor = atof(gv); for (i = 1; i < argc; i++) if (argv[i][0] == '-') @@ -155,7 +167,7 @@ char *argv[]; if (argv[i][2] == 'e') geometry = argv[++i]; else - gamcor = atof(argv[++i]); + gamstr = argv[++i]; break; default: goto userr; @@ -165,15 +177,28 @@ char *argv[]; else break; - if (i == argc-1) { + if (i > argc) + goto userr; + while (i < argc-1) { + sigrecv = 0; + signal(SIGCONT, onsig); + if ((pid=fork()) == 0) { /* a child for each picture */ + parent = -1; + break; + } + if (pid < 0) + quiterr("fork failed"); + parent++; + while (!sigrecv) + pause(); /* wait for wake-up call */ + i++; + } + if (i < argc) { /* open picture file */ fname = argv[i]; fin = fopen(fname, "r"); - if (fin == NULL) { - sprintf(errmsg, "cannot open file \"%s\"", fname); - quiterr(errmsg); - } - } else if (i != argc) - goto userr; + if (fin == NULL) + quiterr("cannot open picture file"); + } /* get header */ getheader(fin, headline, NULL); /* get picture dimensions */ @@ -187,15 +212,19 @@ char *argv[]; if ((scanline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL) quiterr("out of memory"); - init(); /* get file and open window */ + init(argc, argv); /* get file and open window */ + if (parent < 0) { + kill(getppid(), SIGCONT); /* signal parent if child */ + sigrecv--; + } for ( ; ; ) getevent(); /* main loop */ userr: fprintf(stderr, - "Usage: %s [-display disp][-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", +"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops][-g gamcor] pic ..\n", progname); - quit(1); + exit(1); } @@ -214,96 +243,139 @@ char *s; } -init() /* get data and open window */ +init(argc, argv) /* get data and open window */ +int argc; +char **argv; { - XWMHints ourxwmhints; XSetWindowAttributes ourwinattr; - XSizeHints oursizhints; + XClassHint xclshints; + XWMHints xwmhints; + XSizeHints xszhints; + XTextProperty windowName, iconName; + XGCValues xgcv; + char *name; register int i; if (fname != NULL) { scanpos = (long *)malloc(ymax*sizeof(long)); if (scanpos == NULL) - goto memerr; + quiterr("out of memory"); for (i = 0; i < ymax; i++) scanpos[i] = -1; - } + name = fname; + } else + name = progname; + /* remove directory prefix from name */ + for (i = strlen(name); i-- > 0; ) + if (name[i] == '/') + break; + name += i+1; if ((thedisplay = XOpenDisplay(dispname)) == NULL) quiterr("cannot open display"); + /* set gamma value */ + if (gamstr == NULL) /* get it from the X server */ + gamstr = XGetDefault(thedisplay, "radiance", "gamma"); + if (gamstr == NULL) /* get it from the environment */ + gamstr = getenv("GAMMA"); + if (gamstr != NULL) + gamcor = atof(gamstr); /* get best visual for default screen */ getbestvis(); /* store image */ getras(); - /* open window */ - ourwinattr.border_pixel = ourblack; - ourwinattr.background_pixel = ourwhite; - ourwinattr.colormap = XCreateColormap(thedisplay, ourroot, - ourvis.visual, AllocNone); - wind = XCreateWindow(thedisplay, ourroot, 0, 0, xmax, ymax, BORWIDTH, - ourvis.depth, InputOutput, ourvis.visual, - CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); - if (wind == 0) - quiterr("cannot create window"); - XFreeColormap(thedisplay, ourwinattr.colormap); - width = xmax; - height = ymax; - ourgc = XCreateGC(thedisplay, wind, 0, 0); - XSetState(thedisplay, ourgc, ourblack, ourwhite, GXcopy, AllPlanes); - revgc = XCreateGC(thedisplay, wind, 0, 0); - XSetFunction(thedisplay, revgc, GXinvert); - fontid = XLoadFont(thedisplay, FONTNAME); - if (fontid == 0) - quiterr("cannot get font"); - XSetFont(thedisplay, ourgc, fontid); - XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay, - XC_diamond_cross)); - XStoreName(thedisplay, wind, fname == NULL ? progname : fname); + /* get size and position */ + xszhints.flags = 0; + xszhints.width = xmax; xszhints.height = ymax; if (geometry != NULL) { - bzero((char *)&oursizhints, sizeof(oursizhints)); - i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, - (unsigned *)&oursizhints.width, - (unsigned *)&oursizhints.height); + i = XParseGeometry(geometry, &xszhints.x, &xszhints.y, + (unsigned *)&xszhints.width, + (unsigned *)&xszhints.height); if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) - oursizhints.flags |= USSize; - else { - oursizhints.width = xmax; - oursizhints.height = ymax; - oursizhints.flags |= PSize; - } + xszhints.flags |= USSize; + else + xszhints.flags |= PSize; if ((i&(XValue|YValue)) == (XValue|YValue)) { - oursizhints.flags |= USPosition; + xszhints.flags |= USPosition; if (i & XNegative) - oursizhints.x += DisplayWidth(thedisplay, - ourscreen)-1-oursizhints.width-2*BORWIDTH; + xszhints.x += DisplayWidth(thedisplay, + ourscreen)-1-xszhints.width-2*BORWIDTH; if (i & YNegative) - oursizhints.y += DisplayHeight(thedisplay, - ourscreen)-1-oursizhints.height-2*BORWIDTH; + xszhints.y += DisplayHeight(thedisplay, + ourscreen)-1-xszhints.height-2*BORWIDTH; } - XSetNormalHints(thedisplay, wind, &oursizhints); } - ourxwmhints.flags = InputHint|IconPixmapHint; - ourxwmhints.input = True; - ourxwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay, + /* open window */ + ourwinattr.border_pixel = ourwhite; + ourwinattr.background_pixel = ourblack; + ourwinattr.colormap = XCreateColormap(thedisplay, ourroot, + ourvis.visual, AllocNone); + ourwinattr.event_mask = ExposureMask|KeyPressMask|ButtonPressMask| + ButtonReleaseMask|ButtonMotionMask|StructureNotifyMask; + ourwinattr.cursor = XCreateFontCursor(thedisplay, XC_diamond_cross); + wind = XCreateWindow(thedisplay, ourroot, xszhints.x, xszhints.y, + xszhints.width, xszhints.height, BORWIDTH, + ourvis.depth, InputOutput, ourvis.visual, CWEventMask| + CWCursor|CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); + if (wind == 0) + quiterr("cannot create window"); + width = xmax; + height = ymax; + /* prepare graphics drawing context */ + if ((xgcv.font = XLoadFont(thedisplay, FONTNAME)) == 0) + quiterr("cannot get font"); + xgcv.foreground = ourblack; + xgcv.background = ourwhite; + ourgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground| + GCFont, &xgcv); + xgcv.function = GXinvert; + revgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground| + GCFunction, &xgcv); + + /* set up the window manager */ + xwmhints.flags = InputHint|IconPixmapHint; + xwmhints.input = True; + xwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay, wind, icondata, iconwidth, iconheight); - XSetWMHints(thedisplay, wind, &ourxwmhints); - XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask - |ButtonMotionMask|StructureNotifyMask - |KeyPressMask|ExposureMask); + + windowName.encoding = iconName.encoding = XA_STRING; + windowName.format = iconName.format = 8; + windowName.value = (u_char *)name; + windowName.nitems = strlen(windowName.value); + iconName.value = (u_char *)name; + iconName.nitems = strlen(windowName.value); + + xclshints.res_name = NULL; + xclshints.res_class = "Ximage"; + XSetWMProperties(thedisplay, wind, &windowName, &iconName, + argv, argc, &xszhints, &xwmhints, &xclshints); + closedownAtom = XInternAtom(thedisplay, "WM_DELETE_WINDOW", False); + wmProtocolsAtom = XInternAtom(thedisplay, "WM_PROTOCOLS", False); + XSetWMProtocols(thedisplay, wind, &closedownAtom, 1); + XMapWindow(thedisplay, wind); return; -memerr: - quiterr("out of memory"); } /* end of init */ quiterr(err) /* print message and exit */ char *err; { - if (err != NULL) { - fprintf(stderr, "%s: %s\n", progname, err); - exit(1); + register int es; + int cs; + + if (es = err != NULL) + fprintf(stderr, "%s: %s: %s\n", progname, + fname==NULL?"":fname, err); + if (thedisplay != NULL) + XCloseDisplay(thedisplay); + if (parent < 0 & sigrecv == 0) + kill(getppid(), SIGCONT); + while (parent > 0 && wait(&cs) != -1) { /* wait for any children */ + if (es == 0) + es = cs>>8 & 0xff; + parent--; } - exit(0); + exit(es); } @@ -444,10 +516,10 @@ getras() /* get raster file */ goto fail; getmono(); } else if (ourvis.class == TrueColor | ourvis.class == DirectColor) { - ourdata = (unsigned char *)malloc(4*xmax*ymax); + ourdata = (unsigned char *)malloc(sizeof(int4)*xmax*ymax); if (ourdata == NULL) goto fail; - ourras = make_raster(thedisplay, &ourvis, 32, + ourras = make_raster(thedisplay, &ourvis, sizeof(int4)*8, ourdata, xmax, ymax, 32); if (ourras == NULL) goto fail; @@ -475,22 +547,16 @@ fail: getevent() /* process the next event */ { - union { - XEvent u; - XConfigureEvent c; - XExposeEvent e; - XButtonPressedEvent b; - XKeyPressedEvent k; - } e; + XEvent xev; - XNextEvent(thedisplay, &e.u); - switch (e.u.type) { + XNextEvent(thedisplay, &xev); + switch ((int)xev.type) { case KeyPress: - docom(&e.k); + docom(&xev.xkey); break; case ConfigureNotify: - width = e.c.width; - height = e.c.height; + width = xev.xconfigure.width; + height = xev.xconfigure.height; break; case MapNotify: map_rcolors(ourras, wind); @@ -502,19 +568,47 @@ getevent() /* process the next event */ unmap_rcolors(ourras); break; case Expose: - redraw(e.e.x, e.e.y, e.e.width, e.e.height); + redraw(xev.xexpose.x, xev.xexpose.y, + xev.xexpose.width, xev.xexpose.height); break; case ButtonPress: - if (e.b.state & (ShiftMask|ControlMask)) - moveimage(&e.b); + if (xev.xbutton.state & (ShiftMask|ControlMask)) + moveimage(&xev.xbutton); + else if (xev.xbutton.button == Button2) + traceray(xev.xbutton.x, xev.xbutton.y); else - getbox(&e.b); + getbox(&xev.xbutton); break; + case ClientMessage: + if ((xev.xclient.message_type == wmProtocolsAtom) && + (xev.xclient.data.l[0] == closedownAtom)) + quiterr(NULL); + break; } } -docom(ekey) /* execute command */ +traceray(xpos, ypos) /* print ray corresponding to pixel */ +int xpos, ypos; +{ + FLOAT hv[2]; + FVECT rorg, rdir; + + if (!gotview) { /* no view, no can do */ + XBell(thedisplay, 0); + return(-1); + } + pix2loc(hv, &inpres, xpos-xoff, ypos-yoff); + if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) + return(-1); + printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); + printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); + fflush(stdout); + return(0); +} + + +docom(ekey) /* execute command */ XKeyPressedEvent *ekey; { char buf[80]; @@ -523,7 +617,6 @@ XKeyPressedEvent *ekey; int com, n; double comp; FLOAT hv[2]; - FVECT rorg, rdir; n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL); if (n == 0) @@ -531,8 +624,9 @@ XKeyPressedEvent *ekey; com = buf[0]; switch (com) { /* interpret command */ case 'q': + case 'Q': case CTRL('D'): /* quit */ - quit(0); + quiterr(NULL); case '\n': case '\r': case 'l': @@ -578,21 +672,23 @@ XKeyPressedEvent *ekey; buf, strlen(buf)); return(0); case 't': /* trace */ - if (!gotview) { - XBell(thedisplay, 0); - return(-1); - } - pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff); - if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) - return(-1); - printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); - printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); - fflush(stdout); - return(0); + return(traceray(ekey->x, ekey->y)); case '=': /* adjust exposure */ + case '@': /* adaptation level */ if (avgbox(cval) == -1) return(-1); - n = log(.5/bright(cval))/.69315 - scale; /* truncate */ + comp = bright(cval); + if (comp < 1e-20) { + XBell(thedisplay, 0); + return(-1); + } + if (com == '@') + comp = 106./exposure/ + pow(1.219+pow(comp*WHTEFFICACY/exposure,.4),2.5); + else + comp = .5/comp; + comp = log(comp)/.69315 - scale; + n = comp < 0 ? comp-.5 : comp+.5 ; /* round */ if (n == 0) return(0); scale_rcolors(ourras, pow(2.0, (double)n)); @@ -614,6 +710,21 @@ XKeyPressedEvent *ekey; make_rpixmap(ourras, wind); redraw(0, 0, width, height); return(0); + case 'f': /* turn on fast redraw */ + fast = 1; + make_rpixmap(ourras, wind); + return(0); + case 'F': /* turn off fast redraw */ + fast = 0; + free_rpixmap(ourras); + return(0); + case '0': /* recenter origin */ + if (xoff == 0 & yoff == 0) + return(0); + xoff = yoff = 0; + XClearWindow(thedisplay, wind); + redraw(0, 0, width, height); + return(0); case ' ': /* clear */ redraw(box.xmin, box.ymin, box.xsiz, box.ysiz); return(0); @@ -627,27 +738,23 @@ XKeyPressedEvent *ekey; moveimage(ebut) /* shift the image */ XButtonPressedEvent *ebut; { - union { - XEvent u; - XButtonReleasedEvent b; - XPointerMovedEvent m; - } e; + XEvent e; int mxo, myo; - XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); - while (e.u.type == MotionNotify) { - mxo = e.m.x; - myo = e.m.y; + XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e); + while (e.type == MotionNotify) { + mxo = e.xmotion.x; + myo = e.xmotion.y; revline(ebut->x, ebut->y, mxo, myo); revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); - XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); + XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e); revline(ebut->x, ebut->y, mxo, myo); revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); } - xoff += e.b.x - ebut->x; - yoff += e.b.y - ebut->y; + xoff += e.xbutton.x - ebut->x; + yoff += e.xbutton.y - ebut->y; XClearWindow(thedisplay, wind); redraw(0, 0, width, height); } @@ -656,20 +763,16 @@ XButtonPressedEvent *ebut; getbox(ebut) /* get new box */ XButtonPressedEvent *ebut; { - union { - XEvent u; - XButtonReleasedEvent b; - XPointerMovedEvent m; - } e; + XEvent e; - XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); - while (e.u.type == MotionNotify) { - revbox(ebut->x, ebut->y, box.xmin = e.m.x, box.ymin = e.m.y); - XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); + XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e); + while (e.type == MotionNotify) { + revbox(ebut->x, ebut->y, box.xmin = e.xmotion.x, box.ymin = e.xmotion.y); + XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e); revbox(ebut->x, ebut->y, box.xmin, box.ymin); } - box.xmin = e.b.x<0 ? 0 : (e.b.x>=width ? width-1 : e.b.x); - box.ymin = e.b.y<0 ? 0 : (e.b.y>=height ? height-1 : e.b.y); + box.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x); + box.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y); if (box.xmin > ebut->x) { box.xsiz = box.xmin - ebut->x + 1; box.xmin = ebut->x; @@ -782,8 +885,7 @@ COLR *scan; static short cerr[ICONSIZ]; static int ynext; static char *dp; - double sf; - COLOR col; + COLR clr; register int err; register int x, ti; int errp; @@ -808,17 +910,15 @@ COLR *scan; } if (y < ynext*ymax/iconheight) /* skip this one */ return; - sf = pow(2.0, (double)(scale+8)); err = 0; for (x = 0; x < iconwidth; x++) { if (!(x&7)) *++dp = 0; errp = err; ti = x*xmax/iconwidth; - colr_color(col, scan[ti]); - ti = sf*bright(col); - if (ti > 255) ti = 255; - err += ti + cerr[x]; + copycolr(clr, scan[ti]); + normcolrs(clr, 1, scale); + err += normbright(clr) + cerr[x]; if (err > 127) err -= 255; else @@ -833,12 +933,12 @@ COLR *scan; getfull() /* get full (24-bit) data */ { int y; - register unsigned long *dp; + register unsigned int4 *dp; register int x; /* set gamma correction */ setcolrgam(gamcor); /* read and convert file */ - dp = (unsigned long *)ourdata; + dp = (unsigned int4 *)ourdata; for (y = 0; y < ymax; y++) { getscan(y); add2icon(y, scanline); @@ -847,14 +947,14 @@ getfull() /* get full (24-bit) data */ colrs_gambs(scanline, xmax); if (ourras->image->blue_mask & 1) for (x = 0; x < xmax; x++) - *dp++ = scanline[x][RED] << 16 | - scanline[x][GRN] << 8 | - scanline[x][BLU] ; + *dp++ = (unsigned int4)scanline[x][RED] << 16 | + (unsigned int4)scanline[x][GRN] << 8 | + (unsigned int4)scanline[x][BLU] ; else for (x = 0; x < xmax; x++) - *dp++ = scanline[x][RED] | - scanline[x][GRN] << 8 | - scanline[x][BLU] << 16 ; + *dp++ = (unsigned int4)scanline[x][RED] | + (unsigned int4)scanline[x][GRN] << 8 | + (unsigned int4)scanline[x][BLU] << 16 ; } } @@ -873,31 +973,37 @@ getgrey() /* get greyscale data */ add2icon(y, scanline); if (scale) shiftcolrs(scanline, xmax, scale); + for (x = 0; x < xmax; x++) + scanline[x][GRN] = normbright(scanline[x]); colrs_gambs(scanline, xmax); if (maxcolors < 256) for (x = 0; x < xmax; x++) - *dp++ = ((long)normbright(scanline[x]) * - maxcolors + 128) >> 8; + *dp++ = ((long)scanline[x][GRN] * + maxcolors + maxcolors/2) >> 8; else for (x = 0; x < xmax; x++) - *dp++ = normbright(scanline[x]); + *dp++ = scanline[x][GRN]; } for (x = 0; x < maxcolors; x++) clrtab[x][RED] = clrtab[x][GRN] = - clrtab[x][BLU] = ((long)x*256+maxcolors/2)/maxcolors; + clrtab[x][BLU] = ((long)x*256 + 128)/maxcolors; } getmapped() /* get color-mapped data */ { int y; + /* make sure we can do it first */ + if (fname == NULL) + quiterr("cannot map colors from standard input"); /* set gamma correction */ setcolrgam(gamcor); /* make histogram */ - new_histo(); + if (new_histo((long)xmax*ymax) == -1) + quiterr("cannot initialize histogram"); for (y = 0; y < ymax; y++) { if (getscan(y) < 0) - quiterr("seek error in getmapped"); + break; add2icon(y, scanline); if (scale) shiftcolrs(scanline, xmax, scale); @@ -908,8 +1014,7 @@ getmapped() /* get color-mapped data */ if (!new_clrtab(maxcolors)) quiterr("cannot create color map"); for (y = 0; y < ymax; y++) { - if (getscan(y) < 0) - quiterr("seek error in getmapped"); + getscan(y); if (scale) shiftcolrs(scanline, xmax, scale); colrs_gambs(scanline, xmax); @@ -952,6 +1057,12 @@ double sf; getscan(y) int y; { + static int trunced = -1; /* truncated file? */ +skipit: + if (trunced >= 0 && y >= trunced) { + bzero(scanline, xmax*sizeof(COLR)); + return(-1); + } if (y != cury) { if (scanpos == NULL || scanpos[y] == -1) return(-1); @@ -961,9 +1072,12 @@ int y; } else if (scanpos != NULL && scanpos[y] == -1) scanpos[y] = ftell(fin); - if (freadcolrs(scanline, xmax, fin) < 0) - quiterr("read error"); - + if (freadcolrs(scanline, xmax, fin) < 0) { + fprintf(stderr, "%s: %s: unfinished picture\n", + progname, fname==NULL?"":fname); + trunced = y; + goto skipit; + } cury++; return(0); }