From patchwork Fri May 27 14:44:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 16073 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 712B0BD161 for ; Fri, 27 May 2022 14:45:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2A5A16563B; Fri, 27 May 2022 16:45:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653662709; bh=u2tqjxRj2OwecQxi/1sS9LWYVbQZr9S9oBztjV3FNyo=; 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=Qg3fHcaXGRSEL6b5cjtjPgNSvDT890FAbyaDO1If9b2N9Rh4x/LejWhamspRoGVPo c+X7NmnscG+lucRVUJBIJk/i8Y1qLHjwc2yYEauNU8lfSyQKBZQwjsb9Ds99uHaILf gmSAwP8OOl3NdqamXmfmxlUf5JB+wGEr3Nf0kRjdgjiE7jHuvNoHKBP2y+az1erqM4 DVvZvfYj9SKewCNWtnE5OJ8Zx4XHd0GLmYnvVVG2y9EJJGZQzo/KghRs5y8HItVB3a Y14n4smo/uXeUwKtcmeAyU8IgKzCbuoX+d6DfjHvcvgh07KwnihjtcUXbqIWxffrMU Y+XqeOOrL60oQ== 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 8E762633A4 for ; Fri, 27 May 2022 16:45:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Kh7cbjY3"; 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 08077B1D; Fri, 27 May 2022 16:45:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653662705; bh=u2tqjxRj2OwecQxi/1sS9LWYVbQZr9S9oBztjV3FNyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kh7cbjY3sQTKEne8uCrA6FfyLnl+5DSXTEPkDB9Z1+xVMjTNpRkAEvkmeypeCohgQ 77bWiTzk20Zl+JYJId4B6T9okQuXdiGkbXeagsnE3ptG1OC+tEJ5Yj8cpXTcaR8P8m ge3eGWNE8nZxjZbg0YHFFB/l7KruevkMUlQrYmZM= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Fri, 27 May 2022 17:44:19 +0300 Message-Id: <20220527144447.94891-3-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220527144447.94891-1-tomi.valkeinen@ideasonboard.com> References: <20220527144447.94891-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 02/30] 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 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py index 91be2a08..0a25a823 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,21 @@ 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'): + fmt = str(fmt) bayer_pattern = fmt[1:5] bitspp = int(fmt[5:]) @@ -296,7 +296,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)