From patchwork Fri Oct 13 07:48:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19125 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 54681C3274 for ; Fri, 13 Oct 2023 07:48:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8F8CE6297B; Fri, 13 Oct 2023 09:48:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183331; bh=ukEAiab497hGfyJvmVrVc3AQEQ62Am0ig990ebj2BLY=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=QF/C4lYvr5ZrOUsgUVR9PNL88FGocHsxdwgNb1w8lX1PGbQMUrgVJLlv8ww5hTFNG wWS2uSQBgXsf39gdRPouLqhSRp4w6bzhsSFkM7F7vIvabmPLP+5hXpS89BbZZomA3i AhJRF/THRtaaf2bmcI6+qLCny3OxRIhk+OhaoterAHNFmB3eQXAnXox3B+KjqzLn7R BWYxVRh7GEpHFmrQdyE+yxi/r7qNNmnauZQbO9fvWs6Zy3z7aea5u3UYzciBL7VKLr h9I10ibG8GI2cWYDUhuBpVgmZtBhIi4uXLLS71gtskTroH5eSWmBS/64qYHr2pNxa9 AbBewO+HyoaFw== Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A2FA6295F for ; Fri, 13 Oct 2023 09:48:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="p2ZcR8MH"; dkim-atps=neutral Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-53b8f8c6b1fso3165574a12.0 for ; Fri, 13 Oct 2023 00:48:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183328; x=1697788128; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vTMQlft/OcZG1+L7DUZr/wsKE/ARJQButlEv9E/GrNI=; b=p2ZcR8MHTUVQl2dgS665Rul0juvYvPFd/hCYZdHSBGk1JqL58bybaBNoOpYwzaPEKK sXYdkyfvj80AX4lH+pGaxhm2hC/48VNRqvRq2VAzWiT3uC3ZnVfPuFIAd3ipgnIhPlrn cVnQgqE7uNyNdgTnfNkGronOXZ3JgVjps+Sf5o6K2UcHhOF6T9FYd32W0lw5Prd/vD4J vjr6nohTFUbuo5Br38IUp/YHggsYGitux6mT7dwwPUf2Q/9LDGTrz719OTSKyaek8Vwn 7+pyekWS8+XViZjzYmmqReO1mCpLYxQGWMfOUdiVEg7Pkzvg5rDc8hppAxqiKwL+LAkK PMRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183328; x=1697788128; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vTMQlft/OcZG1+L7DUZr/wsKE/ARJQButlEv9E/GrNI=; b=QhxMnkYQQAby/i+q4pcwzp25LXEBgLlPZmHc2+O1tdj5JajfK9rhtpRsavxzVuCQyL Qp9SMq4XOHPN0Qz735tVRZY8pgVGlDz55GjU7Y5iGm+iNu1oRXqxfqtD7w+k+kMD4nII 02vnDGm2NPnM01gn8pXQHt5Sbj2gag3W9MTenZJ1mIhbsgOsZlmE6GXwvfcofv/g4IPr 5j3yWo/YOgLe1TB2kh+OughnlOwR78sclZHWEH+P4G6myk4Fj9Inn8U2xrZZwmA0L76h iSGBeVbk10AlnE94GQ8SkpttoJEHjG4dRu9HQGN+3VQ/c/jv/szzUvvLiuawwk4fREjC P8eg== X-Gm-Message-State: AOJu0YzN9DYPvCZ2fiL+UEWkU6IrQqndbD/YyYd77BHnF1qoUs64Z17R GbSnwBe0cMHps9xcRMtL+P/3Q0+l9M1fasyDyp5LZQ== X-Google-Smtp-Source: AGHT+IGHZyuQGj49M31gECS5xIs6IyAEfd7j5c23bR6bGYHJQxHXEEWBlMoN4L5nYQcFs83nEQje3g== X-Received: by 2002:a17:906:530c:b0:9ae:3d8e:b635 with SMTP id h12-20020a170906530c00b009ae3d8eb635mr22227584ejo.24.1697183327626; Fri, 13 Oct 2023 00:48:47 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:46 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:22 +0100 Message-Id: <20231013074841.16972-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 01/20] pipeline: rpi: Add RequiresMmap flag to RPi::Stream 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a new RequiresMmap flag to the RPi::Stream class indicating that buffers handled by the stream must be mmapped after allocation and cached internally. Add a new member function getBuffer(id) which can be used to obtain the mapped buffers for a given buffer id. Add a new member function acquireBuffer() which can be used to obtain any mapped buffer that has not already been acquired by the caller. As a drive-by, add the header to rpi_stream.cpp as it is needed for the std::find_if() function. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- .../pipeline/rpi/common/pipeline_base.cpp | 2 +- .../pipeline/rpi/common/rpi_stream.cpp | 49 +++++++++++++++++-- .../pipeline/rpi/common/rpi_stream.h | 32 +++++++++++- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 6 +-- 4 files changed, 80 insertions(+), 9 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index fad710a63c46..825eae80d014 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -888,7 +888,7 @@ void PipelineHandlerBase::mapBuffers(Camera *camera, const BufferMap &buffers, u */ for (auto const &it : buffers) { bufferIds.push_back(IPABuffer(mask | it.first, - it.second->planes())); + it.second.buffer->planes())); data->bufferIds_.insert(mask | it.first); } diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp index 7319f510a371..ee827a86b06a 100644 --- a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp @@ -6,6 +6,10 @@ */ #include "rpi_stream.h" +#include +#include +#include + #include /* Maximum number of buffer slots to allocate in the V4L2 device driver. */ @@ -17,8 +21,13 @@ LOG_DEFINE_CATEGORY(RPISTREAM) namespace RPi { +const BufferObject Stream::errorBufferObject{ nullptr, false }; + void Stream::setFlags(StreamFlags flags) { + /* We don't want dynamic mmapping. */ + ASSERT(!(flags & StreamFlag::RequiresMmap)); + flags_ |= flags; /* Import streams cannot be external. */ @@ -27,6 +36,9 @@ void Stream::setFlags(StreamFlags flags) void Stream::clearFlags(StreamFlags flags) { + /* We don't want dynamic mmapping. */ + ASSERT(!(flags & StreamFlag::RequiresMmap)); + flags_ &= ~flags; } @@ -56,7 +68,7 @@ void Stream::resetBuffers() void Stream::setExportedBuffers(std::vector> *buffers) { for (auto const &buffer : *buffers) - bufferMap_.emplace(++id_, buffer.get()); + bufferEmplace(++id_, buffer.get()); } const BufferMap &Stream::getBuffers() const @@ -71,7 +83,7 @@ unsigned int Stream::getBufferId(FrameBuffer *buffer) const /* Find the buffer in the map, and return the buffer id. */ auto it = std::find_if(bufferMap_.begin(), bufferMap_.end(), - [&buffer](auto const &p) { return p.second == buffer; }); + [&buffer](auto const &p) { return p.second.buffer == buffer; }); if (it == bufferMap_.end()) return 0; @@ -81,7 +93,7 @@ unsigned int Stream::getBufferId(FrameBuffer *buffer) const void Stream::setExportedBuffer(FrameBuffer *buffer) { - bufferMap_.emplace(++id_, buffer); + bufferEmplace(++id_, buffer); } int Stream::prepareBuffers(unsigned int count) @@ -180,6 +192,27 @@ void Stream::returnBuffer(FrameBuffer *buffer) } } +const BufferObject &Stream::getBuffer(unsigned int id) +{ + auto const &it = bufferMap_.find(id); + if (it == bufferMap_.end()) + return errorBufferObject; + + return it->second; +} + +const BufferObject &Stream::acquireBuffer() +{ + /* No id provided, so pick up the next available buffer if possible. */ + if (availableBuffers_.empty()) + return errorBufferObject; + + unsigned int id = getBufferId(availableBuffers_.front()); + availableBuffers_.pop(); + + return getBuffer(id); +} + int Stream::queueAllBuffers() { int ret; @@ -204,6 +237,16 @@ void Stream::releaseBuffers() clearBuffers(); } +void Stream::bufferEmplace(unsigned int id, FrameBuffer *buffer) +{ + if (flags_ & StreamFlag::RequiresMmap) + bufferMap_.emplace(std::piecewise_construct, std::forward_as_tuple(id), + std::forward_as_tuple(buffer, true)); + else + bufferMap_.emplace(std::piecewise_construct, std::forward_as_tuple(id), + std::forward_as_tuple(buffer, false)); +} + void Stream::clearBuffers() { availableBuffers_ = std::queue{}; diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.h b/src/libcamera/pipeline/rpi/common/rpi_stream.h index 889b499782a4..861e9c8e7dab 100644 --- a/src/libcamera/pipeline/rpi/common/rpi_stream.h +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.h @@ -7,22 +7,23 @@ #pragma once +#include #include #include #include #include #include + #include +#include "libcamera/internal/mapped_framebuffer.h" #include "libcamera/internal/v4l2_videodevice.h" namespace libcamera { namespace RPi { -using BufferMap = std::unordered_map; - enum BufferMask { MaskID = 0x00ffff, MaskStats = 0x010000, @@ -30,6 +31,21 @@ enum BufferMask { MaskBayerData = 0x040000, }; +struct BufferObject { + BufferObject(FrameBuffer *b, bool requiresMmap) + : buffer(b), mapped(std::nullopt) + { + if (requiresMmap) + mapped = std::make_optional + (b, MappedFrameBuffer::MapFlag::ReadWrite); + } + + FrameBuffer *buffer; + std::optional mapped; +}; + +using BufferMap = std::unordered_map; + /* * Device stream abstraction for either an internal or external stream. * Used for both Unicam and the ISP. @@ -49,6 +65,11 @@ public: * buffers might be provided by (and returned to) the application. */ External = (1 << 1), + /* + * Indicates that the stream buffers need to be mmaped and returned + * to the pipeline handler when requested. + */ + RequiresMmap = (1 << 2), }; using StreamFlags = Flags; @@ -82,10 +103,17 @@ public: int queueBuffer(FrameBuffer *buffer); void returnBuffer(FrameBuffer *buffer); + const BufferObject &getBuffer(unsigned int id); + const BufferObject &acquireBuffer(); + int queueAllBuffers(); void releaseBuffers(); + /* For error handling. */ + static const BufferObject errorBufferObject; + private: + void bufferEmplace(unsigned int id, FrameBuffer *buffer); void clearBuffers(); int queueToDevice(FrameBuffer *buffer); diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index c189abaabc87..bc90d6324777 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -825,7 +825,7 @@ void Vc4CameraData::processStatsComplete(const ipa::RPi::BufferIds &buffers) if (!isRunning()) return; - FrameBuffer *buffer = isp_[Isp::Stats].getBuffers().at(buffers.stats & RPi::MaskID); + FrameBuffer *buffer = isp_[Isp::Stats].getBuffers().at(buffers.stats & RPi::MaskID).buffer; handleStreamBuffer(buffer, &isp_[Isp::Stats]); @@ -842,7 +842,7 @@ void Vc4CameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers) if (!isRunning()) return; - buffer = unicam_[Unicam::Image].getBuffers().at(bayer & RPi::MaskID); + buffer = unicam_[Unicam::Image].getBuffers().at(bayer & RPi::MaskID).buffer; LOG(RPI, Debug) << "Input re-queue to ISP, buffer id " << (bayer & RPi::MaskID) << ", timestamp: " << buffer->metadata().timestamp; @@ -850,7 +850,7 @@ void Vc4CameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers) ispOutputCount_ = 0; if (sensorMetadata_ && embeddedId) { - buffer = unicam_[Unicam::Embedded].getBuffers().at(embeddedId & RPi::MaskID); + buffer = unicam_[Unicam::Embedded].getBuffers().at(embeddedId & RPi::MaskID).buffer; handleStreamBuffer(buffer, &unicam_[Unicam::Embedded]); } From patchwork Fri Oct 13 07:48:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19126 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 83CB1C32B6 for ; Fri, 13 Oct 2023 07:48:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 44BB562980; Fri, 13 Oct 2023 09:48:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183332; bh=vpTMwsBE85smJGdnV8ufWU9wfac7cA+9jg3yj6jEfFA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=VKPECP8UnI1HLqytkisiCh94dSW5KcCi/Lv01uGcn7sZ56C3gT2fMar8cax3EXSU1 gJGjwdn9r8JeThXmyt9kcBxk5NdITS2OE6DMsJ2vuXVZDFq+RziTiSnWwaORoWEsC0 0uYPBQd1dffUMuGewosf6rVLZxl0vnCcWD4zmZjnX9RKprOjSFhq7gG5GHPo0rOyzH sKmFEoitjVXbzPbUCrnW0biEVAfYqPjzaRAOF8rEgLDt5ulD118H6bOZV097XK7W33 bgm8lAIG+tCN7M8Y3MGejLbCiJXiu/HFJJdyCczCXVbatHtssOdjj92PgpbbbrdV6u HdaPPZXfYKOug== Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 13E2D6295F for ; Fri, 13 Oct 2023 09:48:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="LsHm5uII"; dkim-atps=neutral Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40666aa674fso18809525e9.0 for ; Fri, 13 Oct 2023 00:48:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183328; x=1697788128; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kn40iwxfpZOODJIPAGAfiw/6Gmd7I0zdgzH/m35HEcM=; b=LsHm5uIIHM0MVRz6SJklchnLRhqoqvlXqkNqojWyw+OFrrbJCVQfxtkn2eU1KwLwks sGHzGgEEZSzmqOUt/N3DHaFX0SaHq9fAsa8Myqzd6uWtCgf76FcHYjTnBKzmn+iJM9WO U1N7y5Skn0qJAlQZNvdKJZISOsl3zpBbyk7LViYdP1YnkZh/izUVkSRqA5rL4jvyRipC PRtHu2qI9XBKnkEipQ8EL8RX75//u/W2JzJfxebGBkB0/Ctep6WJQ/PqswSf+PgwagV9 HOuMJ2BgFuc6ZiGPoMDomIAvUGPxBhNNJ4giWjhelB/aCAJali2SFVS9HvfqJH3L/icq uVGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183328; x=1697788128; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kn40iwxfpZOODJIPAGAfiw/6Gmd7I0zdgzH/m35HEcM=; b=LuXn2Mb6M2/BaMT7USowMR3IHlI2A7/hG+DPi4tP4Wy/AtzqKleSjLx0DLJ3wxLEtk DpPswrqj3Svh7bhPQtohMj+fDUKcZ+UmPNkXmK6+jXsK7QVUKjkYd+/ZhkUeaLHxBO/A UhASzn4uk6F6t88FNAT/BOdAIVfZxy7zqwH2WB1Mf7EMpzWr0sn+us4uesm7LaLjIAsF P8qSn/WBmUK3wPsJ6m64MvYsFokz9q93GBrkXlWJc+enUH+YTPRmYxm0hRsk4V8rPrbJ DQSsXc8/sh+rYdtpbzdr16LAAdLlgusJQmqwn2zSBn78uk7b6z8adocWypB6cQj8R215 AJhQ== X-Gm-Message-State: AOJu0YxBz+GeXo2IVbUmvshmUSAm2YJEjQ2PjRgcMaQ2o1uOD2WvJfh/ rvrg7I9flHBbiOlIfP6pNQCIpKDCz3oH6xiISnsfdA== X-Google-Smtp-Source: AGHT+IHsFi1NnQ6MrltLBpCb6Fiw2Ia74S36Woz8SA2HMpfCC9wQEYOQyCQG0iVYeCpKekqwmNMCdw== X-Received: by 2002:a1c:7914:0:b0:405:37bb:d942 with SMTP id l20-20020a1c7914000000b0040537bbd942mr23917932wme.4.1697183328243; Fri, 13 Oct 2023 00:48:48 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:47 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:23 +0100 Message-Id: <20231013074841.16972-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 02/20] pipeline: rpi: Add Recurrent and Needs32bitConv flags to RPi::Stream 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a new "Recurrent" stream flag. This flag indicates the stream buffer handling/management happend from the pipeline handler exclusively. This is used for TDN/Stitch and Config streams. Add a new Needs32bitConv stream flag to indicate that this stream needs a software postprocessing conversion run on it before returning out to the application. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/rpi/common/rpi_stream.cpp | 4 ++-- src/libcamera/pipeline/rpi/common/rpi_stream.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp index ee827a86b06a..20864aeed2d1 100644 --- a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp @@ -155,7 +155,7 @@ int Stream::queueBuffer(FrameBuffer *buffer) void Stream::returnBuffer(FrameBuffer *buffer) { - if (!(flags_ & StreamFlag::External)) { + if (!(flags_ & StreamFlag::External) && !(flags_ & StreamFlag::Recurrent)) { /* For internal buffers, simply requeue back to the device. */ queueToDevice(buffer); return; @@ -217,7 +217,7 @@ int Stream::queueAllBuffers() { int ret; - if (flags_ & StreamFlag::External) + if ((flags_ & StreamFlag::External) || (flags_ & StreamFlag::Recurrent)) return 0; while (!availableBuffers_.empty()) { diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.h b/src/libcamera/pipeline/rpi/common/rpi_stream.h index 861e9c8e7dab..c5e35d134926 100644 --- a/src/libcamera/pipeline/rpi/common/rpi_stream.h +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.h @@ -70,6 +70,17 @@ public: * to the pipeline handler when requested. */ RequiresMmap = (1 << 2), + /* + * Indicates a stream that needs buffers recycled every frame internally + * in the pipeline handler, e.g. stitch, TDN, config. All buffer + * management will be handled by the pipeline handler. + */ + Recurrent = (1 << 3), + /* + * Indicates that the output stream needs a software format conversion + * to be applied after ISP processing. + */ + Needs32bitConv = (1 << 4), }; using StreamFlags = Flags; From patchwork Fri Oct 13 07:48:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19127 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 89BCDC32B7 for ; Fri, 13 Oct 2023 07:48:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D053D6298E; Fri, 13 Oct 2023 09:48:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183332; bh=U+LuW5XpM1TGIphdq0IiFVOuYqOc16ZDNqA+E0cEDeA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=x+K3bRBjpW+qKtWNWdqb5DpAzHfH3rgdubvjLMAThWt8nNjzJF4KNGyzcN+67UVUA 495MEzczzGO9DcHGHGr7gpUxorW3Ve3bPL2IOteJL1J9p+KYjq1K3Nwv8ykix3giId KXsRtFeFMtg13iqdnA97fPuNS8i0bVKNN2xMAN7VGhIC8v2+c6VXPAYwoDqx4Y4pPF i6CCxpPnTKi8xbM5c0NWNuUPR8ahZdDbGbLCbdJHllnxNdiOMEexjFpzmDOc0kPtF6 WVFml3fs01+dL1gKmrIvv1HrEMCuCm1Dpk+HFE6i0EUZcIMek2YZoXYzb16j5trXf1 j7JCcsHrKn6qQ== Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5D67162980 for ; Fri, 13 Oct 2023 09:48:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="IbewTnly"; dkim-atps=neutral Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3232be274a0so1920952f8f.1 for ; Fri, 13 Oct 2023 00:48:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183329; x=1697788129; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Tf9cMYwANGl6wI2KKAEoNBPrx/L8GaWXI40cn6J1ToE=; b=IbewTnlyU1GW04W+JKOYc0F6Yd5LWxF/tXOYlQalNgBz1tCwosfa1tZWNDA1/F/f0y ByI2tw+WheeKplMjrJ42mGQQSDBPTAelxlGSVgOAgiqrIED1zaqfoVEtQQtNT528Pv6T zSejb6ygt7ajRnlHQ1BM805qDAGq5mWEritn6c9CDcz3E2BIy3lsyK1Ogq4Dxmp/N9so j+dk94C4QapqMIRfDNYIANoUTBeeXJ9Yx3giLVHsPO1hAq5PlpzDlkAIl2aS3xf4DLhi KWMaqddt4kdKbPVuUvnnIvyiLKHgxu4twxniGgie+7imLnWzjYjBPYlSUUqkjzmXdRaz tq8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183329; x=1697788129; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Tf9cMYwANGl6wI2KKAEoNBPrx/L8GaWXI40cn6J1ToE=; b=I1CaeXozWcG7bma9ecaNF29IihpsvzcJt0tXqZX4n0AoWfJ+HNhVITzsGBtFUdRz7/ Tk+EflBVz1F6N9/xCCcYy26s7MhFUoe/hUTZ9aQz6YG6bjjQ83ydh7V9dhc/zfYNcUc6 tq5QxGg0cIovYNoGV7blX2f/VkZiNGfL8r/57DixpcG+JCm5mBGJeqgUhoK9X0h9+j25 0JoPlXaeht8HrjJ2kgBmnGxTtRP/0WYzudtvXmKpF+CPxBbec6yyJxwYMvH1to5UTdjK WLeH6buYGH/VDzV6/AqTriyQQyvBEbd+ACGHcoHmKFJkoIhKXEht5h7jI1AHIrvhDkeP xuNA== X-Gm-Message-State: AOJu0Yxe5tukCKXaQQMsaLgC4Gh5pnvAoKc3Puv+xmlDLM78VQwEc2gZ QRM3UoMku+7/HN2TVRGN2jjvrhaeUb8zlGYWzfk5KQ== X-Google-Smtp-Source: AGHT+IGrV7VQi2p4m1VWoVxVHepXo60OLME3mGMYohrmv+Y2prtOitBULGxypvWjVjl73hx5nUO7SQ== X-Received: by 2002:a5d:6904:0:b0:31f:fc9a:a03 with SMTP id t4-20020a5d6904000000b0031ffc9a0a03mr18498993wru.20.1697183328798; Fri, 13 Oct 2023 00:48:48 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:48 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:24 +0100 Message-Id: <20231013074841.16972-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 03/20] pipeline: rpi: Add SharedMemObject class 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add new SharedMemObject class that wraps a memfd memory allocation and constructs a templated object in the memory. With appropriate locking, this object can then be shared across different processes using the associated allocation file handle. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- .../pipeline/rpi/common/shared_mem_object.h | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 src/libcamera/pipeline/rpi/common/shared_mem_object.h diff --git a/src/libcamera/pipeline/rpi/common/shared_mem_object.h b/src/libcamera/pipeline/rpi/common/shared_mem_object.h new file mode 100644 index 000000000000..aa56c2209201 --- /dev/null +++ b/src/libcamera/pipeline/rpi/common/shared_mem_object.h @@ -0,0 +1,128 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023, Raspberry Pi Ltd + * + * shared_mem_object.h - Helper class for shared memory allocations + */ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace libcamera { + +namespace RPi { + +template +class SharedMemObject +{ +public: + static constexpr std::size_t SIZE = sizeof(T); + + SharedMemObject() + : obj_(nullptr) + { + } + + template + SharedMemObject(const std::string &name, Args &&...args) + : name_(name), obj_(nullptr) + { + void *mem; + int ret; + + ret = memfd_create(name_.c_str(), MFD_CLOEXEC); + if (ret < 0) + return; + + fd_ = SharedFD(std::move(ret)); + if (!fd_.isValid()) + return; + + ret = ftruncate(fd_.get(), SIZE); + if (ret < 0) + return; + + mem = mmap(nullptr, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, + fd_.get(), 0); + if (mem == MAP_FAILED) + return; + + obj_ = new (mem) T(std::forward(args)...); + } + + SharedMemObject(SharedMemObject &&rhs) + { + this->name_ = std::move(rhs.name_); + this->fd_ = std::move(rhs.fd_); + this->obj_ = rhs.obj_; + rhs.obj_ = nullptr; + } + + ~SharedMemObject() + { + if (obj_) { + obj_->~T(); + munmap(obj_, SIZE); + } + } + + /* Make SharedMemObject non-copyable for now. */ + LIBCAMERA_DISABLE_COPY(SharedMemObject) + + SharedMemObject &operator=(SharedMemObject &&rhs) + { + this->name_ = std::move(rhs.name_); + this->fd_ = std::move(rhs.fd_); + this->obj_ = rhs.obj_; + rhs.obj_ = nullptr; + return *this; + } + + T *operator->() + { + return obj_; + } + + const T *operator->() const + { + return obj_; + } + + T &operator*() + { + return *obj_; + } + + const T &operator*() const + { + return *obj_; + } + + const SharedFD &fd() const + { + return fd_; + } + + explicit operator bool() const + { + return !!obj_; + } + +private: + std::string name_; + SharedFD fd_; + T *obj_; +}; + +} /* namespace RPi */ + +} /* namespace libcamera */ From patchwork Fri Oct 13 07:48:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19128 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 A174FC32B8 for ; Fri, 13 Oct 2023 07:48:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 80C386297E; Fri, 13 Oct 2023 09:48:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183333; bh=rxVei+/bCJL0Jded4ibv1g3xlqNCQ9dDIFL/A3oIamA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=t0xnbzWLU0Dc+vsDT1DV8sssH1mw2EjlPutGeoi4rowQcZMEt7at/TxFnfjo9rAno YN8zWnAQ2oW/PtWAFSNXg1q1weyu40/lnI6+QTd/h2inxZpJUF0K1cx7Ma2POWZy9F MN+JUfCYqCYS1sxU3HlNnP8Zhq37jIJUOb9tZDXx426xQdhhBwH+ZDTSZ+TJgE//rf GpUF2BS0WAEqnPrycIMzYQEaol4mMBX2qpNHtC1waEEgGGeASKNzVv63+LJSksZOKl k9wPpT7D72SHORKZmvw80tGooh9ukOxdbydf0/B4xwri6iBSLJa7L8G5ojsggg5uyl leYfFSChuSNCg== Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4186462980 for ; Fri, 13 Oct 2023 09:48:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="YnDExHuX"; dkim-atps=neutral Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-31f71b25a99so1697576f8f.2 for ; Fri, 13 Oct 2023 00:48:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183329; x=1697788129; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kUh7r73vgyaw/ga4Ir8ecXHXGWBguUKt7Z76Z8tysMU=; b=YnDExHuXlTh+UBbdWeLtW2mB9K4FmKa1227Wk8nqNefhyoYOwYcE1JSVJIB3Yhapjy 81XOkONTRAK6FV0gK3yRLCJ+gaHlGIVmoo4unnTxi76AaTQ7n6HzSui9DUa0rP81sNHR ceZRV/UWTyJfi6T4iZq0/epToILXAMrNAqzgoEHViUs93sIsRfQ2i2SdpjziM3ngIR7s fjjZg3I0SVh63ECqgykVlD77YSLc/o54PH/wN8Wz0yiUGHoo8mZWgEPgsBkVkpthN+Js Mz5DrLlzKH3l4Qt6YTuqgGtG4j+nCBP63RuP/e1bgBXStaWAMpdK2JJxvDdRSTbRz0I0 NVgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183329; x=1697788129; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kUh7r73vgyaw/ga4Ir8ecXHXGWBguUKt7Z76Z8tysMU=; b=Lu0ib9dMXMFwI+O7rQAUfN1Hxxd9de0gXR2RbJstWwqc/9kMWzxWgVJNGnEvz1XdgZ 2P/z/WPas8PF0raj0WSE5RM1d4VKpsqeJnyz0ZiW3KMdQY6pcdCwyCWpIQbMSDygEnzG mVuUAT6WjKLfaDW3ra9/T8BU/pV3gtPnmJuiV/rsmozka5L8aErDfsu0hGwIp07ObdUp Ob6B7xxGfrZD5cpp7T+t/JkWGVayeeJqVIhlMkT9xZwvGW9g4HTJ1q7ml1qSzDtdhSTG 3C+7og1a/TEvZYeOCZksaXp7Val4AeK9YR6nTPJSAS2wwCL+bq6qONbf/RZkpNUzMDgx QuKQ== X-Gm-Message-State: AOJu0YwRMIRICnaEB2en6wJkYXudcGA8hcksxuoQ5KTPSSr8GGlI90Tr eeblZgtOMyehw/Fj04qvQy6ImAuQqymHcslqhYjHWA== X-Google-Smtp-Source: AGHT+IFugMizvcTpEW+nLBMAHZUDyrGkXzxZQaxQxKudxsop3NxvlTgoJ00cyuxdgHn1sTFbxT+PMA== X-Received: by 2002:a05:6000:24a:b0:32d:9337:e7d4 with SMTP id m10-20020a056000024a00b0032d9337e7d4mr3044736wrz.9.1697183329615; Fri, 13 Oct 2023 00:48:49 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:49 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:25 +0100 Message-Id: <20231013074841.16972-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 04/20] ipa: rpi: Add IpaBase::platformStart() member function 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a virtual IpaBase::platformStart() member function that is called at the end of IpaBase::start(). For the IpaVc4 derived class, this function does nothing, but will be used in the PiSP derived class to reset internal state on startup. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- src/ipa/rpi/common/ipa_base.cpp | 2 ++ src/ipa/rpi/common/ipa_base.h | 1 + src/ipa/rpi/vc4/vc4.cpp | 7 +++++++ 3 files changed, 10 insertions(+) diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp index 5df1998c8113..5939fe57f040 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -341,6 +341,8 @@ void IpaBase::start(const ControlList &controls, StartResult *result) firstStart_ = false; lastRunTimestamp_ = 0; + + platformStart(controls, result); } void IpaBase::mapBuffers(const std::vector &buffers) diff --git a/src/ipa/rpi/common/ipa_base.h b/src/ipa/rpi/common/ipa_base.h index 097f436af93b..eaa9f71182ed 100644 --- a/src/ipa/rpi/common/ipa_base.h +++ b/src/ipa/rpi/common/ipa_base.h @@ -67,6 +67,7 @@ private: static constexpr unsigned int numMetadataContexts = 16; virtual int32_t platformInit(const InitParams ¶ms, InitResult *result) = 0; + virtual int32_t platformStart(const ControlList &controls, StartResult *result) = 0; virtual int32_t platformConfigure(const ConfigParams ¶ms, ConfigResult *result) = 0; virtual void platformPrepareIsp(const PrepareParams ¶ms, diff --git a/src/ipa/rpi/vc4/vc4.cpp b/src/ipa/rpi/vc4/vc4.cpp index 1de0d3ccdc44..4a4d720ce7dd 100644 --- a/src/ipa/rpi/vc4/vc4.cpp +++ b/src/ipa/rpi/vc4/vc4.cpp @@ -51,6 +51,7 @@ public: private: int32_t platformInit(const InitParams ¶ms, InitResult *result) override; + int32_t platformStart(const ControlList &controls, StartResult *result) override; int32_t platformConfigure(const ConfigParams ¶ms, ConfigResult *result) override; void platformPrepareIsp(const PrepareParams ¶ms, RPiController::Metadata &rpiMetadata) override; @@ -94,6 +95,12 @@ int32_t IpaVc4::platformInit([[maybe_unused]] const InitParams ¶ms, [[maybe_ return 0; } +int32_t IpaVc4::platformStart([[maybe_unused]] const ControlList &controls, + [[maybe_unused]] StartResult *result) +{ + return 0; +} + int32_t IpaVc4::platformConfigure(const ConfigParams ¶ms, [[maybe_unused]] ConfigResult *result) { ispCtrls_ = params.ispControls; From patchwork Fri Oct 13 07:48:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19129 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 73707C32B9 for ; Fri, 13 Oct 2023 07:48:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 374A162992; Fri, 13 Oct 2023 09:48:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183334; bh=iGMyhmt0bK1VsQNsnIf7pQRklQnUnY6RGTCE1C4YmEg=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=jhDFS4ZaccdEfW/cueQi8TH0NC6qNpPCP0y+I3AKQdImCKtp8m2MtGA8dT5QdCKVb iLwet2fCa+2yjZw4bkc3KC0bCu/+etlEFVUi/oko3e6d5MPWEos3pXXFH3mvylQW+s 65/po8P0GRPVGu9WA0ZnSEXwg0aSaSS/w3uqVWzReRod42SSdMwlNolWSr0a6DayIo 7ceE/zwHpjlJw+3EtpLzr0LQPjK4meisArPmmq7w7ZCpmnQX3s9nj60Rdn2/T3D/AK 8yFi6gG6IivR55f8fLzUo/SQQbCrG2g49VlJP6xUxmwvOkMlOxMLRg/C3dejfyXZEQ 8N4sjPoRwn9uA== Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EEB6762983 for ; Fri, 13 Oct 2023 09:48:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="gOnJlSLB"; dkim-atps=neutral Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-9ada2e6e75fso310237666b.2 for ; Fri, 13 Oct 2023 00:48:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183330; x=1697788130; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BODlzmgW5M/gqIgdlKGcK5w+gODL1ypd7loAk8PQnJM=; b=gOnJlSLBay6u93iE/bVTEvT0u2WWGdTgSN6ZZdUFIiODhftoXv36E8V/ACD9UrrXJn IJMo/VpfVLVnCQJKd5PI/Uz6+lJj/t1Y9xT08aJfBK+lqW2no1cKovfxwS8pNH/Cpzri moiZjcUCzfDIJcpppummZ8qzxiplWodRMf/ZcoGh3YRs4XkSS+zf3e6Vphn4b7hnmD76 32WPfmYuImTJuJd+M9BKrMHgZjoLON1EuHsc3b+GmAFFg2R89G0VM0h3k4gKLxq0nfNK 9/nWqpKL0JZJFITZIUvD02OE1Xam+U51BKxUj1DfzswDBokh1owbtrgSM+XfYwsbbFrt sD8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183330; x=1697788130; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BODlzmgW5M/gqIgdlKGcK5w+gODL1ypd7loAk8PQnJM=; b=ZHVS4DpowSJ0lWqiPPGR/Ykepq+LYQ8OL/Lm7AtQAG0XSWK0VXXGa7XVRSB57G2/Tb R6GBTNTSYbm+TWzMeYvptGCi0dyDluz3AA3pJbtrg1ZRKoZap0evDme+jXXpRgEKc9zk sGKG05QQgVED9zuQ/Ri0hmleWEOgOURVPJkMQenhDKqLK4CcDbsX8fkB61GynK5MbnoD 6uSko42Dh1u5gLGULC3r+tf7QdbdXKMRHK1sTZ8K0qES1W0YcK/vSuVnzWpmG0Sd64o6 hCeBsENlZGaF5RbH9SUGV6V3KSL2i9Lg63tGkgl6i5/HGJwuBRQIlK1eDF1blhj50KUy ePRA== X-Gm-Message-State: AOJu0YyeF8da5RCiE9+X+lqPXOUX9GR/xXMmzGG0D4sZ87TBkxjx1PoD G3+qFp64/c7CHqboRfi5bOgvVX5mFNeOGkpnpTiOpA== X-Google-Smtp-Source: AGHT+IFvYmAzUXCJ1ah/ad2V3Alj1TZETpwxPT+Qg6g/GTAwpCpLvjFv6tFDMZxV2Jwz16iqcit+Ww== X-Received: by 2002:a17:906:cb:b0:9ae:4eb7:ae8b with SMTP id 11-20020a17090600cb00b009ae4eb7ae8bmr26208479eji.7.1697183330320; Fri, 13 Oct 2023 00:48:50 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:49 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:26 +0100 Message-Id: <20231013074841.16972-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 05/20] mojom: pipeline: ipa: rpi: Add fields for PiSP objects 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add the PiSP Frontend and Backend SharedMemObject file descriptors to the ipa::init() call. This will allow the pipeline handler to pass these objects to the IPA after construction. Add a flag to indicate if buffer swaps are needed when starting the ISP for the stitch block. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- include/libcamera/ipa/raspberrypi.mojom | 6 +++++- src/ipa/rpi/common/ipa_base.cpp | 2 +- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index ab4c4e2edca3..5986c4366c15 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -22,6 +22,9 @@ struct SensorConfig { struct InitParams { bool lensPresent; libcamera.IPACameraSensorInfo sensorInfo; + /* PISP specific */ + libcamera.SharedFD fe; + libcamera.SharedFD be; }; struct InitResult { @@ -219,13 +222,14 @@ interface IPARPiEventInterface { * \fn prepareIspComplete() * \brief Signal completion of \a prepareIsp * \param[in] buffers Bayer and embedded buffers actioned. + * \param[in] stitchSwapBuffers Whether the stitch block buffers need to be swapped. * * This asynchronous event is signalled to the pipeline handler once * the \a prepareIsp signal has completed, and the ISP is ready to start * processing the frame. The embedded data buffer may be recycled after * this event. */ - prepareIspComplete(BufferIds buffers); + prepareIspComplete(BufferIds buffers, bool stitchSwapBuffers); /** * \fn processStatsComplete() diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp index 5939fe57f040..97f647a9e53e 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -446,7 +446,7 @@ void IpaBase::prepareIsp(const PrepareParams ¶ms) frameCount_++; /* Ready to push the input buffer into the ISP. */ - prepareIspComplete.emit(params.buffers); + prepareIspComplete.emit(params.buffers, false); } void IpaBase::processStats(const ProcessParams ¶ms) diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index bc90d6324777..233473e2fe2b 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -78,7 +78,7 @@ public: void ispOutputDequeue(FrameBuffer *buffer); void processStatsComplete(const ipa::RPi::BufferIds &buffers); - void prepareIspComplete(const ipa::RPi::BufferIds &buffers); + void prepareIspComplete(const ipa::RPi::BufferIds &buffers, bool stitchSwapBuffers); void setIspControls(const ControlList &controls); void setCameraTimeout(uint32_t maxFrameLengthMs); @@ -833,7 +833,8 @@ void Vc4CameraData::processStatsComplete(const ipa::RPi::BufferIds &buffers) handleState(); } -void Vc4CameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers) +void Vc4CameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers, + [[maybe_unused]] bool stitchSwapBuffers) { unsigned int embeddedId = buffers.embedded & RPi::MaskID; unsigned int bayer = buffers.bayer & RPi::MaskID; From patchwork Fri Oct 13 07:48:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19130 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 AD28FC32BA for ; Fri, 13 Oct 2023 07:48:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1C0E462997; Fri, 13 Oct 2023 09:48:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183336; bh=vyNP6GL/NvQu1qtuus8Vql2nWEyyu0RXUAt+aNcr38w=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=zcPKuR49wNU1f0IC5L6ztP7j7c+bPfTX20cD2OcfUaKY5eiuGuWDF7OHfpKwTx1MZ ZIjrzRA1Sb3L93XT/CD4CEsl1VKjojAjGLUM8QdF3A4NvmNaro7Pr055m9xRdGuohT PitlsQM0WxooWVL0W0BQJmek1BhkDMi7/XLE34EVMwOZViGLCQIsQWdZSXrD2KxIYb elXJpq6MxGg9GLZKqT+pM/BBloUbzb8hWAuN35VSITXjsuNQVVN6oP77ftn9AYYsAd lG21C0GD6SoOhM8lKY8+Tzc6wwqjsG+/I4DJ96u5bIbT+DdRNgPf7H09q3coTmSLjM /7uKQ7euPRSyQ== Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BD66562987 for ; Fri, 13 Oct 2023 09:48:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="i4I5Y/Kw"; dkim-atps=neutral Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4056ce55e7eso18579535e9.2 for ; Fri, 13 Oct 2023 00:48:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183331; x=1697788131; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kw7H4NyscZJrAD6u85gBoZ7kQ4HlC5GeOqW4krYVWeM=; b=i4I5Y/KwLeugpxDX/m5LGTt6hM6kE3SVingFLuG30ZaPpzleNiBR+gc+S5PrCA1nXz nc5RACbeoIqajGPCK93o9WV5iWRtFO1OkNQzFEktN3f6aWGP2YhqR03FQDCH8H/4eMRS 28/x+tCs2R1llEa+W5XJwpI3r9p973vtWjIWy7vYydDDIvk8jrNbRP8LAMB87bUiA/jY 1iW031TBSFub1vlfalBiyevym7/8cKO7iHiWz6e693tIdwhiOj3BEAQYcc9lGOHlVoHg hBUq8iHtwKsyglgTjFazW32r5GPsxxLdgLDBqkeEU9cOMdPzc21MvTcushH7WmTLO1wf YgUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183331; x=1697788131; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kw7H4NyscZJrAD6u85gBoZ7kQ4HlC5GeOqW4krYVWeM=; b=JWRrQvuoq4NsmYvXl2tfnCAhJkZvm+Py/s5eXR6MiBGwIBGW99GW3ZFkjZiL6UFxjB I0T0m3x4yXZ3nxLY85ok8aSOjBzvq3usdFbtr+7aQAfpMz9KPHVPTevcQFkWicl5vTnC 8pWFbKr547AE8Q3RApwq/EKhfQMrgMCjscdhIoYwECW1gzmNZ0V1ZoQ5q8OK0Mxja2yg JMkfg0CdKQz0HV17NSeXoaVNSFoLxfxQsAoV78xqnvtCDEENbas++c6Ku8uXfmWcypU2 d3iLUXYnGwtu+xrVyAEGqwMSnSebzUBunGKoxjPU1iKKe59od5o5XFuKuFQGqKFeArkM S7Sw== X-Gm-Message-State: AOJu0Yz6D4MIx95Az7rQXdF3YuVfzUSe8y6kChQULh6mQuZtXBYoQhyB FTABFRjQGJMrKuNKCIOd3rGLYaIuhlSpe/nDiKx6aA== X-Google-Smtp-Source: AGHT+IGKuGXqdULmnz4qn8uHTL289Nu7moCWC3Q0RsU8NoCy3DhPDQxXZomfivId94qAFCEt/E0xOQ== X-Received: by 2002:a7b:cbd4:0:b0:3fb:b3aa:1c8a with SMTP id n20-20020a7bcbd4000000b003fbb3aa1c8amr23615576wmi.16.1697183331056; Fri, 13 Oct 2023 00:48:51 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:50 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:27 +0100 Message-Id: <20231013074841.16972-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 06/20] ipa: rpi: Add try_lock() to RPiController::Metadata 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add the missing try_lock() member function to RPiController::Metadata. This will allow RPiController::Metadata to be used as a template parameter in std::scoped_lock. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- src/ipa/rpi/controller/metadata.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ipa/rpi/controller/metadata.h b/src/ipa/rpi/controller/metadata.h index bf8a2393457a..a232dcb12456 100644 --- a/src/ipa/rpi/controller/metadata.h +++ b/src/ipa/rpi/controller/metadata.h @@ -116,6 +116,7 @@ public: * e.g. std::lock_guard lock(metadata) */ void lock() LIBCAMERA_TSA_ACQUIRE() { mutex_.lock(); } + auto try_lock() LIBCAMERA_TSA_ACQUIRE() { return mutex_.try_lock(); } void unlock() LIBCAMERA_TSA_RELEASE() { mutex_.unlock(); } private: From patchwork Fri Oct 13 07:48:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19131 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 3F605BD808 for ; Fri, 13 Oct 2023 07:48:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DB3E26299D; Fri, 13 Oct 2023 09:48:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183338; bh=AMtoncnlfTKf3q8Duk6hCk/4s3cQdb6NPrRw2NSrYwA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=vyFs9PYDu468DTcmUeKtutesaz/HskmGQZFjtMKMwFPn1Wia5bkKRHw10vuQLMnAv giWd59Y4DDro0ITELFi826osUGtS7aDXU3MEaGg7Q8znoHfawUSB0YxWpFH6sW7iJ8 TS1n2mhdo+moxYu3t3Sx8MotuGwAA53AO8s6acsZQ8iiB4zfzkGeeFoZ8BJQvgqczc 61WtUxXvoMabH3Qey6SuyC6m3l3dyT3WLSBKC0RfRb4rBxJm4/tw2ZgLwlei2k7nY1 4zIUeFZAECD+AScDrFiBMTia2N6MF8BoSuasEb4Svo1F4wmGQGj4hg1OSnvjMxjrkW RU0CpePoT8SVA== Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5E67D62989 for ; Fri, 13 Oct 2023 09:48:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="nIloUCWO"; dkim-atps=neutral Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-405524e6769so11286925e9.1 for ; Fri, 13 Oct 2023 00:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183331; x=1697788131; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7U80zkN/M8+3OGgpgvJfple7vo+jwEOA04kNzWBIb3g=; b=nIloUCWOrFJkei4VtPMASFFPkd+vv14DGrni4kGjNddDGALKQ/IEHCr+eZx6jHg0q2 937DrX919VXtajFhaeW4Fz8FSwVO9avO/0NjG+J8XGLiAt4fTMYWPFEh0nRz3k+fytyq 8Xy3YAf78zYkpkQ64fGzDlD1+TueVriZwup9vNDj6Cago5ehmi1xZuhnxV8cZ8K9CBR5 KgF+RytjzQ+Ws1Grvc3dMfhNeu8zOKCjUn5ak5Eey1xjL0Z4KPuCiZdY1EtEbeYrOiiV dAHS6eMOnxNhZIZn/LCG6Rse/gBjJfcKVddM9fFnxMD3Hu4KJq4rICmQAymokQF8jsiF X4wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183331; x=1697788131; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7U80zkN/M8+3OGgpgvJfple7vo+jwEOA04kNzWBIb3g=; b=kiq639ehjAWO1+u0qAgr8glxm78TOO4DSI9vGwd+UZMZMAB8PDSvDDj1L/TCL13QPf Q4mOPEW7mQh8S+9NZMouulzrv2Ze+IYdwtZtYaPT2aJ3+Kjdg9T/ktJ7vZ+KUEVnFH5N EzIhQLxl6uCa97O5O6sd3rd7UENAosdq5c1ARoyaNXHQsREOKlj6OGmcdd3V+tehVnqT QkA1L8hlckAK3pUzC1x/hKZpofLgHuoXxgYZEqgWk8xlaveW2kLI/EI+hH8TS113qGXP BcvngCM0523W4yDdTwmnXj2BcI8CL5ysiRpsNYT7E+v65jb9j9awaHl0azFCzs+H4ThA yMMA== X-Gm-Message-State: AOJu0YxvyBmMM/q5DXirKFnkHzztqKWb7L4RygR07oF4yUeML1aHJgIZ d+DMHKCrKq345jAeoID+sfKdiTC3ufSR53G9rc3gaw== X-Google-Smtp-Source: AGHT+IFJm37FHYT3+61JBQmKthTxYIK21j+jsK0yj+WB2g2w1/2+oSxMBHXQ2R4dkheSM33ia7/jhA== X-Received: by 2002:a7b:c4cc:0:b0:402:f91e:df80 with SMTP id g12-20020a7bc4cc000000b00402f91edf80mr19174648wmk.3.1697183331610; Fri, 13 Oct 2023 00:48:51 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:51 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:28 +0100 Message-Id: <20231013074841.16972-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 07/20] ipa: rpi: Add statsInline to the Controller hardware description 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a new boolean field (statsInline) to Controller::HardwareConfigMap. This field indicates where the statistics are generated in the hardware ISP pipeline. For statsInline == true, statistics are generated before the frame is processed (e.g. the PiSP case), and statsInline == false indicates statistics are generated after the frame is processed (e.g. the VC4 case). Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- src/ipa/rpi/common/ipa_base.cpp | 19 ++++++++++++++----- src/ipa/rpi/controller/controller.cpp | 3 ++- src/ipa/rpi/controller/controller.h | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp index 97f647a9e53e..f28eb36b7a44 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -429,11 +429,10 @@ void IpaBase::prepareIsp(const PrepareParams ¶ms) } /* - * If a statistics buffer has been passed in, call processStats - * directly now before prepare() since the statistics are available in-line - * with the Bayer frame. + * If the statistics are inline (i.e. already available with the Bayer + * frame), call processStats() now before prepare(). */ - if (params.buffers.stats) + if (controller_.getHardwareConfig().statsInline) processStats({ params.buffers, params.ipaContext }); /* Do we need/want to call prepare? */ @@ -445,6 +444,10 @@ void IpaBase::prepareIsp(const PrepareParams ¶ms) frameCount_++; + /* If the statistics are inline the metadata can be returned early. */ + if (controller_.getHardwareConfig().statsInline) + reportMetadata(ipaContext); + /* Ready to push the input buffer into the ISP. */ prepareIspComplete.emit(params.buffers, false); } @@ -479,7 +482,13 @@ void IpaBase::processStats(const ProcessParams ¶ms) } } - reportMetadata(ipaContext); + /* + * If the statistics are not inline the metadata must be returned now, + * before the processStatsComplete signal. + */ + if (!controller_.getHardwareConfig().statsInline) + reportMetadata(ipaContext); + processStatsComplete.emit(params.buffers); } diff --git a/src/ipa/rpi/controller/controller.cpp b/src/ipa/rpi/controller/controller.cpp index 14d245da2ce7..4b6f82b41916 100644 --- a/src/ipa/rpi/controller/controller.cpp +++ b/src/ipa/rpi/controller/controller.cpp @@ -34,7 +34,8 @@ static const std::map HardwareConfigMap .focusRegions = { 4, 3 }, .numHistogramBins = 128, .numGammaPoints = 33, - .pipelineWidth = 13 + .pipelineWidth = 13, + .statsInline = false, } }, }; diff --git a/src/ipa/rpi/controller/controller.h b/src/ipa/rpi/controller/controller.h index c6af5cd6c7d4..a8bc61880ab4 100644 --- a/src/ipa/rpi/controller/controller.h +++ b/src/ipa/rpi/controller/controller.h @@ -45,6 +45,7 @@ public: unsigned int numHistogramBins; unsigned int numGammaPoints; unsigned int pipelineWidth; + bool statsInline; }; Controller(); From patchwork Fri Oct 13 07:48:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19132 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 EE35CC32BB for ; Fri, 13 Oct 2023 07:48:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7A5156299C; Fri, 13 Oct 2023 09:48:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183339; bh=grKRcMsPLPTDt0zCnVGMPYfcCnn0WLFzYyoDqxEwl0Q=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=j40VU/MqpL/vR4a/fmDWchTTvLrloA19H8zaUhzs0thK4cUA+3dMFyULQD3x74lgt iVxNptZfPyvpTbFJdye2dUBFLztAD9xR0oH/Plj0pXfL2nNfV5vBGhBXlp3llZF8RZ v8kiShAn562Oqgj4flp3r/kUzRfjnEjJ6f7s+0NDxtpmdieQaUYgvHyUOHY1Y0+yu/ S58Uhc9LWARF/J/sea5ynJ61B/Mfbj4hOc01CGx15V39UsWYD972/01aIKJsHDI1EW qjiHj2bVRkOqKUCVpwUS3Nfei9CVfTHtEoP8NXAA02Y6XijlTEQVQXmLYFhqf90ilm c++IbF3WfyEfA== Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E03B962988 for ; Fri, 13 Oct 2023 09:48:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="e73sxPBg"; dkim-atps=neutral Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5230a22cfd1so3186277a12.1 for ; Fri, 13 Oct 2023 00:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183332; x=1697788132; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dszJkstXMUB4hIMHgiMs+n0waKBu2LYR6hRex+ii310=; b=e73sxPBgX8BRiNDvmJ9usYadvktbNvSzZtKbPnq3viRPUGz5w93gliFkQXUKtJISRe eiKE322XsESeOO42405lEZ4+4enw477al9n/w/PiCkD/BGpeBGIgTcTf7e2AcOooJ77m jvL8IdQOirKaZ/ZqAsg0Bs6P9IJ2o30aPGO8XplT+QcEvnYLsan9V/O83nS7J4vqFs+J eU5KmgRuyti6UINr4wiN1S/0SIUjycYzISt27iHdVYAMDGs306ofyXLFc7I4m5ng0bUe fXa2oKaCbK/LIWRb+CdnAzgM1hU4+CVxRVfgc+J0vaECTTkfd/GdscvEKv9oLsl6j0ud cHNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183332; x=1697788132; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dszJkstXMUB4hIMHgiMs+n0waKBu2LYR6hRex+ii310=; b=LWEyRzlhUyt+TGQZnc2N+qA5wzfpGGDXqlj7Sm2pa15yT2FGRrgEloahKOTJY+850Y 6Q4ej0EYwSRfSKvkgpnpnPvJNZFJN/YJ6YLSblr1GL9uVSS2Blioh/QxI1JIrPwo/W1J HolSxL1yf4xHEaKW4hCgyvjZyoXRt8DEGOApyPzSNFsq0EilZJZ1EDuPHyCbE9ggZII8 EoDG2lV0JSSzzMaPX36RINNBHlDtwZrUfkyEDV7wednBie6xliPShMCrSfcnoFRpb6Oz gAmtY6+uAlcyB8QB9XMzCXqTIf7NCPGUYCYCaUN76GdSI6R+T6mH023wQJZ/EI4U8AGd +K3w== X-Gm-Message-State: AOJu0Yyc+klYSaW2KSubZE/2Xd8pybyNl5GbPEapqtDwS0Tp0I0i586y IcgJ1Ow0mChaaHJoHwpfLsFJZkqtPW2woUFMpU2JTA== X-Google-Smtp-Source: AGHT+IHM10BjP+s0fmXFfQ511pbuhEK/O/6snajg0IuZcvVEpq+qozB4AuETjMtescT6TGMa5ibX7A== X-Received: by 2002:aa7:ccd3:0:b0:538:a47:89d3 with SMTP id y19-20020aa7ccd3000000b005380a4789d3mr21114841edt.21.1697183332205; Fri, 13 Oct 2023 00:48:52 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:51 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:29 +0100 Message-Id: <20231013074841.16972-9-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 08/20] ipa: rpi: Add PiSP definitions to the Controller hardware description 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add an entry to Controller::HardwareConfig describing the PiSP hardware for the IPA and controller algorithms to use. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- src/ipa/rpi/controller/controller.cpp | 15 +++++++++++++++ src/ipa/rpi/controller/controller.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/ipa/rpi/controller/controller.cpp b/src/ipa/rpi/controller/controller.cpp index 4b6f82b41916..e62becd87e85 100644 --- a/src/ipa/rpi/controller/controller.cpp +++ b/src/ipa/rpi/controller/controller.cpp @@ -31,6 +31,7 @@ static const std::map HardwareConfigMap .agcRegions = { 15 , 1 }, .agcZoneWeights = { 15 , 1 }, .awbRegions = { 16, 12 }, + .cacRegions = { 0, 0 }, .focusRegions = { 4, 3 }, .numHistogramBins = 128, .numGammaPoints = 33, @@ -38,6 +39,20 @@ static const std::map HardwareConfigMap .statsInline = false, } }, + { + "pisp", + { + .agcRegions = { 0, 0 }, + .agcZoneWeights = { 15, 15 }, + .awbRegions = { 32, 32 }, + .cacRegions = { 8, 8 }, + .focusRegions = { 8, 8 }, + .numHistogramBins = 1024, + .numGammaPoints = 64, + .pipelineWidth = 16, + .statsInline = true, + } + }, }; Controller::Controller() diff --git a/src/ipa/rpi/controller/controller.h b/src/ipa/rpi/controller/controller.h index a8bc61880ab4..6e5f595284fd 100644 --- a/src/ipa/rpi/controller/controller.h +++ b/src/ipa/rpi/controller/controller.h @@ -41,6 +41,7 @@ public: libcamera::Size agcRegions; libcamera::Size agcZoneWeights; libcamera::Size awbRegions; + libcamera::Size cacRegions; libcamera::Size focusRegions; unsigned int numHistogramBins; unsigned int numGammaPoints; From patchwork Fri Oct 13 07:48:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19133 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 59CEEC32BC for ; Fri, 13 Oct 2023 07:49:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8808362992; Fri, 13 Oct 2023 09:49:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183340; bh=Jjo/F25/0Dv7zcg7UHN1vZt7o6yjnm8ekVoHAswsCJA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=O3ug6L9750ao9wlgp+WeSoC3NgcJPZ6vaXIM4M375UD0/iMC9p0c+SeArXtmVK4Pu vAU+bw149+sioVmj+sCuVEdD4WoUevjt/qAau5calpXp7k/BshJu/mdPrF60OJKUiy FOSTDonB2sx0uLXmaIVJ1Hh7TB91rqbdnEAbLjyepqvlvc66bA6Wc2N1KpFO5XoJau sXKQw9HnA+DtceEnqEWfvaZXAL5eZN/ggCHprsyHZDw0igkAGt54xp2I7yvqDNZQF8 n145uRI+2vkONKsZ8iFWqJIrvtsUYMPbPOKI1+Nd0KVG6pKtcr855m28eKNFFSyHzZ LpStTjivlR8Ew== Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BBD1462986 for ; Fri, 13 Oct 2023 09:48:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="PmWkNhh2"; dkim-atps=neutral Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40666aa674fso18810115e9.0 for ; Fri, 13 Oct 2023 00:48:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183333; x=1697788133; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v0nbS29QoQ7yqrDXklQ2NX32XLs3Z77SCfUCSFVZHik=; b=PmWkNhh2iRfW84fnVWud+Vq7Xi+qEAsv9i1POq6L/EREinY9vFvWxFW35gKSGTJZxf J/mfxTu4RMspOQxsyRgToCXntqMNFak45CwFhd8kwgvFhCypkwKb13jQwXt2I0KZvoZP OYsvIwWvvfG62DM5s2iU0LJ+h3SQJMdZkQK2/pieWX6+etbK3WcsIxAfeoZMroveidQy +0F9wHVMUl4KGDqdTbjRR13Rd6xPwCeefsOFLKEeyCdh0BzpxV563IqebE/to/YCLFbp 53IKOyGMW7Qv+UZ+oAnVmrnQRs6Pq2b8JdmV1/aUhAbczTHQM3OUbDmv1/6p6J1QMn3g /PwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183333; x=1697788133; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v0nbS29QoQ7yqrDXklQ2NX32XLs3Z77SCfUCSFVZHik=; b=hAtaZIK4lW0KLnl0UQgcubBll2+dgwuCK380oRrDV8zvz7WdTC8BubcBjz/dDoR2Av siBPEl1X8yloQsk7PlziYNfr+NlT30zWNVv+u1ju/kqrw2keB0ojOX/QJbb1G1LQHdt8 Nip/loLsudKXWDvPMLEGr+jI7CyyENciyJmM7el9d0Op8wJYYlnaRPak/Q9Y9DuBKNCn JIkWj5iQaR/WDV998fg2DU8qQPCp3sO325PbQzn5PYNVgcinCkI5Jbg/z1dTbuH66U5J oKOys9+gnZBeOMoukJdwBmQdxhqP9tcvmPlEaEMNlC3EXV7ZS7dHUtPeKINRi4kQTYnI vqFA== X-Gm-Message-State: AOJu0YxfybKQulQCj4d5QuFCwR6bhDHbtoKkDJxB5SwkyXZ6hU18RNfb F7Vq+9Sf1GRwC7723HCGEmrIuM1nIA/MqFDiczOR9Q== X-Google-Smtp-Source: AGHT+IHi2pG37WGEmkyxneBt1cC3Aj5Bm3QyI+GyPBNd2Mwg+/QcOhD7ENu+leXEZsTNzpSVe7y9tw== X-Received: by 2002:a7b:c393:0:b0:401:bd2e:49fc with SMTP id s19-20020a7bc393000000b00401bd2e49fcmr23748595wmj.24.1697183332983; Fri, 13 Oct 2023 00:48:52 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:52 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:30 +0100 Message-Id: <20231013074841.16972-10-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 09/20] ipa: rpi: Prepare ALSC for PiSP support 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- 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 ®ions, StatisticsPtr &stats, const std::vector &bTable = status.b; for (unsigned int i = 0; i < stats->awbRegions.numRegions(); i++) { auto r = stats->awbRegions.get(i); - r.val.rSum = static_cast(r.val.rSum / rTable[i]); - r.val.gSum = static_cast(r.val.gSum / gTable[i]); - r.val.bSum = static_cast(r.val.bSum / bTable[i]); + if (stats->colourStatsPos == Statistics::ColourStatsPos::PostLsc) { + r.val.rSum = static_cast(r.val.rSum / rTable[i]); + r.val.gSum = static_cast(r.val.gSum / gTable[i]); + r.val.bSum = static_cast(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) From patchwork Fri Oct 13 07:48:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19134 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 90A9CC3274 for ; Fri, 13 Oct 2023 07:49:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 38B4B629AB; Fri, 13 Oct 2023 09:49:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183342; bh=tp/MwLhP6gZ1z/A6Ll2u9PkxFUFlzobD3MPo84nfCtg=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=cLkm0GLBt+jQwNDfZKOCqU113O37TKOFnXUQmeJUmbaucjs6yVoOQdjDPr+3bkNGt N3sHAB/q2nnL0bIkKssJUGGbO4vgvS+iaRBx5vRwcNk++az1XZDyWtF08m3MblRBiZ bXXScOb1i3SWCkjnjoaBg8WZD5ojxbAC4WbALBQoYP18qEMmARlRaMspIgrPS1Vh61 YjaKbNDOZD7cUg5GtIpDMdU8PIpQJ8K1kuu2N4RTf28YcjkdWLISn8XVu8PSayXUI1 BbGk1pXU+FbU6psrijCuQfxFJTnwyTGIB7rPRvjjHk4spXOuB0JPvrnI/poVil5EhB 4sRaJm4g+iayw== Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 304C362991 for ; Fri, 13 Oct 2023 09:48:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="dQNaEGxL"; dkim-atps=neutral Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40666aa674fso18810165e9.0 for ; Fri, 13 Oct 2023 00:48:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183333; x=1697788133; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1uiXMJfgz2P+0kPDj41SLrSF7nj0Ja1wBeD8+vQd89M=; b=dQNaEGxLBNMGFmLAqGNd7wrkJQ/PnBN6nSf3O4lzs8RwrtCIyD0Re3GHK1TvFlg+5r FGcGL7OMDh2TcgA16BnvVSYjAhttz2sZWPA9MSKq2uvIHHSssZ5k98LmLVZp8zuMQKBn eo2M/AmfIZti6jFshkvAGNFC5iOIaV4EQ9N7qrhYLV3ZkoTGLk3bK6uuckQcU2JXNagp Ep+F5SiEM7IM/wMPRnakGV6/zwzlwAmBOvqs05LtQVi3Mj7qrOEJSM39dDNE4OJFVhDw /Uu3HYF4HlaPtS2ekLLeaF5VyC01QaThYxWkqBnzWfH+NSDTUCguuuC35MgWsxUdAeCu 0Lnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183333; x=1697788133; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1uiXMJfgz2P+0kPDj41SLrSF7nj0Ja1wBeD8+vQd89M=; b=Px88crImV5Vdba70E174bqV5GxwpqCgFjwY1Y1hMKLCa+EErayZruiOMjMFpiei8J+ 6C6XeSj+w0DjArFdPZ2pZxcYeZPJ2ZsWxeUThFaBQ5c24s1PoUTP5JlCKqv8cPsJvAqO sbj1syx7XSqYbw7zmNhRrXeFo4rbi3npYPQJcUvPwlLI4BLdSyGu87cB1xPaBgnwxZuo XxYkoMJo/vo3EFmw/gM4wysjEInsggKO6cOWCyoqOq6iypzQTKv5btkjUNrC/nxGQMPi ylDi7aCibQ8wC97Dc3gqbx0vNsMH3f1widzMPbTfzlHUQvWd0KHPtWSh5I+8cxpxtj+v 81Fw== X-Gm-Message-State: AOJu0Ywexn0oybOCKo/WiNMWUQkBTcV/HUTuDO4kL0xwzz2+FosbbhcT c4EtLRJHUknGAs/I6HF6K3T3t3giszp39A3H1RyE1g== X-Google-Smtp-Source: AGHT+IEV6TSzJEQsjfX8UMMPZu0hqnM2Z763yppl3EwmdFTMwQ4AtfzoQfrcUmvkmR3cIbVFKXg9+g== X-Received: by 2002:a05:600c:2146:b0:401:daf2:2735 with SMTP id v6-20020a05600c214600b00401daf22735mr21997420wml.31.1697183333548; Fri, 13 Oct 2023 00:48:53 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:53 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:31 +0100 Message-Id: <20231013074841.16972-11-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 10/20] ipa: rpi: Prepare AWB for PiSP support 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Prepare the AWB algorithm to support the PiSP hardware. The key change is to factor in the LS correction in the AWB zone statistics. This is different from VC4 where the LS correction happens before statistics gathering. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- src/ipa/rpi/controller/rpi/awb.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp index ef3435d66106..5ae0c2fad6e9 100644 --- a/src/ipa/rpi/controller/rpi/awb.cpp +++ b/src/ipa/rpi/controller/rpi/awb.cpp @@ -12,6 +12,7 @@ #include "../lux_status.h" +#include "alsc_status.h" #include "awb.h" using namespace RPiController; @@ -398,18 +399,28 @@ void Awb::asyncFunc() } static void generateStats(std::vector &zones, - RgbyRegions &stats, double minPixels, - double minG) + StatisticsPtr &stats, double minPixels, + double minG, Metadata &globalMetadata) { - for (auto const ®ion : stats) { + std::scoped_lock l(globalMetadata); + + for (unsigned int i = 0; i < stats->awbRegions.numRegions(); i++) { Awb::RGB zone; + auto ®ion = stats->awbRegions.get(i); if (region.counted >= minPixels) { zone.G = region.val.gSum / region.counted; - if (zone.G >= minG) { - zone.R = region.val.rSum / region.counted; - zone.B = region.val.bSum / region.counted; - zones.push_back(zone); + if (zone.G < minG) + continue; + zone.R = region.val.rSum / region.counted; + zone.B = region.val.bSum / region.counted; + /* Factor in the ALSC applied colour shading correction if required. */ + const AlscStatus *alscStatus = globalMetadata.getLocked("alsc.status"); + if (stats->colourStatsPos == Statistics::ColourStatsPos::PreLsc && alscStatus) { + zone.R *= alscStatus->r[i]; + zone.G *= alscStatus->g[i]; + zone.B *= alscStatus->b[i]; } + zones.push_back(zone); } } } @@ -421,8 +432,8 @@ void Awb::prepareStats() * LSC has already been applied to the stats in this pipeline, so stop * any LSC compensation. We also ignore config_.fast in this version. */ - generateStats(zones_, statistics_->awbRegions, config_.minPixels, - config_.minG); + generateStats(zones_, statistics_, config_.minPixels, + config_.minG, getGlobalMetadata()); /* * apply sensitivities, so values appear to come from our "canonical" * sensor. From patchwork Fri Oct 13 07:48:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19136 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 84763C32BE for ; Fri, 13 Oct 2023 07:49:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0FC4C62986; Fri, 13 Oct 2023 09:49:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183344; bh=InJk5nE/LHRBOTGRWjRFoKav2SdmaIyuGdMs8XQP2Ek=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=AuFTsBtJf7UG715DjW7aBOCQ+bqPYsNooJrskZYnPjbp90VbKbvfjVvPEdb6xf+ic l6g2QwNxgD8ynnlsLJV9Id86NvOX9KHMBc/UttfCdotWN8PL/0RrCH3yRwOQADYmOP armPGtS5BR42Xfv1BV1s4Y8Y9/T/OxSM2jwSjw9uWcSkv32SeR0pPViVTBMGZdeGqX xq4Aapjx8QS4dKZ9uWRZPOSDCw5pzxdF/POVaCP3fECY1BkLq1RNpvb+Q+D1u0tTHG byU6BOG9IX3sC6Hlt5lW30CojRZoqIPWUY59YggI0gigNadA5JpXjcI7DEFGuAyNVY DS+3TbCeh6tzA== Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7BBE262985 for ; Fri, 13 Oct 2023 09:48:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="P0GdK46u"; dkim-atps=neutral Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-9adca291f99so269716266b.2 for ; Fri, 13 Oct 2023 00:48:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183335; x=1697788135; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VR+P5mQIrApbu0Xnw/5rpn4ma5izTxpcrx2OEmGcuNM=; b=P0GdK46u89r+6WZ19KATX+/h8tCl/e241FQ2t4wvmSS9Lw4fDMI9xWGngpsbTGwegx BQI/ghglm14/4Oj11OhfdTdNRp7kQ5EdnAoj2oB0vjIAtZKCoHZ+XBFHX32Ga4i1RGjZ JIPB0CYwRSIs6WHfB+tm3wQqsSKFt+aNV7F6bkWktS3ATW5SUT+iUcJZYXDEe0cnZLYE NwIv2yRq0BBBYRs+4aDapqyBoSbg2avrN8uNxlt8g2oLW+H6ax8Pb7Bl+DJT9+LL4HkT cynNuLej2A7Wia3MC13D7nNaBqYdGsiNJBl9hkXzJzPrFPZz/PRqc6Q3THRE3Bpobvyk Bc/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183335; x=1697788135; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VR+P5mQIrApbu0Xnw/5rpn4ma5izTxpcrx2OEmGcuNM=; b=DzdqUT5pzxNRE1l1pSqI0IFk8oRpsfGckAy5k6Va42c3TPCLHzFZYULpZ52HQx/+/K b1+zfnPt/D08g2fT3S1kNK3RdRM0eM5xfCQ4v/PmG1k0K4p3i9zK55zc8RW279n2HJNB dgqWEFeC8L8rLmnXI3lfeFrukHeZ3LXBHpTG3uKJ2BRXl2tg3xfYkFnqp7S88b4QWOWL u3ESYLgzf1JvcWu+ZIFAjEqkeHg2Y5xto0qhtMJu5CAJA4Nf+MHSdJrbTLso8YGFtPRs uVJrIJsaPRvnWDKpTEzgQMqWWzGccf7uuRZT5KilLI/Jtj3ObOiEeai6yAHmaXTx4ZTq enJQ== X-Gm-Message-State: AOJu0YzF2oxM0p4WLnvVJLqZWwE2lNxKp3rz3qm5Z1QkRaZbEAcYx9Sj lM69JpmKpS117uvNWV4e19BCxhXta0cSIi1mhwUUSg== X-Google-Smtp-Source: AGHT+IHFq8vmCifoWhvGboCptFa00ahf602vhXu3HRe1bXrfJGbvv/5WCyYbdTFD3TQryFkjgpVUoA== X-Received: by 2002:a17:906:1d:b0:9b2:9a0e:9972 with SMTP id 29-20020a170906001d00b009b29a0e9972mr24309921eja.13.1697183334359; Fri, 13 Oct 2023 00:48:54 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:53 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:32 +0100 Message-Id: <20231013074841.16972-12-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 11/20] ipa: rpi: Add new algorithms for PiSP 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add new CAC, HDR, Saturation and Tonemapping algorithms. Add a new Denoise algorithm that handles spatial/temporal/colour denoise through one interface. With this change, the old SDN algorithm is now considered deprecated and a warning message will be displayed if it is enabled. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- src/ipa/rpi/controller/agc_status.h | 3 + src/ipa/rpi/controller/cac_status.h | 16 ++ src/ipa/rpi/controller/denoise_status.h | 19 ++ src/ipa/rpi/controller/hdr_algorithm.h | 25 ++ src/ipa/rpi/controller/hdr_status.h | 19 ++ src/ipa/rpi/controller/meson.build | 5 + src/ipa/rpi/controller/rpi/cac.cpp | 81 +++++++ src/ipa/rpi/controller/rpi/cac.h | 38 +++ src/ipa/rpi/controller/rpi/denoise.cpp | 156 ++++++++++++ src/ipa/rpi/controller/rpi/denoise.h | 49 ++++ src/ipa/rpi/controller/rpi/hdr.cpp | 270 +++++++++++++++++++++ src/ipa/rpi/controller/rpi/hdr.h | 72 ++++++ src/ipa/rpi/controller/rpi/saturation.cpp | 57 +++++ src/ipa/rpi/controller/rpi/saturation.h | 32 +++ src/ipa/rpi/controller/rpi/sdn.cpp | 2 + src/ipa/rpi/controller/rpi/tonemap.cpp | 61 +++++ src/ipa/rpi/controller/rpi/tonemap.h | 35 +++ src/ipa/rpi/controller/saturation_status.h | 13 + src/ipa/rpi/controller/stitch_status.h | 17 ++ src/ipa/rpi/controller/tonemap_status.h | 17 ++ 20 files changed, 987 insertions(+) create mode 100644 src/ipa/rpi/controller/cac_status.h create mode 100644 src/ipa/rpi/controller/hdr_algorithm.h create mode 100644 src/ipa/rpi/controller/hdr_status.h create mode 100644 src/ipa/rpi/controller/rpi/cac.cpp create mode 100644 src/ipa/rpi/controller/rpi/cac.h create mode 100644 src/ipa/rpi/controller/rpi/denoise.cpp create mode 100644 src/ipa/rpi/controller/rpi/denoise.h create mode 100644 src/ipa/rpi/controller/rpi/hdr.cpp create mode 100644 src/ipa/rpi/controller/rpi/hdr.h create mode 100644 src/ipa/rpi/controller/rpi/saturation.cpp create mode 100644 src/ipa/rpi/controller/rpi/saturation.h create mode 100644 src/ipa/rpi/controller/rpi/tonemap.cpp create mode 100644 src/ipa/rpi/controller/rpi/tonemap.h create mode 100644 src/ipa/rpi/controller/saturation_status.h create mode 100644 src/ipa/rpi/controller/stitch_status.h create mode 100644 src/ipa/rpi/controller/tonemap_status.h diff --git a/src/ipa/rpi/controller/agc_status.h b/src/ipa/rpi/controller/agc_status.h index e5c4ee2239d9..68f899585740 100644 --- a/src/ipa/rpi/controller/agc_status.h +++ b/src/ipa/rpi/controller/agc_status.h @@ -10,6 +10,8 @@ #include +#include "hdr_status.h" + /* * The AGC algorithm process method should post an AgcStatus into the image * metadata under the tag "agc.status". @@ -37,6 +39,7 @@ struct AgcStatus { libcamera::utils::Duration fixedShutter; double fixedAnalogueGain; unsigned int channel; + HdrStatus hdr; }; struct AgcPrepareStatus { diff --git a/src/ipa/rpi/controller/cac_status.h b/src/ipa/rpi/controller/cac_status.h new file mode 100644 index 000000000000..475d4c5cc734 --- /dev/null +++ b/src/ipa/rpi/controller/cac_status.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2023 Raspberry Pi Ltd + * + * CAC (Chromatic Abberation Correction) algorithm status + */ +#pragma once + +#include "pwl.h" + +struct CacStatus { + std::vector lutRx; + std::vector lutRy; + std::vector lutBx; + std::vector lutBy; +}; diff --git a/src/ipa/rpi/controller/denoise_status.h b/src/ipa/rpi/controller/denoise_status.h index f6b9ee29dad6..4d2bd291f2f1 100644 --- a/src/ipa/rpi/controller/denoise_status.h +++ b/src/ipa/rpi/controller/denoise_status.h @@ -14,3 +14,22 @@ struct DenoiseStatus { double strength; unsigned int mode; }; + +struct SdnStatus { + double noiseConstant; + double noiseSlope; + double noiseConstant2; + double noiseSlope2; + double strength; +}; + +struct CdnStatus { + double strength; + double threshold; +}; + +struct TdnStatus { + double noiseConstant; + double noiseSlope; + double threshold; +}; diff --git a/src/ipa/rpi/controller/hdr_algorithm.h b/src/ipa/rpi/controller/hdr_algorithm.h new file mode 100644 index 000000000000..f622e099b6f5 --- /dev/null +++ b/src/ipa/rpi/controller/hdr_algorithm.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2023, Raspberry Pi Ltd + * + * hdr_algorithm.h - HDR control algorithm interface + */ +#pragma once + +#include + +#include "algorithm.h" + +namespace RPiController { + +class HdrAlgorithm : public Algorithm +{ +public: + HdrAlgorithm(Controller *controller) + : Algorithm(controller) {} + /* An HDR algorithm must provide the following: */ + virtual int setMode(std::string const &modeName) = 0; + virtual std::vector getChannels() const = 0; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/rpi/controller/hdr_status.h b/src/ipa/rpi/controller/hdr_status.h new file mode 100644 index 000000000000..24b1a9358871 --- /dev/null +++ b/src/ipa/rpi/controller/hdr_status.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2023 Raspberry Pi Ltd + * + * hdr_status.h - HDR control algorithm status + */ +#pragma once + +#include + +/* + * The HDR algorithm process method should post an HdrStatus into the image + * metadata under the tag "hdr.status". + */ + +struct HdrStatus { + std::string mode; + std::string channel; +}; diff --git a/src/ipa/rpi/controller/meson.build b/src/ipa/rpi/controller/meson.build index 20b9cda93661..32a4d31cfada 100644 --- a/src/ipa/rpi/controller/meson.build +++ b/src/ipa/rpi/controller/meson.build @@ -12,14 +12,19 @@ rpi_ipa_controller_sources = files([ 'rpi/alsc.cpp', 'rpi/awb.cpp', 'rpi/black_level.cpp', + 'rpi/cac.cpp', 'rpi/ccm.cpp', 'rpi/contrast.cpp', + 'rpi/denoise.cpp', 'rpi/dpc.cpp', 'rpi/geq.cpp', + 'rpi/hdr.cpp', 'rpi/lux.cpp', 'rpi/noise.cpp', + 'rpi/saturation.cpp', 'rpi/sdn.cpp', 'rpi/sharpen.cpp', + 'rpi/tonemap.cpp', ]) rpi_ipa_controller_deps = [ diff --git a/src/ipa/rpi/controller/rpi/cac.cpp b/src/ipa/rpi/controller/rpi/cac.cpp new file mode 100644 index 000000000000..7c123da1530a --- /dev/null +++ b/src/ipa/rpi/controller/rpi/cac.cpp @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2023 Raspberry Pi Ltd + * + * cac.cpp - Chromatic Aberration Correction algorithm + */ +#include "cac.h" + +#include + +#include "cac_status.h" + +using namespace RPiController; +using namespace libcamera; + +LOG_DEFINE_CATEGORY(RPiCac) + +#define NAME "rpi.cac" + +Cac::Cac(Controller *controller) + : Algorithm(controller) +{ +} + +char const *Cac::name() const +{ + return NAME; +} + +int Cac::read(const libcamera::YamlObject ¶ms) +{ + arrayToSet(params["lut_rx"], config_.lutRx); + arrayToSet(params["lut_ry"], config_.lutRy); + arrayToSet(params["lut_bx"], config_.lutBx); + arrayToSet(params["lut_by"], config_.lutBy); + cacStatus_.lutRx = config_.lutRx; + cacStatus_.lutRy = config_.lutRy; + cacStatus_.lutBx = config_.lutBx; + cacStatus_.lutBy = config_.lutBy; + double strength = params["strength"].get(1); + setStrength(config_.lutRx, cacStatus_.lutRx, strength); + setStrength(config_.lutBx, cacStatus_.lutBx, strength); + setStrength(config_.lutRy, cacStatus_.lutRy, strength); + setStrength(config_.lutBy, cacStatus_.lutBy, strength); + return 0; +} + +void Cac::initialise() +{ +} + +void Cac::arrayToSet(const libcamera::YamlObject ¶ms, std::vector &inputArray) +{ + int num = 0; + const Size &size = getHardwareConfig().cacRegions; + inputArray.resize((size.width + 1) * (size.height + 1)); + for (const auto &p : params.asList()) { + inputArray[num++] = p.get(0); + } +} + +void Cac::setStrength(std::vector &inputArray, std::vector &outputArray, + double strengthFactor) +{ + int num = 0; + for (const auto &p : inputArray) { + outputArray[num++] = p * strengthFactor; + } +} + +void Cac::prepare(Metadata *imageMetadata) +{ + imageMetadata->set("cac.status", cacStatus_); +} + +// Register algorithm with the system. +static Algorithm *Create(Controller *controller) +{ + return (Algorithm *)new Cac(controller); +} +static RegisterAlgorithm reg(NAME, &Create); diff --git a/src/ipa/rpi/controller/rpi/cac.h b/src/ipa/rpi/controller/rpi/cac.h new file mode 100644 index 000000000000..419180ab7d29 --- /dev/null +++ b/src/ipa/rpi/controller/rpi/cac.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2023, Raspberry Pi Ltd + * + * cac.hpp - CAC control algorithm + */ +#pragma once + +#include "algorithm.h" +#include "cac_status.h" + +namespace RPiController { + +struct CacConfig { + std::vector lutRx; + std::vector lutRy; + std::vector lutBx; + std::vector lutBy; +}; + +class Cac : public Algorithm +{ +public: + Cac(Controller *controller = NULL); + char const *name() const override; + int read(const libcamera::YamlObject ¶ms) override; + void initialise() override; + void prepare(Metadata *imageMetadata) override; + void setStrength(std::vector &inputArray, std::vector &outputArray, + double strengthFactor); + +private: + CacConfig config_; + CacStatus cacStatus_; + void arrayToSet(const libcamera::YamlObject ¶ms, std::vector &inputArray); +}; + +} // namespace RPiController diff --git a/src/ipa/rpi/controller/rpi/denoise.cpp b/src/ipa/rpi/controller/rpi/denoise.cpp new file mode 100644 index 000000000000..440ee4425534 --- /dev/null +++ b/src/ipa/rpi/controller/rpi/denoise.cpp @@ -0,0 +1,156 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022 Raspberry Pi Ltd + * + * Denoise.cpp - Denoise (spatial, colour, temporal) control algorithm + */ +#include "denoise.h" + +#include + +#include "denoise_status.h" +#include "noise_status.h" + +using namespace RPiController; +using namespace libcamera; + +LOG_DEFINE_CATEGORY(RPiDenoise) + +// Calculate settings for the denoise blocks using the noise profile in +// the image metadata. + +#define NAME "rpi.denoise" + +Denoise::Denoise(Controller *controller) + : DenoiseAlgorithm(controller), mode_(DenoiseMode::ColourHighQuality) +{ +} + +char const *Denoise::name() const +{ + return NAME; +} + +int Denoise::read(const libcamera::YamlObject ¶ms) +{ + sdnEnable_ = params.contains("sdn"); + if (sdnEnable_) { + auto &sdnParams = params["sdn"]; + sdnDeviation_ = sdnParams["deviation"].get(3.2); + sdnStrength_ = sdnParams["strength"].get(0.25); + sdnDeviation2_ = sdnParams["deviation2"].get(sdnDeviation_); + sdnDeviationNoTdn_ = sdnParams["deviation_no_tdn"].get(sdnDeviation_); + sdnStrengthNoTdn_ = sdnParams["strength_no_tdn"].get(sdnStrength_); + sdnTdnBackoff_ = sdnParams["backoff"].get(0.75); + } + + cdnEnable_ = params.contains("cdn"); + if (cdnEnable_) { + auto &cdnParams = params["cdn"]; + cdnDeviation_ = cdnParams["deviation"].get(120); + cdnStrength_ = cdnParams["strength"].get(0.2); + } + + tdnEnable_ = params.contains("tdn"); + if (tdnEnable_) { + auto &tdnParams = params["tdn"]; + tdnDeviation_ = tdnParams["deviation"].get(0.5); + tdnThreshold_ = tdnParams["threshold"].get(0.75); + } else if (sdnEnable_) { + /* + * If SDN is enabled but TDN isn't, overwrite all the SDN settings + * with the "no TDN" versions. This makes it easier to enable or + * disable TDN in the tuning file without editing all the other + * parameters. + */ + sdnDeviation_ = sdnDeviation2_ = sdnDeviationNoTdn_; + sdnStrength_ = sdnStrengthNoTdn_; + } + + return 0; +} + +void Denoise::initialise() +{ +} + +void Denoise::switchMode([[maybe_unused]] CameraMode const &cameraMode, + [[maybe_unused]] Metadata *metadata) +{ + /* A mode switch effectively resets temporal denoise and it has to start over. */ + currentSdnDeviation_ = sdnDeviationNoTdn_; + currentSdnStrength_ = sdnStrengthNoTdn_; + currentSdnDeviation2_ = sdnDeviationNoTdn_; +} + +void Denoise::prepare(Metadata *imageMetadata) +{ + struct NoiseStatus noiseStatus = {}; + noiseStatus.noiseSlope = 3.0; // in case no metadata + if (imageMetadata->get("noise.status", noiseStatus) != 0) + LOG(RPiDenoise, Warning) << "no noise profile found"; + + LOG(RPiDenoise, Debug) + << "Noise profile: constant " << noiseStatus.noiseConstant + << " slope " << noiseStatus.noiseSlope; + + if (mode_ == DenoiseMode::Off) + return; + + if (sdnEnable_) { + struct SdnStatus sdn; + sdn.noiseConstant = noiseStatus.noiseConstant * currentSdnDeviation_; + sdn.noiseSlope = noiseStatus.noiseSlope * currentSdnDeviation_; + sdn.noiseConstant2 = noiseStatus.noiseConstant * sdnDeviation2_; + sdn.noiseSlope2 = noiseStatus.noiseSlope * currentSdnDeviation2_; + sdn.strength = currentSdnStrength_; + imageMetadata->set("sdn.status", sdn); + LOG(RPiDenoise, Debug) + << "const " << sdn.noiseConstant + << " slope " << sdn.noiseSlope + << " str " << sdn.strength + << " const2 " << sdn.noiseConstant2 + << " slope2 " << sdn.noiseSlope2; + + /* For the next frame, we back off the SDN parameters as TDN ramps up. */ + double f = sdnTdnBackoff_; + currentSdnDeviation_ = f * currentSdnDeviation_ + (1 - f) * sdnDeviation_; + currentSdnStrength_ = f * currentSdnStrength_ + (1 - f) * sdnStrength_; + currentSdnDeviation2_ = f * currentSdnDeviation2_ + (1 - f) * sdnDeviation2_; + } + + if (tdnEnable_) { + struct TdnStatus tdn; + tdn.noiseConstant = noiseStatus.noiseConstant * tdnDeviation_; + tdn.noiseSlope = noiseStatus.noiseSlope * tdnDeviation_; + tdn.threshold = tdnThreshold_; + imageMetadata->set("tdn.status", tdn); + LOG(RPiDenoise, Debug) + << "programmed tdn threshold " << tdn.threshold + << " constant " << tdn.noiseConstant + << " slope " << tdn.noiseSlope; + } + + if (cdnEnable_ && mode_ != DenoiseMode::ColourOff) { + struct CdnStatus cdn; + cdn.threshold = cdnDeviation_ * noiseStatus.noiseSlope + noiseStatus.noiseConstant; + cdn.strength = cdnStrength_; + imageMetadata->set("cdn.status", cdn); + LOG(RPiDenoise, Debug) + << "programmed cdn threshold " << cdn.threshold + << " strength " << cdn.strength; + } +} + +void Denoise::setMode(DenoiseMode mode) +{ + // We only distinguish between off and all other modes. + mode_ = mode; +} + +// Register algorithm with the system. +static Algorithm *Create(Controller *controller) +{ + return (Algorithm *)new Denoise(controller); +} +static RegisterAlgorithm reg(NAME, &Create); diff --git a/src/ipa/rpi/controller/rpi/denoise.h b/src/ipa/rpi/controller/rpi/denoise.h new file mode 100644 index 000000000000..88b37663e569 --- /dev/null +++ b/src/ipa/rpi/controller/rpi/denoise.h @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022, Raspberry Pi Ltd + * + * denoise.hpp - Denoise (spatial, colour, temporal) control algorithm + */ +#pragma once + +#include "algorithm.h" +#include "denoise_algorithm.h" + +namespace RPiController { + +// Algorithm to calculate correct denoise settings. + +class Denoise : public DenoiseAlgorithm +{ +public: + Denoise(Controller *controller); + char const *name() const override; + int read(const libcamera::YamlObject ¶ms) override; + void initialise() override; + void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; + void prepare(Metadata *imageMetadata) override; + void setMode(DenoiseMode mode) override; + +private: + double sdnDeviation_; + double sdnStrength_; + double sdnDeviation2_; + double sdnDeviationNoTdn_; + double sdnStrengthNoTdn_; + double sdnTdnBackoff_; + double cdnDeviation_; + double cdnStrength_; + double tdnDeviation_; + double tdnThreshold_; + DenoiseMode mode_; + bool tdnEnable_; + bool sdnEnable_; + bool cdnEnable_; + + /* SDN parameters attenuate over time if TDN is running. */ + double currentSdnDeviation_; + double currentSdnStrength_; + double currentSdnDeviation2_; +}; + +} // namespace RPiController diff --git a/src/ipa/rpi/controller/rpi/hdr.cpp b/src/ipa/rpi/controller/rpi/hdr.cpp new file mode 100644 index 000000000000..295e4c5f1c0a --- /dev/null +++ b/src/ipa/rpi/controller/rpi/hdr.cpp @@ -0,0 +1,270 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2023 Raspberry Pi Ltd + * + * hdr.cpp - HDR control algorithm + */ + +#include "hdr.h" + +#include + +#include "../agc_status.h" +#include "../stitch_status.h" +#include "../tonemap_status.h" + +using namespace RPiController; +using namespace libcamera; + +LOG_DEFINE_CATEGORY(RPiHdr) + +#define NAME "rpi.hdr" + +void HdrConfig::read(const libcamera::YamlObject ¶ms, const std::string &modeName) +{ + name = modeName; + + if (!params.contains("cadence")) + LOG(RPiHdr, Fatal) << "No cadence for HDR mode " << name; + cadence = params["cadence"].getList().value(); + if (cadence.empty()) + LOG(RPiHdr, Fatal) << "Empty cadence in HDR mode " << name; + + /* + * In the JSON file it's easier to use the channel name as the key, but + * for us it's convenient to swap them over. + */ + for (const auto &[k, v] : params["channel_map"].asDict()) + channelMap[v.get().value()] = k; + + /* Read any tonemap parameters. */ + tonemapEnable = params["tonemap_enable"].get(0); + detailConstant = params["detail_constant"].get(50); + detailSlope = params["detail_slope"].get(8.0); + iirStrength = params["iir_strength"].get(8.0); + strength = params["strength"].get(1.5); + + if (tonemapEnable) { + /* We need either an explicit tonemap, or the information to build them dynamically. */ + if (params.contains("tonemap")) { + if (tonemap.read(params["tonemap"])) + LOG(RPiHdr, Fatal) << "Failed to read tonemap in HDR mode " << name; + } else { + if (target.read(params["target"])) + LOG(RPiHdr, Fatal) << "Failed to read target in HDR mode " << name; + if (maxSlope.read(params["max_slope"])) + LOG(RPiHdr, Fatal) << "Failed to read max_slope in HDR mode " << name; + minSlope = params["min_slope"].get(1.0); + maxGain = params["max_gain"].get(64.0); + step = params["step"].get(0.05); + speed = params["speed"].get(0.5); + } + } + + /* Read any stitch parameters. */ + stitchEnable = params["stitch_enable"].get(0); + thresholdLo = params["threshold_lo"].get(50000); + motionThreshold = params["motion_threshold"].get(0.005); + diffPower = params["diff_power"].get(13); + if (diffPower > 15) + LOG(RPiHdr, Fatal) << "Bad diff_power value in HDR mode " << name; +} + +Hdr::Hdr(Controller *controller) + : HdrAlgorithm(controller) +{ +} + +char const *Hdr::name() const +{ + return NAME; +} + +int Hdr::read(const libcamera::YamlObject ¶ms) +{ + /* Make an "HDR off" mode by default so that tuning files don't have to. */ + HdrConfig &offMode = config_["Off"]; + offMode.name = "Off"; + offMode.cadence = { 0 }; + offMode.channelMap[0] = "None"; + status_.mode = offMode.name; + delayedStatus_.mode = offMode.name; + + /* + * But we still allow the tuning file to override the "Off" mode if it wants. + * For example, maybe an application will make channel 0 be the "short" + * channel, in order to apply other AGC controls to it. + */ + for (const auto &[key, value] : params.asDict()) + config_[key].read(value, key); + + return 0; +} + +int Hdr::setMode(std::string const &mode) +{ + /* Always validate the mode, so it can be used later without checking. */ + auto it = config_.find(mode); + if (it == config_.end()) { + LOG(RPiHdr, Warning) << "No such HDR mode " << mode; + return -1; + } + + status_.mode = it->second.name; + + return 0; +} + +std::vector Hdr::getChannels() const +{ + return config_.at(status_.mode).cadence; +} + +void Hdr::updateAgcStatus(Metadata *metadata) +{ + std::scoped_lock lock(*metadata); + AgcStatus *agcStatus = metadata->getLocked("agc.status"); + if (agcStatus) { + HdrConfig &hdrConfig = config_[status_.mode]; + auto it = hdrConfig.channelMap.find(agcStatus->channel); + if (it != hdrConfig.channelMap.end()) { + status_.channel = it->second; + agcStatus->hdr = status_; + } else + LOG(RPiHdr, Warning) << "Channel " << agcStatus->channel + << " not found in mode " << status_.mode; + } else + LOG(RPiHdr, Warning) << "No agc.status found"; +} + +void Hdr::switchMode([[maybe_unused]] CameraMode const &cameraMode, Metadata *metadata) +{ + updateAgcStatus(metadata); + delayedStatus_ = status_; +} + +bool Hdr::updateTonemap(StatisticsPtr &stats, HdrConfig &config) +{ + /* When there's a change of HDR mode we start over with a new tonemap curve. */ + if (delayedStatus_.mode != previousMode_) { + previousMode_ = delayedStatus_.mode; + tonemap_ = Pwl(); + } + + /* No tonemapping. No need to output a tonemap.status. */ + if (!config.tonemapEnable) + return false; + + /* If an explicit tonemap was given, use it. */ + if (!config.tonemap.empty()) { + tonemap_ = config.tonemap; + return true; + } + + /* + * We only update the tonemap on short frames when in multi-exposure mode. But + * we still need to output the most recent tonemap. Possibly we should make the + * config indicate the channels for which we should update the tonemap? + */ + if (delayedStatus_.mode == "MultiExposure" && delayedStatus_.channel != "short") + return true; + + /* Build the tonemap dynamically using the image histogram. */ + Pwl tonemap; + tonemap.append(0, 0); + + double prev_input_val = 0; + double prev_output_val = 0; + const double step2 = config.step / 2; + for (double q = config.step; q < 1.0 - step2; q += config.step) { + double q_lo = std::max(0.0, q - step2); + double q_hi = std::min(1.0, q + step2); + double iqm = stats->yHist.interQuantileMean(q_lo, q_hi); + double input_val = std::min(iqm * 64, 65535.0); + + if (input_val > prev_input_val + 1) { + /* We're going to calcualte a Pwl to map input_val to this output_val. */ + double want_output_val = config.target.eval(q) * 65535; + /* But we must ensure we aren't applying too small or too great a local gain. */ + double want_slope = (want_output_val - prev_output_val) / (input_val - prev_input_val); + double slope = std::clamp(want_slope, config.minSlope, + config.maxSlope.eval(q)); + double output_val = prev_output_val + slope * (input_val - prev_input_val); + output_val = std::min(output_val, config.maxGain * input_val); + output_val = std::clamp(output_val, 0.0, 65535.0); + /* Let the tonemap adapte slightly more gently from frame to frame. */ + if (!tonemap_.empty()) { + double old_output_val = tonemap_.eval(input_val); + output_val = config.speed * output_val + + (1 - config.speed) * old_output_val; + } + LOG(RPiHdr, Debug) << "q " << q << " input " << input_val + << " output " << want_output_val << " slope " << want_slope + << " slope " << slope << " output " << output_val; + tonemap.append(input_val, output_val); + prev_input_val = input_val; + prev_output_val = output_val; + } + } + + tonemap.append(65535, 65535); + /* tonemap.debug(); */ + tonemap_ = tonemap; + + return true; +} + +void Hdr::process(StatisticsPtr &stats, Metadata *imageMetadata) +{ + /* Note what HDR channel this frame will be once it comes back to us. */ + updateAgcStatus(imageMetadata); + + /* + * Now figure out what HDR channel this frame is. It should be available in the + * agc.delayed_status, unless this is an early frame after a mode switch, in which + * case delayedStatus_ should be right. + */ + AgcStatus agcStatus; + if (!imageMetadata->get("agc.delayed_status", agcStatus)) + delayedStatus_ = agcStatus.hdr; + + auto it = config_.find(delayedStatus_.mode); + if (it == config_.end()) { + /* Shouldn't be possible. There would be nothing we could do. */ + LOG(RPiHdr, Warning) << "Unexpected HDR mode " << delayedStatus_.mode; + return; + } + + HdrConfig &config = it->second; + + if (updateTonemap(stats, config)) { + /* Add tonemap.status metadata. */ + TonemapStatus tonemapStatus; + + tonemapStatus.detailConstant = config.detailConstant; + tonemapStatus.detailSlope = config.detailSlope; + tonemapStatus.iirStrength = config.iirStrength; + tonemapStatus.strength = config.strength; + tonemapStatus.tonemap = tonemap_; + + imageMetadata->set("tonemap.status", tonemapStatus); + } + + if (config.stitchEnable) { + /* Add stitch.status metadata. */ + StitchStatus stitchStatus; + + stitchStatus.diffPower = config.diffPower; + stitchStatus.motionThreshold = config.motionThreshold; + stitchStatus.thresholdLo = config.thresholdLo; + + imageMetadata->set("stitch.status", stitchStatus); + } +} + +/* Register algorithm with the system. */ +static Algorithm *create(Controller *controller) +{ + return (Algorithm *)new Hdr(controller); +} +static RegisterAlgorithm reg(NAME, &create); diff --git a/src/ipa/rpi/controller/rpi/hdr.h b/src/ipa/rpi/controller/rpi/hdr.h new file mode 100644 index 000000000000..01ba45f1d3dc --- /dev/null +++ b/src/ipa/rpi/controller/rpi/hdr.h @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2023, Raspberry Pi Ltd + * + * hdr.h - HDR control algorithm + */ +#pragma once + +#include +#include +#include + +#include "../hdr_algorithm.h" +#include "../hdr_status.h" +#include "../pwl.h" + +/* This is our implementation of an HDR algorithm. */ + +namespace RPiController { + +struct HdrConfig { + std::string name; + std::vector cadence; + std::map channelMap; + + /* Tonemap related parameters. */ + bool tonemapEnable; + uint16_t detailConstant; + double detailSlope; + double iirStrength; + double strength; + /* We must have either an explicit tonemap curve, or the other parameters. */ + Pwl tonemap; + Pwl target; /* maps histogram quatile to desired target output value */ + Pwl maxSlope; /* the maximum slope allowed at each point in the mapping */ + double minSlope; /* the minimum allowed slope */ + double maxGain; /* limit to the max absolute gain */ + double step; /* the histogram granularity for building the mapping */ + double speed; /* rate at which tonemap is updated */ + + /* Stitch related parameters. */ + bool stitchEnable; + uint16_t thresholdLo; + uint8_t diffPower; + double motionThreshold; + + void read(const libcamera::YamlObject ¶ms, const std::string &name); +}; + +class Hdr : public HdrAlgorithm +{ +public: + Hdr(Controller *controller); + char const *name() const override; + void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; + int read(const libcamera::YamlObject ¶ms) override; + void process(StatisticsPtr &stats, Metadata *imageMetadata) override; + int setMode(std::string const &mode) override; + std::vector getChannels() const override; + +private: + void updateAgcStatus(Metadata *metadata); + bool updateTonemap(StatisticsPtr &stats, HdrConfig &config); + + std::map config_; + HdrStatus status_; /* track the current HDR mode and channel */ + HdrStatus delayedStatus_; /* track the delayed HDR mode and channel */ + std::string previousMode_; + Pwl tonemap_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/rpi/controller/rpi/saturation.cpp b/src/ipa/rpi/controller/rpi/saturation.cpp new file mode 100644 index 000000000000..813540e5154d --- /dev/null +++ b/src/ipa/rpi/controller/rpi/saturation.cpp @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022 Raspberry Pi Ltd + * + * saturation.cpp - Saturation control algorithm + */ +#include "saturation.h" + +#include + +#include "saturation_status.h" + +using namespace RPiController; +using namespace libcamera; + +LOG_DEFINE_CATEGORY(RPiSaturation) + +#define NAME "rpi.saturation" + +Saturation::Saturation(Controller *controller) + : Algorithm(controller) +{ +} + +char const *Saturation::name() const +{ + return NAME; +} + +int Saturation::read(const libcamera::YamlObject ¶ms) +{ + config_.shiftR = params["shift_r"].get(0); + config_.shiftG = params["shift_g"].get(0); + config_.shiftB = params["shift_b"].get(0); + return 0; +} + +void Saturation::initialise() +{ +} + +void Saturation::prepare(Metadata *imageMetadata) +{ + SaturationStatus saturation; + + saturation.shiftR = config_.shiftR; + saturation.shiftG = config_.shiftG; + saturation.shiftB = config_.shiftB; + imageMetadata->set("saturation.status", saturation); +} + +// Register algorithm with the system. +static Algorithm *Create(Controller *controller) +{ + return (Algorithm *)new Saturation(controller); +} +static RegisterAlgorithm reg(NAME, &Create); diff --git a/src/ipa/rpi/controller/rpi/saturation.h b/src/ipa/rpi/controller/rpi/saturation.h new file mode 100644 index 000000000000..97da412ad59a --- /dev/null +++ b/src/ipa/rpi/controller/rpi/saturation.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022, Raspberry Pi Ltd + * + * saturation.hpp - Saturation control algorithm + */ +#pragma once + +#include "algorithm.h" + +namespace RPiController { + +struct SaturationConfig { + uint8_t shiftR; + uint8_t shiftG; + uint8_t shiftB; +}; + +class Saturation : public Algorithm +{ +public: + Saturation(Controller *controller = NULL); + char const *name() const override; + int read(const libcamera::YamlObject ¶ms) override; + void initialise() override; + void prepare(Metadata *imageMetadata) override; + +private: + SaturationConfig config_; +}; + +} // namespace RPiController diff --git a/src/ipa/rpi/controller/rpi/sdn.cpp b/src/ipa/rpi/controller/rpi/sdn.cpp index b6b662518f2c..6743919e6b36 100644 --- a/src/ipa/rpi/controller/rpi/sdn.cpp +++ b/src/ipa/rpi/controller/rpi/sdn.cpp @@ -36,6 +36,8 @@ char const *Sdn::name() const int Sdn::read(const libcamera::YamlObject ¶ms) { + LOG(RPiSdn, Warning) + << "Using legacy SDN tuning - please consider moving SDN inside rpi.denoise"; deviation_ = params["deviation"].get(3.2); strength_ = params["strength"].get(0.75); return 0; diff --git a/src/ipa/rpi/controller/rpi/tonemap.cpp b/src/ipa/rpi/controller/rpi/tonemap.cpp new file mode 100644 index 000000000000..5f8b2bf25aeb --- /dev/null +++ b/src/ipa/rpi/controller/rpi/tonemap.cpp @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022 Raspberry Pi Ltd + * + * tonemap.cpp - Tonemap control algorithm + */ +#include "tonemap.h" + +#include + +#include "tonemap_status.h" + +using namespace RPiController; +using namespace libcamera; + +LOG_DEFINE_CATEGORY(RPiTonemap) + +#define NAME "rpi.tonemap" + +Tonemap::Tonemap(Controller *controller) + : Algorithm(controller) +{ +} + +char const *Tonemap::name() const +{ + return NAME; +} + +int Tonemap::read(const libcamera::YamlObject ¶ms) +{ + config_.detailConstant = params["detail_constant"].get(0); + config_.detailSlope = params["detail_slope"].get(0.1); + config_.iirStrength = params["iir_strength"].get(1.0); + config_.strength = params["strength"].get(1.0); + config_.tonemap.read(params["tone_curve"]); + return 0; +} + +void Tonemap::initialise() +{ +} + +void Tonemap::prepare(Metadata *imageMetadata) +{ + TonemapStatus tonemapStatus; + + tonemapStatus.detailConstant = config_.detailConstant; + tonemapStatus.detailSlope = config_.detailSlope; + tonemapStatus.iirStrength = config_.iirStrength; + tonemapStatus.strength = config_.strength; + tonemapStatus.tonemap = config_.tonemap; + imageMetadata->set("tonemap.status", tonemapStatus); +} + +// Register algorithm with the system. +static Algorithm *Create(Controller *controller) +{ + return (Algorithm *)new Tonemap(controller); +} +static RegisterAlgorithm reg(NAME, &Create); diff --git a/src/ipa/rpi/controller/rpi/tonemap.h b/src/ipa/rpi/controller/rpi/tonemap.h new file mode 100644 index 000000000000..f25aa47f86c2 --- /dev/null +++ b/src/ipa/rpi/controller/rpi/tonemap.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022, Raspberry Pi Ltd + * + * tonemap.hpp - Tonemap control algorithm + */ +#pragma once + +#include "algorithm.h" +#include "pwl.h" + +namespace RPiController { + +struct TonemapConfig { + uint16_t detailConstant; + double detailSlope; + double iirStrength; + double strength; + Pwl tonemap; +}; + +class Tonemap : public Algorithm +{ +public: + Tonemap(Controller *controller = NULL); + char const *name() const override; + int read(const libcamera::YamlObject ¶ms) override; + void initialise() override; + void prepare(Metadata *imageMetadata) override; + +private: + TonemapConfig config_; +}; + +} // namespace RPiController diff --git a/src/ipa/rpi/controller/saturation_status.h b/src/ipa/rpi/controller/saturation_status.h new file mode 100644 index 000000000000..337b66a3e91e --- /dev/null +++ b/src/ipa/rpi/controller/saturation_status.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022 Raspberry Pi Ltd + * + * saturation_status.h - Saturation control algorithm status + */ +#pragma once + +struct SaturationStatus { + uint8_t shiftR; + uint8_t shiftG; + uint8_t shiftB; +}; diff --git a/src/ipa/rpi/controller/stitch_status.h b/src/ipa/rpi/controller/stitch_status.h new file mode 100644 index 000000000000..b17800ed6697 --- /dev/null +++ b/src/ipa/rpi/controller/stitch_status.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2023 Raspberry Pi Ltd + * + * stitch_status.h - stitch control algorithm status + */ +#pragma once + +/* + * Parameters for the stitch block. + */ + +struct StitchStatus { + uint16_t thresholdLo; + uint8_t diffPower; + double motionThreshold; +}; diff --git a/src/ipa/rpi/controller/tonemap_status.h b/src/ipa/rpi/controller/tonemap_status.h new file mode 100644 index 000000000000..0e6399467869 --- /dev/null +++ b/src/ipa/rpi/controller/tonemap_status.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022 Raspberry Pi Ltd + * + * hdr.h - Tonemap control algorithm status + */ +#pragma once + +#include "pwl.h" + +struct TonemapStatus { + uint16_t detailConstant; + double detailSlope; + double iirStrength; + double strength; + RPiController::Pwl tonemap; +}; From patchwork Fri Oct 13 07:48:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19135 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 96FA8C32BD for ; Fri, 13 Oct 2023 07:49:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3611D629A1; Fri, 13 Oct 2023 09:49:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183343; bh=laC4WmX5dHbJ/iHze+vwusWOUuOXhEdsffSbd9YGUYw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=gMadSTw7bC056I/94rg85fAzzNlC/rIGU1dQKq8VcQFC0zb2LoLOHgNfbZLrjx6B7 H8fMC9Z3r65jWImoGDkEFR6itAUcrde5K1wCkC4dhPaFUR81hl49HWfKMbpS3RBxBg NOm9B0kehFP0SGNEsBeAfAGsEDdQf2uw/gWXxja3Ec3jyI0l68ke9x1UtyT1cL2UKC xG/0VGAj7NCkhDGAjtAxQNSyBB0ChLXNdkKns6jk418WKZReUfPaYULg85NcDkrcat fOVDGDFHaDqtpqkhstqROVv0WJ9zSRkKjRows2chO3qmyras0JMduY+hS22MtAGydn pMScfrDOmBpfA== Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E7CD62987 for ; Fri, 13 Oct 2023 09:48:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="n6NfM0oj"; dkim-atps=neutral Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-406618d0992so18911255e9.0 for ; Fri, 13 Oct 2023 00:48:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183335; x=1697788135; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fs9TmN/NmB3KCzxAJfMZtU6Q37Dpqb4i7HZcupMowb8=; b=n6NfM0ojPVILUmm5Vb13f55fYTJJGOstYyeaSTILV/jqWoYGbZO5ZuuMtz7on4ry3v 0AZW6nidS/bkdYDpw8YGOzg/41i6ruUHqAGMzkhk1yjanJV91GmKEZw+hMcLva9MMJgA zojgNYUjjMzxdjQlIraYJm6uaAnvd3j2G/ky1TV9NduVLiBnp7kKgsy1sw1IQcQWc+Wt 71otk0PVJGxv0nGzxeOKbcMh9uG0RV8jy17SP5P5+lzA0G+Qyla4YtKPNWUhAjfCSNLc hGoCX7kNNbNPoFywqSjQvTdX3T8jBUuWNaD7ksaFTulCq00WZcRZotYMabCYfEyePWrN h1+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183335; x=1697788135; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fs9TmN/NmB3KCzxAJfMZtU6Q37Dpqb4i7HZcupMowb8=; b=njJuLi9oj3CxWDmwxRk+Tgh8mswW9nSIc2GLEBTOSNsFpRdMj54YqoVpDRd/AkwMHd CBovlhT2LC2RAJEfy7OZMB4HQRkSJICIzojhmQCIDo7y/CiyejSoTsgaerG5L62bb1Yz /B8rp/MFjVqmaFlVkC2Haq8OWfpWzCgU1bD7uacZ5NH4V799fh4hwGkO1Ljxxa+sxNTz HnyazPITu6ibYDk+TPu3NjavIR8YIgvRiIH4HJyi0q3H9gg8YaL+9qT7QbUfuqO0qF0B qXIZwmvx66npe3P51O6d5yvOW1DsgwOO/hS4E2031eZp8UuEH5t+ZK54+hnSPGXNUJ/D FR1g== X-Gm-Message-State: AOJu0YwASKWcDWBFBUeX4K0rYzD6QhsmKy6VZfXZBF3kMyzmJhbq1DfP fC1cU3wrNLrCgEu0CEgXO4yz3mx6syTM4AqDUKkDdg== X-Google-Smtp-Source: AGHT+IH5Nih2aSqUcjcudbqO3grdLn+/r+Qsx7U1W3+bfUhcG4tUdLU/S0uImjAd90GF9rOXMDYrvQ== X-Received: by 2002:a1c:f709:0:b0:405:3b1f:9691 with SMTP id v9-20020a1cf709000000b004053b1f9691mr24010464wmh.11.1697183335036; Fri, 13 Oct 2023 00:48:55 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:54 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:33 +0100 Message-Id: <20231013074841.16972-13-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 12/20] pipeline: rpi: Add SW downscale status to RPi::Stream 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Record if additional software downscaling is needed for a particular stream in the RPi::Stream class. Additional software downscaling may be needed if the user required downscale factor is greater than what the ISP hardware is capable of. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/rpi/common/rpi_stream.cpp | 10 ++++++++++ src/libcamera/pipeline/rpi/common/rpi_stream.h | 11 +++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp index 20864aeed2d1..70f115f17977 100644 --- a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp @@ -57,6 +57,16 @@ const std::string &Stream::name() const return name_; } +unsigned int Stream::swDownscale() const +{ + return swDownscale_; +} + +void Stream::setSwDownscale(unsigned int swDownscale) +{ + swDownscale_ = swDownscale; +} + void Stream::resetBuffers() { /* Add all internal buffers to the queue of usable buffers. */ diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.h b/src/libcamera/pipeline/rpi/common/rpi_stream.h index c5e35d134926..fc2bdfe25d4a 100644 --- a/src/libcamera/pipeline/rpi/common/rpi_stream.h +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.h @@ -86,13 +86,14 @@ public: using StreamFlags = Flags; Stream() - : flags_(StreamFlag::None), id_(0) + : flags_(StreamFlag::None), id_(0), swDownscale_(0) { } Stream(const char *name, MediaEntity *dev, StreamFlags flags = StreamFlag::None) : flags_(flags), name_(name), - dev_(std::make_unique(dev)), id_(0) + dev_(std::make_unique(dev)), id_(0), + swDownscale_(0) { } @@ -104,6 +105,9 @@ public: const std::string &name() const; void resetBuffers(); + unsigned int swDownscale() const; + void setSwDownscale(unsigned int swDownscale); + void setExportedBuffers(std::vector> *buffers); const BufferMap &getBuffers() const; unsigned int getBufferId(FrameBuffer *buffer) const; @@ -139,6 +143,9 @@ private: /* Tracks a unique id key for the bufferMap_ */ unsigned int id_; + /* Power of 2 greater than one if software downscaling will be required. */ + unsigned int swDownscale_; + /* All frame buffers associated with this device stream. */ BufferMap bufferMap_; From patchwork Fri Oct 13 07:48:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19137 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 28C71C32B6 for ; Fri, 13 Oct 2023 07:49:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C886C62989; Fri, 13 Oct 2023 09:49:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183344; bh=M7cvfczoL4R5A+xDn9pwR2p2QJHc8GIJiZGE4EeFT/I=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=C7L8NIOShC7K0hhiZ3MB3j+5mvpsX+aeGVNZmk6AIOUG/vmWhkTCos/O2qwV/zefm Hy4mLYwnOX2s3WW5nYhHv4fKDvEzruChdICOGw8c2z5WkT5RALfOud+5xG40B8w2PX FKXbbiTQ53avOwvXz6MONDDnQBP2C9eaogsuvnQC6roPmMoQ/X5hXQktOdya2v4pYW RO3AB3jCYdPC4BBSomXhpBsS1DrahW4zUiHQ7w80r7PHHyeoO1r5pnoSmbuTGPTP3q 7qP+TgLQLm2SiUDtIjpr+KcBUQFm9Z0BxPHBts1UGbNIu4u1zJHvQWqNAsl+WXAR1D Byt8t53sAWDQw== Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A3926297E for ; Fri, 13 Oct 2023 09:48:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="mIdvPe+T"; dkim-atps=neutral Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40572aeb673so19437145e9.0 for ; Fri, 13 Oct 2023 00:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183336; x=1697788136; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D4exOpCTPvbDuxJSbapt0qMAr2YwjKudXo3nibFYFyU=; b=mIdvPe+T5DZxyhHgTRHYTg6r84EszWZ1zFVjZPIZ40nC0MGcoYZLPxIrptLQFTsWW2 s8fSQU8ccRw67pqlVCwpiqKMwJoV+eEVzZXEqmK4GFIW+c1hNzbGj/Y4/BPoZvVCY1T5 teEa2lkRIYswvM1jHTUVafUGbS638rxPazcD6tdxFMrsZVuumcpifAoKYZyeROLxi+V2 E8EO7bwOmN2EL/wSUWWg69OMqmd0cCAGTqcEpjqiE6WGYawlJv9/BduZX17RnPln50TZ vjMkdcKuk2QOj8vccGQLJd/BPh/cX6F3Zg83CihL2NzFoot4RL4QsV5IMrVA7DiU1juy XKbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183336; x=1697788136; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D4exOpCTPvbDuxJSbapt0qMAr2YwjKudXo3nibFYFyU=; b=ZVGN029XeM8U1pIhe9TO+377qqtana8pp53PFTkQOpGbZCAMtnW1Vm46Ks85Zjgq3T doBekFXBgNg9QlHKoLWWd0b5woTX0rlgSBbMVEnw+fQSZE1u0HJtWYCCswDsVDUoYWEt PNu2u8pk8zHCvvitY29DTnYQA2heky0JshP/ZnQy42UX0a4gy55kbI350Fc+g9y+CGCC jj8Hc+5EO3klzF3TNmKcRm+ZgSmuUjDG+nLWZXERjne1wEeqUW+sEaJ+wcMWp+IHM6oY MKPuzYxqTT6Y8zz70z/KP8PE025j10o8dyKtkPWS+Ug5EDHIID1+S5bRvC4bQxppbxrX iaiA== X-Gm-Message-State: AOJu0Yz5sX40FFK6ClxDv7iWNB+9OcOvHSDt4gxTq1GLhW1gLMKVoxP0 FqIJvAt8QO2DAfeuLep4f5dOzWdojo4xvHLWI4jy3g== X-Google-Smtp-Source: AGHT+IH6zsrEcNFZTxNFOChmQ9s/KKMyLFCkbqY/0l8CUQBkrVGr8avfgOkkwqKR5Qp4ZZfq6oluvQ== X-Received: by 2002:a05:600c:2197:b0:406:5227:86f0 with SMTP id e23-20020a05600c219700b00406522786f0mr21550523wme.5.1697183335808; Fri, 13 Oct 2023 00:48:55 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:55 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:34 +0100 Message-Id: <20231013074841.16972-14-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 13/20] build: ipa: Fix bug in building multiple IPA interfaces with the same mojom file 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In the existing meson scripts, an IPA mojom interface file may not be built if: - There are duplicate entries for the mojom file shared by different pipeline handlers in pipeline_ipa_mojom_mapping, and - The IPA is not listed first in pipeline_ipa_mojom_mapping, and - The first listed IPA for the given mojom file is not selected in the build. Fix this by using a separate list of already built mojom files (mojoms_built) instead of overloading use of the existing ipa_mojom_files list. Now, ipa_mojom_files gets filled in outside of the IPA list enumeration loop, this also guarantees the IPA documentation gets built even if the pipeline is not selected. Fixes: 312e9910ba2e ("meson: ipa: Add mapping for pipeline handler to mojom interface file") Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- include/libcamera/ipa/meson.build | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/include/libcamera/ipa/meson.build b/include/libcamera/ipa/meson.build index e72803b4e243..f3b4881c9c91 100644 --- a/include/libcamera/ipa/meson.build +++ b/include/libcamera/ipa/meson.build @@ -68,29 +68,28 @@ pipeline_ipa_mojom_mapping = { 'vimc': 'vimc.mojom', } -ipa_mojom_files = [] -ipa_mojoms = [] - # # Generate headers from templates. # # TODO Define per-pipeline ControlInfoMap with yaml? +ipa_mojoms = [] +mojoms_built = [] foreach pipeline, file : pipeline_ipa_mojom_mapping name = file.split('.')[0] - # Ensure we do not build duplicate mojom modules - if file in ipa_mojom_files + # Avoid building duplicate mojom interfaces with the same interface file + if name in mojoms_built continue endif - ipa_mojom_files += file - if pipeline not in pipelines continue endif + mojoms_built += name + # {interface}.mojom-module mojom = custom_target(name + '_mojom_module', input : file, @@ -155,6 +154,12 @@ foreach pipeline, file : pipeline_ipa_mojom_mapping libcamera_generated_ipa_headers += [header, serializer, proxy_header] endforeach +ipa_mojom_files = [] +foreach pipeline, file : pipeline_ipa_mojom_mapping + if file not in ipa_mojom_files + ipa_mojom_files += file + endif +endforeach ipa_mojom_files = files(ipa_mojom_files) # Pass this to the documentation generator in src/libcamera/ipa From patchwork Fri Oct 13 07:48:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19138 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 0DCB5C32BF for ; Fri, 13 Oct 2023 07:49:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7EF1A629AD; Fri, 13 Oct 2023 09:49:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183345; bh=7l6NP7L67GZaRoxAF4LGABUZZ0aXJk6H7Yf/x8c+BeE=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=tBnTyZHjpMf43DjZt/9KvL/EzSUByY4C3ZxIj0Gv9qOtiHy5mpxYwsR6YiLFnVvWD G/DXXl1/Q8rTkq+2EnN7/6OZmwh9aqc8HayEkr5QqJbblw2zRtSc+s1nZKpDwoiy3e dzjNcad9Repp0HHVhEnyyh5JX84whMRyYxegT0WskuzDXi0UoRTdYG1AMCXGwv+/4/ FzwkuBn8xLj3hnev+BfwaSvw1EFMt3SHT6G9USfHrZ7/PRWZhIYwFoBOaXwHAhxyoD KUGnA9SyzwXnWvxuqtofsmyMhER4zJc5zPKsRq2Wk7nbLw8n6LZXi/cn+D8WNPpCAT Kn8uIIkpkNL/A== Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6218962996 for ; Fri, 13 Oct 2023 09:48:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="phGEV+a9"; dkim-atps=neutral Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-53e07db272cso2583096a12.3 for ; Fri, 13 Oct 2023 00:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183336; x=1697788136; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=63ebRbhpy61ExuOGtyPGxJ72VDfar8BgQdTJMUJHTGA=; b=phGEV+a9+E9uNi6TcOXycUdMw/V1rzoSLs1lmarBoxBp16QcIaQR1TlRbWpwUHtU4A duAaMVHC0HhoOvlQVjOi4PZTAe2R661gVjDKy0RQFHIfHpK3HPGoKkzg0gsysC6OGee+ tyBhqVV9v9E3Pf7WGqffvZLg8TtPP9a0SvgmExYrbBVZEyZekk/Gmn+VEuesy95sm4b3 zT0n1ovTICHULWNs7TUGjam1M2w6JnacuJern3ubePMzDwnK5JDKs0fp138OKpGosQPM grcR8XHprvBM6RFN8FrS0TursTahdYH00lTICrACzIie+/13neHkGmwP432kXrhUSHKY ppcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183336; x=1697788136; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=63ebRbhpy61ExuOGtyPGxJ72VDfar8BgQdTJMUJHTGA=; b=j8jLbGFJPYZ++1dxULAVyTk0V59NMNWcBPyikGBqYOpO1XsGCMmpL2Kk+SrOrgPWew Nou4nI8Ht1UuUslKn6An0Gcqqk30uAkw262mn4tV8csOOChuleT4hOIonOyJboe28g9T wE3zvX0VidjdJYL0OyQ8wbtqNnxZQPOOpmHTTPwKmcWou2h83S19W+KKRfHClmAx4TZP UBL8lHkFJ1DUBrHshQCHpJ3T8Ll4CEe7Gd96G7T4+oWLZj7DidmkcblHzAoK0+FOLHuU tCNYLmgLsB7y3RQmjYaKWHn9mbY6+tYbv5nFMtG1Wus1oCJ8xtWvEs7S4kh62kJAmqpT IDeg== X-Gm-Message-State: AOJu0Yyygg5yGnI87L3JTvmwaM+HuC2FXtUQ9ndTFNYMRvhZnFUtep79 khPa8smIryPZZMNov72sBGre6pv4qtUvdswcxCqMhw== X-Google-Smtp-Source: AGHT+IGg3FNEK1LMdMpe/D7KHmPVr0i1sISg+6F0gH0q6bDwSJEv2Azac70ii/Fa6erPbGRh4KDW2g== X-Received: by 2002:a17:907:2e19:b0:994:4095:3abf with SMTP id ig25-20020a1709072e1900b0099440953abfmr23095951ejc.14.1697183336654; Fri, 13 Oct 2023 00:48:56 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:56 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:35 +0100 Message-Id: <20231013074841.16972-15-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 14/20] pipeline: rpi: Move flip handling validation code 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Move the handling of Bayer order changes due to flips to run before platformValidate(). This removes the need for this code to be split between platformValidate() and validate() as it is right now. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- .../pipeline/rpi/common/pipeline_base.cpp | 43 +++++++++++++------ src/libcamera/pipeline/rpi/vc4/vc4.cpp | 14 +----- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 825eae80d014..7c88b87e0608 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -231,16 +231,12 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() } } - /* Do any platform specific fixups. */ - status = data_->platformValidate(this); - if (status == Invalid) - return Invalid; - - /* Further fixups on the RAW streams. */ + /* Start with some initial generic RAW stream adjustments. */ for (auto &raw : rawStreams_) { - int ret = raw.dev->tryFormat(&raw.format); - if (ret) - return Invalid; + StreamConfiguration *rawStream = raw.cfg; + + /* Adjust the RAW stream to match the computed sensor format. */ + BayerFormat sensorBayer = BayerFormat::fromMbusCode(sensorFormat_.mbus_code); /* * Some sensors change their Bayer order when they are h-flipped @@ -249,12 +245,33 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() * Note how we must fetch the "native" (i.e. untransformed) Bayer * order, because the sensor may currently be flipped! */ - BayerFormat bayer = BayerFormat::fromPixelFormat(raw.cfg->pixelFormat); if (data_->flipsAlterBayerOrder_) { - bayer.order = data_->nativeBayerOrder_; - bayer = bayer.transform(combinedTransform_); + sensorBayer.order = data_->nativeBayerOrder_; + sensorBayer = sensorBayer.transform(combinedTransform_); + } + + /* Apply the sensor adjusted Bayer order to the user request. */ + BayerFormat cfgBayer = BayerFormat::fromPixelFormat(rawStream->pixelFormat); + cfgBayer.order = sensorBayer.order; + + if (rawStream->pixelFormat != cfgBayer.toPixelFormat()) { + rawStream->pixelFormat = cfgBayer.toPixelFormat(); + status = Adjusted; } - raw.cfg->pixelFormat = bayer.toPixelFormat(); + } + + /* Do any platform specific fixups. */ + Status st = data_->platformValidate(this); + if (st == Invalid) + return Invalid; + else if (st == Adjusted) + status = Adjusted; + + /* Further fixups on the RAW streams. */ + for (auto &raw : rawStreams_) { + int ret = raw.dev->tryFormat(&raw.format); + if (ret) + return Invalid; if (RPi::PipelineHandlerBase::updateStreamConfig(raw.cfg, raw.format)) status = Adjusted; diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index 233473e2fe2b..cf7b45985738 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -409,21 +409,9 @@ CameraConfiguration::Status Vc4CameraData::platformValidate(RPi::RPiCameraConfig /* Adjust the RAW stream to match the computed sensor format. */ StreamConfiguration *rawStream = rawStreams[0].cfg; - BayerFormat rawBayer = BayerFormat::fromMbusCode(rpiConfig->sensorFormat_.mbus_code); - /* Handle flips to make sure to match the RAW stream format. */ - if (flipsAlterBayerOrder_) - rawBayer = rawBayer.transform(rpiConfig->combinedTransform_); - - /* Apply the user requested packing. */ - rawBayer.packing = BayerFormat::fromPixelFormat(rawStream->pixelFormat).packing; - PixelFormat rawFormat = rawBayer.toPixelFormat(); - - if (rawStream->pixelFormat != rawFormat || - rawStream->size != rpiConfig->sensorFormat_.size) { - rawStream->pixelFormat = rawFormat; + if (rawStream->size != rpiConfig->sensorFormat_.size) { rawStream->size = rpiConfig->sensorFormat_.size; - status = CameraConfiguration::Adjusted; } From patchwork Fri Oct 13 07:48:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19139 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 B7BB9C32C0 for ; Fri, 13 Oct 2023 07:49:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5C74A62999; Fri, 13 Oct 2023 09:49:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183346; bh=k6AIkgxNK2TCKRgGWXmKIS+DZmRVUgN3qu4+zZdoSDA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=UN5+N86FS4G43JfI2F+odJ1QpmTpwpv7h6BRyBWMPXGFSNJrChal58WbP4Werbh6s 2lrYQceuP6Z2EegAD+ro6LDUClCdz4kK7pD0pEyXM9sDYvGsDqr7xCtPNJ9G77qrmb Q6LmXZRc2OCGwDp20FE9e7wIfqK2HbSARPJ1nhOC3dyjh2IRLEX3s5Zj5SpH4YWjHE De9posDJOywes75NyGGEH03bt4suuEy6jqopLSplJiQd9HJy/31TycyCnk49flZsCW yZdidkNi8lcnEv4FakXdtiM16s7vr7Piz7sNMOpXm7BUXW4IYfN9a2N4hO5+yOyXGN +MGvORQl9mVaw== Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B484762989 for ; Fri, 13 Oct 2023 09:48:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="GDXA1iB3"; dkim-atps=neutral Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4054f790190so20864305e9.2 for ; Fri, 13 Oct 2023 00:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183337; x=1697788137; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6KeD7RYi36cgDXjCWlDhOsoX6YMd/Et152aNpo+jQdA=; b=GDXA1iB3zD+8Q8e1SCIadoh+fypLqhqEXnGhk0U2vuTcWVkFYnlG0OYktoOeLAEx8m olr140iD8uIgu92FtLz75TODjFbDyYPex70/y+p0VW/9B2lNXLDuRw6BLytyC5bbziED +MDkRzvnSnXpfFDS1tIoaq3c4rpVibRIy/gvRZi4YCJ4rULkOPjluHcdaqm7cMmnHBUF UoNQhbkfoafBhx4IhDhPUeiZupITIyJRTHmQq9+wulgqMdYcz7xU+yKZpEcEKOHwqpHE RLoFqyryRHY7YCcqKLJKr1D//AqRiVSxp3MikQjuiuPr5tCuLGoJiL6EnCBt4LX79kx1 m3rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183337; x=1697788137; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6KeD7RYi36cgDXjCWlDhOsoX6YMd/Et152aNpo+jQdA=; b=dixXwwuBn4mnedEhWG9bwkbN8YL4Kk8MPABwR+rlZAPu2hGiVD6nskbt4cG5qk7KrM 0Z5x1FrZpooPhs8A/uejm9nN0tyY673/3WCibZGZbum9vBAD7sYnWNuVuWBgwwa9UHYI ONrdouFRI0gtuKCgmC4kLz02fSHwV1YuOg6nsKa33xPUt/MmOczF0aiTSGZlqknGUA1Z qBtb4a0jm6NrYIgUtXlooxk62fSLtLhluNIQ6q2pHK+UZCE/oYuNTMCy4PAiUSI7a4NL Xl5Sv4k0nVlIgAed9IW4oBfHHPctx+ryyPYNMU+eGCeAzGzEeGh5cB5maoNCY3pBet8l quNw== X-Gm-Message-State: AOJu0Ywm27yr27Vb1rsHNQr7YCQ0/wtRMy19VY6Sfs/6p/bQ3Jv3ZoFZ 7d0s4oJoLYLFVyjeBQuugmPDHC2to9vr1zAUut7Bcg== X-Google-Smtp-Source: AGHT+IEZVPN29SMDsaIYNw8/tCH/7gHL47TyUf1Zohg2lHYBgw05B4fHnEMExyUtkMtWHTYKlQQaVQ== X-Received: by 2002:a7b:cb8c:0:b0:406:517f:ac71 with SMTP id m12-20020a7bcb8c000000b00406517fac71mr22625846wmi.29.1697183337179; Fri, 13 Oct 2023 00:48:57 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:56 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:36 +0100 Message-Id: <20231013074841.16972-16-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 15/20] pipeline: rpi: Make color space members in RPiCameraConfiguration public 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This allows them to be accessed by the pipeline handlers when needed. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/rpi/common/pipeline_base.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 0c4a59b7f590..267eef1102f1 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -273,9 +273,6 @@ public: std::vector rawStreams_; std::vector outStreams_; -private: - const CameraData *data_; - /* * Store the colour spaces that all our streams will have. RGB format streams * will have the same colorspace as YUV streams, with YCbCr field cleared and @@ -283,6 +280,9 @@ private: */ std::optional yuvColorSpace_; std::optional rgbColorSpace_; + +private: + const CameraData *data_; }; } /* namespace RPi */ From patchwork Fri Oct 13 07:48:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19140 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 62E96C32B7 for ; Fri, 13 Oct 2023 07:49:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 20A166299A; Fri, 13 Oct 2023 09:49:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183348; bh=x3O3orwN+9EoA2Rduqqnz09cvsygphT8R3W1P/h0/ZU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=GPCikNrwodMncila1kIp+hVfF165nKrfdmhrQHPdq7h436/7qgSlqBna9jzwuTKBh 5VJfgEVjgsllJ0+HtmQcczW16USRskHspA0alczR+o+zz+E62PVTAPg+tFlSgCVQ3o 4U6r75zb3IJcu74ioc2FM1Ic0FppIerJbnybe3MaLMeVIbZV8Hrk2E9cxT3/LvifiJ CzFq1NnFtNdjKmed56aqfAiKyTBPAGbw87UsBYrGUEmI96yLfvfGDzKv3eNyxuLErZ +0XcQI2FKix5jVWK0EUKWXXpYBKMaqTz1LeqoGxW50yDUFh1LqlfBmEEoYz9W3XF5h d/ehTyRkdwHAA== Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 79CAE62988 for ; Fri, 13 Oct 2023 09:48:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="kJSBq0l/"; dkim-atps=neutral Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40572aeb6d0so18693725e9.1 for ; Fri, 13 Oct 2023 00:48:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183338; x=1697788138; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=77tYb2TD81ZwFQSZvXJvqN5v3/YGS+HcLZAwDU1MFVg=; b=kJSBq0l/cFwlCoZDQKnTHMS09zwEblrZ6LF7slzimfc6MIAKaKdevDy1WQOC5HE6SF 6CtnT8V7Cl5U0wb0aGOhnwj5zjSxFQGh3LNBVBWKBOwRrBiAyXKs1y+KHa0ZEGSYr9ZF UTlkRTT+dhYu5hqbJKfoxRNxAwLbet/Q7jajbKwZYLTWIUqXzwsN+lhcpp8z+Awgc43A 2C8dKcoxAvm7sZTp5ZsOpF81FhVNjpvWJHpJ9IUyFo0N2Y5NfmWw5JFSyT+jDuvVywjH JtzkQAcsHH+NN1/V16g0U51UBprgXL8d3PMAFkgl5aPRbUzvjLcQYOBIV9dR7Q1BFZDC 5+EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183338; x=1697788138; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=77tYb2TD81ZwFQSZvXJvqN5v3/YGS+HcLZAwDU1MFVg=; b=CRNuUp/ysT0XRZNqUGv9R1NOLVcQbVdUvKYflA/seR0E3f6oNn21JDTMUzQK75I1F9 JvaRhsw9HVLY+DIjqNZZaf8ITxFgHNhKsCHSDm5o8ZMh1n+sDDv2BeF+bG1X2WxECNHo iIYVs+VnwcNi1fULCEKKujNisA/PTOSdPX/RYwPikUyFhzkdJpmEs8OWeX/g1IU6W44Q hekZb43z6NH5MMu1yS+MWnjhbKDi/H/38Cyv/g1r91SQJ2oohdmbXLphHzBqtlCI+h+x Bh2F5bRxlopmgJNdSosRpZPIYxNDJpRz9fs1f6t8mniOpoWY5zLw9ktDmoo8Wye6fJ+u QpSg== X-Gm-Message-State: AOJu0YwtZtgD0ERtpudVKZFFWokDfVyLWYBCjbqCATFoUgBDUOqDMbX/ gX45MQat9G+lJhkdJzx6adSmFW+/rUJ9TGdnwIcvhw== X-Google-Smtp-Source: AGHT+IE/QKMlYyG5LD2nkfeMBWYjx1kWygV9u9wRapCuWWzQRvfguDY7+KJc4zfUb8I3hMy1mAn7aA== X-Received: by 2002:a1c:4c13:0:b0:406:7d74:a29b with SMTP id z19-20020a1c4c13000000b004067d74a29bmr22623694wmf.13.1697183337865; Fri, 13 Oct 2023 00:48:57 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:57 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:37 +0100 Message-Id: <20231013074841.16972-17-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 16/20] ipa: rpi: agc: Add an AGC stable region 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: David Plowman Add a small "stable region" parameter (defaulting to 2%) within which the AGC will not adjust the exposure it requests. It allows applications to configure the AGC to avoid continual micro-adjustments of exposure values if they are somehow sensitive to it. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Jacopo Mondi --- src/ipa/rpi/controller/rpi/agc_channel.cpp | 7 +++++++ src/ipa/rpi/controller/rpi/agc_channel.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/ipa/rpi/controller/rpi/agc_channel.cpp b/src/ipa/rpi/controller/rpi/agc_channel.cpp index 3957dbc3fa32..1e7eae06d425 100644 --- a/src/ipa/rpi/controller/rpi/agc_channel.cpp +++ b/src/ipa/rpi/controller/rpi/agc_channel.cpp @@ -251,6 +251,8 @@ int AgcConfig::read(const libcamera::YamlObject ¶ms) defaultExposureTime = params["default_exposure_time"].get(1000) * 1us; defaultAnalogueGain = params["default_analogue_gain"].get(1.0); + stableRegion = params["stable_region"].get(0.02); + return 0; } @@ -871,6 +873,8 @@ bool AgcChannel::applyDigitalGain(double gain, double targetY, bool channelBound void AgcChannel::filterExposure() { double speed = config_.speed; + double stableRegion = config_.stableRegion; + /* * AGC adapts instantly if both shutter and gain are directly specified * or we're in the startup phase. @@ -880,6 +884,9 @@ void AgcChannel::filterExposure() speed = 1.0; if (!filtered_.totalExposure) { filtered_.totalExposure = target_.totalExposure; + } else if (filtered_.totalExposure * (1.0 - stableRegion) < target_.totalExposure && + filtered_.totalExposure * (1.0 + stableRegion) > target_.totalExposure) { + /* Total exposure must change by more than this or we leave it alone. */ } else { /* * If close to the result go faster, to save making so many diff --git a/src/ipa/rpi/controller/rpi/agc_channel.h b/src/ipa/rpi/controller/rpi/agc_channel.h index ae826fa8097f..c1808422498a 100644 --- a/src/ipa/rpi/controller/rpi/agc_channel.h +++ b/src/ipa/rpi/controller/rpi/agc_channel.h @@ -75,6 +75,7 @@ struct AgcConfig { double baseEv; libcamera::utils::Duration defaultExposureTime; double defaultAnalogueGain; + double stableRegion; }; class AgcChannel From patchwork Fri Oct 13 07:48:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19141 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 228B7C32C1 for ; Fri, 13 Oct 2023 07:49:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B8931629AA; Fri, 13 Oct 2023 09:49:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183348; bh=BVzzOqrgaQi3OOBwyfJcTJA7cdtOwtsPIxk8KKuR/zU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=jayeQbMFPbkAKFDiAbgsUluec8SNoTzDkw15xqb9jiwHy+l3KW4TfQtkTvfIM0iWX 4eSHrNZtAzyWPSAj+SEq4TDTmVV3I/OHIWZj31wfF0WdCXdCx/m23rkyv6nEXG0Cvd a8mfUe0p+KNgNjzza3t+DO9TB5R6YKnoRx75FMluXLjQ8ptGrGS5KdCq+EagP37ILD Zw91onrteMm39O47JbOvChaeGvYjfXg9J4bCky9u9ahNWwN5i8AhNUSZ/NNrEn4Ukg slRYa63/rCWm8rC7ZvtsxCMMD5eedgjLSs6SxUQ56PrCIwGBtBnsllG/+/SveHgBSV 4iwyF1vpiJIsg== Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 48D45629A2 for ; Fri, 13 Oct 2023 09:48:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="lze3JkQ9"; dkim-atps=neutral Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-405361bb9f7so19232215e9.2 for ; Fri, 13 Oct 2023 00:48:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183338; x=1697788138; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1blZHZTcVda6hrHqBicD9uRzvwISRZzuZpzkStU5tQo=; b=lze3JkQ9veRQ2GFQhjUgjG5bmygMwvpmfPIF7JZtun3JITObjL8Y3Fu2EyZnHul5b6 DxmlLZ2Ian3DjveymmEueMqVFYJYyZPJsS2ReKom87htHkAu1X6x4oyCZrqjQJHRmsZI hFJ8md3kT1M4ktl1A/h/xFbpknGdcnj4tILwNdoLq+neo9Yimb+LANwTJ411mmy7gT8O shGUQNMBGcUpwbap9GbzvwJRQ/RnZ/TSFDQbWctlMWTsiVwc1u93zdZ4GoYCPHKaQ8K4 YDYD2pWzaR5Kdwi72GvZUWMREx2bQ1cT5ShgIa5oMXuZS/0/UuySDEZ17WqYSNv96ekb 9BXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183338; x=1697788138; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1blZHZTcVda6hrHqBicD9uRzvwISRZzuZpzkStU5tQo=; b=soDjX5OS2wAkYq0e4ldzc//6P8q6LX52AYHac6ZxahZ1lDa7kX7pcXtgPC/TcVwviH 1k9h2VKY0kXrIjhfwvb8nV3I92z3uVFc/DtLW3IeqABdpB+7q+sJsuIFznW1O5BZMxQR jc1FnFq+q87tGtGzN3Uq5BsabZcpod7LlQCLBSJAHNLORgGkV3sXlMhzZlSmQa/FqADx uJ4Ye/77Naa/G/NLW4arATOXIigjT3TzaFNnixzQ0pfTDzYDRXFFWMYSV8bIoLGd7AAW c6ZmErI3LlPnFNJWS1U0eBwKw4XqbIEeqALnOekIIx6bLX7C9EIbOc63Kv9INpcHgEDd Yh6Q== X-Gm-Message-State: AOJu0YyBQbifFG+p2thldhRKBvYYJE+NtkUomXdkZR8WN8l2k+sA0iTp 2f+1LMkoVOnzNHMkr7vaqm2o+UALKM0k860xrtpzpg== X-Google-Smtp-Source: AGHT+IHM+LJfWfg+jjk/jtUZvVjq8/xJs4dS03UyHWIOjejYOnjU1kfyNM7K9NqkMcwfVUnx9YpHWA== X-Received: by 2002:a7b:cb8b:0:b0:3fb:e189:3532 with SMTP id m11-20020a7bcb8b000000b003fbe1893532mr22844142wmi.20.1697183338702; Fri, 13 Oct 2023 00:48:58 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:58 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:38 +0100 Message-Id: <20231013074841.16972-18-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 17/20] ipa: rpi: contrast: Allow adaptive contrast enhancement to be disabled 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: David Plowman The enableCe() function enables or disables adaptive contrast enhancement and the restoreCe() function sets it back to its normal state (which is what was read from the tuning file). In future, algorithms like HDR might want to take over tonemapping functions, so any dynamic behaviour here would upset them. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Jacopo Mondi --- src/ipa/rpi/controller/contrast_algorithm.h | 2 ++ src/ipa/rpi/controller/rpi/contrast.cpp | 13 ++++++++++++- src/ipa/rpi/controller/rpi/contrast.h | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ipa/rpi/controller/contrast_algorithm.h b/src/ipa/rpi/controller/contrast_algorithm.h index ce17a4f949b9..895b36b0a80f 100644 --- a/src/ipa/rpi/controller/contrast_algorithm.h +++ b/src/ipa/rpi/controller/contrast_algorithm.h @@ -17,6 +17,8 @@ public: /* A contrast algorithm must provide the following: */ virtual void setBrightness(double brightness) = 0; virtual void setContrast(double contrast) = 0; + virtual void enableCe(bool enable) = 0; + virtual void restoreCe() = 0; }; } /* namespace RPiController */ diff --git a/src/ipa/rpi/controller/rpi/contrast.cpp b/src/ipa/rpi/controller/rpi/contrast.cpp index bee1eadd3657..4e038a021d8a 100644 --- a/src/ipa/rpi/controller/rpi/contrast.cpp +++ b/src/ipa/rpi/controller/rpi/contrast.cpp @@ -42,6 +42,7 @@ int Contrast::read(const libcamera::YamlObject ¶ms) { // enable adaptive enhancement by default config_.ceEnable = params["ce_enable"].get(1); + ceEnable_ = config_.ceEnable; // the point near the bottom of the histogram to move config_.loHistogram = params["lo_histogram"].get(0.01); // where in the range to try and move it to @@ -65,6 +66,16 @@ void Contrast::setContrast(double contrast) contrast_ = contrast; } +void Contrast::enableCe(bool enable) +{ + ceEnable_ = enable; +} + +void Contrast::restoreCe() +{ + ceEnable_ = config_.ceEnable; +} + void Contrast::initialise() { /* @@ -150,7 +161,7 @@ void Contrast::process(StatisticsPtr &stats, * histogram down, and possibly push the end up. */ Pwl gammaCurve = config_.gammaCurve; - if (config_.ceEnable) { + if (ceEnable_) { if (config_.loMax != 0 || config_.hiMax != 0) gammaCurve = computeStretchCurve(histogram, config_).compose(gammaCurve); /* diff --git a/src/ipa/rpi/controller/rpi/contrast.h b/src/ipa/rpi/controller/rpi/contrast.h index 9c81277a0450..59aa70dceeb9 100644 --- a/src/ipa/rpi/controller/rpi/contrast.h +++ b/src/ipa/rpi/controller/rpi/contrast.h @@ -37,6 +37,8 @@ public: int read(const libcamera::YamlObject ¶ms) override; void setBrightness(double brightness) override; void setContrast(double contrast) override; + void enableCe(bool enable) override; + void restoreCe() override; void initialise() override; void prepare(Metadata *imageMetadata) override; void process(StatisticsPtr &stats, Metadata *imageMetadata) override; @@ -46,6 +48,7 @@ private: double brightness_; double contrast_; ContrastStatus status_; + double ceEnable_; }; } /* namespace RPiController */ From patchwork Fri Oct 13 07:48:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19142 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 654D7C32C2 for ; Fri, 13 Oct 2023 07:49:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D5AFF6299A; Fri, 13 Oct 2023 09:49:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183350; bh=a45WmFNuorh7GWBgUQj37lz3xuS4EXguvzLOZ0lzpJQ=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=lkIU19GRIQijDt2hbhgjpWnINY+bNbrM9NiGviP3l+3JWF9wbQ3cKI1o2ABVk4n0D +I3H08UDrXc5cw/xOTBhxUzLHdvlY3ro9AuUuaI2hfDQRYb5KIGqyJNZ/Ps//sjQzC /jqwZuwMb1u4fIZT9+nzWZA36qnPnrmK5KnT1mrPD0jeuG62INvyb+hKUtsllXbzyE QMLdE0UsYznR+CO5ZFu1A/A9jWr4KPMiMcQL1sPR5B/sroJ9vDkh1fRzGRdKxR5cpe arSMUzHwziCQIDo3hHk4FyaQNUAwRCdEC5tHBMzxQUScarhPmGNMWxx2qqB1KMe2R0 3Zog0wM2tVzAg== Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 43A086299B for ; Fri, 13 Oct 2023 09:49:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="PFnT9zpy"; dkim-atps=neutral Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-405524e6769so11287685e9.1 for ; Fri, 13 Oct 2023 00:49:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183339; x=1697788139; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZNgXgb+Cnl0XP4aIcikz0avyv8rl0oeOdAohyVFJnWw=; b=PFnT9zpy3YpxAPqkHWivjPj61mKqVhbuahcKTH2ihRj9fM6gdBjCvL8wJyc0zOEJoB yva/tcIipXr2M6m8x+Ld9Ied93qVRXy7VlC7v+mzfJq7AyX6kNK01FXg8POHZBAQK/No T50qErT9mVGXaecruOns5fQ5nUVLrg2eW9RFBHwomHOm9QCQB6iAsMy8XVwIe9wRKtDz ZwBy9/IzhSRvvywmCRVnSi5IUmS0+9oCJqoHdngbA2abDZCbDHt21cor8swgHKEVMf0b kagAiz88z+nh4dTHEV91zuyEg0E4ZuEJdexZPw8pMieSbzePrh9fsutddZhABCvT6lfw KmPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183339; x=1697788139; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZNgXgb+Cnl0XP4aIcikz0avyv8rl0oeOdAohyVFJnWw=; b=k8gUffokxFaduKxoIhvFLAy/9oMlb55A2KCvJsJEBsWL0Ge79Na24agy7tTWcO3PDw uexzU6CmGpaMcbZrMkcnAsE+ACOjAoAJRt0YgcHOvgQzmAHEh42X63DaqXcyNC0NBuJN zpkEulkD8YwYMscPG45SNBJolHmGiNOx03FbUMk4fk22V3unK0wifZPGd9Ic0bB80ksZ +L6x00hfFxJkTXu0vmEzuLnA7VYf1Djy/Mud49cGD1RUdj9H2KpH4upw2RJ2rkkZa9Gw v1qKpuzw3R1aKFdjhJoENWpLIWn+yF4hAMB5OxY3n+WNMgU8a9x4LmLiQ3OVcQZDELPp 9u1A== X-Gm-Message-State: AOJu0YzRyCePaEzLW1Pmpv59ggUP0vxMJJpr9pHKDjT303LDtWytrPHt /cSNoh07l8VBVVU28pt4ar6827yTvmDPEJyNHxcF9g== X-Google-Smtp-Source: AGHT+IGwNWo953gy74z4vhMlZ2v70DM6FnBG6yJG5+WrIQByv5Dg0jKvf2GqDYkeH1jVVHbtXacDOg== X-Received: by 2002:a7b:c4cc:0:b0:402:f91e:df80 with SMTP id g12-20020a7bc4cc000000b00402f91edf80mr19174916wmk.3.1697183339464; Fri, 13 Oct 2023 00:48:59 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:59 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:39 +0100 Message-Id: <20231013074841.16972-19-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 18/20] ipa: rpi: denoise: Support different denoise configurations 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: David Plowman Some use cases may require stronger, or different, denosie settings to others. For example, the way frames are accumulated during single exposure HDR means that we may want stronger denoise. This commit adds such support for different configurations that can be defined in the tuning file. Older tuning files, or files where there is only a single configuration, load only the "normal" denoise configuration. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck --- src/ipa/rpi/controller/denoise_algorithm.h | 4 + src/ipa/rpi/controller/rpi/denoise.cpp | 130 ++++++++++++++------- src/ipa/rpi/controller/rpi/denoise.h | 36 +++--- 3 files changed, 113 insertions(+), 57 deletions(-) diff --git a/src/ipa/rpi/controller/denoise_algorithm.h b/src/ipa/rpi/controller/denoise_algorithm.h index 52009ba95661..444cbc259889 100644 --- a/src/ipa/rpi/controller/denoise_algorithm.h +++ b/src/ipa/rpi/controller/denoise_algorithm.h @@ -6,6 +6,8 @@ */ #pragma once +#include + #include "algorithm.h" namespace RPiController { @@ -18,6 +20,8 @@ public: DenoiseAlgorithm(Controller *controller) : Algorithm(controller) {} /* A Denoise algorithm must provide the following: */ virtual void setMode(DenoiseMode mode) = 0; + /* Some platforms may not be able to define this, so supply a default. */ + virtual void setConfig([[maybe_unused]] std::string const &name) {} }; } /* namespace RPiController */ diff --git a/src/ipa/rpi/controller/rpi/denoise.cpp b/src/ipa/rpi/controller/rpi/denoise.cpp index 440ee4425534..154ee604ddd0 100644 --- a/src/ipa/rpi/controller/rpi/denoise.cpp +++ b/src/ipa/rpi/controller/rpi/denoise.cpp @@ -21,6 +21,45 @@ LOG_DEFINE_CATEGORY(RPiDenoise) #define NAME "rpi.denoise" +int DenoiseConfig::read(const libcamera::YamlObject ¶ms) +{ + sdnEnable = params.contains("sdn"); + if (sdnEnable) { + auto &sdnParams = params["sdn"]; + sdnDeviation = sdnParams["deviation"].get(3.2); + sdnStrength = sdnParams["strength"].get(0.25); + sdnDeviation2 = sdnParams["deviation2"].get(sdnDeviation); + sdnDeviationNoTdn = sdnParams["deviation_no_tdn"].get(sdnDeviation); + sdnStrengthNoTdn = sdnParams["strength_no_tdn"].get(sdnStrength); + sdnTdnBackoff = sdnParams["backoff"].get(0.75); + } + + cdnEnable = params.contains("cdn"); + if (cdnEnable) { + auto &cdnParams = params["cdn"]; + cdnDeviation = cdnParams["deviation"].get(120); + cdnStrength = cdnParams["strength"].get(0.2); + } + + tdnEnable = params.contains("tdn"); + if (tdnEnable) { + auto &tdnParams = params["tdn"]; + tdnDeviation = tdnParams["deviation"].get(0.5); + tdnThreshold = tdnParams["threshold"].get(0.75); + } else if (sdnEnable) { + /* + * If SDN is enabled but TDN isn't, overwrite all the SDN settings + * with the "no TDN" versions. This makes it easier to enable or + * disable TDN in the tuning file without editing all the other + * parameters. + */ + sdnDeviation = sdnDeviation2 = sdnDeviationNoTdn; + sdnStrength = sdnStrengthNoTdn; + } + + return 0; +} + Denoise::Denoise(Controller *controller) : DenoiseAlgorithm(controller), mode_(DenoiseMode::ColourHighQuality) { @@ -33,39 +72,26 @@ char const *Denoise::name() const int Denoise::read(const libcamera::YamlObject ¶ms) { - sdnEnable_ = params.contains("sdn"); - if (sdnEnable_) { - auto &sdnParams = params["sdn"]; - sdnDeviation_ = sdnParams["deviation"].get(3.2); - sdnStrength_ = sdnParams["strength"].get(0.25); - sdnDeviation2_ = sdnParams["deviation2"].get(sdnDeviation_); - sdnDeviationNoTdn_ = sdnParams["deviation_no_tdn"].get(sdnDeviation_); - sdnStrengthNoTdn_ = sdnParams["strength_no_tdn"].get(sdnStrength_); - sdnTdnBackoff_ = sdnParams["backoff"].get(0.75); + if (!params.contains("normal")) { + configs_["normal"].read(params); + currentConfig_ = &configs_["normal"]; + + return 0; } - cdnEnable_ = params.contains("cdn"); - if (cdnEnable_) { - auto &cdnParams = params["cdn"]; - cdnDeviation_ = cdnParams["deviation"].get(120); - cdnStrength_ = cdnParams["strength"].get(0.2); + for (const auto &[key, value] : params.asDict()) { + if (configs_[key].read(value)) { + LOG(RPiDenoise, Error) << "Failed to read denoise config " << key; + return -EINVAL; + } } - tdnEnable_ = params.contains("tdn"); - if (tdnEnable_) { - auto &tdnParams = params["tdn"]; - tdnDeviation_ = tdnParams["deviation"].get(0.5); - tdnThreshold_ = tdnParams["threshold"].get(0.75); - } else if (sdnEnable_) { - /* - * If SDN is enabled but TDN isn't, overwrite all the SDN settings - * with the "no TDN" versions. This makes it easier to enable or - * disable TDN in the tuning file without editing all the other - * parameters. - */ - sdnDeviation_ = sdnDeviation2_ = sdnDeviationNoTdn_; - sdnStrength_ = sdnStrengthNoTdn_; + auto it = configs_.find("normal"); + if (it == configs_.end()) { + LOG(RPiDenoise, Error) << "No normal denoise settings found"; + return -EINVAL; } + currentConfig_ = &it->second; return 0; } @@ -78,9 +104,9 @@ void Denoise::switchMode([[maybe_unused]] CameraMode const &cameraMode, [[maybe_unused]] Metadata *metadata) { /* A mode switch effectively resets temporal denoise and it has to start over. */ - currentSdnDeviation_ = sdnDeviationNoTdn_; - currentSdnStrength_ = sdnStrengthNoTdn_; - currentSdnDeviation2_ = sdnDeviationNoTdn_; + currentSdnDeviation_ = currentConfig_->sdnDeviationNoTdn; + currentSdnStrength_ = currentConfig_->sdnStrengthNoTdn; + currentSdnDeviation2_ = currentConfig_->sdnDeviationNoTdn; } void Denoise::prepare(Metadata *imageMetadata) @@ -97,11 +123,11 @@ void Denoise::prepare(Metadata *imageMetadata) if (mode_ == DenoiseMode::Off) return; - if (sdnEnable_) { + if (currentConfig_->sdnEnable) { struct SdnStatus sdn; sdn.noiseConstant = noiseStatus.noiseConstant * currentSdnDeviation_; sdn.noiseSlope = noiseStatus.noiseSlope * currentSdnDeviation_; - sdn.noiseConstant2 = noiseStatus.noiseConstant * sdnDeviation2_; + sdn.noiseConstant2 = noiseStatus.noiseConstant * currentConfig_->sdnDeviation2; sdn.noiseSlope2 = noiseStatus.noiseSlope * currentSdnDeviation2_; sdn.strength = currentSdnStrength_; imageMetadata->set("sdn.status", sdn); @@ -113,17 +139,17 @@ void Denoise::prepare(Metadata *imageMetadata) << " slope2 " << sdn.noiseSlope2; /* For the next frame, we back off the SDN parameters as TDN ramps up. */ - double f = sdnTdnBackoff_; - currentSdnDeviation_ = f * currentSdnDeviation_ + (1 - f) * sdnDeviation_; - currentSdnStrength_ = f * currentSdnStrength_ + (1 - f) * sdnStrength_; - currentSdnDeviation2_ = f * currentSdnDeviation2_ + (1 - f) * sdnDeviation2_; + double f = currentConfig_->sdnTdnBackoff; + currentSdnDeviation_ = f * currentSdnDeviation_ + (1 - f) * currentConfig_->sdnDeviation; + currentSdnStrength_ = f * currentSdnStrength_ + (1 - f) * currentConfig_->sdnStrength; + currentSdnDeviation2_ = f * currentSdnDeviation2_ + (1 - f) * currentConfig_->sdnDeviation2; } - if (tdnEnable_) { + if (currentConfig_->tdnEnable) { struct TdnStatus tdn; - tdn.noiseConstant = noiseStatus.noiseConstant * tdnDeviation_; - tdn.noiseSlope = noiseStatus.noiseSlope * tdnDeviation_; - tdn.threshold = tdnThreshold_; + tdn.noiseConstant = noiseStatus.noiseConstant * currentConfig_->tdnDeviation; + tdn.noiseSlope = noiseStatus.noiseSlope * currentConfig_->tdnDeviation; + tdn.threshold = currentConfig_->tdnThreshold; imageMetadata->set("tdn.status", tdn); LOG(RPiDenoise, Debug) << "programmed tdn threshold " << tdn.threshold @@ -131,10 +157,10 @@ void Denoise::prepare(Metadata *imageMetadata) << " slope " << tdn.noiseSlope; } - if (cdnEnable_ && mode_ != DenoiseMode::ColourOff) { + if (currentConfig_->cdnEnable && mode_ != DenoiseMode::ColourOff) { struct CdnStatus cdn; - cdn.threshold = cdnDeviation_ * noiseStatus.noiseSlope + noiseStatus.noiseConstant; - cdn.strength = cdnStrength_; + cdn.threshold = currentConfig_->cdnDeviation * noiseStatus.noiseSlope + noiseStatus.noiseConstant; + cdn.strength = currentConfig_->cdnStrength; imageMetadata->set("cdn.status", cdn); LOG(RPiDenoise, Debug) << "programmed cdn threshold " << cdn.threshold @@ -148,6 +174,22 @@ void Denoise::setMode(DenoiseMode mode) mode_ = mode; } +void Denoise::setConfig(std::string const &name) +{ + auto it = configs_.find(name); + if (it == configs_.end()) { + /* + * Some platforms may have no need for different denoise settings, so we only issue + * a warning if there clearly are several configurations. + */ + if (configs_.size() > 1) + LOG(RPiDenoise, Warning) << "No denoise config found for " << name; + else + LOG(RPiDenoise, Debug) << "No denoise config found for " << name; + } else + currentConfig_ = &it->second; +} + // Register algorithm with the system. static Algorithm *Create(Controller *controller) { diff --git a/src/ipa/rpi/controller/rpi/denoise.h b/src/ipa/rpi/controller/rpi/denoise.h index 88b37663e569..92ff4f93edf2 100644 --- a/src/ipa/rpi/controller/rpi/denoise.h +++ b/src/ipa/rpi/controller/rpi/denoise.h @@ -6,6 +6,9 @@ */ #pragma once +#include +#include + #include "algorithm.h" #include "denoise_algorithm.h" @@ -13,6 +16,23 @@ namespace RPiController { // Algorithm to calculate correct denoise settings. +struct DenoiseConfig { + double sdnDeviation; + double sdnStrength; + double sdnDeviation2; + double sdnDeviationNoTdn; + double sdnStrengthNoTdn; + double sdnTdnBackoff; + double cdnDeviation; + double cdnStrength; + double tdnDeviation; + double tdnThreshold; + bool tdnEnable; + bool sdnEnable; + bool cdnEnable; + int read(const libcamera::YamlObject ¶ms); +}; + class Denoise : public DenoiseAlgorithm { public: @@ -23,22 +43,12 @@ public: void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; void prepare(Metadata *imageMetadata) override; void setMode(DenoiseMode mode) override; + void setConfig(std::string const &name) override; private: - double sdnDeviation_; - double sdnStrength_; - double sdnDeviation2_; - double sdnDeviationNoTdn_; - double sdnStrengthNoTdn_; - double sdnTdnBackoff_; - double cdnDeviation_; - double cdnStrength_; - double tdnDeviation_; - double tdnThreshold_; + std::map configs_; + DenoiseConfig *currentConfig_; DenoiseMode mode_; - bool tdnEnable_; - bool sdnEnable_; - bool cdnEnable_; /* SDN parameters attenuate over time if TDN is running. */ double currentSdnDeviation_; From patchwork Fri Oct 13 07:48:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19143 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 42F6BC32B8 for ; Fri, 13 Oct 2023 07:49:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E8333629AA; Fri, 13 Oct 2023 09:49:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183350; bh=3Lx2hapHthiLl5pLeRAZjJBWOhBKLgxIEHxCdgDRkQE=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=wwRBmdmZL0iS+/qsC7BsAQ8m0tvUJMMIhc30YhHTXAJH5k825wCrxcxkBuJp2gpFx hAwsCgZKYVNsUzno7L37Xn6Ot2x4BMPvXEp+ZrUkX7gWHEj9+DWAdCtk+79q/2Vm7C wosEKIj9n3cRgZnQXCmXT8otb8Bs8UmMn0BTlxlxoN6Fev6yZLn9uCF0gOkplLpocs bHzxOQGmDk7xbEFqUUIbjZ9a7A0fiApCqhq5vZCvvRF6Bv+iseMXtDTWjNy3rS2mJg cfAF3CL3V+pJRDF28XWiiaiyUuqIE+otAFtkkXGXnsBvQa4MliwfxRSrIcR1iY79Jh E25J9K3gH7NpA== Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AF315629A0 for ; Fri, 13 Oct 2023 09:49:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="LwSkK6aK"; dkim-atps=neutral Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4056ce55e7eso18580915e9.2 for ; Fri, 13 Oct 2023 00:49:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183340; x=1697788140; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8iMkGXcyRbrdBdUJFvNNmrvtddhoCuMTne7mGzBmNQM=; b=LwSkK6aKuWH467HMeKt5S7LtZPyFvzGoC3kqas4Lrk05dcNzvpOAkFuiKaUkPzsp+B E41axCa/Fu3c6naFZ4tnAAvE2GjPC+AwHHEdvUU7q/1ULifgOh7h5iHCIyiLPRB7xjWL m87tGY70haZ3Q/ugHxGqLHJ3SAS+faNDVftmNSQyAH6VCfTPwrBJmpPPjlOvnAzg5aSE /LzNB/lG6GlRrn/zmrioXvrE5c7H/wlrwK/8aPMjjvl4rN6NKay6ydQIMwXU+cFwcspn 1f6aklBHDUSCsYGM0a3+uHIG/gI1YnQp47Tr+pZHifnpKkgYI7I8bmqMS2i0BFNKHOX3 3RJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183340; x=1697788140; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8iMkGXcyRbrdBdUJFvNNmrvtddhoCuMTne7mGzBmNQM=; b=mP2mN3CeWLjmJeOHWOK2VP8XF9ZLh+bbnnbB1EeWXTyU9S0lwaIpviyqJRfTi+o8Xb 1Y7NPIJyZiEhjme1+mOvHW3MU5LJIotMIMyl8ewidOgJfr4ty5Ywz/BYUpBf0dhcBn88 9UA41+zWOjH7EqIFmKD5XFar2D5IXrDlqTbrLE27Qw/p/8mEyipN/arcM7/Vn90HFsIk mu8LzCp/A0iCeYk9TIQzxRdrD4Jj3GnKV34ifMJgVXKiqxURVg6ZNAXxxnKCb9mf/zYd w9No4WTN3IM551IOVUcg3cJZnCsMXtdB1VNhQfg3CL1fjJnGuR4Dk888v6ms6WFbFsyA hZTw== X-Gm-Message-State: AOJu0Yz4i2iqw2qszEjdc+zA239cro/lECEIDo7KoUzdB1l0rbs6sPcN u5aZEJkazVA9uaic8Dulw3jKetUkYJlxTMRQYRNWNA== X-Google-Smtp-Source: AGHT+IH0CiTHB91Al6PmePCSQqUx8Aq0QhRHE6wPDh0Grb44NoF9xHxvAdM07rwdRFwJ+cgITML0jQ== X-Received: by 2002:a7b:cbd4:0:b0:3fb:b3aa:1c8a with SMTP id n20-20020a7bcbd4000000b003fbb3aa1c8amr23615813wmi.16.1697183340057; Fri, 13 Oct 2023 00:49:00 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.48.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:48:59 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:40 +0100 Message-Id: <20231013074841.16972-20-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 19/20] ipa: rpi: agc: Avoid overwriting caller's statistics pointer 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: David Plowman The code was inadvertently overwriting the caller's StatisticsPtr, meaning that subsequent algorithms would get the wrong image statistics when AGC channels changed. This could be fix using std::ref, though I find the C-style pointer fix easier to understand! Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Jacopo Mondi --- src/ipa/rpi/controller/rpi/agc.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ipa/rpi/controller/rpi/agc.cpp b/src/ipa/rpi/controller/rpi/agc.cpp index 870cb4315c42..758da0719b9b 100644 --- a/src/ipa/rpi/controller/rpi/agc.cpp +++ b/src/ipa/rpi/controller/rpi/agc.cpp @@ -311,15 +311,16 @@ void Agc::process(StatisticsPtr &stats, Metadata *imageMetadata) * exist, and call process(). We must make the agc.status metadata record correctly * which channel this is. */ + StatisticsPtr *statsPtr = &stats; if (channelData.statistics && channelData.deviceStatus) { deviceStatus = *channelData.deviceStatus; - stats = channelData.statistics; + statsPtr = &channelData.statistics; } else { /* Can also happen when new channels start. */ LOG(RPiAgc, Debug) << "process: channel " << channelIndex << " not seen yet"; } - channelData.channel.process(stats, deviceStatus, imageMetadata, channelTotalExposures_); + channelData.channel.process(*statsPtr, deviceStatus, imageMetadata, channelTotalExposures_); auto dur = setCurrentChannelIndexGetExposure(imageMetadata, "process: no AGC status found", channelIndex); if (dur) From patchwork Fri Oct 13 07:48:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19144 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 DD859C32C3 for ; Fri, 13 Oct 2023 07:49:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8C4B1629A7; Fri, 13 Oct 2023 09:49:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697183351; bh=qWYFKgKt+M35FD/oyMfU26xNozgblvrSu93pmLzVqfc=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=J+OaEyyYpY75XnIFSBRSUXomQAgXZHIRDL4D+1hmXvAIto55j7qQSYZ8Y2Kpgotny X08rOUOMelHVxCOW7/2kbDguqN1aZcWNidTtPbNsEES9ytZ7OTYG0AaEf0VZGiCcHc J9mv2Yj+wrLwP4pXMkrEHirzQbkOiTUK38LW6lpus4gHyaY5KJZYrjoP3fh2hxqIAF 76ZcmOhFBBDq04uZlc1HnfSLLSfbAuekf1BcFajYmYhH2k0O+55HQgOrUj37iOH4W0 n2OvRsBbn62lMMCf8gVNAQRZnRy2ZS+SDxVmFjCrPgwBvLjsBf+uxr1a3f+t3U0XIb QtE7UOYrwZALw== Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 68A5062980 for ; Fri, 13 Oct 2023 09:49:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="lafyLJGS"; dkim-atps=neutral Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-405361bba99so18181555e9.2 for ; Fri, 13 Oct 2023 00:49:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697183341; x=1697788141; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=I5J8mlsHtCYzdntwDAWvg8yYk6A3l+isJ5W7v+jGlFs=; b=lafyLJGSEmAZhmW7OVVTHtnKJlzbdpbH4ouS43Wtee3dTsUC+x214Nz8rV5x0/GtKp Mte1MrcsOR5C5LgbapsYe0Y+gYHZUN7wdd2e4G7iZf4qVtyqXHVsMGF5fn9kGx4fWZIu d2JHyCrK0wRHSO6RAljGmQzLe3FN9IYDk+4faw5SUsLnBk5MpFQ73jwi7NYNYHbSx9ip qJtdjuEffdv4aO5EBPyl3j/6Ao+yXLHeMeR2LCr0Q3GBZYODKLNTGh0LoXvJrSRQNrGx FeUgH7uKObJaSeInJ0SsR5qPol3rsAePlqJfd+J4jvbdE+B3D9EW9noNz9tMvbmOL6tX pCtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183341; x=1697788141; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I5J8mlsHtCYzdntwDAWvg8yYk6A3l+isJ5W7v+jGlFs=; b=bAX7fWiQjGUy5yLm18palzoVlJeuYIGZL0o5Rst8LPQWxXOisiDAjJ0arJqkuWv9dL H9o/1/luN3En8u/NmZ1A2EV5Y5ikgwa4CVxrT2J3rc5sD2BEngpwR5W6Ic9Egvy7m5A7 svgtwiyM6uup6+itigBhW9S4Fxo6NvZJQZz1Dy/NNllOkj7nTQiPG6Fqu0b9HovVnB09 IX4RpYPr9/XnN9ptE1KOYp4cJgWQxh4/8mtfKhDKzKgkkQVVluTpnPFvxM5ckv+2ztq2 /JOH1L4pHJZh3W7vblflwpJF0RRHjW19AzUCC/uYlhggJqkpldxPq7qM7cnxk0UX7Lkn jbuA== X-Gm-Message-State: AOJu0Yz2RAdWmC209CWMbYbNR8xg8J3yXr1W280xCPB6GCxdNpJ0Rpvl ZgnlMaWu1zS5iWTO27QG8ZWSO3QAACcUeRUD+SlQ3w== X-Google-Smtp-Source: AGHT+IGnf1n1iZGT/joIzUzLMuJ5mBYxbTT0SMShTOoCDDdtskdP7YvV7UV7fh56ysZvPakjqR4RXg== X-Received: by 2002:a05:600c:214f:b0:405:3251:47a1 with SMTP id v15-20020a05600c214f00b00405325147a1mr22927731wml.40.1697183340867; Fri, 13 Oct 2023 00:49:00 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m16-20020a7bca50000000b003fee6e170f9sm1791890wml.45.2023.10.13.00.49.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:49:00 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 08:48:41 +0100 Message-Id: <20231013074841.16972-21-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-1-naush@raspberrypi.com> References: <20231013074841.16972-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 20/20] ipa: rpi: agc: When AGC channels are changed, start with the 1st channel 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Whenever the AGC active channels are changed, start with the first channel listed. This allows applications to rely on a particular channel being generated first. For example, multi-exposure HDR always wants the short channel first. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- src/ipa/rpi/controller/rpi/agc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ipa/rpi/controller/rpi/agc.cpp b/src/ipa/rpi/controller/rpi/agc.cpp index 758da0719b9b..32eb36242268 100644 --- a/src/ipa/rpi/controller/rpi/agc.cpp +++ b/src/ipa/rpi/controller/rpi/agc.cpp @@ -203,6 +203,7 @@ void Agc::setActiveChannels(const std::vector &activeChannels) LOG(RPiAgc, Debug) << "setActiveChannels " << activeChannels; activeChannels_ = activeChannels; + index_ = 0; } void Agc::switchMode(CameraMode const &cameraMode,