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)) |
964 |
< |
goto tmerr; |
965 |
< |
/* allocate encoding buffers */ |
966 |
< |
if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL) |
967 |
< |
goto memerr; |
968 |
< |
if (tmflags & TM_F_BW) { |
969 |
< |
cscan = TM_NOCHROM; |
970 |
< |
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; |
985 |
– |
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 |
|
|
1033 |
– |
done_tonemap() /* clean up after tone mapping is done */ |
1034 |
– |
{ |
1035 |
– |
if (tmflags == -1 || tmTop == NULL) |
1036 |
– |
return; |
1037 |
– |
tmDone(tmTop); /* clear old mapping */ |
1038 |
– |
free((char *)lscan); /* free memory */ |
1039 |
– |
free((char *)pscan); |
1040 |
– |
} |
1041 |
– |
|
1042 |
– |
|
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 |
|
} |
1151 |
– |
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; |
1179 |
– |
done_tonemap(); |
1171 |
|
} |
1172 |
|
|
1173 |
|
|
1200 |
|
else |
1201 |
|
map_colrs(ourdata+y*xmax, scanline, xmax); |
1202 |
|
} |
1212 |
– |
done_tonemap(); |
1203 |
|
} |
1204 |
|
|
1205 |
|
|