From patchwork Thu May 23 11:26:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 20095 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 E464EBD87C for ; Thu, 23 May 2024 11:27:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 85CC8634A5; Thu, 23 May 2024 13:27:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="IjewvqLn"; dkim-atps=neutral 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 297BF634A6 for ; Thu, 23 May 2024 13:27:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716463651; 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=skUQ1Y2KuLbcKlSWlti06cq5C2+zC5GBBds10V4jwd0=; b=IjewvqLnOJXiWmOKmGtyj+RM2iaQj9oM40QnaOcF2ilt7o3UoTR+VqrA+WoX2d9wVcgbIp 2vobuilc8lgOLa492Nh8se/ksMLyVVu/cdd1mKLmu9m1KzrTxnMqxKUekafywoQ8hD++5m tu+/4Q8EdwKKa0pbPsAlLESM8G0l47U= 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-453-MN-a_gWBP_iz2VCa9EKkMw-1; Thu, 23 May 2024 07:27:27 -0400 X-MC-Unique: MN-a_gWBP_iz2VCa9EKkMw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 37B393C025A1; Thu, 23 May 2024 11:27:27 +0000 (UTC) Received: from nuthatch.redhat.com (unknown [10.45.226.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED9C22026D68; Thu, 23 May 2024 11:27:25 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Andrei Konovalov , Laurent Pinchart Subject: [PATCH v3 5/5] libcamera: software_isp: Pass color lookup tables as floats Date: Thu, 23 May 2024 13:26:56 +0200 Message-ID: <20240523112656.559150-6-mzamazal@redhat.com> In-Reply-To: <20240523112656.559150-1-mzamazal@redhat.com> References: <20240523112656.559150-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The color lookup tables are passed from stats processing to debayering for direct use as 8-bit color output values. Let's pass the values as 0.0..1.0 floats to make the gains color bit width independent. Completes software ISP TODO #4. Signed-off-by: Milan Zamazal Reviewed-by: Andrei Konovalov --- .../internal/software_isp/debayer_params.h | 2 +- src/ipa/simple/soft_simple.cpp | 4 ++-- src/libcamera/software_isp/TODO | 13 ------------- src/libcamera/software_isp/debayer.cpp | 6 +++--- src/libcamera/software_isp/debayer_cpu.cpp | 18 +++++++++++++++--- src/libcamera/software_isp/debayer_cpu.h | 10 +++++++--- 6 files changed, 28 insertions(+), 25 deletions(-) diff --git a/include/libcamera/internal/software_isp/debayer_params.h b/include/libcamera/internal/software_isp/debayer_params.h index 7d8fdd48..af959e1a 100644 --- a/include/libcamera/internal/software_isp/debayer_params.h +++ b/include/libcamera/internal/software_isp/debayer_params.h @@ -18,7 +18,7 @@ namespace libcamera { struct DebayerParams { static constexpr unsigned int kRGBLookupSize = 256; - using ColorLookupTable = std::array; + using ColorLookupTable = std::array; ColorLookupTable red; ColorLookupTable green; diff --git a/src/ipa/simple/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp index cd89e673..11678393 100644 --- a/src/ipa/simple/soft_simple.cpp +++ b/src/ipa/simple/soft_simple.cpp @@ -86,7 +86,7 @@ private: BlackLevel blackLevel_; static constexpr unsigned int kGammaLookupSize = 1024; - std::array gammaTable_; + std::array gammaTable_; int lastBlackLevel_ = -1; int32_t exposureMin_, exposureMax_; @@ -283,7 +283,7 @@ void IPASoftSimple::processStats(const ControlList &sensorControls) std::fill(gammaTable_.begin(), gammaTable_.begin() + blackIndex, 0); const float divisor = kGammaLookupSize - blackIndex - 1.0; for (unsigned int i = blackIndex; i < kGammaLookupSize; i++) - gammaTable_[i] = UINT8_MAX * powf((i - blackIndex) / divisor, gamma); + gammaTable_[i] = powf((i - blackIndex) / divisor, gamma); lastBlackLevel_ = blackLevel; } diff --git a/src/libcamera/software_isp/TODO b/src/libcamera/software_isp/TODO index 4fcee39b..6bdc5905 100644 --- a/src/libcamera/software_isp/TODO +++ b/src/libcamera/software_isp/TODO @@ -72,19 +72,6 @@ stats in hardware, such as the i.MX7), but please keep it on your radar. --- -4. Hide internal representation of gains from callers - -> struct DebayerParams { -> static constexpr unsigned int kGain10 = 256; - -Forcing the caller to deal with the internal representation of gains -isn't nice, especially given that it precludes implementing gains of -different precisions in different backend. Wouldn't it be better to pass -the values as floating point numbers, and convert them to the internal -representation in the implementation of process() before using them ? - ---- - 5. Store ISP parameters in per-frame buffers > /** diff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/debayer.cpp index f4a299d5..1c93ac44 100644 --- a/src/libcamera/software_isp/debayer.cpp +++ b/src/libcamera/software_isp/debayer.cpp @@ -30,17 +30,17 @@ namespace libcamera { /** * \var DebayerParams::red - * \brief Lookup table for red color, mapping input values to output values + * \brief Lookup table for red color, mapping input values to 0.0..1.0 */ /** * \var DebayerParams::green - * \brief Lookup table for green color, mapping input values to output values + * \brief Lookup table for green color, mapping input values to 0.0..1.0 */ /** * \var DebayerParams::blue - * \brief Lookup table for blue color, mapping input values to output values + * \brief Lookup table for blue color, mapping input values to 0.0..1.0 */ /** diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index f3099a62..e71b5057 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -11,6 +11,8 @@ #include "debayer_cpu.h" +#include +#include #include #include @@ -688,6 +690,14 @@ static inline int64_t timeDiff(timespec &after, timespec &before) (int64_t)after.tv_nsec - (int64_t)before.tv_nsec; } +void DebayerCpu::updateColorLookupTable( + const DebayerParams::ColorLookupTable &src, + ColorLookupTable &dst) +{ + for (std::size_t i = 0; i < src.size(); i++) + dst[i] = src[i] * UINT8_MAX; +} + void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams params) { timespec frameStartTime; @@ -697,9 +707,11 @@ void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime); } - green_ = params.green; - red_ = swapRedBlueGains_ ? params.blue : params.red; - blue_ = swapRedBlueGains_ ? params.red : params.blue; + updateColorLookupTable(params.green, green_); + updateColorLookupTable(swapRedBlueGains_ ? params.blue : params.red, + red_); + updateColorLookupTable(swapRedBlueGains_ ? params.red : params.blue, + blue_); /* Copy metadata from the input buffer */ FrameMetadata &metadata = output->_d()->metadata(); diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h index 768a4643..ed1003a9 100644 --- a/src/libcamera/software_isp/debayer_cpu.h +++ b/src/libcamera/software_isp/debayer_cpu.h @@ -18,6 +18,7 @@ #include #include "libcamera/internal/bayer_format.h" +#include "libcamera/internal/software_isp/debayer_params.h" #include "debayer.h" #include "swstats_cpu.h" @@ -125,9 +126,12 @@ private: /* Max. supported Bayer pattern height is 4, debayering this requires 5 lines */ static constexpr unsigned int kMaxLineBuffers = 5; - DebayerParams::ColorLookupTable red_; - DebayerParams::ColorLookupTable green_; - DebayerParams::ColorLookupTable blue_; + using ColorLookupTable = std::array; + void updateColorLookupTable(const DebayerParams::ColorLookupTable &src, + ColorLookupTable &dst); + ColorLookupTable red_; + ColorLookupTable green_; + ColorLookupTable blue_; debayerFn debayer0_; debayerFn debayer1_; debayerFn debayer2_;