[07/13] ipa: simple: Add lux algorithm to the SoftIPA
diff mbox series

Message ID 20260407-kbingham-awb-split-v1-7-a39af3f4dc20@ideasonboard.com
State Changes Requested
Headers show
Series
  • ipa: simple: Convert to libipa AWB implementation
Related show

Commit Message

Kieran Bingham April 7, 2026, 10:01 p.m. UTC
Utilise the lux component of libipa to map in the lux estimate
process using the yHistgram of the Soft ISP statistics.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/ipa/simple/algorithms/lux.cpp     | 93 +++++++++++++++++++++++++++++++++++
 src/ipa/simple/algorithms/lux.h       | 39 +++++++++++++++
 src/ipa/simple/algorithms/meson.build |  1 +
 src/ipa/simple/ipa_context.h          |  5 ++
 4 files changed, 138 insertions(+)

Comments

Milan Zamazal April 8, 2026, 2:12 p.m. UTC | #1
Hi Kieran,

Kieran Bingham <kieran.bingham@ideasonboard.com> writes:

> Utilise the lux component of libipa to map in the lux estimate
> process using the yHistgram of the Soft ISP statistics.

s/yHistgram/yHistogram/

I suppose the algorithm is supposed to be enabled manually, in case the
corresponding tuning data is available?  It would be worth to explain
its purpose and use here.

> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  src/ipa/simple/algorithms/lux.cpp     | 93 +++++++++++++++++++++++++++++++++++
>  src/ipa/simple/algorithms/lux.h       | 39 +++++++++++++++
>  src/ipa/simple/algorithms/meson.build |  1 +
>  src/ipa/simple/ipa_context.h          |  5 ++
>  4 files changed, 138 insertions(+)
>
> diff --git a/src/ipa/simple/algorithms/lux.cpp b/src/ipa/simple/algorithms/lux.cpp
> new file mode 100644
> index 0000000000000000000000000000000000000000..03b44ac584ae141509e79954159272504cdba17d
> --- /dev/null
> +++ b/src/ipa/simple/algorithms/lux.cpp
> @@ -0,0 +1,93 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2024, Ideas On Board
> + *
> + * Simple Lux control
> + */
> +
> +#include "lux.h"
> +
> +#include <libcamera/base/log.h>
> +
> +#include <libcamera/control_ids.h>
> +
> +#include "libipa/histogram.h"
> +#include "libipa/lux.h"
> +
> +/**
> + * \file lux.h
> + */
> +
> +namespace libcamera {
> +
> +namespace ipa::soft::algorithms {
> +
> +/**
> + * \class Lux
> + * \brief SoftISP Lux control
> + *
> + * The Lux algorithm is responsible for estimating the lux level of the image.
> + * It doesn't take or generate any controls, but it provides a lux level for
> + * other algorithms (such as AGC) to use.
> + */
> +
> +/**
> + * \brief Construct a SoftISP Lux algo module
> + */
> +Lux::Lux()
> +{
> +}
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::init
> + */
> +int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)
> +{
> +	return lux_.parseTuningData(tuningData);
> +}
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::prepare
> + */
> +void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,
> +		  IPAFrameContext &frameContext,
> +		  [[maybe_unused]] DebayerParams *params)
> +{
> +	frameContext.lux.lux = context.activeState.lux.lux;
> +}
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::process
> + */
> +void Lux::process(IPAContext &context,
> +		  [[maybe_unused]] const uint32_t frame,
> +		  IPAFrameContext &frameContext,
> +		  const SwIspStats *stats,
> +		  ControlList &metadata)
> +{
> +	/*
> +	 * Report the lux level used by algorithms to prepare this frame
> +	 * not the lux level *of* this frame.
> +	 */
> +	metadata.set(controls::Lux, frameContext.lux.lux);

Should this be reported before the lux value is determined for the first
time?

> +	if (!stats)
> +		return;
> +
> +	/* Todo: Sensor configuration should move out of AGC */

Todo: -> \todo

The comment is a bit confusing here, it might be better to attach it to
the sensor configuration in AGC.

> +	utils::Duration exposureTime = context.configuration.agc.lineDuration *
> +				       frameContext.sensor.exposure;
> +	double gain = frameContext.sensor.gain;
> +	double digitalGain = 1.0;
> +
> +	Histogram yHist(stats->yHistogram);
> +
> +	context.activeState.lux.lux =
> +		lux_.estimateLux(exposureTime, gain, digitalGain, yHist);
> +}
> +
> +REGISTER_IPA_ALGORITHM(Lux, "Lux")
> +
> +} /* namespace ipa::soft::algorithms */
> +
> +} /* namespace libcamera */
> diff --git a/src/ipa/simple/algorithms/lux.h b/src/ipa/simple/algorithms/lux.h
> new file mode 100644
> index 0000000000000000000000000000000000000000..04ec4c163ede422369977017cca70d12a8d361fb
> --- /dev/null
> +++ b/src/ipa/simple/algorithms/lux.h
> @@ -0,0 +1,39 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2024, Ideas On Board
> + *
> + * Simple Lux control
> + */
> +
> +#pragma once
> +
> +#include <sys/types.h>
> +
> +#include "libipa/lux.h"
> +
> +#include "algorithm.h"
> +
> +namespace libcamera {
> +
> +namespace ipa::soft::algorithms {
> +
> +class Lux : public Algorithm
> +{
> +public:
> +	Lux();
> +
> +	int init(IPAContext &context, const YamlObject &tuningData) override;
> +	void prepare(IPAContext &context, const uint32_t frame,
> +		     IPAFrameContext &frameContext,
> +		     DebayerParams *params) override;
> +	void process(IPAContext &context, const uint32_t frame,
> +		     IPAFrameContext &frameContext,
> +		     const SwIspStats *stats,
> +		     ControlList &metadata) override;
> +
> +private:
> +	ipa::Lux lux_;
> +};
> +
> +} /* namespace ipa::soft::algorithms */
> +} /* namespace libcamera */
> diff --git a/src/ipa/simple/algorithms/meson.build b/src/ipa/simple/algorithms/meson.build
> index 73c63722083ff92147253c6b10440ce50743988d..27e73c9a0eea2241cc4a4cefd1594c976fb59318 100644
> --- a/src/ipa/simple/algorithms/meson.build
> +++ b/src/ipa/simple/algorithms/meson.build
> @@ -6,4 +6,5 @@ soft_simple_ipa_algorithms = files([
>      'agc.cpp',
>      'blc.cpp',
>      'ccm.cpp',
> +    'lux.cpp',
>  ])
> diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h
> index 8ccfacb46a59cedb5a0ad051d67f7c1f40af4b52..2bd7c4642b118d7bb94b1b16cdf4ede5fb2554b5 100644
> --- a/src/ipa/simple/ipa_context.h
> +++ b/src/ipa/simple/ipa_context.h
> @@ -17,6 +17,7 @@
>  #include "libcamera/internal/vector.h"
>  
>  #include <libipa/fc_queue.h>
> +#include <libipa/lux.h>
>  
>  #include "core_ipa_interface.h"
>  
> @@ -36,6 +37,8 @@ struct IPASessionConfiguration {
>  };
>  
>  struct IPAActiveState {
> +	ipa::lux::ActiveState lux;

Does this need setting an initial value some way?

> +
>  	struct {
>  		int32_t exposure;
>  		double again;
> @@ -64,6 +67,8 @@ struct IPAActiveState {
>  };
>  
>  struct IPAFrameContext : public FrameContext {
> +	ipa::lux::FrameContext lux;
> +
>  	Matrix<float, 3, 3> ccm;
>  
>  	struct {
Kieran Bingham April 8, 2026, 5:38 p.m. UTC | #2
Quoting Milan Zamazal (2026-04-08 15:12:26)
> Hi Kieran,
> 
> Kieran Bingham <kieran.bingham@ideasonboard.com> writes:
> 
> > Utilise the lux component of libipa to map in the lux estimate
> > process using the yHistgram of the Soft ISP statistics.
> 
> s/yHistgram/yHistogram/
> 
> I suppose the algorithm is supposed to be enabled manually, in case the
> corresponding tuning data is available?  It would be worth to explain
> its purpose and use here.

Not manually, I think it's just used when there is available tuning
data. It helps for AWB ultimately.


> 
> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > ---
> >  src/ipa/simple/algorithms/lux.cpp     | 93 +++++++++++++++++++++++++++++++++++
> >  src/ipa/simple/algorithms/lux.h       | 39 +++++++++++++++
> >  src/ipa/simple/algorithms/meson.build |  1 +
> >  src/ipa/simple/ipa_context.h          |  5 ++
> >  4 files changed, 138 insertions(+)
> >
> > diff --git a/src/ipa/simple/algorithms/lux.cpp b/src/ipa/simple/algorithms/lux.cpp
> > new file mode 100644
> > index 0000000000000000000000000000000000000000..03b44ac584ae141509e79954159272504cdba17d
> > --- /dev/null
> > +++ b/src/ipa/simple/algorithms/lux.cpp
> > @@ -0,0 +1,93 @@
> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> > +/*
> > + * Copyright (C) 2024, Ideas On Board
> > + *
> > + * Simple Lux control
> > + */
> > +
> > +#include "lux.h"
> > +
> > +#include <libcamera/base/log.h>
> > +
> > +#include <libcamera/control_ids.h>
> > +
> > +#include "libipa/histogram.h"
> > +#include "libipa/lux.h"
> > +
> > +/**
> > + * \file lux.h
> > + */
> > +
> > +namespace libcamera {
> > +
> > +namespace ipa::soft::algorithms {
> > +
> > +/**
> > + * \class Lux
> > + * \brief SoftISP Lux control
> > + *
> > + * The Lux algorithm is responsible for estimating the lux level of the image.
> > + * It doesn't take or generate any controls, but it provides a lux level for
> > + * other algorithms (such as AGC) to use.
> > + */
> > +
> > +/**
> > + * \brief Construct a SoftISP Lux algo module
> > + */
> > +Lux::Lux()
> > +{
> > +}

I don't think that's needed when it's empty ;-)

> > +
> > +/**
> > + * \copydoc libcamera::ipa::Algorithm::init
> > + */
> > +int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)
> > +{
> > +     return lux_.parseTuningData(tuningData);
> > +}
> > +
> > +/**
> > + * \copydoc libcamera::ipa::Algorithm::prepare
> > + */
> > +void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,
> > +               IPAFrameContext &frameContext,
> > +               [[maybe_unused]] DebayerParams *params)
> > +{
> > +     frameContext.lux.lux = context.activeState.lux.lux;
> > +}
> > +
> > +/**
> > + * \copydoc libcamera::ipa::Algorithm::process
> > + */
> > +void Lux::process(IPAContext &context,
> > +               [[maybe_unused]] const uint32_t frame,
> > +               IPAFrameContext &frameContext,
> > +               const SwIspStats *stats,
> > +               ControlList &metadata)
> > +{
> > +     /*
> > +      * Report the lux level used by algorithms to prepare this frame
> > +      * not the lux level *of* this frame.
> > +      */
> > +     metadata.set(controls::Lux, frameContext.lux.lux);
> 
> Should this be reported before the lux value is determined for the first
> time?

Ohh no good spot, there's some startup ordering errors here...

> 
> > +     if (!stats)
> > +             return;
> > +
> > +     /* Todo: Sensor configuration should move out of AGC */
> 
> Todo: -> \todo
> 
> The comment is a bit confusing here, it might be better to attach it to
> the sensor configuration in AGC.

Maybe, but this is me explicitly telling myself yet another place that
needs to refactor the AEGC into libipa, and split out sensor controls
from the AGC, and have a dedicated sensor context.

Because even if AEGC isn't "running" if we know the stats, and the
exposure and gain we can know the lux - so the sensor properties
shouldn't be tied directly into the AGC like they are.

It's one of the many rabbit holes that have made it harder for me to split out
AgcMeanLuminance and use it for soft-ipa. I've hoped starting with
Lux/AWB will make it easier to progress and then do the same for AGC./


> 
> > +     utils::Duration exposureTime = context.configuration.agc.lineDuration *
> > +                                    frameContext.sensor.exposure;
> > +     double gain = frameContext.sensor.gain;
> > +     double digitalGain = 1.0;
> > +
> > +     Histogram yHist(stats->yHistogram);
> > +
> > +     context.activeState.lux.lux =
> > +             lux_.estimateLux(exposureTime, gain, digitalGain, yHist);
> > +}
> > +
> > +REGISTER_IPA_ALGORITHM(Lux, "Lux")
> > +
> > +} /* namespace ipa::soft::algorithms */
> > +
> > +} /* namespace libcamera */
> > diff --git a/src/ipa/simple/algorithms/lux.h b/src/ipa/simple/algorithms/lux.h
> > new file mode 100644
> > index 0000000000000000000000000000000000000000..04ec4c163ede422369977017cca70d12a8d361fb
> > --- /dev/null
> > +++ b/src/ipa/simple/algorithms/lux.h
> > @@ -0,0 +1,39 @@
> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> > +/*
> > + * Copyright (C) 2024, Ideas On Board
> > + *
> > + * Simple Lux control
> > + */
> > +
> > +#pragma once
> > +
> > +#include <sys/types.h>
> > +
> > +#include "libipa/lux.h"
> > +
> > +#include "algorithm.h"
> > +
> > +namespace libcamera {
> > +
> > +namespace ipa::soft::algorithms {
> > +
> > +class Lux : public Algorithm
> > +{
> > +public:
> > +     Lux();
> > +
> > +     int init(IPAContext &context, const YamlObject &tuningData) override;
> > +     void prepare(IPAContext &context, const uint32_t frame,
> > +                  IPAFrameContext &frameContext,
> > +                  DebayerParams *params) override;
> > +     void process(IPAContext &context, const uint32_t frame,
> > +                  IPAFrameContext &frameContext,
> > +                  const SwIspStats *stats,
> > +                  ControlList &metadata) override;
> > +
> > +private:
> > +     ipa::Lux lux_;
> > +};
> > +
> > +} /* namespace ipa::soft::algorithms */
> > +} /* namespace libcamera */
> > diff --git a/src/ipa/simple/algorithms/meson.build b/src/ipa/simple/algorithms/meson.build
> > index 73c63722083ff92147253c6b10440ce50743988d..27e73c9a0eea2241cc4a4cefd1594c976fb59318 100644
> > --- a/src/ipa/simple/algorithms/meson.build
> > +++ b/src/ipa/simple/algorithms/meson.build
> > @@ -6,4 +6,5 @@ soft_simple_ipa_algorithms = files([
> >      'agc.cpp',
> >      'blc.cpp',
> >      'ccm.cpp',
> > +    'lux.cpp',
> >  ])
> > diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h
> > index 8ccfacb46a59cedb5a0ad051d67f7c1f40af4b52..2bd7c4642b118d7bb94b1b16cdf4ede5fb2554b5 100644
> > --- a/src/ipa/simple/ipa_context.h
> > +++ b/src/ipa/simple/ipa_context.h
> > @@ -17,6 +17,7 @@
> >  #include "libcamera/internal/vector.h"
> >  
> >  #include <libipa/fc_queue.h>
> > +#include <libipa/lux.h>
> >  
> >  #include "core_ipa_interface.h"
> >  
> > @@ -36,6 +37,8 @@ struct IPASessionConfiguration {
> >  };
> >  
> >  struct IPAActiveState {
> > +     ipa::lux::ActiveState lux;
> 
> Does this need setting an initial value some way?

It at least needs to be not reported before we calculate it perhaps...
I'll think about it when I refresh this series.

Thanks

Kieran


> 
> > +
> >       struct {
> >               int32_t exposure;
> >               double again;
> > @@ -64,6 +67,8 @@ struct IPAActiveState {
> >  };
> >  
> >  struct IPAFrameContext : public FrameContext {
> > +     ipa::lux::FrameContext lux;
> > +
> >       Matrix<float, 3, 3> ccm;
> >  
> >       struct {
>
Milan Zamazal April 8, 2026, 7:41 p.m. UTC | #3
Kieran Bingham <kieran.bingham@ideasonboard.com> writes:

> Quoting Milan Zamazal (2026-04-08 15:12:26)
>> Hi Kieran,
>> 
>
>> Kieran Bingham <kieran.bingham@ideasonboard.com> writes:
>> 
>> > Utilise the lux component of libipa to map in the lux estimate
>> > process using the yHistgram of the Soft ISP statistics.
>> 
>> s/yHistgram/yHistogram/
>> 
>> I suppose the algorithm is supposed to be enabled manually, in case the
>> corresponding tuning data is available?  It would be worth to explain
>> its purpose and use here.
>
> Not manually, I think it's just used when there is available tuning
> data. It helps for AWB ultimately.

OK.

>> 
>> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>> > ---
>> >  src/ipa/simple/algorithms/lux.cpp     | 93 +++++++++++++++++++++++++++++++++++
>> >  src/ipa/simple/algorithms/lux.h       | 39 +++++++++++++++
>> >  src/ipa/simple/algorithms/meson.build |  1 +
>> >  src/ipa/simple/ipa_context.h          |  5 ++
>> >  4 files changed, 138 insertions(+)
>> >
>> > diff --git a/src/ipa/simple/algorithms/lux.cpp b/src/ipa/simple/algorithms/lux.cpp
>> > new file mode 100644
>> > index 0000000000000000000000000000000000000000..03b44ac584ae141509e79954159272504cdba17d
>> > --- /dev/null
>> > +++ b/src/ipa/simple/algorithms/lux.cpp
>> > @@ -0,0 +1,93 @@
>> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */
>> > +/*
>> > + * Copyright (C) 2024, Ideas On Board
>> > + *
>> > + * Simple Lux control
>> > + */
>> > +
>> > +#include "lux.h"
>> > +
>> > +#include <libcamera/base/log.h>
>> > +
>> > +#include <libcamera/control_ids.h>
>> > +
>> > +#include "libipa/histogram.h"
>> > +#include "libipa/lux.h"
>> > +
>> > +/**
>> > + * \file lux.h
>> > + */
>> > +
>> > +namespace libcamera {
>> > +
>> > +namespace ipa::soft::algorithms {
>> > +
>> > +/**
>> > + * \class Lux
>> > + * \brief SoftISP Lux control
>> > + *
>> > + * The Lux algorithm is responsible for estimating the lux level of the image.
>> > + * It doesn't take or generate any controls, but it provides a lux level for
>> > + * other algorithms (such as AGC) to use.
>> > + */
>> > +
>> > +/**
>> > + * \brief Construct a SoftISP Lux algo module
>> > + */
>> > +Lux::Lux()
>> > +{
>> > +}
>
> I don't think that's needed when it's empty ;-)

Then the declaration in lux.h should be removed too.

>> > +
>> > +/**
>> > + * \copydoc libcamera::ipa::Algorithm::init
>> > + */
>> > +int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)
>> > +{
>> > +     return lux_.parseTuningData(tuningData);
>> > +}
>> > +
>> > +/**
>> > + * \copydoc libcamera::ipa::Algorithm::prepare
>> > + */
>> > +void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,
>> > +               IPAFrameContext &frameContext,
>> > +               [[maybe_unused]] DebayerParams *params)
>> > +{
>> > +     frameContext.lux.lux = context.activeState.lux.lux;
>> > +}
>> > +
>> > +/**
>> > + * \copydoc libcamera::ipa::Algorithm::process
>> > + */
>> > +void Lux::process(IPAContext &context,
>> > +               [[maybe_unused]] const uint32_t frame,
>> > +               IPAFrameContext &frameContext,
>> > +               const SwIspStats *stats,
>> > +               ControlList &metadata)
>> > +{
>> > +     /*
>> > +      * Report the lux level used by algorithms to prepare this frame
>> > +      * not the lux level *of* this frame.
>> > +      */
>> > +     metadata.set(controls::Lux, frameContext.lux.lux);
>> 
>> Should this be reported before the lux value is determined for the first
>> time?
>
> Ohh no good spot, there's some startup ordering errors here...
>
>> 
>> > +     if (!stats)
>> > +             return;
>> > +
>> > +     /* Todo: Sensor configuration should move out of AGC */
>> 
>> Todo: -> \todo
>> 
>> The comment is a bit confusing here, it might be better to attach it to
>> the sensor configuration in AGC.
>
> Maybe, but this is me explicitly telling myself yet another place that
> needs to refactor the AEGC into libipa, and split out sensor controls
> from the AGC, and have a dedicated sensor context.
>
> Because even if AEGC isn't "running" if we know the stats, and the
> exposure and gain we can know the lux - so the sensor properties
> shouldn't be tied directly into the AGC like they are.
>
> It's one of the many rabbit holes that have made it harder for me to split out
> AgcMeanLuminance and use it for soft-ipa. I've hoped starting with
> Lux/AWB will make it easier to progress and then do the same for AGC./

Makes sense but then I'd suggest to make the comment clearer; well, many
TODO comments survive much longer than initially expected.

>> 
>> > +     utils::Duration exposureTime = context.configuration.agc.lineDuration *
>> > +                                    frameContext.sensor.exposure;
>> > +     double gain = frameContext.sensor.gain;
>> > +     double digitalGain = 1.0;
>> > +
>> > +     Histogram yHist(stats->yHistogram);
>> > +
>> > +     context.activeState.lux.lux =
>> > +             lux_.estimateLux(exposureTime, gain, digitalGain, yHist);
>> > +}
>> > +
>> > +REGISTER_IPA_ALGORITHM(Lux, "Lux")
>> > +
>> > +} /* namespace ipa::soft::algorithms */
>> > +
>> > +} /* namespace libcamera */
>> > diff --git a/src/ipa/simple/algorithms/lux.h b/src/ipa/simple/algorithms/lux.h
>> > new file mode 100644
>> > index 0000000000000000000000000000000000000000..04ec4c163ede422369977017cca70d12a8d361fb
>> > --- /dev/null
>> > +++ b/src/ipa/simple/algorithms/lux.h
>> > @@ -0,0 +1,39 @@
>> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */
>> > +/*
>> > + * Copyright (C) 2024, Ideas On Board
>> > + *
>> > + * Simple Lux control
>> > + */
>> > +
>> > +#pragma once
>> > +
>> > +#include <sys/types.h>
>> > +
>> > +#include "libipa/lux.h"
>> > +
>> > +#include "algorithm.h"
>> > +
>> > +namespace libcamera {
>> > +
>> > +namespace ipa::soft::algorithms {
>> > +
>> > +class Lux : public Algorithm
>> > +{
>> > +public:
>> > +     Lux();
>> > +
>> > +     int init(IPAContext &context, const YamlObject &tuningData) override;
>> > +     void prepare(IPAContext &context, const uint32_t frame,
>> > +                  IPAFrameContext &frameContext,
>> > +                  DebayerParams *params) override;
>> > +     void process(IPAContext &context, const uint32_t frame,
>> > +                  IPAFrameContext &frameContext,
>> > +                  const SwIspStats *stats,
>> > +                  ControlList &metadata) override;
>> > +
>> > +private:
>> > +     ipa::Lux lux_;
>> > +};
>> > +
>> > +} /* namespace ipa::soft::algorithms */
>> > +} /* namespace libcamera */
>> > diff --git a/src/ipa/simple/algorithms/meson.build b/src/ipa/simple/algorithms/meson.build
>> > index 73c63722083ff92147253c6b10440ce50743988d..27e73c9a0eea2241cc4a4cefd1594c976fb59318 100644
>> > --- a/src/ipa/simple/algorithms/meson.build
>> > +++ b/src/ipa/simple/algorithms/meson.build
>> > @@ -6,4 +6,5 @@ soft_simple_ipa_algorithms = files([
>> >      'agc.cpp',
>> >      'blc.cpp',
>> >      'ccm.cpp',
>> > +    'lux.cpp',
>> >  ])
>> > diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h
>> > index 8ccfacb46a59cedb5a0ad051d67f7c1f40af4b52..2bd7c4642b118d7bb94b1b16cdf4ede5fb2554b5 100644
>> > --- a/src/ipa/simple/ipa_context.h
>> > +++ b/src/ipa/simple/ipa_context.h
>> > @@ -17,6 +17,7 @@
>> >  #include "libcamera/internal/vector.h"
>> >  
>> >  #include <libipa/fc_queue.h>
>> > +#include <libipa/lux.h>
>> >  
>> >  #include "core_ipa_interface.h"
>> >  
>> > @@ -36,6 +37,8 @@ struct IPASessionConfiguration {
>> >  };
>> >  
>> >  struct IPAActiveState {
>> > +     ipa::lux::ActiveState lux;
>> 
>> Does this need setting an initial value some way?
>
> It at least needs to be not reported before we calculate it perhaps...
> I'll think about it when I refresh this series.
>
> Thanks
>
> Kieran
>
>
>> 
>> > +
>> >       struct {
>> >               int32_t exposure;
>> >               double again;
>> > @@ -64,6 +67,8 @@ struct IPAActiveState {
>> >  };
>> >  
>> >  struct IPAFrameContext : public FrameContext {
>> > +     ipa::lux::FrameContext lux;
>> > +
>> >       Matrix<float, 3, 3> ccm;
>> >  
>> >       struct {
>>
Laurent Pinchart April 8, 2026, 9:16 p.m. UTC | #4
On Tue, Apr 07, 2026 at 11:01:10PM +0100, Kieran Bingham wrote:
> Utilise the lux component of libipa to map in the lux estimate
> process using the yHistgram of the Soft ISP statistics.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  src/ipa/simple/algorithms/lux.cpp     | 93 +++++++++++++++++++++++++++++++++++
>  src/ipa/simple/algorithms/lux.h       | 39 +++++++++++++++
>  src/ipa/simple/algorithms/meson.build |  1 +
>  src/ipa/simple/ipa_context.h          |  5 ++
>  4 files changed, 138 insertions(+)
> 
> diff --git a/src/ipa/simple/algorithms/lux.cpp b/src/ipa/simple/algorithms/lux.cpp
> new file mode 100644
> index 0000000000000000000000000000000000000000..03b44ac584ae141509e79954159272504cdba17d
> --- /dev/null
> +++ b/src/ipa/simple/algorithms/lux.cpp
> @@ -0,0 +1,93 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2024, Ideas On Board
> + *
> + * Simple Lux control
> + */
> +
> +#include "lux.h"
> +
> +#include <libcamera/base/log.h>
> +
> +#include <libcamera/control_ids.h>
> +
> +#include "libipa/histogram.h"
> +#include "libipa/lux.h"
> +
> +/**
> + * \file lux.h
> + */
> +
> +namespace libcamera {
> +
> +namespace ipa::soft::algorithms {
> +
> +/**
> + * \class Lux
> + * \brief SoftISP Lux control
> + *
> + * The Lux algorithm is responsible for estimating the lux level of the image.
> + * It doesn't take or generate any controls, but it provides a lux level for
> + * other algorithms (such as AGC) to use.
> + */
> +
> +/**
> + * \brief Construct a SoftISP Lux algo module
> + */
> +Lux::Lux()
> +{
> +}
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::init
> + */
> +int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)
> +{
> +	return lux_.parseTuningData(tuningData);
> +}
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::prepare
> + */
> +void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,
> +		  IPAFrameContext &frameContext,
> +		  [[maybe_unused]] DebayerParams *params)
> +{
> +	frameContext.lux.lux = context.activeState.lux.lux;
> +}
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::process
> + */
> +void Lux::process(IPAContext &context,
> +		  [[maybe_unused]] const uint32_t frame,
> +		  IPAFrameContext &frameContext,
> +		  const SwIspStats *stats,
> +		  ControlList &metadata)
> +{
> +	/*
> +	 * Report the lux level used by algorithms to prepare this frame
> +	 * not the lux level *of* this frame.
> +	 */
> +	metadata.set(controls::Lux, frameContext.lux.lux);
> +
> +	if (!stats)
> +		return;
> +
> +	/* Todo: Sensor configuration should move out of AGC */
> +	utils::Duration exposureTime = context.configuration.agc.lineDuration *
> +				       frameContext.sensor.exposure;
> +	double gain = frameContext.sensor.gain;
> +	double digitalGain = 1.0;
> +
> +	Histogram yHist(stats->yHistogram);
> +
> +	context.activeState.lux.lux =
> +		lux_.estimateLux(exposureTime, gain, digitalGain, yHist);
> +}
> +
> +REGISTER_IPA_ALGORITHM(Lux, "Lux")
> +
> +} /* namespace ipa::soft::algorithms */
> +
> +} /* namespace libcamera */
> diff --git a/src/ipa/simple/algorithms/lux.h b/src/ipa/simple/algorithms/lux.h
> new file mode 100644
> index 0000000000000000000000000000000000000000..04ec4c163ede422369977017cca70d12a8d361fb
> --- /dev/null
> +++ b/src/ipa/simple/algorithms/lux.h
> @@ -0,0 +1,39 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2024, Ideas On Board
> + *
> + * Simple Lux control
> + */
> +
> +#pragma once
> +
> +#include <sys/types.h>
> +
> +#include "libipa/lux.h"
> +
> +#include "algorithm.h"
> +
> +namespace libcamera {
> +
> +namespace ipa::soft::algorithms {
> +
> +class Lux : public Algorithm
> +{
> +public:
> +	Lux();
> +
> +	int init(IPAContext &context, const YamlObject &tuningData) override;
> +	void prepare(IPAContext &context, const uint32_t frame,
> +		     IPAFrameContext &frameContext,
> +		     DebayerParams *params) override;
> +	void process(IPAContext &context, const uint32_t frame,
> +		     IPAFrameContext &frameContext,
> +		     const SwIspStats *stats,
> +		     ControlList &metadata) override;
> +
> +private:
> +	ipa::Lux lux_;

Would it make sense to inherit from ipa::Lux instead, the same way Agc
in rkisp1 inherits from AgcMeanLuminance ?

> +};
> +
> +} /* namespace ipa::soft::algorithms */
> +} /* namespace libcamera */
> diff --git a/src/ipa/simple/algorithms/meson.build b/src/ipa/simple/algorithms/meson.build
> index 73c63722083ff92147253c6b10440ce50743988d..27e73c9a0eea2241cc4a4cefd1594c976fb59318 100644
> --- a/src/ipa/simple/algorithms/meson.build
> +++ b/src/ipa/simple/algorithms/meson.build
> @@ -6,4 +6,5 @@ soft_simple_ipa_algorithms = files([
>      'agc.cpp',
>      'blc.cpp',
>      'ccm.cpp',
> +    'lux.cpp',
>  ])
> diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h
> index 8ccfacb46a59cedb5a0ad051d67f7c1f40af4b52..2bd7c4642b118d7bb94b1b16cdf4ede5fb2554b5 100644
> --- a/src/ipa/simple/ipa_context.h
> +++ b/src/ipa/simple/ipa_context.h
> @@ -17,6 +17,7 @@
>  #include "libcamera/internal/vector.h"
>  
>  #include <libipa/fc_queue.h>
> +#include <libipa/lux.h>
>  
>  #include "core_ipa_interface.h"
>  
> @@ -36,6 +37,8 @@ struct IPASessionConfiguration {
>  };
>  
>  struct IPAActiveState {
> +	ipa::lux::ActiveState lux;
> +
>  	struct {
>  		int32_t exposure;
>  		double again;
> @@ -64,6 +67,8 @@ struct IPAActiveState {
>  };
>  
>  struct IPAFrameContext : public FrameContext {
> +	ipa::lux::FrameContext lux;
> +
>  	Matrix<float, 3, 3> ccm;
>  
>  	struct {
>
Kieran Bingham May 10, 2026, 6:50 p.m. UTC | #5
Quoting Laurent Pinchart (2026-04-08 22:16:58)
> On Tue, Apr 07, 2026 at 11:01:10PM +0100, Kieran Bingham wrote:
> > Utilise the lux component of libipa to map in the lux estimate
> > process using the yHistgram of the Soft ISP statistics.
> > 
> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > ---
> >  src/ipa/simple/algorithms/lux.cpp     | 93 +++++++++++++++++++++++++++++++++++
> >  src/ipa/simple/algorithms/lux.h       | 39 +++++++++++++++
> >  src/ipa/simple/algorithms/meson.build |  1 +
> >  src/ipa/simple/ipa_context.h          |  5 ++
> >  4 files changed, 138 insertions(+)
> > 
> > diff --git a/src/ipa/simple/algorithms/lux.cpp b/src/ipa/simple/algorithms/lux.cpp
> > new file mode 100644
> > index 0000000000000000000000000000000000000000..03b44ac584ae141509e79954159272504cdba17d
> > --- /dev/null
> > +++ b/src/ipa/simple/algorithms/lux.cpp
> > @@ -0,0 +1,93 @@
> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> > +/*
> > + * Copyright (C) 2024, Ideas On Board
> > + *
> > + * Simple Lux control
> > + */
> > +
> > +#include "lux.h"
> > +
> > +#include <libcamera/base/log.h>
> > +
> > +#include <libcamera/control_ids.h>
> > +
> > +#include "libipa/histogram.h"
> > +#include "libipa/lux.h"
> > +
> > +/**
> > + * \file lux.h
> > + */
> > +
> > +namespace libcamera {
> > +
> > +namespace ipa::soft::algorithms {
> > +
> > +/**
> > + * \class Lux
> > + * \brief SoftISP Lux control
> > + *
> > + * The Lux algorithm is responsible for estimating the lux level of the image.
> > + * It doesn't take or generate any controls, but it provides a lux level for
> > + * other algorithms (such as AGC) to use.
> > + */
> > +
> > +/**
> > + * \brief Construct a SoftISP Lux algo module
> > + */
> > +Lux::Lux()
> > +{
> > +}
> > +
> > +/**
> > + * \copydoc libcamera::ipa::Algorithm::init
> > + */
> > +int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)
> > +{
> > +     return lux_.parseTuningData(tuningData);
> > +}
> > +
> > +/**
> > + * \copydoc libcamera::ipa::Algorithm::prepare
> > + */
> > +void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,
> > +               IPAFrameContext &frameContext,
> > +               [[maybe_unused]] DebayerParams *params)
> > +{
> > +     frameContext.lux.lux = context.activeState.lux.lux;
> > +}
> > +
> > +/**
> > + * \copydoc libcamera::ipa::Algorithm::process
> > + */
> > +void Lux::process(IPAContext &context,
> > +               [[maybe_unused]] const uint32_t frame,
> > +               IPAFrameContext &frameContext,
> > +               const SwIspStats *stats,
> > +               ControlList &metadata)
> > +{
> > +     /*
> > +      * Report the lux level used by algorithms to prepare this frame
> > +      * not the lux level *of* this frame.
> > +      */
> > +     metadata.set(controls::Lux, frameContext.lux.lux);
> > +
> > +     if (!stats)
> > +             return;
> > +
> > +     /* Todo: Sensor configuration should move out of AGC */
> > +     utils::Duration exposureTime = context.configuration.agc.lineDuration *
> > +                                    frameContext.sensor.exposure;
> > +     double gain = frameContext.sensor.gain;
> > +     double digitalGain = 1.0;
> > +
> > +     Histogram yHist(stats->yHistogram);
> > +
> > +     context.activeState.lux.lux =
> > +             lux_.estimateLux(exposureTime, gain, digitalGain, yHist);
> > +}
> > +
> > +REGISTER_IPA_ALGORITHM(Lux, "Lux")
> > +
> > +} /* namespace ipa::soft::algorithms */
> > +
> > +} /* namespace libcamera */
> > diff --git a/src/ipa/simple/algorithms/lux.h b/src/ipa/simple/algorithms/lux.h
> > new file mode 100644
> > index 0000000000000000000000000000000000000000..04ec4c163ede422369977017cca70d12a8d361fb
> > --- /dev/null
> > +++ b/src/ipa/simple/algorithms/lux.h
> > @@ -0,0 +1,39 @@
> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> > +/*
> > + * Copyright (C) 2024, Ideas On Board
> > + *
> > + * Simple Lux control
> > + */
> > +
> > +#pragma once
> > +
> > +#include <sys/types.h>
> > +
> > +#include "libipa/lux.h"
> > +
> > +#include "algorithm.h"
> > +
> > +namespace libcamera {
> > +
> > +namespace ipa::soft::algorithms {
> > +
> > +class Lux : public Algorithm
> > +{
> > +public:
> > +     Lux();
> > +
> > +     int init(IPAContext &context, const YamlObject &tuningData) override;
> > +     void prepare(IPAContext &context, const uint32_t frame,
> > +                  IPAFrameContext &frameContext,
> > +                  DebayerParams *params) override;
> > +     void process(IPAContext &context, const uint32_t frame,
> > +                  IPAFrameContext &frameContext,
> > +                  const SwIspStats *stats,
> > +                  ControlList &metadata) override;
> > +
> > +private:
> > +     ipa::Lux lux_;
> 
> Would it make sense to inherit from ipa::Lux instead, the same way Agc
> in rkisp1 inherits from AgcMeanLuminance ?

I don't know about this yet, as I want to reduce duplication in the main
interface functions, but we can't inherit init, prepare, and process
which have IPA specific function parameters.

So I think at the moment (along with my previous efforts to factor out
AGC for simple/SoftISP as well) that we probably want composition and
have the main interface as the wrapper into the libipa implementation on
the object directly.

That means we'll have 

simple:Awb::init(...)
{
	return awb_->init(...modified...);
}

instead of

simple::Awb::init(...)
{
	return init(...modified...);
}


Any preferences or specific thoughts ?

We'll have a lot of 'map this structure through to the component' and
trying to massage the data structures seems to be the most awkward part.

--
Kieran


> 
> > +};
> > +
> > +} /* namespace ipa::soft::algorithms */
> > +} /* namespace libcamera */
> > diff --git a/src/ipa/simple/algorithms/meson.build b/src/ipa/simple/algorithms/meson.build
> > index 73c63722083ff92147253c6b10440ce50743988d..27e73c9a0eea2241cc4a4cefd1594c976fb59318 100644
> > --- a/src/ipa/simple/algorithms/meson.build
> > +++ b/src/ipa/simple/algorithms/meson.build
> > @@ -6,4 +6,5 @@ soft_simple_ipa_algorithms = files([
> >      'agc.cpp',
> >      'blc.cpp',
> >      'ccm.cpp',
> > +    'lux.cpp',
> >  ])
> > diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h
> > index 8ccfacb46a59cedb5a0ad051d67f7c1f40af4b52..2bd7c4642b118d7bb94b1b16cdf4ede5fb2554b5 100644
> > --- a/src/ipa/simple/ipa_context.h
> > +++ b/src/ipa/simple/ipa_context.h
> > @@ -17,6 +17,7 @@
> >  #include "libcamera/internal/vector.h"
> >  
> >  #include <libipa/fc_queue.h>
> > +#include <libipa/lux.h>
> >  
> >  #include "core_ipa_interface.h"
> >  
> > @@ -36,6 +37,8 @@ struct IPASessionConfiguration {
> >  };
> >  
> >  struct IPAActiveState {
> > +     ipa::lux::ActiveState lux;
> > +
> >       struct {
> >               int32_t exposure;
> >               double again;
> > @@ -64,6 +67,8 @@ struct IPAActiveState {
> >  };
> >  
> >  struct IPAFrameContext : public FrameContext {
> > +     ipa::lux::FrameContext lux;
> > +
> >       Matrix<float, 3, 3> ccm;
> >  
> >       struct {
> > 
> 
> -- 
> Regards,
> 
> Laurent Pinchart
Keith Carter Nov. 17, 2026, 6:40 a.m. UTC | #6
Hi Kiernan,

Are you planning an updated version of the SoftIPA Lux patches (06/13 and 07/13)?   https://patchwork.libcamera.org/patch/26491/

I'm new to the list. I run the OV5675 on an MSI Prestige 13 AI+ Evo (Intel IPU7, Lunar Lake) through the simple pipeline and the soft ISP, and today I posted a tuning file for it: https://patchwork.libcamera.org/patch/28936/

The file fixes color and the dark corners, but dim rooms stay dark: without a Lux algorithm the soft ISP's lux stays at its default, so the low-light end of relativeLuminanceTarget never applies.

As reference for the changes, please see this repo that includes the scripts, measurements and dated steps are at https://github.com/cartek99/msi-prestige-evo-camera


Barnabás's v5 series turns the libipa Lux into an algorithm (patch 28923), which may change how softisp Lux plugs in. 

If there's an update I can test it by day and in the evening and send you the numbers.

I'm open to assist!


Sincerely,

Keith

On 8/4/26 06:01, Kieran Bingham wrote:
> Utilise the lux component of libipa to map in the lux estimate
> process using the yHistgram of the Soft ISP statistics.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  src/ipa/simple/algorithms/lux.cpp     | 93 +++++++++++++++++++++++++++++++++++
>  src/ipa/simple/algorithms/lux.h       | 39 +++++++++++++++
>  src/ipa/simple/algorithms/meson.build |  1 +
>  src/ipa/simple/ipa_context.h          |  5 ++
>  4 files changed, 138 insertions(+)
> 
> diff --git a/src/ipa/simple/algorithms/lux.cpp b/src/ipa/simple/algorithms/lux.cpp
> new file mode 100644
> index 0000000000000000000000000000000000000000..03b44ac584ae141509e79954159272504cdba17d
> --- /dev/null
> +++ b/src/ipa/simple/algorithms/lux.cpp
> @@ -0,0 +1,93 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2024, Ideas On Board
> + *
> + * Simple Lux control
> + */
> +
> +#include "lux.h"
> +
> +#include <libcamera/base/log.h>
> +
> +#include <libcamera/control_ids.h>
> +
> +#include "libipa/histogram.h"
> +#include "libipa/lux.h"
> +
> +/**
> + * \file lux.h
> + */
> +
> +namespace libcamera {
> +
> +namespace ipa::soft::algorithms {
> +
> +/**
> + * \class Lux
> + * \brief SoftISP Lux control
> + *
> + * The Lux algorithm is responsible for estimating the lux level of the image.
> + * It doesn't take or generate any controls, but it provides a lux level for
> + * other algorithms (such as AGC) to use.
> + */
> +
> +/**
> + * \brief Construct a SoftISP Lux algo module
> + */
> +Lux::Lux()
> +{
> +}
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::init
> + */
> +int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)
> +{
> +	return lux_.parseTuningData(tuningData);
> +}
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::prepare
> + */
> +void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,
> +		  IPAFrameContext &frameContext,
> +		  [[maybe_unused]] DebayerParams *params)
> +{
> +	frameContext.lux.lux = context.activeState.lux.lux;
> +}
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::process
> + */
> +void Lux::process(IPAContext &context,
> +		  [[maybe_unused]] const uint32_t frame,
> +		  IPAFrameContext &frameContext,
> +		  const SwIspStats *stats,
> +		  ControlList &metadata)
> +{
> +	/*
> +	 * Report the lux level used by algorithms to prepare this frame
> +	 * not the lux level *of* this frame.
> +	 */
> +	metadata.set(controls::Lux, frameContext.lux.lux);
> +
> +	if (!stats)
> +		return;
> +
> +	/* Todo: Sensor configuration should move out of AGC */
> +	utils::Duration exposureTime = context.configuration.agc.lineDuration *
> +				       frameContext.sensor.exposure;
> +	double gain = frameContext.sensor.gain;
> +	double digitalGain = 1.0;
> +
> +	Histogram yHist(stats->yHistogram);
> +
> +	context.activeState.lux.lux =
> +		lux_.estimateLux(exposureTime, gain, digitalGain, yHist);
> +}
> +
> +REGISTER_IPA_ALGORITHM(Lux, "Lux")
> +
> +} /* namespace ipa::soft::algorithms */
> +
> +} /* namespace libcamera */
> diff --git a/src/ipa/simple/algorithms/lux.h b/src/ipa/simple/algorithms/lux.h
> new file mode 100644
> index 0000000000000000000000000000000000000000..04ec4c163ede422369977017cca70d12a8d361fb
> --- /dev/null
> +++ b/src/ipa/simple/algorithms/lux.h
> @@ -0,0 +1,39 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2024, Ideas On Board
> + *
> + * Simple Lux control
> + */
> +
> +#pragma once
> +
> +#include <sys/types.h>
> +
> +#include "libipa/lux.h"
> +
> +#include "algorithm.h"
> +
> +namespace libcamera {
> +
> +namespace ipa::soft::algorithms {
> +
> +class Lux : public Algorithm
> +{
> +public:
> +	Lux();
> +
> +	int init(IPAContext &context, const YamlObject &tuningData) override;
> +	void prepare(IPAContext &context, const uint32_t frame,
> +		     IPAFrameContext &frameContext,
> +		     DebayerParams *params) override;
> +	void process(IPAContext &context, const uint32_t frame,
> +		     IPAFrameContext &frameContext,
> +		     const SwIspStats *stats,
> +		     ControlList &metadata) override;
> +
> +private:
> +	ipa::Lux lux_;
> +};
> +
> +} /* namespace ipa::soft::algorithms */
> +} /* namespace libcamera */
> diff --git a/src/ipa/simple/algorithms/meson.build b/src/ipa/simple/algorithms/meson.build
> index 73c63722083ff92147253c6b10440ce50743988d..27e73c9a0eea2241cc4a4cefd1594c976fb59318 100644
> --- a/src/ipa/simple/algorithms/meson.build
> +++ b/src/ipa/simple/algorithms/meson.build
> @@ -6,4 +6,5 @@ soft_simple_ipa_algorithms = files([
>      'agc.cpp',
>      'blc.cpp',
>      'ccm.cpp',
> +    'lux.cpp',
>  ])
> diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h
> index 8ccfacb46a59cedb5a0ad051d67f7c1f40af4b52..2bd7c4642b118d7bb94b1b16cdf4ede5fb2554b5 100644
> --- a/src/ipa/simple/ipa_context.h
> +++ b/src/ipa/simple/ipa_context.h
> @@ -17,6 +17,7 @@
>  #include "libcamera/internal/vector.h"
>  
>  #include <libipa/fc_queue.h>
> +#include <libipa/lux.h>
>  
>  #include "core_ipa_interface.h"
>  
> @@ -36,6 +37,8 @@ struct IPASessionConfiguration {
>  };
>  
>  struct IPAActiveState {
> +	ipa::lux::ActiveState lux;
> +
>  	struct {
>  		int32_t exposure;
>  		double again;
> @@ -64,6 +67,8 @@ struct IPAActiveState {
>  };
>  
>  struct IPAFrameContext : public FrameContext {
> +	ipa::lux::FrameContext lux;
> +
>  	Matrix<float, 3, 3> ccm;
>  
>  	struct {
Kieran Bingham Nov. 17, 2026, 2:53 p.m. UTC | #7
Quoting Keith Carter (2026-11-17 06:40:19)
> Hi Kiernan,
> 
> Are you planning an updated version of the SoftIPA Lux patches (06/13
> and 07/13)?   https://patchwork.libcamera.org/patch/26491/
> 
> I'm new to the list. I run the OV5675 on an MSI Prestige 13 AI+ Evo
> (Intel IPU7, Lunar Lake) through the simple pipeline and the soft ISP,
> and today I posted a tuning file for it:
> https://patchwork.libcamera.org/patch/28936/
> 
> The file fixes color and the dark corners, but dim rooms stay dark:
> without a Lux algorithm the soft ISP's lux stays at its default, so
> the low-light end of relativeLuminanceTarget never applies.
> 
> As reference for the changes, please see this repo that includes the
> scripts, measurements and dated steps are at
> https://github.com/cartek99/msi-prestige-evo-camera
> 
> 
> Barnabás's v5 series turns the libipa Lux into an algorithm (patch
> 28923), which may change how softisp Lux plugs in. 
> 
> If there's an update I can test it by day and in the evening and send
> you the numbers.

Oh good spot. Yes, Barnabás' work makes this very easy to revive and add.

I've done a quick compile-tested only version on top of his patches at:

  https://git.ideasonboard.com/kbingham/libcamera/pulls/40

- https://git.ideasonboard.com/kbingham/libcamera/pulls/40/commits/6f3d5c6b5455a606e8c98677a6e5fd672935216d

But I haven't tested it. Please have a look at let me know. Once
Barnabás' work lands I'll post it to the list.

--
Kieran



> I'm open to assist!
> 
> 
> Sincerely,
> 
> Keith
> 
> On 8/4/26 06:01, Kieran Bingham wrote:
> > Utilise the lux component of libipa to map in the lux estimate
> > process using the yHistgram of the Soft ISP statistics.
> > 
> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > ---
> >  src/ipa/simple/algorithms/lux.cpp     | 93 +++++++++++++++++++++++++++++++++++
> >  src/ipa/simple/algorithms/lux.h       | 39 +++++++++++++++
> >  src/ipa/simple/algorithms/meson.build |  1 +
> >  src/ipa/simple/ipa_context.h          |  5 ++
> >  4 files changed, 138 insertions(+)
> > 
> > diff --git a/src/ipa/simple/algorithms/lux.cpp b/src/ipa/simple/algorithms/lux.cpp
> > new file mode 100644
> > index 0000000000000000000000000000000000000000..03b44ac584ae141509e79954159272504cdba17d
> > --- /dev/null
> > +++ b/src/ipa/simple/algorithms/lux.cpp
> > @@ -0,0 +1,93 @@
> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> > +/*
> > + * Copyright (C) 2024, Ideas On Board
> > + *
> > + * Simple Lux control
> > + */
> > +
> > +#include "lux.h"
> > +
> > +#include <libcamera/base/log.h>
> > +
> > +#include <libcamera/control_ids.h>
> > +
> > +#include "libipa/histogram.h"
> > +#include "libipa/lux.h"
> > +
> > +/**
> > + * \file lux.h
> > + */
> > +
> > +namespace libcamera {
> > +
> > +namespace ipa::soft::algorithms {
> > +
> > +/**
> > + * \class Lux
> > + * \brief SoftISP Lux control
> > + *
> > + * The Lux algorithm is responsible for estimating the lux level of the image.
> > + * It doesn't take or generate any controls, but it provides a lux level for
> > + * other algorithms (such as AGC) to use.
> > + */
> > +
> > +/**
> > + * \brief Construct a SoftISP Lux algo module
> > + */
> > +Lux::Lux()
> > +{
> > +}
> > +
> > +/**
> > + * \copydoc libcamera::ipa::Algorithm::init
> > + */
> > +int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)
> > +{
> > +     return lux_.parseTuningData(tuningData);
> > +}
> > +
> > +/**
> > + * \copydoc libcamera::ipa::Algorithm::prepare
> > + */
> > +void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,
> > +               IPAFrameContext &frameContext,
> > +               [[maybe_unused]] DebayerParams *params)
> > +{
> > +     frameContext.lux.lux = context.activeState.lux.lux;
> > +}
> > +
> > +/**
> > + * \copydoc libcamera::ipa::Algorithm::process
> > + */
> > +void Lux::process(IPAContext &context,
> > +               [[maybe_unused]] const uint32_t frame,
> > +               IPAFrameContext &frameContext,
> > +               const SwIspStats *stats,
> > +               ControlList &metadata)
> > +{
> > +     /*
> > +      * Report the lux level used by algorithms to prepare this frame
> > +      * not the lux level *of* this frame.
> > +      */
> > +     metadata.set(controls::Lux, frameContext.lux.lux);
> > +
> > +     if (!stats)
> > +             return;
> > +
> > +     /* Todo: Sensor configuration should move out of AGC */
> > +     utils::Duration exposureTime = context.configuration.agc.lineDuration *
> > +                                    frameContext.sensor.exposure;
> > +     double gain = frameContext.sensor.gain;
> > +     double digitalGain = 1.0;
> > +
> > +     Histogram yHist(stats->yHistogram);
> > +
> > +     context.activeState.lux.lux =
> > +             lux_.estimateLux(exposureTime, gain, digitalGain, yHist);
> > +}
> > +
> > +REGISTER_IPA_ALGORITHM(Lux, "Lux")
> > +
> > +} /* namespace ipa::soft::algorithms */
> > +
> > +} /* namespace libcamera */
> > diff --git a/src/ipa/simple/algorithms/lux.h b/src/ipa/simple/algorithms/lux.h
> > new file mode 100644
> > index 0000000000000000000000000000000000000000..04ec4c163ede422369977017cca70d12a8d361fb
> > --- /dev/null
> > +++ b/src/ipa/simple/algorithms/lux.h
> > @@ -0,0 +1,39 @@
> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> > +/*
> > + * Copyright (C) 2024, Ideas On Board
> > + *
> > + * Simple Lux control
> > + */
> > +
> > +#pragma once
> > +
> > +#include <sys/types.h>
> > +
> > +#include "libipa/lux.h"
> > +
> > +#include "algorithm.h"
> > +
> > +namespace libcamera {
> > +
> > +namespace ipa::soft::algorithms {
> > +
> > +class Lux : public Algorithm
> > +{
> > +public:
> > +     Lux();
> > +
> > +     int init(IPAContext &context, const YamlObject &tuningData) override;
> > +     void prepare(IPAContext &context, const uint32_t frame,
> > +                  IPAFrameContext &frameContext,
> > +                  DebayerParams *params) override;
> > +     void process(IPAContext &context, const uint32_t frame,
> > +                  IPAFrameContext &frameContext,
> > +                  const SwIspStats *stats,
> > +                  ControlList &metadata) override;
> > +
> > +private:
> > +     ipa::Lux lux_;
> > +};
> > +
> > +} /* namespace ipa::soft::algorithms */
> > +} /* namespace libcamera */
> > diff --git a/src/ipa/simple/algorithms/meson.build b/src/ipa/simple/algorithms/meson.build
> > index 73c63722083ff92147253c6b10440ce50743988d..27e73c9a0eea2241cc4a4cefd1594c976fb59318 100644
> > --- a/src/ipa/simple/algorithms/meson.build
> > +++ b/src/ipa/simple/algorithms/meson.build
> > @@ -6,4 +6,5 @@ soft_simple_ipa_algorithms = files([
> >      'agc.cpp',
> >      'blc.cpp',
> >      'ccm.cpp',
> > +    'lux.cpp',
> >  ])
> > diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h
> > index 8ccfacb46a59cedb5a0ad051d67f7c1f40af4b52..2bd7c4642b118d7bb94b1b16cdf4ede5fb2554b5 100644
> > --- a/src/ipa/simple/ipa_context.h
> > +++ b/src/ipa/simple/ipa_context.h
> > @@ -17,6 +17,7 @@
> >  #include "libcamera/internal/vector.h"
> >  
> >  #include <libipa/fc_queue.h>
> > +#include <libipa/lux.h>
> >  
> >  #include "core_ipa_interface.h"
> >  
> > @@ -36,6 +37,8 @@ struct IPASessionConfiguration {
> >  };
> >  
> >  struct IPAActiveState {
> > +     ipa::lux::ActiveState lux;
> > +
> >       struct {
> >               int32_t exposure;
> >               double again;
> > @@ -64,6 +67,8 @@ struct IPAActiveState {
> >  };
> >  
> >  struct IPAFrameContext : public FrameContext {
> > +     ipa::lux::FrameContext lux;
> > +
> >       Matrix<float, 3, 3> ccm;
> >  
> >       struct {
>
Keith Carter Nov. 18, 2026, 12:33 a.m. UTC | #8
Hi Kiernan,
Thanks for turning this around so quickly. I built your branch with my
OV5675 tuning file and ran it on the laptop today. Short version: it
works. Lux reports on every frame, the numbers follow the room, and in
daylight the picture stays the same, which is what I expected. It
builds without warnings and meson test passes (47 OK, 0 fail).

For the reference values I borrowed the libipa example and scaled
referenceLux to 354, so the estimate matched my phone's light meter
(178-215 lux at the laptop). Then I ran each scene twice on the same
build, once with the tuning file as posted and once with the Lux block
added (cam, 1920x1080, locked to 30 fps):

  Scene                       Lux (median)   Mean Y, no Lux / Lux
  Me at the desk, uncalib.    554            108.3 / 108.4
  Me at the desk              203                - / 102.7
  Empty room, ceiling light   263            120.6 / 120.5
  Me at the desk              218            115.3 / 113.3

I shifted in my chair between the last two runs, hence the small gap.
Color stayed within 0.006 in R/G and B/G throughout.

Two things I noticed:

- The first frame reports Lux = 0, before there is an estimate.
- For the first 15 frames or so the estimate jumps to about double
  while AGC hunts between gain 1.0 and 2.2. AGC does the same without
  Lux, so I suspect the sensor delays (the log says "No sensor delays
  found in static properties. Assuming unverified defaults.") rather
  than your code.

All the daylight runs share one room, so they only show the scaling
took effect. Tonight I'll repeat them in a dim room with a fresh phone
reading. That's where the lux curve should lift the picture. For the
test I use relativeLuminanceTarget [ 0, 0.32, 50, 0.26, 200, 0.16 ];
it isn't in my posted patch. I'll send those numbers, andand I'll 
test it again when you post it.

As in my patch: I use an AI assistant (Claude Code) for the builds, and the
analysis/ The tests run on my laptop and I check the results myself.

On 17/11/26 22:53, Kieran Bingham wrote:
> Quoting Keith Carter (2026-11-17 06:40:19)
>> Hi Kiernan,
>>
>> Are you planning an updated version of the SoftIPA Lux patches (06/13
>> and 07/13)?   https://patchwork.libcamera.org/patch/26491/
>>
>> I'm new to the list. I run the OV5675 on an MSI Prestige 13 AI+ Evo
>> (Intel IPU7, Lunar Lake) through the simple pipeline and the soft ISP,
>> and today I posted a tuning file for it:
>> https://patchwork.libcamera.org/patch/28936/
>>
>> The file fixes color and the dark corners, but dim rooms stay dark:
>> without a Lux algorithm the soft ISP's lux stays at its default, so
>> the low-light end of relativeLuminanceTarget never applies.
>>
>> As reference for the changes, please see this repo that includes the
>> scripts, measurements and dated steps are at
>> https://github.com/cartek99/msi-prestige-evo-camera
>>
>>
>> Barnabás's v5 series turns the libipa Lux into an algorithm (patch
>> 28923), which may change how softisp Lux plugs in. 
>>
>> If there's an update I can test it by day and in the evening and send
>> you the numbers.
> 
> Oh good spot. Yes, Barnabás' work makes this very easy to revive and add.
> 
> I've done a quick compile-tested only version on top of his patches at:
> 
>   https://git.ideasonboard.com/kbingham/libcamera/pulls/40
> 
> - https://git.ideasonboard.com/kbingham/libcamera/pulls/40/commits/6f3d5c6b5455a606e8c98677a6e5fd672935216d
> 
> But I haven't tested it. Please have a look at let me know. Once
> Barnabás' work lands I'll post it to the list.
> 
> --
> Kieran
> 
> 
> 
>> I'm open to assist!
>>
>>
>> Sincerely,
>>
>> Keith
>>
>> On 8/4/26 06:01, Kieran Bingham wrote:
>>> Utilise the lux component of libipa to map in the lux estimate
>>> process using the yHistgram of the Soft ISP statistics.
>>>
>>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>>> ---
>>>  src/ipa/simple/algorithms/lux.cpp     | 93 +++++++++++++++++++++++++++++++++++
>>>  src/ipa/simple/algorithms/lux.h       | 39 +++++++++++++++
>>>  src/ipa/simple/algorithms/meson.build |  1 +
>>>  src/ipa/simple/ipa_context.h          |  5 ++
>>>  4 files changed, 138 insertions(+)
>>>
>>> diff --git a/src/ipa/simple/algorithms/lux.cpp b/src/ipa/simple/algorithms/lux.cpp
>>> new file mode 100644
>>> index 0000000000000000000000000000000000000000..03b44ac584ae141509e79954159272504cdba17d
>>> --- /dev/null
>>> +++ b/src/ipa/simple/algorithms/lux.cpp
>>> @@ -0,0 +1,93 @@
>>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
>>> +/*
>>> + * Copyright (C) 2024, Ideas On Board
>>> + *
>>> + * Simple Lux control
>>> + */
>>> +
>>> +#include "lux.h"
>>> +
>>> +#include <libcamera/base/log.h>
>>> +
>>> +#include <libcamera/control_ids.h>
>>> +
>>> +#include "libipa/histogram.h"
>>> +#include "libipa/lux.h"
>>> +
>>> +/**
>>> + * \file lux.h
>>> + */
>>> +
>>> +namespace libcamera {
>>> +
>>> +namespace ipa::soft::algorithms {
>>> +
>>> +/**
>>> + * \class Lux
>>> + * \brief SoftISP Lux control
>>> + *
>>> + * The Lux algorithm is responsible for estimating the lux level of the image.
>>> + * It doesn't take or generate any controls, but it provides a lux level for
>>> + * other algorithms (such as AGC) to use.
>>> + */
>>> +
>>> +/**
>>> + * \brief Construct a SoftISP Lux algo module
>>> + */
>>> +Lux::Lux()
>>> +{
>>> +}
>>> +
>>> +/**
>>> + * \copydoc libcamera::ipa::Algorithm::init
>>> + */
>>> +int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)
>>> +{
>>> +     return lux_.parseTuningData(tuningData);
>>> +}
>>> +
>>> +/**
>>> + * \copydoc libcamera::ipa::Algorithm::prepare
>>> + */
>>> +void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,
>>> +               IPAFrameContext &frameContext,
>>> +               [[maybe_unused]] DebayerParams *params)
>>> +{
>>> +     frameContext.lux.lux = context.activeState.lux.lux;
>>> +}
>>> +
>>> +/**
>>> + * \copydoc libcamera::ipa::Algorithm::process
>>> + */
>>> +void Lux::process(IPAContext &context,
>>> +               [[maybe_unused]] const uint32_t frame,
>>> +               IPAFrameContext &frameContext,
>>> +               const SwIspStats *stats,
>>> +               ControlList &metadata)
>>> +{
>>> +     /*
>>> +      * Report the lux level used by algorithms to prepare this frame
>>> +      * not the lux level *of* this frame.
>>> +      */
>>> +     metadata.set(controls::Lux, frameContext.lux.lux);
>>> +
>>> +     if (!stats)
>>> +             return;
>>> +
>>> +     /* Todo: Sensor configuration should move out of AGC */
>>> +     utils::Duration exposureTime = context.configuration.agc.lineDuration *
>>> +                                    frameContext.sensor.exposure;
>>> +     double gain = frameContext.sensor.gain;
>>> +     double digitalGain = 1.0;
>>> +
>>> +     Histogram yHist(stats->yHistogram);
>>> +
>>> +     context.activeState.lux.lux =
>>> +             lux_.estimateLux(exposureTime, gain, digitalGain, yHist);
>>> +}
>>> +
>>> +REGISTER_IPA_ALGORITHM(Lux, "Lux")
>>> +
>>> +} /* namespace ipa::soft::algorithms */
>>> +
>>> +} /* namespace libcamera */
>>> diff --git a/src/ipa/simple/algorithms/lux.h b/src/ipa/simple/algorithms/lux.h
>>> new file mode 100644
>>> index 0000000000000000000000000000000000000000..04ec4c163ede422369977017cca70d12a8d361fb
>>> --- /dev/null
>>> +++ b/src/ipa/simple/algorithms/lux.h
>>> @@ -0,0 +1,39 @@
>>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
>>> +/*
>>> + * Copyright (C) 2024, Ideas On Board
>>> + *
>>> + * Simple Lux control
>>> + */
>>> +
>>> +#pragma once
>>> +
>>> +#include <sys/types.h>
>>> +
>>> +#include "libipa/lux.h"
>>> +
>>> +#include "algorithm.h"
>>> +
>>> +namespace libcamera {
>>> +
>>> +namespace ipa::soft::algorithms {
>>> +
>>> +class Lux : public Algorithm
>>> +{
>>> +public:
>>> +     Lux();
>>> +
>>> +     int init(IPAContext &context, const YamlObject &tuningData) override;
>>> +     void prepare(IPAContext &context, const uint32_t frame,
>>> +                  IPAFrameContext &frameContext,
>>> +                  DebayerParams *params) override;
>>> +     void process(IPAContext &context, const uint32_t frame,
>>> +                  IPAFrameContext &frameContext,
>>> +                  const SwIspStats *stats,
>>> +                  ControlList &metadata) override;
>>> +
>>> +private:
>>> +     ipa::Lux lux_;
>>> +};
>>> +
>>> +} /* namespace ipa::soft::algorithms */
>>> +} /* namespace libcamera */
>>> diff --git a/src/ipa/simple/algorithms/meson.build b/src/ipa/simple/algorithms/meson.build
>>> index 73c63722083ff92147253c6b10440ce50743988d..27e73c9a0eea2241cc4a4cefd1594c976fb59318 100644
>>> --- a/src/ipa/simple/algorithms/meson.build
>>> +++ b/src/ipa/simple/algorithms/meson.build
>>> @@ -6,4 +6,5 @@ soft_simple_ipa_algorithms = files([
>>>      'agc.cpp',
>>>      'blc.cpp',
>>>      'ccm.cpp',
>>> +    'lux.cpp',
>>>  ])
>>> diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h
>>> index 8ccfacb46a59cedb5a0ad051d67f7c1f40af4b52..2bd7c4642b118d7bb94b1b16cdf4ede5fb2554b5 100644
>>> --- a/src/ipa/simple/ipa_context.h
>>> +++ b/src/ipa/simple/ipa_context.h
>>> @@ -17,6 +17,7 @@
>>>  #include "libcamera/internal/vector.h"
>>>  
>>>  #include <libipa/fc_queue.h>
>>> +#include <libipa/lux.h>
>>>  
>>>  #include "core_ipa_interface.h"
>>>  
>>> @@ -36,6 +37,8 @@ struct IPASessionConfiguration {
>>>  };
>>>  
>>>  struct IPAActiveState {
>>> +     ipa::lux::ActiveState lux;
>>> +
>>>       struct {
>>>               int32_t exposure;
>>>               double again;
>>> @@ -64,6 +67,8 @@ struct IPAActiveState {
>>>  };
>>>  
>>>  struct IPAFrameContext : public FrameContext {
>>> +     ipa::lux::FrameContext lux;
>>> +
>>>       Matrix<float, 3, 3> ccm;
>>>  
>>>       struct {
>>
Keith Carter Nov. 18, 2026, 3:33 p.m. UTC | #9
Hi Kieran,

Here are the evening numbers I promised. Same build, same two tuning
files, two light levels. For each one I held my phone at the laptop,
facing the room, and noted its reading:

  Light (phone)           Scene   Lux     Mean Y          Gain
                                  (med.)  no Lux / Lux    no Lux / Lux
  ~90 lux, ceiling light  empty   44      133.4 / 162.7   10.6 / 16.0
  ~90 lux, ceiling light  me      39      146.6 / 166.9   11.8 / 16.0
  ~8 lux, lamp in view    empty   57       83.1 /  83.1    6.6 /  6.7
  ~8 lux, lamp in view    me      44       83.8 /  84.6    8.1 /  8.1

The good news first: Lux reaches AGC and it works. In the lit room AGC
hit the higher target from my test curve (0.268 instead of 0.16) and
the picture got brighter. Colour stayed within 0.02 in R/G and B/G in
every run.

Three limits showed up. None of them looks like your code:

- That lift used all the gain there was. Gain went to 16, the maximum,
  and at 30 fps exposure can't go past 33.6 ms. A darker room with
  nothing bright in view would get no extra brightness.

- The upper constraint (brightest 2% at most 0.9) caps the gain when
  something bright is in the frame. My white shirt did it in row 2
  (only with Lux). The fan lamp behind me did it in rows 3 and 4, with
  and without Lux, so those pictures came out the same.

- The estimate goes up when a lamp is in view: 57 at ~8 lux, against
  44 at ~90 lux. I think that's because it uses the mean of the whole
  image. Against the phone it read 1.0 in daylight (where I calibrated
  it), 0.45 in the lit room and about 7 with the lamp. With the lamp it
  also took about 45 frames to settle instead of 15. The phone measures
  the light reaching it, not the scene, so treat these ratios as rough.


The brighter picture costs noise: speckle went from 0.45% to 0.67% in
row 1, since all the extra brightness came from gain. The soft ISP has
no despeckle step yet, so my tuning patch keeps a constant target for
now.

Locally I reduced the speckle with a small 3x3 selective median shader
  after the pipeline. I haven't tried it inside the soft ISP's GPU path.

Sincerely,

Keith

On 18/11/26 08:33, Keith Carter wrote:
> Hi Kiernan,
> Thanks for turning this around so quickly. I built your branch with my
> OV5675 tuning file and ran it on the laptop today. Short version: it
> works. Lux reports on every frame, the numbers follow the room, and in
> daylight the picture stays the same, which is what I expected. It
> builds without warnings and meson test passes (47 OK, 0 fail).
> 
> For the reference values I borrowed the libipa example and scaled
> referenceLux to 354, so the estimate matched my phone's light meter
> (178-215 lux at the laptop). Then I ran each scene twice on the same
> build, once with the tuning file as posted and once with the Lux block
> added (cam, 1920x1080, locked to 30 fps):
> 
>   Scene                       Lux (median)   Mean Y, no Lux / Lux
>   Me at the desk, uncalib.    554            108.3 / 108.4
>   Me at the desk              203                - / 102.7
>   Empty room, ceiling light   263            120.6 / 120.5
>   Me at the desk              218            115.3 / 113.3
> 
> I shifted in my chair between the last two runs, hence the small gap.
> Color stayed within 0.006 in R/G and B/G throughout.
> 
> Two things I noticed:
> 
> - The first frame reports Lux = 0, before there is an estimate.
> - For the first 15 frames or so the estimate jumps to about double
>   while AGC hunts between gain 1.0 and 2.2. AGC does the same without
>   Lux, so I suspect the sensor delays (the log says "No sensor delays
>   found in static properties. Assuming unverified defaults.") rather
>   than your code.
> 
> All the daylight runs share one room, so they only show the scaling
> took effect. Tonight I'll repeat them in a dim room with a fresh phone
> reading. That's where the lux curve should lift the picture. For the
> test I use relativeLuminanceTarget [ 0, 0.32, 50, 0.26, 200, 0.16 ];
> it isn't in my posted patch. I'll send those numbers, andand I'll 
> test it again when you post it.
> 
> As in my patch: I use an AI assistant (Claude Code) for the builds, and the
> analysis/ The tests run on my laptop and I check the results myself.
> 
> On 17/11/26 22:53, Kieran Bingham wrote:
>> Quoting Keith Carter (2026-11-17 06:40:19)
>>> Hi Kiernan,
>>>
>>> Are you planning an updated version of the SoftIPA Lux patches (06/13
>>> and 07/13)?   https://patchwork.libcamera.org/patch/26491/
>>>
>>> I'm new to the list. I run the OV5675 on an MSI Prestige 13 AI+ Evo
>>> (Intel IPU7, Lunar Lake) through the simple pipeline and the soft ISP,
>>> and today I posted a tuning file for it:
>>> https://patchwork.libcamera.org/patch/28936/
>>>
>>> The file fixes color and the dark corners, but dim rooms stay dark:
>>> without a Lux algorithm the soft ISP's lux stays at its default, so
>>> the low-light end of relativeLuminanceTarget never applies.
>>>
>>> As reference for the changes, please see this repo that includes the
>>> scripts, measurements and dated steps are at
>>> https://github.com/cartek99/msi-prestige-evo-camera
>>>
>>>
>>> Barnabás's v5 series turns the libipa Lux into an algorithm (patch
>>> 28923), which may change how softisp Lux plugs in. 
>>>
>>> If there's an update I can test it by day and in the evening and send
>>> you the numbers.
>>
>> Oh good spot. Yes, Barnabás' work makes this very easy to revive and add.
>>
>> I've done a quick compile-tested only version on top of his patches at:
>>
>>   https://git.ideasonboard.com/kbingham/libcamera/pulls/40
>>
>> - https://git.ideasonboard.com/kbingham/libcamera/pulls/40/commits/6f3d5c6b5455a606e8c98677a6e5fd672935216d
>>
>> But I haven't tested it. Please have a look at let me know. Once
>> Barnabás' work lands I'll post it to the list.
>>
>> --
>> Kieran
>>
>>
>>
>>> I'm open to assist!
>>>
>>>
>>> Sincerely,
>>>
>>> Keith
>>>
>>> On 8/4/26 06:01, Kieran Bingham wrote:
>>>> Utilise the lux component of libipa to map in the lux estimate
>>>> process using the yHistgram of the Soft ISP statistics.
>>>>
>>>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>>>> ---
>>>>  src/ipa/simple/algorithms/lux.cpp     | 93 +++++++++++++++++++++++++++++++++++
>>>>  src/ipa/simple/algorithms/lux.h       | 39 +++++++++++++++
>>>>  src/ipa/simple/algorithms/meson.build |  1 +
>>>>  src/ipa/simple/ipa_context.h          |  5 ++
>>>>  4 files changed, 138 insertions(+)
>>>>
>>>> diff --git a/src/ipa/simple/algorithms/lux.cpp b/src/ipa/simple/algorithms/lux.cpp
>>>> new file mode 100644
>>>> index 0000000000000000000000000000000000000000..03b44ac584ae141509e79954159272504cdba17d
>>>> --- /dev/null
>>>> +++ b/src/ipa/simple/algorithms/lux.cpp
>>>> @@ -0,0 +1,93 @@
>>>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
>>>> +/*
>>>> + * Copyright (C) 2024, Ideas On Board
>>>> + *
>>>> + * Simple Lux control
>>>> + */
>>>> +
>>>> +#include "lux.h"
>>>> +
>>>> +#include <libcamera/base/log.h>
>>>> +
>>>> +#include <libcamera/control_ids.h>
>>>> +
>>>> +#include "libipa/histogram.h"
>>>> +#include "libipa/lux.h"
>>>> +
>>>> +/**
>>>> + * \file lux.h
>>>> + */
>>>> +
>>>> +namespace libcamera {
>>>> +
>>>> +namespace ipa::soft::algorithms {
>>>> +
>>>> +/**
>>>> + * \class Lux
>>>> + * \brief SoftISP Lux control
>>>> + *
>>>> + * The Lux algorithm is responsible for estimating the lux level of the image.
>>>> + * It doesn't take or generate any controls, but it provides a lux level for
>>>> + * other algorithms (such as AGC) to use.
>>>> + */
>>>> +
>>>> +/**
>>>> + * \brief Construct a SoftISP Lux algo module
>>>> + */
>>>> +Lux::Lux()
>>>> +{
>>>> +}
>>>> +
>>>> +/**
>>>> + * \copydoc libcamera::ipa::Algorithm::init
>>>> + */
>>>> +int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)
>>>> +{
>>>> +     return lux_.parseTuningData(tuningData);
>>>> +}
>>>> +
>>>> +/**
>>>> + * \copydoc libcamera::ipa::Algorithm::prepare
>>>> + */
>>>> +void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,
>>>> +               IPAFrameContext &frameContext,
>>>> +               [[maybe_unused]] DebayerParams *params)
>>>> +{
>>>> +     frameContext.lux.lux = context.activeState.lux.lux;
>>>> +}
>>>> +
>>>> +/**
>>>> + * \copydoc libcamera::ipa::Algorithm::process
>>>> + */
>>>> +void Lux::process(IPAContext &context,
>>>> +               [[maybe_unused]] const uint32_t frame,
>>>> +               IPAFrameContext &frameContext,
>>>> +               const SwIspStats *stats,
>>>> +               ControlList &metadata)
>>>> +{
>>>> +     /*
>>>> +      * Report the lux level used by algorithms to prepare this frame
>>>> +      * not the lux level *of* this frame.
>>>> +      */
>>>> +     metadata.set(controls::Lux, frameContext.lux.lux);
>>>> +
>>>> +     if (!stats)
>>>> +             return;
>>>> +
>>>> +     /* Todo: Sensor configuration should move out of AGC */
>>>> +     utils::Duration exposureTime = context.configuration.agc.lineDuration *
>>>> +                                    frameContext.sensor.exposure;
>>>> +     double gain = frameContext.sensor.gain;
>>>> +     double digitalGain = 1.0;
>>>> +
>>>> +     Histogram yHist(stats->yHistogram);
>>>> +
>>>> +     context.activeState.lux.lux =
>>>> +             lux_.estimateLux(exposureTime, gain, digitalGain, yHist);
>>>> +}
>>>> +
>>>> +REGISTER_IPA_ALGORITHM(Lux, "Lux")
>>>> +
>>>> +} /* namespace ipa::soft::algorithms */
>>>> +
>>>> +} /* namespace libcamera */
>>>> diff --git a/src/ipa/simple/algorithms/lux.h b/src/ipa/simple/algorithms/lux.h
>>>> new file mode 100644
>>>> index 0000000000000000000000000000000000000000..04ec4c163ede422369977017cca70d12a8d361fb
>>>> --- /dev/null
>>>> +++ b/src/ipa/simple/algorithms/lux.h
>>>> @@ -0,0 +1,39 @@
>>>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
>>>> +/*
>>>> + * Copyright (C) 2024, Ideas On Board
>>>> + *
>>>> + * Simple Lux control
>>>> + */
>>>> +
>>>> +#pragma once
>>>> +
>>>> +#include <sys/types.h>
>>>> +
>>>> +#include "libipa/lux.h"
>>>> +
>>>> +#include "algorithm.h"
>>>> +
>>>> +namespace libcamera {
>>>> +
>>>> +namespace ipa::soft::algorithms {
>>>> +
>>>> +class Lux : public Algorithm
>>>> +{
>>>> +public:
>>>> +     Lux();
>>>> +
>>>> +     int init(IPAContext &context, const YamlObject &tuningData) override;
>>>> +     void prepare(IPAContext &context, const uint32_t frame,
>>>> +                  IPAFrameContext &frameContext,
>>>> +                  DebayerParams *params) override;
>>>> +     void process(IPAContext &context, const uint32_t frame,
>>>> +                  IPAFrameContext &frameContext,
>>>> +                  const SwIspStats *stats,
>>>> +                  ControlList &metadata) override;
>>>> +
>>>> +private:
>>>> +     ipa::Lux lux_;
>>>> +};
>>>> +
>>>> +} /* namespace ipa::soft::algorithms */
>>>> +} /* namespace libcamera */
>>>> diff --git a/src/ipa/simple/algorithms/meson.build b/src/ipa/simple/algorithms/meson.build
>>>> index 73c63722083ff92147253c6b10440ce50743988d..27e73c9a0eea2241cc4a4cefd1594c976fb59318 100644
>>>> --- a/src/ipa/simple/algorithms/meson.build
>>>> +++ b/src/ipa/simple/algorithms/meson.build
>>>> @@ -6,4 +6,5 @@ soft_simple_ipa_algorithms = files([
>>>>      'agc.cpp',
>>>>      'blc.cpp',
>>>>      'ccm.cpp',
>>>> +    'lux.cpp',
>>>>  ])
>>>> diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h
>>>> index 8ccfacb46a59cedb5a0ad051d67f7c1f40af4b52..2bd7c4642b118d7bb94b1b16cdf4ede5fb2554b5 100644
>>>> --- a/src/ipa/simple/ipa_context.h
>>>> +++ b/src/ipa/simple/ipa_context.h
>>>> @@ -17,6 +17,7 @@
>>>>  #include "libcamera/internal/vector.h"
>>>>  
>>>>  #include <libipa/fc_queue.h>
>>>> +#include <libipa/lux.h>
>>>>  
>>>>  #include "core_ipa_interface.h"
>>>>  
>>>> @@ -36,6 +37,8 @@ struct IPASessionConfiguration {
>>>>  };
>>>>  
>>>>  struct IPAActiveState {
>>>> +     ipa::lux::ActiveState lux;
>>>> +
>>>>       struct {
>>>>               int32_t exposure;
>>>>               double again;
>>>> @@ -64,6 +67,8 @@ struct IPAActiveState {
>>>>  };
>>>>  
>>>>  struct IPAFrameContext : public FrameContext {
>>>> +     ipa::lux::FrameContext lux;
>>>> +
>>>>       Matrix<float, 3, 3> ccm;
>>>>  
>>>>       struct {
>>>
>

Patch
diff mbox series

diff --git a/src/ipa/simple/algorithms/lux.cpp b/src/ipa/simple/algorithms/lux.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..03b44ac584ae141509e79954159272504cdba17d
--- /dev/null
+++ b/src/ipa/simple/algorithms/lux.cpp
@@ -0,0 +1,93 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2024, Ideas On Board
+ *
+ * Simple Lux control
+ */
+
+#include "lux.h"
+
+#include <libcamera/base/log.h>
+
+#include <libcamera/control_ids.h>
+
+#include "libipa/histogram.h"
+#include "libipa/lux.h"
+
+/**
+ * \file lux.h
+ */
+
+namespace libcamera {
+
+namespace ipa::soft::algorithms {
+
+/**
+ * \class Lux
+ * \brief SoftISP Lux control
+ *
+ * The Lux algorithm is responsible for estimating the lux level of the image.
+ * It doesn't take or generate any controls, but it provides a lux level for
+ * other algorithms (such as AGC) to use.
+ */
+
+/**
+ * \brief Construct a SoftISP Lux algo module
+ */
+Lux::Lux()
+{
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::init
+ */
+int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)
+{
+	return lux_.parseTuningData(tuningData);
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::prepare
+ */
+void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,
+		  IPAFrameContext &frameContext,
+		  [[maybe_unused]] DebayerParams *params)
+{
+	frameContext.lux.lux = context.activeState.lux.lux;
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::process
+ */
+void Lux::process(IPAContext &context,
+		  [[maybe_unused]] const uint32_t frame,
+		  IPAFrameContext &frameContext,
+		  const SwIspStats *stats,
+		  ControlList &metadata)
+{
+	/*
+	 * Report the lux level used by algorithms to prepare this frame
+	 * not the lux level *of* this frame.
+	 */
+	metadata.set(controls::Lux, frameContext.lux.lux);
+
+	if (!stats)
+		return;
+
+	/* Todo: Sensor configuration should move out of AGC */
+	utils::Duration exposureTime = context.configuration.agc.lineDuration *
+				       frameContext.sensor.exposure;
+	double gain = frameContext.sensor.gain;
+	double digitalGain = 1.0;
+
+	Histogram yHist(stats->yHistogram);
+
+	context.activeState.lux.lux =
+		lux_.estimateLux(exposureTime, gain, digitalGain, yHist);
+}
+
+REGISTER_IPA_ALGORITHM(Lux, "Lux")
+
+} /* namespace ipa::soft::algorithms */
+
+} /* namespace libcamera */
diff --git a/src/ipa/simple/algorithms/lux.h b/src/ipa/simple/algorithms/lux.h
new file mode 100644
index 0000000000000000000000000000000000000000..04ec4c163ede422369977017cca70d12a8d361fb
--- /dev/null
+++ b/src/ipa/simple/algorithms/lux.h
@@ -0,0 +1,39 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2024, Ideas On Board
+ *
+ * Simple Lux control
+ */
+
+#pragma once
+
+#include <sys/types.h>
+
+#include "libipa/lux.h"
+
+#include "algorithm.h"
+
+namespace libcamera {
+
+namespace ipa::soft::algorithms {
+
+class Lux : public Algorithm
+{
+public:
+	Lux();
+
+	int init(IPAContext &context, const YamlObject &tuningData) override;
+	void prepare(IPAContext &context, const uint32_t frame,
+		     IPAFrameContext &frameContext,
+		     DebayerParams *params) override;
+	void process(IPAContext &context, const uint32_t frame,
+		     IPAFrameContext &frameContext,
+		     const SwIspStats *stats,
+		     ControlList &metadata) override;
+
+private:
+	ipa::Lux lux_;
+};
+
+} /* namespace ipa::soft::algorithms */
+} /* namespace libcamera */
diff --git a/src/ipa/simple/algorithms/meson.build b/src/ipa/simple/algorithms/meson.build
index 73c63722083ff92147253c6b10440ce50743988d..27e73c9a0eea2241cc4a4cefd1594c976fb59318 100644
--- a/src/ipa/simple/algorithms/meson.build
+++ b/src/ipa/simple/algorithms/meson.build
@@ -6,4 +6,5 @@  soft_simple_ipa_algorithms = files([
     'agc.cpp',
     'blc.cpp',
     'ccm.cpp',
+    'lux.cpp',
 ])
diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h
index 8ccfacb46a59cedb5a0ad051d67f7c1f40af4b52..2bd7c4642b118d7bb94b1b16cdf4ede5fb2554b5 100644
--- a/src/ipa/simple/ipa_context.h
+++ b/src/ipa/simple/ipa_context.h
@@ -17,6 +17,7 @@ 
 #include "libcamera/internal/vector.h"
 
 #include <libipa/fc_queue.h>
+#include <libipa/lux.h>
 
 #include "core_ipa_interface.h"
 
@@ -36,6 +37,8 @@  struct IPASessionConfiguration {
 };
 
 struct IPAActiveState {
+	ipa::lux::ActiveState lux;
+
 	struct {
 		int32_t exposure;
 		double again;
@@ -64,6 +67,8 @@  struct IPAActiveState {
 };
 
 struct IPAFrameContext : public FrameContext {
+	ipa::lux::FrameContext lux;
+
 	Matrix<float, 3, 3> ccm;
 
 	struct {