1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
41 |
|
#define ICONSIZ (8*10) /* maximum icon dimension (even 8) */ |
42 |
|
|
43 |
|
#define ourscreen DefaultScreen(thedisplay) |
44 |
– |
#define ourblack BlackPixel(thedisplay,ourscreen) |
45 |
– |
#define ourwhite WhitePixel(thedisplay,ourscreen) |
44 |
|
#define ourroot RootWindow(thedisplay,ourscreen) |
45 |
|
|
46 |
|
#define revline(x0,y0,x1,y1) XDrawLine(thedisplay,wind,revgc,x0,y0,x1,y1) |
55 |
|
char *dispname = NULL; /* our display name */ |
56 |
|
|
57 |
|
Window wind = 0; /* our output window */ |
58 |
+ |
unsigned long ourblack=0, ourwhite=1; /* black and white for this visual */ |
59 |
|
Font fontid; /* our font */ |
60 |
|
|
61 |
|
int maxcolors = 0; /* maximum colors */ |
116 |
|
int argc; |
117 |
|
char *argv[]; |
118 |
|
{ |
119 |
+ |
extern char *getenv(); |
120 |
+ |
char *gv; |
121 |
|
int headline(); |
122 |
|
int i; |
123 |
|
|
124 |
|
progname = argv[0]; |
125 |
+ |
if ((gv = getenv("GAMMA")) != NULL) |
126 |
+ |
gamcor = atof(gv); |
127 |
|
|
128 |
|
for (i = 1; i < argc; i++) |
129 |
|
if (argv[i][0] == '-') |
138 |
|
maxcolors = 2; |
139 |
|
break; |
140 |
|
case 'd': |
141 |
< |
if (argv[i][2] == 'i') { |
141 |
> |
if (argv[i][2] == 'i') |
142 |
|
dispname = argv[++i]; |
143 |
< |
break; |
144 |
< |
} |
142 |
< |
dither = !dither; |
143 |
> |
else |
144 |
> |
dither = !dither; |
145 |
|
break; |
146 |
|
case 'f': |
147 |
|
fast = !fast; |
152 |
|
scale = atoi(argv[++i]); |
153 |
|
break; |
154 |
|
case 'g': |
155 |
< |
if (!strcmp(argv[i], "-geometry")) |
155 |
> |
if (argv[i][2] == 'e') |
156 |
|
geometry = argv[++i]; |
157 |
|
else |
158 |
|
gamcor = atof(argv[++i]); |
193 |
|
getevent(); /* main loop */ |
194 |
|
userr: |
195 |
|
fprintf(stderr, |
196 |
< |
"Usage: %s [-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
196 |
> |
"Usage: %s [-display disp][-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
197 |
|
progname); |
198 |
|
quit(1); |
199 |
|
} |
244 |
|
CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
245 |
|
if (wind == 0) |
246 |
|
quiterr("cannot create window"); |
247 |
+ |
XFreeColormap(thedisplay, ourwinattr.colormap); |
248 |
|
width = xmax; |
249 |
|
height = ymax; |
250 |
|
ourgc = XCreateGC(thedisplay, wind, 0, 0); |
251 |
< |
XSetState(thedisplay, ourgc, BlackPixel(thedisplay,ourscreen), |
249 |
< |
WhitePixel(thedisplay,ourscreen), GXcopy, AllPlanes); |
251 |
> |
XSetState(thedisplay, ourgc, ourblack, ourwhite, GXcopy, AllPlanes); |
252 |
|
revgc = XCreateGC(thedisplay, wind, 0, 0); |
253 |
|
XSetFunction(thedisplay, revgc, GXinvert); |
254 |
|
fontid = XLoadFont(thedisplay, FONTNAME); |
364 |
|
|
365 |
|
getbestvis() /* get the best visual for this screen */ |
366 |
|
{ |
367 |
+ |
#ifdef DEBUG |
368 |
|
static char vistype[][12] = { |
369 |
|
"StaticGray", |
370 |
|
"GrayScale", |
373 |
|
"TrueColor", |
374 |
|
"DirectColor" |
375 |
|
}; |
376 |
+ |
#endif |
377 |
|
static int rankings[3][6] = { |
378 |
|
{TrueColor,DirectColor,PseudoColor,GrayScale,StaticGray,-1}, |
379 |
< |
{PseudoColor,GrayScale,-1}, |
380 |
< |
{PseudoColor,GrayScale,-1} |
379 |
> |
{PseudoColor,GrayScale,StaticGray,-1}, |
380 |
> |
{PseudoColor,GrayScale,StaticGray,-1} |
381 |
|
}; |
382 |
|
XVisualInfo *xvi; |
383 |
|
int vismatched; |
397 |
|
xvi = XGetVisualInfo(thedisplay,VisualScreenMask,&ourvis,&vismatched); |
398 |
|
if (xvi == NULL) |
399 |
|
quiterr("no visuals for this screen!"); |
400 |
< |
for (i = 0; i < vismatched; i++) |
401 |
< |
fprintf(stderr, "Type %s, depth %d\n", vistype[xvi[i].class], xvi[i].depth); |
400 |
> |
#ifdef DEBUG |
401 |
> |
fprintf(stderr, "Supported visuals:\n"); |
402 |
> |
for (i = 0; i < vismatched; i++) |
403 |
> |
fprintf(stderr, "\ttype %s, depth %d\n", |
404 |
> |
vistype[xvi[i].class], xvi[i].depth); |
405 |
> |
#endif |
406 |
|
for (i = 0, j = 1; j < vismatched; j++) |
407 |
|
if (viscmp(&xvi[i],&xvi[j]) > 0) |
408 |
|
i = j; |
415 |
|
quiterr("inadequate visuals on this screen"); |
416 |
|
/* OK, we'll use it */ |
417 |
|
copystruct(&ourvis, &xvi[i]); |
418 |
< |
fprintf(stderr, "Selected visual type %s, depth %d\n", vistype[ourvis.class], |
419 |
< |
ourvis.depth); |
418 |
> |
#ifdef DEBUG |
419 |
> |
fprintf(stderr, "Selected visual type %s, depth %d\n", |
420 |
> |
vistype[ourvis.class], ourvis.depth); |
421 |
> |
#endif |
422 |
> |
/* make appropriate adjustments */ |
423 |
|
if (ourvis.class == GrayScale || ourvis.class == StaticGray) |
424 |
|
greyscale = 1; |
425 |
< |
if (1<<ourvis.depth < maxcolors) |
426 |
< |
maxcolors = 1<<ourvis.depth; |
425 |
> |
if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors) |
426 |
> |
maxcolors = ourvis.colormap_size; |
427 |
|
if (maxcolors > 4) |
428 |
|
maxcolors -= 2; |
429 |
+ |
if (ourvis.class == StaticGray) { |
430 |
+ |
ourblack = 0; |
431 |
+ |
ourwhite = 255; |
432 |
+ |
} else if (ourvis.class == PseudoColor) { |
433 |
+ |
ourblack = BlackPixel(thedisplay,ourscreen); |
434 |
+ |
ourwhite = WhitePixel(thedisplay,ourscreen); |
435 |
+ |
if ((ourblack|ourwhite) & ~255L) { |
436 |
+ |
ourblack = 0; |
437 |
+ |
ourwhite = 1; |
438 |
+ |
} |
439 |
+ |
} else { |
440 |
+ |
ourblack = 0; |
441 |
+ |
ourwhite = ourvis.red_mask|ourvis.green_mask|ourvis.blue_mask; |
442 |
+ |
} |
443 |
|
XFree((char *)xvi); |
444 |
|
} |
445 |
|
|
475 |
|
xmax, ymax, 8); |
476 |
|
if (ourras == NULL) |
477 |
|
goto fail; |
478 |
< |
if (greyscale) |
479 |
< |
biq(dither,maxcolors,1,ourmap); |
480 |
< |
else |
481 |
< |
ciq(dither,maxcolors,1,ourmap); |
482 |
< |
if (init_rcolors(ourras, ourmap[0], ourmap[1], ourmap[2]) == 0) |
483 |
< |
goto fail; |
478 |
> |
if (ourvis.class == StaticGray) |
479 |
> |
getgrey(); |
480 |
> |
else { |
481 |
> |
if (greyscale) |
482 |
> |
biq(dither,maxcolors,1,ourmap); |
483 |
> |
else |
484 |
> |
ciq(dither,maxcolors,1,ourmap); |
485 |
> |
if (init_rcolors(ourras, ourmap[0], |
486 |
> |
ourmap[1], ourmap[2]) == 0) |
487 |
> |
goto fail; |
488 |
> |
} |
489 |
|
} |
490 |
< |
return; |
490 |
> |
return; |
491 |
|
fail: |
492 |
|
quiterr("could not create raster image"); |
493 |
|
} |
518 |
|
make_rpixmap(ourras, wind); |
519 |
|
break; |
520 |
|
case UnmapNotify: |
521 |
< |
unmap_rcolors(ourras); |
521 |
> |
if (!fast) |
522 |
> |
unmap_rcolors(ourras); |
523 |
|
break; |
524 |
|
case Expose: |
525 |
|
redraw(e.e.x, e.e.y, e.e.width, e.e.height); |
875 |
|
} |
876 |
|
|
877 |
|
|
878 |
+ |
getgrey() /* get greyscale data */ |
879 |
+ |
{ |
880 |
+ |
int y; |
881 |
+ |
register unsigned char *dp; |
882 |
+ |
register int x; |
883 |
+ |
/* set gamma correction */ |
884 |
+ |
setcolrgam(gamcor); |
885 |
+ |
/* read and convert file */ |
886 |
+ |
dp = ourdata; |
887 |
+ |
for (y = 0; y < ymax; y++) { |
888 |
+ |
if (getscan(y) < 0) |
889 |
+ |
quiterr("seek error in getfull"); |
890 |
+ |
if (scale) |
891 |
+ |
shiftcolrs(scanline, xmax, scale); |
892 |
+ |
colrs_gambs(scanline, xmax); |
893 |
+ |
add2icon(y, scanline); |
894 |
+ |
if (ourvis.colormap_size < 256) |
895 |
+ |
for (x = 0; x < xmax; x++) |
896 |
+ |
*dp++ = ((long)normbright(scanline[x]) * |
897 |
+ |
ourvis.colormap_size + 128) >> 8; |
898 |
+ |
else |
899 |
+ |
for (x = 0; x < xmax; x++) |
900 |
+ |
*dp++ = normbright(scanline[x]); |
901 |
+ |
} |
902 |
+ |
} |
903 |
+ |
|
904 |
+ |
|
905 |
|
scale_rcolors(xr, sf) /* scale color map */ |
906 |
|
register XRASTER *xr; |
907 |
|
double sf; |
939 |
|
if (fseek(fin, scanpos[y], 0) == -1) |
940 |
|
quiterr("fseek error"); |
941 |
|
cury = y; |
942 |
< |
} else if (scanpos != NULL) |
942 |
> |
} else if (scanpos != NULL && scanpos[y] == -1) |
943 |
|
scanpos[y] = ftell(fin); |
944 |
|
|
945 |
|
if (freadcolrs(scanline, xmax, fin) < 0) |
993 |
|
picwritecm(map) /* handled elsewhere */ |
994 |
|
colormap map; |
995 |
|
{ |
996 |
< |
#ifdef DEBUG |
996 |
> |
#if 0 |
997 |
|
register int i; |
998 |
|
|
999 |
|
for (i = 0; i < 256; i++) |