From 1ad2408718fed275cdc2df659bfff9163f497390 Mon Sep 17 00:00:00 2001 From: "Gregory J. Ward" Date: Wed, 7 Apr 2021 23:12:19 +0000 Subject: [PATCH] perf: improved black crushing behavior for linear mapping --- src/common/tonemap.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/common/tonemap.c b/src/common/tonemap.c index 85c097cd..80acd6ce 100644 --- a/src/common/tonemap.c +++ b/src/common/tonemap.c @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: tonemap.c,v 3.47 2021/04/07 21:13:52 greg Exp $"; +static const char RCSid[] = "$Id: tonemap.c,v 3.48 2021/04/07 23:12:19 greg Exp $"; #endif /* * Tone mapping functions. @@ -439,9 +439,11 @@ double Lddyn for (i = tms->mbrmax-tms->mbrmin+1; i--; ) { double d; d = expmult/tms->inpsf * tmLuminance(tms->mbrmin + i); - if (d <= minD) - break; /* map initialized to zeroes */ - d = (d - minD)/(1. - minD); + if (d >= 2.*minD) + d -= minD; + else /* soft black crushing */ + d *= d/(4.*minD); + d /= 1. - minD; d = TM_BRES*pow(d, 1./gamval); tms->lumap[i] = (d > maxV) ? maxV : (int)d; }