From patchwork Wed Dec 10 16:15:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 25469 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 BDD6BC3257 for ; Wed, 10 Dec 2025 16:41:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 93AD0614BD; Wed, 10 Dec 2025 17:41:08 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="aSayuMXD"; dkim-atps=neutral Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 170FA6149F for ; Wed, 10 Dec 2025 17:41:03 +0100 (CET) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-477b5e0323bso6251245e9.0 for ; Wed, 10 Dec 2025 08:41:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1765384862; x=1765989662; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iHr6Y5W5ilP5vo9pl+dVLtmHzFbYz74H+sbzpnc0Cuc=; b=aSayuMXDnAuBeukuMs2NAWUhRHHeXANUTApMgtFfI+U5ooqZndtP/znJ/ZNAjXeUkR /gcz/1yp1djGKvOGYjN5dz85lFGAzY8v4AEWh0edybFhISxc9tKI3eYwiSWYoV6LFDRe BDP0PM+rPnBPsiOwixKanRo5U6B5yCHT0Hc7kZDG/pRlpUGjRuOrsTSvr7WQODVEtaaN NXPZXG794FqhyFZwkpZvuRTstyWPMLtG8rDBAC3iam3y3G9EHaaX4/kbcpV363f55Taz 5njU78xT+1WzHqe9Z6W+ZNP/GwjHA4nVgpWayt68PcQpLQR2FdWN7XeEUBoExb+ylbo2 JoVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765384862; x=1765989662; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=iHr6Y5W5ilP5vo9pl+dVLtmHzFbYz74H+sbzpnc0Cuc=; b=iqPtbYx5q0CoBOoQ1Xoe5V4rTm3/f+BkMPVVgDD+LyezbbuMXydIQ+jG9qzfYec+cB ofC8NJyhaqD++bHgjrBsIo3qXIrXEk0Rv+W1M8Q+qglwAtoczkiCyPO8kmGY1+8WW9bz q/MXcB00e7c/Py9jRmGyG4vJVKJT2YS6MK3QxcvMuwuXpI166GtdjVpvhn2T/w1XY/cd 82vg4a+dOouRQIHQztniATWdj1m/M3kcAQq6BOZ4P8es2E0XOMfa87nZFYFQri5SoIoS o2JV2UweIRvbpctuiOqFHsF/7av7/uiNMnGqErG3nFvu9PIfIdKxUeN3AxsUJi0dwaxo NvEg== X-Gm-Message-State: AOJu0YwP+EDgMJ7ORrhYQQgKGgpOLDtj+F6m3w/5IS5b87/3RZhup+qg 6YgagjXK+ouIOdr7HMR7oEXBlK4sJjez8vFPlh4pyGDfBp3Tb7SPAV5ggt+ichxHTrtPwuCGSHQ daWnn X-Gm-Gg: ASbGncujz6RvEaCUxObk0wvyuqGVX0dWAgBNJff0EtQEPzHkjeCyH67+9uRuumZCrTs +xwIAck+sDX1MXXXEX8YnAi4wZrTOcc35HAg4TRFtvdR2DNiTvOwuujKW6cdrFcygYZ8dRSoMbH Afg4c5BbSWBqXO2S6U/4GXAPHoiZFe4/2o9y4z3tz12hzXuAwRKcjkzd5OxzWDnwWkHesq1lcmG v09YBzSyFL7z+N12AsBYSxPXAzdjc1XYoYRv2EU74Wm9oXGfGS3PJctDoZonakXjjUN5FLZzoOu wSsTfj1DvYoCFK3x13fOLcmY+QdnzzYSxqPAXstCzUhu/xVhrJ/20DJqNibNPI4gVgFYASicrau g/DMmiK9Ew1HDFndhqR0yMRS850YN1l4xIFKU2aIY3GU9pLQ0OLFtRJIZwgcSGs5Ht6goodnAIR WrsrHg2g8+JaJrFYIE+aSv65muV6r3f1zoFLKQBd9R8J3CrEgDjjxd8IuRarddEWVZU8NguK2RV iay/u03LgHZq/MQcZdH5stcq4W0kA== X-Google-Smtp-Source: AGHT+IG7V2NDW7TOkVpf8lUl9bntreePeaV3CZsoNZVnWp9JlpUAutSYPlaslmpQPaasKvufRq29CA== X-Received: by 2002:a05:600c:3505:b0:479:1348:c63e with SMTP id 5b1f17b1804b1-47a886d92b4mr333015e9.9.1765384862158; Wed, 10 Dec 2025 08:41:02 -0800 (PST) Received: from davidp-pi5.pitowers.org ([2a00:1098:3142:1f:88ea:c658:5b20:5e46]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47a88371e13sm1270415e9.11.2025.12.10.08.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Dec 2025 08:41:01 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH 04/11] pipeline: rpi: Add PipelineHandlerBase::bayerToMbusCode Date: Wed, 10 Dec 2025 16:15:19 +0000 Message-ID: <20251210164055.17856-5-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251210164055.17856-1-david.plowman@raspberrypi.com> References: <20251210164055.17856-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 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" In future we are going to need this function outside pisp.cpp, so move it to PipelineHandlerBase and amend any existing callers to use the new version. It is functionally identical. Signed-off-by: David Plowman --- .../pipeline/rpi/common/pipeline_base.cpp | 43 +++++++++++++++++ .../pipeline/rpi/common/pipeline_base.h | 1 + src/libcamera/pipeline/rpi/pisp/pisp.cpp | 47 +------------------ 3 files changed, 46 insertions(+), 45 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 9d65dc83..00b088fc 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -381,6 +381,49 @@ V4L2DeviceFormat PipelineHandlerBase::toV4L2DeviceFormat(const V4L2VideoDevice * return deviceFormat; } +const std::vector> BayerToMbusCodeMap{ + { { BayerFormat::BGGR, 8, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SBGGR8_1X8, }, + { { BayerFormat::GBRG, 8, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGBRG8_1X8, }, + { { BayerFormat::GRBG, 8, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGRBG8_1X8, }, + { { BayerFormat::RGGB, 8, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SRGGB8_1X8, }, + { { BayerFormat::BGGR, 10, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SBGGR10_1X10, }, + { { BayerFormat::GBRG, 10, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGBRG10_1X10, }, + { { BayerFormat::GRBG, 10, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGRBG10_1X10, }, + { { BayerFormat::RGGB, 10, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SRGGB10_1X10, }, + { { BayerFormat::BGGR, 12, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SBGGR12_1X12, }, + { { BayerFormat::GBRG, 12, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGBRG12_1X12, }, + { { BayerFormat::GRBG, 12, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGRBG12_1X12, }, + { { BayerFormat::RGGB, 12, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SRGGB12_1X12, }, + { { BayerFormat::BGGR, 14, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SBGGR14_1X14, }, + { { BayerFormat::GBRG, 14, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGBRG14_1X14, }, + { { BayerFormat::GRBG, 14, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGRBG14_1X14, }, + { { BayerFormat::RGGB, 14, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SRGGB14_1X14, }, + { { BayerFormat::BGGR, 16, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SBGGR16_1X16, }, + { { BayerFormat::GBRG, 16, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGBRG16_1X16, }, + { { BayerFormat::GRBG, 16, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGRBG16_1X16, }, + { { BayerFormat::RGGB, 16, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SRGGB16_1X16, }, + { { BayerFormat::BGGR, 16, BayerFormat::Packing::PISP1 }, MEDIA_BUS_FMT_SBGGR16_1X16, }, + { { BayerFormat::GBRG, 16, BayerFormat::Packing::PISP1 }, MEDIA_BUS_FMT_SGBRG16_1X16, }, + { { BayerFormat::GRBG, 16, BayerFormat::Packing::PISP1 }, MEDIA_BUS_FMT_SGRBG16_1X16, }, + { { BayerFormat::RGGB, 16, BayerFormat::Packing::PISP1 }, MEDIA_BUS_FMT_SRGGB16_1X16, }, + { { BayerFormat::RGGB, 16, BayerFormat::Packing::PISP1 }, MEDIA_BUS_FMT_SRGGB16_1X16, }, + { { BayerFormat::MONO, 16, BayerFormat::Packing::None }, MEDIA_BUS_FMT_Y16_1X16, }, + { { BayerFormat::MONO, 16, BayerFormat::Packing::PISP1 }, MEDIA_BUS_FMT_Y16_1X16, }, +}; + +unsigned int PipelineHandlerBase::bayerToMbusCode(const BayerFormat &bayer) +{ + const auto it = std::find_if(BayerToMbusCodeMap.begin(), BayerToMbusCodeMap.end(), + [bayer](const std::pair &match) { + return bayer == match.first; + }); + + if (it != BayerToMbusCodeMap.end()) + return it->second; + + return 0; +} + std::unique_ptr PipelineHandlerBase::generateConfiguration(Camera *camera, Span roles) { diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 15628259..1f174473 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -208,6 +208,7 @@ public: static V4L2DeviceFormat toV4L2DeviceFormat(const V4L2VideoDevice *dev, const V4L2SubdeviceFormat &format, BayerFormat::Packing packingReq); + static unsigned int bayerToMbusCode(const BayerFormat &bayer); std::unique_ptr generateConfiguration(Camera *camera, Span roles) override; diff --git a/src/libcamera/pipeline/rpi/pisp/pisp.cpp b/src/libcamera/pipeline/rpi/pisp/pisp.cpp index ade31de1..c08210b4 100644 --- a/src/libcamera/pipeline/rpi/pisp/pisp.cpp +++ b/src/libcamera/pipeline/rpi/pisp/pisp.cpp @@ -55,55 +55,12 @@ enum class Isp : unsigned int { Input, Output0, Output1, TdnInput, TdnOutput, constexpr unsigned int DefaultCompressionOffset = 2048; constexpr unsigned int DefaultCompressionMode = 1; -const std::vector> BayerToMbusCodeMap{ - { { BayerFormat::BGGR, 8, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SBGGR8_1X8, }, - { { BayerFormat::GBRG, 8, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGBRG8_1X8, }, - { { BayerFormat::GRBG, 8, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGRBG8_1X8, }, - { { BayerFormat::RGGB, 8, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SRGGB8_1X8, }, - { { BayerFormat::BGGR, 10, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SBGGR10_1X10, }, - { { BayerFormat::GBRG, 10, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGBRG10_1X10, }, - { { BayerFormat::GRBG, 10, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGRBG10_1X10, }, - { { BayerFormat::RGGB, 10, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SRGGB10_1X10, }, - { { BayerFormat::BGGR, 12, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SBGGR12_1X12, }, - { { BayerFormat::GBRG, 12, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGBRG12_1X12, }, - { { BayerFormat::GRBG, 12, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGRBG12_1X12, }, - { { BayerFormat::RGGB, 12, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SRGGB12_1X12, }, - { { BayerFormat::BGGR, 14, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SBGGR14_1X14, }, - { { BayerFormat::GBRG, 14, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGBRG14_1X14, }, - { { BayerFormat::GRBG, 14, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGRBG14_1X14, }, - { { BayerFormat::RGGB, 14, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SRGGB14_1X14, }, - { { BayerFormat::BGGR, 16, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SBGGR16_1X16, }, - { { BayerFormat::GBRG, 16, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGBRG16_1X16, }, - { { BayerFormat::GRBG, 16, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SGRBG16_1X16, }, - { { BayerFormat::RGGB, 16, BayerFormat::Packing::None }, MEDIA_BUS_FMT_SRGGB16_1X16, }, - { { BayerFormat::BGGR, 16, BayerFormat::Packing::PISP1 }, MEDIA_BUS_FMT_SBGGR16_1X16, }, - { { BayerFormat::GBRG, 16, BayerFormat::Packing::PISP1 }, MEDIA_BUS_FMT_SGBRG16_1X16, }, - { { BayerFormat::GRBG, 16, BayerFormat::Packing::PISP1 }, MEDIA_BUS_FMT_SGRBG16_1X16, }, - { { BayerFormat::RGGB, 16, BayerFormat::Packing::PISP1 }, MEDIA_BUS_FMT_SRGGB16_1X16, }, - { { BayerFormat::RGGB, 16, BayerFormat::Packing::PISP1 }, MEDIA_BUS_FMT_SRGGB16_1X16, }, - { { BayerFormat::MONO, 16, BayerFormat::Packing::None }, MEDIA_BUS_FMT_Y16_1X16, }, - { { BayerFormat::MONO, 16, BayerFormat::Packing::PISP1 }, MEDIA_BUS_FMT_Y16_1X16, }, -}; - -unsigned int bayerToMbusCode(const BayerFormat &bayer) -{ - const auto it = std::find_if(BayerToMbusCodeMap.begin(), BayerToMbusCodeMap.end(), - [bayer](const std::pair &match) { - return bayer == match.first; - }); - - if (it != BayerToMbusCodeMap.end()) - return it->second; - - return 0; -} - uint32_t mbusCodeUnpacked16(unsigned int code) { BayerFormat bayer = BayerFormat::fromMbusCode(code); BayerFormat bayer16(bayer.order, 16, BayerFormat::Packing::None); - return bayerToMbusCode(bayer16); + return RPi::PipelineHandlerBase::bayerToMbusCode(bayer16); } uint8_t toPiSPBayerOrder(V4L2PixelFormat format) @@ -2219,7 +2176,7 @@ int PiSPCameraData::configureEntities(V4L2SubdeviceFormat sensorFormat, cfe_[Cfe::Output0].dev()->getFormat(&feOutputFormat); BayerFormat feOutputBayer = BayerFormat::fromV4L2PixelFormat(feOutputFormat.fourcc); - feFormat.code = bayerToMbusCode(feOutputBayer); + feFormat.code = RPi::PipelineHandlerBase::bayerToMbusCode(feOutputBayer); ret = feSubdev_->setFormat(feVideo0SourcePad, &feFormat); return ret;