From patchwork Thu Jan 12 12:56:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 42410 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3864019wrt; Thu, 12 Jan 2023 04:57:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXuPddqzfRlEnEVY6/e3wTWQx91ij5UAvOkb77VTevmdTWmq4nMaCvDOPhpb0EnkNReX+bjJ X-Received: by 2002:a05:6a20:6f61:b0:9d:efd3:66f7 with SMTP id gu33-20020a056a206f6100b0009defd366f7mr74878548pzb.62.1673528255518; Thu, 12 Jan 2023 04:57:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673528255; cv=none; d=google.com; s=arc-20160816; b=VLkpqACf+gGwcBV+hKn9gTmfCqQ3x8qb51s8ybV3/EOdM2gyTi+7GAWWqxd7/abNfg fVYZM7yCk/OzCDTfEuJ+YFXmIVIXD2NUeP+He9FdCrDvnxwy/6+Vp4pSO24Mn5v540rQ Ibpkhnwfc2n00FSsqrvGwdu7VuEON+iEFh4Jiwrydwhnp/wDAzH9zqT/hFIm+a/tV8my 7ec4iYT80as/DGB58XpnAvv9RWOr7ujTA47I1+Fpzr7vKdz41Ny0Tpbk3NE0i9SM+lX4 +3NgVoHwOssxAg3p66DnXCNmilKpnXmK3hNBkJ7qagA6BhvZa1e6p2JDolZSRYnLPdpF XJPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=Q23ScXl8Txb5EkICgQZ6ADMLJn90AMngCxRqruQOP9o=; b=K/JdlPyc5T0IxQhKsNzEayxyE7TC00V8hC+Q4MgUqWIk+K6g49a2qkgDhlLB5u741n Xjplpez4JpCYe0yusQZyfef6MVG41szCmTrLwTpp4VyZGYK0up3bfGnyf1071GhNGWnK n5jsSxHntmfElRJ1BrZdaAPkRzbop6K5NtaJ/DvF+9Fe7dyNpqh0OUGX3ZyOvxIWVFrS p7oDHq7fB0a0ekmzASwkPcZdF3p2tloJ2qlFME8+RfdWG/rC4H6g1cuBg6TGgxOy5uIY Z0kPk7NLqXyCeRtVrmBzk3CFp27er46dxQWNvbEBpDNMr2zDBbtqhXQYIfaj3/Tu+ogc xXOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XOPL1XeR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c20-20020a6566d4000000b004b3b04315cdsi11016667pgw.180.2023.01.12.04.57.23; Thu, 12 Jan 2023 04:57:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XOPL1XeR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232010AbjALM5H (ORCPT + 99 others); Thu, 12 Jan 2023 07:57:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231434AbjALM4h (ORCPT ); Thu, 12 Jan 2023 07:56:37 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88EC7AE4A; Thu, 12 Jan 2023 04:56:36 -0800 (PST) Received: from localhost (89-26-75-29.goll.dyn.salzburg-online.at [89.26.75.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sebastianfricke) by madras.collabora.co.uk (Postfix) with ESMTPSA id 2E7356602DBC; Thu, 12 Jan 2023 12:56:35 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1673528195; bh=TMBuSYYQgufdE8ilX8+9MkfvSRLEsm/O1NHAsGj+B/Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XOPL1XeRQInEt43srKZYrnrk2C/E2t6TlKO5p4bXvoEV/zBpFhHONeClKtTqj6JBz 4o16E9P1tWHpCvOrfc/+9iIjNnCFUEt3alSQI9jpYrBa97dU0lspWglEQG7xskQ+Vh XgKtlMfpbzLXq5q5BhUkbtzWVHVDkvZEYFxOjhJNvkgCXtU1KoG3oR4M3PnfACexdl 9q7Korw+75cBpygJm/0frQyYKChkqDwnB9NkXuNDQiZrBS9TrMrOaalV1OFgwXKasX moplnbm24XFPXMFZ9qSAmZAwk4rp/hYi5DzvT741iOfZxvOz2Ti1iZicgEHEOkRIEQ VFf5gm44ncdsA== From: Sebastian Fricke Date: Thu, 12 Jan 2023 13:56:17 +0100 Subject: [PATCH v2 02/12] media: v4l2-common: Add helpers to calculate bytesperline and sizeimage MIME-Version: 1.0 Message-Id: <20230101-patch-series-v2-6-2-rc1-v2-2-fa1897efac14@collabora.com> References: <20230101-patch-series-v2-6-2-rc1-v2-0-fa1897efac14@collabora.com> In-Reply-To: <20230101-patch-series-v2-6-2-rc1-v2-0-fa1897efac14@collabora.com> To: Mauro Carvalho Chehab , Ezequiel Garcia , Greg Kroah-Hartman Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, Jonas Karlman , Alex Bee , Nicolas Dufresne , Collabora Kernel-domain , Robert Beckett , Laurent Pinchart , Andrzej Pietrasiewicz , Benjamin Gaignard , Sebastian Fricke X-Mailer: b4 0.11.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1673528186; l=4683; i=sebastian.fricke@collabora.com; s=linux-media; h=from:subject:message-id; bh=LcMmGvBIJq4nek85HGURC0+BOvaXuS5YxkC2HDnyM4I=; b=21yB2ximJGHXO2qRmwC71wOACLdxQEDfraCFxz9My9OOeP/Bg30IT6qXnRdRmTEICA6UNWxjEJjI 0AsKrLSDBeIJqIIhK3dU2M8+aYSDn/AyK7/xOhcyFbJLtFv1L49Z X-Developer-Key: i=sebastian.fricke@collabora.com; a=ed25519; pk=pYXedPwrTtErcj7ERYeo/IpTrpe4QbJuEzSB52fslBg= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754821564403088966?= X-GMAIL-MSGID: =?utf-8?q?1754821564403088966?= From: Jonas Karlman Add helper functions to calculate plane bytesperline and sizeimage, these new helpers consider block width and height when calculating plane bytesperline and sizeimage. This prepares support for a new pixel format added in next patch that makes use of block width and height. Signed-off-by: Jonas Karlman --- drivers/media/v4l2-core/v4l2-common.c | 77 +++++++++++++++++------------------ 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c index be23e319fb3a..12c1d2f409b0 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -340,6 +340,33 @@ static inline unsigned int v4l2_format_block_height(const struct v4l2_format_inf return info->block_h[plane]; } +static inline unsigned int v4l2_format_plane_width(const struct v4l2_format_info *info, int plane, + unsigned int width) +{ + unsigned int hdiv = plane ? info->hdiv : 1; + unsigned int bytes = DIV_ROUND_UP(width * info->bpp[plane], + v4l2_format_block_width(info, plane) * + v4l2_format_block_height(info, plane)); + + return DIV_ROUND_UP(bytes, hdiv); +} + +static inline unsigned int v4l2_format_plane_height(const struct v4l2_format_info *info, int plane, + unsigned int height) +{ + unsigned int vdiv = plane ? info->vdiv : 1; + unsigned int lines = ALIGN(height, v4l2_format_block_height(info, plane)); + + return DIV_ROUND_UP(lines, vdiv); +} + +static inline unsigned int v4l2_format_plane_size(const struct v4l2_format_info *info, int plane, + unsigned int width, unsigned int height) +{ + return v4l2_format_plane_width(info, plane, width) * + v4l2_format_plane_height(info, plane, height); +} + void v4l2_apply_frmsize_constraints(u32 *width, u32 *height, const struct v4l2_frmsize_stepwise *frmsize) { @@ -375,37 +402,19 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, if (info->mem_planes == 1) { plane = &pixfmt->plane_fmt[0]; - plane->bytesperline = ALIGN(width, v4l2_format_block_width(info, 0)) * info->bpp[0]; + plane->bytesperline = v4l2_format_plane_width(info, 0, width); plane->sizeimage = 0; - for (i = 0; i < info->comp_planes; i++) { - unsigned int hdiv = (i == 0) ? 1 : info->hdiv; - unsigned int vdiv = (i == 0) ? 1 : info->vdiv; - unsigned int aligned_width; - unsigned int aligned_height; - - aligned_width = ALIGN(width, v4l2_format_block_width(info, i)); - aligned_height = ALIGN(height, v4l2_format_block_height(info, i)); - - plane->sizeimage += info->bpp[i] * - DIV_ROUND_UP(aligned_width, hdiv) * - DIV_ROUND_UP(aligned_height, vdiv); - } + for (i = 0; i < info->comp_planes; i++) + plane->sizeimage += + v4l2_format_plane_size(info, i, width, height); } else { for (i = 0; i < info->comp_planes; i++) { - unsigned int hdiv = (i == 0) ? 1 : info->hdiv; - unsigned int vdiv = (i == 0) ? 1 : info->vdiv; - unsigned int aligned_width; - unsigned int aligned_height; - - aligned_width = ALIGN(width, v4l2_format_block_width(info, i)); - aligned_height = ALIGN(height, v4l2_format_block_height(info, i)); - plane = &pixfmt->plane_fmt[i]; plane->bytesperline = - info->bpp[i] * DIV_ROUND_UP(aligned_width, hdiv); - plane->sizeimage = - plane->bytesperline * DIV_ROUND_UP(aligned_height, vdiv); + v4l2_format_plane_width(info, i, width); + plane->sizeimage = plane->bytesperline * + v4l2_format_plane_height(info, i, height); } } return 0; @@ -429,22 +438,12 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, pixfmt->width = width; pixfmt->height = height; pixfmt->pixelformat = pixelformat; - pixfmt->bytesperline = ALIGN(width, v4l2_format_block_width(info, 0)) * info->bpp[0]; + pixfmt->bytesperline = v4l2_format_plane_width(info, 0, width); pixfmt->sizeimage = 0; - for (i = 0; i < info->comp_planes; i++) { - unsigned int hdiv = (i == 0) ? 1 : info->hdiv; - unsigned int vdiv = (i == 0) ? 1 : info->vdiv; - unsigned int aligned_width; - unsigned int aligned_height; - - aligned_width = ALIGN(width, v4l2_format_block_width(info, i)); - aligned_height = ALIGN(height, v4l2_format_block_height(info, i)); - - pixfmt->sizeimage += info->bpp[i] * - DIV_ROUND_UP(aligned_width, hdiv) * - DIV_ROUND_UP(aligned_height, vdiv); - } + for (i = 0; i < info->comp_planes; i++) + pixfmt->sizeimage += + v4l2_format_plane_size(info, i, width, height); return 0; } EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt);