95 |
|
TMstruct *tms, |
96 |
|
RGBPRIMP pri, |
97 |
|
double sf, |
98 |
< |
MEM_PTR dat |
98 |
> |
void *dat |
99 |
|
) |
100 |
|
{ |
101 |
|
static const char funcName[] = "tmSetSpace"; |
160 |
|
if (tms == NULL || tms->histo == NULL) |
161 |
|
return; |
162 |
|
free(tms->histo); |
163 |
+ |
tms->hbrmin = 10; tms->hbrmax = -10; |
164 |
|
tms->histo = NULL; |
165 |
|
} |
166 |
|
|
321 |
|
cmon[BLU] += d; |
322 |
|
} |
323 |
|
} else if (tms->flags & TM_F_BW) { |
324 |
< |
cmon[RED] = cmon[GRN] = cmon[BLU] = lum; |
324 |
> |
int j = 3; |
325 |
> |
while (j--) cs[3*i+j] = tms->cdiv[j]/(TM_BRES>>8); |
326 |
> |
continue; |
327 |
|
} |
328 |
|
d = tms->clf[RED]*cmon[RED]/lum; |
329 |
|
cs[3*i ] = d>=.999f ? 255 : gamtab[(int)(1024.f*d)]; |
346 |
|
{ |
347 |
|
static const char funcName[] = "tmAddHisto"; |
348 |
|
int oldorig=0, oldlen, horig, hlen; |
349 |
< |
int i, j; |
349 |
> |
int i; |
350 |
|
|
351 |
|
if (tms == NULL) |
352 |
|
returnErr(TM_E_TMINVAL); |
367 |
|
oldlen = HISTI(tms->hbrmax) + 1 - oldorig; |
368 |
|
} |
369 |
|
for (i = len; i--; ) { |
370 |
< |
if ((j = ls[i]) < MINBRT) |
370 |
> |
if (ls[i] < MINBRT) |
371 |
|
continue; |
372 |
< |
if (j < tms->hbrmin) |
373 |
< |
tms->hbrmin = j; |
374 |
< |
else if (j > tms->hbrmax) |
375 |
< |
tms->hbrmax = j; |
372 |
> |
if (ls[i] < tms->hbrmin) |
373 |
> |
tms->hbrmin = ls[i]; |
374 |
> |
else if (ls[i] > tms->hbrmax) |
375 |
> |
tms->hbrmax = ls[i]; |
376 |
|
} |
377 |
|
horig = HISTI(tms->hbrmin); |
378 |
|
hlen = HISTI(tms->hbrmax) + 1 - horig; |
493 |
|
} |
494 |
|
if (!histot) |
495 |
|
returnErr(TM_E_TMFAIL); |
496 |
< |
threshold = histot/40 + 1; |
496 |
> |
threshold = histot/500 + 1; |
497 |
|
Lwavg = tmLuminance( (double)sum / histot ); |
498 |
|
/* use linear tone mapping? */ |
499 |
< |
if (tms->flags & TM_F_LINEAR || threshold < 4 || |
499 |
> |
if (tms->flags & TM_F_LINEAR || |
500 |
|
tms->hbrmax - tms->hbrmin < TM_BRTSCALE*logLddyn) |
501 |
|
goto linearmap; |
502 |
|
/* clamp histogram */ |