From df8ba90d448b15a3438627e7b6a76a9832f08315 Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Tue, 21 Jan 2025 12:58:20 +0000 Subject: [PATCH] pipeline: rpi: pisp: Enable FE stats crop if needed If the decimation width is greater than the max stats width, add a centre crop on the image to allow the stats to be gathered correctly. Signed-off-by: Naushir Patuck --- src/libcamera/pipeline/rpi/pisp/pisp.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/rpi/pisp/pisp.cpp b/src/libcamera/pipeline/rpi/pisp/pisp.cpp index c7799f2b..a450583b 100644 --- a/src/libcamera/pipeline/rpi/pisp/pisp.cpp +++ b/src/libcamera/pipeline/rpi/pisp/pisp.cpp @@ -1905,7 +1905,8 @@ int PiSPCameraData::configureCfe() pisp_fe_global_config global; fe_->GetGlobal(global); - global.enables &= ~PISP_FE_ENABLE_COMPRESS0; + global.enables &= ~(PISP_FE_ENABLE_COMPRESS0 | PISP_FE_ENABLE_DECIMATE | + PISP_FE_ENABLE_STATS_CROP); global.enables |= PISP_FE_ENABLE_OUTPUT0; global.bayer_order = toPiSPBayerOrder(cfeFormat.fourcc); @@ -1926,8 +1927,23 @@ int PiSPCameraData::configureCfe() fe_->SetCompress(0, compress); } - if (input.format.width > pispVariant_.FrontEndDownscalerMaxWidth(0, 0)) + const unsigned int maxStatsWidth = pispVariant_.FrontEndDownscalerMaxWidth(0, 0); + if (input.format.width > maxStatsWidth) { + /* The line is too wide for the stats generation, so try to decimate. */ global.enables |= PISP_FE_ENABLE_DECIMATE; + if ((input.format.width >> 1) > maxStatsWidth) { + /* Still too wide, crop a window before the decimation. */ + pisp_fe_crop_config statsCrop{}; + statsCrop.width = maxStatsWidth << 1; + statsCrop.height = input.format.height; + statsCrop.offset_x = + (((input.format.width - statsCrop.width) >> 1) & ~1); + statsCrop.offset_y = 0; + fe_->SetStatsCrop(statsCrop); + global.enables |= PISP_FE_ENABLE_STATS_CROP; + LOG(RPI, Warning) << "Cropping FE stats window"; + } + } fe_->SetGlobal(global); fe_->SetInput(input);