From patchwork Mon Mar 13 09:19:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18385 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 7AC21BE080 for ; Mon, 13 Mar 2023 09:20:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 279826270B; Mon, 13 Mar 2023 10:20:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678699205; bh=fnk8FXPK22xua3Le8vS/sLAF9iAKZiM3KrwNi1CY3Ks=; 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=aQ2TNQHyoD1THLiUxtRKNY8J2f68tGS20oK56QczXhZdQe2fpYEWg/ZyIPZB/VmAa OaaI/Itl2MCGUpeWD+RzLFqKUaSeEdE+H+TaW9y+ozMw1O11J0zbejwVPQv8hQoEs3 0CTIx6aWMhDW/oAaExCHakIqtdJyQmyZ1B7VRcp6KpNsG9TnGRjUbXSbDz0vpy1o/9 Dekl+N7mIzW+t5o+2wSBwO9kvbA+jUc1m02b8A7z9F0URxGRLQxboEPASmzY2HuHk8 0cft4a8uH6788IXj9yhsDqupa5uUG4sAl1bv6dYkwwXL2lmlo2qpcrkRqYUjIqmki0 PZgyuOj3eSkNQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1BB0E62707 for ; Mon, 13 Mar 2023 10:20:03 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gkx8sR9e"; dkim-atps=neutral Received: from uno.homenet.telecomitalia.it (host-79-33-55-183.retail.telecomitalia.it [79.33.55.183]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 40A7D563; Mon, 13 Mar 2023 10:20:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1678699202; bh=fnk8FXPK22xua3Le8vS/sLAF9iAKZiM3KrwNi1CY3Ks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gkx8sR9ebh0va2eKJodQtr8U6J8NoHbiP/N9zYYs/jZUJVh99YPaeKYCh8rt8zjtb LtzGGFgei5mww8kiRV8ec0vrSn4pHIOyDCSkOl9k+YJf/R73OPqGnFUlxIRgj7RE3R 1cw4LEAUVoWkWaVcSJ4Gv2eoi5tMVrj1JllNd2xw= To: libcamera-devel@lists.libcamera.org Date: Mon, 13 Mar 2023 10:19:40 +0100 Message-Id: <20230313091944.9530-3-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230313091944.9530-1-jacopo.mondi@ideasonboard.com> References: <20230313091944.9530-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/6] libcamera: imx8-isi: Break out YUV format selection 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: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" As per the RAW format selection, the media bus format selection procedure relies on the direct association of PixelFormat and media bus code in the formatsMap_ map. As the ISI can generate YUV and RGB formats from any non-Bayer media bus format, break out the YUV/RGB media bus format selection to a separate function. The newly introduced getYuvMediaBusFormat() tests a list of known-supported media bus formats against the list of media bus formats supported by the sensor and tries to prefer media bus codes with the same encoding as the requested PixelFormat. Use the newly introduced function in ISICameraConfiguration::validateYuv() to make sure the sensor can produce a YUV/RGB media bus format. Signed-off-by: Jacopo Mondi Reviewed-by: Paul Elder Reviewed-by: Daniel Scally Tested-by: Daniel Scally Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/imx8-isi/imx8-isi.cpp | 76 ++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp index ffb96e6284f0..390e82b6947f 100644 --- a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp +++ b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp @@ -60,6 +60,7 @@ public: } unsigned int getRawMediaBusFormat(PixelFormat *pixelFormat) const; + unsigned int getYuvMediaBusFormat(PixelFormat *pixelFormat) const; std::unique_ptr sensor_; std::unique_ptr csis_; @@ -255,6 +256,65 @@ unsigned int ISICameraData::getRawMediaBusFormat(PixelFormat *pixelFormat) const return sensorCode; } +/* + * Get a YUV/RGB media bus format from which the ISI can produce a processed + * stream, preferring codes with the same colour encoding as the requested + * pixelformat. + * + * If the sensor does not provide any YUV/RGB media bus format the ISI cannot + * generate any processed pixel format as it cannot debayer. + */ +unsigned int ISICameraData::getYuvMediaBusFormat(PixelFormat *pixelFormat) const +{ + std::vector mbusCodes = sensor_->mbusCodes(); + + /* + * The ISI can produce YUV/RGB pixel formats from any non-RAW Bayer + * media bus formats. + * + * Keep the list in sync with the mxc_isi_bus_formats[] array in + * the ISI driver. + */ + std::vector yuvCodes = { + MEDIA_BUS_FMT_UYVY8_1X16, + MEDIA_BUS_FMT_YUV8_1X24, + MEDIA_BUS_FMT_RGB565_1X16, + MEDIA_BUS_FMT_RGB888_1X24, + }; + + std::sort(mbusCodes.begin(), mbusCodes.end()); + std::sort(yuvCodes.begin(), yuvCodes.end()); + + std::vector supportedCodes; + std::set_intersection(mbusCodes.begin(), mbusCodes.end(), + yuvCodes.begin(), yuvCodes.end(), + std::back_inserter(supportedCodes)); + + if (supportedCodes.empty()) { + LOG(ISI, Warning) << "Cannot find a supported YUV/RGB format"; + *pixelFormat = {}; + + return 0; + } + + /* Prefer codes with the same encoding as the requested pixel format. */ + const PixelFormatInfo &info = PixelFormatInfo::info(*pixelFormat); + for (unsigned int code : supportedCodes) { + if (info.colourEncoding == PixelFormatInfo::ColourEncodingYUV && + (code == MEDIA_BUS_FMT_UYVY8_1X16 || + code == MEDIA_BUS_FMT_YUV8_1X24)) + return code; + + if (info.colourEncoding == PixelFormatInfo::ColourEncodingRGB && + (code == MEDIA_BUS_FMT_RGB565_1X16 || + code == MEDIA_BUS_FMT_RGB888_1X24)) + return code; + } + + /* Otherwise return the first found code. */ + return supportedCodes[0]; +} + /* ----------------------------------------------------------------------------- * Camera Configuration */ @@ -455,6 +515,22 @@ ISICameraConfiguration::validateYuv(std::set &availableStreams, { CameraConfiguration::Status status = Valid; + StreamConfiguration &yuvConfig = config_[0]; + PixelFormat yuvPixelFormat = yuvConfig.pixelFormat; + + /* + * Make sure the sensor can produce a compatible YUV/RGB media bus + * format. If the sensor can only produce RAW Bayer we can only fail + * here as we can't adjust to anything but RAW. + */ + unsigned int yuvMediaBusCode = data_->getYuvMediaBusFormat(&yuvPixelFormat); + if (!yuvMediaBusCode) { + LOG(ISI, Error) << "Cannot adjust pixelformat " + << yuvConfig.pixelFormat; + return Invalid; + } + + /* Adjust all the other streams. */ for (const auto &[i, cfg] : utils::enumerate(config_)) { LOG(ISI, Debug) << "Stream " << i << ": " << cfg.toString();