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" |
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(); |
425 |
|
greyscale = 1; |
426 |
|
if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors) |
427 |
|
maxcolors = ourvis.colormap_size; |
427 |
– |
if (maxcolors > 4) |
428 |
– |
maxcolors -= 2; |
428 |
|
if (ourvis.class == StaticGray) { |
429 |
|
ourblack = 0; |
430 |
|
ourwhite = 255; |
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; |
447 |
|
|
448 |
|
getras() /* get raster file */ |
449 |
|
{ |
449 |
– |
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 |
484 |
< |
ciq(dither,maxcolors,1,ourmap); |
485 |
< |
if (init_rcolors(ourras, ourmap[0], |
486 |
< |
ourmap[1], ourmap[2]) == 0) |
487 |
< |
goto fail; |
488 |
< |
} |
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; |
978 |
|
|
979 |
|
cury++; |
980 |
|
return(0); |
950 |
– |
} |
951 |
– |
|
952 |
– |
|
953 |
– |
picreadline3(y, l3) /* read in 3-byte scanline */ |
954 |
– |
int y; |
955 |
– |
register rgbpixel *l3; |
956 |
– |
{ |
957 |
– |
register int i; |
958 |
– |
/* read scanline */ |
959 |
– |
if (getscan(y) < 0) |
960 |
– |
quiterr("cannot seek for picreadline"); |
961 |
– |
/* convert scanline */ |
962 |
– |
normcolrs(scanline, xmax, scale); |
963 |
– |
add2icon(y, scanline); |
964 |
– |
for (i = 0; i < xmax; i++) { |
965 |
– |
l3[i].r = scanline[i][RED]; |
966 |
– |
l3[i].g = scanline[i][GRN]; |
967 |
– |
l3[i].b = scanline[i][BLU]; |
968 |
– |
} |
969 |
– |
} |
970 |
– |
|
971 |
– |
|
972 |
– |
picwriteline(y, l) /* add 8-bit scanline to image */ |
973 |
– |
int y; |
974 |
– |
pixel *l; |
975 |
– |
{ |
976 |
– |
bcopy((char *)l, (char *)ourdata+y*xmax, xmax); |
977 |
– |
} |
978 |
– |
|
979 |
– |
|
980 |
– |
picreadcm(map) /* do gamma correction */ |
981 |
– |
colormap map; |
982 |
– |
{ |
983 |
– |
extern double pow(); |
984 |
– |
register int i, val; |
985 |
– |
|
986 |
– |
for (i = 0; i < 256; i++) { |
987 |
– |
val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0; |
988 |
– |
map[0][i] = map[1][i] = map[2][i] = val; |
989 |
– |
} |
990 |
– |
} |
991 |
– |
|
992 |
– |
|
993 |
– |
picwritecm(map) /* handled elsewhere */ |
994 |
– |
colormap map; |
995 |
– |
{ |
996 |
– |
#if 0 |
997 |
– |
register int i; |
998 |
– |
|
999 |
– |
for (i = 0; i < 256; i++) |
1000 |
– |
printf("%d %d %d\n", map[0][i],map[1][i],map[2][i]); |
1001 |
– |
#endif |
981 |
|
} |