From patchwork Tue Oct 27 21:24:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 10270 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 5EF58C3B5C for ; Tue, 27 Oct 2020 21:25:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2EFC562230; Tue, 27 Oct 2020 22:25:01 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="g4zx2o5Q"; dkim-atps=neutral Received: from mail.uajain.com (static.126.159.217.95.clients.your-server.de [95.217.159.126]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EE7AF6205F for ; Tue, 27 Oct 2020 22:24:59 +0100 (CET) From: Umang Jain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=uajain.com; s=mail; t=1603833899; bh=GbH+9TPuv/EdjiwNPJXY2dWcOMqZNJcKqFJJt+3Rd3U=; h=From:To:Cc:Subject:In-Reply-To:References; b=g4zx2o5QBq2xT9CWdhiqxIdjZ3eA6KqDOEAjC9Y2rOLugjqjkyXytqEjwvAcsjtkZ BJNpTk2qicmdt9a0EpY5RpcKGW8ukkMImQnYBuN4sR6hZ57fKhrOhdxpmptB55YUFl RXG5UHsyjAMZ54HuhctqTFaNnTern2iEYUtaARMMuJB7zggFSftKB/t66e7tttbkJD tF3eJ7AqRdatvr73sgBv9/VMH9zTlmSMbXfyNFcvWxd8gZGHpD0jHOfe0tA3Ve2c7z j+y2197pKb0EsQGCeC9ASccazvWozBcnJH/ogAZKRHjo5e0m2vBq+FtnB7Jq1iUXDt kxutukq4Vtg1w== To: libcamera-devel@lists.libcamera.org Date: Wed, 28 Oct 2020 02:54:45 +0530 Message-Id: <20201027212447.131431-2-email@uajain.com> In-Reply-To: <20201027212447.131431-1-email@uajain.com> References: <20201027212447.131431-1-email@uajain.com> Mime-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/3] android: jpeg: encoder_libjpeg: Allow encoding raw frame bytes 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" Allow encoding frames which are directly handed over to the encoder via a span or vector i.e. a raw frame bytes. Introduce an overloaded EncoderLibJpeg::encode() with libcamera::Span source parameter to achieve this functionality. This makes the libjpeg-encoder a bit flexible for use case such as compressing a thumbnail generated for Exif. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/android/jpeg/encoder_libjpeg.cpp | 18 ++++++++++++------ src/android/jpeg/encoder_libjpeg.h | 7 +++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp index cfa5332..aed919b 100644 --- a/src/android/jpeg/encoder_libjpeg.cpp +++ b/src/android/jpeg/encoder_libjpeg.cpp @@ -104,9 +104,9 @@ int EncoderLibJpeg::configure(const StreamConfiguration &cfg) return 0; } -void EncoderLibJpeg::compressRGB(const MappedBuffer *frame) +void EncoderLibJpeg::compressRGB(Span frame) { - unsigned char *src = static_cast(frame->maps()[0].data()); + unsigned char *src = const_cast(frame.data()); /* \todo Stride information should come from buffer configuration. */ unsigned int stride = pixelFormatInfo_->stride(compress_.image_width, 0); @@ -122,7 +122,7 @@ void EncoderLibJpeg::compressRGB(const MappedBuffer *frame) * Compress the incoming buffer from a supported NV format. * This naively unpacks the semi-planar NV12 to a YUV888 format for libjpeg. */ -void EncoderLibJpeg::compressNV(const MappedBuffer *frame) +void EncoderLibJpeg::compressNV(Span frame) { uint8_t tmprowbuf[compress_.image_width * 3]; @@ -144,7 +144,7 @@ void EncoderLibJpeg::compressNV(const MappedBuffer *frame) unsigned int cb_pos = nvSwap_ ? 1 : 0; unsigned int cr_pos = nvSwap_ ? 0 : 1; - const unsigned char *src = static_cast(frame->maps()[0].data()); + const unsigned char *src = frame.data(); const unsigned char *src_c = src + y_stride * compress_.image_height; JSAMPROW row_pointer[1]; @@ -189,6 +189,12 @@ int EncoderLibJpeg::encode(const FrameBuffer &source, Span dest, return frame.error(); } + return encode(frame.maps()[0], dest, exifData); +} + +int EncoderLibJpeg::encode(Span src, Span dest, + Span exifData) +{ unsigned char *destination = dest.data(); unsigned long size = dest.size(); @@ -214,9 +220,9 @@ int EncoderLibJpeg::encode(const FrameBuffer &source, Span dest, << "x" << compress_.image_height; if (nv_) - compressNV(&frame); + compressNV(src); else - compressRGB(&frame); + compressRGB(src); jpeg_finish_compress(&compress_); diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h index 40505dd..070f56f 100644 --- a/src/android/jpeg/encoder_libjpeg.h +++ b/src/android/jpeg/encoder_libjpeg.h @@ -24,10 +24,13 @@ public: int encode(const libcamera::FrameBuffer &source, libcamera::Span destination, libcamera::Span exifData) override; + int encode(libcamera::Span source, + libcamera::Span destination, + libcamera::Span exifData); private: - void compressRGB(const libcamera::MappedBuffer *frame); - void compressNV(const libcamera::MappedBuffer *frame); + void compressRGB(libcamera::Span frame); + void compressNV(libcamera::Span frame); struct jpeg_compress_struct compress_; struct jpeg_error_mgr jerr_;