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 (tmTop != NULL) /* already initialized? */ |
959 |
< |
return; |
960 |
< |
flags = tmflags; |
958 |
> |
flags = tmflags; /* histogram adjustment */ |
959 |
|
if (greyscale) flags |= TM_F_BW; |
960 |
< |
/* initialize tm library */ |
961 |
< |
if (tmInit(flags, stdprims, gamcor) == NULL) |
962 |
< |
goto memerr; |
963 |
< |
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 (greyscale) { |
971 |
< |
cscan = TM_NOCHROM; |
972 |
< |
if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL) |
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; |
989 |
|
return; |