[{"id":10993,"web_url":"https://patchwork.libcamera.org/comment/10993/","msgid":"<20200629215406.GB21452@pendragon.ideasonboard.com>","date":"2020-06-29T21:54:06","subject":"Re: [libcamera-devel] [PATCH 4/6] libcamera: PixelFormatInfo: Add\n\tmethods bytesPerLine and imageSize","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\n\nThank you for the patch.\n\nOn Tue, Jun 30, 2020 at 12:14:09AM +0900, Paul Elder wrote:\n> Add instance methods to PixelFormatInfo for calculating bytes-per-line\n\nThey're called member functions in C++ :-) \"instance method\" is Java.\n\n> and image size. This will simplify existing code that calculates these\n> things.\n\nLet's bikeshed the names in 2/6.\n\n> Signed-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(+)\n> \n> diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h\n> index 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;\n> diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp\n> index 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\nIs this needed ? Does it belong to 3/6 ?\n\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\nIf this is used in a single place, I'd rather inline it. Otherwise it\nshould go to utils.h (as an inline function instead of a macro for type\nsafety and to avoid evaluating d twice).\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\nMissing documentation for these two functions.\n\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\nYou could skip this as bytesPerLine() has the same check.\n\n> +\n> +\treturn height * bytesPerLine(width);\n> +}\n> +\n>  } /* namespace libcamera */","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 1D08CBFFE2\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 29 Jun 2020 21:54:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8B0A3609DD;\n\tMon, 29 Jun 2020 23:54:11 +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 E145A603B2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Jun 2020 23:54:10 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 54882299;\n\tMon, 29 Jun 2020 23:54:10 +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=\"u/TQgxa/\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1593467650;\n\tbh=v3o5tgUGWhmve3YqJ35uD8pZESmEriHMgNbbiUbepFc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=u/TQgxa/+oNtjv/UqD1Am22Prnn7sRfEQaWMs52byEy6eFlJaNl4HEGgL0X5jT+nW\n\tV2rc1GgzLLQhpR+jTmkqV69nMpMiG56LrHd/LPkGCdGjg3x6oY4vAaLVpeKW2UIaci\n\tDKWmfNRBxqEK5FypO4nSXd7+wGlpuS2Zxq1awuxk=","Date":"Tue, 30 Jun 2020 00:54:06 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Message-ID":"<20200629215406.GB21452@pendragon.ideasonboard.com>","References":"<20200629151411.216477-1-paul.elder@ideasonboard.com>\n\t<20200629151411.216477-5-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200629151411.216477-5-paul.elder@ideasonboard.com>","Subject":"Re: [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>","Cc":"libcamera-devel@lists.libcamera.org","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>"}}]