From patchwork Tue Jul 14 23:40:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8801 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 A92ACBD792 for ; Tue, 14 Jul 2020 23:40:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1353960926; Wed, 15 Jul 2020 01:40:23 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="O0wYJovU"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C32E860913 for ; Wed, 15 Jul 2020 01:40:20 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5DEDD10F6 for ; Wed, 15 Jul 2020 01:40:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594770020; bh=tWEqVyXXzJm1nnlSSSVjmRc8BW/umlVfUxftGjE2DoU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=O0wYJovUGQ0HHKmyStkBdS09g5I2DSx47t4MreVQmdpRylxvg9y/55xy8ERAxUwL7 UYF/NRD3BEKXV3DJ2JTTcFHZ4CfbRQntNEzx0+cbDkNdfRxQs38VMiG4GXi+L1hqDl Eeq6PnLioIYJ2GmB2yhWXj9fuzmKhQf/2VvWcn+w= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 15 Jul 2020 02:40:05 +0300 Message-Id: <20200714234009.16596-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714234009.16596-1-laurent.pinchart@ideasonboard.com> References: <20200714234009.16596-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/5] libcamera: geometry: Don't default-initialize Size unnecessarily 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Size has a default constructor, there's no need to default-initialize instances explicitly. Fix it. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index c6cb84e0b0c9..009e502b288c 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -418,7 +418,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() unsigned int rawCount = 0, outCount = 0, count = 0, maxIndex = 0; std::pair outSize[2]; - Size maxSize = {}; + Size maxSize; for (StreamConfiguration &cfg : config_) { if (isRaw(cfg.pixelFormat)) { /* @@ -621,7 +621,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) for (auto const stream : data->streams_) stream->reset(); - Size maxSize = {}, sensorSize = {}; + Size maxSize, sensorSize; unsigned int maxIndex = 0; bool rawStream = false; From patchwork Tue Jul 14 23:40:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8802 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 64678BD792 for ; Tue, 14 Jul 2020 23:40:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5F57960930; Wed, 15 Jul 2020 01:40:23 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="EXrnZLsq"; dkim-atps=neutral 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 09EAA60905 for ; Wed, 15 Jul 2020 01:40:21 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A7AFB71D for ; Wed, 15 Jul 2020 01:40:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594770020; bh=SqpJejNoNnCvoQwIv19jm7magFhcAcEfgNRiVJF4qcI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=EXrnZLsqHXF+Fuo0xF+NdYl98ssrHZcoKRZXSM3U4ATGfcIm9WRUfbLJArKufpBr5 aYvD+2nThgHw4nv6PY2AqxpuNJ1NTMrSMvBRUn4n/ioaxPpjmiLNheTTb8kMFBy04m Qkic3JXCL8YwCn8WLdfGEGhQPzm/IcE5mPvcxDrE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 15 Jul 2020 02:40:06 +0300 Message-Id: <20200714234009.16596-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714234009.16596-1-laurent.pinchart@ideasonboard.com> References: <20200714234009.16596-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/5] libcamera: geometry: Define Rectangle after Size 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" A subsequent change to the Rectangle will require the definition of the Size to be available. Define Rectangle after Size to ease review of that change. No code change is included. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/geometry.h | 30 ++++----- src/libcamera/geometry.cpp | 122 +++++++++++++++++------------------ 2 files changed, 76 insertions(+), 76 deletions(-) diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index d217cfd50c86..f3088d33fa2c 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -13,21 +13,6 @@ namespace libcamera { -struct Rectangle { - int x; - int y; - unsigned int width; - unsigned int height; - - const std::string toString() const; -}; - -bool operator==(const Rectangle &lhs, const Rectangle &rhs); -static inline bool operator!=(const Rectangle &lhs, const Rectangle &rhs) -{ - return !(lhs == rhs); -} - struct Size { Size() : Size(0, 0) @@ -141,6 +126,21 @@ static inline bool operator!=(const SizeRange &lhs, const SizeRange &rhs) return !(lhs == rhs); } +struct Rectangle { + int x; + int y; + unsigned int width; + unsigned int height; + + const std::string toString() const; +}; + +bool operator==(const Rectangle &lhs, const Rectangle &rhs); +static inline bool operator!=(const Rectangle &lhs, const Rectangle &rhs) +{ + return !(lhs == rhs); +} + } /* namespace libcamera */ #endif /* __LIBCAMERA_GEOMETRY_H__ */ diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp index 4594f9ff435f..5a0bcf7c1e12 100644 --- a/src/libcamera/geometry.cpp +++ b/src/libcamera/geometry.cpp @@ -17,67 +17,6 @@ namespace libcamera { -/** - * \struct Rectangle - * \brief Describe a rectangle's position and dimensions - * - * Rectangles are used to identify an area of an image. They are specified by - * the coordinates of top-left corner and their horizontal and vertical size. - * - * The measure unit of the rectangle coordinates and size, as well as the - * reference point from which the Rectangle::x and Rectangle::y displacements - * refers to, are defined by the context were rectangle is used. - */ - -/** - * \var Rectangle::x - * \brief The horizontal coordinate of the rectangle's top-left corner - */ - -/** - * \var Rectangle::y - * \brief The vertical coordinate of the rectangle's top-left corner - */ - -/** - * \var Rectangle::width - * \brief The distance between the left and right sides - */ - -/** - * \var Rectangle::height - * \brief The distance between the top and bottom sides - */ - -/** - * \brief Assemble and return a string describing the rectangle - * \return A string describing the Rectangle - */ -const std::string Rectangle::toString() const -{ - std::stringstream ss; - - ss << "(" << x << "x" << y << ")/" << width << "x" << height; - - return ss.str(); -} - -/** - * \brief Compare rectangles for equality - * \return True if the two rectangles are equal, false otherwise - */ -bool operator==(const Rectangle &lhs, const Rectangle &rhs) -{ - return lhs.x == rhs.x && lhs.y == rhs.y && - lhs.width == rhs.width && lhs.height == rhs.height; -} - -/** - * \fn bool operator!=(const Rectangle &lhs, const Rectangle &rhs) - * \brief Compare rectangles for inequality - * \return True if the two rectangles are not equal, false otherwise - */ - /** * \struct Size * \brief Describe a two-dimensional size @@ -346,4 +285,65 @@ bool operator==(const SizeRange &lhs, const SizeRange &rhs) * \return True if the two size ranges are not equal, false otherwise */ +/** + * \struct Rectangle + * \brief Describe a rectangle's position and dimensions + * + * Rectangles are used to identify an area of an image. They are specified by + * the coordinates of top-left corner and their horizontal and vertical size. + * + * The measure unit of the rectangle coordinates and size, as well as the + * reference point from which the Rectangle::x and Rectangle::y displacements + * refers to, are defined by the context were rectangle is used. + */ + +/** + * \var Rectangle::x + * \brief The horizontal coordinate of the rectangle's top-left corner + */ + +/** + * \var Rectangle::y + * \brief The vertical coordinate of the rectangle's top-left corner + */ + +/** + * \var Rectangle::width + * \brief The distance between the left and right sides + */ + +/** + * \var Rectangle::height + * \brief The distance between the top and bottom sides + */ + +/** + * \brief Assemble and return a string describing the rectangle + * \return A string describing the Rectangle + */ +const std::string Rectangle::toString() const +{ + std::stringstream ss; + + ss << "(" << x << "x" << y << ")/" << width << "x" << height; + + return ss.str(); +} + +/** + * \brief Compare rectangles for equality + * \return True if the two rectangles are equal, false otherwise + */ +bool operator==(const Rectangle &lhs, const Rectangle &rhs) +{ + return lhs.x == rhs.x && lhs.y == rhs.y && + lhs.width == rhs.width && lhs.height == rhs.height; +} + +/** + * \fn bool operator!=(const Rectangle &lhs, const Rectangle &rhs) + * \brief Compare rectangles for inequality + * \return True if the two rectangles are not equal, false otherwise + */ + } /* namespace libcamera */ From patchwork Tue Jul 14 23:40:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8803 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 F0C45BD792 for ; Tue, 14 Jul 2020 23:40:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BC72C60925; Wed, 15 Jul 2020 01:40:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="N10QWH/c"; dkim-atps=neutral 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 5B11460905 for ; Wed, 15 Jul 2020 01:40:21 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F06EA10F6 for ; Wed, 15 Jul 2020 01:40:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594770021; bh=waPAdl26c/ZnBNcOAGTj55qxffTbdd90yd6MIYQptEY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=N10QWH/cFeGe24Y/LvyoQH4BVSXm0bPrWFdcBR//QxDj5ZSvtjfyd7IStLeUSb69B hNBE5QhOGam3V8rBpRRuTfY+XVEqlxuKloh6QXSrcDLALbLwc1XG1/5iJpxEdZew2S sJcoqbJXYIiCrwytj1wLsa+10j6icpEUcp5KNLQQ= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 15 Jul 2020 02:40:07 +0300 Message-Id: <20200714234009.16596-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714234009.16596-1-laurent.pinchart@ideasonboard.com> References: <20200714234009.16596-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/5] libcamera: geometry: Give constructors to Rectangle 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Rectangle, unlike Size, has no constructor, requiring the users to explicitly initialize the instances. This is error-prone, add constructors. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/geometry.h | 15 +++++++++++++ src/libcamera/camera_sensor.cpp | 2 +- src/libcamera/geometry.cpp | 22 +++++++++++++++++++ src/libcamera/pipeline/ipu3/imgu.cpp | 7 +----- .../pipeline/raspberrypi/raspberrypi.cpp | 7 +----- src/libcamera/pipeline/vimc/vimc.cpp | 7 +----- 6 files changed, 41 insertions(+), 19 deletions(-) diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index f3088d33fa2c..380248ac9a50 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -127,6 +127,21 @@ static inline bool operator!=(const SizeRange &lhs, const SizeRange &rhs) } struct Rectangle { + Rectangle() + : Rectangle(0, 0, 0, 0) + { + } + + Rectangle(int xpos, int ypos, const Size &size) + : x(xpos), y(ypos), width(size.width), height(size.height) + { + } + + Rectangle(int xpos, int ypos, unsigned int w, unsigned int h) + : x(xpos), y(ypos), width(w), height(h) + { + } + int x; int y; unsigned int width; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index b14b4051dca6..6e93cc51155b 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -487,7 +487,7 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const info->model = model(); /* Get the active area size. */ - Rectangle rect = {}; + Rectangle rect; int ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP_DEFAULT, &rect); if (ret) { LOG(CameraSensor, Error) diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp index 5a0bcf7c1e12..3a3784df39e6 100644 --- a/src/libcamera/geometry.cpp +++ b/src/libcamera/geometry.cpp @@ -297,6 +297,28 @@ bool operator==(const SizeRange &lhs, const SizeRange &rhs) * refers to, are defined by the context were rectangle is used. */ +/** + * \fn Rectangle::Rectangle() + * \brief Construct a Rectangle with all coordinates set to 0 + */ + +/** + * \fn Rectangle::Rectangle(int x, int y, const Size &size) + * \brief Construct a Rectangle with the given position and size + * \param[in] x The horizontal coordinate of the top-left corner + * \param[in] y The vertical coordinate of the top-left corner + * \param[in] size The size + */ + +/** + * \fn Rectangle::Rectangle(int x, int y, unsigned int width, unsigned int height) + * \brief Construct a Rectangle with the given position and size + * \param[in] x The horizontal coordinate of the top-left corner + * \param[in] y The vertical coordinate of the top-left corner + * \param[in] width The width + * \param[in] height The height + */ + /** * \var Rectangle::x * \brief The horizontal coordinate of the rectangle's top-left corner diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp index d7f4173d3607..4bec4b2f1a76 100644 --- a/src/libcamera/pipeline/ipu3/imgu.cpp +++ b/src/libcamera/pipeline/ipu3/imgu.cpp @@ -100,12 +100,7 @@ int ImgUDevice::configureInput(const Size &size, * to configure the crop/compose rectangles, contradicting the * V4L2 specification. */ - Rectangle rect = { - .x = 0, - .y = 0, - .width = inputFormat->size.width, - .height = inputFormat->size.height, - }; + Rectangle rect{ 0, 0, inputFormat->size }; ret = imgu_->setSelection(PAD_INPUT, V4L2_SEL_TGT_CROP, &rect); if (ret) return ret; diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 009e502b288c..2d848ac3c735 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -752,12 +752,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) } /* Adjust aspect ratio by providing crops on the input image. */ - Rectangle crop = { - .x = 0, - .y = 0, - .width = sensorFormat.size.width, - .height = sensorFormat.size.height - }; + Rectangle crop{ 0, 0, sensorFormat.size }; int ar = maxSize.height * sensorFormat.size.width - maxSize.width * sensorFormat.size.height; if (ar > 0) diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp index a6f457c71fb1..4f461b928514 100644 --- a/src/libcamera/pipeline/vimc/vimc.cpp +++ b/src/libcamera/pipeline/vimc/vimc.cpp @@ -256,12 +256,7 @@ int PipelineHandlerVimc::configure(Camera *camera, CameraConfiguration *config) return ret; if (data->media_->version() >= KERNEL_VERSION(5, 6, 0)) { - Rectangle crop = { - .x = 0, - .y = 0, - .width = subformat.size.width, - .height = subformat.size.height, - }; + Rectangle crop{ 0, 0, subformat.size }; ret = data->scaler_->setSelection(0, V4L2_SEL_TGT_CROP, &crop); if (ret) return ret; From patchwork Tue Jul 14 23:40:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8804 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 5BB0CBDB1C for ; Tue, 14 Jul 2020 23:40:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 24AD260939; Wed, 15 Jul 2020 01:40:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="KhN+u/85"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A5EB260905 for ; Wed, 15 Jul 2020 01:40:21 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4701671D for ; Wed, 15 Jul 2020 01:40:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594770021; bh=detGMdE8pu6zBfzhpVatFuJPitvKO/s97GBeJhxMryI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KhN+u/85DacML7Liw4Yj4EoaBSMmzCeUo9WeXgqlrVVK9c6LgsXsLXBKAmcfV413O cc/SW3Pqq/Fnsf6CPK2tWs7ttZQjgfGXiHxnXYCm1QVlY4pQmjxVbQTbocB/LdsE/g 66StzPKZ+y5yT29Wf+81KuiW6+SM0jFovNXjiQq4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 15 Jul 2020 02:40:08 +0300 Message-Id: <20200714234009.16596-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714234009.16596-1-laurent.pinchart@ideasonboard.com> References: <20200714234009.16596-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/5] libcamera: geometry: Turn Size and Rectangle into classes 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" SizeRange is defined as a class while Size and Rectangle are defined as struct. This is confusing for users in forward declarations. Simplify it by turning both structures into classes. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/geometry.h | 10 +++++++--- src/libcamera/pipeline/ipu3/cio2.h | 2 +- src/libcamera/pipeline/ipu3/imgu.h | 2 +- src/libcamera/pipeline/simple/converter.h | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index 380248ac9a50..16c94a4861d6 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -2,7 +2,7 @@ /* * Copyright (C) 2019, Google Inc. * - * geometry.h - Geometry-related structure + * geometry.h - Geometry-related classes */ #ifndef __LIBCAMERA_GEOMETRY_H__ @@ -13,7 +13,9 @@ namespace libcamera { -struct Size { +class Size +{ +public: Size() : Size(0, 0) { @@ -126,7 +128,9 @@ static inline bool operator!=(const SizeRange &lhs, const SizeRange &rhs) return !(lhs == rhs); } -struct Rectangle { +class Rectangle +{ +public: Rectangle() : Rectangle(0, 0, 0, 0) { diff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h index 4fd949f8e513..956355a0aa58 100644 --- a/src/libcamera/pipeline/ipu3/cio2.h +++ b/src/libcamera/pipeline/ipu3/cio2.h @@ -21,8 +21,8 @@ class CameraSensor; class FrameBuffer; class MediaDevice; class Request; +class Size; class V4L2Subdevice; -struct Size; struct StreamConfiguration; class CIO2Device diff --git a/src/libcamera/pipeline/ipu3/imgu.h b/src/libcamera/pipeline/ipu3/imgu.h index 5c124af2e9fe..23ec1ca1c6ae 100644 --- a/src/libcamera/pipeline/ipu3/imgu.h +++ b/src/libcamera/pipeline/ipu3/imgu.h @@ -17,7 +17,7 @@ namespace libcamera { class FrameBuffer; class MediaDevice; -struct Size; +class Size; struct StreamConfiguration; class ImgUDevice diff --git a/src/libcamera/pipeline/simple/converter.h b/src/libcamera/pipeline/simple/converter.h index 8ca88912b4be..78296680aa14 100644 --- a/src/libcamera/pipeline/simple/converter.h +++ b/src/libcamera/pipeline/simple/converter.h @@ -20,7 +20,7 @@ namespace libcamera { class FrameBuffer; class MediaDevice; -struct Size; +class Size; class SizeRange; struct StreamConfiguration; class V4L2M2MDevice; From patchwork Tue Jul 14 23:40:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8805 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 BF026BD792 for ; Tue, 14 Jul 2020 23:40:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8BE8760932; Wed, 15 Jul 2020 01:40:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="q6xSqenL"; dkim-atps=neutral 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 F282C60929 for ; Wed, 15 Jul 2020 01:40:21 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 913AF10F6 for ; Wed, 15 Jul 2020 01:40:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594770021; bh=xGr4RoikmEMcAebjYTKr1Ajk4ZADwnn3qHrk5k20Wkw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=q6xSqenLaoq7rSWXkxGHTyw4//pIgb4wIDCR78uDBeOxKgrbNmC3YrkEsPKalNUrb gBmwfI+WuEyp1ljmHGihKh7/h35dBc16c61I/oyME8MqxPNnpXfXy/rt9GOX8dJnaD Qwrc0HJFs5Ey+TQpG1BMU1Rwxe0oqXqffDbeXPzw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 15 Jul 2020 02:40:09 +0300 Message-Id: <20200714234009.16596-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714234009.16596-1-laurent.pinchart@ideasonboard.com> References: <20200714234009.16596-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/5] libcamera: geometry: Make Size and Rectangle usable as constexpr 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" There are use cases for declaring constexpr Size and Rectangle instances. Make it possible. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/geometry.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index 16c94a4861d6..30aaa7a30fe2 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -16,12 +16,12 @@ namespace libcamera { class Size { public: - Size() + constexpr Size() : Size(0, 0) { } - Size(unsigned int w, unsigned int h) + constexpr Size(unsigned int w, unsigned int h) : width(w), height(h) { } @@ -32,7 +32,8 @@ public: bool isNull() const { return !width && !height; } const std::string toString() const; - Size alignedDownTo(unsigned int hAlignment, unsigned int vAlignment) const + constexpr Size alignedDownTo(unsigned int hAlignment, + unsigned int vAlignment) const { return { width / hAlignment * hAlignment, @@ -40,7 +41,8 @@ public: }; } - Size alignedUpTo(unsigned int hAlignment, unsigned int vAlignment) const + constexpr Size alignedUpTo(unsigned int hAlignment, + unsigned int vAlignment) const { return { (width + hAlignment - 1) / hAlignment * hAlignment, @@ -48,7 +50,7 @@ public: }; } - Size boundedTo(const Size &bound) const + constexpr Size boundedTo(const Size &bound) const { return { std::min(width, bound.width), @@ -56,7 +58,7 @@ public: }; } - Size expandedTo(const Size &expand) const + constexpr Size expandedTo(const Size &expand) const { return { std::max(width, expand.width), @@ -131,17 +133,17 @@ static inline bool operator!=(const SizeRange &lhs, const SizeRange &rhs) class Rectangle { public: - Rectangle() + constexpr Rectangle() : Rectangle(0, 0, 0, 0) { } - Rectangle(int xpos, int ypos, const Size &size) + constexpr Rectangle(int xpos, int ypos, const Size &size) : x(xpos), y(ypos), width(size.width), height(size.height) { } - Rectangle(int xpos, int ypos, unsigned int w, unsigned int h) + constexpr Rectangle(int xpos, int ypos, unsigned int w, unsigned int h) : x(xpos), y(ypos), width(w), height(h) { }