1 |
< |
/* Copyright (c) 1997 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
4 |
> |
static char SCCSid[] = "$SunId$ SGI"; |
5 |
|
#endif |
6 |
|
|
7 |
|
/* |
47 |
|
|
48 |
|
#define ICONSIZ (8*10) /* maximum icon dimension (even 8) */ |
49 |
|
|
50 |
+ |
#define FIXWEIGHT 20 /* weight to add for fixation points */ |
51 |
+ |
|
52 |
|
#define ourscreen DefaultScreen(thedisplay) |
53 |
|
#define ourroot RootWindow(thedisplay,ourscreen) |
54 |
|
|
80 |
|
char *tout = "od"; /* output of 't' command */ |
81 |
|
int tinterv = 0; /* interval between mouse reports */ |
82 |
|
|
83 |
< |
int tmflags = -1; /* tone mapping flags (-1 for none) */ |
83 |
> |
int tmflags = TM_F_LINEAR; /* tone mapping flags */ |
84 |
|
|
85 |
|
VIEW ourview = STDVIEW; /* image view parameters */ |
86 |
|
int gotview = 0; /* got parameters from file */ |
693 |
|
case '\r': |
694 |
|
case 'l': |
695 |
|
case 'c': /* value */ |
696 |
< |
if (avgbox(cval) == -1) |
696 |
> |
if (!avgbox(cval)) |
697 |
|
return(-1); |
698 |
|
switch (com) { |
699 |
|
case '\n': |
736 |
|
case 't': /* trace */ |
737 |
|
return(traceray(ekey->x, ekey->y)); |
738 |
|
case 'a': /* auto exposure */ |
737 |
– |
if (tmflags == TM_F_CAMERA) |
738 |
– |
return(0); |
739 |
|
tmflags = TM_F_CAMERA; |
740 |
|
strcpy(buf, "auto exposure..."); |
741 |
|
goto remap; |
742 |
|
case 'h': /* human response */ |
743 |
– |
if (tmflags == TM_F_HUMAN) |
744 |
– |
return(0); |
743 |
|
tmflags = TM_F_HUMAN; |
744 |
|
strcpy(buf, "human exposure..."); |
745 |
|
goto remap; |
746 |
|
case '=': /* adjust exposure */ |
747 |
|
case '@': /* adaptation level */ |
748 |
< |
if (avgbox(cval) == -1) |
748 |
> |
if (!avgbox(cval)) |
749 |
|
return(-1); |
750 |
|
comp = bright(cval); |
751 |
|
if (comp < 1e-20) { |
759 |
|
comp = .5/comp; |
760 |
|
comp = log(comp)/.69315 - scale; |
761 |
|
n = comp < 0 ? comp-.5 : comp+.5 ; /* round */ |
762 |
< |
if (tmflags != -1) |
763 |
< |
tmflags = -1; /* turn off tone mapping */ |
762 |
> |
if (tmflags != TM_F_LINEAR) |
763 |
> |
tmflags = TM_F_LINEAR; /* turn off tone mapping */ |
764 |
|
else { |
765 |
|
if (n == 0) /* else check if any change */ |
766 |
|
return(0); |
892 |
|
} |
893 |
|
|
894 |
|
|
895 |
< |
avgbox(clr) /* average color over current box */ |
896 |
< |
COLOR clr; |
895 |
> |
int |
896 |
> |
colavg(scn, n, cavg) |
897 |
> |
register COLR *scn; |
898 |
> |
register int n; |
899 |
> |
COLOR cavg; |
900 |
|
{ |
901 |
< |
static COLOR lc; |
902 |
< |
static int ll, lr, lt, lb; |
901 |
> |
COLOR col; |
902 |
> |
|
903 |
> |
while (n--) { |
904 |
> |
colr_color(col, scn++); |
905 |
> |
addcolor(cavg, col); |
906 |
> |
} |
907 |
> |
} |
908 |
> |
|
909 |
> |
|
910 |
> |
int |
911 |
> |
avgbox(cavg) /* average color over current box */ |
912 |
> |
COLOR cavg; |
913 |
> |
{ |
914 |
> |
double d; |
915 |
> |
register int rval; |
916 |
> |
|
917 |
> |
setcolor(cavg, 0., 0., 0.); |
918 |
> |
rval = dobox(colavg, (char *)cavg); |
919 |
> |
if (rval > 0) { |
920 |
> |
d = 1./rval; |
921 |
> |
scalecolor(cavg, d); |
922 |
> |
} |
923 |
> |
return(rval); |
924 |
> |
} |
925 |
> |
|
926 |
> |
|
927 |
> |
int |
928 |
> |
dobox(f, p) /* run function over box */ |
929 |
> |
int (*f)(); /* function to call for each subscan */ |
930 |
> |
char *p; /* pointer to private data */ |
931 |
> |
{ |
932 |
|
int left, right, top, bottom; |
933 |
|
int y; |
904 |
– |
double d; |
905 |
– |
COLOR ctmp; |
906 |
– |
register int x; |
934 |
|
|
908 |
– |
setcolor(clr, 0.0, 0.0, 0.0); |
935 |
|
left = box.xmin - xoff; |
936 |
|
right = left + box.xsiz; |
937 |
|
if (left < 0) |
939 |
|
if (right > xmax) |
940 |
|
right = xmax; |
941 |
|
if (left >= right) |
942 |
< |
return(-1); |
942 |
> |
return(0); |
943 |
|
top = box.ymin - yoff; |
944 |
|
bottom = top + box.ysiz; |
945 |
|
if (top < 0) |
947 |
|
if (bottom > ymax) |
948 |
|
bottom = ymax; |
949 |
|
if (top >= bottom) |
924 |
– |
return(-1); |
925 |
– |
if (left == ll && right == lr && top == lt && bottom == lb) { |
926 |
– |
copycolor(clr, lc); |
950 |
|
return(0); |
928 |
– |
} |
951 |
|
for (y = top; y < bottom; y++) { |
952 |
|
if (getscan(y) == -1) |
953 |
|
return(-1); |
954 |
< |
for (x = left; x < right; x++) { |
933 |
< |
colr_color(ctmp, scanline[x]); |
934 |
< |
addcolor(clr, ctmp); |
935 |
< |
} |
954 |
> |
(*f)(scanline+left, right-left, p); |
955 |
|
} |
956 |
< |
d = 1.0/((right-left)*(bottom-top)); |
938 |
< |
scalecolor(clr, d); |
939 |
< |
ll = left; lr = right; lt = top; lb = bottom; |
940 |
< |
copycolor(lc, clr); |
941 |
< |
return(0); |
956 |
> |
return((right-left)*(bottom-top)); |
957 |
|
} |
958 |
|
|
959 |
|
|
960 |
+ |
int |
961 |
+ |
addfix(scn, n) /* add fixation points to histogram */ |
962 |
+ |
COLR *scn; |
963 |
+ |
int n; |
964 |
+ |
{ |
965 |
+ |
if (tmCvColrs(lscan, TM_NOCHROM, scn, n)) |
966 |
+ |
goto tmerr; |
967 |
+ |
if (tmAddHisto(lscan, n, FIXWEIGHT)) |
968 |
+ |
goto tmerr; |
969 |
+ |
return; |
970 |
+ |
tmerr: |
971 |
+ |
quiterr("tone mapping error"); |
972 |
+ |
} |
973 |
+ |
|
974 |
+ |
|
975 |
|
make_tonemap() /* initialize tone mapping */ |
976 |
|
{ |
977 |
|
int flags, y; |
978 |
|
|
979 |
< |
if (tmflags != -1 && fname == NULL) { |
979 |
> |
if (tmflags != TM_F_LINEAR && fname == NULL) { |
980 |
|
fprintf(stderr, "%s: cannot adjust tone of standard input\n", |
981 |
|
progname); |
982 |
< |
tmflags = -1; |
982 |
> |
tmflags = TM_F_LINEAR; |
983 |
|
} |
984 |
< |
if (tmflags == -1) { /* linear with clamping */ |
984 |
> |
if (tmflags == TM_F_LINEAR) { /* linear with clamping */ |
985 |
|
setcolrcor(pow, 1.0/gamcor); |
986 |
|
return; |
987 |
|
} |
988 |
|
flags = tmflags; /* histogram adjustment */ |
989 |
|
if (greyscale) flags |= TM_F_BW; |
990 |
|
if (tmTop != NULL) { /* reuse old histogram if one */ |
991 |
+ |
tmDone(tmTop); |
992 |
|
tmTop->flags = flags; |
993 |
|
} else { /* else initialize */ |
994 |
|
if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL) |
1014 |
|
goto tmerr; |
1015 |
|
} |
1016 |
|
} |
1017 |
+ |
tmDup(); /* add fixations to duplicate map */ |
1018 |
+ |
dobox(addfix, NULL); |
1019 |
|
/* (re)compute tone mapping */ |
1020 |
|
if (tmComputeMapping(gamcor, 0., 0.)) |
1021 |
|
goto tmerr; |
1033 |
|
{ |
1034 |
|
register BYTE *ps; |
1035 |
|
|
1036 |
< |
if (tmflags == -1) { |
1036 |
> |
if (tmflags == TM_F_LINEAR) { |
1037 |
|
if (scale) |
1038 |
|
shiftcolrs(scn, len, scale); |
1039 |
|
colrs_gambs(scn, len); |