[{"id":21754,"web_url":"https://patchwork.libcamera.org/comment/21754/","msgid":"<20211210145205.zn2z5qsp7mdsoluc@uno.localdomain>","date":"2021-12-10T14:52:05","subject":"Re: [libcamera-devel] [PATCH v12 8/8] libcamera: pipeline:\n\traspberrypi: Support color spaces","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi David,\n\nOn Fri, Dec 10, 2021 at 02:44:24PM +0000, David Plowman wrote:\n> The Raspberry Pi pipeline handler now sets color spaces correctly.\n>\n> In generateConfiguration() it sets them to reasonable default values\n> based on the stream role.\n>\n> validate() now calls validateColorSpaces() to ensure that the\n> requested color spaces are sensible, before proceeding to check what\n> the hardware can deliver.\n>\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> Reviewed-by: Naushir Patuck <naush@raspberrypi.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  .../pipeline/raspberrypi/raspberrypi.cpp      | 40 +++++++++++++++++++\n>  1 file changed, 40 insertions(+)\n>\n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index 86851ac4..eb74d96c 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -96,6 +96,7 @@ V4L2DeviceFormat toV4L2DeviceFormat(const V4L2SubdeviceFormat &format,\n>\n>  \tdeviceFormat.fourcc = V4L2PixelFormat::fromPixelFormat(pix);\n>  \tdeviceFormat.size = format.size;\n> +\tdeviceFormat.colorSpace = format.colorSpace;\n>  \treturn deviceFormat;\n>  }\n>\n> @@ -132,6 +133,7 @@ V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size &\n>  {\n>  \tdouble bestScore = std::numeric_limits<double>::max(), score;\n>  \tV4L2SubdeviceFormat bestFormat;\n> +\tbestFormat.colorSpace = ColorSpace::Raw;\n>\n>  \tconstexpr float penaltyAr = 1500.0;\n>  \tconstexpr float penaltyBitDepth = 500.0;\n> @@ -329,6 +331,8 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n>  \tif (config_.empty())\n>  \t\treturn Invalid;\n>\n> +\tstatus = validateColorSpaces(ColorSpaceFlag::StreamsShareColorSpace);\n> +\n>  \t/*\n>  \t * What if the platform has a non-90 degree rotation? We can't even\n>  \t * \"adjust\" the configuration and carry on. Alternatively, raising an\n> @@ -496,11 +500,25 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n>  \t\tV4L2DeviceFormat format;\n>  \t\tformat.fourcc = V4L2PixelFormat::fromPixelFormat(cfg.pixelFormat);\n>  \t\tformat.size = cfg.size;\n> +\t\tformat.colorSpace = cfg.colorSpace;\n> +\n> +\t\tLOG(RPI, Debug)\n> +\t\t\t<< \"Try color space \" << ColorSpace::toString(cfg.colorSpace);\n>\n>  \t\tint ret = dev->tryFormat(&format);\n>  \t\tif (ret)\n>  \t\t\treturn Invalid;\n>\n> +\t\tif (!format.colorSpace || cfg.colorSpace != format.colorSpace) {\n\nWhat if format.colorSpace was nullopt before validate ?\nIsn't it enough to check for cfg.colorSpace != format.colorSpace ?\n\nIf this is otherwise intended:\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n   j\n\n\n> +\t\t\tstatus = Adjusted;\n> +\t\t\tLOG(RPI, Debug)\n> +\t\t\t\t<< \"Color space changed from \"\n> +\t\t\t\t<< ColorSpace::toString(cfg.colorSpace) << \" to \"\n> +\t\t\t\t<< ColorSpace::toString(format.colorSpace);\n> +\t\t}\n> +\n> +\t\tcfg.colorSpace = format.colorSpace;\n> +\n>  \t\tcfg.stride = format.planes[0].bpl;\n>  \t\tcfg.frameSize = format.planes[0].size;\n>\n> @@ -524,6 +542,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n>  \tPixelFormat pixelFormat;\n>  \tV4L2VideoDevice::Formats fmts;\n>  \tSize size;\n> +\tstd::optional<ColorSpace> colorSpace;\n>\n>  \tif (roles.empty())\n>  \t\treturn config;\n> @@ -539,6 +558,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n>  \t\t\tpixelFormat = mbusCodeToPixelFormat(sensorFormat.mbus_code,\n>  \t\t\t\t\t\t\t    BayerFormat::Packing::CSI2);\n>  \t\t\tASSERT(pixelFormat.isValid());\n> +\t\t\tcolorSpace = ColorSpace::Raw;\n>  \t\t\tbufferCount = 2;\n>  \t\t\trawCount++;\n>  \t\t\tbreak;\n> @@ -546,6 +566,12 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n>  \t\tcase StreamRole::StillCapture:\n>  \t\t\tfmts = data->isp_[Isp::Output0].dev()->formats();\n>  \t\t\tpixelFormat = formats::NV12;\n> +\t\t\t/*\n> +\t\t\t * Still image codecs usually expect the JPEG color space.\n> +\t\t\t * Even RGB codecs will be fine as the RGB we get with the\n> +\t\t\t * JPEG color space is the same as sRGB.\n> +\t\t\t */\n> +\t\t\tcolorSpace = ColorSpace::Jpeg;\n>  \t\t\t/* Return the largest sensor resolution. */\n>  \t\t\tsize = sensorSize;\n>  \t\t\tbufferCount = 1;\n> @@ -563,6 +589,11 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n>  \t\t\t */\n>  \t\t\tfmts = data->isp_[Isp::Output0].dev()->formats();\n>  \t\t\tpixelFormat = formats::YUV420;\n> +\t\t\t/*\n> +\t\t\t * Choose a color space appropriate for video recording.\n> +\t\t\t * Rec.709 will be a good default for HD resolutions.\n> +\t\t\t */\n> +\t\t\tcolorSpace = ColorSpace::Rec709;\n>  \t\t\tsize = { 1920, 1080 };\n>  \t\t\tbufferCount = 4;\n>  \t\t\toutCount++;\n> @@ -571,6 +602,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n>  \t\tcase StreamRole::Viewfinder:\n>  \t\t\tfmts = data->isp_[Isp::Output0].dev()->formats();\n>  \t\t\tpixelFormat = formats::ARGB8888;\n> +\t\t\tcolorSpace = ColorSpace::Jpeg;\n>  \t\t\tsize = { 800, 600 };\n>  \t\t\tbufferCount = 4;\n>  \t\t\toutCount++;\n> @@ -617,6 +649,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n>  \t\tStreamConfiguration cfg(formats);\n>  \t\tcfg.size = size;\n>  \t\tcfg.pixelFormat = pixelFormat;\n> +\t\tcfg.colorSpace = colorSpace;\n>  \t\tcfg.bufferCount = bufferCount;\n>  \t\tconfig->addConfiguration(cfg);\n>  \t}\n> @@ -724,6 +757,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n>  \t\tV4L2PixelFormat fourcc = V4L2PixelFormat::fromPixelFormat(cfg.pixelFormat);\n>  \t\tformat.size = cfg.size;\n>  \t\tformat.fourcc = fourcc;\n> +\t\tformat.colorSpace = cfg.colorSpace;\n>\n>  \t\tLOG(RPI, Debug) << \"Setting \" << stream->name() << \" to \"\n>  \t\t\t\t<< format.toString();\n> @@ -739,6 +773,10 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n>  \t\t\treturn -EINVAL;\n>  \t\t}\n>\n> +\t\tLOG(RPI, Debug)\n> +\t\t\t<< \"Stream \" << stream->name() << \" has color space \"\n> +\t\t\t<< ColorSpace::toString(cfg.colorSpace);\n> +\n>  \t\tcfg.setStream(stream);\n>  \t\tstream->setExternal(true);\n>\n> @@ -763,6 +801,8 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n>  \t\tformat = {};\n>  \t\tformat.size = maxSize;\n>  \t\tformat.fourcc = V4L2PixelFormat::fromPixelFormat(formats::YUV420);\n> +\t\t/* No one asked for output, so the color space doesn't matter. */\n> +\t\tformat.colorSpace = ColorSpace::Jpeg;\n>  \t\tret = data->isp_[Isp::Output0].dev()->setFormat(&format);\n>  \t\tif (ret) {\n>  \t\t\tLOG(RPI, Error)\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 87832BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 10 Dec 2021 14:51:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D666C60890;\n\tFri, 10 Dec 2021 15:51:16 +0100 (CET)","from relay10.mail.gandi.net (relay10.mail.gandi.net\n\t[217.70.178.230])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2F5E760868\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 10 Dec 2021 15:51:15 +0100 (CET)","(Authenticated sender: jacopo@jmondi.org)\n\tby relay10.mail.gandi.net (Postfix) with ESMTPSA id 7F0B6240010;\n\tFri, 10 Dec 2021 14:51:13 +0000 (UTC)"],"Date":"Fri, 10 Dec 2021 15:52:05 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"David Plowman <david.plowman@raspberrypi.com>","Message-ID":"<20211210145205.zn2z5qsp7mdsoluc@uno.localdomain>","References":"<20211210144424.14747-1-david.plowman@raspberrypi.com>\n\t<20211210144424.14747-9-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211210144424.14747-9-david.plowman@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v12 8/8] libcamera: pipeline:\n\traspberrypi: Support color spaces","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>"}},{"id":21756,"web_url":"https://patchwork.libcamera.org/comment/21756/","msgid":"<CAHW6GYJvQjKJnbVvOb_evk8abnkgS9dvA6ThhcpGjWLS1-5sYw@mail.gmail.com>","date":"2021-12-10T15:08:03","subject":"Re: [libcamera-devel] [PATCH v12 8/8] libcamera: pipeline:\n\traspberrypi: Support color spaces","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"content":"Hi Jacopo\n\nThanks for looking at this again.\n\nOn Fri, 10 Dec 2021 at 14:51, Jacopo Mondi <jacopo@jmondi.org> wrote:\n>\n> Hi David,\n>\n> On Fri, Dec 10, 2021 at 02:44:24PM +0000, David Plowman wrote:\n> > The Raspberry Pi pipeline handler now sets color spaces correctly.\n> >\n> > In generateConfiguration() it sets them to reasonable default values\n> > based on the stream role.\n> >\n> > validate() now calls validateColorSpaces() to ensure that the\n> > requested color spaces are sensible, before proceeding to check what\n> > the hardware can deliver.\n> >\n> > Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> > Reviewed-by: Naushir Patuck <naush@raspberrypi.com>\n> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  .../pipeline/raspberrypi/raspberrypi.cpp      | 40 +++++++++++++++++++\n> >  1 file changed, 40 insertions(+)\n> >\n> > diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > index 86851ac4..eb74d96c 100644\n> > --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > @@ -96,6 +96,7 @@ V4L2DeviceFormat toV4L2DeviceFormat(const V4L2SubdeviceFormat &format,\n> >\n> >       deviceFormat.fourcc = V4L2PixelFormat::fromPixelFormat(pix);\n> >       deviceFormat.size = format.size;\n> > +     deviceFormat.colorSpace = format.colorSpace;\n> >       return deviceFormat;\n> >  }\n> >\n> > @@ -132,6 +133,7 @@ V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size &\n> >  {\n> >       double bestScore = std::numeric_limits<double>::max(), score;\n> >       V4L2SubdeviceFormat bestFormat;\n> > +     bestFormat.colorSpace = ColorSpace::Raw;\n> >\n> >       constexpr float penaltyAr = 1500.0;\n> >       constexpr float penaltyBitDepth = 500.0;\n> > @@ -329,6 +331,8 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n> >       if (config_.empty())\n> >               return Invalid;\n> >\n> > +     status = validateColorSpaces(ColorSpaceFlag::StreamsShareColorSpace);\n> > +\n> >       /*\n> >        * What if the platform has a non-90 degree rotation? We can't even\n> >        * \"adjust\" the configuration and carry on. Alternatively, raising an\n> > @@ -496,11 +500,25 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n> >               V4L2DeviceFormat format;\n> >               format.fourcc = V4L2PixelFormat::fromPixelFormat(cfg.pixelFormat);\n> >               format.size = cfg.size;\n> > +             format.colorSpace = cfg.colorSpace;\n> > +\n> > +             LOG(RPI, Debug)\n> > +                     << \"Try color space \" << ColorSpace::toString(cfg.colorSpace);\n> >\n> >               int ret = dev->tryFormat(&format);\n> >               if (ret)\n> >                       return Invalid;\n> >\n> > +             if (!format.colorSpace || cfg.colorSpace != format.colorSpace) {\n>\n> What if format.colorSpace was nullopt before validate ?\n> Isn't it enough to check for cfg.colorSpace != format.colorSpace ?\n>\n> If this is otherwise intended:\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n>\n> Thanks\n>    j\n\nYes, perhaps I've been fiddling very slightly with all this for just a\nbit too long. I guess one might just drop the \"format.colorSpace ||\"\nfrom the line above (as you suggest) and it would be strictly correct\n(and fine).\n\nLaurent, is that fixable-while-applying or would another version of\nthis specific patch be better?\n\nThanks\nDavid\n\n>\n>\n> > +                     status = Adjusted;\n> > +                     LOG(RPI, Debug)\n> > +                             << \"Color space changed from \"\n> > +                             << ColorSpace::toString(cfg.colorSpace) << \" to \"\n> > +                             << ColorSpace::toString(format.colorSpace);\n> > +             }\n> > +\n> > +             cfg.colorSpace = format.colorSpace;\n> > +\n> >               cfg.stride = format.planes[0].bpl;\n> >               cfg.frameSize = format.planes[0].size;\n> >\n> > @@ -524,6 +542,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n> >       PixelFormat pixelFormat;\n> >       V4L2VideoDevice::Formats fmts;\n> >       Size size;\n> > +     std::optional<ColorSpace> colorSpace;\n> >\n> >       if (roles.empty())\n> >               return config;\n> > @@ -539,6 +558,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n> >                       pixelFormat = mbusCodeToPixelFormat(sensorFormat.mbus_code,\n> >                                                           BayerFormat::Packing::CSI2);\n> >                       ASSERT(pixelFormat.isValid());\n> > +                     colorSpace = ColorSpace::Raw;\n> >                       bufferCount = 2;\n> >                       rawCount++;\n> >                       break;\n> > @@ -546,6 +566,12 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n> >               case StreamRole::StillCapture:\n> >                       fmts = data->isp_[Isp::Output0].dev()->formats();\n> >                       pixelFormat = formats::NV12;\n> > +                     /*\n> > +                      * Still image codecs usually expect the JPEG color space.\n> > +                      * Even RGB codecs will be fine as the RGB we get with the\n> > +                      * JPEG color space is the same as sRGB.\n> > +                      */\n> > +                     colorSpace = ColorSpace::Jpeg;\n> >                       /* Return the largest sensor resolution. */\n> >                       size = sensorSize;\n> >                       bufferCount = 1;\n> > @@ -563,6 +589,11 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n> >                        */\n> >                       fmts = data->isp_[Isp::Output0].dev()->formats();\n> >                       pixelFormat = formats::YUV420;\n> > +                     /*\n> > +                      * Choose a color space appropriate for video recording.\n> > +                      * Rec.709 will be a good default for HD resolutions.\n> > +                      */\n> > +                     colorSpace = ColorSpace::Rec709;\n> >                       size = { 1920, 1080 };\n> >                       bufferCount = 4;\n> >                       outCount++;\n> > @@ -571,6 +602,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n> >               case StreamRole::Viewfinder:\n> >                       fmts = data->isp_[Isp::Output0].dev()->formats();\n> >                       pixelFormat = formats::ARGB8888;\n> > +                     colorSpace = ColorSpace::Jpeg;\n> >                       size = { 800, 600 };\n> >                       bufferCount = 4;\n> >                       outCount++;\n> > @@ -617,6 +649,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n> >               StreamConfiguration cfg(formats);\n> >               cfg.size = size;\n> >               cfg.pixelFormat = pixelFormat;\n> > +             cfg.colorSpace = colorSpace;\n> >               cfg.bufferCount = bufferCount;\n> >               config->addConfiguration(cfg);\n> >       }\n> > @@ -724,6 +757,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n> >               V4L2PixelFormat fourcc = V4L2PixelFormat::fromPixelFormat(cfg.pixelFormat);\n> >               format.size = cfg.size;\n> >               format.fourcc = fourcc;\n> > +             format.colorSpace = cfg.colorSpace;\n> >\n> >               LOG(RPI, Debug) << \"Setting \" << stream->name() << \" to \"\n> >                               << format.toString();\n> > @@ -739,6 +773,10 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n> >                       return -EINVAL;\n> >               }\n> >\n> > +             LOG(RPI, Debug)\n> > +                     << \"Stream \" << stream->name() << \" has color space \"\n> > +                     << ColorSpace::toString(cfg.colorSpace);\n> > +\n> >               cfg.setStream(stream);\n> >               stream->setExternal(true);\n> >\n> > @@ -763,6 +801,8 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n> >               format = {};\n> >               format.size = maxSize;\n> >               format.fourcc = V4L2PixelFormat::fromPixelFormat(formats::YUV420);\n> > +             /* No one asked for output, so the color space doesn't matter. */\n> > +             format.colorSpace = ColorSpace::Jpeg;\n> >               ret = data->isp_[Isp::Output0].dev()->setFormat(&format);\n> >               if (ret) {\n> >                       LOG(RPI, Error)\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 175EBBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 10 Dec 2021 15:08:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5D661608A1;\n\tFri, 10 Dec 2021 16:08:17 +0100 (CET)","from mail-wr1-x435.google.com (mail-wr1-x435.google.com\n\t[IPv6:2a00:1450:4864:20::435])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 560706088E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 10 Dec 2021 16:08:15 +0100 (CET)","by mail-wr1-x435.google.com with SMTP id a18so15431790wrn.6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 10 Dec 2021 07:08:15 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"l01MuwEs\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=/pTg+8E35PIYvJC6sovOVb2eOVUSsrDP0bPkgMLAme0=;\n\tb=l01MuwEspY+or30ev3GqknUX0HkycELQpJPRsdOTrrVNZRIKzdiain1eVNiEn085VP\n\tqKWtAhLvhz6UquuSfKEvr0w6bQGStIIInmOwIHvV/HK+pwEZ/rbYZDvZ5HjoHpaERM6p\n\te7KxIaHglWsHZRznfYirSirJVBdqzIbFlTq66emU+IMRvDnllMVKs/zSB96R4+uhrL+g\n\teddWPyfOffHbk13lJs9FixmAKTADnciuRFpWr4EV+nkNtec0nqMCZ/3yHAEZcLFVRrzt\n\t496Hczay+xfpIq/y3fQ9B4oOrGGRA3YKpRR6k/wjN6l+ZQ8WF4uncHz4WcvaAd15ke/1\n\t3duQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=/pTg+8E35PIYvJC6sovOVb2eOVUSsrDP0bPkgMLAme0=;\n\tb=BKjno7B4XeYtUxOSIw71nrtR4Wof3XI6HbPfkJhnEk7ICpMCKR1tCc8boAin9c4TmJ\n\t4JlbBTNofE3tKAeSyee7pB3aL6pclrqymqDItvMnUt13m5Mnc1dtBBT/L0tKsipOjqoQ\n\txPplxIhH/fsGHzV8GBYFX4w+SpcIK3YtKBhbAVsz5uYsycrvnvnZTqGWEB7EUAuax8sq\n\tdIPJLqfyehKiB8lW6HDND+RZIg5lic+RqaQQkQyt97ReYsIzYSsA4n7RHu8G7UHDCmtu\n\t8bZGIU7waVL37ov7KF6Dm92Ix3ezHIZvt+CiULnViP3Nl76aUsisw77y1/7GIOBGgtpU\n\txV1g==","X-Gm-Message-State":"AOAM532ZDmF6ZvmoUl7Lfk+1EJU1mvqC383LGS5uGaNNK8iW/GSE7/4q\n\tnitY9JIix362LtoyvtHBlxzB69IL//sNGkfiipM8OtrlkBc=","X-Google-Smtp-Source":"ABdhPJxqt3yMzaf6eIBLv0t3ZM3DjcBy0J6qauwUBMuS+QbetfGkeIutqjn3AkK4hY0f57JWAoVDOLrHiup92yeCZAs=","X-Received":"by 2002:adf:f44e:: with SMTP id\n\tf14mr14875341wrp.37.1639148894656; \n\tFri, 10 Dec 2021 07:08:14 -0800 (PST)","MIME-Version":"1.0","References":"<20211210144424.14747-1-david.plowman@raspberrypi.com>\n\t<20211210144424.14747-9-david.plowman@raspberrypi.com>\n\t<20211210145205.zn2z5qsp7mdsoluc@uno.localdomain>","In-Reply-To":"<20211210145205.zn2z5qsp7mdsoluc@uno.localdomain>","From":"David Plowman <david.plowman@raspberrypi.com>","Date":"Fri, 10 Dec 2021 15:08:03 +0000","Message-ID":"<CAHW6GYJvQjKJnbVvOb_evk8abnkgS9dvA6ThhcpGjWLS1-5sYw@mail.gmail.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH v12 8/8] libcamera: pipeline:\n\traspberrypi: Support color spaces","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>,\n\tlibcamera devel <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>"}},{"id":21764,"web_url":"https://patchwork.libcamera.org/comment/21764/","msgid":"<YbPcHJiuKPJ06NoQ@pendragon.ideasonboard.com>","date":"2021-12-10T23:00:44","subject":"Re: [libcamera-devel] [PATCH v12 8/8] libcamera: pipeline:\n\traspberrypi: Support color spaces","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi David,\n\nOn Fri, Dec 10, 2021 at 03:08:03PM +0000, David Plowman wrote:\n> On Fri, 10 Dec 2021 at 14:51, Jacopo Mondi wrote:\n> > On Fri, Dec 10, 2021 at 02:44:24PM +0000, David Plowman wrote:\n> > > The Raspberry Pi pipeline handler now sets color spaces correctly.\n> > >\n> > > In generateConfiguration() it sets them to reasonable default values\n> > > based on the stream role.\n> > >\n> > > validate() now calls validateColorSpaces() to ensure that the\n> > > requested color spaces are sensible, before proceeding to check what\n> > > the hardware can deliver.\n> > >\n> > > Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> > > Reviewed-by: Naushir Patuck <naush@raspberrypi.com>\n> > > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > > ---\n> > >  .../pipeline/raspberrypi/raspberrypi.cpp      | 40 +++++++++++++++++++\n> > >  1 file changed, 40 insertions(+)\n> > >\n> > > diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > > index 86851ac4..eb74d96c 100644\n> > > --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > > +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > > @@ -96,6 +96,7 @@ V4L2DeviceFormat toV4L2DeviceFormat(const V4L2SubdeviceFormat &format,\n> > >\n> > >       deviceFormat.fourcc = V4L2PixelFormat::fromPixelFormat(pix);\n> > >       deviceFormat.size = format.size;\n> > > +     deviceFormat.colorSpace = format.colorSpace;\n> > >       return deviceFormat;\n> > >  }\n> > >\n> > > @@ -132,6 +133,7 @@ V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size &\n> > >  {\n> > >       double bestScore = std::numeric_limits<double>::max(), score;\n> > >       V4L2SubdeviceFormat bestFormat;\n> > > +     bestFormat.colorSpace = ColorSpace::Raw;\n> > >\n> > >       constexpr float penaltyAr = 1500.0;\n> > >       constexpr float penaltyBitDepth = 500.0;\n> > > @@ -329,6 +331,8 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n> > >       if (config_.empty())\n> > >               return Invalid;\n> > >\n> > > +     status = validateColorSpaces(ColorSpaceFlag::StreamsShareColorSpace);\n> > > +\n> > >       /*\n> > >        * What if the platform has a non-90 degree rotation? We can't even\n> > >        * \"adjust\" the configuration and carry on. Alternatively, raising an\n> > > @@ -496,11 +500,25 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n> > >               V4L2DeviceFormat format;\n> > >               format.fourcc = V4L2PixelFormat::fromPixelFormat(cfg.pixelFormat);\n> > >               format.size = cfg.size;\n> > > +             format.colorSpace = cfg.colorSpace;\n> > > +\n> > > +             LOG(RPI, Debug)\n> > > +                     << \"Try color space \" << ColorSpace::toString(cfg.colorSpace);\n> > >\n> > >               int ret = dev->tryFormat(&format);\n> > >               if (ret)\n> > >                       return Invalid;\n> > >\n> > > +             if (!format.colorSpace || cfg.colorSpace != format.colorSpace) {\n> >\n> > What if format.colorSpace was nullopt before validate ?\n> > Isn't it enough to check for cfg.colorSpace != format.colorSpace ?\n> >\n> > If this is otherwise intended:\n> > Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> \n> Yes, perhaps I've been fiddling very slightly with all this for just a\n> bit too long. I guess one might just drop the \"format.colorSpace ||\"\n> from the line above (as you suggest) and it would be strictly correct\n> (and fine).\n> \n> Laurent, is that fixable-while-applying or would another version of\n> this specific patch be better?\n\nAbsolutely fixable while applying.\n\nThe whole series has been fully reviewed, so I'll queue it for merge.\n\n> > > +                     status = Adjusted;\n> > > +                     LOG(RPI, Debug)\n> > > +                             << \"Color space changed from \"\n> > > +                             << ColorSpace::toString(cfg.colorSpace) << \" to \"\n> > > +                             << ColorSpace::toString(format.colorSpace);\n> > > +             }\n> > > +\n> > > +             cfg.colorSpace = format.colorSpace;\n> > > +\n> > >               cfg.stride = format.planes[0].bpl;\n> > >               cfg.frameSize = format.planes[0].size;\n> > >\n> > > @@ -524,6 +542,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n> > >       PixelFormat pixelFormat;\n> > >       V4L2VideoDevice::Formats fmts;\n> > >       Size size;\n> > > +     std::optional<ColorSpace> colorSpace;\n> > >\n> > >       if (roles.empty())\n> > >               return config;\n> > > @@ -539,6 +558,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n> > >                       pixelFormat = mbusCodeToPixelFormat(sensorFormat.mbus_code,\n> > >                                                           BayerFormat::Packing::CSI2);\n> > >                       ASSERT(pixelFormat.isValid());\n> > > +                     colorSpace = ColorSpace::Raw;\n> > >                       bufferCount = 2;\n> > >                       rawCount++;\n> > >                       break;\n> > > @@ -546,6 +566,12 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n> > >               case StreamRole::StillCapture:\n> > >                       fmts = data->isp_[Isp::Output0].dev()->formats();\n> > >                       pixelFormat = formats::NV12;\n> > > +                     /*\n> > > +                      * Still image codecs usually expect the JPEG color space.\n> > > +                      * Even RGB codecs will be fine as the RGB we get with the\n> > > +                      * JPEG color space is the same as sRGB.\n> > > +                      */\n> > > +                     colorSpace = ColorSpace::Jpeg;\n> > >                       /* Return the largest sensor resolution. */\n> > >                       size = sensorSize;\n> > >                       bufferCount = 1;\n> > > @@ -563,6 +589,11 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n> > >                        */\n> > >                       fmts = data->isp_[Isp::Output0].dev()->formats();\n> > >                       pixelFormat = formats::YUV420;\n> > > +                     /*\n> > > +                      * Choose a color space appropriate for video recording.\n> > > +                      * Rec.709 will be a good default for HD resolutions.\n> > > +                      */\n> > > +                     colorSpace = ColorSpace::Rec709;\n> > >                       size = { 1920, 1080 };\n> > >                       bufferCount = 4;\n> > >                       outCount++;\n> > > @@ -571,6 +602,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n> > >               case StreamRole::Viewfinder:\n> > >                       fmts = data->isp_[Isp::Output0].dev()->formats();\n> > >                       pixelFormat = formats::ARGB8888;\n> > > +                     colorSpace = ColorSpace::Jpeg;\n> > >                       size = { 800, 600 };\n> > >                       bufferCount = 4;\n> > >                       outCount++;\n> > > @@ -617,6 +649,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n> > >               StreamConfiguration cfg(formats);\n> > >               cfg.size = size;\n> > >               cfg.pixelFormat = pixelFormat;\n> > > +             cfg.colorSpace = colorSpace;\n> > >               cfg.bufferCount = bufferCount;\n> > >               config->addConfiguration(cfg);\n> > >       }\n> > > @@ -724,6 +757,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n> > >               V4L2PixelFormat fourcc = V4L2PixelFormat::fromPixelFormat(cfg.pixelFormat);\n> > >               format.size = cfg.size;\n> > >               format.fourcc = fourcc;\n> > > +             format.colorSpace = cfg.colorSpace;\n> > >\n> > >               LOG(RPI, Debug) << \"Setting \" << stream->name() << \" to \"\n> > >                               << format.toString();\n> > > @@ -739,6 +773,10 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n> > >                       return -EINVAL;\n> > >               }\n> > >\n> > > +             LOG(RPI, Debug)\n> > > +                     << \"Stream \" << stream->name() << \" has color space \"\n> > > +                     << ColorSpace::toString(cfg.colorSpace);\n> > > +\n> > >               cfg.setStream(stream);\n> > >               stream->setExternal(true);\n> > >\n> > > @@ -763,6 +801,8 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n> > >               format = {};\n> > >               format.size = maxSize;\n> > >               format.fourcc = V4L2PixelFormat::fromPixelFormat(formats::YUV420);\n> > > +             /* No one asked for output, so the color space doesn't matter. */\n> > > +             format.colorSpace = ColorSpace::Jpeg;\n> > >               ret = data->isp_[Isp::Output0].dev()->setFormat(&format);\n> > >               if (ret) {\n> > >                       LOG(RPI, Error)","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 AC031BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 10 Dec 2021 23:01:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CFBF46088E;\n\tSat, 11 Dec 2021 00:01:16 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 143D960114\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 11 Dec 2021 00:01:15 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5A812BBE;\n\tSat, 11 Dec 2021 00:01:14 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"la71GZ9v\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1639177274;\n\tbh=lVrO41smJ6T6GhiMx7h37I/uCSa9AanBsvJwrVsIr00=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=la71GZ9vuzYPXeCj91nND2o0ITFNr2r/rWMZ4ZDdPgWbtNfzQBHd49v/1eVszQ5uM\n\tqgriRpGeQ5xMH9Yyal9yYe1nZQhhDJKL3dp1P4tGz5vM8R35dfCitTyAwBzTce+m4G\n\tsO9WUGFMVFnB0gYA5dYw/TWtythyP9Ir+V3OTdT0=","Date":"Sat, 11 Dec 2021 01:00:44 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"David Plowman <david.plowman@raspberrypi.com>","Message-ID":"<YbPcHJiuKPJ06NoQ@pendragon.ideasonboard.com>","References":"<20211210144424.14747-1-david.plowman@raspberrypi.com>\n\t<20211210144424.14747-9-david.plowman@raspberrypi.com>\n\t<20211210145205.zn2z5qsp7mdsoluc@uno.localdomain>\n\t<CAHW6GYJvQjKJnbVvOb_evk8abnkgS9dvA6ThhcpGjWLS1-5sYw@mail.gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<CAHW6GYJvQjKJnbVvOb_evk8abnkgS9dvA6ThhcpGjWLS1-5sYw@mail.gmail.com>","Subject":"Re: [libcamera-devel] [PATCH v12 8/8] libcamera: pipeline:\n\traspberrypi: Support color spaces","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>,\n\tlibcamera devel <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>"}}]