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: 10860485 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 AF3D36C2 for ; Tue, 19 Mar 2019 21:58:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94EDD2917E for ; Tue, 19 Mar 2019 21:58:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88FF9298FF; Tue, 19 Mar 2019 21:58:47 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2814429912 for ; Tue, 19 Mar 2019 21:58:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727908AbfCSV6Y (ORCPT ); Tue, 19 Mar 2019 17:58:24 -0400 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:41529 "EHLO relay9-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727442AbfCSV6X (ORCPT ); Tue, 19 Mar 2019 17:58:23 -0400 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 Cc: Sakari Ailus , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , Paul Kocialkowski , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org 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 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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