From patchwork Thu Dec 14 12:13:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 19322 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 1777ABD87C for ; Thu, 14 Dec 2023 12:14:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C59FB62B60; Thu, 14 Dec 2023 13:14:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1702556050; bh=LhipIp4GtupJ6IaZ4rU1hdfOM4k+B4tp1rNOs3vZZhM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=X+PK7G6ejJzjWapZ9vXWaVYpXWCPpwdoIkkipHzSzcbBHyzBRzL6VStJYixi1g4Ra AtsYkSS/A+ZKxhCBlp3UNKIPxgbIJVXFy5BFfQsbElzVu8nC2KCmXYlmMTwuJGYtSc aOVtShLA944qyHzSlTRJ6WgaMtpPw3wiQqq8BGS5XXikl8ep2ZAqsy2FNw+dQkL9go Io9gYhfUG1bsy/hwD0FMBLDHsM+Gxjx45hyrD6UH8bwZihCI8lQ0JmYFAVf3X2LH4M KM72jvlG+B6t7QVJlVWsT4vpjCwLhAr+/y2yp1/9iCJsrFJlVRyYmfHl/NNR5aWHa0 KoJ8p2D3yixkQ== Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9495862B5C for ; Thu, 14 Dec 2023 13:14:07 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="MiqDOFlK"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702556046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tdIzGLQxhxYICZ6OdjRLAGlPb0lmvJYHuBZDXsIFGfs=; b=MiqDOFlK8hYw42doQy/SeEYGJFTb8cytEFspUufA5en9Het49HNR5O6izPOJcPnzKVkHPe Mm1DEpfAy/BrwweIeKCyNymzx5muhHGV9je6FZRaLBN0vAOQ3MshlU/Kn3PsPheUzKCYXh lE+dQSaRNRJcJ463Q3oS9UcNZPpyO4Q= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-625-TclWStvuNSSePfAJU6mq_g-1; Thu, 14 Dec 2023 07:14:00 -0500 X-MC-Unique: TclWStvuNSSePfAJU6mq_g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D530185A588; Thu, 14 Dec 2023 12:13:59 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8ED601121306; Thu, 14 Dec 2023 12:13:58 +0000 (UTC) To: libcamera-devel@lists.libcamera.org, Andrey Konovalov Date: Thu, 14 Dec 2023 13:13:43 +0100 Message-ID: <20231214121350.206015-6-hdegoede@redhat.com> In-Reply-To: <20231214121350.206015-1-hdegoede@redhat.com> References: <20231214121350.206015-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [libcamera-devel] [PATCH 05/11] libcamera: software_isp: Add Debayer base 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: Hans de Goede via libcamera-devel From: Hans de Goede Reply-To: Hans de Goede Cc: Maxime Ripard , g.martti@gmail.com, t.langendam@gmail.com, srinivas.kandagatla@linaro.org, Bryan O'Donoghue , admin@dennisbonke.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a base class for debayer implementations. This is intended to be suitable for both GPU (or otherwise) accelerated debayer implementations as well as CPU based debayering. Co-authored-by: Andrey Konovalov Signed-off-by: Andrey Konovalov Signed-off-by: Hans de Goede --- .../libcamera/internal/software_isp/debayer.h | 90 +++++++++++++++++++ .../internal/software_isp/debayer_params.h | 24 +++++ .../internal/software_isp/meson.build | 2 + src/libcamera/software_isp/debayer.cpp | 22 +++++ src/libcamera/software_isp/meson.build | 1 + 5 files changed, 139 insertions(+) create mode 100644 include/libcamera/internal/software_isp/debayer.h create mode 100644 include/libcamera/internal/software_isp/debayer_params.h create mode 100644 src/libcamera/software_isp/debayer.cpp diff --git a/include/libcamera/internal/software_isp/debayer.h b/include/libcamera/internal/software_isp/debayer.h new file mode 100644 index 00000000..206bc2ac --- /dev/null +++ b/include/libcamera/internal/software_isp/debayer.h @@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023, Linaro Ltd + * Copyright (C) 2023, Red Hat Inc. + * + * Authors: + * Hans de Goede + * + * debayer.h - debayering base class + */ + +#pragma once + +#include + +#include +#include + +#include +#include + +#include "libcamera/internal/software_isp/debayer_params.h" + +namespace libcamera { + +class FrameBuffer; + +LOG_DECLARE_CATEGORY(Debayer) + +class Debayer +{ +public: + virtual ~Debayer() = 0; + + /* + * Setup the Debayer object according to the passed in parameters. + * Return 0 on success, a negative errno value on failure + * (unsupported parameters). + */ + virtual int configure(const StreamConfiguration &inputCfg, + const std::vector> &outputCfgs) = 0; + + /* + * Get width and height at which the bayer-pattern repeats. + * Return pattern-size or an empty Size for an unsupported inputFormat. + */ + virtual Size patternSize(PixelFormat inputFormat) = 0; + + virtual std::vector formats(PixelFormat inputFormat) = 0; + virtual std::tuple + strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) = 0; + + /* + * Note DebayerParams is passed by value deliberately so that a copy is passed + * when this is run in another thread to invokeMethod. + */ + virtual void process(FrameBuffer *input, FrameBuffer *output, DebayerParams params) = 0; + + /* sizes() - Get supported output sizes for given input fmt + size */ + SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) + { + Size pattern_size = patternSize(inputFormat); + + if (pattern_size.isNull()) + return {}; + + /* + * For debayer interpolation a border of pattern-height x pattern-width + * is kept around the entire image. Combined with a minimum-size of + * pattern-height x pattern-width this means the input-size needs to be + * at least (3 * pattern-height) x (3 * pattern-width). + */ + if (inputSize.width < (3 * pattern_size.width) || + inputSize.height < (3 * pattern_size.height)) { + LOG(Debayer, Warning) + << "Input format size too small: " << inputSize.toString(); + return {}; + } + + return SizeRange(Size(pattern_size.width, pattern_size.height), + Size((inputSize.width - 2 * pattern_size.width) & ~(pattern_size.width - 1), + (inputSize.height - 2 * pattern_size.height) & ~(pattern_size.height - 1)), + pattern_size.width, pattern_size.height); + } + + Signal inputBufferReady; + Signal outputBufferReady; +}; + +} /* namespace libcamera */ diff --git a/include/libcamera/internal/software_isp/debayer_params.h b/include/libcamera/internal/software_isp/debayer_params.h new file mode 100644 index 00000000..885d3605 --- /dev/null +++ b/include/libcamera/internal/software_isp/debayer_params.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023, Red Hat Inc. + * + * Authors: + * Hans de Goede + * + * swstats.h - software statistics base class + */ + +#pragma once + +namespace libcamera { + +struct DebayerParams { + /* Red Gain, 128 = 0.5, 256 = 1.0, 512 = 2.0, etc. */ + unsigned int gainR; + /* Blue Gain, same range as Red Gain. */ + unsigned int gainB; + /* Gamma correction, 1.0 is no correction. */ + float gamma; +}; + +} /* namespace libcamera */ diff --git a/include/libcamera/internal/software_isp/meson.build b/include/libcamera/internal/software_isp/meson.build index 1d9e4018..7e40925e 100644 --- a/include/libcamera/internal/software_isp/meson.build +++ b/include/libcamera/internal/software_isp/meson.build @@ -1,6 +1,8 @@ # SPDX-License-Identifier: CC0-1.0 libcamera_internal_headers += files([ + 'debayer.h', + 'debayer_params.h', 'swisp_stats.h', 'swstats.h', 'swstats_cpu.h', diff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/debayer.cpp new file mode 100644 index 00000000..442da1ac --- /dev/null +++ b/src/libcamera/software_isp/debayer.cpp @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023, Linaro Ltd + * Copyright (C) 2023, Red Hat Inc. + * + * Authors: + * Hans de Goede + * + * debayer.cpp - debayer base class + */ + +#include "libcamera/internal/software_isp/debayer.h" + +namespace libcamera { + +LOG_DEFINE_CATEGORY(Debayer) + +Debayer::~Debayer() +{ +} + +} /* namespace libcamera */ diff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build index d31c6217..d4ae5ac7 100644 --- a/src/libcamera/software_isp/meson.build +++ b/src/libcamera/software_isp/meson.build @@ -1,6 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 libcamera_sources += files([ + 'debayer.cpp', 'swstats.cpp', 'swstats_cpu.cpp', ])