[{"id":23055,"web_url":"https://patchwork.libcamera.org/comment/23055/","msgid":"<YoT7jGQFmLGhCmkI@pendragon.ideasonboard.com>","date":"2022-05-18T13:58:36","subject":"Re: [libcamera-devel] [PATCH v3 18/18] py: cam_qt: use\n\tlibcamera.formats","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Tomi,\n\nThank you for the patch.\n\nOn Wed, May 18, 2022 at 04:13:29PM +0300, Tomi Valkeinen wrote:\n> Use the new libcamera.formats in cam_qt.py.\n> \n> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n> ---\n>  src/py/cam/cam_qt.py | 17 +++++++++--------\n>  1 file changed, 9 insertions(+), 8 deletions(-)\n> \n> diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py\n> index 91be2a08..142bb35e 100644\n> --- a/src/py/cam/cam_qt.py\n> +++ b/src/py/cam/cam_qt.py\n> @@ -8,6 +8,7 @@ from numpy.lib.stride_tricks import as_strided\n>  from PIL import Image\n>  from PIL.ImageQt import ImageQt\n>  from PyQt5 import QtCore, QtGui, QtWidgets\n> +import libcamera as libcam\n>  import numpy as np\n>  import sys\n>  \n> @@ -87,9 +88,7 @@ def to_rgb(fmt, size, data):\n>      w = size.width\n>      h = size.height\n>  \n> -    fmt = str(fmt)\n> -\n> -    if fmt == 'YUYV':\n> +    if fmt == libcam.formats.YUYV:\n>          # YUV422\n>          yuyv = data.reshape((h, w // 2 * 4))\n>  \n> @@ -111,20 +110,22 @@ def to_rgb(fmt, size, data):\n>          rgb[:, :, 2] -= 226.8183044444304\n>          rgb = rgb.astype(np.uint8)\n>  \n> -    elif fmt == 'RGB888':\n> +    elif fmt == libcam.formats.RGB888:\n>          rgb = data.reshape((h, w, 3))\n>          rgb[:, :, [0, 1, 2]] = rgb[:, :, [2, 1, 0]]\n>  \n> -    elif fmt == 'BGR888':\n> +    elif fmt == libcam.formats.BGR888:\n>          rgb = data.reshape((h, w, 3))\n>  \n> -    elif fmt in ['ARGB8888', 'XRGB8888']:\n> +    elif fmt in [libcam.formats.ARGB8888, libcam.formats.XRGB8888]:\n>          rgb = data.reshape((h, w, 4))\n>          rgb = np.flip(rgb, axis=2)\n>          # drop alpha component\n>          rgb = np.delete(rgb, np.s_[0::4], axis=2)\n>  \n> -    elif fmt.startswith('S'):\n> +    elif str(fmt).startswith('S'):\n> +        # \\todo implement PixelFormatInfo and use it here\n\nPixelFormatInfo is not exposed through the libcamera public API, so I'd\ndrop this comment.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +        fmt = str(fmt)\n>          bayer_pattern = fmt[1:5]\n>          bitspp = int(fmt[5:])\n>  \n> @@ -296,7 +297,7 @@ class MainWindow(QtWidgets.QWidget):\n>              h = cfg.size.height\n>              pitch = cfg.stride\n>  \n> -            if str(cfg.pixel_format) == 'MJPEG':\n> +            if cfg.pixel_format == libcam.formats.MJPEG:\n>                  img = Image.open(BytesIO(mfb.planes[0]))\n>                  qim = ImageQt(img).copy()\n>                  pix = QtGui.QPixmap.fromImage(qim)","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 26F67C3256\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 18 May 2022 13:58:45 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7CC9165657;\n\tWed, 18 May 2022 15:58:44 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7C18965656\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 18 May 2022 15:58:43 +0200 (CEST)","from pendragon.ideasonboard.com (unknown [45.131.31.124])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C09D9E50;\n\tWed, 18 May 2022 15:58:42 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1652882324;\n\tbh=Zk/BNh4T/G+5eUE3AhQkyCEJVIS/FFstdkevnPP2bIY=;\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=qb8o/e+HYfxZWzVQ/tAFSOTpoewPeMOgtcxohE1LfnFl/sYCRC8fZf1q+kBfEJEQZ\n\taokxHYPptxbetZF/BEPGKpW9aMNYkWAmS+6x9udn74boGyyjbjqq0bY+oAHKJTcV1h\n\tTMS+rWRliaqt53o8mIe18Ed6UiJl4uwT/u8bh0TF0rgMyl648B8M8NlBQinu+Be86f\n\t6d9PN1ZpeH2bdQc1ZKdKW16qdvQ/Invz485hSea4c5AtOKQGhqb9Z0JvY9XuTBE13y\n\tu6qRtxfKa7NmKxheNrVPBv6jcKH3lG1poDlGrVVujQCxkaM2VAe0SjdfmXEWbjpnoS\n\tZKU5LI541y5Sg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1652882323;\n\tbh=Zk/BNh4T/G+5eUE3AhQkyCEJVIS/FFstdkevnPP2bIY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=f/rgxZdvpjIYyiKpaaeF23Icxto3iRTSCfwKEeJ7Rdp7QeZKxNmPDFl9OuZVyR7RM\n\tI7yEnxuIfFwVhXntT5THVsfK1QcEvuJ5EdJr4G+ev09rKPmXyonpzaNcdZTukWrl7m\n\tQ4pMWphGffuq7pFI63GnYMyxr6Iqg64j7NcCQm9E="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"f/rgxZdv\"; dkim-atps=neutral","Date":"Wed, 18 May 2022 16:58:36 +0300","To":"Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Message-ID":"<YoT7jGQFmLGhCmkI@pendragon.ideasonboard.com>","References":"<20220518131329.66994-1-tomi.valkeinen@ideasonboard.com>\n\t<20220518131329.66994-19-tomi.valkeinen@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220518131329.66994-19-tomi.valkeinen@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 18/18] py: cam_qt: use\n\tlibcamera.formats","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>"}},{"id":23062,"web_url":"https://patchwork.libcamera.org/comment/23062/","msgid":"<165288351677.368702.7876296186738620274@Monstersaurus>","date":"2022-05-18T14:18:36","subject":"Re: [libcamera-devel] [PATCH v3 18/18] py: cam_qt: use\n\tlibcamera.formats","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Tomi Valkeinen (2022-05-18 14:13:29)\n> Use the new libcamera.formats in cam_qt.py.\n> \n\nAha, this answers my question in the previous patch.\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n> ---\n>  src/py/cam/cam_qt.py | 17 +++++++++--------\n>  1 file changed, 9 insertions(+), 8 deletions(-)\n> \n> diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py\n> index 91be2a08..142bb35e 100644\n> --- a/src/py/cam/cam_qt.py\n> +++ b/src/py/cam/cam_qt.py\n> @@ -8,6 +8,7 @@ from numpy.lib.stride_tricks import as_strided\n>  from PIL import Image\n>  from PIL.ImageQt import ImageQt\n>  from PyQt5 import QtCore, QtGui, QtWidgets\n> +import libcamera as libcam\n>  import numpy as np\n>  import sys\n>  \n> @@ -87,9 +88,7 @@ def to_rgb(fmt, size, data):\n>      w = size.width\n>      h = size.height\n>  \n> -    fmt = str(fmt)\n> -\n> -    if fmt == 'YUYV':\n> +    if fmt == libcam.formats.YUYV:\n>          # YUV422\n>          yuyv = data.reshape((h, w // 2 * 4))\n>  \n> @@ -111,20 +110,22 @@ def to_rgb(fmt, size, data):\n>          rgb[:, :, 2] -= 226.8183044444304\n>          rgb = rgb.astype(np.uint8)\n>  \n> -    elif fmt == 'RGB888':\n> +    elif fmt == libcam.formats.RGB888:\n>          rgb = data.reshape((h, w, 3))\n>          rgb[:, :, [0, 1, 2]] = rgb[:, :, [2, 1, 0]]\n>  \n> -    elif fmt == 'BGR888':\n> +    elif fmt == libcam.formats.BGR888:\n>          rgb = data.reshape((h, w, 3))\n>  \n> -    elif fmt in ['ARGB8888', 'XRGB8888']:\n> +    elif fmt in [libcam.formats.ARGB8888, libcam.formats.XRGB8888]:\n>          rgb = data.reshape((h, w, 4))\n>          rgb = np.flip(rgb, axis=2)\n>          # drop alpha component\n>          rgb = np.delete(rgb, np.s_[0::4], axis=2)\n>  \n> -    elif fmt.startswith('S'):\n> +    elif str(fmt).startswith('S'):\n> +        # \\todo implement PixelFormatInfo and use it here\n> +        fmt = str(fmt)\n>          bayer_pattern = fmt[1:5]\n>          bitspp = int(fmt[5:])\n>  \n> @@ -296,7 +297,7 @@ class MainWindow(QtWidgets.QWidget):\n>              h = cfg.size.height\n>              pitch = cfg.stride\n>  \n> -            if str(cfg.pixel_format) == 'MJPEG':\n> +            if cfg.pixel_format == libcam.formats.MJPEG:\n>                  img = Image.open(BytesIO(mfb.planes[0]))\n>                  qim = ImageQt(img).copy()\n>                  pix = QtGui.QPixmap.fromImage(qim)\n> -- \n> 2.34.1\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 A6C47C0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 18 May 2022 14:18:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F3DBA65659;\n\tWed, 18 May 2022 16:18:40 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7427C65656\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 18 May 2022 16:18:39 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EAC7AE50;\n\tWed, 18 May 2022 16:18:38 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1652883521;\n\tbh=LmknHamWp0CjY3Iri23ZMka4VCUYnD8MQHt+lgQO/4Q=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=EwuzWdlr7QeBKRhy2hYDvbHQ1WjiL0wo2/4MU8X48lNVqRWQ8AfWGK1cWaeM3fwEF\n\trjlBly7628YEFg4Jee0gzu7x5EDDlxLkXzs2GDCGkdNDd03AobXm5nWSxw6PACWN+t\n\tONnz5JBWPz+AX/FUu/4ZD9cfKGv9xVCm+hEq7hetrpQFKZAuTbWtlKvDxPccoi1SlW\n\teYTgPsEn7ja6nRdwmDzXUb1bYveq+QazGaH6r8VAI8wFbxnCwEkcBSVIJlIm41WB7O\n\t7pslhmaPiJ6Ew+uiDWKpOwhPa2O///gBeDIVlahxT1zbvjbx/oumdrnsLFNrHwTJfe\n\tQH4DF/i+EeGGg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1652883519;\n\tbh=LmknHamWp0CjY3Iri23ZMka4VCUYnD8MQHt+lgQO/4Q=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=enfmQLZ/4r0eFzI9Cy838rnbZDlnzidcH99ZjYJhSwagIWIgbeUunmGrBnovLIexw\n\tfRnc2gW+9k1XosUms0MBHfTVlQzGipOw7lx4ysz4xRcpXFRyFPg5aYCs0VYuxQBdpK\n\tUHZE+5bWUuhlBwOJkzawOZ/JpWw9CyZ/5g22eBLo="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"enfmQLZ/\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220518131329.66994-19-tomi.valkeinen@ideasonboard.com>","References":"<20220518131329.66994-1-tomi.valkeinen@ideasonboard.com>\n\t<20220518131329.66994-19-tomi.valkeinen@ideasonboard.com>","To":"David Plowman <david.plowman@raspberrypi.com>,\n\tJacopo Mondi <jacopo@jmondi.org>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tTomi Valkeinen <tomi.valkeinen@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 18 May 2022 15:18:36 +0100","Message-ID":"<165288351677.368702.7876296186738620274@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v3 18/18] py: cam_qt: use\n\tlibcamera.formats","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":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]