| 27 |
|
#include <X11/Xutil.h> |
| 28 |
|
#include <X11/Xatom.h> |
| 29 |
|
|
| 30 |
+ |
#undef NOPROTO |
| 31 |
+ |
#define NOPROTO 1 |
| 32 |
|
#include "tonemap.h" |
| 33 |
|
#include "view.h" |
| 34 |
|
#include "x11raster.h" |
| 178 |
|
break; |
| 179 |
|
case 'e': /* exposure comp. */ |
| 180 |
|
i++; |
| 181 |
< |
if (!strcmp(argv[i], "auto")) { |
| 181 |
> |
if (argv[i][0] == 'a') { |
| 182 |
|
tmflags = TM_F_CAMERA; |
| 183 |
|
break; |
| 184 |
|
} |
| 185 |
< |
if (!strcmp(argv[i], "human")) { |
| 185 |
> |
if (argv[i][0] == 'h') { |
| 186 |
|
tmflags = TM_F_HUMAN; |
| 187 |
|
break; |
| 188 |
|
} |
| 733 |
|
return(0); |
| 734 |
|
case 't': /* trace */ |
| 735 |
|
return(traceray(ekey->x, ekey->y)); |
| 736 |
+ |
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); |
| 745 |
+ |
tmflags = TM_F_HUMAN; |
| 746 |
+ |
strcpy(buf, "human exposure..."); |
| 747 |
+ |
goto remap; |
| 748 |
|
case '=': /* adjust exposure */ |
| 749 |
|
case '@': /* adaptation level */ |
| 750 |
|
if (avgbox(cval) == -1) |
| 770 |
|
} |
| 771 |
|
scale += n; |
| 772 |
|
sprintf(buf, "%+d", scale); |
| 773 |
+ |
remap: |
| 774 |
|
XDrawImageString(thedisplay, wind, ourgc, |
| 775 |
|
box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); |
| 776 |
|
XFlush(thedisplay); |
| 944 |
|
|
| 945 |
|
make_tonemap() /* initialize tone mapping */ |
| 946 |
|
{ |
| 947 |
< |
int y; |
| 947 |
> |
int flags, y; |
| 948 |
|
|
| 949 |
|
if (tmflags != -1 && fname == NULL) { |
| 950 |
|
fprintf(stderr, "%s: cannot adjust tone of standard input\n", |
| 955 |
|
setcolrcor(pow, 1.0/gamcor); |
| 956 |
|
return; |
| 957 |
|
} |
| 958 |
< |
if (greyscale) |
| 959 |
< |
tmflags |= TM_F_BW; |
| 958 |
> |
if (tmTop != NULL) /* already initialized? */ |
| 959 |
> |
return; |
| 960 |
> |
flags = tmflags; |
| 961 |
> |
if (greyscale) flags |= TM_F_BW; |
| 962 |
|
/* initialize tm library */ |
| 963 |
< |
if (tmInit(tmflags, stdprims, gamcor) == NULL) |
| 963 |
> |
if (tmInit(flags, stdprims, gamcor) == NULL) |
| 964 |
|
goto memerr; |
| 965 |
|
if (tmSetSpace(stdprims, WHTEFFICACY/exposure)) |
| 966 |
|
goto tmerr; |
| 967 |
|
/* allocate encoding buffers */ |
| 968 |
|
if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL) |
| 969 |
|
goto memerr; |
| 970 |
< |
if (tmflags & TM_F_BW) { |
| 970 |
> |
if (greyscale) { |
| 971 |
|
cscan = TM_NOCHROM; |
| 972 |
|
if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL) |
| 973 |
|
goto memerr; |
| 984 |
|
/* compute tone mapping */ |
| 985 |
|
if (tmComputeMapping(gamcor, 0., 0.)) |
| 986 |
|
goto tmerr; |
| 970 |
– |
free((char *)lscan); |
| 987 |
|
return; |
| 988 |
|
memerr: |
| 989 |
|
quiterr("out of memory in make_tonemap"); |
| 1011 |
|
if (tmMapPixels(pscan, lscan, cscan, len)) |
| 1012 |
|
goto tmerr; |
| 1013 |
|
ps = pscan; |
| 1014 |
< |
if (tmflags & TM_F_BW) |
| 1014 |
> |
if (greyscale) |
| 1015 |
|
while (len--) { |
| 1016 |
|
scn[0][RED] = scn[0][GRN] = scn[0][BLU] = *ps++; |
| 1017 |
|
scn[0][EXP] = COLXS; |
| 1031 |
|
} |
| 1032 |
|
|
| 1033 |
|
|
| 1018 |
– |
done_tonemap() /* clean up after tone mapping is done */ |
| 1019 |
– |
{ |
| 1020 |
– |
if (tmflags == -1 || tmTop == NULL) |
| 1021 |
– |
return; |
| 1022 |
– |
tmDone(tmTop); /* clear old mapping */ |
| 1023 |
– |
free((char *)lscan); /* free memory */ |
| 1024 |
– |
free((char *)pscan); |
| 1025 |
– |
} |
| 1026 |
– |
|
| 1027 |
– |
|
| 1034 |
|
getmono() /* get monochrome data */ |
| 1035 |
|
{ |
| 1036 |
|
register unsigned char *dp; |
| 1139 |
|
(unsigned int4)scanline[x][GRN] << 8 | |
| 1140 |
|
(unsigned int4)scanline[x][BLU] << 16 ; |
| 1141 |
|
} |
| 1136 |
– |
done_tonemap(); |
| 1142 |
|
} |
| 1143 |
|
|
| 1144 |
|
|
| 1166 |
|
for (x = 0; x < maxcolors; x++) |
| 1167 |
|
clrtab[x][RED] = clrtab[x][GRN] = |
| 1168 |
|
clrtab[x][BLU] = ((int4)x*256 + 128)/maxcolors; |
| 1164 |
– |
done_tonemap(); |
| 1169 |
|
} |
| 1170 |
|
|
| 1171 |
|
|
| 1198 |
|
else |
| 1199 |
|
map_colrs(ourdata+y*xmax, scanline, xmax); |
| 1200 |
|
} |
| 1197 |
– |
done_tonemap(); |
| 1201 |
|
} |
| 1202 |
|
|
| 1203 |
|
|