From 8eae1f8dda574c60f75e676aa5706148f448db1f Mon Sep 17 00:00:00 2001 From: Vasiliy Doylov Date: Wed, 9 Jul 2025 00:20:03 +0300 Subject: [PATCH] WIP: AUTOFOCUS Signed-off-by: Vasiliy Doylov --- .../libcamera/internal/software_isp/swisp_stats.h | 4 ++++ src/libcamera/software_isp/swstats_cpu.cpp | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/libcamera/internal/software_isp/swisp_stats.h b/include/libcamera/internal/software_isp/swisp_stats.h index ae11f112e..3377dd825 100644 --- a/include/libcamera/internal/software_isp/swisp_stats.h +++ b/include/libcamera/internal/software_isp/swisp_stats.h @@ -44,6 +44,10 @@ struct SwIspStats { * \brief A histogram of luminance values */ Histogram yHistogram; + /** + * \brief Holds the sharpness of an image + */ + uint64_t sharpness; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index c520c806e..2294056e8 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -147,7 +147,8 @@ static constexpr unsigned int kBlueYMul = 29; /* 0.114 * 256 */ \ uint64_t sumR = 0; \ uint64_t sumG = 0; \ - uint64_t sumB = 0; + uint64_t sumB = 0; \ + uint64_t sharpness = 0; #define SWSTATS_ACCUMULATE_LINE_STATS(div) \ sumR += r; \ @@ -162,7 +163,8 @@ static constexpr unsigned int kBlueYMul = 29; /* 0.114 * 256 */ #define SWSTATS_FINISH_LINE_STATS() \ stats_.sumR_ += sumR; \ stats_.sumG_ += sumG; \ - stats_.sumB_ += sumB; + stats_.sumB_ += sumB; \ + stats_.sharpness += sharpness; void SwStatsCpu::statsBGGR8Line0(const uint8_t *src[]) { @@ -174,6 +176,13 @@ void SwStatsCpu::statsBGGR8Line0(const uint8_t *src[]) if (swapLines_) std::swap(src0, src1); + for(int x = 0; x < (int)window_.width; x+=2){ + int sum = 0; + sum += src0[x-2]; + sum += src0[x+2]; + sum -= 2*src0[x]; + sharpness += sum*sum; + } /* x += 4 sample every other 2x2 block */ for (int x = 0; x < (int)window_.width; x += 4) { b = src0[x]; @@ -320,6 +329,7 @@ void SwStatsCpu::finishFrame(uint32_t frame, uint32_t bufferId) { *sharedStats_ = stats_; statsReady.emit(frame, bufferId); + LOG(SwStatsCpu, Error) << "Sharpness" << stats_.sharpness; } /**