From patchwork Thu Sep 30 09:37:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 13994 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 07993BDC71 for ; Thu, 30 Sep 2021 09:37:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B365A691C7; Thu, 30 Sep 2021 11:37:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="i/KmHXxM"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DCC5B691B8 for ; Thu, 30 Sep 2021 11:37:21 +0200 (CEST) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:bab4:22c5:662d:e478]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7E6C0B2B; Thu, 30 Sep 2021 11:37:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1632994641; bh=Hz82vcBRtJaofUifx/6e1lRt2lFJ5rNpThsTC2zIwKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i/KmHXxMQwp+aQVZi8dVTd2+dSudbAzsRnJglWsmRT33rB0qUEX2CO7hvb3z5wsH0 XeUFi3HVy5ehXr+Sa/rdWHQ0cOy9yiYK05nvy34EVzUxqHwjZjp8DwpQgSJFM9/tzJ E2IoW+6QVBCBWm13fzLQJ5KcxRpQtuvFiDFmxMOw= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Sep 2021 11:37:13 +0200 Message-Id: <20210930093715.73293-11-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210930093715.73293-1-jeanmichel.hautbois@ideasonboard.com> References: <20210930093715.73293-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 10/12] ipa: ipu3: awb: Introduce Black Level Correction X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The pixels output by the camera normally include a black level, because sensors do not always report a signal level of '0' for black. Pixels at or below this level should be considered black and to achieve that, we need to substract an offset to all the pixels. This can be taken into account by reading the lowest value of a special region on sensors which is not exposed to light. This provides a substracting factor to be able to adjust the expected black levels in the resultant images. For a camera outputting 10-bit pixel values (in the range 0 to 1023) a typical black level might be 64. It is a fixed value, obtained by capturing a raw frame with minimum exposure and gain fixed to 1.0 while covering the sensor (the darker the better). We consider it good enough as a very first approximation, until we measure it during a tuning process and include it in a configuration file Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/ipa/ipu3/algorithms/black_correction.cpp | 67 ++++++++++++++++++++ src/ipa/ipu3/algorithms/black_correction.h | 28 ++++++++ src/ipa/ipu3/algorithms/meson.build | 1 + src/ipa/ipu3/ipu3.cpp | 2 + 4 files changed, 98 insertions(+) create mode 100644 src/ipa/ipu3/algorithms/black_correction.cpp create mode 100644 src/ipa/ipu3/algorithms/black_correction.h diff --git a/src/ipa/ipu3/algorithms/black_correction.cpp b/src/ipa/ipu3/algorithms/black_correction.cpp new file mode 100644 index 00000000..5b5b5d31 --- /dev/null +++ b/src/ipa/ipu3/algorithms/black_correction.cpp @@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google inc. + * + * black_correction.cpp - IPU3 Optical Black Correction control + */ + +#include "black_correction.h" + +#include + +/** + * \file black_correction.h + */ + +namespace libcamera { + +namespace ipa::ipu3::algorithms { + +/** + * \class BlackCorrection + * \brief A class to handle optical black correction + * + * The pixels output by the camera normally include a black level, because + * sensors do not always report a signal level of '0' for black. Pixels at or + * below this level should be considered black and to achieve that, we need to + * substract an offset to all the pixels. + * + * This can be taken into account by reading the lowest value of a special + * region on sensors which is not exposed to light. This provides a substracting + * factor to be able to adjust the expected black levels in the resultant + * images. + */ + +BlackCorrection::BlackCorrection() +{ +} + +/** + * \brief Fill in the parameter structure, and enable optical black correction + * \param context The shared IPA context + * \param params The IPU3 parameters + * + * Populate the IPU3 parameter structure with the correction values for each + * channel and enable the corresponding ImgU block processing. + */ +void BlackCorrection::prepare([[maybe_unused]] IPAContext &context, + ipu3_uapi_params *params) +{ + /* + * The Optical Black Level correction values + * \todo The correction values should come from sensor specific + * tuning processes. This is a first approximation + */ + params->obgrid_param.gr = 64; + params->obgrid_param.r = 64; + params->obgrid_param.b = 64; + params->obgrid_param.gb = 64; + + /* Enable the custom optical black correction processing */ + params->use.obgrid = 1; + params->use.obgrid_param = 1; +} + +} /* namespace ipa::ipu3::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/ipu3/algorithms/black_correction.h b/src/ipa/ipu3/algorithms/black_correction.h new file mode 100644 index 00000000..6486ac5b --- /dev/null +++ b/src/ipa/ipu3/algorithms/black_correction.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google inc. + * + * black_correction.h - IPU3 Optical Black Correction control + */ +#ifndef __LIBCAMERA_IPU3_ALGORITHMS_BLACK_CORRECTION_H__ +#define __LIBCAMERA_IPU3_ALGORITHMS_BLACK_CORRECTION_H__ + +#include "algorithm.h" + +namespace libcamera { + +namespace ipa::ipu3::algorithms { + +class BlackCorrection : public Algorithm +{ +public: + BlackCorrection(); + + void prepare(IPAContext &context, ipu3_uapi_params *params) override; +}; + +} /* namespace ipa::ipu3::algorithms */ + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_IPU3_ALGORITHMS_BLACK_CORRECTION_H__ */ diff --git a/src/ipa/ipu3/algorithms/meson.build b/src/ipa/ipu3/algorithms/meson.build index deae225b..66877c1b 100644 --- a/src/ipa/ipu3/algorithms/meson.build +++ b/src/ipa/ipu3/algorithms/meson.build @@ -4,5 +4,6 @@ ipu3_ipa_algorithms = files([ 'agc.cpp', 'algorithm.cpp', 'awb.cpp', + 'black_correction.cpp', 'tone_mapping.cpp', ]) diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index b33e8c77..7cc0fb89 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -33,6 +33,7 @@ #include "algorithms/agc.h" #include "algorithms/algorithm.h" #include "algorithms/awb.h" +#include "algorithms/black_correction.h" #include "algorithms/tone_mapping.h" #include "libipa/camera_sensor_helper.h" @@ -279,6 +280,7 @@ int IPAIPU3::init(const IPASettings &settings, /* Construct our Algorithms */ algorithms_.push_back(std::make_unique()); algorithms_.push_back(std::make_unique()); + algorithms_.push_back(std::make_unique()); algorithms_.push_back(std::make_unique()); return 0;