[{"id":34317,"web_url":"https://patchwork.libcamera.org/comment/34317/","msgid":"<5a170637-0ea1-4a57-9563-9afbab51ffd1@ideasonboard.com>","date":"2025-05-22T09:09:37","subject":"Re: [PATCH v5 08/12] libcamera: simple: Consider raw output\n\tconfigurations","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n\n2025. 05. 20. 14:31 keltezéssel, Milan Zamazal írta:\n> When generating simple pipeline configuration, raw output configurations\n> are generated but later filtered out.  Let's include processed and/or\n> raw output configurations depending on the requested stream roles.\n> \n> Raw and processed formats are handled separately.  The intention is that\n> in case both raw and processed formats are requested then the raw\n> formats should be left intact to the extent possible and not be\n> influenced by the processed formats (implying that raw parameters\n> compatible with the processed output requirements must be requested by\n> the application).\n> \n> Raw output configurations are identified by colorSpace being set to\n> ColorSpace::Raw.\n> \n> This is another preparatory patch without making raw outputs working.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>   src/libcamera/pipeline/simple/simple.cpp | 71 ++++++++++++++----------\n>   1 file changed, 43 insertions(+), 28 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\n> index 78a76f34..12fd28fa 100644\n> --- a/src/libcamera/pipeline/simple/simple.cpp\n> +++ b/src/libcamera/pipeline/simple/simple.cpp\n> @@ -1322,37 +1322,50 @@ SimplePipelineHandler::generateConfiguration(Camera *camera, Span<const StreamRo\n>   \t\t\tconfig->processedRequested_ = true;\n>   \t\t}\n>   \n> -\t/* Create the formats map. */\n> -\tstd::map<PixelFormat, std::vector<SizeRange>> formats;\n> +\t/* Create the formats maps. */\n> +\tstd::map<PixelFormat, std::vector<SizeRange>> processedFormats;\n> +\tstd::map<PixelFormat, std::vector<SizeRange>> rawFormats;\n>   \n> -\tconst bool rawOnly = std::all_of(data->configs_.cbegin(),\n> -\t\t\t\t\t data->configs_.cend(),\n> -\t\t\t\t\t [](const auto &c) { return c.raw; });\n>   \tfor (const SimpleCameraData::Configuration &cfg : data->configs_)\n> -\t\tif (!cfg.raw || rawOnly)\n> -\t\t\tfor (PixelFormat format : cfg.outputFormats)\n> -\t\t\t\tformats[format].push_back(cfg.outputSizes);\n> -\n> -\t/* Sort the sizes and merge any consecutive overlapping ranges. */\n> -\tfor (auto &[format, sizes] : formats) {\n> -\t\tstd::sort(sizes.begin(), sizes.end(),\n> -\t\t\t  [](SizeRange &a, SizeRange &b) {\n> -\t\t\t\t  return a.min < b.min;\n> -\t\t\t  });\n> -\n> -\t\tauto cur = sizes.begin();\n> -\t\tauto next = cur;\n> -\n> -\t\twhile (++next != sizes.end()) {\n> -\t\t\tif (cur->max.width >= next->min.width &&\n> -\t\t\t    cur->max.height >= next->min.height)\n> -\t\t\t\tcur->max = next->max;\n> -\t\t\telse if (++cur != next)\n> -\t\t\t\t*cur = *next;\n> -\t\t}\n> +\t\tfor (PixelFormat format : cfg.outputFormats)\n> +\t\t\t(cfg.raw ? rawFormats : processedFormats)[format].push_back(cfg.outputSizes);\n>   \n> -\t\tsizes.erase(++cur, sizes.end());\n> +\tif (config->processedRequested_ && processedFormats.empty()) {\n> +\t\tLOG(SimplePipeline, Error)\n> +\t\t\t<< \"Processed stream requsted but no corresponding output configuration found\";\n> +\t\treturn nullptr;\n>   \t}\n> +\tif (config->rawRequested_ && rawFormats.empty()) {\n> +\t\tLOG(SimplePipeline, Error)\n> +\t\t\t<< \"Raw stream requsted but no corresponding output configuration found\";\n> +\t\treturn nullptr;\n> +\t}\n> +\n> +\tauto setUpFormatSizes = [](std::map<PixelFormat, std::vector<SizeRange>> &formats) {\n> +\t\t/* Sort the sizes and merge any consecutive overlapping ranges. */\n> +\n> +\t\tfor (auto &[format, sizes] : formats) {\n> +\t\t\tstd::sort(sizes.begin(), sizes.end(),\n> +\t\t\t\t  [](SizeRange &a, SizeRange &b) {\n> +\t\t\t\t\t  return a.min < b.min;\n> +\t\t\t\t  });\n> +\n> +\t\t\tauto cur = sizes.begin();\n> +\t\t\tauto next = cur;\n> +\n> +\t\t\twhile (++next != sizes.end()) {\n> +\t\t\t\tif (cur->max.width >= next->min.width &&\n> +\t\t\t\t    cur->max.height >= next->min.height)\n> +\t\t\t\t\tcur->max = next->max;\n> +\t\t\t\telse if (++cur != next)\n> +\t\t\t\t\t*cur = *next;\n> +\t\t\t}\n> +\n> +\t\t\tsizes.erase(++cur, sizes.end());\n> +\t\t}\n> +\t};\n> +\tsetUpFormatSizes(processedFormats);\n> +\tsetUpFormatSizes(rawFormats);\n>   \n>   \t/*\n>   \t * Create the stream configurations. Take the first entry in the formats\n> @@ -1361,11 +1374,13 @@ SimplePipelineHandler::generateConfiguration(Camera *camera, Span<const StreamRo\n>   \t * \\todo Implement a better way to pick the default format\n>   \t */\n>   \tfor (StreamRole role : roles) {\n> +\t\tbool raw = (role == StreamRole::Raw);\n> +\t\tauto formats = (raw ? rawFormats : processedFormats);\n\nThis makes a copy, can you do `const auto &formats = ...`?\n\n\nRegards,\nBarnabás Pőcze\n\n\n>   \t\tStreamConfiguration cfg{ StreamFormats{ formats } };\n>   \t\tcfg.pixelFormat = formats.begin()->first;\n>   \t\tcfg.size = formats.begin()->second[0].max;\n>   \n> -\t\tif (role == StreamRole::Raw)\n> +\t\tif (raw)\n>   \t\t\tcfg.colorSpace = ColorSpace::Raw;\n>   \t\telse if (data->swIsp_)\n>   \t\t\tcfg.colorSpace = ColorSpace::Srgb;","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 9C205BD78E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 22 May 2025 09:09:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 89BBA68D92;\n\tThu, 22 May 2025 11:09:42 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DF10168D7A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 22 May 2025 11:09:40 +0200 (CEST)","from [192.168.33.22] (185.221.141.78.nat.pool.zt.hu\n\t[185.221.141.78])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id AB71956D;\n\tThu, 22 May 2025 11:09:18 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Ld2ylRLT\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1747904958;\n\tbh=v4pQLMi7copG0Gr+svoAagAEMNXaVyfkFDWm9aEzdrc=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=Ld2ylRLTAHY6ouMjQVWIoV8eWXdaKPFcPMyoTvs99Md/2ka+cKNfaF673xmLjneCR\n\t2h5QQdljDJWEauxZvMaG4CYcRqHWJ2FDl68nPRBGo4hReCTQW70RzvgYBjOxHbW1xn\n\tV/cJJipJ/HIUx72EMyhW7JDk7dOcRx7G7qhoBvS8=","Message-ID":"<5a170637-0ea1-4a57-9563-9afbab51ffd1@ideasonboard.com>","Date":"Thu, 22 May 2025 11:09:37 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v5 08/12] libcamera: simple: Consider raw output\n\tconfigurations","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Cc":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>","References":"<20250520123158.44237-1-mzamazal@redhat.com>\n\t<20250520123158.44237-9-mzamazal@redhat.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20250520123158.44237-9-mzamazal@redhat.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]