From patchwork Tue Jun 30 14:58:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8523 X-Patchwork-Delegate: paul.elder@ideasonboard.com 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 7B5CEBF415 for ; Tue, 30 Jun 2020 14:58:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 480BD60C61; Tue, 30 Jun 2020 16:58:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="CQwDS5DF"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 19EAD60C5F for ; Tue, 30 Jun 2020 16:58:31 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 970A329F; Tue, 30 Jun 2020 16:58:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1593529110; bh=Gy7Ju+OuZwBHQkoZozUhku4niNFTxzhbSrTNSWuo3Gs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CQwDS5DFWEPTbrqrEHKDiuxhv3I4PV7KkrHDI3EfHUAvZAbaVW+Z0bHEOfsH50pCq 3350+sOLLXxa3WWnAEjjM1/zKV/j4LeyNDura0+LZ3fMtQyaOMYtj4ZUfMgLzYWVVV 1Ha1mu2iVMUa4dDGowtFcyhNAL8EFgz2AplfFE78= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Tue, 30 Jun 2020 23:58:06 +0900 Message-Id: <20200630145808.2976956-5-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200630145808.2976956-1-paul.elder@ideasonboard.com> References: <20200630145808.2976956-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/6] libcamera: PixelFormatInfo: Add functions bytesPerLine and imageSize 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add member functions to PixelFormatInfo for calculating bytes-per-line and image size. This will simplify existing code that calculates these things. Signed-off-by: Paul Elder --- Changes in v2: - make these functions const - add documentation - inline DIV_ROUND_UP --- include/libcamera/internal/formats.h | 3 +++ src/libcamera/formats.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h index 3c7440a..af0f1ac 100644 --- a/include/libcamera/internal/formats.h +++ b/include/libcamera/internal/formats.h @@ -46,6 +46,9 @@ public: static const PixelFormatInfo &info(const PixelFormat &format); static const PixelFormatInfo &info(const V4L2PixelFormat &format); + unsigned int bytesPerLine(unsigned int width) const; + unsigned int imageSize(const Size &size) const; + const char *name; PixelFormat format; V4L2PixelFormat v4l2Format; diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index 4d18825..698c905 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -693,4 +693,31 @@ const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format) return info->second; } +/** + * \brief Compute the bytes per line + * \param[in] width The width of the line, in pixels + * \return The number of bytes necessary to store the line, or 0 if the + * PixelFormatInfo instance not valid + */ +unsigned int PixelFormatInfo::bytesPerLine(unsigned int width) const +{ + if (!isValid()) + return 0; + + /* ceil(width / pixelsPerGroup) * bytesPerGroup */ + return ((width + pixelsPerGroup - 1) / pixelsPerGroup) * bytesPerGroup; + +} + +/** + * \brief Compute the bytes necessary to store the frame + * \param[in] size The size of the frame, in pixels + * \return The number of bytes necessary to store the frame, or 0 if the + * PixelFormatInfo instance is not valid + */ +unsigned int PixelFormatInfo::imageSize(const Size &size) const +{ + return size.height * bytesPerLine(size.width); +} + } /* namespace libcamera */