From patchwork Wed Sep 8 09:49:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13767 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 6A73FBDB1D for ; Wed, 8 Sep 2021 09:50:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ED7D760250; Wed, 8 Sep 2021 11:50:06 +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="vUzPOoHu"; 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 8D4106024D for ; Wed, 8 Sep 2021 11:50:05 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.149]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 835E8993; Wed, 8 Sep 2021 11:50:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1631094605; bh=kK3M4LSliyIJmB4VszDM4Ghu31VvnQvxCLt2AV3Zf68=; h=From:To:Cc:Subject:Date:From; b=vUzPOoHugUqb0j87ln0euLLzi6tAupGKRgE+bhargKICHfkrgd3ir5zbWKC2R32Y/ R4mmah7flUBGtQcvadqNw4M2+9V+QHXyn/bPmyA7SMsR3R6U8cXd1fhTPr3GWb/AfJ ChlWJbM2IEskhb6G4wNawwFcKSwJNXc6RlCykqwU= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Sep 2021 15:19:49 +0530 Message-Id: <20210908094949.111140-1-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] android: jpeg: Split and pass the thumbnail planes to encoder 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" After multi-planar support was introduced for jpeg encoding as well, EncoderLibJpeg::encode() expects a vector of planes as the source of framebuffer to be encoded. Currently, we are passing a contiguous buffer which is treated as only one plane (instead of two, as thumbnail is NV12). Hence, split the thumbnail data into respective planes according to NV12. This fixes a crash in encoding of thumbnails. Fixes: 894ca69f6043("android: jpeg: Support multi-planar buffers") Signed-off-by: Umang Jain Reviewed-by: Hirokazu Honda Reviewed-by: Jacopo Mondi --- Changes in v2: - Fix basic split logic error. - Add Jacopo's suggestion as a \todo since it's a superior method to fix this. --- src/android/jpeg/post_processor_jpeg.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index 68d74842..1bf507a4 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -66,13 +66,23 @@ void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source, int ret = thumbnailEncoder_.configure(thCfg); if (!rawThumbnail.empty() && !ret) { + thumbnail->resize(rawThumbnail.size()); + /* - * \todo Avoid value-initialization of all elements of the - * vector. + * Split planes manually as the encoder expects a vector of + * planes. + * + * \todo Pass a vector of planes directly to + * Thumbnailer::createThumbnailer above and remove the manual + * planes split from here. */ - thumbnail->resize(rawThumbnail.size()); + std::vector> thumbnailPlanes; + unsigned int thumbnailSize = targetSize.height * targetSize.width; + thumbnailPlanes.push_back({ rawThumbnail.data(), thumbnailSize }); + thumbnailPlanes.push_back({ rawThumbnail.data() + thumbnailSize, + thumbnailSize / 2 }); - int jpeg_size = thumbnailEncoder_.encode({ rawThumbnail }, + int jpeg_size = thumbnailEncoder_.encode(thumbnailPlanes, *thumbnail, {}, quality); thumbnail->resize(jpeg_size);