From patchwork Fri Jun 19 09:27:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 4100 Return-Path: Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 98524609B3 for ; Fri, 19 Jun 2020 11:27:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="aQKA7vm0"; dkim-atps=neutral Received: by mail-wr1-x42b.google.com with SMTP id q11so8997824wrp.3 for ; Fri, 19 Jun 2020 02:27:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3QCDBkaxFXVXaBWcvlJm6aIO+K2xVTiA1JY72i6arQ8=; b=aQKA7vm0D8C1i3DTs3IAo5x5ER8wyE/snCIqoRvJZLrDp/qiDfyVc4hJiPn3kU19M1 kgb+tExfzWk/ynqKeeZ/FHr66aCARpuMIQsF7iAItZMrJ2cf6efRZg8928lXhmskP4qB s5vXhAL1VGFJCEA2/wk8BNox6o7Y4CmtrnDwrugiByVC83kq4+Azd7NFXXJuidu8GghR +1qGR5P8I3LXrZK1thgom7LAyEPtKsGlRa8ofHmXHZgMoSKKrMDc3xbXmU/RZQ6BIGyn a6VX1SHiHm2SNsHogfUucVUhaabpAbyZgIlCTns2h71NVGsfqBfGzBO4DBNLdf3QUrem B3Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3QCDBkaxFXVXaBWcvlJm6aIO+K2xVTiA1JY72i6arQ8=; b=ZI/QuoORfL4qLml0TT4oPQyq8pDwLbco6hbEHg5qWzy1L8Ee9nCTbMwqVEO6thcK1p 8D1E2wadweFRY4zQAcef61kYqCUuSOs4YTZXBMrtmKZIPdUqaZaNz1ScFlA7NdoPuoNy tYhwHPB4o+GDAoFfdrd64iX5K1vB+y8PaIDhZK15goh0ygF1XpEamuzD/ixjol6JIFmh 06U64TA5a2rUNAqnY+/cnQCA1Ysy4+5PhaRu5WYQkYHzBwVbAZXxgH6cZk9SOw7oiqWY gc1SZccHgfTD5ol1KmaD2G/PRb6yCt4+Pe/WdN0/bXK2jiDCVp63+5EJBCuEExzVYXaL gZmw== X-Gm-Message-State: AOAM533WzkMuefpJiNJVM0YFnqoXPyXourzbSuq4DWg/XSdp/BKrx31q 8tGOER7xMmZdWt5fzJtPAe+SAh6lJ2c= X-Google-Smtp-Source: ABdhPJxZwExjevM8zKMtt6JI9M1QTQS8xjMnPXDFbRQJTdowrM+F/TT3jyJR9w8g5pKG4FS28A+IlA== X-Received: by 2002:a5d:490f:: with SMTP id x15mr2998614wrq.259.1592558872976; Fri, 19 Jun 2020 02:27:52 -0700 (PDT) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id n65sm5156154wmf.47.2020.06.19.02.27.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2020 02:27:52 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Fri, 19 Jun 2020 10:27:24 +0100 Message-Id: <20200619092725.19109-3-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200619092725.19109-1-david.plowman@raspberrypi.com> References: <20200619092725.19109-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] libcamera: raspberrypi: add sharpness strength control to Raspberry Pi IPAs 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: , X-List-Received-Date: Fri, 19 Jun 2020 09:27:53 -0000 The sharpness control is, loosely speaking, a gain applied to the amount of sharpening added to an image. We also report the sharpness setting used back to the caller in metadata. Signed-off-by: David Plowman --- .../raspberrypi/controller/rpi/sharpen.cpp | 23 +++++++++++++++---- .../raspberrypi/controller/rpi/sharpen.hpp | 6 +++-- .../controller/sharpen_algorithm.hpp | 21 +++++++++++++++++ .../raspberrypi/controller/sharpen_status.h | 2 ++ 4 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 src/ipa/raspberrypi/controller/sharpen_algorithm.hpp diff --git a/src/ipa/raspberrypi/controller/rpi/sharpen.cpp b/src/ipa/raspberrypi/controller/rpi/sharpen.cpp index 1f07bb6..45fe3fe 100644 --- a/src/ipa/raspberrypi/controller/rpi/sharpen.cpp +++ b/src/ipa/raspberrypi/controller/rpi/sharpen.cpp @@ -17,7 +17,7 @@ using namespace RPi; #define NAME "rpi.sharpen" Sharpen::Sharpen(Controller *controller) - : Algorithm(controller) + : SharpenAlgorithm(controller), user_strength_(1.0) { } @@ -40,15 +40,30 @@ void Sharpen::Read(boost::property_tree::ptree const ¶ms) limit_ = params.get("limit", 1.0); } +void Sharpen::SetStrength(double strength) +{ + // Note that this method is how an application sets the overall + // sharpening "strength". We call this the "user strength" field + // as there already is a strength_ field - being an internal gain + // parameter that gets passed to the ISP control code. + user_strength_ = strength; +} + void Sharpen::Prepare(Metadata *image_metadata) { double mode_factor = mode_factor_; + // The user_strength affects the algorithm's internal gain directly, but + // we adjust the limit and threshold more cautiously, hence the sqrt. + double user_strength = user_strength_; + double user_strength_sqrt = sqrt(user_strength); struct SharpenStatus status; // Binned modes seem to need the sharpening toned down with this // pipeline. - status.threshold = threshold_ * mode_factor; - status.strength = strength_ / mode_factor; - status.limit = limit_ / mode_factor; + status.threshold = threshold_ * mode_factor / user_strength_sqrt; + status.strength = (strength_ / mode_factor) * user_strength; + status.limit = (limit_ / mode_factor) * user_strength_sqrt; + // Finally, report any application-supplied parameters that were used. + status.user_strength = user_strength; image_metadata->Set("sharpen.status", status); } diff --git a/src/ipa/raspberrypi/controller/rpi/sharpen.hpp b/src/ipa/raspberrypi/controller/rpi/sharpen.hpp index 3b0d680..5b419b4 100644 --- a/src/ipa/raspberrypi/controller/rpi/sharpen.hpp +++ b/src/ipa/raspberrypi/controller/rpi/sharpen.hpp @@ -6,20 +6,21 @@ */ #pragma once -#include "../algorithm.hpp" +#include "../sharpen_algorithm.hpp" #include "../sharpen_status.h" // This is our implementation of the "sharpen algorithm". namespace RPi { -class Sharpen : public Algorithm +class Sharpen : public SharpenAlgorithm { public: Sharpen(Controller *controller); char const *Name() const override; void SwitchMode(CameraMode const &camera_mode) override; void Read(boost::property_tree::ptree const ¶ms) override; + void SetStrength(double strength) override; void Prepare(Metadata *image_metadata) override; private: @@ -27,6 +28,7 @@ private: double strength_; double limit_; std::atomic mode_factor_; + std::atomic user_strength_; }; } // namespace RPi diff --git a/src/ipa/raspberrypi/controller/sharpen_algorithm.hpp b/src/ipa/raspberrypi/controller/sharpen_algorithm.hpp new file mode 100644 index 0000000..3b27a74 --- /dev/null +++ b/src/ipa/raspberrypi/controller/sharpen_algorithm.hpp @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2020, Raspberry Pi (Trading) Limited + * + * sharpen_algorithm.hpp - sharpness control algorithm interface + */ +#pragma once + +#include "algorithm.hpp" + +namespace RPi { + +class SharpenAlgorithm : public Algorithm +{ +public: + SharpenAlgorithm(Controller *controller) : Algorithm(controller) {} + // A sharpness control algorithm must provide the following: + virtual void SetStrength(double strength) = 0; +}; + +} // namespace RPi diff --git a/src/ipa/raspberrypi/controller/sharpen_status.h b/src/ipa/raspberrypi/controller/sharpen_status.h index 6de80f4..7501b19 100644 --- a/src/ipa/raspberrypi/controller/sharpen_status.h +++ b/src/ipa/raspberrypi/controller/sharpen_status.h @@ -19,6 +19,8 @@ struct SharpenStatus { double strength; // upper limit of the allowed sharpening response double limit; + // The sharpening strength requested by the user or application. + double user_strength; }; #ifdef __cplusplus