From patchwork Thu Oct 19 14:01:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19160 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 26929C32BB for ; Thu, 19 Oct 2023 14:02:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C97D96299E; Thu, 19 Oct 2023 16:02:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697724122; bh=jPUq1A9sUQKQYtv41RZ3i6l4nfYqyMpxL+pYMbxUW64=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=vNbr5zhaUmj8hQFNjna4l4Z9h851bA3ScD6HH0hUBNPUpTnlD5/6tx41D3TLCtjxM f0afQ5qDgkkA/xLgxy3CdK2txOb6Tw9vnplmX25xKVigCTKin/q8OtMgwoObMyNf3F Qe45L7pIkN8MY9GJPIgNnT0ypjqueY1MDnQpH+sULY23wFyKXVUCNyJzDYa6FdOlgc jDBjuOkFtRBeb5m3Ndkpjok4MRfrydESnKSPr49fLSMy/DZMHFfgSQLdWif5AEcZGQ BsQJuO4PCSLP0Efs6i9U/IiJFfOkGDsgwfLbcH3VIkhEGH/BBh4Q9EVMKsm4+ofsgn WchCmGNdz0K3Q== 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 9C1C862982 for ; Thu, 19 Oct 2023 16:01:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qRy1LNiC"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 90D93735; Thu, 19 Oct 2023 16:01:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1697724106; bh=jPUq1A9sUQKQYtv41RZ3i6l4nfYqyMpxL+pYMbxUW64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qRy1LNiCPY+mmNAnUrfPmGnwXlAv3nUeXWJCPXPl9svVGUHV6r7k2W9L5gpmGnEdt X5kdjSFntsi2JiHXi152h5DLMbh5t2L1wxp4TakwesKipLdUboQh88bAUPtlmjhaCw rfOhF08KCKyyQkCcBRmQ42fjZz8CEHyhM6/vBtw8= To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Oct 2023 16:01:33 +0200 Message-ID: <20231019140133.32090-13-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 12/12] py: cam: Add option to set stream orientation 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: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a '--orientation|-o' option to the Python version of the cam test application to set an orientation to the image stream. Supported values are: - rot0: no rotation - rot180: rotate 180 degrees - flip: vertical flip - mirror: horizontal flip Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/py/cam/cam.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py index a2a115c164b4..06bd51aa5efe 100755 --- a/src/py/cam/cam.py +++ b/src/py/cam/cam.py @@ -23,6 +23,7 @@ class CameraContext: opt_metadata: bool opt_save_frames: bool opt_capture: int + opt_orientation: str stream_names: dict[libcam.Stream, str] streams: list[libcam.Stream] @@ -146,6 +147,21 @@ class CameraContext: if 'pixelformat' in stream_opts: stream_config.pixel_format = libcam.PixelFormat(stream_opts['pixelformat']) + if self.opt_orientation is not None: + orientation_map = { + 'rot0': libcam.Orientation.Rotate0, + 'rot180': libcam.Orientation.Rotate180, + 'mirror': libcam.Orientation.Rotate0Mirror, + 'flip': libcam.Orientation.Rotate180Mirror, + } + + orient = orientation_map.get(self.opt_orientation, None) + if orient is None: + print('Bad orientation: ', self.opt_orientation) + sys.exit(-1) + + camconfig.orientation = orient + stat = camconfig.validate() if stat == libcam.CameraConfiguration.Status.Invalid: @@ -385,6 +401,7 @@ def main(): parser.add_argument('--metadata', nargs=0, type=bool, action=CustomAction, help='Print the metadata for completed requests') parser.add_argument('--strict-formats', type=bool, nargs=0, action=CustomAction, help='Do not allow requested stream format(s) to be adjusted') parser.add_argument('-s', '--stream', nargs='+', action=CustomAction) + parser.add_argument('-o', '--orientation', help='Desired image orientation (rot0, rot180, mirror, flip)') args = parser.parse_args() cm = libcam.CameraManager.singleton() @@ -408,6 +425,10 @@ def main(): ctx.opt_metadata = args.metadata.get(cam_idx, False) ctx.opt_strict_formats = args.strict_formats.get(cam_idx, False) ctx.opt_stream = args.stream.get(cam_idx, ['role=viewfinder']) + if args.orientation is not None: + ctx.opt_orientation = args.orientation + else: + ctx.opt_orientation = None contexts.append(ctx) for ctx in contexts: