Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp33439img; Tue, 19 Mar 2019 15:00:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqyn5fG6Ur+5DHZVckUEpdu1tftG+iE4YecTzzLarj5on//7VjAccBiAI5xuipvt3m268H7a X-Received: by 2002:a63:ed53:: with SMTP id m19mr3876169pgk.78.1553032803665; Tue, 19 Mar 2019 15:00:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553032803; cv=none; d=google.com; s=arc-20160816; b=w0BbaDIKE3Eca96uzTk8GKWw6nGwF82RyfrrzeBn4wclvRxImGVLvButtmBKuI9ArS M7hpaP6QDoNP0Nox2lo6VhgNM0FDv3XaQKKgL1k05U9NZv9TdPldBmkhEUNZiNb9tAGI K448smAL03i1pWwuvmpQjczWpNiKNbAMxDU9TdGCBh3qsVFdJInk9J6JPY3yPKQ+YK8P CiFeB+dRKyWZTzOs0ZdpaFUo1Cye6r0iKBq/SGAv+j2pP6tOEV0FU5X8QF9CEVdL9lcs ymkwhreohm/sKYhEhj/j9omVP/vUeBjxEWqF07D6Tx2rlbIrIYDnacGpkWhelvkiWiAO 4gBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=zUeIAs1uCvg/+4ZhJ1h8Kb1XGeEfl2/ufx3TAruT8ZU=; b=EzEGe0v0lEnOfKzhEXYLeoFeR9vak/C3wmNtnBI6fepPL58ATDUrVMu5kwe4qK/23u nLMO+iCEhRFW9jueEMeIVWFRpR+lA87E5lOIbM9wx2pc2shF68IJGgzlBUKvpG4Jip4f 7OftI48eG3McqmBm4skUIJFmdCydSEhKPE5uu8daRAIgKokxBLeBWqA9C4iNzv4iwQ+E uM1h0lueLUVinfXhuMVMWsqRviAKm/eElulaIUpzQ6WXD4hnkUCDIl+ysGYKjQT+xRGH 8fj97MMAjMwr4qIVoyN0GQbHbp95YRWpGc18s7WyVAd8Nuiu58vr32iJPpE/PoS6/gda bkbw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w5si148107plz.23.2019.03.19.14.59.48; Tue, 19 Mar 2019 15:00:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727918AbfCSV6Z (ORCPT + 99 others); Tue, 19 Mar 2019 17:58:25 -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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- git-series 0.9.1