From patchwork Mon Aug 12 11:49:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 20883 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 3844CC323E for ; Mon, 12 Aug 2024 11:50:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D562B633D3; Mon, 12 Aug 2024 13:50:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="axPFnCBr"; dkim-atps=neutral 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 2FA9F633CC for ; Mon, 12 Aug 2024 13:50:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723463435; 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=LGTinOMIdh/wLBfcPnfMvqOVU/mkZ44ix0MPiPqx12o=; b=axPFnCBr4DuxGAi3CA/TeuBfIxXTKBwKDjDFu40dw8XE54dd8x42vFZGs9rpYbVjEsm686 FhlInMqYoEDmznBzrjeeuJtRN+0/FBEXziF2DYCYmnIK8BrPqtNPI+ee6LRYcySxSAPNox Cybxaxz2p1QGEv7la83g/f1IKulTE/w= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-616-Lo5Ug71uOtyF-Wrxvk8EEg-1; Mon, 12 Aug 2024 07:50:34 -0400 X-MC-Unique: Lo5Ug71uOtyF-Wrxvk8EEg-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 786141954211 for ; Mon, 12 Aug 2024 11:50:33 +0000 (UTC) Received: from nuthatch.redhat.com (unknown [10.45.225.57]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 600E019772C4; Mon, 12 Aug 2024 11:50:32 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [PATCH 09/16] libcamera: software_isp: Avoid copying particular color 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 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 in software CPU debayering are currently copied from the provided parameters. The preceding work avoided copying the parameters when passed to debayering, this patch avoids the copying inside debayering. Signed-off-by: Milan Zamazal --- src/libcamera/software_isp/debayer_cpu.cpp | 60 +++++++++++----------- src/libcamera/software_isp/debayer_cpu.h | 7 +-- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index af08ab10..d3831474 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -51,7 +51,8 @@ DebayerCpu::DebayerCpu(std::unique_ptr stats, /* Initialize color lookup tables */ for (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) - red_[i] = green_[i] = blue_[i] = i; + initColorLookupTable_[i] = i; + red_ = green_ = blue_ = &initColorLookupTable_; paramsBuffers_ = std::map(); @@ -80,12 +81,12 @@ DebayerCpu::~DebayerCpu() = default; * GBG * RGR */ -#define BGGR_BGR888(p, n, div) \ - *dst++ = blue_[curr[x] / (div)]; \ - *dst++ = green_[(prev[x] + curr[x - p] + curr[x + n] + next[x]) / (4 * (div))]; \ - *dst++ = red_[(prev[x - p] + prev[x + n] + next[x - p] + next[x + n]) / (4 * (div))]; \ - if constexpr (addAlphaByte) \ - *dst++ = 255; \ +#define BGGR_BGR888(p, n, div) \ + *dst++ = (*blue_)[curr[x] / (div)]; \ + *dst++ = (*green_)[(prev[x] + curr[x - p] + curr[x + n] + next[x]) / (4 * (div))]; \ + *dst++ = (*red_)[(prev[x - p] + prev[x + n] + next[x - p] + next[x + n]) / (4 * (div))]; \ + if constexpr (addAlphaByte) \ + *dst++ = 255; \ x++; /* @@ -93,12 +94,12 @@ DebayerCpu::~DebayerCpu() = default; * RGR * GBG */ -#define GRBG_BGR888(p, n, div) \ - *dst++ = blue_[(prev[x] + next[x]) / (2 * (div))]; \ - *dst++ = green_[curr[x] / (div)]; \ - *dst++ = red_[(curr[x - p] + curr[x + n]) / (2 * (div))]; \ - if constexpr (addAlphaByte) \ - *dst++ = 255; \ +#define GRBG_BGR888(p, n, div) \ + *dst++ = (*blue_)[(prev[x] + next[x]) / (2 * (div))]; \ + *dst++ = (*green_)[curr[x] / (div)]; \ + *dst++ = (*red_)[(curr[x - p] + curr[x + n]) / (2 * (div))]; \ + if constexpr (addAlphaByte) \ + *dst++ = 255; \ x++; /* @@ -106,12 +107,12 @@ DebayerCpu::~DebayerCpu() = default; * BGB * GRG */ -#define GBRG_BGR888(p, n, div) \ - *dst++ = blue_[(curr[x - p] + curr[x + n]) / (2 * (div))]; \ - *dst++ = green_[curr[x] / (div)]; \ - *dst++ = red_[(prev[x] + next[x]) / (2 * (div))]; \ - if constexpr (addAlphaByte) \ - *dst++ = 255; \ +#define GBRG_BGR888(p, n, div) \ + *dst++ = (*blue_)[(curr[x - p] + curr[x + n]) / (2 * (div))]; \ + *dst++ = (*green_)[curr[x] / (div)]; \ + *dst++ = (*red_)[(prev[x] + next[x]) / (2 * (div))]; \ + if constexpr (addAlphaByte) \ + *dst++ = 255; \ x++; /* @@ -119,12 +120,12 @@ DebayerCpu::~DebayerCpu() = default; * GRG * BGB */ -#define RGGB_BGR888(p, n, div) \ - *dst++ = blue_[(prev[x - p] + prev[x + n] + next[x - p] + next[x + n]) / (4 * (div))]; \ - *dst++ = green_[(prev[x] + curr[x - p] + curr[x + n] + next[x]) / (4 * (div))]; \ - *dst++ = red_[curr[x] / (div)]; \ - if constexpr (addAlphaByte) \ - *dst++ = 255; \ +#define RGGB_BGR888(p, n, div) \ + *dst++ = (*blue_)[(prev[x - p] + prev[x + n] + next[x - p] + next[x + n]) / (4 * (div))]; \ + *dst++ = (*green_)[(prev[x] + curr[x - p] + curr[x + n] + next[x]) / (4 * (div))]; \ + *dst++ = (*red_)[curr[x] / (div)]; \ + if constexpr (addAlphaByte) \ + *dst++ = 255; \ x++; template @@ -752,12 +753,10 @@ void DebayerCpu::process(uint32_t frame, } DebayerParams *params = paramsBuffers_.at(paramsBufferId); - releaseIspParams.emit(paramsBufferId); - /* \todo Avoid copying here. */ - green_ = params->green; - red_ = swapRedBlueGains_ ? params->blue : params->red; - blue_ = swapRedBlueGains_ ? params->red : params->blue; + green_ = ¶ms->green; + red_ = swapRedBlueGains_ ? ¶ms->blue : ¶ms->red; + blue_ = swapRedBlueGains_ ? ¶ms->red : ¶ms->blue; /* Copy metadata from the input buffer */ FrameMetadata &metadata = output->_d()->metadata(); @@ -779,6 +778,7 @@ void DebayerCpu::process(uint32_t frame, process2(in.planes()[0].data(), out.planes()[0].data()); else process4(in.planes()[0].data(), out.planes()[0].data()); + releaseIspParams.emit(paramsBufferId); metadata.planes()[0].bytesused = out.planes()[0].size(); diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h index 324fc6c0..f25520be 100644 --- a/src/libcamera/software_isp/debayer_cpu.h +++ b/src/libcamera/software_isp/debayer_cpu.h @@ -139,9 +139,10 @@ 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_; + DebayerParams::ColorLookupTable initColorLookupTable_; + DebayerParams::ColorLookupTable *red_; + DebayerParams::ColorLookupTable *green_; + DebayerParams::ColorLookupTable *blue_; debayerFn debayer0_; debayerFn debayer1_; debayerFn debayer2_;