[{"id":21544,"web_url":"https://patchwork.libcamera.org/comment/21544/","msgid":"<20211202101245.o5pn3gmuylsxlfrs@uno.localdomain>","date":"2021-12-02T10:12:45","subject":"Re: [libcamera-devel] [PATCH v8 5/8] libcamera: Add colorSpace\n\tfield to V4L2SubdeviceFormat","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi David,\n\nOn Wed, Dec 01, 2021 at 03:44:31PM +0000, David Plowman wrote:\n> This adds a ColorSpace field to the V4L2SubdeviceFormat so that we can\n> set and request particular color spaces from V4L2.\n>\n> This commit simply adds the field and fixes some occurrences of brace\n> initializers that would otherwise be broken. A subsequent commit will\n> pass and retrieve the value correctly to/from V4l2 itself.\n>\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> ---\n>  include/libcamera/internal/v4l2_subdevice.h |  2 ++\n>  src/libcamera/camera_sensor.cpp             |  1 +\n>  src/libcamera/pipeline/ipu3/cio2.cpp        |  7 +++----\n>  src/libcamera/pipeline/simple/simple.cpp    |  8 ++++++--\n>  src/libcamera/v4l2_subdevice.cpp            | 15 +++++++++++++++\n>  5 files changed, 27 insertions(+), 6 deletions(-)\n>\n> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\n> index 484fcfdd..e6fa451b 100644\n> --- a/include/libcamera/internal/v4l2_subdevice.h\n> +++ b/include/libcamera/internal/v4l2_subdevice.h\n> @@ -14,6 +14,7 @@\n>  #include <libcamera/base/class.h>\n>  #include <libcamera/base/log.h>\n>\n> +#include <libcamera/color_space.h>\n>  #include <libcamera/geometry.h>\n>\n>  #include \"libcamera/internal/formats.h\"\n> @@ -27,6 +28,7 @@ class MediaDevice;\n>  struct V4L2SubdeviceFormat {\n>  \tuint32_t mbus_code;\n>  \tSize size;\n> +\tstd::optional<ColorSpace> colorSpace;\n>\n>  \tconst std::string toString() const;\n>  \tuint8_t bitsPerPixel() const;\n> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\n> index 9fdb8c09..6fcd1c1d 100644\n> --- a/src/libcamera/camera_sensor.cpp\n> +++ b/src/libcamera/camera_sensor.cpp\n\nDoes camera_sensor include color_space.h\n\n> @@ -613,6 +613,7 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector<unsigned int> &mbu\n>  \tV4L2SubdeviceFormat format{\n>  \t\t.mbus_code = bestCode,\n>  \t\t.size = *bestSize,\n> +\t\t.colorSpace = ColorSpace::Raw,\n>  \t};\n>\n>  \treturn format;\n> diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp\n> index 59dda56b..f4e8c663 100644\n> --- a/src/libcamera/pipeline/ipu3/cio2.cpp\n> +++ b/src/libcamera/pipeline/ipu3/cio2.cpp\n> @@ -322,10 +322,9 @@ V4L2SubdeviceFormat CIO2Device::getSensorFormat(const std::vector<unsigned int>\n>  \t\treturn {};\n>  \t}\n>\n> -\tV4L2SubdeviceFormat format{\n> -\t\t.mbus_code = bestCode,\n> -\t\t.size = bestSize,\n> -\t};\n> +\tV4L2SubdeviceFormat format{};\n> +\tformat.mbus_code = bestCode;\n> +\tformat.size = bestSize;\n>\n>  \treturn format;\n>  }\n> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\n> index 701fb4be..a3108fc0 100644\n> --- a/src/libcamera/pipeline/simple/simple.cpp\n> +++ b/src/libcamera/pipeline/simple/simple.cpp\n> @@ -457,7 +457,9 @@ int SimpleCameraData::init()\n>  \t * formats on the video node.\n>  \t */\n>  \tfor (unsigned int code : sensor_->mbusCodes()) {\n> -\t\tV4L2SubdeviceFormat format{ code, sensor_->resolution() };\n> +\t\tV4L2SubdeviceFormat format{};\n> +\t\tformat.mbus_code = code;\n> +\t\tformat.size = sensor_->resolution();\n>\n>  \t\tret = setupFormats(&format, V4L2Subdevice::TryFormat);\n>  \t\tif (ret < 0) {\n> @@ -908,7 +910,9 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)\n>  \t\treturn ret;\n>\n>  \tconst SimpleCameraData::Configuration *pipeConfig = config->pipeConfig();\n> -\tV4L2SubdeviceFormat format{ pipeConfig->code, data->sensor_->resolution() };\n> +\tV4L2SubdeviceFormat format{};\n> +\tformat.mbus_code = pipeConfig->code;\n> +\tformat.size = data->sensor_->resolution();\n>\n>  \tret = data->setupFormats(&format, V4L2Subdevice::ActiveFormat);\n>  \tif (ret < 0)\n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index 023e2328..66e08333 100644\n> --- a/src/libcamera/v4l2_subdevice.cpp\n> +++ b/src/libcamera/v4l2_subdevice.cpp\n> @@ -168,6 +168,21 @@ const std::map<uint32_t, V4L2SubdeviceFormatInfo> formatInfoMap = {\n>   * \\brief The image size in pixels\n>   */\n>\n> +/**\n> + * \\var V4L2SubdeviceFormat::colorSpace\n> + * \\brief The color space of the pixels\n> + *\n> + * The color space of the image. When setting the format this may be\n> + * unset, in which case the driver gets to use its default color space.\n> + * After being set, this value should contain the color space that\n\nWhat do you mean \"After being set\" ?\nDoes this mean \"after validate()\" ? I would drop this, none of the\nother StreamConfiguration fields documents that, it is implicit that\nthe pipeline handler update fields to what it can produce, this is no\nspecial\n\n> + * was actually used. If this value is unset, then the color space chosen\n> + * by the driver could not be represented by the ColorSpace class (and\n> + * should probably be added).\n\nThis (the fact it can be 'unset') is special instead and should be documented\nlike you're doing\n\n> + *\n> + * It is up to the pipeline handler or application to check if the\n> + * resulting color space is acceptable.\n\nThe same happens for, say, the image format. If application get an\nadjusted configuration they should check if the returned config is\ncorrect for them. I would drop this last paragraph.\n\n> + */\n> +\n>  /**\n>   * \\brief Assemble and return a string describing the format\n>   * \\return A string describing the V4L2SubdeviceFormat\n> --\n> 2.30.2\n>","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 ED158BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  2 Dec 2021 10:11:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 04FDE60826;\n\tThu,  2 Dec 2021 11:11:57 +0100 (CET)","from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 834496059E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  2 Dec 2021 11:11:55 +0100 (CET)","(Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id DE18A100011;\n\tThu,  2 Dec 2021 10:11:53 +0000 (UTC)"],"Date":"Thu, 2 Dec 2021 11:12:45 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"David Plowman <david.plowman@raspberrypi.com>","Message-ID":"<20211202101245.o5pn3gmuylsxlfrs@uno.localdomain>","References":"<20211201154434.23127-1-david.plowman@raspberrypi.com>\n\t<20211201154434.23127-6-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211201154434.23127-6-david.plowman@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v8 5/8] libcamera: Add colorSpace\n\tfield to V4L2SubdeviceFormat","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>","Cc":"Tomasz Figa <tfiga@google.com>, libcamera-devel@lists.libcamera.org,\n\tHans Verkuil <hverkuil-cisco@xs4all.nl>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]