From patchwork Sat Jan 13 14:22:16 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: 19406 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 E994EBEFBE for ; Sat, 13 Jan 2024 14:23:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8E07662949; Sat, 13 Jan 2024 15:23:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1705155792; bh=hsBYVdTBrAZWsxlE2UOT1Y8nzt9N04UWvFwDF/G04sU=; 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=QE77ijKTTPmgAnLKlrDHnzMCZUNHAVmGBwGlGgF8MFDPaMMETZHo2HwrttBO2OQaQ VLoDve78ZvwT6pmMBYGx+/2VGCpjaNBekgL/RWRfZW/eVH/6xmbp7UhsA6mbM7ee8R zXkJ03uBvl8pwVCnKOaSwfeHB/QYqGfuAfswNxf3KdSWntRU5ZbR50zt4FPGh7WBVT QqpaOvgwmLiHijyvrFmGWxbZiGAbZU7n2NX0yfvWqSKwzym7FQKE5Y5Yhy/yWiLCPK TfoyXr14pyUYgmg9Z7xEKaTccXNl6Hv3/4BSuCaFDhb8H9WPF/OLrdH/nfeAEWAkn6 y9PeT+S/06FDA== 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 15816628BA for ; Sat, 13 Jan 2024 15:23:11 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="DMNkBKtc"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705155790; 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=diAP1U/Qgri4qaPRP+DrtDR3hQ8y1Pz2h6tNa7MEXtQ=; b=DMNkBKtcAsXVEaqvgd2IwRAMQtOQljnBtE9KoLhyqhr75OS9+kSO/Ytx9bmsqEb5xwvvQo kqGLEVrLsgVLp7AAL/Nedh78jSi5oi/kvvZ1nGYKteV/0NUJbWAOkJ99Uy/F5TfGDqU798 AekdSkEmpaplyQWN2DY2hXk+uQi6Zfc= 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-671-t3V_O6aiNAeHRJBkdj3UqQ-1; Sat, 13 Jan 2024 09:23:05 -0500 X-MC-Unique: t3V_O6aiNAeHRJBkdj3UqQ-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 01AE429AA389; Sat, 13 Jan 2024 14:23:05 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DB8A3C25; Sat, 13 Jan 2024 14:23:03 +0000 (UTC) To: libcamera-devel@lists.libcamera.org, Andrey Konovalov Date: Sat, 13 Jan 2024 15:22:16 +0100 Message-ID: <20240113142218.28063-17-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 16/18] libcamera: swstats_cpu: Add support for 8 and 10 bpp unpacked bayer input 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 support for 8 and 10 bpp unpacked bayer input for all 4 standard bayer orders. Signed-off-by: Hans de Goede Tested-by: Bryan O'Donoghue # sc8280xp Lenovo x13s Tested-by: Pavel Machek --- .../internal/software_isp/swstats_cpu.h | 7 ++ src/libcamera/software_isp/swstats_cpu.cpp | 97 +++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h index 8bb86e98..3410753c 100644 --- a/include/libcamera/internal/software_isp/swstats_cpu.h +++ b/include/libcamera/internal/software_isp/swstats_cpu.h @@ -11,6 +11,7 @@ #pragma once +#include "libcamera/internal/bayer_format.h" #include "libcamera/internal/shared_mem_object.h" #include "libcamera/internal/software_isp/swisp_stats.h" #include "libcamera/internal/software_isp/swstats.h" @@ -31,6 +32,12 @@ public: const SharedFD &getStatsFD() { return sharedStats_.fd(); } int configure(const StreamConfiguration &inputCfg); private: + int setupStandardBayerOrder(BayerFormat::Order order); + /* Bayer 8 bpp unpacked */ + void statsBGGR8Line0(const uint8_t *src[]); + /* Bayer 10 bpp unpacked */ + void statsBGGR10Line0(const uint8_t *src[]); + /* Bayer 10 bpp packed */ void statsBGGR10PLine0(const uint8_t *src[]); void statsGBRG10PLine0(const uint8_t *src[]); void resetStats(void); diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index 59453d07..6bd78860 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -59,6 +59,57 @@ static const unsigned int BLUE_Y_MUL = 29; /* 0.11 * 256 */ stats_.sumG_ += sumG; \ stats_.sumB_ += sumB; +void SwStatsCpu::statsBGGR8Line0(const uint8_t *src[]) +{ + const uint8_t *src0 = src[1] + window_.x; + const uint8_t *src1 = src[2] + window_.x; + + SWISP_LINARO_START_LINE_STATS(uint8_t) + + if (swap_lines_) + std::swap(src0, src1); + + /* x += 4 sample every other 2x2 block */ + for (int x = 0; x < (int)window_.width; x += 4) { + b = src0[x]; + g = src0[x + 1]; + g2 = src1[x]; + r = src1[x + 1]; + + g = (g + g2) / 2; + + SWISP_LINARO_ACCUMULATE_LINE_STATS(1) + } + + SWISP_LINARO_FINISH_LINE_STATS() +} + +void SwStatsCpu::statsBGGR10Line0(const uint8_t *src[]) +{ + const uint16_t *src0 = (const uint16_t *)src[1] + window_.x; + const uint16_t *src1 = (const uint16_t *)src[2] + window_.x; + + SWISP_LINARO_START_LINE_STATS(uint16_t) + + if (swap_lines_) + std::swap(src0, src1); + + /* x += 4 sample every other 2x2 block */ + for (int x = 0; x < (int)window_.width; x += 4) { + b = src0[x]; + g = src0[x + 1]; + g2 = src1[x]; + r = src1[x + 1]; + + g = (g + g2) / 2; + + /* divide Y by 4 for 10 -> 8 bpp value */ + SWISP_LINARO_ACCUMULATE_LINE_STATS(4) + } + + SWISP_LINARO_FINISH_LINE_STATS() +} + static inline __attribute__((always_inline)) void statsBayer10P(const int width, const uint8_t *src0, const uint8_t *src1, bool bggr, SwIspStats &stats_) { @@ -124,6 +175,39 @@ void SwStatsCpu::finishStats(void) statsReady.emit(0); } +/* + * Check if order is a standard Bayer order and setup x_shift_ and swap_lines_ + * so that a single BGGR stats function can be used for all 4 standard orders. + */ +int SwStatsCpu::setupStandardBayerOrder(BayerFormat::Order order) +{ + switch (order) { + case BayerFormat::BGGR: + x_shift_ = 0; + swap_lines_ = false; + break; + case BayerFormat::GBRG: + x_shift_ = 1; /* BGGR -> GBRG */ + swap_lines_ = false; + break; + case BayerFormat::GRBG: + x_shift_ = 0; + swap_lines_ = true; /* BGGR -> GRBG */ + break; + case BayerFormat::RGGB: + x_shift_ = 1; /* BGGR -> GBRG */ + swap_lines_ = true; /* GBRG -> RGGB */ + break; + default: + return -EINVAL; + } + + patternSize_.height = 2; + patternSize_.width = 2; + y_skip_mask_ = 0x02; /* Skip every 3th and 4th line */ + return 0; +} + int SwStatsCpu::configure(const StreamConfiguration &inputCfg) { BayerFormat bayerFormat = @@ -132,6 +216,19 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg) startFrame_ = (SwStats::statsVoidFn)&SwStatsCpu::resetStats; finishFrame_ = (SwStats::statsVoidFn)&SwStatsCpu::finishStats; + if (bayerFormat.packing == BayerFormat::Packing::None && + setupStandardBayerOrder(bayerFormat.order) == 0) { + bpp_ = (bayerFormat.bitDepth + 7) & ~7; + switch (bayerFormat.bitDepth) { + case 8: + stats0_ = (SwStats::statsProcessFn)&SwStatsCpu::statsBGGR8Line0; + return 0; + case 10: + stats0_ = (SwStats::statsProcessFn)&SwStatsCpu::statsBGGR10Line0; + return 0; + } + } + if (bayerFormat.bitDepth == 10 && bayerFormat.packing == BayerFormat::Packing::CSI2) { bpp_ = 10;