From patchwork Wed May 18 13:13:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15968 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 4D826C3276 for ; Wed, 18 May 2022 13:14:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D36F465681; Wed, 18 May 2022 15:14:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879651; bh=Q25Ba4mjLxmvzDleDRORF9gDsRZxtS6O/odB5NQekI4=; 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=unMtBjAUPUjs6CcP66DUPoeLfmFfVkU3se6cZLaedPnHsyNKd/14uBJVj9WDYPkHE 3DcpAb2PTSc6j85zplsxGWivM89WE7LYFHA8f7vLIiNLvlSRF72zT7xQUsb+6ewjZo 9N4kE7kLPvqxSwOKEm3vm5NWi7Pr/1VIQvYGrvOrGab220yDF8sgXZS1y9zkeQQzzi GhrJxfecXu6uzEPdPlIwXXzoEWPfoXbVuSkIkvfstj5LN2PVTRKWy24nUwueAf+cpk 66PLdu21/s+6XODC9YVZJwI/y2laFE/7gb2iRTwtp52dzp6Z10+Mo+6TKVnw80+GkE FkFV9DNx5BHVQ== 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 9F0336565E for ; Wed, 18 May 2022 15:13:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="aHlkCN6G"; 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 1B9561BBB; Wed, 18 May 2022 15:13:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879635; bh=Q25Ba4mjLxmvzDleDRORF9gDsRZxtS6O/odB5NQekI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aHlkCN6GWBj5nBEGydA4AjeerLetKbEJIKRhQbl2B7rhoGqe1JcobIrk0lR5ceAHb KvzRHB3nXBGPS0DUNpLmswBjiNySp18Jn2l0HJwpdZJy10G4ge+m3nytBLIrqW1+lN ini6cHlSYFHsTyn2a6PloxBAsWO2kBRld3u74yhU= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:29 +0300 Message-Id: <20220518131329.66994-19-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 18/18] py: cam_qt: use libcamera.formats 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" Use the new libcamera.formats in cam_qt.py. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/py/cam/cam_qt.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py index 91be2a08..142bb35e 100644 --- a/src/py/cam/cam_qt.py +++ b/src/py/cam/cam_qt.py @@ -8,6 +8,7 @@ from numpy.lib.stride_tricks import as_strided from PIL import Image from PIL.ImageQt import ImageQt from PyQt5 import QtCore, QtGui, QtWidgets +import libcamera as libcam import numpy as np import sys @@ -87,9 +88,7 @@ def to_rgb(fmt, size, data): w = size.width h = size.height - fmt = str(fmt) - - if fmt == 'YUYV': + if fmt == libcam.formats.YUYV: # YUV422 yuyv = data.reshape((h, w // 2 * 4)) @@ -111,20 +110,22 @@ def to_rgb(fmt, size, data): rgb[:, :, 2] -= 226.8183044444304 rgb = rgb.astype(np.uint8) - elif fmt == 'RGB888': + elif fmt == libcam.formats.RGB888: rgb = data.reshape((h, w, 3)) rgb[:, :, [0, 1, 2]] = rgb[:, :, [2, 1, 0]] - elif fmt == 'BGR888': + elif fmt == libcam.formats.BGR888: rgb = data.reshape((h, w, 3)) - elif fmt in ['ARGB8888', 'XRGB8888']: + elif fmt in [libcam.formats.ARGB8888, libcam.formats.XRGB8888]: rgb = data.reshape((h, w, 4)) rgb = np.flip(rgb, axis=2) # drop alpha component rgb = np.delete(rgb, np.s_[0::4], axis=2) - elif fmt.startswith('S'): + elif str(fmt).startswith('S'): + # \todo implement PixelFormatInfo and use it here + fmt = str(fmt) bayer_pattern = fmt[1:5] bitspp = int(fmt[5:]) @@ -296,7 +297,7 @@ class MainWindow(QtWidgets.QWidget): h = cfg.size.height pitch = cfg.stride - if str(cfg.pixel_format) == 'MJPEG': + if cfg.pixel_format == libcam.formats.MJPEG: img = Image.open(BytesIO(mfb.planes[0])) qim = ImageQt(img).copy() pix = QtGui.QPixmap.fromImage(qim)