From patchwork Sat Jan 13 14:22:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 19399 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 D3FB6C328C for ; Sat, 13 Jan 2024 14:22:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 77E16628D7; Sat, 13 Jan 2024 15:22:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1705155774; bh=zxRRfYVp9eJ9KMIXtZ28QZbE2JIMf/QEy1NLeeM2zXg=; 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=jG/yVjOgaoUrNBlaitonEKYDuxWzmoAbg5u9FvcxFjEQ7r03StHg4zN5R4AbMGECu sRQbF1JBdZAtrFpMMS93lWOjKfyJu7yO9PLrcS1/tGBNA5/nJBDsFIBfj9ZlcgnxHn 9zEQ3eecYEXb65SfjCEQ+61Ws0g5ImbC6UAwGnDPxaJY8zTP1k5gXBtryYL7JgODdD tNYRYzeijV0lLYyfzqjJQJcc6NC3aJyTR1j6vboGLDbLTchXZRTqg0bs/sr6cq8NRT OT/hSrq9d3A8FwbQz6WQpZPBPAIEfZJqDSJbeM7K/IBCoCWaSxCtbhNJaq5hGJnvgB fpvvOrhpL6HTw== Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D4E961D57 for ; Sat, 13 Jan 2024 15:22:52 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="CyxNE3KY"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705155771; 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=CB/P6UmIvPqdKb0o8YPwItNIejyIxOOK7VIVMh9mDf4=; b=CyxNE3KYtSISGP2dJVcErw+y8IcJzyi/ypDOK886pOHp5gtiJ7Kc9mwK8s9uGSIFcvTk1L +LXM8FGR+CzPjAGTE2iEt5fAbO3kZP+E3iQ+4OKC6kSBqty1GBPMbsMs7NW0WIQPmlthHg AAC9PYAV9RXUr78kZK9KTpLiKy7LZok= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-266-9a56yyP0MfuUHI76Zb16VQ-1; Sat, 13 Jan 2024 09:22:49 -0500 X-MC-Unique: 9a56yyP0MfuUHI76Zb16VQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 E8C9C3C11C8F; Sat, 13 Jan 2024 14:22:48 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1C503C25; Sat, 13 Jan 2024 14:22:46 +0000 (UTC) To: libcamera-devel@lists.libcamera.org, Andrey Konovalov Date: Sat, 13 Jan 2024 15:22:09 +0100 Message-ID: <20240113142218.28063-10-hdegoede@redhat.com> In-Reply-To: <20240113142218.28063-1-hdegoede@redhat.com> References: <20240113142218.28063-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [libcamera-devel] [PATCH v2 09/18] 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, Pavel Machek , 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. Doxygen documentation by Dennis Bonke. Co-authored-by: Dennis Bonke Signed-off-by: Dennis Bonke Co-authored-by: Andrey Konovalov Signed-off-by: Andrey Konovalov Signed-off-by: Hans de Goede Tested-by: Bryan O'Donoghue # sc8280xp Lenovo x13s Tested-by: Pavel Machek --- .../libcamera/internal/software_isp/debayer.h | 132 ++++++++++++++++++ .../internal/software_isp/debayer_params.h | 43 ++++++ .../internal/software_isp/meson.build | 2 + src/libcamera/software_isp/debayer.cpp | 22 +++ src/libcamera/software_isp/meson.build | 1 + 5 files changed, 200 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..39e6f393 --- /dev/null +++ b/include/libcamera/internal/software_isp/debayer.h @@ -0,0 +1,132 @@ +/* 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 + * \brief Base debayering class + * + * Base class that provides functions for setting up the debayering process. + */ +class Debayer +{ +public: + virtual ~Debayer() = 0; + + /** + * \brief Configure the debayer object according to the passed in parameters. + * \param[in] inputCfg The input configuration. + * \param[in] outputCfgs The output configurations. + * + * \return 0 on success, a negative errno on failure. + */ + virtual int configure(const StreamConfiguration &inputCfg, + const std::vector> &outputCfgs) = 0; + + /** + * \brief Get the width and height at which the bayer pattern repeats. + * \param[in] inputFormat The input format. + * + * \return pattern size or an empty size for unsupported inputFormats. + */ + virtual Size patternSize(PixelFormat inputFormat) = 0; + + /** + * \brief Get the supported output formats. + * \param[in] inputFormat The input format. + * + * \return all supported output formats or an empty vector if there are none. + */ + virtual std::vector formats(PixelFormat inputFormat) = 0; + + /** + * \brief Get the stride and the frame size. + * \param[in] outputFormat The output format. + * \param[in] size The output size. + * + * \return a tuple of the stride and the frame size, or a tuple with 0,0 if there is no valid output config. + */ + virtual std::tuple + strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) = 0; + + /** + * \brief Process the bayer data into the requested format. + * \param[in] input The input buffer. + * \param[in] output The output buffer. + * \param[in] params The parameters to be used in debayering. + * + * \note DebayerParams is passed by value deliberately so that a copy is passed + * when this is run in another thread by invokeMethod(). + */ + virtual void process(FrameBuffer *input, FrameBuffer *output, DebayerParams params) = 0; + + /** + * \brief Get the supported output sizes for the given input format and size. + * \param[in] inputFormat The input format. + * \param[in] inputSize The input size. + * + * \return The valid size ranges or an empty range if there are none. + */ + 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); + } + + /** + * \brief Signals when the input buffer is ready. + */ + Signal inputBufferReady; + + /** + * \brief Signals when the output buffer is ready. + */ + 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..8f515304 --- /dev/null +++ b/include/libcamera/internal/software_isp/debayer_params.h @@ -0,0 +1,43 @@ +/* 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 { + +/** + * \brief Struct to hold the debayer parameters. + */ +struct DebayerParams { + /** + * \brief Red Gain. + * + * 128 = 0.5, 256 = 1.0, 512 = 2.0, etc. + */ + unsigned int gainR; + /** + * \brief Green Gain. + * + * 128 = 0.5, 256 = 1.0, 512 = 2.0, etc. + */ + unsigned int gainG; + /** + * \brief Blue Gain. + * + * 128 = 0.5, 256 = 1.0, 512 = 2.0, etc. + */ + unsigned int gainB; + /** + * \brief 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', ])