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", |
951 |
|
progname); |
952 |
|
tmflags = -1; |
953 |
|
} |
954 |
< |
if (tmflags == -1) { |
954 |
> |
if (tmflags == -1) { /* linear with clamping */ |
955 |
|
setcolrcor(pow, 1.0/gamcor); |
956 |
|
return; |
957 |
|
} |
958 |
< |
if (greyscale) |
959 |
< |
tmflags |= TM_F_BW; |
960 |
< |
/* initialize tm library */ |
961 |
< |
if (tmInit(tmflags, stdprims, gamcor) == NULL) |
962 |
< |
goto memerr; |
963 |
< |
if (tmSetSpace(stdprims, WHTEFFICACY/exposure)) |
951 |
< |
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) |
958 |
> |
flags = tmflags; /* histogram adjustment */ |
959 |
> |
if (greyscale) flags |= TM_F_BW; |
960 |
> |
if (tmTop != NULL) { /* reuse old histogram if one */ |
961 |
> |
tmTop->flags = flags; |
962 |
> |
} else { /* else initialize */ |
963 |
> |
if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL) |
964 |
|
goto memerr; |
965 |
< |
} else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax)) == NULL) |
966 |
< |
goto memerr; |
967 |
< |
/* compute picture histogram */ |
968 |
< |
for (y = 0; y < ymax; y++) { |
969 |
< |
getscan(y); |
970 |
< |
if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax)) |
965 |
> |
if (greyscale) { |
966 |
> |
cscan = TM_NOCHROM; |
967 |
> |
if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL) |
968 |
> |
goto memerr; |
969 |
> |
} else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax)) |
970 |
> |
== NULL) |
971 |
> |
goto memerr; |
972 |
> |
/* initialize tm library */ |
973 |
> |
if (tmInit(flags, stdprims, gamcor) == NULL) |
974 |
> |
goto memerr; |
975 |
> |
if (tmSetSpace(stdprims, WHTEFFICACY/exposure)) |
976 |
|
goto tmerr; |
977 |
< |
if (tmAddHisto(lscan, xmax, 1)) |
978 |
< |
goto tmerr; |
977 |
> |
/* compute picture histogram */ |
978 |
> |
for (y = 0; y < ymax; y++) { |
979 |
> |
getscan(y); |
980 |
> |
if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax)) |
981 |
> |
goto tmerr; |
982 |
> |
if (tmAddHisto(lscan, xmax, 1)) |
983 |
> |
goto tmerr; |
984 |
> |
} |
985 |
|
} |
986 |
< |
/* compute tone mapping */ |
986 |
> |
/* (re)compute tone mapping */ |
987 |
|
if (tmComputeMapping(gamcor, 0., 0.)) |
988 |
|
goto tmerr; |
972 |
– |
free((char *)lscan); |
989 |
|
return; |
990 |
|
memerr: |
991 |
|
quiterr("out of memory in make_tonemap"); |
1013 |
|
if (tmMapPixels(pscan, lscan, cscan, len)) |
1014 |
|
goto tmerr; |
1015 |
|
ps = pscan; |
1016 |
< |
if (tmflags & TM_F_BW) |
1016 |
> |
if (greyscale) |
1017 |
|
while (len--) { |
1018 |
|
scn[0][RED] = scn[0][GRN] = scn[0][BLU] = *ps++; |
1019 |
|
scn[0][EXP] = COLXS; |
1033 |
|
} |
1034 |
|
|
1035 |
|
|
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 |
– |
|
1036 |
|
getmono() /* get monochrome data */ |
1037 |
|
{ |
1038 |
|
register unsigned char *dp; |
1141 |
|
(unsigned int4)scanline[x][GRN] << 8 | |
1142 |
|
(unsigned int4)scanline[x][BLU] << 16 ; |
1143 |
|
} |
1138 |
– |
done_tonemap(); |
1144 |
|
} |
1145 |
|
|
1146 |
|
|
1168 |
|
for (x = 0; x < maxcolors; x++) |
1169 |
|
clrtab[x][RED] = clrtab[x][GRN] = |
1170 |
|
clrtab[x][BLU] = ((int4)x*256 + 128)/maxcolors; |
1166 |
– |
done_tonemap(); |
1171 |
|
} |
1172 |
|
|
1173 |
|
|
1200 |
|
else |
1201 |
|
map_colrs(ourdata+y*xmax, scanline, xmax); |
1202 |
|
} |
1199 |
– |
done_tonemap(); |
1203 |
|
} |
1204 |
|
|
1205 |
|
|