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; |
985 |
– |
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 |
|
|
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 |
– |
|
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 |
|
} |
1151 |
– |
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; |
1179 |
– |
done_tonemap(); |
1169 |
|
} |
1170 |
|
|
1171 |
|
|
1198 |
|
else |
1199 |
|
map_colrs(ourdata+y*xmax, scanline, xmax); |
1200 |
|
} |
1212 |
– |
done_tonemap(); |
1201 |
|
} |
1202 |
|
|
1203 |
|
|