[libcamera-devel] [PATCH 11/11] ipa: ipu3: tonemapping: Add the documentation for ToneMapping

Laurent Pinchart laurent.pinchart at ideasonboard.com
Tue Sep 14 06:56:08 CEST 2021


Hi Jean-Michel,

Thank you for the patch.

On Mon, Sep 13, 2021 at 04:58:10PM +0200, Jean-Michel Hautbois wrote:
> The Tonemapping algorithm is currently undocumented.

s/Tonemapping/tone mapping/

> Provide an introduction and overview to the implementation as the class
> definition and document how the algorithm operates in the process and
> prepare methods.
> 
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois at ideasonboard.com>
> Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> ---
>  src/ipa/ipu3/algorithms/tone_mapping.cpp | 35 +++++++++++++++++++++++-
>  1 file changed, 34 insertions(+), 1 deletion(-)
> 
> diff --git a/src/ipa/ipu3/algorithms/tone_mapping.cpp b/src/ipa/ipu3/algorithms/tone_mapping.cpp
> index 40337f9d..15e9ab3f 100644
> --- a/src/ipa/ipu3/algorithms/tone_mapping.cpp
> +++ b/src/ipa/ipu3/algorithms/tone_mapping.cpp
> @@ -10,15 +10,40 @@
>  #include <cmath>
>  #include <string.h>
>  
> +/**
> + * \file tone_mapping.h
> + */
> +
>  namespace libcamera {
>  
>  namespace ipa::ipu3::algorithms {
>  
> +/**
> + * \class ToneMapping
> + * \brief A class to handle tone mapping based on gamma
> + *
> + * This algorithm improves the image dynamic using a look-up table which is
> + * generated based on a gamma parameter.
> + *
> + * Gamma values less than one have the effect of compressing the image histogram
> + * while values over 1 will expand it.

I think this is misleading. The standard gamma correction formula is
V_{out} = A V_{in}^\gamma, but we implement inverse gamma. I'm also not
sure that "compressing" or "expanding" the histogram is accurate. 0.0
stays 0.0 and 1.0 stays 1.0, so the histogram is not really stretched when
"expanding". Saying that it provides better overall contrast in that
case doesn't seem accurate to me.

> + *
> + * Expanding the histogram has the effect of providing better overall contrast.
> + */
> +
>  ToneMapping::ToneMapping()
>  	: gamma_(1.0)
>  {
>  }
>  
> +/**
> + * \brief Fill in the parameter structure, and enable gamma control
> + * \param context The shared IPA context
> + * \param params The IPU3 parameters
> + *
> + * Populate the IPU3 parameter structure with our gamma correction table, and
> + * enable the gamma control module in the accelerator cluster.

Same comment as in other patches about accelerator cluster.

> + */
>  void ToneMapping::prepare([[maybe_unused]] IPAContext &context,
>  			  ipu3_uapi_params *params)
>  {
> @@ -33,7 +58,15 @@ void ToneMapping::prepare([[maybe_unused]] IPAContext &context,
>  	params->acc_param.gamma.gc_ctrl.enable = 1;
>  }
>  
> -void ToneMapping::process([[maybe_unused]] IPAContext &context,
> +/**
> + * \brief Calculate the Gamma curve

"Calculate the tone mapping look up table"

We should consider the algorithm as handling tone mapping, with the
current implementation using a fixed inverse gamma function (the
decision to name the corresponding ImgU data structure gamma is a bit
unfortunate as it's misleading). I'd update the rest of the
documentation accordingly.

> + * \param context The shared IPA context
> + * \param stats The IPU3 statistics and ISP results
> + *
> + * The gamma correction look up table is generated as an inverse power curve
> + * from our gamma setting.
> + */
> +void ToneMapping::process(IPAContext &context,
>  			  [[maybe_unused]] const ipu3_uapi_stats_3a *stats)
>  {
>  	/*

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list