[{"id":37000,"web_url":"https://patchwork.libcamera.org/comment/37000/","msgid":"<176374037673.117488.13847592379856408716@isaac-ThinkPad-T16-Gen-2>","date":"2025-11-21T15:52:56","subject":"Re: [PATCH] libcamera: software_isp: Assign colour spaces in\n\tconfigurations","submitter":{"id":215,"url":"https://patchwork.libcamera.org/api/people/215/","name":"Isaac Scott","email":"isaac.scott@ideasonboard.com"},"content":"Hi Milan,\n\nThank you for the patch!\n\nQuoting Milan Zamazal (2025-11-21 15:18:02)\n> StreamConfiguration's should have colorSpace set.  This is not the case\n> in the simple pipeline.  Let's set it there.  This also fixes a crash in\n> `cam' due to accessing an unset colorSpace.\n> \n> We set the colour spaces according to the pixel format.  This is not\n> completely correct because pixel formats and colour spaces are\n> different, although not completely independent, things.  But for the\n> lack of a better practical option to determine the colour space, we use\n> this.\n> \n> Closes: https://gitlab.freedesktop.org/camera/libcamera/-/issues/294\n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>  src/libcamera/pipeline/simple/simple.cpp | 40 ++++++++++++++++++++++++\n>  1 file changed, 40 insertions(+)\n> \n> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\n> index 118b4186c..a8bfe0cf7 100644\n> --- a/src/libcamera/pipeline/simple/simple.cpp\n> +++ b/src/libcamera/pipeline/simple/simple.cpp\n> @@ -25,6 +25,7 @@\n>  #include <libcamera/base/log.h>\n>  \n>  #include <libcamera/camera.h>\n> +#include <libcamera/color_space.h>\n>  #include <libcamera/control_ids.h>\n>  #include <libcamera/request.h>\n>  #include <libcamera/stream.h>\n> @@ -36,6 +37,7 @@\n>  #include \"libcamera/internal/converter.h\"\n>  #include \"libcamera/internal/delayed_controls.h\"\n>  #include \"libcamera/internal/device_enumerator.h\"\n> +#include \"libcamera/internal/formats.h\"\n>  #include \"libcamera/internal/global_configuration.h\"\n>  #include \"libcamera/internal/media_device.h\"\n>  #include \"libcamera/internal/pipeline_handler.h\"\n> @@ -1227,6 +1229,44 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()\n>                         status = Adjusted;\n>                 }\n>  \n> +               /*\n> +                * Best effort to fix the color space. If the color space is not set,\n> +                * set it according to the pixel format, which may not be correct (pixel\n> +                * formats and color spaces are different things, although somewhat\n> +                * related) but we don't have a better option at the moment. Then in any\n> +                * case, perform the standard pixel format based color space adjustment.\n> +                */\n> +               if (!cfg.colorSpace) {\n> +                       const PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat);\n> +                       switch (info.colourEncoding) {\n> +                       case PixelFormatInfo::ColourEncodingRGB:\n> +                               cfg.colorSpace = ColorSpace::Srgb;\n> +                               break;\n> +                       case libcamera::PixelFormatInfo::ColourEncodingYUV:\n> +                               cfg.colorSpace = ColorSpace::Sycc;\n> +                               break;\n\nDoes this need to be libcamera::PixelFormatInfo::ColourEncoding as opposed to the\nPixelFormatInfo::ColourEncoding used above?\n\nIf it does, looks good to me!\n\nReviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\n\n> +                       default:\n> +                               cfg.colorSpace = ColorSpace::Raw;\n> +                       }\n> +                       LOG(SimplePipeline, Debug)\n> +                               << \"Unspecified color space set to \"\n> +                               << cfg.colorSpace.value().toString();\n> +                       /*\n> +                        * Adjust the assigned color space to make sure everything is OK.\n> +                        * Since this is assigning an unspecified color space rather than\n> +                        * adjusting a requested one, changes here shouldn't set the status\n> +                        * to Adjusted.\n> +                        */\n> +                       cfg.colorSpace->adjust(pixelFormat);\n> +               } else {\n> +                       if (cfg.colorSpace->adjust(pixelFormat)) {\n> +                               LOG(SimplePipeline, Debug)\n> +                                       << \"Color space adjusted to \"\n> +                                       << cfg.colorSpace.value().toString();\n> +                               status = Adjusted;\n> +                       }\n> +               }\n> +\n>                 if (!pipeConfig_->outputSizes.contains(cfg.size)) {\n>                         Size adjustedSize = pipeConfig_->captureSize;\n>                         /*\n> -- \n> 2.51.1\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 98315C3333\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 21 Nov 2025 15:53:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BF49B609D8;\n\tFri, 21 Nov 2025 16:53:02 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 55AEA60805\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 21 Nov 2025 16:53:01 +0100 (CET)","from thinkpad.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 465AE66B;\n\tFri, 21 Nov 2025 16:50:54 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"uW1gYZuj\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763740254;\n\tbh=a8zGKDyw9jEzYI2ElHgQcZCUYEhWRR7iKM7kmTJyooc=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=uW1gYZujMcB0rxgP3/QMBycyK5VOql0xneckITA849T80VIi0qERUsTi5IWTM7XAN\n\tekO8RW+W0RIL3t8HhcU/fiRqcx/bW3CjngirfxW3tsySli9OuwAcOreovO1YklR0bu\n\tIVHzOaRdLrDCsSVojW778WQRkRCknpa0rX+J8NRw=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251121151802.80095-1-mzamazal@redhat.com>","References":"<20251121151802.80095-1-mzamazal@redhat.com>","Subject":"Re: [PATCH] libcamera: software_isp: Assign colour spaces in\n\tconfigurations","From":"Isaac Scott <isaac.scott@ideasonboard.com>","Cc":"Milan Zamazal <mzamazal@redhat.com>, Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>, Laurent Pinchart\n\t<laurent.pinchart@ideasonboard.com>, =?utf-8?b?QmFybmFiw6FzIFDFkWN6?=\n\t=?utf-8?q?e?= <barnabas.pocze@ideasonboard.com>, Paul Elder\n\t<paul.elder@ideasonboard.com>, Umang Jain <uajain@igalia.com>","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Date":"Fri, 21 Nov 2025 15:52:56 +0000","Message-ID":"<176374037673.117488.13847592379856408716@isaac-ThinkPad-T16-Gen-2>","User-Agent":"alot/0.10","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":37004,"web_url":"https://patchwork.libcamera.org/comment/37004/","msgid":"<85wm3j8i2w.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2025-11-21T16:29:43","subject":"Re: [PATCH] libcamera: software_isp: Assign colour spaces in\n\tconfigurations","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Hi Isaac,\n\nthank you for review.\n\nIsaac Scott <isaac.scott@ideasonboard.com> writes:\n\n> Hi Milan,\n>\n> Thank you for the patch!\n>\n> Quoting Milan Zamazal (2025-11-21 15:18:02)\n>> StreamConfiguration's should have colorSpace set.  This is not the case\n>> in the simple pipeline.  Let's set it there.  This also fixes a crash in\n>> `cam' due to accessing an unset colorSpace.\n>> \n>> We set the colour spaces according to the pixel format.  This is not\n>> completely correct because pixel formats and colour spaces are\n>> different, although not completely independent, things.  But for the\n>> lack of a better practical option to determine the colour space, we use\n>> this.\n>> \n>> Closes: https://gitlab.freedesktop.org/camera/libcamera/-/issues/294\n>> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n>> ---\n>>  src/libcamera/pipeline/simple/simple.cpp | 40 ++++++++++++++++++++++++\n>>  1 file changed, 40 insertions(+)\n>> \n>> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\n>> index 118b4186c..a8bfe0cf7 100644\n>> --- a/src/libcamera/pipeline/simple/simple.cpp\n>> +++ b/src/libcamera/pipeline/simple/simple.cpp\n>> @@ -25,6 +25,7 @@\n>>  #include <libcamera/base/log.h>\n>>  \n>>  #include <libcamera/camera.h>\n>> +#include <libcamera/color_space.h>\n>>  #include <libcamera/control_ids.h>\n>>  #include <libcamera/request.h>\n>>  #include <libcamera/stream.h>\n>> @@ -36,6 +37,7 @@\n>>  #include \"libcamera/internal/converter.h\"\n>>  #include \"libcamera/internal/delayed_controls.h\"\n>>  #include \"libcamera/internal/device_enumerator.h\"\n>> +#include \"libcamera/internal/formats.h\"\n>>  #include \"libcamera/internal/global_configuration.h\"\n>>  #include \"libcamera/internal/media_device.h\"\n>>  #include \"libcamera/internal/pipeline_handler.h\"\n>> @@ -1227,6 +1229,44 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()\n>>                         status = Adjusted;\n>>                 }\n>>  \n>> +               /*\n>> +                * Best effort to fix the color space. If the color space is not set,\n>> +                * set it according to the pixel format, which may not be correct (pixel\n>> +                * formats and color spaces are different things, although somewhat\n>> +                * related) but we don't have a better option at the moment. Then in any\n>> +                * case, perform the standard pixel format based color space adjustment.\n>> +                */\n>> +               if (!cfg.colorSpace) {\n>> +                       const PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat);\n>> +                       switch (info.colourEncoding) {\n>> +                       case PixelFormatInfo::ColourEncodingRGB:\n>> +                               cfg.colorSpace = ColorSpace::Srgb;\n>> +                               break;\n>> +                       case libcamera::PixelFormatInfo::ColourEncodingYUV:\n>> +                               cfg.colorSpace = ColorSpace::Sycc;\n>> +                               break;\n>\n> Does this need to be libcamera::PixelFormatInfo::ColourEncoding as opposed to the\n> PixelFormatInfo::ColourEncoding used above?\n\nNo, I'll post v2 with the prefix removed.\n\n> If it does, looks good to me!\n>\n> Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\n>\n>> +                       default:\n>> +                               cfg.colorSpace = ColorSpace::Raw;\n>> +                       }\n>> +                       LOG(SimplePipeline, Debug)\n>> +                               << \"Unspecified color space set to \"\n>> +                               << cfg.colorSpace.value().toString();\n>> +                       /*\n>> +                        * Adjust the assigned color space to make sure everything is OK.\n>> +                        * Since this is assigning an unspecified color space rather than\n>> +                        * adjusting a requested one, changes here shouldn't set the status\n>> +                        * to Adjusted.\n>> +                        */\n>> +                       cfg.colorSpace->adjust(pixelFormat);\n>> +               } else {\n>> +                       if (cfg.colorSpace->adjust(pixelFormat)) {\n>> +                               LOG(SimplePipeline, Debug)\n>> +                                       << \"Color space adjusted to \"\n>> +                                       << cfg.colorSpace.value().toString();\n>> +                               status = Adjusted;\n>> +                       }\n>> +               }\n>> +\n>>                 if (!pipeConfig_->outputSizes.contains(cfg.size)) {\n>>                         Size adjustedSize = pipeConfig_->captureSize;\n>>                         /*\n>> -- \n>> 2.51.1\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 D574BC3333\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 21 Nov 2025 16:29:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 18D3560A80;\n\tFri, 21 Nov 2025 17:29:52 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 993FE60805\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 21 Nov 2025 17:29:50 +0100 (CET)","from mail-wr1-f69.google.com (mail-wr1-f69.google.com\n\t[209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-549-BGPuf4C_PCOjj1AivcLoZA-1; Fri, 21 Nov 2025 11:29:47 -0500","by mail-wr1-f69.google.com with SMTP id\n\tffacd0b85a97d-429cd1d0d98so1795243f8f.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 21 Nov 2025 08:29:47 -0800 (PST)","from mzamazal-thinkpadp1gen7.tpbc.csb\n\t(ip-77-48-47-2.net.vodafone.cz. [77.48.47.2])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-42cb7fd8c47sm12474927f8f.38.2025.11.21.08.29.44\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 21 Nov 2025 08:29:44 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"ajFO+h/8\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1763742589;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=mDXj9fvtJ5nr02TLpluJ4DwzC1wpstQjrJiM1BTJKKA=;\n\tb=ajFO+h/8dreCj1FhbSvaSkRfbD1svfejZ2DMWBPkD1Lexp1cu1TgvgtqsnqRyhK4pBf7Dx\n\t6d2sgxqJvxwxPTTbKGGVdLVNtO95gMw/ghgr8Hz1KGibdJb5kl55AbUiFRV3Iqeb47Zxov\n\tRD6bDWIJJxXuf/KCv73/70+QFpcshlg=","X-MC-Unique":"BGPuf4C_PCOjj1AivcLoZA-1","X-Mimecast-MFC-AGG-ID":"BGPuf4C_PCOjj1AivcLoZA_1763742586","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1763742586; x=1764347386;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject\n\t:date:message-id:reply-to;\n\tbh=mDXj9fvtJ5nr02TLpluJ4DwzC1wpstQjrJiM1BTJKKA=;\n\tb=mCdcL2mI7xDiJv5IOIurRPx0DG4NPzjAD4sjxphwMYfDhKTKJi1h3ekS41IWOA2kTg\n\tbaBeoI99VJbFvGPEf1IHY8KxJIjM//pjfJS+6v5VAxfc/g1vq9unv1p2EIk9DJTVGumN\n\tNBj2uzQXV8WH5Ric9WlehcyyctEhtGOBZkEchLvi+TchzJHj5l1lR6+hDKwtAK2Ii4Ns\n\tnfYtksJRJ0liPU9LnnTV7LOl/2BugbsBCg5NmZAiFalkwxfRxTuLDtqXdg6wRnoBDgr9\n\tpiMd6g2DrgsACZwdwai1a1LCzSnO2GViX/OsakAWu5br8zV9ndXmymo6zWbkRPs4T0JN\n\tUFHg==","X-Gm-Message-State":"AOJu0YzjEpjQMM/P9+TNjA1+lxAyAO8tzAjAy17nkySghbVBuaL9NRv4\n\ttC5QIOcq5o8tc8YnnPPjT0r27S/JgraBrbBt713ZO2r+b049rg7OrKce9/sIXZqsLrQIaugF7XY\n\tmoqqFYUp4gxWJUnFGfgEKPanNd5UJ8s5da7MbSoJnCEY2qrIGhW2fy/zhyK0vWxVOMdEMakHpXV\n\tY=","X-Gm-Gg":"ASbGncv8qe9Ys0nvEeGTQCosY013JyIBWOMYB43yWp9nSGLQggsFLbrovtB6fSEOOwu\n\t6zofuoUZG+WbB7F65O1pxHc4nO3F8pDWVskHj3DYGlRuAC/FQNP+KVVHNNLCExcXsQJsuZc6FIu\n\td/9hy0ytpr2cgCYmRA+oiJXTjwhawZARjhXP28ndsi1Ec7PyecIMBiOnpkjX+2X7Ihf7urcdBIu\n\tajOACrR5/a+nlut9ytlXIMW82C1BZHk7nETuGfTTJNSEVSEFYZGYHnkgTI2lbs+BO+xgftECGl8\n\tMjYTWaCX0WWowvnj3+eMbexp+oi2EmeEGrKefV+FfFgQLHGGtm/8pHhGydFkSy72/9Ril1tIhLQ\n\tPOU4UG1lPRfwvN7AX4pTOCWZtxft6BNcYs768AVxGTuLX8QrWUntmvtBBXERLcBI=","X-Received":["by 2002:a05:6000:1868:b0:429:8daa:c6b4 with SMTP id\n\tffacd0b85a97d-42cc1ce4791mr2935169f8f.21.1763742586443; \n\tFri, 21 Nov 2025 08:29:46 -0800 (PST)","by 2002:a05:6000:1868:b0:429:8daa:c6b4 with SMTP id\n\tffacd0b85a97d-42cc1ce4791mr2935141f8f.21.1763742585983; \n\tFri, 21 Nov 2025 08:29:45 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IFWnPDlrMrdqcwRQ8kG3G2kKnCbL6a28IJnmNEGITIGMYF48DF9LEKDC6waUUjKBg7KgLQk2w==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Isaac Scott <isaac.scott@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,  Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>, =?utf-8?q?Barna?=\n\t=?utf-8?b?YsOhcyBQxZFjemU=?=\n\t<barnabas.pocze@ideasonboard.com>, Paul Elder\n\t<paul.elder@ideasonboard.com>, Umang Jain <uajain@igalia.com>","Subject":"Re: [PATCH] libcamera: software_isp: Assign colour spaces in\n\tconfigurations","In-Reply-To":"<176374037673.117488.13847592379856408716@isaac-ThinkPad-T16-Gen-2>\n\t(Isaac Scott's message of \"Fri, 21 Nov 2025 15:52:56 +0000\")","References":"<20251121151802.80095-1-mzamazal@redhat.com>\n\t<176374037673.117488.13847592379856408716@isaac-ThinkPad-T16-Gen-2>","Date":"Fri, 21 Nov 2025 17:29:43 +0100","Message-ID":"<85wm3j8i2w.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"YgKLmPa5EqV0nUJHM4hMoWKns78ijZj8q9kETYcat3g_1763742586","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]