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=1, ourwhite=0; /* black and white for this visual */ |
59 |
|
Font fontid; /* our font */ |
60 |
|
|
61 |
|
int maxcolors = 0; /* maximum colors */ |
134 |
|
maxcolors = 2; |
135 |
|
break; |
136 |
|
case 'd': |
137 |
< |
if (argv[i][2] == 'i') { |
137 |
> |
if (argv[i][2] == 'i') |
138 |
|
dispname = argv[++i]; |
139 |
< |
break; |
140 |
< |
} |
142 |
< |
dither = !dither; |
139 |
> |
else |
140 |
> |
dither = !dither; |
141 |
|
break; |
142 |
|
case 'f': |
143 |
|
fast = !fast; |
148 |
|
scale = atoi(argv[++i]); |
149 |
|
break; |
150 |
|
case 'g': |
151 |
< |
if (!strcmp(argv[i], "-geometry")) |
151 |
> |
if (argv[i][2] == 'e') |
152 |
|
geometry = argv[++i]; |
153 |
|
else |
154 |
|
gamcor = atof(argv[++i]); |
189 |
|
getevent(); /* main loop */ |
190 |
|
userr: |
191 |
|
fprintf(stderr, |
192 |
< |
"Usage: %s [-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
192 |
> |
"Usage: %s [-display disp][-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
193 |
|
progname); |
194 |
|
quit(1); |
195 |
|
} |
243 |
|
width = xmax; |
244 |
|
height = ymax; |
245 |
|
ourgc = XCreateGC(thedisplay, wind, 0, 0); |
246 |
< |
XSetState(thedisplay, ourgc, BlackPixel(thedisplay,ourscreen), |
249 |
< |
WhitePixel(thedisplay,ourscreen), GXcopy, AllPlanes); |
246 |
> |
XSetState(thedisplay, ourgc, ourblack, ourwhite, GXcopy, AllPlanes); |
247 |
|
revgc = XCreateGC(thedisplay, wind, 0, 0); |
248 |
|
XSetFunction(thedisplay, revgc, GXinvert); |
249 |
|
fontid = XLoadFont(thedisplay, FONTNAME); |
359 |
|
|
360 |
|
getbestvis() /* get the best visual for this screen */ |
361 |
|
{ |
362 |
+ |
#ifdef DEBUG |
363 |
|
static char vistype[][12] = { |
364 |
|
"StaticGray", |
365 |
|
"GrayScale", |
368 |
|
"TrueColor", |
369 |
|
"DirectColor" |
370 |
|
}; |
371 |
+ |
#endif |
372 |
|
static int rankings[3][6] = { |
373 |
|
{TrueColor,DirectColor,PseudoColor,GrayScale,StaticGray,-1}, |
374 |
< |
{PseudoColor,GrayScale,-1}, |
375 |
< |
{PseudoColor,GrayScale,-1} |
374 |
> |
{PseudoColor,GrayScale,StaticGray,-1}, |
375 |
> |
{PseudoColor,GrayScale,StaticGray,-1} |
376 |
|
}; |
377 |
|
XVisualInfo *xvi; |
378 |
|
int vismatched; |
392 |
|
xvi = XGetVisualInfo(thedisplay,VisualScreenMask,&ourvis,&vismatched); |
393 |
|
if (xvi == NULL) |
394 |
|
quiterr("no visuals for this screen!"); |
395 |
< |
for (i = 0; i < vismatched; i++) |
396 |
< |
fprintf(stderr, "Type %s, depth %d\n", vistype[xvi[i].class], xvi[i].depth); |
395 |
> |
#ifdef DEBUG |
396 |
> |
fprintf(stderr, "Supported visuals:\n"); |
397 |
> |
for (i = 0; i < vismatched; i++) |
398 |
> |
fprintf(stderr, "\ttype %s, depth %d\n", |
399 |
> |
vistype[xvi[i].class], xvi[i].depth); |
400 |
> |
#endif |
401 |
|
for (i = 0, j = 1; j < vismatched; j++) |
402 |
|
if (viscmp(&xvi[i],&xvi[j]) > 0) |
403 |
|
i = j; |
410 |
|
quiterr("inadequate visuals on this screen"); |
411 |
|
/* OK, we'll use it */ |
412 |
|
copystruct(&ourvis, &xvi[i]); |
413 |
< |
fprintf(stderr, "Selected visual type %s, depth %d\n", vistype[ourvis.class], |
414 |
< |
ourvis.depth); |
413 |
> |
#ifdef DEBUG |
414 |
> |
fprintf(stderr, "Selected visual type %s, depth %d\n", |
415 |
> |
vistype[ourvis.class], ourvis.depth); |
416 |
> |
#endif |
417 |
> |
/* make appropriate adjustments */ |
418 |
|
if (ourvis.class == GrayScale || ourvis.class == StaticGray) |
419 |
|
greyscale = 1; |
420 |
< |
if (1<<ourvis.depth < maxcolors) |
421 |
< |
maxcolors = 1<<ourvis.depth; |
420 |
> |
if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors) |
421 |
> |
maxcolors = ourvis.colormap_size; |
422 |
|
if (maxcolors > 4) |
423 |
|
maxcolors -= 2; |
424 |
+ |
if (ourvis.class == StaticGray) { |
425 |
+ |
ourblack = 0; |
426 |
+ |
ourwhite = 255; |
427 |
+ |
} else if (ourvis.class == PseudoColor) { |
428 |
+ |
ourblack = BlackPixel(thedisplay,ourscreen); |
429 |
+ |
ourwhite = WhitePixel(thedisplay,ourscreen); |
430 |
+ |
} else { |
431 |
+ |
ourblack = 0; |
432 |
+ |
ourwhite = ~0; |
433 |
+ |
} |
434 |
|
XFree((char *)xvi); |
435 |
|
} |
436 |
|
|
466 |
|
xmax, ymax, 8); |
467 |
|
if (ourras == NULL) |
468 |
|
goto fail; |
469 |
< |
if (greyscale) |
470 |
< |
biq(dither,maxcolors,1,ourmap); |
471 |
< |
else |
472 |
< |
ciq(dither,maxcolors,1,ourmap); |
473 |
< |
if (init_rcolors(ourras, ourmap[0], ourmap[1], ourmap[2]) == 0) |
474 |
< |
goto fail; |
469 |
> |
if (ourvis.class == StaticGray) |
470 |
> |
getgrey(); |
471 |
> |
else { |
472 |
> |
if (greyscale) |
473 |
> |
biq(dither,maxcolors,1,ourmap); |
474 |
> |
else |
475 |
> |
ciq(dither,maxcolors,1,ourmap); |
476 |
> |
if (init_rcolors(ourras, ourmap[0], |
477 |
> |
ourmap[1], ourmap[2]) == 0) |
478 |
> |
goto fail; |
479 |
> |
} |
480 |
|
} |
481 |
< |
return; |
481 |
> |
return; |
482 |
|
fail: |
483 |
|
quiterr("could not create raster image"); |
484 |
|
} |
509 |
|
make_rpixmap(ourras, wind); |
510 |
|
break; |
511 |
|
case UnmapNotify: |
512 |
< |
unmap_rcolors(ourras); |
512 |
> |
if (!fast) |
513 |
> |
unmap_rcolors(ourras); |
514 |
|
break; |
515 |
|
case Expose: |
516 |
|
redraw(e.e.x, e.e.y, e.e.width, e.e.height); |
866 |
|
} |
867 |
|
|
868 |
|
|
869 |
+ |
getgrey() /* get greyscale data */ |
870 |
+ |
{ |
871 |
+ |
int y; |
872 |
+ |
register unsigned char *dp; |
873 |
+ |
register int x; |
874 |
+ |
/* set gamma correction */ |
875 |
+ |
setcolrgam(gamcor); |
876 |
+ |
/* read and convert file */ |
877 |
+ |
dp = ourdata; |
878 |
+ |
for (y = 0; y < ymax; y++) { |
879 |
+ |
if (getscan(y) < 0) |
880 |
+ |
quiterr("seek error in getfull"); |
881 |
+ |
if (scale) |
882 |
+ |
shiftcolrs(scanline, xmax, scale); |
883 |
+ |
colrs_gambs(scanline, xmax); |
884 |
+ |
add2icon(y, scanline); |
885 |
+ |
if (ourvis.colormap_size < 256) |
886 |
+ |
for (x = 0; x < xmax; x++) |
887 |
+ |
*dp++ = ((long)normbright(scanline[x]) * |
888 |
+ |
ourvis.colormap_size + 128) >> 8; |
889 |
+ |
else |
890 |
+ |
for (x = 0; x < xmax; x++) |
891 |
+ |
*dp++ = normbright(scanline[x]); |
892 |
+ |
} |
893 |
+ |
} |
894 |
+ |
|
895 |
+ |
|
896 |
|
scale_rcolors(xr, sf) /* scale color map */ |
897 |
|
register XRASTER *xr; |
898 |
|
double sf; |
984 |
|
picwritecm(map) /* handled elsewhere */ |
985 |
|
colormap map; |
986 |
|
{ |
987 |
< |
#ifdef DEBUG |
987 |
> |
#if 0 |
988 |
|
register int i; |
989 |
|
|
990 |
|
for (i = 0; i < 256; i++) |