From 06942089b70ac3748a40b2eca4f8df77e44cb17f Mon Sep 17 00:00:00 2001 From: "Gregory J. Ward" Date: Fri, 7 Jan 2022 23:01:01 +0000 Subject: [PATCH] perf: minor performance improvement in grayscale mode to 24-bit output --- src/common/tmap16bit.c | 6 ++++-- src/common/tmapcolrs.c | 6 ++++-- src/common/tonemap.c | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/common/tmap16bit.c b/src/common/tmap16bit.c index 697c75c83..ea155ab95 100644 --- a/src/common/tmap16bit.c +++ b/src/common/tmap16bit.c @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: tmap16bit.c,v 1.10 2011/05/20 02:06:38 greg Exp $"; +static const char RCSid[] = "$Id: tmap16bit.c,v 1.11 2022/01/07 23:01:01 greg Exp $"; #endif /* * Routines for tone-mapping 16-bit/primary pixels @@ -257,7 +257,9 @@ tmCvRGB48(TMstruct *tms, TMbright *ls, uby8 *cs, cmon[BLU] = slum + pf*cmon[BLU]; } } else if (tms->flags & TM_F_BW) { - cmon[RED] = cmon[GRN] = cmon[BLU] = lum; + int j = 3; + while (j--) cs[3*i+j] = tms->cdiv[j]/(TM_BRES>>8); + continue; } bi = (double)MONGAMTSZ*tms->clf[RED]*cmon[RED]/lum; cs[3*i ] = bi>=MONGAMTSZ ? 255 : mongamtab[bi]; diff --git a/src/common/tmapcolrs.c b/src/common/tmapcolrs.c index 6e4219223..36a7d6b91 100644 --- a/src/common/tmapcolrs.c +++ b/src/common/tmapcolrs.c @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: tmapcolrs.c,v 3.35 2020/10/13 00:08:46 greg Exp $"; +static const char RCSid[] = "$Id: tmapcolrs.c,v 3.36 2022/01/07 23:01:01 greg Exp $"; #endif /* * Routines for tone mapping on Radiance RGBE and XYZE pictures. @@ -122,7 +122,9 @@ int len } } } else if (tms->flags & TM_F_BW) { - cmon[RED] = cmon[GRN] = cmon[BLU] = li; + for (j = 3; j--; ) + cs[3*i+j] = tms->cdiv[j]/(TM_BRES>>8); + continue; } else { for (j = 3; j--; ) cmon[j] *= (cmon[j] > 0); diff --git a/src/common/tonemap.c b/src/common/tonemap.c index b3a84eb7d..e74afeda5 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.52 2021/05/26 17:50:26 greg Exp $"; +static const char RCSid[] = "$Id: tonemap.c,v 3.53 2022/01/07 23:01:01 greg Exp $"; #endif /* * Tone mapping functions. @@ -321,7 +321,9 @@ int len cmon[BLU] += d; } } else if (tms->flags & TM_F_BW) { - cmon[RED] = cmon[GRN] = cmon[BLU] = lum; + int j = 3; + while (j--) cs[3*i+j] = tms->cdiv[j]/(TM_BRES>>8); + continue; } d = tms->clf[RED]*cmon[RED]/lum; cs[3*i ] = d>=.999f ? 255 : gamtab[(int)(1024.f*d)];