[v5,17/22] ipa: rppx1: Add lux estimation
diff mbox series

Message ID 20261116174919.1056403-18-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • libcamera: rcar-gen4 + rpp-x1
Related show

Commit Message

Barnabás Pőcze Nov. 16, 2026, 5:49 p.m. UTC
From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

Add the algorithm to the rppx1 ipa module based on the corresponding
algorithm in the rkisp1 ipa module.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 src/ipa/rppx1/algorithms/agc.cpp     |  1 +
 src/ipa/rppx1/algorithms/awb.cpp     |  2 +-
 src/ipa/rppx1/algorithms/lux.cpp     | 63 ++++++++++++++++++++++++++++
 src/ipa/rppx1/algorithms/lux.h       | 36 ++++++++++++++++
 src/ipa/rppx1/algorithms/meson.build |  1 +
 src/ipa/rppx1/ipa_context.h          |  5 +++
 6 files changed, 107 insertions(+), 1 deletion(-)
 create mode 100644 src/ipa/rppx1/algorithms/lux.cpp
 create mode 100644 src/ipa/rppx1/algorithms/lux.h

Comments

Kieran Bingham Nov. 16, 2026, 6:47 p.m. UTC | #1
Quoting Barnabás Pőcze (2026-11-16 17:49:13)
> From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> 
> Add the algorithm to the rppx1 ipa module based on the corresponding
> algorithm in the rkisp1 ipa module.
> 
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

Nice, all the implementation in libipa.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  src/ipa/rppx1/algorithms/agc.cpp     |  1 +
>  src/ipa/rppx1/algorithms/awb.cpp     |  2 +-
>  src/ipa/rppx1/algorithms/lux.cpp     | 63 ++++++++++++++++++++++++++++
>  src/ipa/rppx1/algorithms/lux.h       | 36 ++++++++++++++++
>  src/ipa/rppx1/algorithms/meson.build |  1 +
>  src/ipa/rppx1/ipa_context.h          |  5 +++
>  6 files changed, 107 insertions(+), 1 deletion(-)
>  create mode 100644 src/ipa/rppx1/algorithms/lux.cpp
>  create mode 100644 src/ipa/rppx1/algorithms/lux.h
> 
> diff --git a/src/ipa/rppx1/algorithms/agc.cpp b/src/ipa/rppx1/algorithms/agc.cpp
> index 22a3c7467b..38ea4de9ca 100644
> --- a/src/ipa/rppx1/algorithms/agc.cpp
> +++ b/src/ipa/rppx1/algorithms/agc.cpp
> @@ -314,6 +314,7 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,
>                         },
>                         .exposure = frameContext.sensor.exposure,
>                         .gain = frameContext.sensor.gain,
> +                       .lux = frameContext.lux.lux,
>                 }}, metadata);
>         } else {
>                 agc_.process(context.configuration.agc, context.activeState.agc, frameContext.agc, {}, metadata);
> diff --git a/src/ipa/rppx1/algorithms/awb.cpp b/src/ipa/rppx1/algorithms/awb.cpp
> index bd59d13ad5..7c748e9a2c 100644
> --- a/src/ipa/rppx1/algorithms/awb.cpp
> +++ b/src/ipa/rppx1/algorithms/awb.cpp
> @@ -190,7 +190,7 @@ void Awb::process(IPAContext &context,
>         RppX1AwbStats awbStats = calculateRgbMeans(frameContext, *awb);
>  
>         awbAlgo_.process(context.activeState.awb, frameContext.awb, awbStats,
> -                        0, metadata);
> +                        frameContext.lux.lux, metadata);
>  }
>  
>  RppX1AwbStats Awb::calculateRgbMeans(const IPAFrameContext &frameContext,
> diff --git a/src/ipa/rppx1/algorithms/lux.cpp b/src/ipa/rppx1/algorithms/lux.cpp
> new file mode 100644
> index 0000000000..56275d1973
> --- /dev/null
> +++ b/src/ipa/rppx1/algorithms/lux.cpp
> @@ -0,0 +1,63 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2026, Ideas On Board
> + *
> + * RPP-X1 lux estimation algorithm
> + */
> +
> +#include "lux.h"
> +
> +#include <libcamera/base/utils.h>
> +
> +#include <libcamera/control_ids.h>
> +
> +#include "libipa/histogram.h"
> +#include "libipa/lux.h"
> +
> +namespace libcamera {
> +
> +namespace ipa::rppx1::algorithms {
> +
> +int Lux::init([[maybe_unused]] IPAContext &context, const ValueNode &tuningData)
> +{
> +       return lux_.init(tuningData);
> +}
> +
> +void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,
> +                 IPAFrameContext &frameContext,
> +                 [[maybe_unused]] RppX1Params *params)
> +{
> +       lux_.prepare(context.activeState.lux, frameContext.lux);
> +}
> +
> +void Lux::process(IPAContext &context,
> +                 [[maybe_unused]] const uint32_t frame,
> +                 IPAFrameContext &frameContext,
> +                 const RppX1Stats *stats,
> +                 ControlList &metadata)
> +{
> +       const auto histPost = stats->block<StatsType::HistPost>();
> +       if (!histPost) {
> +               lux_.process(context.activeState.lux, frameContext.lux, metadata, {});
> +               return;
> +       }
> +
> +       lux_.process(context.activeState.lux, frameContext.lux, metadata,
> +                    { {
> +                            .exposureTime = context.configuration.agc.lineDuration *
> +                                            frameContext.sensor.exposure,
> +                            .analogueGain = frameContext.sensor.gain,
> +                            .digitalGain = 1,
> +                            /* \todo Deduplicate the histogram calculation from AGC */
> +                            .yHist = {
> +                                    histPost->hist_bins,
> +                                    [](uint32_t x) { return x >> 4; },
> +                            },
> +                    } });
> +}
> +
> +REGISTER_IPA_ALGORITHM(Lux, "Lux")
> +
> +} /* namespace ipa::rppx1::algorithms */
> +
> +} /* namespace libcamera */
> diff --git a/src/ipa/rppx1/algorithms/lux.h b/src/ipa/rppx1/algorithms/lux.h
> new file mode 100644
> index 0000000000..6c94f7507a
> --- /dev/null
> +++ b/src/ipa/rppx1/algorithms/lux.h
> @@ -0,0 +1,36 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2026, Ideas On Board
> + *
> + * RPP-X1 lux estimation algorithm
> + */
> +
> +#pragma once
> +
> +#include "libipa/lux.h"
> +
> +#include "algorithm.h"
> +
> +namespace libcamera {
> +
> +namespace ipa::rppx1::algorithms {
> +
> +class Lux : public Algorithm
> +{
> +public:
> +       int init(IPAContext &context, const ValueNode &tuningData) override;
> +       void prepare(IPAContext &context, const uint32_t frame,
> +                    IPAFrameContext &frameContext,
> +                    RppX1Params *params) override;
> +       void process(IPAContext &context, const uint32_t frame,
> +                    IPAFrameContext &frameContext,
> +                    const RppX1Stats *stats,
> +                    ControlList &metadata) override;
> +
> +private:
> +       ipa::LuxAlgorithm lux_;
> +};
> +
> +} /* namespace ipa::rppx1::algorithms */
> +
> +} /* namespace libcamera */
> diff --git a/src/ipa/rppx1/algorithms/meson.build b/src/ipa/rppx1/algorithms/meson.build
> index 4a2c1b52dd..19688854a3 100644
> --- a/src/ipa/rppx1/algorithms/meson.build
> +++ b/src/ipa/rppx1/algorithms/meson.build
> @@ -4,4 +4,5 @@ rppx1_ipa_algorithms = files([
>      'agc.cpp',
>      'awb.cpp',
>      'blc.cpp',
> +    'lux.cpp',
>  ])
> diff --git a/src/ipa/rppx1/ipa_context.h b/src/ipa/rppx1/ipa_context.h
> index 24fbbfaa28..baa82d5f3b 100644
> --- a/src/ipa/rppx1/ipa_context.h
> +++ b/src/ipa/rppx1/ipa_context.h
> @@ -20,6 +20,7 @@
>  #include <libipa/awb.h>
>  #include <libipa/camera_sensor_helper.h>
>  #include <libipa/fc_queue.h>
> +#include <libipa/lux.h>
>  
>  namespace libcamera {
>  
> @@ -42,6 +43,8 @@ struct IPAActiveState {
>         } agc;
>  
>         ipa::awb::ActiveState awb;
> +
> +       ipa::lux::ActiveState lux;
>  };
>  
>  struct IPAFrameContext : public FrameContext {
> @@ -56,6 +59,8 @@ struct IPAFrameContext : public FrameContext {
>         } agc;
>  
>         ipa::awb::FrameContext awb;
> +
> +       ipa::lux::FrameContext lux;
>  };
>  
>  struct IPAContext {
> -- 
> 2.56.1
>

Patch
diff mbox series

diff --git a/src/ipa/rppx1/algorithms/agc.cpp b/src/ipa/rppx1/algorithms/agc.cpp
index 22a3c7467b..38ea4de9ca 100644
--- a/src/ipa/rppx1/algorithms/agc.cpp
+++ b/src/ipa/rppx1/algorithms/agc.cpp
@@ -314,6 +314,7 @@  void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,
 			},
 			.exposure = frameContext.sensor.exposure,
 			.gain = frameContext.sensor.gain,
+			.lux = frameContext.lux.lux,
 		}}, metadata);
 	} else {
 		agc_.process(context.configuration.agc, context.activeState.agc, frameContext.agc, {}, metadata);
diff --git a/src/ipa/rppx1/algorithms/awb.cpp b/src/ipa/rppx1/algorithms/awb.cpp
index bd59d13ad5..7c748e9a2c 100644
--- a/src/ipa/rppx1/algorithms/awb.cpp
+++ b/src/ipa/rppx1/algorithms/awb.cpp
@@ -190,7 +190,7 @@  void Awb::process(IPAContext &context,
 	RppX1AwbStats awbStats = calculateRgbMeans(frameContext, *awb);
 
 	awbAlgo_.process(context.activeState.awb, frameContext.awb, awbStats,
-			 0, metadata);
+			 frameContext.lux.lux, metadata);
 }
 
 RppX1AwbStats Awb::calculateRgbMeans(const IPAFrameContext &frameContext,
diff --git a/src/ipa/rppx1/algorithms/lux.cpp b/src/ipa/rppx1/algorithms/lux.cpp
new file mode 100644
index 0000000000..56275d1973
--- /dev/null
+++ b/src/ipa/rppx1/algorithms/lux.cpp
@@ -0,0 +1,63 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2026, Ideas On Board
+ *
+ * RPP-X1 lux estimation algorithm
+ */
+
+#include "lux.h"
+
+#include <libcamera/base/utils.h>
+
+#include <libcamera/control_ids.h>
+
+#include "libipa/histogram.h"
+#include "libipa/lux.h"
+
+namespace libcamera {
+
+namespace ipa::rppx1::algorithms {
+
+int Lux::init([[maybe_unused]] IPAContext &context, const ValueNode &tuningData)
+{
+	return lux_.init(tuningData);
+}
+
+void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,
+		  IPAFrameContext &frameContext,
+		  [[maybe_unused]] RppX1Params *params)
+{
+	lux_.prepare(context.activeState.lux, frameContext.lux);
+}
+
+void Lux::process(IPAContext &context,
+		  [[maybe_unused]] const uint32_t frame,
+		  IPAFrameContext &frameContext,
+		  const RppX1Stats *stats,
+		  ControlList &metadata)
+{
+	const auto histPost = stats->block<StatsType::HistPost>();
+	if (!histPost) {
+		lux_.process(context.activeState.lux, frameContext.lux, metadata, {});
+		return;
+	}
+
+	lux_.process(context.activeState.lux, frameContext.lux, metadata,
+		     { {
+			     .exposureTime = context.configuration.agc.lineDuration *
+					     frameContext.sensor.exposure,
+			     .analogueGain = frameContext.sensor.gain,
+			     .digitalGain = 1,
+			     /* \todo Deduplicate the histogram calculation from AGC */
+			     .yHist = {
+				     histPost->hist_bins,
+				     [](uint32_t x) { return x >> 4; },
+			     },
+		     } });
+}
+
+REGISTER_IPA_ALGORITHM(Lux, "Lux")
+
+} /* namespace ipa::rppx1::algorithms */
+
+} /* namespace libcamera */
diff --git a/src/ipa/rppx1/algorithms/lux.h b/src/ipa/rppx1/algorithms/lux.h
new file mode 100644
index 0000000000..6c94f7507a
--- /dev/null
+++ b/src/ipa/rppx1/algorithms/lux.h
@@ -0,0 +1,36 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2026, Ideas On Board
+ *
+ * RPP-X1 lux estimation algorithm
+ */
+
+#pragma once
+
+#include "libipa/lux.h"
+
+#include "algorithm.h"
+
+namespace libcamera {
+
+namespace ipa::rppx1::algorithms {
+
+class Lux : public Algorithm
+{
+public:
+	int init(IPAContext &context, const ValueNode &tuningData) override;
+	void prepare(IPAContext &context, const uint32_t frame,
+		     IPAFrameContext &frameContext,
+		     RppX1Params *params) override;
+	void process(IPAContext &context, const uint32_t frame,
+		     IPAFrameContext &frameContext,
+		     const RppX1Stats *stats,
+		     ControlList &metadata) override;
+
+private:
+	ipa::LuxAlgorithm lux_;
+};
+
+} /* namespace ipa::rppx1::algorithms */
+
+} /* namespace libcamera */
diff --git a/src/ipa/rppx1/algorithms/meson.build b/src/ipa/rppx1/algorithms/meson.build
index 4a2c1b52dd..19688854a3 100644
--- a/src/ipa/rppx1/algorithms/meson.build
+++ b/src/ipa/rppx1/algorithms/meson.build
@@ -4,4 +4,5 @@  rppx1_ipa_algorithms = files([
     'agc.cpp',
     'awb.cpp',
     'blc.cpp',
+    'lux.cpp',
 ])
diff --git a/src/ipa/rppx1/ipa_context.h b/src/ipa/rppx1/ipa_context.h
index 24fbbfaa28..baa82d5f3b 100644
--- a/src/ipa/rppx1/ipa_context.h
+++ b/src/ipa/rppx1/ipa_context.h
@@ -20,6 +20,7 @@ 
 #include <libipa/awb.h>
 #include <libipa/camera_sensor_helper.h>
 #include <libipa/fc_queue.h>
+#include <libipa/lux.h>
 
 namespace libcamera {
 
@@ -42,6 +43,8 @@  struct IPAActiveState {
 	} agc;
 
 	ipa::awb::ActiveState awb;
+
+	ipa::lux::ActiveState lux;
 };
 
 struct IPAFrameContext : public FrameContext {
@@ -56,6 +59,8 @@  struct IPAFrameContext : public FrameContext {
 	} agc;
 
 	ipa::awb::FrameContext awb;
+
+	ipa::lux::FrameContext lux;
 };
 
 struct IPAContext {