From patchwork Wed Jul 29 09:31:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 9060 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 29FE8BD86F for ; Wed, 29 Jul 2020 09:32:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0F3E36185C; Wed, 29 Jul 2020 11:32:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="cNyMNGL1"; dkim-atps=neutral Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 220D7605B2 for ; Wed, 29 Jul 2020 11:32:02 +0200 (CEST) Received: by mail-wm1-x32a.google.com with SMTP id k8so2249328wma.2 for ; Wed, 29 Jul 2020 02:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xonQ42icnoeM5+ZjLptP5FX3WqLgo0G6u2lfNy8TDyY=; b=cNyMNGL1xHiJJEqO5zgRqrA2N+QFkyduLP9e9BL0OxDgutrXmaotcRXAnifN3ET962 nnouRU1jBgGgCf2nwEf71qUkI+5avCVrE+2J2faqItdd9aWppo18F9+RPvRgUogMfamn s6WlCTVq8GjZqdbyVRMEuCGFgiq8UhVe86mHiR15Bct2KglEN673kXAv6QU8qECpa1Go u1Uu+GwQT/Hi7CqcNFeIr0m2D6YFDrLGbL02mznGuOWnDYMk5sDwbSLf7Fdxe0889a/O SGHH+8S17YO7qsrqowBLEj0lQ1T59a4iE9Cf4OfhUoAR3gAVPXEAHCp95arxBj92aFhT Wr0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xonQ42icnoeM5+ZjLptP5FX3WqLgo0G6u2lfNy8TDyY=; b=Ji0CLc6bEstNdAv0pyU24IEjYLy3lDXDbSa+i7OUxXKXtVMCly0ayD1rNN7v30WgJj bVXfjmWzWdgTGFDWXt4xXVtONT/pJ7mAFHs/C/Gj2nUlbo7UxNCCcq7TUP8girZF+8m/ hWLXSN3Gnuv1MrcGpSxQhHhrudJVZXzsKxYtWLVNU4c0MwzTnHJz4uK0iuGfA8thKAvo 56bOGs4a4tmxxpj4btlHYiyUastLjS583W0pdpeAlXgcJH9NUYNzHgSydHbPkRHUVZi1 65LEfAdYuJGlNpQM51UcZY2Qc864C8kAEgb/bjY/XuKzIAjIdDvKyW8CpRIVajOuQIMo +iPw== X-Gm-Message-State: AOAM5303D+z99ZbUAIXQGzHRSidS1rBiGoRPTLcuLVUyiiQhoJVvUjxa NEKFDcvmbGaiEi6llgczy64lJJAVh/2PiA== X-Google-Smtp-Source: ABdhPJyr9oVy0aclePILz269u8DZCDXDXkh+LmEofO+OW9D/Q3OX0MaEAA6bu3HtrOx19jS9t03wcQ== X-Received: by 2002:a1c:3b06:: with SMTP id i6mr7903903wma.42.1596015121151; Wed, 29 Jul 2020 02:32:01 -0700 (PDT) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id c15sm3709921wme.23.2020.07.29.02.32.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jul 2020 02:32:00 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Wed, 29 Jul 2020 10:31:50 +0100 Message-Id: <20200729093154.12296-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200729093154.12296-1-david.plowman@raspberrypi.com> References: <20200729093154.12296-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/5] libcamera: Add Transform class 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" Add implementation of 2d plane transforms, and include a Transform field in the CameraConfiguration to record the application's choice of image transform for this session. --- include/libcamera/camera.h | 3 + include/libcamera/meson.build | 1 + include/libcamera/transform.h | 193 ++++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 include/libcamera/transform.h diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 4d1a4a9..fd9355e 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -16,6 +16,7 @@ #include #include #include +#include namespace libcamera { @@ -60,6 +61,8 @@ public: bool empty() const; std::size_t size() const; + Transform userTransform; + protected: CameraConfiguration(); diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index cdb8e03..7fae5e5 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -19,6 +19,7 @@ libcamera_public_headers = files([ 'span.h', 'stream.h', 'timer.h', + 'transform.h', ]) include_dir = join_paths(libcamera_include_dir, 'libcamera') diff --git a/include/libcamera/transform.h b/include/libcamera/transform.h new file mode 100644 index 0000000..cfd5026 --- /dev/null +++ b/include/libcamera/transform.h @@ -0,0 +1,193 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * transform.h - Implementation of 2d plane transforms + */ + +#ifndef __LIBCAMERA_TRANSFORM_H__ +#define __LIBCAMERA_TRANSFORM_H__ + +#include + +namespace libcamera { + +class Transform +{ +public: + constexpr Transform() + : Transform(Identity) + { + } + + constexpr static Transform identity() + { + return Transform(Identity); + } + + constexpr static Transform rot0() + { + return identity(); + } + + constexpr static Transform hflip() + { + return Transform(HFlip); + } + + constexpr static Transform vflip() + { + return Transform(VFlip); + } + + constexpr static Transform hvflip() + { + return Transform(HVFlip); + } + + constexpr static Transform rot180() + { + return hvflip(); + } + + constexpr static Transform transpose() + { + return Transform(Transpose); + } + + constexpr static Transform rot270() + { + return Transform(Rot270); + } + + constexpr static Transform rot90() + { + return Transform(Rot90); + } + + constexpr static Transform rot180Transpose() + { + return Transform(Rot180Transpose); + } + + constexpr static Transform hvflipTranspose() + { + return rot180Transpose(); + } + + constexpr static bool rotation(int32_t angle, Transform &xfm) + { + bool success = true; + angle = angle % 360; + if (angle < 0) + angle += 360; + + if (angle == 0) + xfm = identity(); + else if (angle == 90) + xfm = rot90(); + else if (angle == 180) + xfm = rot180(); + else if (angle == 270) + xfm = rot270(); + else + success = false; + + return success; + } + + constexpr bool rotation(int32_t &angle) const + { + bool success = true; + + if (type_ == Identity) + angle = 0; + else if (type_ == Rot90) + angle = 90; + else if (type_ == HVFlip) + angle = 180; + else if (type_ == Rot270) + angle = 270; + else + success = false; + + return success; + } + + constexpr bool contains(Transform xfm) const + { + return (type_ & xfm.type_) == xfm.type_; + } + + constexpr Transform inverse() const + { + /* They're all self-inverses, except for Rot90 and Rot270. */ + const Type inverses[] = { Identity, HFlip, VFlip, HVFlip, + Transpose, Rot90, Rot270, Rot180Transpose }; + + return Transform(inverses[type_]); + } + + constexpr Transform operator*(Transform xfm) const + { + /* + * Reorder the operations so that we imagine doing xfm's transpose + * (if any) after our flips. The effect is to swap our hflips for + * vflips and vice versa, after which we can just xor all the bits. + */ + int reorderedType = type_; + if (xfm.type_ & Transpose) + reorderedType = (type_ & 4) | ((type_ & 1) << 1) | ((type_ & 2) >> 1); + + return Transform((Type)(reorderedType ^ xfm.type_)); + } + + bool operator==(Transform xfm) const + { + return type_ == xfm.type_; + } + + bool operator!=(Transform xfm) const + { + return !(*this == xfm); + } + + std::string toString() const + { + char const *strings[] = { + "identity", + "hflip", + "vflip", + "hvflip", + "transpose", + "rot270", + "rot90", + "rot180transpose" + }; + return strings[type_]; + } + +private: + enum Type : int { + Identity = 0, + HFlip = 1, + VFlip = 2, + HVFlip = HFlip | VFlip, + Transpose = 4, + Rot270 = HFlip | Transpose, + Rot90 = VFlip | Transpose, + Rot180Transpose = HFlip | VFlip | Transpose + }; + + constexpr Transform(Type type) + : type_(type) + { + } + + Type type_; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_TRANSFORM_H__ */ +