| 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(); |
| 111 |
|
|
| 111 |
– |
extern double pow(), log(); |
| 112 |
– |
|
| 112 |
|
Display *thedisplay; |
| 113 |
|
|
| 114 |
+ |
|
| 115 |
|
main(argc, argv) |
| 116 |
|
int argc; |
| 117 |
|
char *argv[]; |
| 307 |
|
} |
| 308 |
|
|
| 309 |
|
|
| 310 |
– |
eputs(s) |
| 311 |
– |
char *s; |
| 312 |
– |
{ |
| 313 |
– |
fputs(s, stderr); |
| 314 |
– |
} |
| 315 |
– |
|
| 316 |
– |
|
| 317 |
– |
quit(code) |
| 318 |
– |
int code; |
| 319 |
– |
{ |
| 320 |
– |
exit(code); |
| 321 |
– |
} |
| 322 |
– |
|
| 323 |
– |
|
| 310 |
|
static int |
| 311 |
|
viscmp(v1,v2) /* compare visual to see which is better, descending */ |
| 312 |
|
register XVisualInfo *v1, *v2; |
| 410 |
|
greyscale = 1; |
| 411 |
|
if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors) |
| 412 |
|
maxcolors = ourvis.colormap_size; |
| 427 |
– |
if (maxcolors > 4) |
| 428 |
– |
maxcolors -= 2; |
| 413 |
|
if (ourvis.class == StaticGray) { |
| 414 |
|
ourblack = 0; |
| 415 |
|
ourwhite = 255; |
| 420 |
|
ourblack = 0; |
| 421 |
|
ourwhite = 1; |
| 422 |
|
} |
| 423 |
+ |
if (maxcolors > 4) |
| 424 |
+ |
maxcolors -= 2; |
| 425 |
|
} else { |
| 426 |
|
ourblack = 0; |
| 427 |
|
ourwhite = ourvis.red_mask|ourvis.green_mask|ourvis.blue_mask; |
| 432 |
|
|
| 433 |
|
getras() /* get raster file */ |
| 434 |
|
{ |
| 449 |
– |
colormap ourmap; |
| 435 |
|
XVisualInfo vinfo; |
| 436 |
|
|
| 437 |
|
if (maxcolors <= 2) { /* monochrome */ |
| 443 |
|
if (ourras == NULL) |
| 444 |
|
goto fail; |
| 445 |
|
getmono(); |
| 446 |
< |
} else if (ourvis.class == TrueColor || ourvis.class == DirectColor) { |
| 446 |
> |
} else if (ourvis.class == TrueColor | ourvis.class == DirectColor) { |
| 447 |
|
ourdata = (unsigned char *)malloc(4*xmax*ymax); |
| 448 |
|
if (ourdata == NULL) |
| 449 |
|
goto fail; |
| 460 |
|
xmax, ymax, 8); |
| 461 |
|
if (ourras == NULL) |
| 462 |
|
goto fail; |
| 463 |
< |
if (ourvis.class == StaticGray) |
| 463 |
> |
if (greyscale | ourvis.class == StaticGray) |
| 464 |
|
getgrey(); |
| 465 |
< |
else { |
| 466 |
< |
if (greyscale) |
| 467 |
< |
biq(dither,maxcolors,1,ourmap); |
| 468 |
< |
else |
| 484 |
< |
ciq(dither,maxcolors,1,ourmap); |
| 485 |
< |
if (init_rcolors(ourras, ourmap[0], |
| 486 |
< |
ourmap[1], ourmap[2]) == 0) |
| 487 |
< |
goto fail; |
| 488 |
< |
} |
| 465 |
> |
else |
| 466 |
> |
getmapped(); |
| 467 |
> |
if (ourvis.class != StaticGray && !init_rcolors(ourras,clrtab)) |
| 468 |
> |
goto fail; |
| 469 |
|
} |
| 470 |
< |
return; |
| 470 |
> |
return; |
| 471 |
|
fail: |
| 472 |
|
quiterr("could not create raster image"); |
| 473 |
|
} |
| 614 |
|
make_rpixmap(ourras, wind); |
| 615 |
|
redraw(0, 0, width, height); |
| 616 |
|
return(0); |
| 617 |
+ |
case '0': /* recenter origin */ |
| 618 |
+ |
if (xoff == 0 & yoff == 0) |
| 619 |
+ |
return(0); |
| 620 |
+ |
xoff = yoff = 0; |
| 621 |
+ |
XClearWindow(thedisplay, wind); |
| 622 |
+ |
redraw(0, 0, width, height); |
| 623 |
+ |
return(0); |
| 624 |
|
case ' ': /* clear */ |
| 625 |
|
redraw(box.xmin, box.ymin, box.xsiz, box.ysiz); |
| 626 |
|
return(0); |
| 732 |
|
return(-1); |
| 733 |
|
if (left == ll && right == lr && top == lt && bottom == lb) { |
| 734 |
|
copycolor(clr, lc); |
| 735 |
< |
return; |
| 735 |
> |
return(0); |
| 736 |
|
} |
| 737 |
|
for (y = top; y < bottom; y++) { |
| 738 |
|
if (getscan(y) == -1) |
| 761 |
|
quiterr("out of memory in getmono"); |
| 762 |
|
dp = ourdata - 1; |
| 763 |
|
for (y = 0; y < ymax; y++) { |
| 764 |
< |
if (getscan(y) < 0) |
| 778 |
< |
quiterr("seek error in getmono"); |
| 779 |
< |
normcolrs(scanline, xmax, scale); |
| 764 |
> |
getscan(y); |
| 765 |
|
add2icon(y, scanline); |
| 766 |
+ |
normcolrs(scanline, xmax, scale); |
| 767 |
|
err = 0; |
| 768 |
|
for (x = 0; x < xmax; x++) { |
| 769 |
|
if (!(x&7)) |
| 789 |
|
static short cerr[ICONSIZ]; |
| 790 |
|
static int ynext; |
| 791 |
|
static char *dp; |
| 792 |
+ |
COLR clr; |
| 793 |
|
register int err; |
| 794 |
|
register int x, ti; |
| 795 |
|
int errp; |
| 820 |
|
*++dp = 0; |
| 821 |
|
errp = err; |
| 822 |
|
ti = x*xmax/iconwidth; |
| 823 |
< |
err += normbright(scan[ti]) + cerr[x]; |
| 823 |
> |
copycolr(clr, scan[ti]); |
| 824 |
> |
normcolrs(clr, 1, scale); |
| 825 |
> |
err += normbright(clr) + cerr[x]; |
| 826 |
|
if (err > 127) |
| 827 |
|
err -= 255; |
| 828 |
|
else |
| 844 |
|
/* read and convert file */ |
| 845 |
|
dp = (unsigned long *)ourdata; |
| 846 |
|
for (y = 0; y < ymax; y++) { |
| 847 |
< |
if (getscan(y) < 0) |
| 848 |
< |
quiterr("seek error in getfull"); |
| 847 |
> |
getscan(y); |
| 848 |
> |
add2icon(y, scanline); |
| 849 |
|
if (scale) |
| 850 |
|
shiftcolrs(scanline, xmax, scale); |
| 851 |
|
colrs_gambs(scanline, xmax); |
| 863 |
– |
add2icon(y, scanline); |
| 852 |
|
if (ourras->image->blue_mask & 1) |
| 853 |
|
for (x = 0; x < xmax; x++) |
| 854 |
|
*dp++ = scanline[x][RED] << 16 | |
| 873 |
|
/* read and convert file */ |
| 874 |
|
dp = ourdata; |
| 875 |
|
for (y = 0; y < ymax; y++) { |
| 876 |
< |
if (getscan(y) < 0) |
| 877 |
< |
quiterr("seek error in getfull"); |
| 876 |
> |
getscan(y); |
| 877 |
> |
add2icon(y, scanline); |
| 878 |
|
if (scale) |
| 879 |
|
shiftcolrs(scanline, xmax, scale); |
| 880 |
+ |
for (x = 0; x < xmax; x++) |
| 881 |
+ |
scanline[x][GRN] = normbright(scanline[x]); |
| 882 |
|
colrs_gambs(scanline, xmax); |
| 883 |
< |
add2icon(y, scanline); |
| 894 |
< |
if (ourvis.colormap_size < 256) |
| 883 |
> |
if (maxcolors < 256) |
| 884 |
|
for (x = 0; x < xmax; x++) |
| 885 |
< |
*dp++ = ((long)normbright(scanline[x]) * |
| 886 |
< |
ourvis.colormap_size + 128) >> 8; |
| 885 |
> |
*dp++ = ((long)scanline[x][GRN] * |
| 886 |
> |
maxcolors + maxcolors/2) >> 8; |
| 887 |
|
else |
| 888 |
|
for (x = 0; x < xmax; x++) |
| 889 |
< |
*dp++ = normbright(scanline[x]); |
| 889 |
> |
*dp++ = scanline[x][GRN]; |
| 890 |
|
} |
| 891 |
+ |
for (x = 0; x < maxcolors; x++) |
| 892 |
+ |
clrtab[x][RED] = clrtab[x][GRN] = |
| 893 |
+ |
clrtab[x][BLU] = ((long)x*256 + 128)/maxcolors; |
| 894 |
|
} |
| 895 |
|
|
| 896 |
|
|
| 897 |
+ |
getmapped() /* get color-mapped data */ |
| 898 |
+ |
{ |
| 899 |
+ |
int y; |
| 900 |
+ |
/* set gamma correction */ |
| 901 |
+ |
setcolrgam(gamcor); |
| 902 |
+ |
/* make histogram */ |
| 903 |
+ |
new_histo(); |
| 904 |
+ |
for (y = 0; y < ymax; y++) { |
| 905 |
+ |
if (getscan(y) < 0) |
| 906 |
+ |
quiterr("seek error in getmapped"); |
| 907 |
+ |
add2icon(y, scanline); |
| 908 |
+ |
if (scale) |
| 909 |
+ |
shiftcolrs(scanline, xmax, scale); |
| 910 |
+ |
colrs_gambs(scanline, xmax); |
| 911 |
+ |
cnt_colrs(scanline, xmax); |
| 912 |
+ |
} |
| 913 |
+ |
/* map pixels */ |
| 914 |
+ |
if (!new_clrtab(maxcolors)) |
| 915 |
+ |
quiterr("cannot create color map"); |
| 916 |
+ |
for (y = 0; y < ymax; y++) { |
| 917 |
+ |
if (getscan(y) < 0) |
| 918 |
+ |
quiterr("seek error in getmapped"); |
| 919 |
+ |
if (scale) |
| 920 |
+ |
shiftcolrs(scanline, xmax, scale); |
| 921 |
+ |
colrs_gambs(scanline, xmax); |
| 922 |
+ |
if (dither) |
| 923 |
+ |
dith_colrs(ourdata+y*xmax, scanline, xmax); |
| 924 |
+ |
else |
| 925 |
+ |
map_colrs(ourdata+y*xmax, scanline, xmax); |
| 926 |
+ |
} |
| 927 |
+ |
} |
| 928 |
+ |
|
| 929 |
+ |
|
| 930 |
|
scale_rcolors(xr, sf) /* scale color map */ |
| 931 |
|
register XRASTER *xr; |
| 932 |
|
double sf; |
| 972 |
|
|
| 973 |
|
cury++; |
| 974 |
|
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 |
| 975 |
|
} |