From nobody Sat Nov 30 16:31:26 2024 Received: from smtp.forwardemail.net (smtp.forwardemail.net [149.28.215.223]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38C04189907 for ; Mon, 9 Sep 2024 19:25:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=149.28.215.223 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725909947; cv=none; b=l0iz2chQA0IpI0/v7CxYtAgZHACxAbJfaMLaFzu6nFEBsG0N8VgOmGM4hyTsSHxBmJymw66LHnOR+ien8SCaGjQI2HItU7jCuS4tDSPMuFOd2iSPJujoYdWioFXxqkH4q9O3Bln5tr0heN7k31rLDyogonKj0nEJxb2/1rUMjM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725909947; c=relaxed/simple; bh=+f1GZPuZtWrWzSnWxjeLNHljlNwUwFrqxKjgtIzVzq4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O5L5zEs33xOzkoSxbjd0WqdoNhhzulyAxpT7C2wx6bWOlQJKapzAFgUQqZa9QfIzvbEArW5UsIi4qebdpowqWUexTWVKVC7Aw0FQ0uvTjqC+o24JMkVs6whqjiZJoEnAbnXvWBWhxsafM6fE9pQJBpR+XfAcs7uz1O+tr7U1p34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kwiboo.se; spf=pass smtp.mailfrom=fe-bounces.kwiboo.se; dkim=pass (2048-bit key) header.d=kwiboo.se header.i=@kwiboo.se header.b=DDV64Qcy; arc=none smtp.client-ip=149.28.215.223 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fe-bounces.kwiboo.se Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kwiboo.se header.i=@kwiboo.se header.b="DDV64Qcy" 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=1725909938; bh=M3iLoJF/xoVMuEP83VTRXZkMp46lvnfPde0CsnmqYXM=; b=DDV64QcyvwMMaLuTxCkFznVfXohGncrS9J0MzDLIpTF4aMzomBzs4LxGx1Bq+TB9FsRuMEpAU E/hhqkMmd+tnv73SgjGVz7O4gRx6y/Jo1tQxO1KNAN0MmX1PM4TkHSmGE5QL4EuBKdhUvRmUZx8 zAsgj95lMYiXU0TCqViyvMqZVTV/f/jc3mDkD7XNd82G65pEP779ET/7+JHiSNx9nyEnCRcZhFm Ge7Agjua0gYmjOrziBs8K/LDATscYZX3hFKsMgWR6izLEONstI9qbgCPEEgjIhYrXjvbVnVgnWB Uvj+GrkITtr4nrzIX4tB/lsJZR8X/gYPc3C7GaUf6BCA== From: Jonas Karlman To: Sebastian Fricke , Ezequiel Garcia , Mauro Carvalho Chehab Cc: Alex Bee , Nicolas Dufresne , Benjamin Gaignard , Detlev Casanova , Dan Carpenter , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Jonas Karlman , Christopher Obbard Subject: [PATCH v6 01/11] media: v4l2-common: Add helpers to calculate bytesperline and sizeimage Date: Mon, 9 Sep 2024 19:24:59 +0000 Message-ID: <20240909192522.1076704-2-jonas@kwiboo.se> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240909192522.1076704-1-jonas@kwiboo.se> References: <20240909192522.1076704-1-jonas@kwiboo.se> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: 66df4bafc680cb8b7d2dc118 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Nicolas Dufresne Tested-by: Christopher Obbard Reviewed-by: Nicolas Dufresne --- v6: - No change v5: - Collect t-b tags 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-cor= e/v4l2-common.c index 0a2f4f0d0a07..8ad04d48a023 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -357,6 +357,34 @@ static inline unsigned int v4l2_format_block_height(co= nst struct v4l2_format_inf return info->block_h[plane]; } =20 +static inline unsigned int v4l2_format_plane_width(const struct v4l2_forma= t_info *info, int plane, + unsigned int width) +{ + unsigned int hdiv =3D plane ? info->hdiv : 1; + unsigned int aligned_width =3D + 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_form= at_info *info, int plane, + unsigned int height) +{ + unsigned int vdiv =3D plane ? info->vdiv : 1; + unsigned int aligned_height =3D + 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) { @@ -392,37 +420,19 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane= *pixfmt, =20 if (info->mem_planes =3D=3D 1) { plane =3D &pixfmt->plane_fmt[0]; - plane->bytesperline =3D ALIGN(width, v4l2_format_block_width(info, 0)) *= info->bpp[0] / info->bpp_div[0]; + plane->bytesperline =3D v4l2_format_plane_width(info, 0, width); plane->sizeimage =3D 0; =20 - for (i =3D 0; i < info->comp_planes; i++) { - unsigned int hdiv =3D (i =3D=3D 0) ? 1 : info->hdiv; - unsigned int vdiv =3D (i =3D=3D 0) ? 1 : info->vdiv; - unsigned int aligned_width; - unsigned int aligned_height; - - aligned_width =3D ALIGN(width, v4l2_format_block_width(info, i)); - aligned_height =3D ALIGN(height, v4l2_format_block_height(info, i)); - - plane->sizeimage +=3D info->bpp[i] * - DIV_ROUND_UP(aligned_width, hdiv) * - DIV_ROUND_UP(aligned_height, vdiv) / info->bpp_div[i]; - } + for (i =3D 0; i < info->comp_planes; i++) + plane->sizeimage +=3D + v4l2_format_plane_size(info, i, width, height); } else { for (i =3D 0; i < info->comp_planes; i++) { - unsigned int hdiv =3D (i =3D=3D 0) ? 1 : info->hdiv; - unsigned int vdiv =3D (i =3D=3D 0) ? 1 : info->vdiv; - unsigned int aligned_width; - unsigned int aligned_height; - - aligned_width =3D ALIGN(width, v4l2_format_block_width(info, i)); - aligned_height =3D ALIGN(height, v4l2_format_block_height(info, i)); - plane =3D &pixfmt->plane_fmt[i]; plane->bytesperline =3D - info->bpp[i] * DIV_ROUND_UP(aligned_width, hdiv) / info->bpp_div[i]; - plane->sizeimage =3D - plane->bytesperline * DIV_ROUND_UP(aligned_height, vdiv); + v4l2_format_plane_width(info, i, width); + plane->sizeimage =3D plane->bytesperline * + v4l2_format_plane_height(info, i, height); } } return 0; @@ -446,22 +456,12 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, = u32 pixelformat, pixfmt->width =3D width; pixfmt->height =3D height; pixfmt->pixelformat =3D pixelformat; - pixfmt->bytesperline =3D ALIGN(width, v4l2_format_block_width(info, 0)) *= info->bpp[0] / info->bpp_div[0]; + pixfmt->bytesperline =3D v4l2_format_plane_width(info, 0, width); pixfmt->sizeimage =3D 0; =20 - for (i =3D 0; i < info->comp_planes; i++) { - unsigned int hdiv =3D (i =3D=3D 0) ? 1 : info->hdiv; - unsigned int vdiv =3D (i =3D=3D 0) ? 1 : info->vdiv; - unsigned int aligned_width; - unsigned int aligned_height; - - aligned_width =3D ALIGN(width, v4l2_format_block_width(info, i)); - aligned_height =3D ALIGN(height, v4l2_format_block_height(info, i)); - - pixfmt->sizeimage +=3D info->bpp[i] * - DIV_ROUND_UP(aligned_width, hdiv) * - DIV_ROUND_UP(aligned_height, vdiv) / info->bpp_div[i]; - } + for (i =3D 0; i < info->comp_planes; i++) + pixfmt->sizeimage +=3D + v4l2_format_plane_size(info, i, width, height); return 0; } EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt); --=20 2.46.0