--- ray/src/px/vgaimage.c 1992/10/16 13:09:36 2.3 +++ ray/src/px/vgaimage.c 1994/09/20 15:48:36 2.8 @@ -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"; @@ -86,7 +86,7 @@ char *argv[]; int i; progname = argv[0] = fixargv0(argv[0]); - if ((gv = getenv("GAMMA")) != NULL) + if ((gv = getenv("DISPLAY_GAMMA")) != NULL) gamcor = atof(gv); for (i = 1; i < argc; i++) @@ -168,10 +168,10 @@ init() /* initialize and load display */ short xsiz, ysiz; } video[] = { {_MRES256COLOR, 320, 200}, - {_VRES256COLOR, 640, 400}, + {_VRES256COLOR, 640, 480}, {_SVRES256COLOR, 800, 600}, {_XRES256COLOR, 1024, 768}, - -1 + {-1, 0, 0} }; struct videoconfig config; register int i; @@ -183,14 +183,16 @@ init() /* initialize and load display */ quiterr("input picture too large"); if (_setvideomode(video[i].mode) == 0) quiterr("inadequate display card for picture"); + ms_init(); initialized = 1; _getvideoconfig(&config); - if (maxcolors == 0) - maxcolors = config.numcolors; - if (maxcolors > 4) { - maxcolors -= minpix = 2; - _settextcolor(ourwhite); - } + if (maxcolors == 0 | maxcolors > config.numcolors) + maxcolors = config.numcolors-2; + if (maxcolors <= config.numcolors-2) + minpix = 2; + else + ourwhite = maxcolors-1; + _settextcolor(ourwhite); cheight = config.numypixels/config.numtextrows; cwidth = config.numxpixels/config.numtextcols; /* clear scan position array */ @@ -207,8 +209,10 @@ init() /* initialize and load display */ quiterr(err) /* print message and exit */ char *err; { - if (initialized) + if (initialized) { + ms_done(); _setvideomode(_DEFAULTMODE); + } if (err != NULL) { fprintf(stderr, "%s: %s\n", progname, err); exit(1); @@ -267,13 +271,8 @@ docommand() /* execute command */ watch_mouse() /* look after mousie */ { - static int mouse_installed = 0; int a_x, a_y, l_x, l_y; - if (!mouse_installed) { - ms_init(); - mouse_installed = 1; - } if (mouse_event & M_MOTION) move_cursor(mouse_xpos, mouse_ypos); if (!(mouse_event & M_LDOWN)) @@ -377,11 +376,10 @@ setpalette() /* set our palette using clrtab */ long cvals[256]; register int i; - if (minpix >= 2) { - cvals[ourblack] = _BLACK; cvals[ourwhite] = _BRIGHTWHITE; - } + cvals[ourblack] = _BLACK; + cvals[ourwhite] = _BRIGHTWHITE; for (i = 0; i < maxcolors; i++) - cvals[i+minpix] = clrtab[i][BLU]<<14 & 0x3f0000L | + cvals[i+minpix] = (long)clrtab[i][BLU]<<14 & 0x3f0000L | clrtab[i][GRN]<<6 & 0x3f00 | clrtab[i][RED]>>2; _remapallpalette(cvals); @@ -397,8 +395,8 @@ greyimage() /* display greyscale image */ setcolrgam(gamcor); /* set up color map */ for (x = 0; x < maxcolors; x++) - clrtab[x][RED] = clrtab[x][GRN] = - clrtab[x][BLU] = ((long)x*256+maxcolors/2)/maxcolors; + clrtab[x][RED] = clrtab[x][GRN] = clrtab[x][BLU] = + ((long)x*256 + 128)/maxcolors; setpalette(); _setplotaction(_GPSET); /* read and display file */ @@ -406,18 +404,20 @@ greyimage() /* display greyscale image */ getscan(y); 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++) { - thiscolor = ((long)normbright(scanline[x]) * - maxcolors + 128) >> 8; + thiscolor = ((long)scanline[x][GRN] * + maxcolors + maxcolors/2) / 256; if (thiscolor != lastcolor) _setcolor((lastcolor=thiscolor)+minpix); _setpixel(x, y); } else for (x = 0; x < xmax; x++) { - thiscolor = normbright(scanline[x]); + thiscolor = scanline[x][GRN]; if (thiscolor != lastcolor) _setcolor((lastcolor=thiscolor)+minpix); _setpixel(x, y); @@ -434,6 +434,7 @@ mappedimage() /* display color-mapped image */ /* set gamma correction */ setcolrgam(gamcor); /* make histogram */ + _outtext("Quantizing image -- Please wait..."); new_histo(); for (y = 0; y < ymax; y++) { if (getscan(y) < 0) @@ -477,7 +478,7 @@ int y; if (fseek(fin, scanpos[y], 0) == -1) quiterr("fseek error"); cury = y; - } else if (scanpos != NULL && scanpos[y] == -1) + } else if (fin != stdin && scanpos[y] == -1) scanpos[y] = ftell(fin); if (freadcolrs(scanline, xmax, fin) < 0) @@ -587,4 +588,14 @@ ms_init() int386x( 0x33, &inregs, &outregs, &sregs ); return(1); +} + +ms_done() +{ + union REGS inregs, outregs; + + /* uninstall watcher */ + + inregs.w.ax = 0; + int386 (0x33, &inregs, &outregs); }