From patchwork Tue Mar 19 21:57:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860473 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F3DEC13B5 for ; Tue, 19 Mar 2019 21:58:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCA002936B for ; Tue, 19 Mar 2019 21:58:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D133929913; Tue, 19 Mar 2019 21:58:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 775172936B for ; Tue, 19 Mar 2019 21:58:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D0CB189C2A; Tue, 19 Mar 2019 21:58:24 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by gabe.freedesktop.org (Postfix) with ESMTPS id 834D789C2A for ; Tue, 19 Mar 2019 21:58:22 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 3A4EAFF80C; Tue, 19 Mar 2019 21:58:19 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 19/20] lib: image-formats: Add more functions Date: Tue, 19 Mar 2019 22:57:24 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP V4L2 drivers typically need a few more helpers compared to DRM drivers, so let's add them. Signed-off-by: Maxime Ripard --- include/linux/image-formats.h | 4 +++- lib/image-formats.c | 42 ++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+) diff --git a/include/linux/image-formats.h b/include/linux/image-formats.h index fbc3a4501ebd..f1d4a2a03cc0 100644 --- a/include/linux/image-formats.h +++ b/include/linux/image-formats.h @@ -236,9 +236,13 @@ unsigned int image_format_plane_cpp(const struct image_format_info *format, unsigned int image_format_plane_width(int width, const struct image_format_info *format, int plane); +unsigned int image_format_plane_stride(const struct image_format_info *format, + int width, int plane); unsigned int image_format_plane_height(int height, const struct image_format_info *format, int plane); +unsigned int image_format_plane_size(const struct image_format_info *format, + int width, int height, int plane); unsigned int image_format_block_width(const struct image_format_info *format, int plane); unsigned int image_format_block_height(const struct image_format_info *format, diff --git a/lib/image-formats.c b/lib/image-formats.c index 39f1d38ae861..c4e213a89edb 100644 --- a/lib/image-formats.c +++ b/lib/image-formats.c @@ -740,6 +740,26 @@ unsigned int image_format_plane_width(int width, EXPORT_SYMBOL(image_format_plane_width); /** + * image_format_plane_stride - determine the stride value + * @format: pointer to the image_format + * @width: plane width + * @plane: plane index + * + * Returns: + * The bytes per pixel value for the specified plane. + */ +unsigned int image_format_plane_stride(const struct image_format_info *format, + unsigned int width, int plane) +{ + if (!format || plane >= format->num_planes) + return 0; + + return image_format_plane_width(width, format, plane) * + image_format_plane_cpp(format, plane); +} +EXPORT_SYMBOL(image_format_plane_stride); + +/** * image_format_plane_height - height of the plane given the first plane * @format: pointer to the image_format * @height: height of the first plane @@ -763,6 +783,28 @@ unsigned int image_format_plane_height(int height, EXPORT_SYMBOL(image_format_plane_height); /** + * image_format_plane_size - determine the size value + * @format: pointer to the image_format + * @width: plane width + * @height: plane width + * @plane: plane index + * + * Returns: + * The size of the plane buffer. + */ +unsigned int image_format_plane_size(const struct image_format_info *format, + unsigned int width, unsigned int height, + int plane) +{ + if (!format || plane >= format->num_planes) + return 0; + + return image_format_plane_stride(format, width, plane) * + image_format_plane_height(format, height, plane); +} +EXPORT_SYMBOL(image_format_plane_size); + +/** * image_format_block_width - width in pixels of block. * @format: pointer to the image_format * @plane: plane index