From patchwork Thu May 5 10:41:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15793 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 9DED9C3270 for ; Thu, 5 May 2022 10:41:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 46B3E6566E; Thu, 5 May 2022 12:41:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651747296; bh=h080XrRzIOw87QZOXhK9AAjRy/YihUNOM7v9sFqPMtk=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=yHfOmOXpfuVpbNDZ+6Orxwgp4eW4VsO7pH1Zs9jDSXVYH03o0uULM8wW4RNXrbetu F+5fam5FcOf4yBiAbCNhw2SGt4RLBJdcMARxkcYsxVkVfwgEBZMHriZQ7XOHPtiX2k cx87Y238X8OttYM8QYWmzX5ghfbxAYPKTqpCecKpn3XKTD1cYmQ03+gUBez3048sgu y8z8SXogZvBdL26CWK9UtBFP/T6RnVgpF/5/BMf2ERhfbGqjGqCzR6xdtMd32zNmVf IHCjlec205TVBgh19cP4d0jey6a9/KN5JVjb0am63B8nYn6JGHKFqD++1j4D5d3PG9 rsdhSpvrMHWTA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F250D65660 for ; Thu, 5 May 2022 12:41:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XOrYxQL3"; dkim-atps=neutral Received: from deskari.lan (91-156-85-209.elisa-laajakaista.fi [91.156.85.209]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6B2B5A58; Thu, 5 May 2022 12:41:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1651747290; bh=h080XrRzIOw87QZOXhK9AAjRy/YihUNOM7v9sFqPMtk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XOrYxQL3KpJBrFDvOqVjmOP8k7fhGNCRGjVHcTKCDNsLnqbY+G6O715A+DOcQ0R9b KySe43fpbVXNIwKVBHC6hmbn6akn3b9wHhJQw/dh1tZ2o/0P1VB3OUHXMzdiffih6v 756B8Bv2fQPl3MLqtdIby11U/pCcOcnbK40j7w7M= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Thu, 5 May 2022 13:41:01 +0300 Message-Id: <20220505104104.70841-11-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220505104104.70841-1-tomi.valkeinen@ideasonboard.com> References: <20220505104104.70841-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 10/13] py: add support for the ColorSpace 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: Tomi Valkeinen via libcamera-devel From: Tomi Valkeinen Reply-To: Tomi Valkeinen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: David Plowman Add binding for ColorSpace. Original version by David Plowman . Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- src/py/libcamera/pymain.cpp | 52 ++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp index 3d2393ab..c442ad50 100644 --- a/src/py/libcamera/pymain.cpp +++ b/src/py/libcamera/pymain.cpp @@ -153,6 +153,11 @@ PYBIND11_MODULE(_libcamera, m) auto pyRequest = py::class_(m, "Request"); auto pyFrameMetadata = py::class_(m, "FrameMetadata"); auto pyTransform = py::class_(m, "Transform"); + auto pyColorSpace = py::class_(m, "ColorSpace"); + auto pyColorSpacePrimaries = py::enum_(pyColorSpace, "Primaries"); + auto pyColorSpaceTransferFunction = py::enum_(pyColorSpace, "TransferFunction"); + auto pyColorSpaceYcbcrEncoding = py::enum_(pyColorSpace, "YcbcrEncoding"); + auto pyColorSpaceRange = py::enum_(pyColorSpace, "Range"); /* Global functions */ m.def("logSetLevel", &logSetLevel); @@ -360,7 +365,8 @@ PYBIND11_MODULE(_libcamera, m) .def_readwrite("stride", &StreamConfiguration::stride) .def_readwrite("frameSize", &StreamConfiguration::frameSize) .def_readwrite("bufferCount", &StreamConfiguration::bufferCount) - .def_property_readonly("formats", &StreamConfiguration::formats, py::return_value_policy::reference_internal); + .def_property_readonly("formats", &StreamConfiguration::formats, py::return_value_policy::reference_internal) + .def_readwrite("colorSpace", &StreamConfiguration::colorSpace); pyStreamFormats .def_property_readonly("pixelFormats", [](StreamFormats &self) { @@ -523,4 +529,48 @@ PYBIND11_MODULE(_libcamera, m) .def("compose", [](Transform &self, Transform &other) { self = self * other; }); + + pyColorSpace + .def(py::init([](ColorSpace::Primaries primaries, + ColorSpace::TransferFunction transferFunction, + ColorSpace::YcbcrEncoding ycbcrEncoding, + ColorSpace::Range range) { + return ColorSpace(primaries, transferFunction, ycbcrEncoding, range); + }), py::arg("primaries"), py::arg("transferFunction"), + py::arg("ycbcrEncoding"), py::arg("range")) + .def(py::init([](ColorSpace &other) { return other; })) + .def("__repr__", [](ColorSpace &self) { + return ""; + }) + .def_readwrite("primaries", &ColorSpace::primaries) + .def_readwrite("transferFunction", &ColorSpace::transferFunction) + .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("Smpte170m", []() { return ColorSpace::Smpte170m; }) + .def_static("Rec709", []() { return ColorSpace::Rec709; }) + .def_static("Rec2020", []() { return ColorSpace::Rec2020; }); + + pyColorSpacePrimaries + .value("Raw", ColorSpace::Primaries::Raw) + .value("Smpte170m", ColorSpace::Primaries::Smpte170m) + .value("Rec709", ColorSpace::Primaries::Rec709) + .value("Rec2020", ColorSpace::Primaries::Rec2020); + + pyColorSpaceTransferFunction + .value("Linear", ColorSpace::TransferFunction::Linear) + .value("Srgb", ColorSpace::TransferFunction::Srgb) + .value("Rec709", ColorSpace::TransferFunction::Rec709); + + pyColorSpaceYcbcrEncoding + .value("Null", ColorSpace::YcbcrEncoding::None) + .value("Rec601", ColorSpace::YcbcrEncoding::Rec601) + .value("Rec709", ColorSpace::YcbcrEncoding::Rec709) + .value("Rec2020", ColorSpace::YcbcrEncoding::Rec2020); + + pyColorSpaceRange + .value("Full", ColorSpace::Range::Full) + .value("Limited", ColorSpace::Range::Limited); }