[libcamera-devel,09/20] ipa: rpi: Prepare ALSC for PiSP support
diff mbox series

Message ID 20231006132000.23504-10-naush@raspberrypi.com
State Superseded
Headers show
Series
  • Raspberry Pi: Preliminary PiSP support
Related show

Commit Message

Naushir Patuck Oct. 6, 2023, 1:19 p.m. UTC
Prepare the ALSC algorithm to support the PiSP hardware. The key change
is to avoid factoring out the WB correction in the AWB zone statistics.

Add the ALSC correction to the global metadata so that AWB can use it to
factor the gains back in for the AWB calculations.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
---
 src/ipa/rpi/controller/rpi/alsc.cpp | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Jacopo Mondi Oct. 12, 2023, 8:54 a.m. UTC | #1
Hi Naush

On Fri, Oct 06, 2023 at 02:19:49PM +0100, Naushir Patuck via libcamera-devel wrote:
> Prepare the ALSC algorithm to support the PiSP hardware. The key change
> is to avoid factoring out the WB correction in the AWB zone statistics.
>
> Add the ALSC correction to the global metadata so that AWB can use it to
> factor the gains back in for the AWB calculations.
>
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
> Reviewed-by: David Plowman <david.plowman@raspberrypi.com>

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

Thanks
  j

> ---
>  src/ipa/rpi/controller/rpi/alsc.cpp | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/src/ipa/rpi/controller/rpi/alsc.cpp b/src/ipa/rpi/controller/rpi/alsc.cpp
> index 3a2e8fe00ca6..f1ccef87c70c 100644
> --- a/src/ipa/rpi/controller/rpi/alsc.cpp
> +++ b/src/ipa/rpi/controller/rpi/alsc.cpp
> @@ -348,9 +348,11 @@ static void copyStats(RgbyRegions &regions, StatisticsPtr &stats,
>  	const std::vector<double> &bTable = status.b;
>  	for (unsigned int i = 0; i < stats->awbRegions.numRegions(); i++) {
>  		auto r = stats->awbRegions.get(i);
> -		r.val.rSum = static_cast<uint64_t>(r.val.rSum / rTable[i]);
> -		r.val.gSum = static_cast<uint64_t>(r.val.gSum / gTable[i]);
> -		r.val.bSum = static_cast<uint64_t>(r.val.bSum / bTable[i]);
> +		if (stats->colourStatsPos == Statistics::ColourStatsPos::PostLsc) {
> +			r.val.rSum = static_cast<uint64_t>(r.val.rSum / rTable[i]);
> +			r.val.gSum = static_cast<uint64_t>(r.val.gSum / gTable[i]);
> +			r.val.bSum = static_cast<uint64_t>(r.val.bSum / bTable[i]);
> +		}
>  		regions.set(i, r);
>  	}
>  }
> @@ -368,7 +370,8 @@ void Alsc::restartAsync(StatisticsPtr &stats, Metadata *imageMetadata)
>  	 * the LSC table that the pipeline applied to them.
>  	 */
>  	AlscStatus alscStatus;
> -	if (imageMetadata->get("alsc.status", alscStatus) != 0) {
> +	if (stats->colourStatsPos == Statistics::ColourStatsPos::PostLsc &&
> +	    imageMetadata->get("alsc.status", alscStatus) != 0) {
>  		LOG(RPiAlsc, Warning)
>  			<< "No ALSC status found for applied gains!";
>  		alscStatus.r.resize(config_.tableSize.width * config_.tableSize.height, 1.0);
> @@ -414,6 +417,11 @@ void Alsc::prepare(Metadata *imageMetadata)
>  	status.g = prevSyncResults_[1].data();
>  	status.b = prevSyncResults_[2].data();
>  	imageMetadata->set("alsc.status", status);
> +	/*
> +	 * Put the results in the global metadata as well. This will be used by
> +	 * AWB to factor in the colour shading correction.
> +	 */
> +	getGlobalMetadata().set("alsc.status", status);
>  }
>
>  void Alsc::process(StatisticsPtr &stats, Metadata *imageMetadata)
> --
> 2.34.1
>

Patch
diff mbox series

diff --git a/src/ipa/rpi/controller/rpi/alsc.cpp b/src/ipa/rpi/controller/rpi/alsc.cpp
index 3a2e8fe00ca6..f1ccef87c70c 100644
--- a/src/ipa/rpi/controller/rpi/alsc.cpp
+++ b/src/ipa/rpi/controller/rpi/alsc.cpp
@@ -348,9 +348,11 @@  static void copyStats(RgbyRegions &regions, StatisticsPtr &stats,
 	const std::vector<double> &bTable = status.b;
 	for (unsigned int i = 0; i < stats->awbRegions.numRegions(); i++) {
 		auto r = stats->awbRegions.get(i);
-		r.val.rSum = static_cast<uint64_t>(r.val.rSum / rTable[i]);
-		r.val.gSum = static_cast<uint64_t>(r.val.gSum / gTable[i]);
-		r.val.bSum = static_cast<uint64_t>(r.val.bSum / bTable[i]);
+		if (stats->colourStatsPos == Statistics::ColourStatsPos::PostLsc) {
+			r.val.rSum = static_cast<uint64_t>(r.val.rSum / rTable[i]);
+			r.val.gSum = static_cast<uint64_t>(r.val.gSum / gTable[i]);
+			r.val.bSum = static_cast<uint64_t>(r.val.bSum / bTable[i]);
+		}
 		regions.set(i, r);
 	}
 }
@@ -368,7 +370,8 @@  void Alsc::restartAsync(StatisticsPtr &stats, Metadata *imageMetadata)
 	 * the LSC table that the pipeline applied to them.
 	 */
 	AlscStatus alscStatus;
-	if (imageMetadata->get("alsc.status", alscStatus) != 0) {
+	if (stats->colourStatsPos == Statistics::ColourStatsPos::PostLsc &&
+	    imageMetadata->get("alsc.status", alscStatus) != 0) {
 		LOG(RPiAlsc, Warning)
 			<< "No ALSC status found for applied gains!";
 		alscStatus.r.resize(config_.tableSize.width * config_.tableSize.height, 1.0);
@@ -414,6 +417,11 @@  void Alsc::prepare(Metadata *imageMetadata)
 	status.g = prevSyncResults_[1].data();
 	status.b = prevSyncResults_[2].data();
 	imageMetadata->set("alsc.status", status);
+	/*
+	 * Put the results in the global metadata as well. This will be used by
+	 * AWB to factor in the colour shading correction.
+	 */
+	getGlobalMetadata().set("alsc.status", status);
 }
 
 void Alsc::process(StatisticsPtr &stats, Metadata *imageMetadata)