{"id":20883,"url":"https://patchwork.libcamera.org/api/1.1/patches/20883/?format=json","web_url":"https://patchwork.libcamera.org/patch/20883/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20240812115009.946036-10-mzamazal@redhat.com>","date":"2024-08-12T11:49:58","name":"[09/16] libcamera: software_isp: Avoid copying particular color tables","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"e77531929453952fd93f78013e76987963ebcc50","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/1.1/people/177/?format=json","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/20883/mbox/","series":[{"id":4511,"url":"https://patchwork.libcamera.org/api/1.1/series/4511/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4511","date":"2024-08-12T11:49:49","name":"Software ISP: Share params and stats buffers","version":1,"mbox":"https://patchwork.libcamera.org/series/4511/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/20883/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/20883/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 3844CC323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 12 Aug 2024 11:50:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D562B633D3;\n\tMon, 12 Aug 2024 13:50:43 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2FA9F633CC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2024 13:50:36 +0200 (CEST)","from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-616-Lo5Ug71uOtyF-Wrxvk8EEg-1;\n\tMon, 12 Aug 2024 07:50:34 -0400","from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.15])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS\n\tid 786141954211 for <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2024 11:50:33 +0000 (UTC)","from nuthatch.redhat.com (unknown [10.45.225.57])\n\tby mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 600E019772C4; Mon, 12 Aug 2024 11:50:32 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"axPFnCBr\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1723463435;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=LGTinOMIdh/wLBfcPnfMvqOVU/mkZ44ix0MPiPqx12o=;\n\tb=axPFnCBr4DuxGAi3CA/TeuBfIxXTKBwKDjDFu40dw8XE54dd8x42vFZGs9rpYbVjEsm686\n\tFhlInMqYoEDmznBzrjeeuJtRN+0/FBEXziF2DYCYmnIK8BrPqtNPI+ee6LRYcySxSAPNox\n\tCybxaxz2p1QGEv7la83g/f1IKulTE/w=","X-MC-Unique":"Lo5Ug71uOtyF-Wrxvk8EEg-1","From":"Milan Zamazal <mzamazal@redhat.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Milan Zamazal <mzamazal@redhat.com>","Subject":"[PATCH 09/16] libcamera: software_isp: Avoid copying particular\n\tcolor tables","Date":"Mon, 12 Aug 2024 13:49:58 +0200","Message-ID":"<20240812115009.946036-10-mzamazal@redhat.com>","In-Reply-To":"<20240812115009.946036-1-mzamazal@redhat.com>","References":"<20240812115009.946036-1-mzamazal@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.0 on 10.30.177.15","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Transfer-Encoding":"8bit","Content-Type":"text/plain; charset=\"US-ASCII\"; x-default=true","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The color lookup tables in software CPU debayering are currently copied\nfrom the provided parameters.  The preceding work avoided copying the\nparameters when passed to debayering, this patch avoids the copying\ninside debayering.\n\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n src/libcamera/software_isp/debayer_cpu.cpp | 60 +++++++++++-----------\n src/libcamera/software_isp/debayer_cpu.h   |  7 +--\n 2 files changed, 34 insertions(+), 33 deletions(-)","diff":"diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex af08ab10..d3831474 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -51,7 +51,8 @@ DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats,\n \n \t/* Initialize color lookup tables */\n \tfor (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++)\n-\t\tred_[i] = green_[i] = blue_[i] = i;\n+\t\tinitColorLookupTable_[i] = i;\n+\tred_ = green_ = blue_ = &initColorLookupTable_;\n \n \tparamsBuffers_ = std::map<unsigned int, DebayerParams *>();\n \n@@ -80,12 +81,12 @@ DebayerCpu::~DebayerCpu() = default;\n  * GBG\n  * RGR\n  */\n-#define BGGR_BGR888(p, n, div)                                                                \\\n-\t*dst++ = blue_[curr[x] / (div)];                                                      \\\n-\t*dst++ = green_[(prev[x] + curr[x - p] + curr[x + n] + next[x]) / (4 * (div))];       \\\n-\t*dst++ = red_[(prev[x - p] + prev[x + n] + next[x - p] + next[x + n]) / (4 * (div))]; \\\n-\tif constexpr (addAlphaByte)                                                           \\\n-\t\t*dst++ = 255;                                                                 \\\n+#define BGGR_BGR888(p, n, div)                                                                   \\\n+\t*dst++ = (*blue_)[curr[x] / (div)];                                                      \\\n+\t*dst++ = (*green_)[(prev[x] + curr[x - p] + curr[x + n] + next[x]) / (4 * (div))];       \\\n+\t*dst++ = (*red_)[(prev[x - p] + prev[x + n] + next[x - p] + next[x + n]) / (4 * (div))]; \\\n+\tif constexpr (addAlphaByte)                                                              \\\n+\t\t*dst++ = 255;                                                                    \\\n \tx++;\n \n /*\n@@ -93,12 +94,12 @@ DebayerCpu::~DebayerCpu() = default;\n  * RGR\n  * GBG\n  */\n-#define GRBG_BGR888(p, n, div)                                    \\\n-\t*dst++ = blue_[(prev[x] + next[x]) / (2 * (div))];        \\\n-\t*dst++ = green_[curr[x] / (div)];                         \\\n-\t*dst++ = red_[(curr[x - p] + curr[x + n]) / (2 * (div))]; \\\n-\tif constexpr (addAlphaByte)                               \\\n-\t\t*dst++ = 255;                                     \\\n+#define GRBG_BGR888(p, n, div)                                       \\\n+\t*dst++ = (*blue_)[(prev[x] + next[x]) / (2 * (div))];        \\\n+\t*dst++ = (*green_)[curr[x] / (div)];                         \\\n+\t*dst++ = (*red_)[(curr[x - p] + curr[x + n]) / (2 * (div))]; \\\n+\tif constexpr (addAlphaByte)                                  \\\n+\t\t*dst++ = 255;                                        \\\n \tx++;\n \n /*\n@@ -106,12 +107,12 @@ DebayerCpu::~DebayerCpu() = default;\n  * BGB\n  * GRG\n  */\n-#define GBRG_BGR888(p, n, div)                                     \\\n-\t*dst++ = blue_[(curr[x - p] + curr[x + n]) / (2 * (div))]; \\\n-\t*dst++ = green_[curr[x] / (div)];                          \\\n-\t*dst++ = red_[(prev[x] + next[x]) / (2 * (div))];          \\\n-\tif constexpr (addAlphaByte)                                \\\n-\t\t*dst++ = 255;                                      \\\n+#define GBRG_BGR888(p, n, div)                                        \\\n+\t*dst++ = (*blue_)[(curr[x - p] + curr[x + n]) / (2 * (div))]; \\\n+\t*dst++ = (*green_)[curr[x] / (div)];                          \\\n+\t*dst++ = (*red_)[(prev[x] + next[x]) / (2 * (div))];          \\\n+\tif constexpr (addAlphaByte)                                   \\\n+\t\t*dst++ = 255;                                         \\\n \tx++;\n \n /*\n@@ -119,12 +120,12 @@ DebayerCpu::~DebayerCpu() = default;\n  * GRG\n  * BGB\n  */\n-#define RGGB_BGR888(p, n, div)                                                                 \\\n-\t*dst++ = blue_[(prev[x - p] + prev[x + n] + next[x - p] + next[x + n]) / (4 * (div))]; \\\n-\t*dst++ = green_[(prev[x] + curr[x - p] + curr[x + n] + next[x]) / (4 * (div))];        \\\n-\t*dst++ = red_[curr[x] / (div)];                                                        \\\n-\tif constexpr (addAlphaByte)                                                            \\\n-\t\t*dst++ = 255;                                                                  \\\n+#define RGGB_BGR888(p, n, div)                                                                    \\\n+\t*dst++ = (*blue_)[(prev[x - p] + prev[x + n] + next[x - p] + next[x + n]) / (4 * (div))]; \\\n+\t*dst++ = (*green_)[(prev[x] + curr[x - p] + curr[x + n] + next[x]) / (4 * (div))];        \\\n+\t*dst++ = (*red_)[curr[x] / (div)];                                                        \\\n+\tif constexpr (addAlphaByte)                                                               \\\n+\t\t*dst++ = 255;                                                                     \\\n \tx++;\n \n template<bool addAlphaByte>\n@@ -752,12 +753,10 @@ void DebayerCpu::process(uint32_t frame,\n \t}\n \n \tDebayerParams *params = paramsBuffers_.at(paramsBufferId);\n-\treleaseIspParams.emit(paramsBufferId);\n \n-\t/* \\todo Avoid copying here. */\n-\tgreen_ = params->green;\n-\tred_ = swapRedBlueGains_ ? params->blue : params->red;\n-\tblue_ = swapRedBlueGains_ ? params->red : params->blue;\n+\tgreen_ = &params->green;\n+\tred_ = swapRedBlueGains_ ? &params->blue : &params->red;\n+\tblue_ = swapRedBlueGains_ ? &params->red : &params->blue;\n \n \t/* Copy metadata from the input buffer */\n \tFrameMetadata &metadata = output->_d()->metadata();\n@@ -779,6 +778,7 @@ void DebayerCpu::process(uint32_t frame,\n \t\tprocess2(in.planes()[0].data(), out.planes()[0].data());\n \telse\n \t\tprocess4(in.planes()[0].data(), out.planes()[0].data());\n+\treleaseIspParams.emit(paramsBufferId);\n \n \tmetadata.planes()[0].bytesused = out.planes()[0].size();\n \ndiff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h\nindex 324fc6c0..f25520be 100644\n--- a/src/libcamera/software_isp/debayer_cpu.h\n+++ b/src/libcamera/software_isp/debayer_cpu.h\n@@ -139,9 +139,10 @@ private:\n \t/* Max. supported Bayer pattern height is 4, debayering this requires 5 lines */\n \tstatic constexpr unsigned int kMaxLineBuffers = 5;\n \n-\tDebayerParams::ColorLookupTable red_;\n-\tDebayerParams::ColorLookupTable green_;\n-\tDebayerParams::ColorLookupTable blue_;\n+\tDebayerParams::ColorLookupTable initColorLookupTable_;\n+\tDebayerParams::ColorLookupTable *red_;\n+\tDebayerParams::ColorLookupTable *green_;\n+\tDebayerParams::ColorLookupTable *blue_;\n \tdebayerFn debayer0_;\n \tdebayerFn debayer1_;\n \tdebayerFn debayer2_;\n","prefixes":["09/16"]}