--- ray/src/px/x11image.c 1992/05/27 14:28:50 2.6 +++ ray/src/px/x11image.c 1993/05/05 10:27:58 2.26 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1993 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -24,10 +24,10 @@ static char SCCSid[] = "$SunId$ LBL"; #include #include #include +#include #include "color.h" #include "view.h" -#include "pic.h" #include "x11raster.h" #include "random.h" #include "resolu.h" @@ -41,8 +41,6 @@ static char SCCSid[] = "$SunId$ LBL"; #define ICONSIZ (8*10) /* maximum icon dimension (even 8) */ #define ourscreen DefaultScreen(thedisplay) -#define ourblack BlackPixel(thedisplay,ourscreen) -#define ourwhite WhitePixel(thedisplay,ourscreen) #define ourroot RootWindow(thedisplay,ourscreen) #define revline(x0,y0,x1,y1) XDrawLine(thedisplay,wind,revgc,x0,y0,x1,y1) @@ -57,8 +55,7 @@ int fast = 0; /* keep picture in Pixmap? */ char *dispname = NULL; /* our display name */ Window wind = 0; /* our output window */ -Font fontid; /* our font */ - +unsigned long ourblack=0, ourwhite=1; /* black and white for this visual */ int maxcolors = 0; /* maximum colors */ int greyscale = 0; /* in grey */ @@ -105,22 +102,26 @@ char *progname; char errmsg[128]; +extern BYTE clrtab[256][3]; /* global color map */ + extern long ftell(); -extern char *malloc(), *calloc(); - -extern double pow(), log(); - Display *thedisplay; +Atom closedownAtom, wmProtocolsAtom; + main(argc, argv) int argc; char *argv[]; { + extern char *getenv(); + char *gv; int headline(); int i; progname = argv[0]; + if ((gv = getenv("GAMMA")) != NULL) + gamcor = atof(gv); for (i = 1; i < argc; i++) if (argv[i][0] == '-') @@ -135,11 +136,10 @@ char *argv[]; maxcolors = 2; break; case 'd': - if (argv[i][2] == 'i') { + if (argv[i][2] == 'i') dispname = argv[++i]; - break; - } - dither = !dither; + else + dither = !dither; break; case 'f': fast = !fast; @@ -150,7 +150,7 @@ char *argv[]; scale = atoi(argv[++i]); break; case 'g': - if (!strcmp(argv[i], "-geometry")) + if (argv[i][2] == 'e') geometry = argv[++i]; else gamcor = atof(argv[++i]); @@ -185,15 +185,15 @@ 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 */ for ( ; ; ) getevent(); /* main loop */ userr: fprintf(stderr, - "Usage: %s [-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] pic\n", progname); - quit(1); + exit(1); } @@ -212,85 +212,109 @@ 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"); /* 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"); - width = xmax; - height = ymax; - ourgc = XCreateGC(thedisplay, wind, 0, 0); - XSetState(thedisplay, ourgc, BlackPixel(thedisplay,ourscreen), - WhitePixel(thedisplay,ourscreen), 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; + xgcv.foreground = ourblack; + xgcv.background = ourwhite; + if ((xgcv.font = XLoadFont(thedisplay, FONTNAME)) == 0) + quiterr("cannot get font"); + 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 */ @@ -305,20 +329,6 @@ char *err; } -eputs(s) -char *s; -{ - fputs(s, stderr); -} - - -quit(code) -int code; -{ - exit(code); -} - - static int viscmp(v1,v2) /* compare visual to see which is better, descending */ register XVisualInfo *v1, *v2; @@ -362,6 +372,7 @@ register XVisualInfo *v1, *v2; getbestvis() /* get the best visual for this screen */ { +#ifdef DEBUG static char vistype[][12] = { "StaticGray", "GrayScale", @@ -370,10 +381,11 @@ static char vistype[][12] = { "TrueColor", "DirectColor" }; +#endif static int rankings[3][6] = { {TrueColor,DirectColor,PseudoColor,GrayScale,StaticGray,-1}, - {PseudoColor,GrayScale,-1}, - {PseudoColor,GrayScale,-1} + {PseudoColor,GrayScale,StaticGray,-1}, + {PseudoColor,GrayScale,StaticGray,-1} }; XVisualInfo *xvi; int vismatched; @@ -393,8 +405,12 @@ static char vistype[][12] = { xvi = XGetVisualInfo(thedisplay,VisualScreenMask,&ourvis,&vismatched); if (xvi == NULL) quiterr("no visuals for this screen!"); -for (i = 0; i < vismatched; i++) -fprintf(stderr, "Type %s, depth %d\n", vistype[xvi[i].class], xvi[i].depth); +#ifdef DEBUG + fprintf(stderr, "Supported visuals:\n"); + for (i = 0; i < vismatched; i++) + fprintf(stderr, "\ttype %s, depth %d\n", + vistype[xvi[i].class], xvi[i].depth); +#endif for (i = 0, j = 1; j < vismatched; j++) if (viscmp(&xvi[i],&xvi[j]) > 0) i = j; @@ -407,21 +423,37 @@ fprintf(stderr, "Type %s, depth %d\n", vistype[xvi[i]. quiterr("inadequate visuals on this screen"); /* OK, we'll use it */ copystruct(&ourvis, &xvi[i]); -fprintf(stderr, "Selected visual type %s, depth %d\n", vistype[ourvis.class], -ourvis.depth); +#ifdef DEBUG + fprintf(stderr, "Selected visual type %s, depth %d\n", + vistype[ourvis.class], ourvis.depth); +#endif + /* make appropriate adjustments */ if (ourvis.class == GrayScale || ourvis.class == StaticGray) greyscale = 1; - if (1< 4) - maxcolors -= 2; + if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors) + maxcolors = ourvis.colormap_size; + if (ourvis.class == StaticGray) { + ourblack = 0; + ourwhite = 255; + } else if (ourvis.class == PseudoColor) { + ourblack = BlackPixel(thedisplay,ourscreen); + ourwhite = WhitePixel(thedisplay,ourscreen); + if ((ourblack|ourwhite) & ~255L) { + ourblack = 0; + ourwhite = 1; + } + if (maxcolors > 4) + maxcolors -= 2; + } else { + ourblack = 0; + ourwhite = ourvis.red_mask|ourvis.green_mask|ourvis.blue_mask; + } XFree((char *)xvi); } getras() /* get raster file */ { - colormap ourmap; XVisualInfo vinfo; if (maxcolors <= 2) { /* monochrome */ @@ -433,7 +465,7 @@ getras() /* get raster file */ if (ourras == NULL) goto fail; getmono(); - } else if (ourvis.class == TrueColor || ourvis.class == DirectColor) { + } else if (ourvis.class == TrueColor | ourvis.class == DirectColor) { ourdata = (unsigned char *)malloc(4*xmax*ymax); if (ourdata == NULL) goto fail; @@ -450,11 +482,11 @@ getras() /* get raster file */ xmax, ymax, 8); if (ourras == NULL) goto fail; - if (greyscale) - biq(dither,maxcolors,1,ourmap); + if (greyscale | ourvis.class == StaticGray) + getgrey(); else - ciq(dither,maxcolors,1,ourmap); - if (init_rcolors(ourras, ourmap[0], ourmap[1], ourmap[2]) == 0) + getmapped(); + if (ourvis.class != StaticGray && !init_rcolors(ourras,clrtab)) goto fail; } return; @@ -465,22 +497,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); @@ -488,22 +514,51 @@ getevent() /* process the next event */ make_rpixmap(ourras, wind); break; case UnmapNotify: - unmap_rcolors(ourras); + if (!fast) + 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]; @@ -512,7 +567,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) @@ -520,8 +574,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': @@ -567,21 +622,16 @@ 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 = com=='@' + ? 106./pow(1.219+pow(luminance(cval)/exposure,.4),2.5)/exposure + : .5/bright(cval) ; + 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)); @@ -600,9 +650,16 @@ XKeyPressedEvent *ekey; XClearWindow(thedisplay, wind); map_rcolors(ourras, wind); if (fast) - make_rpixmap(ourras); + make_rpixmap(ourras, wind); redraw(0, 0, width, height); 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); @@ -616,27 +673,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); } @@ -645,20 +698,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; @@ -714,7 +763,7 @@ COLOR clr; return(-1); if (left == ll && right == lr && top == lt && bottom == lb) { copycolor(clr, lc); - return; + return(0); } for (y = top; y < bottom; y++) { if (getscan(y) == -1) @@ -743,10 +792,9 @@ getmono() /* get monochrome data */ quiterr("out of memory in getmono"); dp = ourdata - 1; for (y = 0; y < ymax; y++) { - if (getscan(y) < 0) - quiterr("seek error in getmono"); - normcolrs(scanline, xmax, scale); + getscan(y); add2icon(y, scanline); + normcolrs(scanline, xmax, scale); err = 0; for (x = 0; x < xmax; x++) { if (!(x&7)) @@ -772,6 +820,7 @@ COLR *scan; static short cerr[ICONSIZ]; static int ynext; static char *dp; + COLR clr; register int err; register int x, ti; int errp; @@ -802,7 +851,9 @@ COLR *scan; *++dp = 0; errp = err; ti = x*xmax/iconwidth; - err += normbright(scan[ti]) + cerr[x]; + copycolr(clr, scan[ti]); + normcolrs(clr, 1, scale); + err += normbright(clr) + cerr[x]; if (err > 127) err -= 255; else @@ -824,12 +875,11 @@ getfull() /* get full (24-bit) data */ /* read and convert file */ dp = (unsigned long *)ourdata; for (y = 0; y < ymax; y++) { - if (getscan(y) < 0) - quiterr("seek error in getfull"); + getscan(y); + add2icon(y, scanline); if (scale) shiftcolrs(scanline, xmax, scale); colrs_gambs(scanline, xmax); - add2icon(y, scanline); if (ourras->image->blue_mask & 1) for (x = 0; x < xmax; x++) *dp++ = scanline[x][RED] << 16 | @@ -844,6 +894,70 @@ getfull() /* get full (24-bit) data */ } +getgrey() /* get greyscale data */ +{ + int y; + register unsigned char *dp; + register int x; + /* set gamma correction */ + setcolrgam(gamcor); + /* read and convert file */ + dp = ourdata; + for (y = 0; y < ymax; y++) { + getscan(y); + 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)scanline[x][GRN] * + maxcolors + maxcolors/2) >> 8; + else + for (x = 0; x < xmax; x++) + *dp++ = scanline[x][GRN]; + } + for (x = 0; x < maxcolors; x++) + clrtab[x][RED] = clrtab[x][GRN] = + clrtab[x][BLU] = ((long)x*256 + 128)/maxcolors; +} + + +getmapped() /* get color-mapped data */ +{ + int y; + /* set gamma correction */ + setcolrgam(gamcor); + /* make histogram */ + new_histo(); + for (y = 0; y < ymax; y++) { + if (getscan(y) < 0) + quiterr("seek error in getmapped"); + add2icon(y, scanline); + if (scale) + shiftcolrs(scanline, xmax, scale); + colrs_gambs(scanline, xmax); + cnt_colrs(scanline, xmax); + } + /* map pixels */ + if (!new_clrtab(maxcolors)) + quiterr("cannot create color map"); + for (y = 0; y < ymax; y++) { + if (getscan(y) < 0) + quiterr("seek error in getmapped"); + if (scale) + shiftcolrs(scanline, xmax, scale); + colrs_gambs(scanline, xmax); + if (dither) + dith_colrs(ourdata+y*xmax, scanline, xmax); + else + map_colrs(ourdata+y*xmax, scanline, xmax); + } +} + + scale_rcolors(xr, sf) /* scale color map */ register XRASTER *xr; double sf; @@ -881,7 +995,7 @@ int y; if (fseek(fin, scanpos[y], 0) == -1) quiterr("fseek error"); cury = y; - } else if (scanpos != NULL) + } else if (scanpos != NULL && scanpos[y] == -1) scanpos[y] = ftell(fin); if (freadcolrs(scanline, xmax, fin) < 0) @@ -889,56 +1003,4 @@ int y; cury++; return(0); -} - - -picreadline3(y, l3) /* read in 3-byte scanline */ -int y; -register rgbpixel *l3; -{ - register int i; - /* read scanline */ - if (getscan(y) < 0) - quiterr("cannot seek for picreadline"); - /* convert scanline */ - normcolrs(scanline, xmax, scale); - add2icon(y, scanline); - for (i = 0; i < xmax; i++) { - l3[i].r = scanline[i][RED]; - l3[i].g = scanline[i][GRN]; - l3[i].b = scanline[i][BLU]; - } -} - - -picwriteline(y, l) /* add 8-bit scanline to image */ -int y; -pixel *l; -{ - bcopy((char *)l, (char *)ourdata+y*xmax, xmax); -} - - -picreadcm(map) /* do gamma correction */ -colormap map; -{ - extern double pow(); - register int i, val; - - for (i = 0; i < 256; i++) { - val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0; - map[0][i] = map[1][i] = map[2][i] = val; - } -} - - -picwritecm(map) /* handled elsewhere */ -colormap map; -{ -#ifdef DEBUG - register int i; - - for (i = 0; i < 256; i++) - printf("%d %d %d\n", map[0][i],map[1][i],map[2][i]); -#endif }