From patchwork Fri Nov 26 10:40:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 14801 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 3F64EBF415 for ; Fri, 26 Nov 2021 10:41:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EC98B60560; Fri, 26 Nov 2021 11:41:12 +0100 (CET) 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="iZQrRgiR"; dkim-atps=neutral Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C9CA604FB for ; Fri, 26 Nov 2021 11:41:03 +0100 (CET) Received: by mail-wr1-x429.google.com with SMTP id s13so17706795wrb.3 for ; Fri, 26 Nov 2021 02:41:03 -0800 (PST) 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=KwV+6mm5K3RAv5gTOEBbnCQylbB+KekglD21a7BiaKQ=; b=iZQrRgiR6ZrFPCS4p7NQbtEK41ZZf0ZAjqSrTf/khxdhBGpiyI4Wu9AO95rv5qGSBM aEnyCCda+ykfsE/HwcKLVs44sQXgHmsJwPy9OkWBO6qTxbFz1BKK6mJ8cGah8XyOh74q mqTNrATMcJQegMqGqVx491N7rafzIA9dLhxDjhzVHL+spBRGxOCBcpxjUT9bAnsvKhEH udkqxqyDqKJVwlw78fqLuJQ12jg3qwgGBfBs1pG3w23rlSMqIzDFdpEQrs2R863y50mX oGsWdeia4r73/AM/TQJvkjmK+CIRA8mK+1AAbtur0XnhznAIzRZNP7r9lTJ87JJ7rXWr KEhQ== 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=KwV+6mm5K3RAv5gTOEBbnCQylbB+KekglD21a7BiaKQ=; b=CqoRQHVgmlPmU2FhVZoS9IXpffaUEZlsweCSOTGnITgUejbcFgFj4vNeENudrw9FKV 7SRbAoeitm7CTBlXZxZ1gQBdDDD21Wh9OkwBuh3nJQKZM+MBhPf3/+DoYZW7npfW4Jox L9nlrdG3II38km9t6zI10TShxMF2dHwy0IBdfuz7u46Ror5xxlKBZBF9u+SgDH6DHbNL fZcsW5nMCQZpM2YyYBp/nIARVVzl9wA0zIS+VYlu9ZAu0UiH//2TlVu7x6Ja/5uYXPxH D4D/38+pbHd65RTAsxU/8hIe0yBei17aS9afgOxRMpaPA0EqdND4O1yJ0Wdf/yEfrzkX GdVA== X-Gm-Message-State: AOAM530aVwJNT6ckGJp+sBKj/WNHw+h1U7ATe7oJhyLsNm/G8p9d2Jha /v4LKoyTvUYPZlC25pf3GCbktw== X-Google-Smtp-Source: ABdhPJyMAgCYmxR1GKOQsnsmklzTRbU83Azk+bUxn0GRtZPmZLxJYmCl+ydIc9T+g365++vkn2dmlQ== X-Received: by 2002:adf:f990:: with SMTP id f16mr12778876wrr.128.1637923262920; Fri, 26 Nov 2021 02:41:02 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:e4a2:3070:eea4:e434]) by smtp.gmail.com with ESMTPSA id y7sm5106795wrw.55.2021.11.26.02.41.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Nov 2021 02:41:02 -0800 (PST) From: David Plowman To: Laurent Pinchart , Kieran Bingham , Hans Verkuil , Tomasz Figa , Jacopo Mondi , Naushir Patuck , libcamera-devel@lists.libcamera.org Date: Fri, 26 Nov 2021 10:40:43 +0000 Message-Id: <20211126104045.4756-6-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211126104045.4756-1-david.plowman@raspberrypi.com> References: <20211126104045.4756-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 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 | 25 ++++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 484fcfdd..e6fa451b 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; + std::optional 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..ee450c31 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -168,6 +168,21 @@ const std::map formatInfoMap = { * \brief The image size in pixels */ +/** + * \var V4L2SubdeviceFormat::colorSpace + * \brief The color space of the pixels + * + * The color space of the image. When setting the format this may be + * unset, in which case the driver gets to use its default color space. + * After being set, this value should contain the color space that + * was actually used. If this value is unset, then the color space chosen + * by the driver could not be represented by the ColorSpace class (and + * should probably be added). + * + * It is up to the pipeline handler or application to check if the + * resulting color space is acceptable. + */ + /** * \brief Assemble and return a string describing the format * \return A string describing the V4L2SubdeviceFormat @@ -399,6 +414,7 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format, format->size.width = subdevFmt.format.width; format->size.height = subdevFmt.format.height; format->mbus_code = subdevFmt.format.code; + format->colorSpace = toColorSpace(subdevFmt.format); return 0; } @@ -427,7 +443,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: " + << ColorSpace::toString(format->colorSpace); + + ret = ioctl(VIDIOC_SUBDEV_S_FMT, &subdevFmt); if (ret) { LOG(V4L2, Error) << "Unable to set format on pad " << pad @@ -438,6 +460,7 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, format->size.width = subdevFmt.format.width; format->size.height = subdevFmt.format.height; format->mbus_code = subdevFmt.format.code; + format->colorSpace = toColorSpace(subdevFmt.format); return 0; }