{"id":8503,"url":"https://patchwork.libcamera.org/api/1.1/patches/8503/?format=json","web_url":"https://patchwork.libcamera.org/patch/8503/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200629151411.216477-5-paul.elder@ideasonboard.com>","date":"2020-06-29T15:14:09","name":"[libcamera-devel,4/6] libcamera: PixelFormatInfo: Add methods bytesPerLine and imageSize","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"742662d3baba6fac9fad18d08e51daa539384a78","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/1.1/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/8503/mbox/","series":[{"id":1056,"url":"https://patchwork.libcamera.org/api/1.1/series/1056/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1056","date":"2020-06-29T15:14:05","name":"Move formats from v4l2-compat into libcamera","version":1,"mbox":"https://patchwork.libcamera.org/series/1056/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/8503/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/8503/checks/","tags":{},"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 87046BFFE2\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 29 Jun 2020 15:14:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 431F060AF9;\n\tMon, 29 Jun 2020 17:14:31 +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 2A93A609C8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Jun 2020 17:14:30 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:2c71:1b79:d06d:5032])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BA45D299;\n\tMon, 29 Jun 2020 17:14:28 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"wUr0DQP4\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1593443669;\n\tbh=uDGAMhzcGy4/p/LxfmWvTyzPftJuB8tIFbXFSA0nhjI=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=wUr0DQP4oW5a2XRK8m53YhZ/Sp2tdx4Agqdlj7FnuWdrbyxVglu85jrwKubgk8CSO\n\tUo/UYr7ybP293o1Z3BZsSwXJFi6Zn4qcBnpwalmq3Eg2UkTo3itnMUu7r22X8gKbi0\n\tIExVXQkZLocsWo/AC+vB/oBRohSmGhpw6A9df4wU=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 30 Jun 2020 00:14:09 +0900","Message-Id":"<20200629151411.216477-5-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20200629151411.216477-1-paul.elder@ideasonboard.com>","References":"<20200629151411.216477-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH 4/6] libcamera: PixelFormatInfo: Add\n\tmethods bytesPerLine and imageSize","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add instance methods to PixelFormatInfo for calculating bytes-per-line\nand image size. This will simplify existing code that calculates these\nthings.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n include/libcamera/internal/formats.h |  3 +++\n src/libcamera/formats.cpp            | 21 +++++++++++++++++++++\n 2 files changed, 24 insertions(+)","diff":"diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h\nindex 3c7440a..1372a43 100644\n--- a/include/libcamera/internal/formats.h\n+++ b/include/libcamera/internal/formats.h\n@@ -46,6 +46,9 @@ public:\n \tstatic const PixelFormatInfo &info(const PixelFormat &format);\n \tstatic const PixelFormatInfo &info(const V4L2PixelFormat &format);\n \n+\tunsigned int bytesPerLine(unsigned int width);\n+\tunsigned int imageSize(unsigned int width, unsigned int height);\n+\n \tconst char *name;\n \tPixelFormat format;\n \tV4L2PixelFormat v4l2Format;\ndiff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp\nindex 7029a94..dc1d348 100644\n--- a/src/libcamera/formats.cpp\n+++ b/src/libcamera/formats.cpp\n@@ -7,12 +7,16 @@\n \n #include \"libcamera/internal/formats.h\"\n \n+#include <algorithm>\n #include <errno.h>\n \n #include <libcamera/formats.h>\n \n #include \"libcamera/internal/log.h\"\n \n+\n+#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))\n+\n /**\n  * \\file internal/formats.h\n  * \\brief Types and helper methods to handle libcamera image formats\n@@ -670,4 +674,21 @@ const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format)\n \treturn info->second;\n }\n \n+unsigned int PixelFormatInfo::bytesPerLine(unsigned int width)\n+{\n+\tif (!isValid())\n+\t\treturn 0;\n+\n+\treturn DIV_ROUND_UP(width, pixelsPerGroup) * bytesPerGroup;\n+\n+}\n+\n+unsigned int PixelFormatInfo::imageSize(unsigned int width, unsigned int height)\n+{\n+\tif (!isValid())\n+\t\treturn 0;\n+\n+\treturn height * bytesPerLine(width);\n+}\n+\n } /* namespace libcamera */\n","prefixes":["libcamera-devel","4/6"]}