From patchwork Mon Sep 6 22:56:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13678 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 43A5ABE175 for ; Mon, 6 Sep 2021 22:57:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EC1356917F; Tue, 7 Sep 2021 00:57:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cVrO9yZn"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DC5916916C for ; Tue, 7 Sep 2021 00:57:03 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6E19F891; Tue, 7 Sep 2021 00:57:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630969023; bh=zVgGXo4m+aHg7nB3jjUEoAJGed4MOav0IDCcFOskuzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cVrO9yZniPMh9O2zR8iE7xIKON8XRnb+YJQ6binm3q/AJj0C81vF+VoFMQ4NbmwtK cUwlm9lRsvXlnmsOorwOZnKFNOego106SJaXRD8z3usNGWthq2KrB1SvBSSTUzUr2P JwEtUxOQCyF7YxqpxkgqZGJvOxnU6pD7ef5dfwGM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Sep 2021 01:56:18 +0300 Message-Id: <20210906225636.14683-12-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210906225420.13275-1-laurent.pinchart@ideasonboard.com> References: <20210906225420.13275-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 12/30] libcamera: v4l2_videodevice: Take stride into account to compute offsets X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When creating FrameBuffer instances, the V4L2VideoDevice computes plane offsets using minimal stride for the format. This doesn't always produce a valid result when the device requires padding at the end of lines. Fix it by computing offsets using the stride reported by V4L2. Signed-off-by: Laurent Pinchart Reviewed-by: Jean-Michel Hautbois Reviewed-by: Hirokazu Honda Reviewed-by: Kieran Bingham --- src/libcamera/v4l2_videodevice.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 88535f5a07c7..c6c9263c49e9 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1354,11 +1354,21 @@ std::unique_ptr V4L2VideoDevice::createBuffer(unsigned int index) size_t offset = 0; for (size_t i = 0; i < planes.size(); ++i) { + /* + * The stride is reported by V4L2 for the first plane + * only. Compute the stride of the other planes by + * taking the horizontal subsampling factor into + * account, which is equal to the bytesPerGroup ratio of + * the planes. + */ + unsigned int stride = format_.planes[0].bpl + * formatInfo_->planes[i].bytesPerGroup + / formatInfo_->planes[0].bytesPerGroup; + planes[i].fd = fd; planes[i].offset = offset; - - /* \todo Take the V4L2 stride into account */ - planes[i].length = formatInfo_->planeSize(format_.size, i); + planes[i].length = formatInfo_->planeSize(format_.size.height, + i, stride); offset += planes[i].length; } }