From patchwork Mon Jan 16 00:28:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 18123 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 9DE8AC3294 for ; Mon, 16 Jan 2023 00:28:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 51B6B625FE; Mon, 16 Jan 2023 01:28:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1673828898; bh=ljLKoyiQEj8/kbVr0ywJOLhgZoHqygtWF9far7AI1QQ=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=aSl9pMbpqQsDKopA2BxPHXGmwhjL80Jzm6HiOegr344/DqDP+uQmGqVyD99spqyjD StqMT5xfh++UUDQXQWMXq6VV3L5+vpY+rdzvor/UrD4ey+pfstLjHInwTjOdKDir5X Qg6pyOB0IEr2HNDU+sX0saHLFcUzO6PPzoC7anuVMND76MWRXzDIsNnpjHxiCC1tiC U65WaAZ0iQ/8Y+hG/kjwSW4iHRaKJbtNc0RumyvZxibFrM5mJxXk3ioSZAxoGvQLsh 4AKOr2UgPAIK/uEvxuXjxa6dCpSPIiSXhWgK/0Nnis6BVYySuWLXkCFdWwttwNLm83 WfcQbvkNpz0fA== 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 389FC625F0 for ; Mon, 16 Jan 2023 01:28:17 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="l9j4QxRc"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BCA3B9B4; Mon, 16 Jan 2023 01:28:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1673828897; bh=ljLKoyiQEj8/kbVr0ywJOLhgZoHqygtWF9far7AI1QQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l9j4QxRcbe2FU74lvYMdcxQvfPXRgXixddddYfZND/GU3zEZk/3nN62p24Bi8122+ G3VSSN6VeMsRhKDSDoYgqGoLcGt32MD9Zsu6gHgy+R0zoUvkgn/gFoFzEC9Z9XlbLG V0IE1mimlyRIeSlI+wCqrVUCFUmk6ZNPrL6+5/+4= To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Jan 2023 02:28:06 +0200 Message-Id: <20230116002808.16014-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.38.2 In-Reply-To: <20230116002808.16014-1-laurent.pinchart@ideasonboard.com> References: <20230116002808.16014-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v9 6/8] android: jpeg: Return an error code from generateThumbnail() 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The usual way to signal errors in libcamera is to return an error code. Change the Encoder::generateThumbnail() function to return an int instead of signaling errors by not resizing the thumbnail vector. This allows propagating error codes to the callers. Signed-off-by: Laurent Pinchart --- src/android/jpeg/encoder.h | 8 +-- src/android/jpeg/encoder_libjpeg.cpp | 70 +++++++++++++----------- src/android/jpeg/encoder_libjpeg.h | 8 +-- src/android/jpeg/post_processor_jpeg.cpp | 6 +- 4 files changed, 48 insertions(+), 44 deletions(-) diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h index 5f9ef890023a..d15f22e67830 100644 --- a/src/android/jpeg/encoder.h +++ b/src/android/jpeg/encoder.h @@ -22,8 +22,8 @@ public: libcamera::Span destination, libcamera::Span exifData, unsigned int quality) = 0; - virtual void generateThumbnail(const libcamera::FrameBuffer &source, - const libcamera::Size &targetSize, - unsigned int quality, - std::vector *thumbnail) = 0; + virtual int generateThumbnail(const libcamera::FrameBuffer &source, + const libcamera::Size &targetSize, + unsigned int quality, + std::vector *thumbnail) = 0; }; diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp index 9bbf1abbe09c..8f4df7899dfd 100644 --- a/src/android/jpeg/encoder_libjpeg.cpp +++ b/src/android/jpeg/encoder_libjpeg.cpp @@ -89,53 +89,57 @@ int EncoderLibJpeg::encode(const FrameBuffer &source, Span dest, return captureEncoder_.encode(frame.planes(), dest, exifData, quality); } -void EncoderLibJpeg::generateThumbnail(const libcamera::FrameBuffer &source, - const libcamera::Size &targetSize, - unsigned int quality, - std::vector *thumbnail) +int EncoderLibJpeg::generateThumbnail(const libcamera::FrameBuffer &source, + const libcamera::Size &targetSize, + unsigned int quality, + std::vector *thumbnail) { /* Stores the raw scaled-down thumbnail bytes. */ std::vector rawThumbnail; thumbnailer_.createThumbnail(source, targetSize, &rawThumbnail); + if (rawThumbnail.empty()) + return -EINVAL; StreamConfiguration thCfg; thCfg.size = targetSize; thCfg.pixelFormat = thumbnailer_.pixelFormat(); int ret = thumbnailEncoder_.configure(thCfg); + if (ret) + return ret; - if (!rawThumbnail.empty() && !ret) { - /* - * \todo Avoid value-initialization of all elements of the - * vector. - */ - thumbnail->resize(rawThumbnail.size()); + /* + * \todo Avoid value-initialization of all elements of the + * vector. + */ + thumbnail->resize(rawThumbnail.size()); - /* - * 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. - */ - std::vector> thumbnailPlanes; - const PixelFormatInfo &formatNV12 = - PixelFormatInfo::info(formats::NV12); - size_t yPlaneSize = formatNV12.planeSize(targetSize, 0); - size_t uvPlaneSize = formatNV12.planeSize(targetSize, 1); - thumbnailPlanes.push_back({ rawThumbnail.data(), yPlaneSize }); - thumbnailPlanes.push_back({ rawThumbnail.data() + yPlaneSize, - uvPlaneSize }); + /* + * 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. + */ + std::vector> thumbnailPlanes; + const PixelFormatInfo &formatNV12 = + PixelFormatInfo::info(formats::NV12); + size_t yPlaneSize = formatNV12.planeSize(targetSize, 0); + size_t uvPlaneSize = formatNV12.planeSize(targetSize, 1); + thumbnailPlanes.push_back({ rawThumbnail.data(), yPlaneSize }); + thumbnailPlanes.push_back({ rawThumbnail.data() + yPlaneSize, + uvPlaneSize }); - int jpegSize = thumbnailEncoder_.encode(thumbnailPlanes, *thumbnail, - {}, quality); - thumbnail->resize(jpegSize); + int jpegSize = thumbnailEncoder_.encode(thumbnailPlanes, *thumbnail, + {}, quality); + thumbnail->resize(jpegSize); - LOG(JPEG, Debug) - << "Thumbnail compress returned " - << jpegSize << " bytes"; - } + LOG(JPEG, Debug) + << "Thumbnail compress returned " + << jpegSize << " bytes"; + + return 0; } EncoderLibJpeg::Encoder::Encoder() diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h index a022a72e02bf..9cff4f1b42e3 100644 --- a/src/android/jpeg/encoder_libjpeg.h +++ b/src/android/jpeg/encoder_libjpeg.h @@ -28,10 +28,10 @@ public: libcamera::Span destination, libcamera::Span exifData, unsigned int quality) override; - void generateThumbnail(const libcamera::FrameBuffer &source, - const libcamera::Size &targetSize, - unsigned int quality, - std::vector *thumbnail) override; + int generateThumbnail(const libcamera::FrameBuffer &source, + const libcamera::Size &targetSize, + unsigned int quality, + std::vector *thumbnail) override; private: class Encoder diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index 69b18a2e5945..5df89383e1af 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -115,9 +115,9 @@ void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBu if (thumbnailSize != Size(0, 0)) { std::vector thumbnail; - encoder_->generateThumbnail(source, thumbnailSize, - quality, &thumbnail); - if (!thumbnail.empty()) + ret = encoder_->generateThumbnail(source, thumbnailSize, + quality, &thumbnail); + if (!ret) exif.setThumbnail(std::move(thumbnail), Exif::Compression::JPEG); }