From patchwork Wed Aug 17 21:18:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17145 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 BC352BE173 for ; Wed, 17 Aug 2022 21:18:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 26A2661FA8; Wed, 17 Aug 2022 23:18:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660771108; bh=Hc+YiOXkrQiyp3uFB8IKmxBqLewjAii0qRf9q8Y/IWw=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=S0f5QDncjvt4SwGGllA+U3FPWhpP4diCGW89mxiyScwxyHXWMPrJB2pkDMaeyQT5G DBOgrvh27twNlZ1mawKVhzKrIPtpt+VregmgprFUNTUCNbscAtggN288bz20RZoW56 ks14Yxsm4uMsWxq9e+gmJmxRRcJZAkyVUxuFzm6ImZgtid2H1bTr04ETytyZAVUo0R U608TD9yfafdheQJbkvHgaNh9rteu0XcaJScGdiei1ZjQ8m2McSzy4fgncVPmZJVop /ojmele+H8574V/r4eHEh2kNW/JVkgmstT8OjG29e4rj1o0ZRaguW7zSBEqblSoFVO SWQXqaMiyy9sw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4EE9B61FA8 for ; Wed, 17 Aug 2022 23:18:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ucAHebse"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A7A6551C; Wed, 17 Aug 2022 23:18:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1660771105; bh=Hc+YiOXkrQiyp3uFB8IKmxBqLewjAii0qRf9q8Y/IWw=; h=From:To:Cc:Subject:Date:From; b=ucAHebse6liKtMcneO0G32O3M2Px5JI7ugTYqY/8WEJjHPhrth87/uFdLfrvdje6P QAhhretAiwkLU40mZfbMuFtCUuCrd3TefV/vmYaBnEQR6l3/ljAZ0MvIf/OfI/XGY4 MjRr843Z3R6tbxBaidQ4QkOhyxUS79g4/J6P5X1k= To: libcamera-devel@lists.libcamera.org Date: Thu, 18 Aug 2022 00:18:24 +0300 Message-Id: <20220817211824.20980-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: color_space: Rename Jpeg to Sycc 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Hans Verkuil Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The JPEG color space is badly name, as the JPEG specification (ITU-T T.81) doesn't define any particular color space: The interchange format does not specify a complete coded image representation. Application-dependent information, e.g. colour space, is outside the scope of this Specification. The JFIF specification (ITU-T T.871) is clearer as it requires ITU-R BT.601 YCbCr encoding and a full quantization range: The interpretations of Y, CB, and CR are derived from the E'Y, E'Cb, and E'Cr signals defined in the 625-line specification of Rec. ITU-R BT.601, but these signals are normalized so as to permit the usage of the full range of 256 levels of the 8-bit binary encoding of the Y component. It however doesn't specify color primaries or a transfer function explicitly. It only mentions the latter when describing the conversion from YCbCr to RGB: The inverse relationship for computing full scale 8-bit per colour channel gamma pre-corrected RGB values (following Rec. ITU-R BT.601 gamma pre-correction and colour primary specifications) from YCbCr colours (with 256 levels per component) can be computed as follows: [...] Given that ITU-R BT.601-5 (1995) didn't specify color primaries or a transfer function, and that the later ITU-R BT.601-7 (2011) version specifies color primaries for the 625-line variant that do not match sRGB, the JPEG color space in libcamera is badly named. Rename the color space to sYCC, as its definition matches the sYCC standard, and indicate that it is typically used to encode JPEG images. Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain --- Hans, following our discussion on IRC, I double-check the JFIF standard, and my findings are described in the commit message above. It seems that naming the color space "JPEG" in V4L2 is actually incorrect, as JFIF expects the 626-line ITU-R BT.601 chromaticities for the primary colors, which are slightly different than sRGB (the 525-line chromaticities match SMPTE 170M and SMPTE 240M, but not sRGB either). It seems that we are missing a V4L2_COLORSPACE_* value to describe the 625-line ITU-R BT.601 chromaticities, is that an oversight ? --- include/libcamera/color_space.h | 2 +- src/libcamera/color_space.cpp | 28 +++++++++---------- .../pipeline/raspberrypi/raspberrypi.cpp | 10 +++---- src/libcamera/v4l2_device.cpp | 4 +-- src/py/libcamera/py_main.cpp | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/include/libcamera/color_space.h b/include/libcamera/color_space.h index 0d39fbc02220..8030a264c66f 100644 --- a/include/libcamera/color_space.h +++ b/include/libcamera/color_space.h @@ -46,8 +46,8 @@ public: } static const ColorSpace Raw; - static const ColorSpace Jpeg; static const ColorSpace Srgb; + static const ColorSpace Sycc; static const ColorSpace Smpte170m; static const ColorSpace Rec709; static const ColorSpace Rec2020; diff --git a/src/libcamera/color_space.cpp b/src/libcamera/color_space.cpp index caf397607b10..6ace40dcb0fb 100644 --- a/src/libcamera/color_space.cpp +++ b/src/libcamera/color_space.cpp @@ -121,8 +121,8 @@ namespace libcamera { * \brief Assemble and return a readable string representation of the * ColorSpace * - * If the color space matches a standard ColorSpace (such as ColorSpace::Jpeg) - * then the short name of the color space ("JPEG") is returned. Otherwise + * If the color space matches a standard ColorSpace (such as ColorSpace::Sycc) + * then the short name of the color space ("sYCC") is returned. Otherwise * the four constituent parts of the ColorSpace are assembled into a longer * string. * @@ -134,8 +134,8 @@ std::string ColorSpace::toString() const static const std::array, 6> colorSpaceNames = { { { ColorSpace::Raw, "RAW" }, - { ColorSpace::Jpeg, "JPEG" }, { ColorSpace::Srgb, "sRGB" }, + { ColorSpace::Sycc, "sYCC" }, { ColorSpace::Smpte170m, "SMPTE170M" }, { ColorSpace::Rec709, "Rec709" }, { ColorSpace::Rec2020, "Rec2020" }, @@ -242,17 +242,6 @@ const ColorSpace ColorSpace::Raw = { Range::Full }; -/** - * \brief A constant representing the JPEG color space used for - * encoding JPEG images - */ -const ColorSpace ColorSpace::Jpeg = { - Primaries::Rec709, - TransferFunction::Srgb, - YcbcrEncoding::Rec601, - Range::Full -}; - /** * \brief A constant representing the sRGB color space * @@ -266,6 +255,17 @@ const ColorSpace ColorSpace::Srgb = { Range::Limited }; +/** + * \brief A constant representing the sYCC color space, typically used for + * encoding JPEG images + */ +const ColorSpace ColorSpace::Sycc = { + Primaries::Rec709, + TransferFunction::Srgb, + YcbcrEncoding::Rec601, + Range::Full +}; + /** * \brief A constant representing the SMPTE170M color space */ diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index e895584d4fbc..b4094898ca6c 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -593,11 +593,11 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera, fmts = data->isp_[Isp::Output0].dev()->formats(); pixelFormat = formats::NV12; /* - * Still image codecs usually expect the JPEG color space. + * Still image codecs usually expect the sYCC color space. * Even RGB codecs will be fine as the RGB we get with the - * JPEG color space is the same as sRGB. + * sYCC color space is the same as sRGB. */ - colorSpace = ColorSpace::Jpeg; + colorSpace = ColorSpace::Sycc; /* Return the largest sensor resolution. */ size = sensorSize; bufferCount = 1; @@ -628,7 +628,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera, case StreamRole::Viewfinder: fmts = data->isp_[Isp::Output0].dev()->formats(); pixelFormat = formats::ARGB8888; - colorSpace = ColorSpace::Jpeg; + colorSpace = ColorSpace::Sycc; size = { 800, 600 }; bufferCount = 4; outCount++; @@ -835,7 +835,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) format.size = maxSize; format.fourcc = dev->toV4L2PixelFormat(formats::YUV420); /* No one asked for output, so the color space doesn't matter. */ - format.colorSpace = ColorSpace::Jpeg; + format.colorSpace = ColorSpace::Sycc; ret = dev->setFormat(&format); if (ret) { LOG(RPI, Error) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 3fc8438f6579..b22a981ff1a6 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -745,8 +745,8 @@ void V4L2Device::eventAvailable() static const std::map v4l2ToColorSpace = { { V4L2_COLORSPACE_RAW, ColorSpace::Raw }, - { V4L2_COLORSPACE_JPEG, ColorSpace::Jpeg }, { V4L2_COLORSPACE_SRGB, ColorSpace::Srgb }, + { V4L2_COLORSPACE_JPEG, ColorSpace::Sycc }, { V4L2_COLORSPACE_SMPTE170M, ColorSpace::Smpte170m }, { V4L2_COLORSPACE_REC709, ColorSpace::Rec709 }, { V4L2_COLORSPACE_BT2020, ColorSpace::Rec2020 }, @@ -771,8 +771,8 @@ static const std::map v4l2ToRange = { static const std::vector> colorSpaceToV4l2 = { { ColorSpace::Raw, V4L2_COLORSPACE_RAW }, - { ColorSpace::Jpeg, V4L2_COLORSPACE_JPEG }, { ColorSpace::Srgb, V4L2_COLORSPACE_SRGB }, + { ColorSpace::Sycc, V4L2_COLORSPACE_JPEG }, { ColorSpace::Smpte170m, V4L2_COLORSPACE_SMPTE170M }, { ColorSpace::Rec709, V4L2_COLORSPACE_REC709 }, { ColorSpace::Rec2020, V4L2_COLORSPACE_BT2020 }, diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp index 505cc3dc1a0d..2a58e34a7cdb 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -602,8 +602,8 @@ PYBIND11_MODULE(_libcamera, m) .def_readwrite("ycbcrEncoding", &ColorSpace::ycbcrEncoding) .def_readwrite("range", &ColorSpace::range) .def_static("Raw", []() { return ColorSpace::Raw; }) - .def_static("Jpeg", []() { return ColorSpace::Jpeg; }) .def_static("Srgb", []() { return ColorSpace::Srgb; }) + .def_static("Sycc", []() { return ColorSpace::Sycc; }) .def_static("Smpte170m", []() { return ColorSpace::Smpte170m; }) .def_static("Rec709", []() { return ColorSpace::Rec709; }) .def_static("Rec2020", []() { return ColorSpace::Rec2020; });