Patch Detail
Show a patch.
GET /api/patches/17676/?format=api
{ "id": 17676, "url": "https://patchwork.libcamera.org/api/patches/17676/?format=api", "web_url": "https://patchwork.libcamera.org/patch/17676/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20221024000356.29521-14-laurent.pinchart@ideasonboard.com>", "date": "2022-10-24T00:03:56", "name": "[libcamera-devel,v3,13/13] pipeline: rkisp1: Support raw Bayer capture configuration", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "5cb73709ac2785db0b6665eebbd10755a39f9ae4", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/17676/mbox/", "series": [ { "id": 3574, "url": "https://patchwork.libcamera.org/api/series/3574/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3574", "date": "2022-10-24T00:03:43", "name": "Add Bayer format support for RkISP1", "version": 3, "mbox": "https://patchwork.libcamera.org/series/3574/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/17676/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/17676/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 C5E81C328C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 24 Oct 2022 00:04:43 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 674AB62EDB;\n\tMon, 24 Oct 2022 02:04:43 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D45D662F05\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 Oct 2022 02:04:38 +0200 (CEST)", "from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 61665471;\n\tMon, 24 Oct 2022 02:04:38 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1666569883;\n\tbh=nWH6bgiJFff13tvz948iLbgD+gVkWhWQtZXSjMKi/no=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=PXBpY87mdS5IHp+n7g9oyhco1Sgzbaj+rWxrmxZ6aG0Bl6ZcPkg8cAVy7TWoeFeWD\n\t1CAQgG3ydfRnywsI+bTwa0kmHL1vEDfswjnW2jaaZvXkfsU8pE7YYRu9qN/pWPUz3e\n\tfaUpTP9tfeoqszu5itLC+I8Riii3zMjFUueHC1Va5s7Hp8knifhaozwQIJVeMgfCNG\n\tjXlfRNv3G4K6wAdpqgm1vvAQvKm6c0WnUMTQHDtn2owBhJZ2ATfiaU608Q5DxXp18s\n\tniPV83vk9YJ531Yb0Gj5vb89iKVrNEg4pw+MRpa0keoSU6dZlPYNGxElWf/PF4BSPA\n\toUMWWMJKshU/g==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1666569878;\n\tbh=nWH6bgiJFff13tvz948iLbgD+gVkWhWQtZXSjMKi/no=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=HMCzZK2m50BX1xg6NI/NExWmkxPoEMe/CMz873ByNCXV73xEobIaIBIPFPrK0lkhS\n\tqlcSxZPGrQrkJWS97HoJLrRxxM7KFpy6hSbTc9nTPF5M36OFoorPgBQg0XMXPiqyZj\n\tUKLXC/Kg/3pmJvKt+cApyVKwTVdm3n/m0osiR0m0=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"HMCzZK2m\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 24 Oct 2022 03:03:56 +0300", "Message-Id": "<20221024000356.29521-14-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.37.4", "In-Reply-To": "<20221024000356.29521-1-laurent.pinchart@ideasonboard.com>", "References": "<20221024000356.29521-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 13/13] pipeline: rkisp1: Support raw\n\tBayer capture configuration", "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>", "From": "Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>", "Reply-To": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "From: Florian Sylvestre <fsylvestre@baylibre.com>\n\nImplement support for raw Bayer capture during configuration generation,\nvalidation and camera configuration.\n\nWhile at it, fix a typo in a comment.\n\nSigned-off-by: Florian Sylvestre <fsylvestre@baylibre.com>\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nChanges since v2:\n\n- Nearly complete rewrite\n---\n src/libcamera/pipeline/rkisp1/rkisp1.cpp | 116 +++++++---\n src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 209 +++++++++++++++---\n src/libcamera/pipeline/rkisp1/rkisp1_path.h | 3 +-\n 3 files changed, 273 insertions(+), 55 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex e57411544f7a..891fd2d50270 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -403,6 +403,30 @@ void RkISP1CameraData::metadataReady(unsigned int frame, const ControlList &meta\n \tpipe()->tryCompleteRequest(info);\n }\n \n+/* -----------------------------------------------------------------------------\n+ * Camera Configuration\n+ */\n+\n+namespace {\n+\n+/* Keep in sync with the supported raw formats in rkisp1_path.cpp. */\n+const std::map<PixelFormat, uint32_t> rawFormats = {\n+\t{ formats::SBGGR8, MEDIA_BUS_FMT_SBGGR8_1X8 },\n+\t{ formats::SGBRG8, MEDIA_BUS_FMT_SGBRG8_1X8 },\n+\t{ formats::SGRBG8, MEDIA_BUS_FMT_SGRBG8_1X8 },\n+\t{ formats::SRGGB8, MEDIA_BUS_FMT_SRGGB8_1X8 },\n+\t{ formats::SBGGR10, MEDIA_BUS_FMT_SBGGR10_1X10 },\n+\t{ formats::SGBRG10, MEDIA_BUS_FMT_SGBRG10_1X10 },\n+\t{ formats::SGRBG10, MEDIA_BUS_FMT_SGRBG10_1X10 },\n+\t{ formats::SRGGB10, MEDIA_BUS_FMT_SRGGB10_1X10 },\n+\t{ formats::SBGGR12, MEDIA_BUS_FMT_SBGGR12_1X12 },\n+\t{ formats::SGBRG12, MEDIA_BUS_FMT_SGBRG12_1X12 },\n+\t{ formats::SGRBG12, MEDIA_BUS_FMT_SGRBG12_1X12 },\n+\t{ formats::SRGGB12, MEDIA_BUS_FMT_SRGGB12_1X12 },\n+};\n+\n+} /* namespace */\n+\n RkISP1CameraConfiguration::RkISP1CameraConfiguration(Camera *camera,\n \t\t\t\t\t\t RkISP1CameraData *data)\n \t: CameraConfiguration()\n@@ -449,6 +473,21 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \t\tstatus = Adjusted;\n \t}\n \n+\t/*\n+\t * Simultaneous capture of raw and processed streams isn't possible. If\n+\t * there is any raw stream, cap the number of streams to one.\n+\t */\n+\tif (config_.size() > 1) {\n+\t\tfor (const auto &cfg : config_) {\n+\t\t\tif (PixelFormatInfo::info(cfg.pixelFormat).colourEncoding ==\n+\t\t\t PixelFormatInfo::ColourEncodingRAW) {\n+\t\t\t\tconfig_.resize(1);\n+\t\t\t\tstatus = Adjusted;\n+\t\t\t}\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n \t/*\n \t * If there are more than one stream in the configuration figure out the\n \t * order to evaluate the streams. The first stream has the highest\n@@ -510,45 +549,51 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \t\t\t}\n \t\t}\n \n-\t\t/* All paths rejected configuraiton. */\n+\t\t/* All paths rejected configuration. */\n \t\tLOG(RkISP1, Debug) << \"Camera configuration not supported \"\n \t\t\t\t << cfg.toString();\n \t\treturn Invalid;\n \t}\n \n \t/* Select the sensor format. */\n+\tPixelFormat rawFormat;\n \tSize maxSize;\n-\tfor (const StreamConfiguration &cfg : config_)\n+\n+\tfor (const StreamConfiguration &cfg : config_) {\n+\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat);\n+\t\tif (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW)\n+\t\t\trawFormat = cfg.pixelFormat;\n+\n \t\tmaxSize = std::max(maxSize, cfg.size);\n+\t}\n+\n+\tstd::vector<unsigned int> mbusCodes;\n+\n+\tif (rawFormat.isValid()) {\n+\t\tmbusCodes = { rawFormats.at(rawFormat) };\n+\t} else {\n+\t\tstd::transform(rawFormats.begin(), rawFormats.end(),\n+\t\t\t std::back_inserter(mbusCodes),\n+\t\t\t [](const auto &value) { return value.second; });\n+\t}\n+\n+\tsensorFormat_ = sensor->getFormat(mbusCodes, maxSize);\n \n-\tsensorFormat_ = sensor->getFormat({ MEDIA_BUS_FMT_SBGGR12_1X12,\n-\t\t\t\t\t MEDIA_BUS_FMT_SGBRG12_1X12,\n-\t\t\t\t\t MEDIA_BUS_FMT_SGRBG12_1X12,\n-\t\t\t\t\t MEDIA_BUS_FMT_SRGGB12_1X12,\n-\t\t\t\t\t MEDIA_BUS_FMT_SBGGR10_1X10,\n-\t\t\t\t\t MEDIA_BUS_FMT_SGBRG10_1X10,\n-\t\t\t\t\t MEDIA_BUS_FMT_SGRBG10_1X10,\n-\t\t\t\t\t MEDIA_BUS_FMT_SRGGB10_1X10,\n-\t\t\t\t\t MEDIA_BUS_FMT_SBGGR8_1X8,\n-\t\t\t\t\t MEDIA_BUS_FMT_SGBRG8_1X8,\n-\t\t\t\t\t MEDIA_BUS_FMT_SGRBG8_1X8,\n-\t\t\t\t\t MEDIA_BUS_FMT_SRGGB8_1X8 },\n-\t\t\t\t\t maxSize);\n \tif (sensorFormat_.size.isNull())\n \t\tsensorFormat_.size = sensor->resolution();\n \n \treturn status;\n }\n \n+/* -----------------------------------------------------------------------------\n+ * Pipeline Operations\n+ */\n+\n PipelineHandlerRkISP1::PipelineHandlerRkISP1(CameraManager *manager)\n \t: PipelineHandler(manager), hasSelfPath_(true)\n {\n }\n \n-/* -----------------------------------------------------------------------------\n- * Pipeline Operations\n- */\n-\n std::unique_ptr<CameraConfiguration>\n PipelineHandlerRkISP1::generateConfiguration(Camera *camera,\n \tconst StreamRoles &roles)\n@@ -604,23 +649,38 @@ PipelineHandlerRkISP1::generateConfiguration(Camera *camera,\n \t\t\t\tcolorSpace = ColorSpace::Rec709;\n \t\t\tbreak;\n \n+\t\tcase StreamRole::Raw:\n+\t\t\tif (roles.size() > 1) {\n+\t\t\t\tLOG(RkISP1, Error)\n+\t\t\t\t\t<< \"Can't capture both raw and processed streams\";\n+\t\t\t\treturn nullptr;\n+\t\t\t}\n+\n+\t\t\tuseMainPath = true;\n+\t\t\tcolorSpace = ColorSpace::Raw;\n+\t\t\tbreak;\n+\n \t\tdefault:\n \t\t\tLOG(RkISP1, Warning)\n \t\t\t\t<< \"Requested stream role not supported: \" << role;\n \t\t\treturn nullptr;\n \t\t}\n \n-\t\tStreamConfiguration cfg;\n+\t\tRkISP1Path *path;\n+\n \t\tif (useMainPath) {\n-\t\t\tcfg = data->mainPath_->generateConfiguration(\n-\t\t\t\tdata->sensor_.get());\n+\t\t\tpath = data->mainPath_;\n \t\t\tmainPathAvailable = false;\n \t\t} else {\n-\t\t\tcfg = data->selfPath_->generateConfiguration(\n-\t\t\t\tdata->sensor_.get());\n+\t\t\tpath = data->selfPath_;\n \t\t\tselfPathAvailable = false;\n \t\t}\n \n+\t\tStreamConfiguration cfg =\n+\t\t\tpath->generateConfiguration(data->sensor_.get(), role);\n+\t\tif (!cfg.pixelFormat.isValid())\n+\t\t\treturn nullptr;\n+\n \t\tcfg.colorSpace = colorSpace;\n \t\tconfig->addConfiguration(cfg);\n \t}\n@@ -674,10 +734,14 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n \t\t<< \"ISP input pad configured with \" << format\n \t\t<< \" crop \" << rect;\n \n-\tisRaw_ = false;\n+\tconst PixelFormat &streamFormat = config->at(0).pixelFormat;\n+\tconst PixelFormatInfo &info = PixelFormatInfo::info(streamFormat);\n+\tisRaw_ = info.colourEncoding == PixelFormatInfo::ColourEncodingRAW;\n \n \t/* YUYV8_2X8 is required on the ISP source path pad for YUV output. */\n-\tformat.mbus_code = MEDIA_BUS_FMT_YUYV8_2X8;\n+\tif (!isRaw_)\n+\t\tformat.mbus_code = MEDIA_BUS_FMT_YUYV8_2X8;\n+\n \tLOG(RkISP1, Debug)\n \t\t<< \"Configuring ISP output pad with \" << format\n \t\t<< \" crop \" << rect;\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\nindex cc2ac66e6939..2994bd665ebb 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n@@ -21,6 +21,39 @@ namespace libcamera {\n \n LOG_DECLARE_CATEGORY(RkISP1)\n \n+namespace {\n+\n+/* Keep in sync with the supported raw formats in rkisp1.cpp. */\n+const std::map<PixelFormat, uint32_t> formatToMediaBus = {\n+\t{ formats::UYVY, MEDIA_BUS_FMT_YUYV8_2X8 },\n+\t{ formats::YUYV, MEDIA_BUS_FMT_YUYV8_2X8 },\n+\t{ formats::NV12, MEDIA_BUS_FMT_YUYV8_1_5X8 },\n+\t{ formats::NV21, MEDIA_BUS_FMT_YUYV8_1_5X8 },\n+\t{ formats::NV16, MEDIA_BUS_FMT_YUYV8_2X8 },\n+\t{ formats::NV61, MEDIA_BUS_FMT_YUYV8_2X8 },\n+\t{ formats::YUV420, MEDIA_BUS_FMT_YUYV8_1_5X8 },\n+\t{ formats::YVU420, MEDIA_BUS_FMT_YUYV8_1_5X8 },\n+\t{ formats::YUV422, MEDIA_BUS_FMT_YUYV8_2X8 },\n+\t{ formats::YVU422, MEDIA_BUS_FMT_YUYV8_2X8 },\n+\t{ formats::R8, MEDIA_BUS_FMT_YUYV8_2X8 },\n+\t{ formats::RGB565, MEDIA_BUS_FMT_YUYV8_2X8 },\n+\t{ formats::XRGB8888, MEDIA_BUS_FMT_YUYV8_2X8 },\n+\t{ formats::SBGGR8, MEDIA_BUS_FMT_SBGGR8_1X8 },\n+\t{ formats::SGBRG8, MEDIA_BUS_FMT_SGBRG8_1X8 },\n+\t{ formats::SGRBG8, MEDIA_BUS_FMT_SGRBG8_1X8 },\n+\t{ formats::SRGGB8, MEDIA_BUS_FMT_SRGGB8_1X8 },\n+\t{ formats::SBGGR10, MEDIA_BUS_FMT_SBGGR10_1X10 },\n+\t{ formats::SGBRG10, MEDIA_BUS_FMT_SGBRG10_1X10 },\n+\t{ formats::SGRBG10, MEDIA_BUS_FMT_SGRBG10_1X10 },\n+\t{ formats::SRGGB10, MEDIA_BUS_FMT_SRGGB10_1X10 },\n+\t{ formats::SBGGR12, MEDIA_BUS_FMT_SBGGR12_1X12 },\n+\t{ formats::SGBRG12, MEDIA_BUS_FMT_SGBRG12_1X12 },\n+\t{ formats::SGRBG12, MEDIA_BUS_FMT_SGRBG12_1X12 },\n+\t{ formats::SRGGB12, MEDIA_BUS_FMT_SRGGB12_1X12 },\n+};\n+\n+} /* namespace */\n+\n RkISP1Path::RkISP1Path(const char *name, const Span<const PixelFormat> &formats,\n \t\t const Size &minResolution, const Size &maxResolution)\n \t: name_(name), running_(false), formats_(formats),\n@@ -69,11 +102,18 @@ void RkISP1Path::populateFormats()\n \tstd::vector<PixelFormat> formats;\n \tfor (const auto &[format, sizes] : v4l2Formats) {\n \t\tconst PixelFormat pixelFormat = format.toPixelFormat();\n-\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat);\n \n-\t\t/* \\todo Add support for RAW formats. */\n-\t\tif (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW)\n+\t\t/*\n+\t\t * As a defensive measure, skip any pixel format exposed by the\n+\t\t * driver that we don't know about. This ensures that looking up\n+\t\t * formats in formatToMediaBus using a key from streamFormats_\n+\t\t * will never fail in any of the other functions.\n+\t\t */\n+\t\tif (!formatToMediaBus.count(pixelFormat)) {\n+\t\t\tLOG(RkISP1, Warning)\n+\t\t\t\t<< \"Unsupported pixel format \" << pixelFormat;\n \t\t\tcontinue;\n+\t\t}\n \n \t\tstreamFormats_.insert(pixelFormat);\n \n@@ -86,21 +126,68 @@ void RkISP1Path::populateFormats()\n \t}\n }\n \n-StreamConfiguration RkISP1Path::generateConfiguration(const CameraSensor *sensor)\n+StreamConfiguration\n+RkISP1Path::generateConfiguration(const CameraSensor *sensor, StreamRole role)\n {\n+\tconst std::vector<unsigned int> &mbusCodes = sensor->mbusCodes();\n \tconst Size &resolution = sensor->resolution();\n \n \tSize maxResolution = maxResolution_.boundedToAspectRatio(resolution)\n \t\t\t\t\t .boundedTo(resolution);\n \tSize minResolution = minResolution_.expandedToAspectRatio(resolution);\n \n+\t/* Create the list of supported stream formats. */\n \tstd::map<PixelFormat, std::vector<SizeRange>> streamFormats;\n-\tfor (const auto &format : streamFormats_)\n-\t\tstreamFormats[format] = { { minResolution, maxResolution } };\n+\tunsigned int rawBitsPerPixel = 0;\n+\tPixelFormat rawFormat;\n+\n+\tfor (const auto &format : streamFormats_) {\n+\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(format);\n+\n+\t\tif (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) {\n+\t\t\t/* Skip raw formats not supported by the sensor. */\n+\t\t\tuint32_t mbusCode = formatToMediaBus.at(format);\n+\t\t\tif (std::find(mbusCodes.begin(), mbusCodes.end(), mbusCode) ==\n+\t\t\t mbusCodes.end())\n+\t\t\t\tcontinue;\n+\n+\t\t\tstreamFormats[format] = { { resolution, resolution } };\n+\n+\t\t\t/*\n+\t\t\t * Store the raw format with the higher bits per pixel\n+\t\t\t * for later usage.\n+\t\t\t */\n+\t\t\tif (info.bitsPerPixel > rawBitsPerPixel) {\n+\t\t\t\trawBitsPerPixel = info.bitsPerPixel;\n+\t\t\t\trawFormat = format;\n+\t\t\t}\n+\t\t} else {\n+\t\t\tstreamFormats[format] = { { minResolution, maxResolution } };\n+\t\t}\n+\t}\n+\n+\t/*\n+\t * Pick a suitable pixel format for the role. Raw streams need to use a\n+\t * raw format, processed streams use NV12 by default.\n+\t */\n+\tPixelFormat format;\n+\n+\tif (role == StreamRole::Raw) {\n+\t\tif (!rawFormat.isValid()) {\n+\t\t\tLOG(RkISP1, Error)\n+\t\t\t\t<< \"Sensor \" << sensor->model()\n+\t\t\t\t<< \" doesn't support raw capture\";\n+\t\t\treturn {};\n+\t\t}\n+\n+\t\tformat = rawFormat;\n+\t} else {\n+\t\tformat = formats::NV12;\n+\t}\n \n \tStreamFormats formats(streamFormats);\n \tStreamConfiguration cfg(formats);\n-\tcfg.pixelFormat = formats::NV12;\n+\tcfg.pixelFormat = format;\n \tcfg.size = maxResolution;\n \tcfg.bufferCount = RKISP1_BUFFER_COUNT;\n \n@@ -110,26 +197,85 @@ StreamConfiguration RkISP1Path::generateConfiguration(const CameraSensor *sensor\n CameraConfiguration::Status RkISP1Path::validate(const CameraSensor *sensor,\n \t\t\t\t\t\t StreamConfiguration *cfg)\n {\n+\tconst std::vector<unsigned int> &mbusCodes = sensor->mbusCodes();\n \tconst Size &resolution = sensor->resolution();\n \n \tconst StreamConfiguration reqCfg = *cfg;\n \tCameraConfiguration::Status status = CameraConfiguration::Valid;\n \n \t/*\n-\t * Default to NV12 if the requested format is not supported. All\n-\t * versions of the ISP are guaranteed to support NV12 on both the main\n-\t * and self paths.\n+\t * Validate the pixel format. If the requested format isn't supported,\n+\t * default to either NV12 (all versions of the ISP are guaranteed to\n+\t * support NV12 on both the main and self paths) if the requested format\n+\t * is not a raw format, or to the supported raw format with the highest\n+\t * bits per pixel otherwise.\n \t */\n-\tif (!streamFormats_.count(cfg->pixelFormat))\n-\t\tcfg->pixelFormat = formats::NV12;\n+\tunsigned int rawBitsPerPixel = 0;\n+\tPixelFormat rawFormat;\n+\tbool found = false;\n+\n+\tfor (const auto &format : streamFormats_) {\n+\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(format);\n+\n+\t\tif (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) {\n+\t\t\t/* Skip raw formats not supported by the sensor. */\n+\t\t\tuint32_t mbusCode = formatToMediaBus.at(format);\n+\t\t\tif (std::find(mbusCodes.begin(), mbusCodes.end(), mbusCode) ==\n+\t\t\t mbusCodes.end())\n+\t\t\t\tcontinue;\n+\n+\t\t\t/*\n+\t\t\t * Store the raw format with the higher bits per pixel\n+\t\t\t * for later usage.\n+\t\t\t */\n+\t\t\tif (info.bitsPerPixel > rawBitsPerPixel) {\n+\t\t\t\trawBitsPerPixel = info.bitsPerPixel;\n+\t\t\t\trawFormat = format;\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (cfg->pixelFormat == format) {\n+\t\t\tfound = true;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tbool isRaw = PixelFormatInfo::info(cfg->pixelFormat).colourEncoding ==\n+\t\t PixelFormatInfo::ColourEncodingRAW;\n \n \t/*\n-\t * Adjust the size based on the sensor resolution and absolute limits\n-\t * of the ISP.\n+\t * If no raw format supported by the sensor has been found, use a\n+\t * processed format.\n \t */\n-\tSize maxResolution = maxResolution_.boundedToAspectRatio(resolution)\n-\t\t\t\t\t .boundedTo(resolution);\n-\tSize minResolution = minResolution_.expandedToAspectRatio(resolution);\n+\tif (!rawFormat.isValid())\n+\t\tisRaw = false;\n+\n+\tif (!found)\n+\t\tcfg->pixelFormat = isRaw ? rawFormat : formats::NV12;\n+\n+\tSize minResolution;\n+\tSize maxResolution;\n+\n+\tif (isRaw) {\n+\t\t/*\n+\t\t * Use the sensor output size closest to the requested stream\n+\t\t * size.\n+\t\t */\n+\t\tuint32_t mbusCode = formatToMediaBus.at(cfg->pixelFormat);\n+\t\tV4L2SubdeviceFormat sensorFormat =\n+\t\t\tsensor->getFormat({ mbusCode }, cfg->size);\n+\n+\t\tminResolution = sensorFormat.size;\n+\t\tmaxResolution = sensorFormat.size;\n+\t} else {\n+\t\t/*\n+\t\t * Adjust the size based on the sensor resolution and absolute\n+\t\t * limits of the ISP.\n+\t\t */\n+\t\tminResolution = minResolution_.expandedToAspectRatio(resolution);\n+\t\tmaxResolution = maxResolution_.boundedToAspectRatio(resolution)\n+\t\t\t\t\t .boundedTo(resolution);\n+\t}\n \n \tcfg->size.boundTo(maxResolution);\n \tcfg->size.expandTo(minResolution);\n@@ -182,15 +328,11 @@ int RkISP1Path::configure(const StreamConfiguration &config,\n \t\t<< \"Configuring \" << name_ << \" resizer output pad with \"\n \t\t<< ispFormat;\n \n-\tswitch (config.pixelFormat) {\n-\tcase formats::NV12:\n-\tcase formats::NV21:\n-\t\tispFormat.mbus_code = MEDIA_BUS_FMT_YUYV8_1_5X8;\n-\t\tbreak;\n-\tdefault:\n-\t\tispFormat.mbus_code = MEDIA_BUS_FMT_YUYV8_2X8;\n-\t\tbreak;\n-\t}\n+\t/*\n+\t * The configuration has been validated, the pixel format is guaranteed\n+\t * to be supported and thus found in formatToMediaBus.\n+\t */\n+\tispFormat.mbus_code = formatToMediaBus.at(config.pixelFormat);\n \n \tret = resizer_->setFormat(1, &ispFormat);\n \tif (ret < 0)\n@@ -266,14 +408,25 @@ void RkISP1Path::stop()\n namespace {\n constexpr Size RKISP1_RSZ_MP_SRC_MIN{ 32, 16 };\n constexpr Size RKISP1_RSZ_MP_SRC_MAX{ 4416, 3312 };\n-constexpr std::array<PixelFormat, 6> RKISP1_RSZ_MP_FORMATS{\n+constexpr std::array<PixelFormat, 18> RKISP1_RSZ_MP_FORMATS{\n \tformats::YUYV,\n \tformats::NV16,\n \tformats::NV61,\n \tformats::NV21,\n \tformats::NV12,\n \tformats::R8,\n-\t/* \\todo Add support for RAW formats. */\n+\tformats::SBGGR8,\n+\tformats::SGBRG8,\n+\tformats::SGRBG8,\n+\tformats::SRGGB8,\n+\tformats::SBGGR10,\n+\tformats::SGBRG10,\n+\tformats::SGRBG10,\n+\tformats::SRGGB10,\n+\tformats::SBGGR12,\n+\tformats::SGBRG12,\n+\tformats::SGRBG12,\n+\tformats::SRGGB12,\n };\n \n constexpr Size RKISP1_RSZ_SP_SRC_MIN{ 32, 16 };\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\nindex bf4ad18fbbf2..bdf3f95b95e1 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n@@ -40,7 +40,8 @@ public:\n \tint setEnabled(bool enable) { return link_->setEnabled(enable); }\n \tbool isEnabled() const { return link_->flags() & MEDIA_LNK_FL_ENABLED; }\n \n-\tStreamConfiguration generateConfiguration(const CameraSensor *sensor);\n+\tStreamConfiguration generateConfiguration(const CameraSensor *sensor,\n+\t\t\t\t\t\t StreamRole role);\n \tCameraConfiguration::Status validate(const CameraSensor *sensor,\n \t\t\t\t\t StreamConfiguration *cfg);\n \n", "prefixes": [ "libcamera-devel", "v3", "13/13" ] }