From patchwork Fri Oct 29 13:23:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 14429 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 12EF8C324E for ; Fri, 29 Oct 2021 13:23:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C40B4600C1; Fri, 29 Oct 2021 15:23:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="owcw/i51"; dkim-atps=neutral Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A230600C9 for ; Fri, 29 Oct 2021 15:23:50 +0200 (CEST) Received: by mail-wr1-x430.google.com with SMTP id k7so16079919wrd.13 for ; Fri, 29 Oct 2021 06:23:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TE3X+BIbROe2GXpvAy5L/7MmT1/6LP/Ws9oGo2jUKTo=; b=owcw/i51upm6ZwpDvExzATk5iZtbINRGC9wxXDRQYahdQQ2XZrgCNa6bLmDUR49SNF yM59+Lx6Uu6PEYa/GrTvyCg5M8Xvaw55UDQzgaEaqKezv+MMCBxz8p08bkZCa/DJ78U1 Q9W7EBK+twiCfqZ6Bf+1iroz7YlJlPr02Qv44GGFuYpW3gbk5JKyHLyJTrhV6+Im6Zh0 6Arz9Bdji1soh8s8oGnSYnt3o/hBgE233InTQvCyknW7hIpQhRQKq4MpbA2FYLgd+M9k ZlydMJ7uOhJHxZYCTlzNGy/j8NE65pyfN6yCYaEgjrMPQEClt2DJsKJuaYeZAGCJ8pVj vzrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TE3X+BIbROe2GXpvAy5L/7MmT1/6LP/Ws9oGo2jUKTo=; b=67Mj/c+q/3NUXYnM5q82E+qIwBUTI4frv3xMdLInB+DFD+J7qVnPmg4/0jsxVs/Z69 gMNLnWGhXdCoVT3V5FvAj+mK6Z7L95pIwD/WuxBWOEef5xnzo8sdfdhzpqYIRHhSfTwX RRqwlcZ+fLCFfY88bwQik11ptT8sMrRy2424co7gCOf/oowrPdPi52an36yM2ugnfmVd WU7Q1noVcEG4vGwBvAo0vSSKCv4fnlQEakzzSnvGCNsICE56a/C9a7q1/oLBwnKTUtSx EXYM0OALf2lT6eBuGFdDglwZ3QPe6gj5Jup1d7HbSk13bScd7biRrpz2mtunZUxQ07f/ hF/g== X-Gm-Message-State: AOAM530M/cbRX+vnvZxO/hJBSoIthB9ecMhBC1dk7+3hZWORgts4lJTL 2gcPOi9Q7YLFWlw9xMflz5/oIob7RK0wDg== X-Google-Smtp-Source: ABdhPJz6oAkmAgoi165clRRQZiE21Yn4BdFBMQYVVsBrenZWqeUHBUy8KgFk5c9xMXL0kVMRJli4/w== X-Received: by 2002:a5d:64a3:: with SMTP id m3mr14393053wrp.393.1635513829496; Fri, 29 Oct 2021 06:23:49 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:1ce1:9965:4328:89c4]) by smtp.gmail.com with ESMTPSA id l7sm111934wrf.31.2021.10.29.06.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Oct 2021 06:23:49 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Fri, 29 Oct 2021 14:23:41 +0100 Message-Id: <20211029132343.1629-6-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211029132343.1629-1-david.plowman@raspberrypi.com> References: <20211029132343.1629-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 5/7] libcamera: Support passing ColorSpaces to V4L2 subdevices 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" The ColorSpace from the StreamConfiguration is now handled appropriately in the V4L2Subdevice. Signed-off-by: David Plowman --- include/libcamera/internal/v4l2_subdevice.h | 2 ++ src/libcamera/camera_sensor.cpp | 1 + src/libcamera/v4l2_subdevice.cpp | 37 ++++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 97b89fb9..f3ab8454 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -14,6 +14,7 @@ #include #include +#include #include #include "libcamera/internal/formats.h" @@ -27,6 +28,7 @@ class MediaDevice; struct V4L2SubdeviceFormat { uint32_t mbus_code; Size size; + ColorSpace colorSpace; const std::string toString() const; uint8_t bitsPerPixel() const; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 9fdb8c09..6fcd1c1d 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -613,6 +613,7 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector &mbu V4L2SubdeviceFormat format{ .mbus_code = bestCode, .size = *bestSize, + .colorSpace = ColorSpace::Raw, }; return format; diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 023e2328..8896e9b0 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -168,6 +168,18 @@ const std::map formatInfoMap = { * \brief The image size in pixels */ +/** + * \var V4L2SubdeviceFormat::colorSpace + * \brief The color space of the pixels + * + * When setting or trying a format, passing in "Undefined" fields in the + * ColorSpace is not recommended because the driver will then make an + * arbitrary choice of its own. Choices made by the driver will be + * passed back in the normal way, though note that "Undefined" values can + * be returned if the device has chosen something that the ColorSpace + * cannot represent. + */ + /** * \brief Assemble and return a string describing the format * \return A string describing the V4L2SubdeviceFormat @@ -400,6 +412,12 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format, format->size.height = subdevFmt.format.height; format->mbus_code = subdevFmt.format.code; + format->colorSpace = toColorSpace(subdevFmt.format); + if (!format->colorSpace.isFullyDefined()) + LOG(V4L2, Warning) + << "Retrieved undefined color space: " + << format->colorSpace.toString(); + return 0; } @@ -418,6 +436,11 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format, int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, Whence whence) { + if (!format->colorSpace.isFullyDefined()) + LOG(V4L2, Error) + << "Trying to set undefined color space: " + << format->colorSpace.toString(); + struct v4l2_subdev_format subdevFmt = {}; subdevFmt.which = whence == ActiveFormat ? V4L2_SUBDEV_FORMAT_ACTIVE : V4L2_SUBDEV_FORMAT_TRY; @@ -427,7 +450,13 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, subdevFmt.format.code = format->mbus_code; subdevFmt.format.field = V4L2_FIELD_NONE; - int ret = ioctl(VIDIOC_SUBDEV_S_FMT, &subdevFmt); + int ret = fromColorSpace(format->colorSpace, subdevFmt.format); + if (ret < 0) + LOG(V4L2, Warning) + << "Setting color space unrecognised by V4L2: " + << format->colorSpace.toString(); + + ret = ioctl(VIDIOC_SUBDEV_S_FMT, &subdevFmt); if (ret) { LOG(V4L2, Error) << "Unable to set format on pad " << pad @@ -439,6 +468,12 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, format->size.height = subdevFmt.format.height; format->mbus_code = subdevFmt.format.code; + format->colorSpace = toColorSpace(subdevFmt.format); + if (!format->colorSpace.isFullyDefined()) + LOG(V4L2, Warning) + << "Undefined color space has been set: " + << format->colorSpace.toString(); + return 0; }