From patchwork Fri Oct 6 13:19: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: 19103 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 0D819C3273 for ; Fri, 6 Oct 2023 13:20:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 85AE562961; Fri, 6 Oct 2023 15:20:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598400; bh=PTdXqvjKTLp5hBTDZKjThMbqL+JhV6U3F7jqTNlXD4k=; 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=OpZQuODdQYuF4a7t5pI5T4PZdv8z+YEhKgzJI8pibKqxZBWWFus+hxHH1jvtGRhiH B4w/aU9Mn+Tm8Rnwkmo4GkWEqPzj0IeDgyp8uKH09W6pa3YuIhbolVSIhGBZ/qsFh5 YpuDrzIje0zQXaY0iz+jhTdKDHS50XK5K0ncrgZiHu0Idc2MhIK65pV+UisS3qy6WL q+F4p7h6PU4dlrEr678bR9F9zqNMWd4h1GXD73No7teDRJ5PrWEGq/XHqssLX7Q6j3 +rUkJT0Qc/r/+nHI4+MtQ5n1Kl8seu39fW+cDylNFuGl/Y+fvIP/zP6al8u0aXPcm8 IhuSCgMJA053g== 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 0E7F961DDD for ; Fri, 6 Oct 2023 15:19:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="LaSco4vz"; dkim-atps=neutral Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40684f53d11so20300385e9.1 for ; Fri, 06 Oct 2023 06:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598397; x=1697203197; 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=uUCSwDkBt9yq+OpvYGFTB+hE9KGM3RBoxwzATHS+2C8=; b=LaSco4vz+FqQHsPOH6bLWJSC77jYFQsqTdHoJr9yoNYX2Kb0bLD7/s1FROafmLD+qw rEjOzgieRPTkJWwoWwWl5DV4WVEPRWqzJgj6HTWtieevOBU8ykv02Lnsjff7vpg4ZGSZ VIaBloqgB8jrnAwGxbClu1bn2KhoKFV+yCU02a4yogcx6dw+DqrsbRrxdJzZ9TyiS2pF t6cjgczZzzkc7dCUWtTg6toaLICFZvmlyf9wSc7P0b+bwzuy83EKxIx4TiRd+srTwA4x qZFHiqdWxZzg0I04wIPlfWzJecqNKesX1nc5cjJLpi3ZN12gEvgRAc9uAyj3UT9ZJw1B eqag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598397; x=1697203197; 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=uUCSwDkBt9yq+OpvYGFTB+hE9KGM3RBoxwzATHS+2C8=; b=nVAXuNFF315ovbNoljdmqkWEw+USHZZgXVGEruomPaWDZvQuDwmJT9vWDMzu/TqA4X 4nPWGvzD4NTNZbUMms0iIRI1yx1O7memBsJSo6+zE8yLXlHZqfgZTBkIPHs59DHpNXWv 0cIXa5BDssCXUlkg2NLdc4JoK4bpHIvK5bZSrUrUg6OwurpOV0PflTBypkc29JUz+0nn uK/CJ6A+JvZp+ybLqXJqF6DsV23ybncXPA8KoFkD71axOFt8OnemP1U8jfJs+8jKtCal DWcAbACduFWHW4W5DfNEvZBHxMRdCzjuFjAOKz51V4+3Q/TVXx8l5DOHLbPIMdKs+Tv5 KJEw== X-Gm-Message-State: AOJu0YyJ7BbCSOWyUOsCwHNk7OUW5LFZLC8Mdh/cLx76vhgi2o1VeGoq 2h2XZDx4W3yqyxP4QdWN8FWJGgmAiOJdo+/sBeZiHA== X-Google-Smtp-Source: AGHT+IHbzKG6XEX2wIwAQDKWZaLpb8rUOAMRO/3pCSJNyBKS2/oLkb5xSaYjnxwrKmwmlXePcXKVRQ== X-Received: by 2002:a7b:c456:0:b0:402:eab3:b4e9 with SMTP id l22-20020a7bc456000000b00402eab3b4e9mr8017203wmi.33.1696598397297; Fri, 06 Oct 2023 06:19:57 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.19.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:19:56 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:41 +0100 Message-Id: <20231006132000.23504-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 | 50 +++++++++++++++++-- .../pipeline/rpi/common/rpi_stream.h | 32 +++++++++++- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 6 +-- 4 files changed, 81 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..83c2205f7ca0 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,17 @@ 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 6 13:19:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19104 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 CAEB7C32B6 for ; Fri, 6 Oct 2023 13:20:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 17D406296C; Fri, 6 Oct 2023 15:20:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598401; bh=suH0PJIgEqPYNksTKJuL5bMOo1kXPdifvQWKd+ecGoc=; 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=wpcx6pdMx5nPshIIujyFT6asBu7xFyZH3oIBFJD7MTxQ+P2XyBmCuolmcSaWOOO9Y rjfaaY66KI3Q0+EAqzcUNLnHh8bweRt0tBtFQomOME4yXnaOm0/EW8OWYL/CMxHQbd knA1tqFGj9pH25eJEu4v5oE/JvpWaZhRgwVikxB2UIdFmSm7Yt9j5L6YI1fbM3v8I7 Yum6E9SXjcmcUYc4JQKWQYywMEwX5aciHYseu4ua9zvhKOvr5P5n2WkGTccbEn1loX KRQy2l0tOoHLOexxgRaPRovoHIpCqCbjlQoOU38X1irJ5x4WDNDSdj+6N9YbbEOwGe JEcSPgdQPxIYQ== Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3B90A62961 for ; Fri, 6 Oct 2023 15:19:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="q5Q7tNiu"; dkim-atps=neutral Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-3232be274a0so2013791f8f.1 for ; Fri, 06 Oct 2023 06:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598398; x=1697203198; 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=iaJ6H3b9VuzhIwenAA8wBuE39LFc+MtAJZU0c3sCiBo=; b=q5Q7tNiucHlsce62xH2qVPHbXlVKL94Z1WgPn1u3y6p1DD3DCYQWiY7MQkTGkqT+4J ICQfcEPeMBS1kuKBrQgDznHCXExb1JKb8yPzVcJu72hxtfZK4i3lcOc0/kZHHUu9lplZ KUMszuhSiKhLAw7rjgJdXEB8aZoC+aS0muvX0ezK+KzaQaSR418u9pB1dRT2ZAtc9DwY ILm64aXcsdA60Bfge+qv+QZoWzjr+HM+uvrwdtiW0gcogRx77u9f1ogEY/5jMwMLc0uc S8+Lb+t2AUT4LIwhziaz4ryq32P8yi9bV3gKcc38Rf6MtiKQMVzWfoZoc9C+woQfaUQ7 F5nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598398; x=1697203198; 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=iaJ6H3b9VuzhIwenAA8wBuE39LFc+MtAJZU0c3sCiBo=; b=d7b806zpYz5u9QeJazSEuat/XmyLSF3ptBxhiVc0/WyfRUhEqUB2sIK8D4t3WishIG nOL7GnvKZRJRWih0L8FM5EBLE/zobBLPF05w4mG6DCj6vTTnQU1Rc3SBB2LpbosIZn/D bIDfnP5l+aFoIJeBkGrnmDa0E5DN/60/3DkQC+QRY45vg3juvqrbchfmzz3kI05Pn1yA mEYlGCYLBJ0Xe+hNHu/HuQlGyqB3dC0TTC0AqCw6xP4SZgUonfbLVo0Y/2AFxYKHRWbr DBBMqJUlnfb132xHqB4NVK0LRJY9RBtdd5tcRNA2uIm7UXhZ5+1MhyJIILL6+oiPPNWb TRmw== X-Gm-Message-State: AOJu0Yw81epG8UDOq2aFhPxMSzwlZP/NpWan9XRk/JjjkcMBmpwSbGm3 M3IocWWswQKsOrJHOaJzE0dEQidZ4psROPbgoI3gWA== X-Google-Smtp-Source: AGHT+IEi9hBaD5Zd1EsPHXtCYiL6nXHGvk8uF5GWJI5PmNzBxcg0MtwnDTbqa+fBNzsG3LlvUddFbg== X-Received: by 2002:adf:cd09:0:b0:323:1e69:7b4 with SMTP id w9-20020adfcd09000000b003231e6907b4mr3864736wrm.31.1696598398301; Fri, 06 Oct 2023 06:19:58 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.19.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:19:57 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:42 +0100 Message-Id: <20231006132000.23504-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 83c2205f7ca0..fd6f2efc6e27 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 6 13:19:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19105 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 51EF1C32B7 for ; Fri, 6 Oct 2023 13:20:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9812C6296F; Fri, 6 Oct 2023 15:20:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598402; bh=MrbguUUhWoJ3mvBKCag4gOOpqwweJsmOEDY+C/5I+lA=; 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=C+Xw2CN3DDx4MBd30F0D49A3hV1oH4eynB05XZfX8RRkhKbWGyPh4OpMT6sxtWJui A8Q0Oyks7x4rYNOsGVfnRwNoc/1a1fXK1MNqZOC/KF//PnkIyqFAgcdNnss5KjgrPy QW3CKAs3aT895hxtvmpP7dKSniYXbUlHMAiKe3huDvx0dTnOTn1lccI3Nx9S9kb9kU OiRsrL7Z0AUV937Wr+3Erhu8ZQrh+z1F3b/gY/L87ydCE4NRU2HEtRPehtqHBND7rU +WriGWwFWpzGt/2HgDn7HZ9G7Tufb1VsaEehJ/l5WxDKDv+T6RZhb3XVAE8o2V+Moo UlSiOVx2WiOdQ== Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3815461DDF for ; Fri, 6 Oct 2023 15:20:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="b1/TcgLS"; dkim-atps=neutral Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-3231dff4343so1329432f8f.0 for ; Fri, 06 Oct 2023 06:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598399; x=1697203199; 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=Mfz7taO4zHPB6ZKI/hoU5uhlW/mJ3kymDVPfQGARFmo=; b=b1/TcgLS+Vv7ucOnboZ0A2yKMEj+JAyirPZ5jpn71lj0cEMDhxy/p/vi7XzyAfT+TB eyKpo2VXOFtPUpEMXE4eSKuTdqqNBXeq/EiMpECJ7dt5ok15ZwFB9isSyeQGaxYggsy7 nIicaYlX5cF5ZEGdtdNMOzs9/viZ2AVrDsoj4vzJbDu0X9IsEJ3KOu4ETEkQO0R8aGOu 4CCEI9VnOdYQzU4h//xhrhAmPg4f/aT/0JfAMawLgfh7i7cipI190WItBBNisJboOKHA PdqvqPLKBeYRMFwdD9XV6YJC5EsGxAtiaKt3p90BJvW7Jygz7MMpOPbd5+sYf9U/M3tE VnuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598399; x=1697203199; 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=Mfz7taO4zHPB6ZKI/hoU5uhlW/mJ3kymDVPfQGARFmo=; b=ClgR4U330U+QfftNuUCVPklb/PUlkh69hqx9e4dupXgXQSXPyQTHacunousnckEPLs 7sPrtSbBafpWhIS3xU+vim2EsIBlg7hPkpv7buHzASjHDWh4vP/7cGAwJyo4PPlsDhPQ IshLtKv24D4SIRPsOlCR8tbMNlrYlsKSlZooSVt95rCy6tuKka+ys9KDJNEeH1nKt2dn b52/6eMwQIkNVsTiHoRoNNznxLwlE44xmE66F3lKR/XjA+GoDNaCo+kiwK2OO5KqTVT9 15c5IUkedZ4ylq0eTACXRFs8EcgqZNTXYYDrOUM7/UquVrrD4bcptpfC5F450Nisq/9g kiHA== X-Gm-Message-State: AOJu0YzPFghpix+r6DcEnOBDWlLaQOC9++1bgH9jjGwJoGh5H+g9W9PH 44QdKfZ/3Mgol9ADiOTXHNYb0zJNsu0NcNZ17SLrLQ== X-Google-Smtp-Source: AGHT+IEabilBkvqh33c9tOG7dqXMMyZgFS3aPGRW/p3+IQiBm59gL01aN1cnkXG+miD43C3VqqpxTQ== X-Received: by 2002:a5d:55c7:0:b0:321:6339:f523 with SMTP id i7-20020a5d55c7000000b003216339f523mr4762413wrw.22.1696598399692; Fri, 06 Oct 2023 06:19:59 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:19:58 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:43 +0100 Message-Id: <20231006132000.23504-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 | 118 ++++++++++++++++++ 1 file changed, 118 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..69051ecc3f52 --- /dev/null +++ b/src/libcamera/pipeline/rpi/common/shared_mem_object.h @@ -0,0 +1,118 @@ +/* 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 + +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() + { + 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 6 13:19:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19106 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 B2BA8BD808 for ; Fri, 6 Oct 2023 13:20:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 60E6762971; Fri, 6 Oct 2023 15:20:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598404; bh=9ZDDvTxPOZsT2Xs9ZsTNX9mUbI9BoXmsCquizANYbFQ=; 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=uUGaFpAOyl6f4sVuWYcbJIKSbAf4KTGFdcOwUvzlsZ6xVt1hkssap9vnKs/toHGmr kCevA3g2ztTEmQt2IqLITD5Sl0JzVkGWY40DdGNfq2KrBh99iqTMVTcICww8vWTA3Q c1a5i5OgvcQoC5+cJGNKRSzEAczA5xdLe/kNQLilJ6U3zN62rIijs8MrYrTD1YC38x RlFS54PgSKFqMdYXda+bsdNhjE7T+wAxhprERe7eTR2r+bCOjPa+U7sCIxEsj7rejg +284VdWe+anU/RaMlOwK1gyiS2bVyOVuuXFnlGBhl3Rj0tqIErWy+1mOhBRVe8X3fb kxwmwjvfY0znQ== 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 8CFBC6296B for ; Fri, 6 Oct 2023 15:20:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="fO0JsH3M"; dkim-atps=neutral Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-406619b53caso18758485e9.1 for ; Fri, 06 Oct 2023 06:20:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598401; x=1697203201; 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=3C7R0572Ac27bu5Wt1ogqZJgDpUoBbC5YoWlWcVDKLY=; b=fO0JsH3MV/1znDZDChDmkH83d50fmBZD96h9M7LdY7JB1y/NMF+I4nnNtShJdEpNam BQPqUTed3KcB3gl8TMHgIWl0/BaCk7yoxB+tkdlv3dpEqMuWHuE1k8UIwnQ79Y2e1/EV tCk13Xs+zFGzB8R3DwTOC8+BrU4HJTMEIANzYUwP+eJ8u0+7+edhVGV2jBZK40xoEA2F w4HNsgjGlhCIdwKFVPcHOIC16vAwrbM7/E+PG5V/btu4idzky4DMvdFQ2ju3ySp1Z3C2 m2T1uiQ0Nlf9k7Zb0KX94+NC6MQAyAholIG3d1KQayQFUBFralEM4oSZIjBtp/5yiW1R 7/oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598401; x=1697203201; 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=3C7R0572Ac27bu5Wt1ogqZJgDpUoBbC5YoWlWcVDKLY=; b=rUeMhanboa75hiDr998tgsdikw9y4Csao/i47MVQb2OORaYLUFYeRX7kbB6kmFiegp ztUtLvk54iwN+e5YBU4ShAe6suEqyCZWoh1JZ/ImEVHCETdK+xmvwmvWncP5K9ggmWum LGqrKLVVVV7+MK6X+YZhS9ZCYjKybUKSmB/M2Vuaf+vbJalUT2UYzYTTBXapM7PWhy+E inNVMl8Jm6dXL0/aBae/CK02VVGSX6y0ME5zujHgzsnVREbZFFCTlxkexiZ62XkMgpQh /OCOFKal0scZrLAgBt/NJgq0beTAzsOKc1tBfOpfeuvc1kFgqKn1bT2Di/Z30A4xxj8a CjsA== X-Gm-Message-State: AOJu0Yx1BmZOhJbkr9TsOpcSgZH9UMVLYlm9mg7D1O0UfRbi/WUNTfmL fM8Lsa7q0fvQThnv3hWaz/MQV1KDy+imQjxSmISf+g== X-Google-Smtp-Source: AGHT+IGQnXIGs0ckmEpBHr8qKRiW5OpYZ8s1DtQFZ22L/8SRpwTW+D2PlMXoYB2hiIdoqUrSsQZnBg== X-Received: by 2002:adf:f404:0:b0:31c:3136:60af with SMTP id g4-20020adff404000000b0031c313660afmr6428510wro.61.1696598400999; Fri, 06 Oct 2023 06:20:00 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.19.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:00 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:44 +0100 Message-Id: <20231006132000.23504-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 6 13:19:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19107 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 4E2FAC32B8 for ; Fri, 6 Oct 2023 13:20:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 026F762978; Fri, 6 Oct 2023 15:20:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598405; bh=q0vFDvJ59VY1d2uiPajM23Wn3sUowIiscRNkmUTSDtU=; 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=lYUvC/bMkUMShHVx11bjv+A2MEOJiJE+yBdqehrqboJxRJtwkCk3GwZAeERWYnY9N 5FM5dPTkbuVOa3duWkzPynLTy/VwweO/SgZzT0pPljltznr2HvR9PXEihde1brnjw0 SnXy7e/XNaczI9DdVo8eDJk3wiuVCVW8wTjg23gTBs80pbDrL8n3R2qGrOilUi0EZ2 3GyQphJIC8JvUY7s5NgzQ5Kr5p+UDuJo/uBmdHgDKZiM5Pse4EdDnzdjSrdIFTeom/ IR7jLb2uw1tnCLRLgn6j6h07XUVsEjY5dtsUJFz5FY/RsWaViW7hJirAAqTc9GHZRo JI8L3OYL0kg7A== 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 DCA216296B for ; Fri, 6 Oct 2023 15:20:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="m8jvrtCU"; dkim-atps=neutral Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3231df68584so1935522f8f.1 for ; Fri, 06 Oct 2023 06:20:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598402; x=1697203202; 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=yWhhsdkDeaFIuTb/9tB3mwgwsDiB+8l3puInlWZGtSQ=; b=m8jvrtCUbjOPnCI28XSfi26YWvIvyJZnkx+/1GcdQykOxoBxqb40pXDeQ27x3RqnW2 wl2RoU4qzOn14hCxccR8M3bztXJgZ6MKissE8pDYt4PAxkw+n3OtV1JcFOsilWe3xP9v faN0SzCZ/nIPVk+9FOsFvIAOBFqcq9EbPrpL14EirEpQQLbT/GLzYREevFp7KT7vvDOb LH7FllfynhRJNVSTXJqWnc+qnKAgce4DZD16H5P8sDsorQnwMDqZ+/YozCKdNjkLoMcD IdEzBVYee0h6x0D9HvuWhLky1JaSoWsq/zGAAjlYp4M1hJ1/MDtbv/rPr31oqhpKXx2f 5YIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598402; x=1697203202; 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=yWhhsdkDeaFIuTb/9tB3mwgwsDiB+8l3puInlWZGtSQ=; b=iqIEL1lLd2G1sfAd+EeldrOctUQCoKo63ldUGvW8hkl4CFcibgqDabXVycfbny3w6x oiYWud/cdD694b7ZAgclmrb0GbKPSHypEJYy/0RwgHKxGkWTcaGOxNl2zQQFUUkPw1bt +WrlFPnJCzSCP6uGQJAzKlf6EvXLdRYbN6epa4lQW1FGfAMvIAL07bdThpnSgcqUPXTB oomCRERBhDvmEdjr2BmAezvncN3CnbiWC6ogTy/MjkT6m8fOK9OZuF2Ez+7s2heGjtQv 2577dr8BijV0+hGpY/a4NYSaBWqE+r0Thp+KkoHUs+rihFsWtWfOBqScJx71+BAd/9hN GI5A== X-Gm-Message-State: AOJu0YzIC1FaMTLcjse85IozHRVUGLWejjIg7OWBi7+XVnDlIZlnEydd 8yDtJ15i/vQW/WwNA+6D1/EaJcETwODLyfzGDg0lDA== X-Google-Smtp-Source: AGHT+IH5/weplZezGmoJcHhoaPIICwc9LriXGWyRKURF6QSSKwxyp/q8ZBQzSTxgCq0ZxktPT9OaQQ== X-Received: by 2002:adf:e491:0:b0:320:b2a:4ea6 with SMTP id i17-20020adfe491000000b003200b2a4ea6mr6888820wrm.9.1696598402020; Fri, 06 Oct 2023 06:20:02 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:01 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:45 +0100 Message-Id: <20231006132000.23504-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 6 13:19:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19108 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 E72C7C32B9 for ; Fri, 6 Oct 2023 13:20:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9CAA762975; Fri, 6 Oct 2023 15:20:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598405; bh=DFKrCrwQ1PQoIr32/ygh049wwrQ4Ec1bObBwxcYMe4U=; 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=ajNrQ42QGM8jDBoSo5LixWsy7IcoMjc4cWpFlfF+W22yxyeDBskfj1xXG/FMu4c+H EZjYvTQ34J9WbX7OPXWQ1IHWPVD6s+InsjDfz0/Fe9RmJs7fYtkaeemhLmfvdPJRC9 6dQ4/OXGGZHig5Dn8yIpkGlmkBXuVUKOzV1szjLbJmozsSa54LDRfkXTUxMZqERrN1 Cz/BTBsDEXU7uIZPTOSqH6gjC7IxY9jyPbLyYJvLh1XF2VyX9HspI88H6tyw1nWaHJ NHC/lrynTrXSayO0p4ZglT82TqOPoGFMaAMi+s6mH34FRAGI9MJex1GAOEspAiCIDT mNNW9Fn1HQa8g== Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 987CB62971 for ; Fri, 6 Oct 2023 15:20:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="cOTGRfeR"; dkim-atps=neutral Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-313e742a787so1313650f8f.1 for ; Fri, 06 Oct 2023 06:20:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598403; x=1697203203; 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=YMiXqTq3vID1L3qbUHsEuUNfPfLpxttUS2JIGfVVgfA=; b=cOTGRfeRv9NTgwnWejSOUHcRk3viF7av/iTwG5EJ6zL4UFri2eqyPOHRBp9DhahQO/ rtvenD/R76srCBi0FOHWnXej3/6Bc/yxDqGNnHc1yBh2dyhRGe+9z11n/piVBmdQWM8f 3qslOqYLb2YMkJNsx19SwFOsL+LtIvuetWlw5z/xi5ShqzZM/mgTsJAECMKl731QW3H4 QUolzNIRr+5CZyBksE3I58aQG6U3HOPpuIBE0wLtV08U6JPysDCpqzhwnQJrbbcPFDbS dm4UawDaWeSB7DLS+m10TEbN1j8aPsZC40nVE5Jpdu7sDR9PoXyOHSb7l0huDupJ0JwT 3OtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598403; x=1697203203; 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=YMiXqTq3vID1L3qbUHsEuUNfPfLpxttUS2JIGfVVgfA=; b=G3FUAQjPQwHnP655vteu2771JjWGfsHDHn6AvSD7F57t18vcbe7ZYbqR4ZkyDlGfTb xWiG/X6TrhrqkTzs6RAOkjkUWfKZZpCtPC0rfu36c9rH3+2LKEDFCQo5y7QS4Z5DAJil KE/XElJ4FQjoj7CiIdUHoG52UhDiOcI0sS4hBrCWkTD/T2sRxoxOWGGyU3Iuo0KfsaY6 s9oyDGuzf83eZ7U11kLvW5O0ipVV58l43xLZcKmMx18wtgV3xUur1ZKr/Bog71Y4LNQV wnbD5FnbZSWWrhsaH1X5jzCjKOQWVLr8w5xLuMJ8mQrfWWxmXJ3Zofs/FrSrV2coK1ch pdLg== X-Gm-Message-State: AOJu0Yz4I1dNfiT8Qy3J01Oq3zQguBZHNHUWEqIss+GGmssrhe9PmAIS KvBCThnhR/cyPWyVZvk8cJb/qcuCbj3KgC3k3p01XQ== X-Google-Smtp-Source: AGHT+IHhiFdkBH/M6wxTgNn7/YfcJQXtkw5tNnScistmNpuFcL2Opkb0Wp7p30vq1eZvBq5qrZ6Iow== X-Received: by 2002:a5d:56c1:0:b0:31f:eb45:462e with SMTP id m1-20020a5d56c1000000b0031feb45462emr5205154wrw.28.1696598402849; Fri, 06 Oct 2023 06:20:02 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:02 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:46 +0100 Message-Id: <20231006132000.23504-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 6 13:19:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19109 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 9C5DCC32BA for ; Fri, 6 Oct 2023 13:20:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4B3F36297E; Fri, 6 Oct 2023 15:20:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598406; bh=LHz8u37OwGI/wuTVdZF3yv9dmJRF0tMBAMBIG9SMWzI=; 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=xiBnsElYYxlNdIUKx+1oOZBONZxXLCooAhrzxUlyluDIjv2cDN+xe8U9b7DM9ai1A GT4EqML5J7XceWzYRxLbmumWdqqX1g5zk2oiJZmLtWBgmxLpbHNX51OiKzpN8MdSQU d4e7hHEkC1LqCnseRqq87iQMpUOFbC/V1/tyR+vU56a4Am25awdYH3bNzpbeaOM6rg D8Hg+/ilZLlADF7wOx2kZTa5t2YrATi1EalRwvt+PMp2oeij8tKCRnX4x4TF0G/0Tm kzGzY42W7tbovkZ07QPJnzOM/NOaonmF3gctE9IJD9yM+lSrOdB39GxTxHrYnkdtJZ VAkIWCqgRm1Aw== Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9144262975 for ; Fri, 6 Oct 2023 15:20:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="ON1SKNZs"; dkim-atps=neutral Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3231d6504e1so1917682f8f.2 for ; Fri, 06 Oct 2023 06:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598404; x=1697203204; 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=Gfnf3eFrGWi5BuX3QgWJhR2IgqMg0A06aPgA4jJrFJ4=; b=ON1SKNZsihWpluDpxJOMTRMhpPCfSGgDWS9Kd5OLqEB/OM+RXY/KyysvV/KD+j8jX1 jhktZLEnrwpnHts9jK3JIh4aIoFpbc2yQM+KuB6Vfu26lmZhU6sJLT99wTiolFKo8jLr GvgX04HSn7peiiinzRCtX0gRJlWF1fJS84qV20ddQt43whhnbvbQw0859wNeKadaSOEG ULatF4q1TVcj8Si41TvpnoG6sxorz3SF0anE72H8BhwhcXE6ZJUUa55JYbjTXuhZY4zd zrul0Z7v9m3jFHvdg7pdP9F6ubsC0KVILVRG50X8DyFpmBzPe3AJsQtAdQ/defoAEhfo R7uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598404; x=1697203204; 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=Gfnf3eFrGWi5BuX3QgWJhR2IgqMg0A06aPgA4jJrFJ4=; b=uTVQ99/sO4QUW5bpNjhSvy1MoxKdyzow0RN+ZJSxW3ywQRjujxj0k/iYBXQkaVcaIj ak0LmGGQZYmT5zQB4qSEksN1Wa3+IBviYaGUOiH+s2U9kza9VI+k3YxcgUMqljVjzAnw oW0cI4K3olFrMl0l55PWRmavJB5YymlcFdxZs54TJAUw+9JhD9wJoM2m0moAoP9Nx/LB 6go+gzSLHqhG+9it4v+vRMAAlb/cDag8zwbG2acPK+uIwyh84GQTl+3EwsxnyjimT9l4 QzWnxlT2xUHslH2irOl/MaO6Dq3MRJ+IXCS4EFxVBl915z5Yx6YnsK4kWqlVx43s5Sec 5CYQ== X-Gm-Message-State: AOJu0YwhBrCE+YetEz9wXNUWUEDELfWQQUW7gWoahzOeDsv4z/MIOCRr scoB69khLzgzmnRL2UPu2Wf7nVDvCHysQR/GpiOGrg== X-Google-Smtp-Source: AGHT+IE41HKWRTBpaXXgTmzkoElLh+4FGquUI/13kX1PvR2p+6+3PDvZmOaiw8Z2vPZxQd8oUR4h6g== X-Received: by 2002:a5d:5448:0:b0:320:7fa:c71e with SMTP id w8-20020a5d5448000000b0032007fac71emr7815787wrv.15.1696598403916; Fri, 06 Oct 2023 06:20:03 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:03 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:47 +0100 Message-Id: <20231006132000.23504-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 6 13:19:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19110 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 7E093C3273 for ; Fri, 6 Oct 2023 13:20:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 20BD562964; Fri, 6 Oct 2023 15:20:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598408; bh=j/SW7gNoxKpiRffDpQ3V6c90rH0Ejl1dJ8x3bHYT7p4=; 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=puBGKZeAJpPAtCI7hPKHvzrQhZ0fLVzD9hIR93m6twcf+oX0gFY5iPTvYFiAh1jQF xyDLUDqb7lTX7KbSKJeNWG9e8VxJ5KiyUCNyM2P/+mcMWJqlZ6Ztsf5Iw9yaf9CY1W KEJMokFxIHzlvIOeM2Tjoy9KjaPwQwXSslIQvC8sIVJVkbpbjAyoA+zYaudVsEgFfB o7WafKss7hGhHfEP4tpRksFxSLEdvP+3jCjASBSZ4Ux3r2pI39zn+SyREwOHJcqbw1 WrW8lIuVYiO/Km155zvf10a5HUrxFxw/xHHcsjiDUuOEYUhX68rQpv3XvhiSv+zJVv jGkGCvaUMKr4A== Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 04F0A62964 for ; Fri, 6 Oct 2023 15:20:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="C/isIsbd"; dkim-atps=neutral Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3296b87aa13so396958f8f.3 for ; Fri, 06 Oct 2023 06:20:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598406; x=1697203206; 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=AkNVdholsXPriKWLuKJtW86dK6QQTBncTOQiC4z4Br8=; b=C/isIsbdiy/hoOd2E/oDVr88GX6Y2nZe3gGj4UkmAp2pPw2khf/vgy9F8WTXPQl8R2 GA23m0M60jag+ZnPPHK53wDJYbpPKh1ZCn47sTjco8ghktNljKJuTpt7WSm3Z9hqInjw 2ZyiCTELFFzEGd78Y2/pN7lKxBQ5DWbCUc6hKNGkG5RInUCga2llag9C8AYa/d2JXYlO NJGhF4drc3qBqljpQMhN/J95yLV058O++LNSWnkSCIGMlX7+DfJLBPCbkYQZDL/hZjcw LqhhagtXapikzra7A8l3RfR9xP3khwY0+ObKH80CIRKr4QEaUop1wqcn3hZvn+ZiHHj3 dTUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598406; x=1697203206; 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=AkNVdholsXPriKWLuKJtW86dK6QQTBncTOQiC4z4Br8=; b=qBAl1jy5jeWJlR2ohsXmG2iu/Po5TKwOO28iXX89/CtAe57hrrMAoHDZ8ODEXdjGnZ 9EbP2jN8LyJdgM7RaqgNC1ZW1i6FMaMOkWGyKM69B/LJT1+EjQOInYt1Tw0XpOHZh65t sQ4TuGNaPJEGoXe5o1/1QlgxevE3InbMZir0dByp2f3jGV0/kbNIsQuUd5vXmQXpcy1d eF1U28JGSAAeHvPqc56Ubhr/yUZ26bQLmylI0mBeloyqNJVKe5sUDC27xCE0l6NUv6O8 F1x7uLfFOMjB1wPwy+634TsD0xa3LbVxQZE8r73Sb4YYxeYwGSFeON4yLTUs2mJjmkmp +UZQ== X-Gm-Message-State: AOJu0YzVlVHviPVIBFhrKByGCGKdMb5m1U7qizE7JunqFfjC0H0rfNGW 29T0y1AIPW+IQ2+W9VvZELvPJ0jN9oZaNdctiHtQXg== X-Google-Smtp-Source: AGHT+IH4JjXZge2bjG9GrChSLmLSraioo0o2LzX7iYH4INRMntlW8Z72CClC8b0v2zWySJBahWCQQg== X-Received: by 2002:adf:e6cd:0:b0:31f:a4fa:130a with SMTP id y13-20020adfe6cd000000b0031fa4fa130amr7469923wrm.14.1696598405459; Fri, 06 Oct 2023 06:20:05 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:04 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:48 +0100 Message-Id: <20231006132000.23504-9-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 6 13:19:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19111 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 0A4D5C32BB for ; Fri, 6 Oct 2023 13:20:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B126862973; Fri, 6 Oct 2023 15:20:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598409; bh=DjzjUWLUnAHZALJOWBNhMzRGZXmd4bbCcswnCZ87r5o=; 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=WIcT6rDyb6ikhvw8nnjVVCG5LLfiTBd2P0+yJiMncc3uH4uVMpeMB2RmkRQ2nNwCV B9D4U3RSlauQDfIgYV/wWtn/3W7m22M51QoMABDd/2GS3jwYgglnq/PfhJjcL6BJTF qDzr4khE2pcMHJqv/pDm5QCJg/BDNazL8DrYQpyg7tGrrfgosJJ6oWb03NmtHoF2Yd V1hWIMoa5/XWSxV9/6t90vSWhCgwT0hcpgnWst2ZPPVK1fbHBpdZxcDawpAMEjqntd dZjgFrZq3gpBxHP3Wn/gvFPt0Hv6mLXT3L9QMNh3nAwot+SOAD3AKF7rrG8UwP4VaF PCiWdzrTqD28Q== Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D0E0A62976 for ; Fri, 6 Oct 2023 15:20:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="bj35JJUW"; dkim-atps=neutral Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40651a726acso19065715e9.1 for ; Fri, 06 Oct 2023 06:20:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598407; x=1697203207; 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=kL4411ue6KUoItjo2jH8OvVljS7ZlVEJVZMzhhlz4F8=; b=bj35JJUW+s70a078WUeUBaGkx/wnQ8K+sOGl/94WvISsAqg8lBXoX5TyyU2u4lVERz Ivu0uh6sfBz+pZPDhNp2LawNNG/hdvUm6iI3FvjXbSmcLYgn4vOmiEPJcP3OaEGvvYXn u+htU69/sMYVXo1urw2J6glKFenC34f82CzaJH73Q+7QASoiQNnQMFzzvYddmUM4fBVd ngF/fmz+SivuGEQYVUzR+Ygj3ee2hy5eYbc53AscKBmHUHbwYvYqey+ZyFUnfUu8PEqG jSV/1OXFQOwOMaclLlH1tvkNii1rCgE7cPjx080mclC73vM6A3TzcfVR+F2hAZ90++gz GqsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598407; x=1697203207; 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=kL4411ue6KUoItjo2jH8OvVljS7ZlVEJVZMzhhlz4F8=; b=D8Q0Pxx6+v/z4Y5F9W6fu2zuadSK9rI2wdn04y+PG1TZi8LWF9oB8RWjSo3w2BSJyj Adcn6PAyYBjoFdNgBsSiTZii0ORYof0+UrdIEDYmUqtV9XiZZHiALxbLzRQVoVCmoZaV XSz67JBWlBu3E0Bw8Bbm5w1/JxtwdC0zON90eHkGKcwvhssO4rYi2EVabTWulgUTNWlX ltgdgKOpl7lv62Syc/GMURqGPYiQPM0ytOCmG/5fdsgiE9uvwaGCz2nyX4md4Q7CsMNz WKn352v6TH0kmJq1kQDbisEoyPXu6Ym/Xuh5TU0BTIXAKHLYNvNmeuLOCw1PaU0Hv8Vt xB9g== X-Gm-Message-State: AOJu0YykWBH+caHMjQ3oNrsWevm8t08A3tjmp1L8GwHHTnovwqsuGXfn Xt2Q523qw1bpI/KkBD5HuH/nYNYmH7OkBK7Rey8GKA== X-Google-Smtp-Source: AGHT+IEvs6BmJnde4jXeYaD5TrAUd63ci8Vff3DsQGbswiXPEgDUz7BNmTJvEF247jdVW8TmzUPV6g== X-Received: by 2002:adf:a3d6:0:b0:329:6b93:e346 with SMTP id m22-20020adfa3d6000000b003296b93e346mr1078709wrb.11.1696598407236; Fri, 06 Oct 2023 06:20:07 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:06 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:49 +0100 Message-Id: <20231006132000.23504-10-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 6 13:19:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19112 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 B3CC8C32BC for ; Fri, 6 Oct 2023 13:20:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5BB5762984; Fri, 6 Oct 2023 15:20:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598411; bh=0ZtfABh258FbGqVnIeOpFRQbTFa6M03BetqktijCdQc=; 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=xMrgbCYdjp8c/fBVdgjBrSTsTEXmQ1icgW7O2XC/SuVXnjmhYQd/fyZChesIU9tWG wR7CrWDsurhuy40C+Nxhj15LvXHWYqoxZXOZGoj62H2LUdVYcknR2ah4/T1qPS2f6z oDE7JLEgMx7eckCVYstk9W+2oUH1JZAieeWbLG6IddloToe96Qg+Zv4N8d7kkMklHC WzTxzl7KV4xMCa/T79U6IPwxTPsOOQLuSNydA8TW3yUw+bXDy9WSO2RmKwuWVPbO5S 3AANQ1WWIsRdNDsQ3K8mj3M50cBsutuxr2vRw9FAYWiGqR2uMNcj3mphutWVSYK6SI 0nstARljuz7Xw== Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D69A16296F for ; Fri, 6 Oct 2023 15:20:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="OhINF8/D"; dkim-atps=neutral Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-406609df1a6so19907235e9.3 for ; Fri, 06 Oct 2023 06:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598409; x=1697203209; 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=TDelLhgOpWpnzQB5HzYn4kSIXqsCbLcSZC/V78W+NJ0=; b=OhINF8/DVKp4/j2JY7qSC31wvZOEtJbyfahhHuTQKsWWMqwxUVx2XqS9kKZ7XOlCA0 AoyZ8jpukMDo/60MvdGkB9Vp5Lzml5RyKeuWcw2zVAQIxnEFnUJgbt9kEG3DGKqGLNsO gEksUpkWLFO976ZHQlqnpb5uaMyXxsi1bzBLl97F61GixY5ncK4u2cGvHp7mfixJNdTs ZAAdzfNwlccjvoGrGSK8HVmMrC9/FT7fjIJjYD3cGKoX6wTZRL2CTTl6Sjv4mhMtdZtP R26XG7TM6kLXDGKZnlWEh04wZxO7d+vbHKTJ7wL0Xxbe85wMPhUfF4sN6fQu/juQ07/U OXzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598409; x=1697203209; 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=TDelLhgOpWpnzQB5HzYn4kSIXqsCbLcSZC/V78W+NJ0=; b=ve9x28WesbxdhOtQV43AD9lpcDkh1sFRPzvdVp2tMTRNtVtytNIoKESKKw6OK9Jhlv r59W8dd8DETSzoUJfPZJ1ZKsUE6ywhuV252YReQNGmOpx1xbyWH894dPY4vW5E+rHC27 C/SGfXVLIMT613dwjHo9DxD4dd5WzfTUHLZRTF1reXLJ4TWUZ4p9LNjmVl1j6rrEi14N LKXZZvBCYh5ZAV+DFfhcfX/CV74iF6WNih+7s5n5PVQH9+gKzL3hQwL4REL38d0GDr9z E8ujHpAiT5APK1hT5Bn1Wi9iotmmWfV69IySQzgjOMW10TzIzaxkfp/JMXldgQ2YQgTF brWg== X-Gm-Message-State: AOJu0Yz9ugOheLmGIF18U87hgiwOyghcZOzXL0IRqzKQKL/M3Uc+oyOO lCuTVEQGeJm0zMuUhxbaXa4e2KxCR82tI5OFEGXdcQ== X-Google-Smtp-Source: AGHT+IHXAGvX7xx8RyD+227KhqGNxcJ2e2uewsJpXTd7Rt+BGgLy4FMAlbwSEgVQuaN24KUAAtLpUQ== X-Received: by 2002:a05:600c:21d0:b0:405:3a3b:2aa2 with SMTP id x16-20020a05600c21d000b004053a3b2aa2mr7312275wmj.37.1696598408181; Fri, 06 Oct 2023 06:20:08 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:07 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:50 +0100 Message-Id: <20231006132000.23504-11-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 6 13:19:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19113 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 5C5EFC32B6 for ; Fri, 6 Oct 2023 13:20:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DB23262976; Fri, 6 Oct 2023 15:20:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598413; 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=GAd+q10Kul7j5I82kXpkiOcLCDUo+5lOTU+DZhhv1fCxNRdZyLqPySSlgeKYVY8hk MkfowTKmZDh7xwtiWwbgAqmdOzqhW0rGUfsmRVQ4RrhMiTN5Gu0R9HbEEeu/s6prZZ tyaXuZ56dtktuLThdpC7Mq9bsQxM2gSH4cmQBDqPH0jYTP9tQ299Ye/fxULimL7O5s sC9ZuTL4gOIsI8bSvr90UqOiqVKJd4BzSi9onsMPB2slTx4ds/B9S979nz9AX9B8dM OOBHcXLhFuN8d2+cQ1aEoK9ZB4UwgcrTOX0n1SBuREhD//j9fE/DM31QPb2d5QhxWz g1rhO7J55VjzA== 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 3797262970 for ; Fri, 6 Oct 2023 15:20:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="B1Yd6/u6"; dkim-atps=neutral Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-406609df1a6so19907575e9.3 for ; Fri, 06 Oct 2023 06:20:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598411; x=1697203211; 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=B1Yd6/u6pIqJvT4usCYEc+pFGWV7ktyPiU/ewh7speCnAPryWU1kCULpPYfIaLv7E1 4+P+sfbSXC1B8edr2lQ3/XrGSgNd94sgAF4x3WEZKANaiDxwqifs68lXpD+MBQLYk6hK X7XBqeLzyNJAL1zmkmM5wqYm3sNfHi56OMNN4393q3Yzt5lxP41R/5l2fl5Yl1vfcOWr zl1yGq+WHLBZq/UJwpJymNLNQzz/rfp2OjcH28FBPuZfF5ZB0KcxHqjP2EdSNtL/58ht UoaEbWoTabSmtPci5DdMhtSkHNUfMpIXoHoeOKIos1I9OYJOLruB9ARscLruLuUahSEq n4Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598411; x=1697203211; 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=Xi9Rig2IoULYcnfr49F9Iz+qRJg8f+2Yp/40IA1fexOMagTHYtuMdJ5gzc6+kL6puu 0bmin6kvHg0ektsVROPTH6K5fvR3XEE7nbFhOtoQaZTPeaVxZvJe5vfRO5SQszTZvJGe j8aBz1DfmBRI0XEB34Cejo3RQuQ37JS3sUfvwPZopMYxImmsYdhORl6W3cYDpFJz0jes 3lKarmgjrOQ6Y8dme2YAj4fSYq6hlqpB/rLURtyHYfb2fx2CUM8pRB0HDc2PX3S5f1xJ ThoZeAmbSH/mQUOACZrlXEfGkmtn2BtlIyZH5l1M1mXAJQyiQma8BtX+Rbl3dp7Ea0Ib zWTg== X-Gm-Message-State: AOJu0YxDaWO741T/3KeycR0rlWbyr/wtsPgacb9PtFFoDvJROyf3EJ9a 9cwOwRwbini5CdoNZ4frlnVy6mKyj0ZMkf8Zlrf0aw== X-Google-Smtp-Source: AGHT+IHe3T1B85IMv7V7UNbA5ZsHNg4nzoHAlXXTuU0e7mJ3LQoAsu6m2LfZXQuRjyIRsDov86Ji8g== X-Received: by 2002:a05:600c:164a:b0:402:ea83:45cf with SMTP id o10-20020a05600c164a00b00402ea8345cfmr7977569wmn.2.1696598410281; Fri, 06 Oct 2023 06:20:10 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:09 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:51 +0100 Message-Id: <20231006132000.23504-12-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 6 13:19:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19114 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 C6D0AC32BD for ; Fri, 6 Oct 2023 13:20:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 59C126298B; Fri, 6 Oct 2023 15:20:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598414; bh=id5qaN0AlQ0dZvG0XNQj6kDyQVGgWcUJ0yI/mdjCs2A=; 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=eBzxkSNNIcrk6JFN3CdgaW5N9qLn0g5Ys/lkgZLqajIae9AHKa1el8wlNmhJF+QTl yktXAyj+qqybzd68Cj3J1UvZ5N5iflfeGXsGoApmCl03hu8ZwVufeJ70sCY9HiaVEU ZPPo6i9u9MXDO6xcI787UqHuMgs3EDfhrdXIIgMiVNBgJyR95ncLn/xyJdqWoXdb/l uPjI/XBAiHa2uA1JPkWjLZ0RNJQf6RI3sXqOYgiL+v6NeIhcKU3GqpftM9zJEU/Xdq yDoatWrLiXtJ1UES3kVpNbl9RZECFGrOuCo+/imWizIbo1eWP6+157U60ZKOhZHB3S 8/PSLlV5xbVYQ== Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 715EE62976 for ; Fri, 6 Oct 2023 15:20:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="N95pZuTd"; dkim-atps=neutral Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3247cefa13aso1927495f8f.1 for ; Fri, 06 Oct 2023 06:20:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598412; x=1697203212; 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=tBYDcv/H5q0eN5pmy8TnArjyUVyQOyyVCfr4S8C4GtY=; b=N95pZuTd09whPZ+jOg5Sm/w7tOe22MVNJ5onx5XU+vReErmiMYRjWDUGiD/5vRKDTX 2auhTZT6QJZUVDOQKX7PcYIj22PKprlqcVSZx7cGM7pQEtSr1KDunmrVNmo6RMuvXCik 33zdhTIv7QllZ978DAQ+V+eR5jMHMMg7K4JdUAEH6Crf1B92vDVASermY9EWokFYuft1 1aGN5O+djh0rn8HQP6uQY4lTKxAo/9ciuMwooAB1M25GVlOSTRtYxlUdO55lzjm59Jut F78IEvJ0lNvC1g0oW1ikn8d6nOSRVQhhSSg9QswUdq9vCe5Yrw+wJ1QankZY0QiHa8ct QLCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598412; x=1697203212; 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=tBYDcv/H5q0eN5pmy8TnArjyUVyQOyyVCfr4S8C4GtY=; b=B2B2HFIP6i3RyMc/FBZvPLfTLWp2sIJq1qNo32tYqQHhVah1KFWR/r8o2KiAZKshgv U/mjs2PRyHIgoFcfFq1g1c8X6tKuDvfqhz4Cl9oyitKdqzbAsrXT1gCQbWNnFQi1hyHF uq7iaQhjkuv7uEGaUzo4nRKrDMNQm0h9cU6ZwUr2eRUdegDKUL5uD1xlfP2UgH79I9rh 4Pn6Wga2X8AHL82U5U9+WSYQsvKw1MazXjEMPHT8FXJlYIM7xdyyhahBVdPA7Nu+cRHJ UK+SmddyYG/ieQLVqCr78FlxQf09UFIYCDuDWCM3EDEvN1QD0OBK+L2AuaQn8/mvjHQk YVSg== X-Gm-Message-State: AOJu0YzVgFOKLbA6wPGPgqam7GMW4/xGlslSGXX0hB/tnxrhOY2SJCYs C4orWVI0n4hwZ8g6i8cvrU1EalvLHWnD5fUFMUKkyA== X-Google-Smtp-Source: AGHT+IHcZw9MlEC43NBmgnItQ2wOyGmdoFLGb2xHhk52tTtMlYO/bDi2b3SSQeSrbCKZg4MmohToRQ== X-Received: by 2002:a5d:6b82:0:b0:319:5677:f832 with SMTP id n2-20020a5d6b82000000b003195677f832mr6828786wrx.62.1696598411882; Fri, 06 Oct 2023 06:20:11 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:11 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:52 +0100 Message-Id: <20231006132000.23504-13-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 fd6f2efc6e27..25e6a4383bf6 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 6 13:19:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19115 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 7E8AFC32B7 for ; Fri, 6 Oct 2023 13:20:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1211862991; Fri, 6 Oct 2023 15:20:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598417; bh=pkyf9QZ03S+r76EzK4eUM9gZP+AGWiIsUDgMjJi2Gp8=; 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=YXokXVGgGa+7syzBGkpN0NcsfNQiZvtr7gW0F44mPjUT5Eg0MgNeTnLIN+0TugvCW W3JRyS4WklaP8+loJzccDhLt/7jAETiOrB7uqArcNAiR2Y7iYHqCCafsqfYzZX0LwL s/nzMR2cdoM+d6KlJSBiGZ0OZho3WkDRUlm6Hay9Y33P5FobqfhQiQ3WfCJC92/Qgr 1E4ReBgKcRv1RKiA2FmfKpq81r2bMfoR47JKJgmXmVAulUa3kPXcn7uuRAq+6PgSvh Ahq3yuDxY9lLOxW8+J621cD7wHbYQFP1QDt+FGR5hccJvmIrzJ+JDCJzOT34bxlCPE StKj88RPNzocg== 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 9FC8F62970 for ; Fri, 6 Oct 2023 15:20:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="e8nP080N"; dkim-atps=neutral Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-405505b07dfso19729895e9.0 for ; Fri, 06 Oct 2023 06:20:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598413; x=1697203213; 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=6yici5UMvvwYWxOu71VoDQY6+Vl9nnQ+jk7k7pxhCEs=; b=e8nP080Nj63Vgi2oEn8WaSCmnOQJdLqltvujUcYEZe7BcqmRKqLx9h/SVe7pxkbWDb vttNnhaPyi2LdM497xkUnGqIErsojL9z2waSySl+wrKGkqZDHaez6ZAm3RYFBMKwfiIl k9bre5XW83WuW1wImcmcNh2sALEIqqDRWl//vC40pkgPDHqcTMsLuHfc77qOy7wgv2MZ T0af5CrzFd2v0kb+zHLLd0NAYBmOkHqyZsXj7ZqhS0G277JlbpNArzeCzHwb+fCMPDrM flaHRICbdU/Hxqc4lhoqZmwcZLcfap7XrNPYL1cK7ZQi1ViPhAt06aQKHrBj+PkyJ7N9 q/eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598413; x=1697203213; 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=6yici5UMvvwYWxOu71VoDQY6+Vl9nnQ+jk7k7pxhCEs=; b=UojDQF3Ri/kruS6WirY8qfDRrrapZke+cD8W1JPBGhjCS0ynO4wO4odtqyT+qV3mE+ 3yIRHEzrWr+26YGSSVOPgp2buvphgweWw4VDW040wQ4QLU0/s1QiXn5a6gCatqLDfKqM 7pnh+h2qoaO5QSLaOp1RGt2kEAmKZII50e72Wl5mWFJX99qjq61t9X5Ocl5gOuCRSv1t UsdRdImnmLFIbQ1PxHK0gtzV4PuI3JAtIKevp76Hfq17d4d5zJR2qb+xpMq5s1id7h7x f1AeGa2ykAn5DvS9AMmp+OL3w43Bbd7g4CYuJxoO4ju4c2YOpglBjlqy4OS7ONjL02tV sgRw== X-Gm-Message-State: AOJu0Yw40fM2nCViOw0DfGxaq3sfyC+A6+H31lGJn9/IGFdlZHdriu4l L7gRva7p+tzsuD1yJ530NQtAXBbVkYsojrjD9WtK3A== X-Google-Smtp-Source: AGHT+IHC+1xE9nXQCA0MH9oeoprxCLiGDMpuTwuDRyjEnnIqcGktT+SwUzGR9B2JNkFFFOxmLBhg+w== X-Received: by 2002:a5d:6b92:0:b0:31f:e02b:18ae with SMTP id n18-20020a5d6b92000000b0031fe02b18aemr4330483wrx.24.1696598412976; Fri, 06 Oct 2023 06:20:12 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:12 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:53 +0100 Message-Id: <20231006132000.23504-14-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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. Fixes: 312e9910ba2e ("meson: ipa: Add mapping for pipeline handler to mojom interface file") Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- 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 6 13:19:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19116 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 EF964C32BE for ; Fri, 6 Oct 2023 13:20:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A20C762975; Fri, 6 Oct 2023 15:20:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598417; bh=lxLUS7Hgi9jrttTfv8CuhWjCTyChmx++p2Hrtu/i7/Y=; 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=M7ldXRcZJPHdQ4ArIFdrrlgDz0dcSyMb1YQXhwlr00o0pcgjbbYmOqjYYVbb7A7ap 5Gv1kdpBD0OaCpMGPCNw/YiWDdXsZSlENwnr9iw1V/PeHWKWjUc3Zo71t7OdNac9jY GTjjSawUNnAuFdfvYq/+gUrDA+6hoKqA+go1oxKBJeop5Z+HEyMmTHyR3/rAE1F/92 TXB9vkdTw0+D6D7EMg5FMkYCZKiYH5Up+rFcZ8gSvGUwNHDMDOG3OB6f46Dhpg0eBo 0cIeUvaBpEhuFMrANuT2SVIMYgjM2CUtBXqwp1rSQi8MBeQVsMH1Owhb0GiAty3Qcq y8xzGzG0Tbe6A== Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 963E06298D for ; Fri, 6 Oct 2023 15:20:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="OiJXJ0hQ"; dkim-atps=neutral Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4060b623e64so13372705e9.0 for ; Fri, 06 Oct 2023 06:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598414; x=1697203214; 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=3Ioik+ycSDe1X4mbw6aoWVc5szejZU03FQI4ZHIzFI0=; b=OiJXJ0hQETSJxjIeDd7uTs/ZZLnnHXp3ZM1KxphUGjfp0MmvDFjKWvjoRyiKFfylxI eYW5EfFNc/mSx/Q0XkbxZQPPfmh4ZukSAuPjni6o7W4qNdT2HLu6F+QNr2HPHFlm200P xfAMBeZ1xy9rXxrS4x7uiKhnrR+IulNUhdkzxC8x21XF1L/zNm/TOy6TQDbN/TSHCDzT P4NCLK4DU549nluBZRZ1LzZ/5LEXp20V/WS9j99IUdxMq5ROXA2kavrx0RFoGKLpN0xS OHD4VnD4NlOxhpXi6ExyCohOID0U6hyuDzEmX75oVVX2LeVaLwBWrDNvD3PsKsjB6sI8 yQig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598414; x=1697203214; 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=3Ioik+ycSDe1X4mbw6aoWVc5szejZU03FQI4ZHIzFI0=; b=VwdqgE2EvlDuGq1wjF2cnoOoH3xWSC3ZLoPcJVQIMtg/lhYVm4H9nF9/iiXmBNikKj ExvNYIBxaP2Wdcd+2eNXig0+UZ0yGwdQnz+B4nBRkVIYq412RxNKIpqglvz8yqYE/naD zeIY1G7AlZfk51/3/JPKAWunkjRcGi+oyEosluXwQzfa09TV+50tT5fS62dopr3PKB8u cmNqVgqI2GffUSd8aJ7M1hLhUdbjZOt9UHfJAmTfhmtQkhiNwlk5CGfJlrZ1qbCruLLZ 8YoJYuFiLs489C7eQ396drT5ZhR+BngLMilMnauM8lb86BE4t2ydYJwilqmvplLUP90r DAXA== X-Gm-Message-State: AOJu0YwgepLJ/NrDGVyRnN+lOfKrVnF0shvFx55++zf0cdxR68pSFwXm Q+w13PEbH1yhR4Jxz/YBBoTr4OOCwumpgu/xwUJ8+Q== X-Google-Smtp-Source: AGHT+IEg2UTu8a7DdvyOJHd9irFWvSlNl3yK9NzyshQi95RiTq1HbOy4psOP7HgJm6T7GZ3IwtDSFA== X-Received: by 2002:a05:600c:3c94:b0:400:5962:6aa9 with SMTP id bg20-20020a05600c3c9400b0040059626aa9mr3873979wmb.11.1696598413951; Fri, 06 Oct 2023 06:20:13 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:13 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:54 +0100 Message-Id: <20231006132000.23504-15-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 entirely into 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 | 14 -------------- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 12 ++++++++++-- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 825eae80d014..7437d38dc9ba 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -242,20 +242,6 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() if (ret) return Invalid; - /* - * Some sensors change their Bayer order when they are h-flipped - * or v-flipped, according to the transform. If this one does, we - * must advertise the transformed Bayer order in the raw stream. - * 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_); - } - raw.cfg->pixelFormat = bayer.toPixelFormat(); - 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..4b42ddc71115 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -411,9 +411,17 @@ CameraConfiguration::Status Vc4CameraData::platformValidate(RPi::RPiCameraConfig 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_) + /* + * Some sensors change their Bayer order when they are h-flipped + * or v-flipped, according to the transform. If this one does, we + * must advertise the transformed Bayer order in the raw stream. + * Note how we must fetch the "native" (i.e. untransformed) Bayer + * order, because the sensor may currently be flipped! + */ + if (flipsAlterBayerOrder_) { + rawBayer.order = nativeBayerOrder_; rawBayer = rawBayer.transform(rpiConfig->combinedTransform_); + } /* Apply the user requested packing. */ rawBayer.packing = BayerFormat::fromPixelFormat(rawStream->pixelFormat).packing; From patchwork Fri Oct 6 13:19:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19117 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 B9820BD808 for ; Fri, 6 Oct 2023 13:20:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 50ECA62997; Fri, 6 Oct 2023 15:20:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598419; bh=ufz7tg/n9JeM7qTjoqdk7XlHaX5amgtAEu+hsGROEf4=; 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=E2jWKws+Egav48eQfXOttbFgUJhWzEwE+4XBFHZ/YZnSnV7WBfW7JrUvSer0kvO4/ be0iRhuQtxUGl7T73Y8XhaWcFP/aGPBTpLVcqO1I36oXolpSzHckztqMOEWm4TotdC qSILc2UNR75k4WCKAgLVVn4hoH8F8aXzEM2BXUMCw/bgNRMUIZOyHvWevp97wKXIKR fUXY7nVGwZDctTJr8sI5kMLGjEX5y7oZKWXDLRGcg5pJuGo+uNx/N5CFCH+VZr7ZqD vILll/nDcAoF20q72zwmJoHOiAqjc38oMZlB4oAI2g2dHhlL/eCx4Wcf+OKscI3B3v 9QBCa1iRDTneg== Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 73CE562989 for ; Fri, 6 Oct 2023 15:20:15 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="dVQFKBat"; dkim-atps=neutral Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-31c5cac3ae2so1847337f8f.3 for ; Fri, 06 Oct 2023 06:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598415; x=1697203215; 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=pU4wKiWXwkZLedJeP1sGrANY/IM78qE81hjwahnBKxk=; b=dVQFKBatAx/hO+HZKyKulIEAvjHr3eDtghLmaLDG/F7UcgTF+HZbabT/VGPySsSP3o JJfQbLUbML4pcHpNpPGjsR79BUGZS+V9vBdCik8VgVipdeiCd/BjlTE4IV+VzM2EfiZO TewcK3m0M8Rteh5qGKlvlY65SAvBR2uxlgK7SBfrZdYdiopkuLwybzGncceu0ScXWkzJ yyhtRAOuq37dm//rsOcdJE9WEQAGHqshktrIu+L3nkMqHJ45i8XShEzgiSymCP9bqK3k 3IVfh2o7yIjvQ9zPGWz8rWR8WJA2zpPMOS2DKteU7q7/fini5UV6rBW3R28NMG+dPjjz NDjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598415; x=1697203215; 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=pU4wKiWXwkZLedJeP1sGrANY/IM78qE81hjwahnBKxk=; b=oBAKdSkQ0Os1m5RF+PMDMNR3ear7qcHhCPVykZweRPQvUTWl4JyZylS+eJSwFxHNFK Lg2WyyoFQBeKibrjwCGBjrOx5q9JdOA0vAcu23oY06SnET3d+/Seo2pPX7nv2482iwrz ZYll3unY/rEp2GNNX8TUdHClRqEmu3CEgq9wGNi4JMf0S0Pd5Ex/h/xlb0oWL91TLnce vJMX7D4Cqk91qpxZ2m5QhlsSluXJ7YN7WD1UI47PEu0A9MidUOiE/n4QGq822sK9QqcW psYRFv+htQNvjUJmbvNSeBJ1jbEm8uFiurZLJPHNVB6pnix1Bm390VFmGPl3Bn87lDf8 rdIg== X-Gm-Message-State: AOJu0Yytxxl4W5UiLx7TJgPtOMdtBh4+AmCRHk4wylc4HK85pXj96nIu eRNS0IX54pC88jmw5PQEZXnDVnPNZaunFVYjmPKFRw== X-Google-Smtp-Source: AGHT+IELOZBlh6BkKnhguxX/9rBs1BOwik8ixz0LziSf2Gr2jtQshxLM23evJ36P9I3mwGQEtwM9Ww== X-Received: by 2002:adf:f24f:0:b0:319:63f3:c0cb with SMTP id b15-20020adff24f000000b0031963f3c0cbmr7179221wrp.40.1696598414829; Fri, 06 Oct 2023 06:20:14 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:14 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:55 +0100 Message-Id: <20231006132000.23504-16-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 6 13:19:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19118 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 558BDC32BF for ; Fri, 6 Oct 2023 13:20:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1ACCC62983; Fri, 6 Oct 2023 15:20:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598420; bh=T75VGxIX4RUkLNCWmNWdLZdY1W9EPwWSCDSbp+dxzaw=; 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=HPmSjMyBRZXzXUy8dqjmkDfRvlSM7xjlhqK1+tBzylIQn9OXBBAQ7r65y3/YZ5Jn5 1IYzWHMNMM5WSnb0wc6wn46DZuf1wj+zQlwY8Z4TrEIRxE0Z97E8A1AqEHP9KDXc2C GQ9u6Mqz1LhYwWz/aKD9Aeuo6f7cCFnLvzqdySfh1PZ5efofuJS8DorFVXy8PJuPpZ 7X9f/Tz1mAaKmk4nf7KY2GFBh9o3CGhodiX/KATvUePKTg9+p0sMjV8Iqszzisef4p tPWeX1nOgNXVSPxUa2BI/BS1Hv72+3/yfKrCqpWY/NmfuGxrwvpSQhC/r47NOTZ9nR QbtwHqRD6UyIQ== 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 9A81062970 for ; Fri, 6 Oct 2023 15:20:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="OifkYwNy"; dkim-atps=neutral Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40684f53d11so20303525e9.1 for ; Fri, 06 Oct 2023 06:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598416; x=1697203216; 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=dQ0brK8cAfxANWWPLZx06cfd1rpKrCG3c+CPadf4YdI=; b=OifkYwNyjECuE60AztcWThHmjz+V3ifrlIqD5kQI6lCJFCdbDGEzyPkLd2hAxsXNJy Jxw8goGAVGRt37vdsEfPKPJlAOFd99Hgp3xFfasOrPSWUB/2PPEZFuFoCOwJZ32p9Sqs MQdtKRh0xL1SmVK4pSnVWjWv8yeJsNcL/CxzVHQwVpycPgZvGbK/DePFBr8m9zgXwSb6 38FAGBEwRJPITq32dEPUEymjWblFd32QYxww/C1d8LXT0xYlcziLvkvgNarB3Y078uqD Va9aShcCbEJDerACiWGYOiQDBOELyIUbnaLvdbovOg3+HVZPpWY3QKMCAEGFXEIEJ/kZ vxhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598416; x=1697203216; 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=dQ0brK8cAfxANWWPLZx06cfd1rpKrCG3c+CPadf4YdI=; b=lZRPSwtyo8NUWgjz0iiqSeTQMJC6zByXw2dVMVH6DC2F6+raBQQ32W+6H/qgWWlu21 1VSXp9ATWJSqaM4tNPOnLVbjjfzbGx97OLczYWcmaSLiWTa8dv48HmNamJwiAqBKzUIK jWJ32ToqlWSOpv6mxcEaWiYIsKP9V8GuU3GEyUQ6TWyOErNPpXTr6BVzpRZXkW4SpfcY MmVDh3o9k3h025GgnbpeuISOJOSsPdKzwRzeAsrabVfJ01WZViuEFFhSpq0IVSG0GCub SLbNW5H4lkR6nhT0CqnZT2joJTVp/wtNFQwM6emceIovGGdyG1+M/q5kONpHF3m8Wa+y BAHQ== X-Gm-Message-State: AOJu0YztaXpBXq8Dn+AR+YTOw0Ca95rlnw/i+51WWt1VuFFONg/ruJWe R0IiMaTVQE+VfVaZ2O98vIOcZii6sRU/h8F9Barzng== X-Google-Smtp-Source: AGHT+IGqQFf3Tzc64RqzgKNq6cCY2m8e+AZMv+S9v6qv7mAqp7FPBKphAx0/JEpGfIvcEOa+XqlrOw== X-Received: by 2002:a5d:484a:0:b0:31f:fe07:fdde with SMTP id n10-20020a5d484a000000b0031ffe07fddemr7895228wrs.12.1696598415999; Fri, 06 Oct 2023 06:20:15 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:15 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:56 +0100 Message-Id: <20231006132000.23504-17-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 6 13:19:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19119 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 D8305C32C0 for ; Fri, 6 Oct 2023 13:20:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9E6F062994; Fri, 6 Oct 2023 15:20:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598420; bh=Vco4sOLhS+b8qbdF80LzDvfty2cxrcwq99X42VGxOE0=; 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=abAfZhUJxO6C3WfQKbBYk/XZ5cU39Ws2ZR+Y9CVYo8npoPM/TVsMnYBUYL26hYbrU BtWbUntgp5CRFGTZaCCaSs56KBCzC5mS6TMUcpY1gG+lvz2LowDHTwY/6caiZYsvxC c7kXjQ33UFTGRNXYMHYaVIJgWtnEW3U/3GZTAnD3aqMXrbN13RQCRn6JYLhVJBcBR3 95HLNi7GWrkX//RtLJZ671lvGOYnLVWYpeqpjLFgx11hbI3UKbFYdb/XP69RLFvIwP 0nr2yv56S0tPMLs1g1EbenWQJirzgwTXkvFME5h/Yx09LAD/JZlj2OA6u+VaDyFyT2 tXrpq+w9HHDVQ== Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 941BA6298A for ; Fri, 6 Oct 2023 15:20:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="rdlX829k"; dkim-atps=neutral Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-32157c8e4c7so2047865f8f.1 for ; Fri, 06 Oct 2023 06:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598417; x=1697203217; 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=GJZWIHSvD4qhUhRVpGxrtaU/At69rVVeRUf6Y6dNodU=; b=rdlX829kPcBQKVVmxNdCSloTET14aGe77VD9/TkW5I6CnFjNXcriAG3tOwGjcMuBwC wOXsQkuKaIuecPmbz2cy8jcrm05EEOI3D4F8QVdpR7TbmhCwz9tsLyE7SNPyNJDZYxH7 tiqkBeN26fRWTeouq4lPAz510HEaomYx+F0ppzM6HhiviiLApDk0rJf3I2xYBjN/xR/v o6nFwkKg83Ll7z/VJzIL9bBKzQkPq8GQCqFb7dn+MF7iS7m37NyU2KWXQB7G/l32O0tf MYfaWVP+3R/lemh89ABAdszoHruVkZMxRl5wPAztQ240Xilqf3JJX4f4ipS63eL9QNz6 A0Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598417; x=1697203217; 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=GJZWIHSvD4qhUhRVpGxrtaU/At69rVVeRUf6Y6dNodU=; b=JURVQz+07G4jSnGcROmtSgw+9R+ZgkcLjCWivxOvrNXLOfNCrrJ5pkKx77+yGjUZdc /hINJXQxvOHrjoqpZq+mLGhJ44Rfe1J84nlhGH7zooNxD7DUgH4jAOEAvAQYyUgFl7BR stoL24Ckmav+6FwzqDnr2CnVzQRsYG1IxzCqq0mI35WzfYom8TudyWzfNYrdEDpnkpp8 R7GwwfXm673uP4OdIGEHwkDRTCmQDnJo/hLrPamMDuRVav/0Zkj3pwWt+9hgyZWCZt7k lJ9ZCP/BpBdRGSYrJT7E7tcdr2NdHqQFD2d9K8X/Cjx1/oVze+6Ep+4kIcGzclrVXsfb e81g== X-Gm-Message-State: AOJu0Ywu0fFLjTkGITgeYzh+LcXVjks9wX6tA/bIgK6g8Mhobb3GdqG3 nrR1gj3bv5l6h3R5KHcJOh5tONUjbl7EW6oIYoX3HQ== X-Google-Smtp-Source: AGHT+IHuVD8O8dg/2yTcHuH6ma3WVIm+YILPJwsPqhbZV81f1nMWbYi/ggRJxuRUd17w9BezZsSgLA== X-Received: by 2002:a05:6000:1112:b0:321:6005:8979 with SMTP id z18-20020a056000111200b0032160058979mr7240126wrw.17.1696598416905; Fri, 06 Oct 2023 06:20:16 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:16 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:57 +0100 Message-Id: <20231006132000.23504-18-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 6 13:19:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19120 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 7A9A9C32B8 for ; Fri, 6 Oct 2023 13:20:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 29D0D6299D; Fri, 6 Oct 2023 15:20:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598422; 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=OheVbbnQhV909xeZYScJu3PdmJmGN2UkFfieFuWmJ6j69fhPoIVcg8DYqDbv+4MYi n2Xddv4OcKZyPlt+NfPJHVpfdUZ+fhfQeDEzT8WpU4GZLzxCT2hwGKfZF9Fj0vRCGy s/R2OHIntWYnk1e859i727LwqOWhG7VGbONMEpnadNLgOYiWGmosuHIqUUvllYCK/U PK27xGqXRLS4eXLWcfvAHXAMy0Zc3iA5gplmSVRz2Q7FEa21G97JQDqFynLaw/gJbw qME+Xn9VOKSbHVDOrOcrH95X+SeA3CQx7BBaTSSJL2A7cS0UGGu12x0UPOsS5HWAh3 Y5vlQj5zSJnsQ== Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CA3F062969 for ; Fri, 6 Oct 2023 15:20:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="iCtnyEPI"; dkim-atps=neutral Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-323168869daso2030826f8f.2 for ; Fri, 06 Oct 2023 06:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598419; x=1697203219; 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=iCtnyEPIQaalWY3Afe+ZANs0wdG84IoXA+zUeOeJvzpdnvxvYYid5vO70yHTHIW/K5 esLfZWzUZGB1Jhsp7awVlPjPy2ZIIIrj9pZXpWnmg2OJftFBcnQv4Ix3p4nY11Kp0F2f b7sPeKfjUYRuXWPVcLZ9g7BzZruOmkjBKkmoCWHR4a+OY+B7rir3l/y8/U8ijBZ3LX+p qH5ktKapWx0LqD4fVLE7rpCzuX99jT9KfoYzXsVVUAW7Yqmc2T7yZk8GniM4/4Ss/LVD xYm6rbYa3hwzJe3a55s+fodxGAt7RPCauOAq9zH3uFH4IfTBsmzUPcfZjkejUsEm0yuZ qEFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598419; x=1697203219; 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=kOQjQHzqs34yP+CWlTb1AAnZPBXZpOLR2OyM9qtYcmNvylSr94mTI6wJLebJAq1QSM DAikd7aVgyj9ae+xy0+mSrD1M8vf5q+s0fIWnvn3svu5av8Lom8FsflYefLaqF+7GQIt KzSdQQ0dcd95DoXgCjhsiU8yHYFObgdqPYPO1IaxJxLXLolsHREkqCBi74DlS00ouM3H /JtesU71FbMQHco3KeopJp/SSsSzNHBObw/bsVQPhfoY/g2I3sZuJuFIRNWW2nA5n/Cm giHR8cEB2MkFx3qn+8R49hS5Uos3XWN9qLqwg3WgLWdvSlJ7YWuH8BcagUxm+sAwQHKd +TXQ== X-Gm-Message-State: AOJu0YyW8yGweS31Ib6/Q1IlpCYnI0bfa0gqoBNnldYetvOH4eRxXeji Fxu4diuDxgZdSGLFxX0dDxjTDPMmk5G7CoAzitwitQ== X-Google-Smtp-Source: AGHT+IEm07U4M6JT1Lv5TjDlWESahv+CwGDiy8JItGud+sA1r9f4Uu904VCmA8xoJRA133r35fCEQA== X-Received: by 2002:a5d:4a0b:0:b0:31a:b3aa:d19b with SMTP id m11-20020a5d4a0b000000b0031ab3aad19bmr7065204wrq.23.1696598417872; Fri, 06 Oct 2023 06:20:17 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:17 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:58 +0100 Message-Id: <20231006132000.23504-19-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 6 13:19:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19121 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 2E29DC32C1 for ; Fri, 6 Oct 2023 13:20:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C66B462963; Fri, 6 Oct 2023 15:20:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598422; bh=g0p94eYnymjkLMt3XLjiCvHtkzKp0QFmMWMNtcKxvcE=; 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=a+3ZaSRPeUjXY1/dQdYhQlW+xxFAJgfkwd7qQv14AzcNc4uiaCBJdN0+0T3vHr0eh DqjWNtelc0azi7o2oRuQr1bUOAVWXSpPGrbiPonNtP6qpwLn6p197GR1pFA2Z/qAJi fPlLLM0vdQBtxuSYjHnvoMr/pVduV0m5FGPoGK9i0rb48CVzWBJ0iclUo2V0Fpdnm5 VyIv/SPDhZ/Ilw49Fvi6hPyETPSRtU/Nh0xv9UR3SVKGEHelglb7qOvo/11jzOs4NL tAGHP766M69n68JW7R3ORHJ12FWw/0i6VyxeskkooRtF4ITEY2aREz4mpg8R7FiVUO RHVn1zSfB6Q4g== Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4AFF462969 for ; Fri, 6 Oct 2023 15:20:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="pFKtpafj"; dkim-atps=neutral Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-317c3ac7339so1867532f8f.0 for ; Fri, 06 Oct 2023 06:20:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598420; x=1697203220; 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=wX6bWO/uDRnRFXGdanoRa7WRWmc0W9jFOPexu58lLy8=; b=pFKtpafjJk40xxqt/ku+pBgfeLO1yepcJx8E1yKjI+0GcBIiy3nGTgXzLovMJlrVSX an+/H8lq87lqcHYdTvk3ZAL5Ug9r7HjaYES4zExsLY+eICcVAf87sU3to1vqrSVuUe3G hxbqN05mUpNUx5/MILder6V34r2g2wGglAJAYskd0qS/XV6thrECFY/LKuezcxttTMPm PZ/8iL2F77TUejACYTusVcVBkXNOtLStOZXfvqF1WHLToVQn4k7JjLQ/1zr6Lxerz0Nb bw4rMwEX4ExQvJI66Vs/Tj/pjrFCBTO2/LQ3H05qWOpIiOjeE0kImuEabtZrBGOpETJ3 JnvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598420; x=1697203220; 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=wX6bWO/uDRnRFXGdanoRa7WRWmc0W9jFOPexu58lLy8=; b=g4Nc3lgig7HTBfolxiCedVUejFV4WAcsRfOpDNw7NiZ0wmBWRFYV5luK7cdC7eCv7x RHz8SEeqhNs5J2UwhJtNv1psL6Wm4sC+nHauW8IylrByzIuNPT9Ck8Dwpgh7hq93XGTE QB0Va+UHbzaiwxysr6iL+38ju/o6V+HNjRKcm/UHb7I3//mwIQ7WTosjsHVf6oE3ZJyv frS4iS2ueyG4JbmI4CLTzuERDOjPNF85bFLjsDpv0EkKPSdCq++H7tD3EN7kIfuDFMGP ZI0TzqDLRZ8t5kvhfMEy8jo/FSWYtyhBsQHCoTxwb5uD7KHNiFvBaMjtEyTW4/TpRnI5 IIeg== X-Gm-Message-State: AOJu0Yx5ie10kFwNtfEc3uXj3F4s22Cn2XGe3sEMSc2u0sKmjPIb3pPq 7un5lMEfRdybz4+wmQCj1z+gS0zPzOS3ZStH3TJd6A== X-Google-Smtp-Source: AGHT+IGEIspYzvmqFi9ifORU42ujjKZ1tTt6JZfU+irJoH6zVUcR2cQ1eCJcx+10aJubiwhEpdNu8A== X-Received: by 2002:adf:e8ca:0:b0:31f:e1b4:583d with SMTP id k10-20020adfe8ca000000b0031fe1b4583dmr8183927wrn.56.1696598420605; Fri, 06 Oct 2023 06:20:20 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:19 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:19:59 +0100 Message-Id: <20231006132000.23504-20-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 6 13:20:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19122 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 02E54C32B9 for ; Fri, 6 Oct 2023 13:20:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ACF356296F; Fri, 6 Oct 2023 15:20:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1696598425; bh=Uzn4lVqtWjaQ8Sb+MKfJXTauUyz0RMz4BqtMjjUX6gM=; 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=E0iYA+UCNG2136+oodcOeSYQsF0o5PMKI3ofiaMv4uPwUtWq/IgIfnJqzXMSYsSXD hYiraZbzNuJGU5kzyAe7W6SBLvrfvC9JpWtI+VagX0Cq7ahrpTg3Ka1M6tdZhle7tx uNYLHeYOAnUEithQMq8RlIzPuoGQ2QwtYcGsCkwnTsFoET/neNMB+ezXzCZ3lwRR3t qWmRmEKYLoxzINsYhQMJDzkTl3qNhz0MRQ/DA6LgptOeqJRHZD7wuRo/70urd6YwTP vLSlC0WcsDG8Wg1TBQksxpCw2nfOEVPUSOuX0CoqKkJ0ypLIhVZaycygREwBZZy/Fe FfwHWJM2hOMJw== 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 2484F62973 for ; Fri, 6 Oct 2023 15:20:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="aXyMqC8J"; dkim-atps=neutral Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-31c5cac3ae2so1847429f8f.3 for ; Fri, 06 Oct 2023 06:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1696598421; x=1697203221; 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=yNBJCUYXo4LXGeLxzlT54YfPdDc3yVuc6878WBeD0Qg=; b=aXyMqC8J/zprDNboWHe/ciNCqDlkePwYoyVNTKnnfHZWIGYmpto5T85es4+Cl/xyns qG4Ggc3ndjwOsQezfyuLRCS5lgQ6OOtceo6ccptoZulWgNlJXduv5F+fAiPtCcHOXioV PFfksuLJ+ts0lndAL8Z3eoqWukZH6oLX1MqsAI5caziCp5Jyr97HEWv6EiOnkGpZGpZ7 Mpb0DIuE8vKm73VsmDvsi6K+76gRgcuiocDzk0aUBxMQf2Vk5EI+rVXVvydNcCe1F1bc pC9xST22M2EwrHbd4dKepBVqVcAMZHUN4j8qU7XFafgdc8FHKmKBoI0ZCvv+JYxg3YW9 4uIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696598421; x=1697203221; 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=yNBJCUYXo4LXGeLxzlT54YfPdDc3yVuc6878WBeD0Qg=; b=k+WG7P1hGpAbq4B6pR3r9dRtg6iDyxa1Wt+zPV5fdSmYdtGZRsRMuf/+Y4zhZCDmd8 JtJvL1VLAwss1bCozkQeDWRc7c2JbC/GoVHUgi8Hnmi7WyvZ36Q+7p7OFVcIRo3feaMf +3dPWOC9Ge2svBB0OnXugHiVDRadfqje+xGA7TUQmDSpdq6BrvBp2zQSObwAWhI1z2da jj/28KkyKerJM24Viy7amIVWPdiQTX0dMSwnCkT5pyfg9vz3PzbIuiRNuoWHZ7U49FIA pOBmpXgpIAVDB7PJ7pHQHzPqY90H0AdY0EFeOwU2E/G56Qkgv02dFox/fIjvNc6aH1JO Se6A== X-Gm-Message-State: AOJu0Yy2FhxNUG3rGffnmOKoh1lctT2Ux9RUrm5GDcFOgizd/KzrR+fR LO5WNtGasN1+l7wVVNfJ+OKePPs3ImVDh+4As7y4Sw== X-Google-Smtp-Source: AGHT+IFWQRFoPZfSp8ts4n3vBTyMEci6mfCzM0Xvt07F4BAVxC31jWyFItfxmXrEAtA1Hu5YJ3UWsg== X-Received: by 2002:adf:f4c6:0:b0:320:5ad:2b9c with SMTP id h6-20020adff4c6000000b0032005ad2b9cmr7330590wrp.2.1696598421523; Fri, 06 Oct 2023 06:20:21 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id m8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:20:20 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Oct 2023 14:20:00 +0100 Message-Id: <20231006132000.23504-21-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006132000.23504-1-naush@raspberrypi.com> References: <20231006132000.23504-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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,