[{"id":27983,"web_url":"https://patchwork.libcamera.org/comment/27983/","msgid":"<20231018202816.GI1512@pendragon.ideasonboard.com>","date":"2023-10-18T20:28:16","subject":"Re: [libcamera-devel] [PATCH v5 07/12] libcamera: transform: Add\n\toperations with Orientation","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Fri, Sep 01, 2023 at 05:02:10PM +0200, Jacopo Mondi via libcamera-devel wrote:\n> Add two operations that allows to combine Transform with Orientation.\n> \n> - Transform operator/(Orientation1, Orientation2)\n\nLet's write valid C++ code here:\n\n\tTransform operator/(const Orientation &o1, const Orientation &o2);\n\n>   allows to easily get back the Transform that needs to be applied to\n>   Orientation2 to get Orientation1\n> \n> - Orientation operator*(Orientation1, Transform)\n>   allows to apply a Transform to an Orientation and obtain the\n>   combination of the two\n\nAs commented in 06/12, this could be\n\n\tOrientation operator()(const Orientation &o);\n\nThe downside is that the division operator won't be the natural inverse\noperation. There's no easy shorthand notation for inverting a function\ncall. It may not be much of an issue though.\n\n> These two operations allow applications to use Transforms to\n> manipulate the Orientation inside the CameraConfiguration, if they\n> wish.\n\nI'll restate what I mentioned in what was (I think) a face to face\nconversation, to avoid future surprises. Once we'll have a C API, I\nexpect these convenience helpers (as well as the geometry helpers for\ninstance) to be dropped from the libcamera official C ABI. We could\nstill provide them to applications as part of the C++ bindings though.\n\n> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> Reviewed-by: David Plowman <david.plowman@raspberrypi.com>\n> ---\n>  include/libcamera/transform.h |  3 +++\n>  src/libcamera/transform.cpp   | 37 +++++++++++++++++++++++++++++++++++\n>  2 files changed, 40 insertions(+)\n> \n> diff --git a/include/libcamera/transform.h b/include/libcamera/transform.h\n> index 14f1db0e8572..847a1f94713c 100644\n> --- a/include/libcamera/transform.h\n> +++ b/include/libcamera/transform.h\n> @@ -74,6 +74,9 @@ Transform transformFromRotation(int angle, bool *success = nullptr);\n>  Transform transformFromOrientation(const Orientation &orientation);\n>  Orientation transformToOrientation(const Transform &transform);\n>  \n> +Transform operator/(const Orientation &o1, const Orientation &o2);\n> +Orientation operator*(const Orientation &o1, const Transform &t);\n> +\n>  const char *transformToString(Transform t);\n>  \n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/transform.cpp b/src/libcamera/transform.cpp\n> index d192d63d9290..80cd804ca530 100644\n> --- a/src/libcamera/transform.cpp\n> +++ b/src/libcamera/transform.cpp\n> @@ -362,6 +362,43 @@ Orientation transformToOrientation(const Transform &transform)\n>  \treturn Orientation::rotate0;\n>  }\n>  \n> +/**\n> + * \\brief Return the Transform that applied to \\a o2 gives \\a o1\n> + * \\param o1 The Orientation to obtain\n> + * \\param o2 The base Orientation\n> + *\n> + * This operation can be used to easily compute the Transform to apply to a\n> + * base orientation \\a o2 to get the desired orientation \\a o1.\n> + *\n> + * The CameraSensor class uses this function to compute what Transform to apply\n> + * to a camera with mounting rotation \\a o2 (the base) to obtain the user\n> + * requested orientation \\a o1.\n\nI would drop this paragraph, it's an internal implementation detail, and\nthe CameraSensor class is not part of the public API.\n\n> + *\n> + * \\return A Transform that applied to \\a o2 gives \\a o1\n> + */\n> +Transform operator/(const Orientation &o1, const Orientation &o2)\n> +{\n> +\tTransform t1 = transformFromOrientation(o1);\n> +\tTransform t2 = transformFromOrientation(o2);\n> +\n> +\treturn -t2 * t1;\n> +}\n> +\n> +/**\n> + * \\brief Apply the Transform \\a t on the base orientation \\a o\n\ns/base //\n\n> + * \\param o The base orientation\n\ns/base //\n\n> + * \\param t The transform to apply on \\a o\n> + * \\return The Orientation resulting from applying \\a t on \\a o\n> + */\n> +Orientation operator*(const Orientation &o, const Transform &t)\n> +{\n> +\t/*\n> +\t * Apply a Transform corresponding to the base orientation first and\n> +\t * then apply \\a t to it.\n> +\t */\n> +\treturn transformToOrientation(transformFromOrientation(o) * t);\n> +}\n> +\n>  /**\n>   * \\brief Return a character string describing the transform\n>   * \\param[in] t The transform to be described.\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 A2297BDCBD\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 18 Oct 2023 20:28:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E078D6297F;\n\tWed, 18 Oct 2023 22:28:10 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 400B761DD1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 18 Oct 2023 22:28:10 +0200 (CEST)","from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi\n\t[213.243.189.158])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8A8C3666;\n\tWed, 18 Oct 2023 22:28:02 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1697660890;\n\tbh=M+L34kRj285wpaGDxdWhtsSgm6rF/MgjpuuBNHUnOGs=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=fYNfynUdbBJEJ+TCqnIZGbpwnpQvIzd2zOqGX+KfUiZ+8M5owA3HSiMUpcg0o35hW\n\tlCzPYa31GQVV0Yb8Hok43MCA6pm6ovioA5/Xjk9V+9NRUWS2VIPxAj9xpqUr5d0zLD\n\t3S5V8tz0FtAdu82S+8m5UST5wcHveqPSYppQT0lloNP+cqJINaCYysMp4VyCQVg0rI\n\tpC0noUIQv1ExJ9hAGEQ1BtIdTAbvjYj5TiLxlLY2DjXJOCuRbyqwt/6+JyriIzIMu3\n\tgc1snQs+xUrOLbG3ZDIDHgwGJ3GdmatmgNzMhGMK02Hlt4d4q1iDXvVWBh0ZwxcSj5\n\towyx1NlP/V3yw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1697660882;\n\tbh=M+L34kRj285wpaGDxdWhtsSgm6rF/MgjpuuBNHUnOGs=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Dw8Xtf/6P6Dj9r09WSwpFb6xCPoAn6f4TURhWC63Wbg6J5+v1xm51l9yFmDQDK9H/\n\tvz7u7cA50teOsFjpMRABAAvnqEpXtSA8twvJJiGGUGvLMMnfSBZDB3LWomdJjdhef6\n\tT3prD9lI4H1jphr+DxG+pnD4KIxpCmiL2/IhJ+I0="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Dw8Xtf/6\"; dkim-atps=neutral","Date":"Wed, 18 Oct 2023 23:28:16 +0300","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Message-ID":"<20231018202816.GI1512@pendragon.ideasonboard.com>","References":"<20230901150215.11585-1-jacopo.mondi@ideasonboard.com>\n\t<20230901150215.11585-8-jacopo.mondi@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230901150215.11585-8-jacopo.mondi@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v5 07/12] libcamera: transform: Add\n\toperations with Orientation","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]