From patchwork Wed Aug 27 09:07:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 24239 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 316F7BD87C for ; Wed, 27 Aug 2025 09:07:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1B94A692FB; Wed, 27 Aug 2025 11:07:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="tOkjfdeY"; dkim-atps=neutral Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 772C2692EB for ; Wed, 27 Aug 2025 11:07:45 +0200 (CEST) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-45a1b004954so51909275e9.0 for ; Wed, 27 Aug 2025 02:07:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1756285665; x=1756890465; 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=Sua0fW4TmtI2NRqqSMfXISvx8gNaU/HRu7j90J3GPoE=; b=tOkjfdeYkWgFASAOMkXgs44TGSUuWXCJ473dH3dVmLsFIkFnB9ahqpXQ1vzu5J0n6p uQRlM+3PqvW7VyrcJOGDayPA5+ctnt5BdaRMS/nvbvyp7PvKmEZKpZmvbZx8KeYP/4YA hQU3DclF3IbeGZ2hOZ3teaamvIubKQiEF/vyUqi+K/UvffSPGxP7bX+tem10lGHu+At8 nHK1KJ87i1Pzbob6Bk75xVUgRo88vFV/7tYVI5xh2StK9J7Gi6eEFtKqyu9a4S9wez8d B5zFZXdl56WEFOhUs+dOO+09pHWWkMyYswj1S4UjnEPjpwfOrzLDQDKFsgaq6dnvq4ZR 0VnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756285665; x=1756890465; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Sua0fW4TmtI2NRqqSMfXISvx8gNaU/HRu7j90J3GPoE=; b=AHOHgLYLzN9Z1wHgiaggPHu69Mzj7rwjuF0hrJJtBhC24L9ubSDXt3+0MrRZIqzPzs ZwvHV1d0QAwoKXgXBLERW7c7IxKyPStOPsMsaRAtHaG1tM1Rrqg335HXK+dqe8svmnWq 8VaC6sAARn/vu8c8SadJI2Zr4aBTo0fc+bd9iZw1kLwJjUQfYNLyehk2CVpm1g9lPXmd 8k9E/NQg6Re0WuxTHMDb86UdPHlu59vtxN7PiQJeE34AV4j2Bhec1ZK1ep9Sa/5mJrfP Q2uqg/XaG/ewOACdOcyVDPVQpcOetpiha3QUxbdJTRwk59lTQYazgj2osxosaBJPwQ9s 5gyg== X-Gm-Message-State: AOJu0YyT+Eam/WCtAbTi412Q/4glLAyqbSpNVRaNXz3fhnY6n/2Is5+D ZYEve/syfbjcng8U5kmQDWDoklu2WsQXKfyPo+EEijezbiQtcJRKybVptYLLEwSPKeZqeL+cyKz KEsrN X-Gm-Gg: ASbGncvW0HL0YqWk1cgyfCv9n8XVgjc8PeWvbNqWAC5lBHkApTz8ZfmDoljiw40ejKB te30IY+C3ZMJNA7Yo+N2WBzfnJJjhC8DHSwJknpWiy4hDlzbR2IGXCmSer1iI0XTjz9S4swNWIC W8tMSrUORkqyM0w/tSRfWCo8ScM8KmUUHlpm0TRcbi878oibKlhnyUQNuap6namZ7pvQCI1nJO3 inrz1A/Zp9diMB+wg78LJVvfg+wfqRe8I9q05yZKGgevMs6dPxal+RDn283x/sDc2Xdt8K4YrDQ MKmTz+X+wVbdm1yBKui7LRlSLFjNmeXD0AdWd+TjtsiG8ANQ5fha23Ib4bSzKZU91C3mMyvnv8E qlDW43wDCz5Z+w5sgphx3F7pTNQXMzn9HEyO1+Taerfz6oQ2Xc4OconV2gsxT0NDjRZIil1zkBf CVaETBkB584aKhQlZJ5r1sEZhyOmtkb9UueAsiMFc5aoLsOKEnrdqQ2aZpfquG X-Google-Smtp-Source: AGHT+IEMuPeTAyXray2xtje4tJ6CkmcQAi2cZ/XeJbdvG6af5uog1UtlaKbu2svo/w6KIUd2qV8g/w== X-Received: by 2002:a05:600c:154f:b0:458:6733:fb43 with SMTP id 5b1f17b1804b1-45b517c552dmr144163855e9.19.1756285664593; Wed, 27 Aug 2025 02:07:44 -0700 (PDT) Received: from raspberrypi.pitowers.org ([2a00:1098:3142:1f:ffc9:aff6:7f7f:893b]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b6f30fe02sm21498675e9.18.2025.08.27.02.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Aug 2025 02:07:44 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [RFC PATCH 02/12] libcamera: Add BayerFormat::toMbusCode Date: Wed, 27 Aug 2025 10:07:29 +0100 Message-Id: <20250827090739.86955-3-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250827090739.86955-1-david.plowman@raspberrypi.com> References: <20250827090739.86955-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" Multiple places now need this, so centralise it here. Signed-off-by: David Plowman --- include/libcamera/internal/bayer_format.h | 1 + src/libcamera/bayer_format.cpp | 124 ++++++++++++++++++++++ 2 files changed, 125 insertions(+) diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h index 5c14bb5f..f2f22932 100644 --- a/include/libcamera/internal/bayer_format.h +++ b/include/libcamera/internal/bayer_format.h @@ -53,6 +53,7 @@ public: std::string toString() const; + unsigned int toMbusCode() const; V4L2PixelFormat toV4L2PixelFormat() const; static BayerFormat fromV4L2PixelFormat(V4L2PixelFormat v4l2Format); PixelFormat toPixelFormat() const; diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index 3dab91fc..9e9d50fc 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -331,6 +331,130 @@ std::ostream &operator<<(std::ostream &out, const BayerFormat &f) return out; } +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 BayerFormat::toMbusCode() const +{ + const auto it = std::find_if(BayerToMbusCodeMap.begin(), BayerToMbusCodeMap.end(), + [this](const std::pair &match) { + return *this == match.first; + }); + + if (it != BayerToMbusCodeMap.end()) + return it->second; + + return 0; +} + /** * \fn bool operator!=(const BayerFormat &lhs, const BayerFormat &rhs) * \brief Compare two BayerFormats for inequality