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"; |
27 |
|
|
28 |
|
#include "color.h" |
29 |
|
#include "view.h" |
30 |
– |
#include "pic.h" |
30 |
|
#include "x11raster.h" |
31 |
|
#include "random.h" |
32 |
|
#include "resolu.h" |
40 |
|
#define ICONSIZ (8*10) /* maximum icon dimension (even 8) */ |
41 |
|
|
42 |
|
#define ourscreen DefaultScreen(thedisplay) |
44 |
– |
#define ourblack BlackPixel(thedisplay,ourscreen) |
45 |
– |
#define ourwhite WhitePixel(thedisplay,ourscreen) |
43 |
|
#define ourroot RootWindow(thedisplay,ourscreen) |
44 |
|
|
45 |
|
#define revline(x0,y0,x1,y1) XDrawLine(thedisplay,wind,revgc,x0,y0,x1,y1) |
54 |
|
char *dispname = NULL; /* our display name */ |
55 |
|
|
56 |
|
Window wind = 0; /* our output window */ |
57 |
+ |
unsigned long ourblack=0, ourwhite=1; /* black and white for this visual */ |
58 |
|
Font fontid; /* our font */ |
59 |
|
|
60 |
|
int maxcolors = 0; /* maximum colors */ |
103 |
|
|
104 |
|
char errmsg[128]; |
105 |
|
|
106 |
+ |
extern BYTE clrtab[256][3]; /* global color map */ |
107 |
+ |
|
108 |
|
extern long ftell(); |
109 |
|
|
110 |
|
extern char *malloc(), *calloc(); |
117 |
|
int argc; |
118 |
|
char *argv[]; |
119 |
|
{ |
120 |
+ |
extern char *getenv(); |
121 |
+ |
char *gv; |
122 |
|
int headline(); |
123 |
|
int i; |
124 |
|
|
125 |
|
progname = argv[0]; |
126 |
+ |
if ((gv = getenv("GAMMA")) != NULL) |
127 |
+ |
gamcor = atof(gv); |
128 |
|
|
129 |
|
for (i = 1; i < argc; i++) |
130 |
|
if (argv[i][0] == '-') |
245 |
|
CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
246 |
|
if (wind == 0) |
247 |
|
quiterr("cannot create window"); |
248 |
+ |
XFreeColormap(thedisplay, ourwinattr.colormap); |
249 |
|
width = xmax; |
250 |
|
height = ymax; |
251 |
|
ourgc = XCreateGC(thedisplay, wind, 0, 0); |
252 |
< |
XSetState(thedisplay, ourgc, BlackPixel(thedisplay,ourscreen), |
248 |
< |
WhitePixel(thedisplay,ourscreen), GXcopy, AllPlanes); |
252 |
> |
XSetState(thedisplay, ourgc, ourblack, ourwhite, GXcopy, AllPlanes); |
253 |
|
revgc = XCreateGC(thedisplay, wind, 0, 0); |
254 |
|
XSetFunction(thedisplay, revgc, GXinvert); |
255 |
|
fontid = XLoadFont(thedisplay, FONTNAME); |
420 |
|
fprintf(stderr, "Selected visual type %s, depth %d\n", |
421 |
|
vistype[ourvis.class], ourvis.depth); |
422 |
|
#endif |
423 |
+ |
/* make appropriate adjustments */ |
424 |
|
if (ourvis.class == GrayScale || ourvis.class == StaticGray) |
425 |
|
greyscale = 1; |
426 |
|
if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors) |
427 |
|
maxcolors = ourvis.colormap_size; |
428 |
< |
if (maxcolors > 4) |
429 |
< |
maxcolors -= 2; |
428 |
> |
if (ourvis.class == StaticGray) { |
429 |
> |
ourblack = 0; |
430 |
> |
ourwhite = 255; |
431 |
> |
} else if (ourvis.class == PseudoColor) { |
432 |
> |
ourblack = BlackPixel(thedisplay,ourscreen); |
433 |
> |
ourwhite = WhitePixel(thedisplay,ourscreen); |
434 |
> |
if ((ourblack|ourwhite) & ~255L) { |
435 |
> |
ourblack = 0; |
436 |
> |
ourwhite = 1; |
437 |
> |
} |
438 |
> |
if (maxcolors > 4) |
439 |
> |
maxcolors -= 2; |
440 |
> |
} else { |
441 |
> |
ourblack = 0; |
442 |
> |
ourwhite = ourvis.red_mask|ourvis.green_mask|ourvis.blue_mask; |
443 |
> |
} |
444 |
|
XFree((char *)xvi); |
445 |
|
} |
446 |
|
|
447 |
|
|
448 |
|
getras() /* get raster file */ |
449 |
|
{ |
431 |
– |
colormap ourmap; |
450 |
|
XVisualInfo vinfo; |
451 |
|
|
452 |
|
if (maxcolors <= 2) { /* monochrome */ |
458 |
|
if (ourras == NULL) |
459 |
|
goto fail; |
460 |
|
getmono(); |
461 |
< |
} else if (ourvis.class == TrueColor || ourvis.class == DirectColor) { |
461 |
> |
} else if (ourvis.class == TrueColor | ourvis.class == DirectColor) { |
462 |
|
ourdata = (unsigned char *)malloc(4*xmax*ymax); |
463 |
|
if (ourdata == NULL) |
464 |
|
goto fail; |
475 |
|
xmax, ymax, 8); |
476 |
|
if (ourras == NULL) |
477 |
|
goto fail; |
478 |
< |
if (ourvis.class == StaticGray) |
478 |
> |
if (greyscale | ourvis.class == StaticGray) |
479 |
|
getgrey(); |
480 |
< |
else { |
481 |
< |
if (greyscale) |
482 |
< |
biq(dither,maxcolors,1,ourmap); |
483 |
< |
else |
466 |
< |
ciq(dither,maxcolors,1,ourmap); |
467 |
< |
if (init_rcolors(ourras, ourmap[0], |
468 |
< |
ourmap[1], ourmap[2]) == 0) |
469 |
< |
goto fail; |
470 |
< |
} |
480 |
> |
else |
481 |
> |
getmapped(); |
482 |
> |
if (ourvis.class != StaticGray && !init_rcolors(ourras,clrtab)) |
483 |
> |
goto fail; |
484 |
|
} |
485 |
< |
return; |
485 |
> |
return; |
486 |
|
fail: |
487 |
|
quiterr("could not create raster image"); |
488 |
|
} |
626 |
|
XClearWindow(thedisplay, wind); |
627 |
|
map_rcolors(ourras, wind); |
628 |
|
if (fast) |
629 |
< |
make_rpixmap(ourras); |
629 |
> |
make_rpixmap(ourras, wind); |
630 |
|
redraw(0, 0, width, height); |
631 |
|
return(0); |
632 |
|
case ' ': /* clear */ |
881 |
|
dp = ourdata; |
882 |
|
for (y = 0; y < ymax; y++) { |
883 |
|
if (getscan(y) < 0) |
884 |
< |
quiterr("seek error in getfull"); |
884 |
> |
quiterr("seek error in getgrey"); |
885 |
|
if (scale) |
886 |
|
shiftcolrs(scanline, xmax, scale); |
887 |
|
colrs_gambs(scanline, xmax); |
888 |
|
add2icon(y, scanline); |
889 |
< |
if (ourvis.colormap_size < 256) |
889 |
> |
if (maxcolors < 256) |
890 |
|
for (x = 0; x < xmax; x++) |
891 |
|
*dp++ = ((long)normbright(scanline[x]) * |
892 |
< |
ourvis.colormap_size + 128) >> 8; |
892 |
> |
maxcolors + 128) >> 8; |
893 |
|
else |
894 |
|
for (x = 0; x < xmax; x++) |
895 |
|
*dp++ = normbright(scanline[x]); |
896 |
|
} |
897 |
+ |
for (x = 0; x < maxcolors; x++) |
898 |
+ |
clrtab[x][RED] = clrtab[x][GRN] = |
899 |
+ |
clrtab[x][BLU] = (x*256+maxcolors/2)/maxcolors; |
900 |
|
} |
901 |
|
|
902 |
|
|
903 |
+ |
getmapped() /* get color-mapped data */ |
904 |
+ |
{ |
905 |
+ |
int y; |
906 |
+ |
/* set gamma correction */ |
907 |
+ |
setcolrgam(gamcor); |
908 |
+ |
/* make histogram */ |
909 |
+ |
new_histo(); |
910 |
+ |
for (y = 0; y < ymax; y++) { |
911 |
+ |
if (getscan(y) < 0) |
912 |
+ |
quiterr("seek error in getmapped"); |
913 |
+ |
if (scale) |
914 |
+ |
shiftcolrs(scanline, xmax, scale); |
915 |
+ |
colrs_gambs(scanline, xmax); |
916 |
+ |
add2icon(y, scanline); |
917 |
+ |
cnt_colrs(scanline, xmax); |
918 |
+ |
} |
919 |
+ |
/* map pixels */ |
920 |
+ |
if (!new_clrtab(maxcolors)) |
921 |
+ |
quiterr("cannot create color map"); |
922 |
+ |
for (y = 0; y < ymax; y++) { |
923 |
+ |
if (getscan(y) < 0) |
924 |
+ |
quiterr("seek error in getmapped"); |
925 |
+ |
if (scale) |
926 |
+ |
shiftcolrs(scanline, xmax, scale); |
927 |
+ |
colrs_gambs(scanline, xmax); |
928 |
+ |
if (dither) |
929 |
+ |
dith_colrs(ourdata+y*xmax, scanline, xmax); |
930 |
+ |
else |
931 |
+ |
map_colrs(ourdata+y*xmax, scanline, xmax); |
932 |
+ |
} |
933 |
+ |
} |
934 |
+ |
|
935 |
+ |
|
936 |
|
scale_rcolors(xr, sf) /* scale color map */ |
937 |
|
register XRASTER *xr; |
938 |
|
double sf; |
970 |
|
if (fseek(fin, scanpos[y], 0) == -1) |
971 |
|
quiterr("fseek error"); |
972 |
|
cury = y; |
973 |
< |
} else if (scanpos != NULL) |
973 |
> |
} else if (scanpos != NULL && scanpos[y] == -1) |
974 |
|
scanpos[y] = ftell(fin); |
975 |
|
|
976 |
|
if (freadcolrs(scanline, xmax, fin) < 0) |
978 |
|
|
979 |
|
cury++; |
980 |
|
return(0); |
932 |
– |
} |
933 |
– |
|
934 |
– |
|
935 |
– |
picreadline3(y, l3) /* read in 3-byte scanline */ |
936 |
– |
int y; |
937 |
– |
register rgbpixel *l3; |
938 |
– |
{ |
939 |
– |
register int i; |
940 |
– |
/* read scanline */ |
941 |
– |
if (getscan(y) < 0) |
942 |
– |
quiterr("cannot seek for picreadline"); |
943 |
– |
/* convert scanline */ |
944 |
– |
normcolrs(scanline, xmax, scale); |
945 |
– |
add2icon(y, scanline); |
946 |
– |
for (i = 0; i < xmax; i++) { |
947 |
– |
l3[i].r = scanline[i][RED]; |
948 |
– |
l3[i].g = scanline[i][GRN]; |
949 |
– |
l3[i].b = scanline[i][BLU]; |
950 |
– |
} |
951 |
– |
} |
952 |
– |
|
953 |
– |
|
954 |
– |
picwriteline(y, l) /* add 8-bit scanline to image */ |
955 |
– |
int y; |
956 |
– |
pixel *l; |
957 |
– |
{ |
958 |
– |
bcopy((char *)l, (char *)ourdata+y*xmax, xmax); |
959 |
– |
} |
960 |
– |
|
961 |
– |
|
962 |
– |
picreadcm(map) /* do gamma correction */ |
963 |
– |
colormap map; |
964 |
– |
{ |
965 |
– |
extern double pow(); |
966 |
– |
register int i, val; |
967 |
– |
|
968 |
– |
for (i = 0; i < 256; i++) { |
969 |
– |
val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0; |
970 |
– |
map[0][i] = map[1][i] = map[2][i] = val; |
971 |
– |
} |
972 |
– |
} |
973 |
– |
|
974 |
– |
|
975 |
– |
picwritecm(map) /* handled elsewhere */ |
976 |
– |
colormap map; |
977 |
– |
{ |
978 |
– |
#if 0 |
979 |
– |
register int i; |
980 |
– |
|
981 |
– |
for (i = 0; i < 256; i++) |
982 |
– |
printf("%d %d %d\n", map[0][i],map[1][i],map[2][i]); |
983 |
– |
#endif |
981 |
|
} |