1 |
– |
/* Copyright (c) 1997 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* x11image.c - driver for X-windows |
6 |
|
* |
24 |
|
#include <X11/Xutil.h> |
25 |
|
#include <X11/Xatom.h> |
26 |
|
|
27 |
< |
#undef NOPROTO |
31 |
< |
#define NOPROTO 1 |
27 |
> |
#include "color.h" |
28 |
|
#include "tonemap.h" |
29 |
|
#include "view.h" |
30 |
|
#include "x11raster.h" |
31 |
|
#include "random.h" |
36 |
– |
#include "resolu.h" |
32 |
|
|
38 |
– |
#ifndef int4 |
39 |
– |
#define int4 int /* most int's are 32-bit */ |
40 |
– |
#endif |
41 |
– |
|
33 |
|
#define FONTNAME "8x13" /* text font we'll use */ |
34 |
|
|
35 |
|
#define CTRL(c) ((c)-'@') |
38 |
|
|
39 |
|
#define ICONSIZ (8*10) /* maximum icon dimension (even 8) */ |
40 |
|
|
41 |
+ |
#define FIXWEIGHT 20 /* weight to add for fixation points */ |
42 |
+ |
|
43 |
|
#define ourscreen DefaultScreen(thedisplay) |
44 |
|
#define ourroot RootWindow(thedisplay,ourscreen) |
45 |
|
|
71 |
|
char *tout = "od"; /* output of 't' command */ |
72 |
|
int tinterv = 0; /* interval between mouse reports */ |
73 |
|
|
74 |
< |
int tmflags = -1; /* tone mapping flags (-1 for none) */ |
74 |
> |
int tmflags = TM_F_LINEAR; /* tone mapping flags */ |
75 |
|
|
76 |
|
VIEW ourview = STDVIEW; /* image view parameters */ |
77 |
|
int gotview = 0; /* got parameters from file */ |
85 |
|
int xmax, ymax; /* picture dimensions */ |
86 |
|
int width, height; /* window size */ |
87 |
|
char *fname = NULL; /* input file name */ |
88 |
< |
FILE *fin = stdin; /* input file */ |
88 |
> |
FILE *fin = NULL; /* input file */ |
89 |
|
long *scanpos = NULL; /* scan line positions in file */ |
90 |
|
int cury = 0; /* current scan location */ |
91 |
|
|
103 |
|
|
104 |
|
struct { |
105 |
|
int xmin, ymin, xsiz, ysiz; |
106 |
< |
} box = {0, 0, 0, 0}; /* current box */ |
106 |
> |
} bbox = {0, 0, 0, 0}; /* current bbox */ |
107 |
|
|
108 |
|
char *geometry = NULL; /* geometry specification */ |
109 |
|
|
137 |
|
int pid; |
138 |
|
|
139 |
|
progname = argv[0]; |
140 |
+ |
fin = stdin; |
141 |
|
|
142 |
|
for (i = 1; i < argc; i++) |
143 |
|
if (argv[i][0] == '-') |
172 |
|
break; |
173 |
|
case 'e': /* exposure comp. */ |
174 |
|
i++; |
175 |
< |
if (!strcmp(argv[i], "auto")) { |
175 |
> |
if (argv[i][0] == 'a') { |
176 |
|
tmflags = TM_F_CAMERA; |
177 |
|
break; |
178 |
|
} |
179 |
< |
if (!strcmp(argv[i], "human")) { |
179 |
> |
if (argv[i][0] == 'h') { |
180 |
|
tmflags = TM_F_HUMAN; |
181 |
|
break; |
182 |
|
} |
245 |
|
} |
246 |
|
|
247 |
|
|
248 |
+ |
int |
249 |
|
headline(s) /* get relevant info from header */ |
250 |
|
char *s; |
251 |
|
{ |
257 |
|
wrongformat = strcmp(fmt, COLRFMT); |
258 |
|
else if (isview(s) && sscanview(&ourview, s) > 0) |
259 |
|
gotview++; |
260 |
+ |
return(0); |
261 |
|
} |
262 |
|
|
263 |
|
|
413 |
|
return(-1); |
414 |
|
if (v1->depth == 32 && v2->depth == 24) |
415 |
|
return(1); |
416 |
< |
return(0); |
416 |
> |
/* go for maximum depth otherwise */ |
417 |
> |
return(v2->depth - v1->depth); |
418 |
|
} |
419 |
|
/* don't be too greedy */ |
420 |
|
if (maxcolors <= 1<<v1->depth && maxcolors <= 1<<v2->depth) |
421 |
|
return(v1->depth - v2->depth); |
422 |
|
return(v2->depth - v1->depth); |
423 |
|
} |
424 |
< |
/* prefer Pseudo when < 24-bit */ |
424 |
> |
/* prefer Pseudo when < 15-bit */ |
425 |
|
if ((v1->class == TrueColor || v1->class == DirectColor) && |
426 |
< |
v1->depth < 24) |
426 |
> |
v1->depth < 15) |
427 |
|
bad1 = 1; |
428 |
|
if ((v2->class == TrueColor || v2->class == DirectColor) && |
429 |
< |
v2->depth < 24) |
429 |
> |
v2->depth < 15) |
430 |
|
bad2 = -1; |
431 |
|
if (bad1 | bad2) |
432 |
|
return(bad1+bad2); |
537 |
|
goto fail; |
538 |
|
getmono(); |
539 |
|
} else if (ourvis.class == TrueColor | ourvis.class == DirectColor) { |
540 |
< |
ourdata = (unsigned char *)malloc(sizeof(int4)*xmax*ymax); |
540 |
> |
int datsiz = ourvis.depth>16 ? sizeof(int4) : sizeof(int2); |
541 |
> |
ourdata = (unsigned char *)malloc(datsiz*xmax*ymax); |
542 |
|
if (ourdata == NULL) |
543 |
|
goto fail; |
544 |
< |
ourras = make_raster(thedisplay, &ourvis, sizeof(int4)*8, |
545 |
< |
ourdata, xmax, ymax, 32); |
544 |
> |
ourras = make_raster(thedisplay, &ourvis, datsiz*8, |
545 |
> |
ourdata, xmax, ymax, datsiz*8); |
546 |
|
if (ourras == NULL) |
547 |
|
goto fail; |
548 |
|
getfull(); |
625 |
|
traceray(xpos, ypos) /* print requested pixel data */ |
626 |
|
int xpos, ypos; |
627 |
|
{ |
630 |
– |
extern char *index(); |
628 |
|
FLOAT hv[2]; |
629 |
|
FVECT rorg, rdir; |
630 |
|
COLOR cval; |
631 |
|
register char *cp; |
632 |
|
|
633 |
< |
box.xmin = xpos; box.xsiz = 1; |
634 |
< |
box.ymin = ypos; box.ysiz = 1; |
633 |
> |
bbox.xmin = xpos; bbox.xsiz = 1; |
634 |
> |
bbox.ymin = ypos; bbox.ysiz = 1; |
635 |
|
avgbox(cval); |
636 |
|
scalecolor(cval, 1./exposure); |
637 |
|
pix2loc(hv, &inpres, xpos-xoff, ypos-yoff); |
688 |
|
case '\r': |
689 |
|
case 'l': |
690 |
|
case 'c': /* value */ |
691 |
< |
if (avgbox(cval) == -1) |
691 |
> |
if (!avgbox(cval)) |
692 |
|
return(-1); |
693 |
|
switch (com) { |
694 |
|
case '\n': |
696 |
|
sprintf(buf, "%.3f", intens(cval)/exposure); |
697 |
|
break; |
698 |
|
case 'l': /* luminance */ |
699 |
< |
sprintf(buf, "%.0fL", luminance(cval)/exposure); |
699 |
> |
sprintf(buf, "%.1fL", luminance(cval)/exposure); |
700 |
|
break; |
701 |
|
case 'c': /* color */ |
702 |
|
comp = pow(2.0, (double)scale); |
707 |
|
break; |
708 |
|
} |
709 |
|
XDrawImageString(thedisplay, wind, ourgc, |
710 |
< |
box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); |
710 |
> |
bbox.xmin, bbox.ymin+bbox.ysiz, buf, strlen(buf)); |
711 |
|
return(0); |
712 |
|
case 'i': /* identify (contour) */ |
713 |
|
if (ourras->pixels == NULL) |
730 |
|
return(0); |
731 |
|
case 't': /* trace */ |
732 |
|
return(traceray(ekey->x, ekey->y)); |
733 |
+ |
case 'a': /* auto exposure */ |
734 |
+ |
if (fname == NULL) |
735 |
+ |
return(-1); |
736 |
+ |
tmflags = TM_F_CAMERA; |
737 |
+ |
strcpy(buf, "auto exposure..."); |
738 |
+ |
goto remap; |
739 |
+ |
case 'h': /* human response */ |
740 |
+ |
if (fname == NULL) |
741 |
+ |
return(-1); |
742 |
+ |
tmflags = TM_F_HUMAN; |
743 |
+ |
strcpy(buf, "human exposure..."); |
744 |
+ |
goto remap; |
745 |
|
case '=': /* adjust exposure */ |
746 |
|
case '@': /* adaptation level */ |
747 |
< |
if (avgbox(cval) == -1) |
747 |
> |
if (!avgbox(cval)) |
748 |
|
return(-1); |
749 |
|
comp = bright(cval); |
750 |
|
if (comp < 1e-20) { |
758 |
|
comp = .5/comp; |
759 |
|
comp = log(comp)/.69315 - scale; |
760 |
|
n = comp < 0 ? comp-.5 : comp+.5 ; /* round */ |
761 |
< |
if (tmflags != -1) |
762 |
< |
tmflags = -1; /* turn off tone mapping */ |
761 |
> |
if (tmflags != TM_F_LINEAR) |
762 |
> |
tmflags = TM_F_LINEAR; /* turn off tone mapping */ |
763 |
|
else { |
764 |
|
if (n == 0) /* else check if any change */ |
765 |
|
return(0); |
767 |
|
} |
768 |
|
scale += n; |
769 |
|
sprintf(buf, "%+d", scale); |
770 |
+ |
remap: |
771 |
|
XDrawImageString(thedisplay, wind, ourgc, |
772 |
< |
box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); |
772 |
> |
bbox.xmin, bbox.ymin+bbox.ysiz, buf, strlen(buf)); |
773 |
|
XFlush(thedisplay); |
774 |
< |
free(ourdata); |
774 |
> |
/* free(ourdata); This is done in XDestroyImage()! */ |
775 |
|
free_raster(ourras); |
776 |
|
getras(); |
777 |
|
/* fall through */ |
800 |
|
redraw(0, 0, width, height); |
801 |
|
return(0); |
802 |
|
case ' ': /* clear */ |
803 |
< |
redraw(box.xmin, box.ymin, box.xsiz, box.ysiz); |
803 |
> |
redraw(bbox.xmin, bbox.ymin, bbox.xsiz, bbox.ysiz); |
804 |
|
return(0); |
805 |
|
default: |
806 |
|
XBell(thedisplay, 0); |
834 |
|
} |
835 |
|
|
836 |
|
|
837 |
< |
getbox(ebut) /* get new box */ |
837 |
> |
getbox(ebut) /* get new bbox */ |
838 |
|
XButtonPressedEvent *ebut; |
839 |
|
{ |
840 |
|
XEvent e; |
841 |
|
|
842 |
|
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e); |
843 |
|
while (e.type == MotionNotify) { |
844 |
< |
revbox(ebut->x, ebut->y, box.xmin = e.xmotion.x, box.ymin = e.xmotion.y); |
844 |
> |
revbox(ebut->x, ebut->y, bbox.xmin = e.xmotion.x, bbox.ymin = e.xmotion.y); |
845 |
|
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e); |
846 |
< |
revbox(ebut->x, ebut->y, box.xmin, box.ymin); |
846 |
> |
revbox(ebut->x, ebut->y, bbox.xmin, bbox.ymin); |
847 |
|
} |
848 |
< |
box.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x); |
849 |
< |
box.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y); |
850 |
< |
if (box.xmin > ebut->x) { |
851 |
< |
box.xsiz = box.xmin - ebut->x + 1; |
852 |
< |
box.xmin = ebut->x; |
848 |
> |
bbox.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x); |
849 |
> |
bbox.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y); |
850 |
> |
if (bbox.xmin > ebut->x) { |
851 |
> |
bbox.xsiz = bbox.xmin - ebut->x + 1; |
852 |
> |
bbox.xmin = ebut->x; |
853 |
|
} else { |
854 |
< |
box.xsiz = ebut->x - box.xmin + 1; |
854 |
> |
bbox.xsiz = ebut->x - bbox.xmin + 1; |
855 |
|
} |
856 |
< |
if (box.ymin > ebut->y) { |
857 |
< |
box.ysiz = box.ymin - ebut->y + 1; |
858 |
< |
box.ymin = ebut->y; |
856 |
> |
if (bbox.ymin > ebut->y) { |
857 |
> |
bbox.ysiz = bbox.ymin - ebut->y + 1; |
858 |
> |
bbox.ymin = ebut->y; |
859 |
|
} else { |
860 |
< |
box.ysiz = ebut->y - box.ymin + 1; |
860 |
> |
bbox.ysiz = ebut->y - bbox.ymin + 1; |
861 |
|
} |
862 |
|
} |
863 |
|
|
881 |
|
} |
882 |
|
|
883 |
|
|
884 |
< |
revbox(x0, y0, x1, y1) /* draw box with reversed lines */ |
884 |
> |
revbox(x0, y0, x1, y1) /* draw bbox with reversed lines */ |
885 |
|
int x0, y0, x1, y1; |
886 |
|
{ |
887 |
|
revline(x0, y0, x1, y0); |
891 |
|
} |
892 |
|
|
893 |
|
|
894 |
< |
avgbox(clr) /* average color over current box */ |
895 |
< |
COLOR clr; |
894 |
> |
int |
895 |
> |
colavg(scn, n, cavg) |
896 |
> |
register COLR *scn; |
897 |
> |
register int n; |
898 |
> |
COLOR cavg; |
899 |
|
{ |
900 |
< |
static COLOR lc; |
901 |
< |
static int ll, lr, lt, lb; |
900 |
> |
COLOR col; |
901 |
> |
|
902 |
> |
while (n--) { |
903 |
> |
colr_color(col, *scn++); |
904 |
> |
addcolor(cavg, col); |
905 |
> |
} |
906 |
> |
} |
907 |
> |
|
908 |
> |
|
909 |
> |
int |
910 |
> |
avgbox(cavg) /* average color over current bbox */ |
911 |
> |
COLOR cavg; |
912 |
> |
{ |
913 |
> |
double d; |
914 |
> |
register int rval; |
915 |
> |
|
916 |
> |
setcolor(cavg, 0., 0., 0.); |
917 |
> |
rval = dobox(colavg, (char *)cavg); |
918 |
> |
if (rval > 0) { |
919 |
> |
d = 1./rval; |
920 |
> |
scalecolor(cavg, d); |
921 |
> |
} |
922 |
> |
return(rval); |
923 |
> |
} |
924 |
> |
|
925 |
> |
|
926 |
> |
int |
927 |
> |
dobox(f, p) /* run function over bbox */ |
928 |
> |
int (*f)(); /* function to call for each subscan */ |
929 |
> |
char *p; /* pointer to private data */ |
930 |
> |
{ |
931 |
|
int left, right, top, bottom; |
932 |
|
int y; |
891 |
– |
double d; |
892 |
– |
COLOR ctmp; |
893 |
– |
register int x; |
933 |
|
|
934 |
< |
setcolor(clr, 0.0, 0.0, 0.0); |
935 |
< |
left = box.xmin - xoff; |
897 |
< |
right = left + box.xsiz; |
934 |
> |
left = bbox.xmin - xoff; |
935 |
> |
right = left + bbox.xsiz; |
936 |
|
if (left < 0) |
937 |
|
left = 0; |
938 |
|
if (right > xmax) |
939 |
|
right = xmax; |
940 |
|
if (left >= right) |
941 |
< |
return(-1); |
942 |
< |
top = box.ymin - yoff; |
943 |
< |
bottom = top + box.ysiz; |
941 |
> |
return(0); |
942 |
> |
top = bbox.ymin - yoff; |
943 |
> |
bottom = top + bbox.ysiz; |
944 |
|
if (top < 0) |
945 |
|
top = 0; |
946 |
|
if (bottom > ymax) |
947 |
|
bottom = ymax; |
948 |
|
if (top >= bottom) |
911 |
– |
return(-1); |
912 |
– |
if (left == ll && right == lr && top == lt && bottom == lb) { |
913 |
– |
copycolor(clr, lc); |
949 |
|
return(0); |
915 |
– |
} |
950 |
|
for (y = top; y < bottom; y++) { |
951 |
|
if (getscan(y) == -1) |
952 |
|
return(-1); |
953 |
< |
for (x = left; x < right; x++) { |
920 |
< |
colr_color(ctmp, scanline[x]); |
921 |
< |
addcolor(clr, ctmp); |
922 |
< |
} |
953 |
> |
(*f)(scanline+left, right-left, p); |
954 |
|
} |
955 |
< |
d = 1.0/((right-left)*(bottom-top)); |
925 |
< |
scalecolor(clr, d); |
926 |
< |
ll = left; lr = right; lt = top; lb = bottom; |
927 |
< |
copycolor(lc, clr); |
928 |
< |
return(0); |
955 |
> |
return((right-left)*(bottom-top)); |
956 |
|
} |
957 |
|
|
958 |
|
|
959 |
+ |
int |
960 |
+ |
addfix(scn, n) /* add fixation points to histogram */ |
961 |
+ |
COLR *scn; |
962 |
+ |
int n; |
963 |
+ |
{ |
964 |
+ |
if (tmCvColrs(lscan, TM_NOCHROM, scn, n)) |
965 |
+ |
goto tmerr; |
966 |
+ |
if (tmAddHisto(lscan, n, FIXWEIGHT)) |
967 |
+ |
goto tmerr; |
968 |
+ |
return; |
969 |
+ |
tmerr: |
970 |
+ |
quiterr("tone mapping error"); |
971 |
+ |
} |
972 |
+ |
|
973 |
+ |
|
974 |
|
make_tonemap() /* initialize tone mapping */ |
975 |
|
{ |
976 |
< |
int y; |
976 |
> |
int flags, y; |
977 |
|
|
978 |
< |
if (tmflags != -1 && fname == NULL) { |
978 |
> |
if (tmflags != TM_F_LINEAR && fname == NULL) { |
979 |
|
fprintf(stderr, "%s: cannot adjust tone of standard input\n", |
980 |
|
progname); |
981 |
< |
tmflags = -1; |
981 |
> |
tmflags = TM_F_LINEAR; |
982 |
|
} |
983 |
< |
if (tmflags == -1) { |
983 |
> |
if (tmflags == TM_F_LINEAR) { /* linear with clamping */ |
984 |
|
setcolrcor(pow, 1.0/gamcor); |
985 |
|
return; |
986 |
|
} |
987 |
< |
if (greyscale) |
988 |
< |
tmflags |= TM_F_BW; |
989 |
< |
/* initialize tm library */ |
990 |
< |
if (tmInit(tmflags, stdprims, gamcor) == NULL) |
991 |
< |
goto memerr; |
992 |
< |
if (tmSetSpace(stdprims, WHTEFFICACY/exposure)) |
993 |
< |
goto tmerr; |
952 |
< |
/* allocate encoding buffers */ |
953 |
< |
if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL) |
954 |
< |
goto memerr; |
955 |
< |
if (tmflags & TM_F_BW) { |
956 |
< |
cscan = TM_NOCHROM; |
957 |
< |
if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL) |
987 |
> |
flags = tmflags; /* histogram adjustment */ |
988 |
> |
if (greyscale) flags |= TM_F_BW; |
989 |
> |
if (tmTop != NULL) { /* reuse old histogram if one */ |
990 |
> |
tmDone(tmTop); |
991 |
> |
tmTop->flags = flags; |
992 |
> |
} else { /* else initialize */ |
993 |
> |
if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL) |
994 |
|
goto memerr; |
995 |
< |
} else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax)) == NULL) |
996 |
< |
goto memerr; |
997 |
< |
/* compute picture histogram */ |
998 |
< |
for (y = 0; y < ymax; y++) { |
999 |
< |
getscan(y); |
1000 |
< |
if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax)) |
995 |
> |
if (greyscale) { |
996 |
> |
cscan = TM_NOCHROM; |
997 |
> |
if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL) |
998 |
> |
goto memerr; |
999 |
> |
} else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax)) |
1000 |
> |
== NULL) |
1001 |
> |
goto memerr; |
1002 |
> |
/* initialize tm library */ |
1003 |
> |
if (tmInit(flags, stdprims, gamcor) == NULL) |
1004 |
> |
goto memerr; |
1005 |
> |
if (tmSetSpace(stdprims, WHTEFFICACY/exposure)) |
1006 |
|
goto tmerr; |
1007 |
< |
if (tmAddHisto(lscan, xmax, 1)) |
1008 |
< |
goto tmerr; |
1007 |
> |
/* compute picture histogram */ |
1008 |
> |
for (y = 0; y < ymax; y++) { |
1009 |
> |
getscan(y); |
1010 |
> |
if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax)) |
1011 |
> |
goto tmerr; |
1012 |
> |
if (tmAddHisto(lscan, xmax, 1)) |
1013 |
> |
goto tmerr; |
1014 |
> |
} |
1015 |
|
} |
1016 |
< |
/* compute tone mapping */ |
1016 |
> |
tmDup(); /* add fixations to duplicate map */ |
1017 |
> |
dobox(addfix, NULL); |
1018 |
> |
/* (re)compute tone mapping */ |
1019 |
|
if (tmComputeMapping(gamcor, 0., 0.)) |
1020 |
|
goto tmerr; |
972 |
– |
free((char *)lscan); |
1021 |
|
return; |
1022 |
|
memerr: |
1023 |
|
quiterr("out of memory in make_tonemap"); |
1032 |
|
{ |
1033 |
|
register BYTE *ps; |
1034 |
|
|
1035 |
< |
if (tmflags == -1) { |
1035 |
> |
if (tmflags == TM_F_LINEAR) { |
1036 |
|
if (scale) |
1037 |
|
shiftcolrs(scn, len, scale); |
1038 |
|
colrs_gambs(scn, len); |
1045 |
|
if (tmMapPixels(pscan, lscan, cscan, len)) |
1046 |
|
goto tmerr; |
1047 |
|
ps = pscan; |
1048 |
< |
if (tmflags & TM_F_BW) |
1048 |
> |
if (greyscale) |
1049 |
|
while (len--) { |
1050 |
|
scn[0][RED] = scn[0][GRN] = scn[0][BLU] = *ps++; |
1051 |
|
scn[0][EXP] = COLXS; |
1065 |
|
} |
1066 |
|
|
1067 |
|
|
1020 |
– |
done_tonemap() /* clean up after tone mapping is done */ |
1021 |
– |
{ |
1022 |
– |
if (tmflags == -1 || tmTop == NULL) |
1023 |
– |
return; |
1024 |
– |
tmDone(tmTop); /* clear old mapping */ |
1025 |
– |
free((char *)lscan); /* free memory */ |
1026 |
– |
free((char *)pscan); |
1027 |
– |
} |
1028 |
– |
|
1029 |
– |
|
1068 |
|
getmono() /* get monochrome data */ |
1069 |
|
{ |
1070 |
|
register unsigned char *dp; |
1093 |
|
cerr[x] = err + errp; |
1094 |
|
} |
1095 |
|
} |
1096 |
< |
free((char *)cerr); |
1096 |
> |
free((void *)cerr); |
1097 |
|
} |
1098 |
|
|
1099 |
|
|
1136 |
|
errp = err; |
1137 |
|
ti = x*xmax/iconwidth; |
1138 |
|
copycolr(clr, scan[ti]); |
1139 |
< |
normcolrs(clr, 1, scale); |
1139 |
> |
normcolrs(&clr, 1, scale); |
1140 |
|
err += normbright(clr) + cerr[x]; |
1141 |
|
if (err > 127) |
1142 |
|
err -= 255; |
1153 |
|
{ |
1154 |
|
int y; |
1155 |
|
register unsigned int4 *dp; |
1156 |
+ |
register unsigned int2 *dph; |
1157 |
|
register int x; |
1158 |
|
/* initialize tone mapping */ |
1159 |
|
make_tonemap(); |
1160 |
|
/* read and convert file */ |
1161 |
|
dp = (unsigned int4 *)ourdata; |
1162 |
+ |
dph = (unsigned int2 *)ourdata; |
1163 |
|
for (y = 0; y < ymax; y++) { |
1164 |
|
getscan(y); |
1165 |
|
add2icon(y, scanline); |
1166 |
|
tmap_colrs(scanline, xmax); |
1167 |
< |
if (ourras->image->blue_mask & 1) |
1167 |
> |
switch (ourras->image->blue_mask) { |
1168 |
> |
case 0xff: /* 24-bit RGB */ |
1169 |
|
for (x = 0; x < xmax; x++) |
1170 |
|
*dp++ = (unsigned int4)scanline[x][RED] << 16 | |
1171 |
|
(unsigned int4)scanline[x][GRN] << 8 | |
1172 |
|
(unsigned int4)scanline[x][BLU] ; |
1173 |
< |
else |
1173 |
> |
break; |
1174 |
> |
case 0xff0000: /* 24-bit BGR */ |
1175 |
|
for (x = 0; x < xmax; x++) |
1176 |
|
*dp++ = (unsigned int4)scanline[x][RED] | |
1177 |
|
(unsigned int4)scanline[x][GRN] << 8 | |
1178 |
|
(unsigned int4)scanline[x][BLU] << 16 ; |
1179 |
+ |
break; |
1180 |
+ |
#if 0 |
1181 |
+ |
case 0x1f: /* 15-bit RGB */ |
1182 |
+ |
for (x = 0; x < xmax; x++) |
1183 |
+ |
*dph++ = (scanline[x][RED] << 7 & 0x7c00) | |
1184 |
+ |
(scanline[x][GRN] << 2 & 0x3e0) | |
1185 |
+ |
(unsigned)scanline[x][BLU] >> 3 ; |
1186 |
+ |
break; |
1187 |
+ |
case 0x7c00: /* 15-bit BGR */ |
1188 |
+ |
for (x = 0; x < xmax; x++) |
1189 |
+ |
*dph++ = (unsigned)scanline[x][RED] >> 3 | |
1190 |
+ |
(scanline[x][GRN] << 2 & 0x3e0) | |
1191 |
+ |
(scanline[x][BLU] << 7 & 0x7c00) ; |
1192 |
+ |
break; |
1193 |
+ |
#endif |
1194 |
+ |
default: /* unknown */ |
1195 |
+ |
if (ourvis.depth > 16) |
1196 |
+ |
for (x = 0; x < xmax; x++) { |
1197 |
+ |
*dp = ourras->image->red_mask & |
1198 |
+ |
ourras->image->red_mask*scanline[x][RED]/255; |
1199 |
+ |
*dp |= ourras->image->green_mask & |
1200 |
+ |
ourras->image->green_mask*scanline[x][GRN]/255; |
1201 |
+ |
*dp++ |= ourras->image->blue_mask & |
1202 |
+ |
ourras->image->blue_mask*scanline[x][BLU]/255; |
1203 |
+ |
} |
1204 |
+ |
else |
1205 |
+ |
for (x = 0; x < xmax; x++) { |
1206 |
+ |
*dph = ourras->image->red_mask & |
1207 |
+ |
ourras->image->red_mask*scanline[x][RED]/255; |
1208 |
+ |
*dph |= ourras->image->green_mask & |
1209 |
+ |
ourras->image->green_mask*scanline[x][GRN]/255; |
1210 |
+ |
*dph++ |= ourras->image->blue_mask & |
1211 |
+ |
ourras->image->blue_mask*scanline[x][BLU]/255; |
1212 |
+ |
} |
1213 |
+ |
break; |
1214 |
+ |
} |
1215 |
|
} |
1138 |
– |
done_tonemap(); |
1216 |
|
} |
1217 |
|
|
1218 |
|
|
1240 |
|
for (x = 0; x < maxcolors; x++) |
1241 |
|
clrtab[x][RED] = clrtab[x][GRN] = |
1242 |
|
clrtab[x][BLU] = ((int4)x*256 + 128)/maxcolors; |
1166 |
– |
done_tonemap(); |
1243 |
|
} |
1244 |
|
|
1245 |
|
|
1272 |
|
else |
1273 |
|
map_colrs(ourdata+y*xmax, scanline, xmax); |
1274 |
|
} |
1199 |
– |
done_tonemap(); |
1275 |
|
} |
1276 |
|
|
1277 |
|
|