Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1673851rdf; Sun, 5 Nov 2023 09:05:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZ+449rBYXkAAGdbrumCMzUuP2gmL920T1fdV7DEm+sc2E3DTz2r/FQKAEioS50yzNSlj9 X-Received: by 2002:a05:6830:164d:b0:6bd:9e1c:93a6 with SMTP id h13-20020a056830164d00b006bd9e1c93a6mr4098289otr.0.1699203949153; Sun, 05 Nov 2023 09:05:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699203949; cv=none; d=google.com; s=arc-20160816; b=VWWEduHZKmSV82OuEMAY5kzOMf9w56S+YmDyNeaKizuQLldk4RkKc9LeXsDkuECX4Y BqZmVHFDp2EfnE15JWeTFrhbAaKffNaHwi/TWJ6JkkBh8MjYYS5n2IYXzGyAqXfq4tMY ypnU8fdi5MI1AOhz8bnPa2EEGSDq5YbfGpVXNcu7jK0LLvV4cpj/yTf2DmOedVbgqHl/ SJ3OkV2lXflG13oNf60hNTUpgnNHpusNvt0GAJQ+eJdl+RbteNfJ9VpR9wvIgH4iYqKY peUtXs2JzzjfrLvHNIm4MPDrJQij1cmKhmzmoyjPEWIMtNOTGzvAoyKXFM0z+MKs/DYB zP1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7TvJ7hJu85Rv+IB9dyvciIwrrP9mf2NII64BLyqL6pI=; fh=YE9Zoov9aZcO6Pol3LAYxeN5UVTuEfMZTPwdHENjbrQ=; b=uBu978Wlghobgi9nlvvncsUEtbQW7ka4lcfFYLIdsh2Gqd0PUL0ec1w0T8tS/0QaGv 3PmFqMAXCYrHK0u6+WlGRT8KvEAsN7u4wgFDeiEyQLcrVdOd9dDaZ/F6O/5HJmt5mAKM 3ZORlAbHtFeL9sppPqUaQsvQgt8F8p8fZ3PEHY1Md5JS210HmNvMFLuiP+RH99W25RZb 2oJLdqnRKfdAgEmN3TX6eQEdCmAQQkSZYopecQbaiLhuF3whFnh0az7t1Lo5NB/b14Oj YB2MEVsM/5QS8rmA2GDXYkMWlQDCVJYRFMS8WrYTW7MpC9Ji/PKl0OnR1xz1njkBhEGp XAkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kwiboo.se header.s=fe-e1b5cab7be header.b=c6ljQ0zc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kwiboo.se Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u19-20020a056830119300b006d3273553e1si2514233otq.30.2023.11.05.09.05.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 09:05:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kwiboo.se header.s=fe-e1b5cab7be header.b=c6ljQ0zc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kwiboo.se Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0AA1D8062916; Sun, 5 Nov 2023 09:05:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229524AbjKERFn (ORCPT + 99 others); Sun, 5 Nov 2023 12:05:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjKERFn (ORCPT ); Sun, 5 Nov 2023 12:05:43 -0500 Received: from smtp.forwardemail.net (smtp.forwardemail.net [149.28.215.223]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 174C497; Sun, 5 Nov 2023 09:05:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-ID: Date: Subject: Cc: To: From; q=dns/txt; s=fe-e1b5cab7be; t=1699203938; bh=7TvJ7hJu85Rv+IB9dyvciIwrrP9mf2NII64BLyqL6pI=; b=c6ljQ0zc5Ummv/9BSWkxu9BtNA/+DCE2lXoUKtp9N4iUnWtyAwwNjkL2Bir0OIk0oyAfDbVaO DydCMQZT7Xw9thbnRaxqGjl9JxlsfsM1MFfeiApOYBFCYpWvEFdZ4LCAo4KuhyYKaAjXPajcxa1 AsKteI80bM0J+jDIkZ7JW3WhVsayK8EFvvkRzG0/p/ioaVcDJH00SNkaTSgGVra9Qlb7VK43LKJ Z2R+RvTtBArmGOPuOJqasDeCAWCp2U+FQW2KsF0hP4s1QWjBTWvMK5kOCuJ/mJ8TiS1Fj0VP/DY 7T4m6ZNaWP0ja3sMROTPADMdc+dBmfooxn74yBsZw0xQ== From: Jonas Karlman To: Ezequiel Garcia , Mauro Carvalho Chehab , Hans Verkuil Cc: Alex Bee , Nicolas Dufresne , Benjamin Gaignard , Sebastian Fricke , Christopher Obbard , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Jonas Karlman Subject: [PATCH v4 01/11] media: v4l2-common: Add helpers to calculate bytesperline and sizeimage Date: Sun, 5 Nov 2023 16:55:00 +0000 Message-ID: <20231105165521.3592037-2-jonas@kwiboo.se> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231105165521.3592037-1-jonas@kwiboo.se> References: <20231105165521.3592037-1-jonas@kwiboo.se> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Report-Abuse-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Complaints-To: abuse@forwardemail.net X-ForwardEmail-Version: 0.4.40 X-ForwardEmail-Sender: rfc822; jonas@kwiboo.se, smtp.forwardemail.net, 149.28.215.223 X-ForwardEmail-ID: 6547c90342ad2f8d152468e7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 05 Nov 2023 09:05:48 -0800 (PST) Add helper functions to calculate plane bytesperline and sizeimage, these new helpers consider bpp div, block width and height when calculating plane bytesperline and sizeimage. Signed-off-by: Jonas Karlman --- v4: - No change v3: - Consider bpp_div in calculation drivers/media/v4l2-core/v4l2-common.c | 78 +++++++++++++-------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c index 3a4b15a98e02..834b426da8b1 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -350,6 +350,34 @@ 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 aligned_width = + ALIGN(width, v4l2_format_block_width(info, plane)); + + return DIV_ROUND_UP(aligned_width, hdiv) * + info->bpp[plane] / info->bpp_div[plane]; +} + +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 aligned_height = + ALIGN(height, v4l2_format_block_height(info, plane)); + + return DIV_ROUND_UP(aligned_height, 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) { @@ -385,37 +413,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] / info->bpp_div[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) / info->bpp_div[i]; - } + 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) / info->bpp_div[i]; - 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; @@ -439,22 +449,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] / info->bpp_div[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) / info->bpp_div[i]; - } + 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); -- 2.42.0