From patchwork Tue Aug 31 06:34:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13575 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 C2A4BC3242 for ; Tue, 31 Aug 2021 06:35:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6ECE86916A; Tue, 31 Aug 2021 08:35:15 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="W+NKqbEv"; dkim-atps=neutral Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8EDD26916D for ; Tue, 31 Aug 2021 08:35:12 +0200 (CEST) Received: by mail-pl1-x62d.google.com with SMTP id u1so6210383plq.5 for ; Mon, 30 Aug 2021 23:35:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qBdnyVWP1J27KA/6C2MYOFwAsmP2Kaj2I8YDdtscb3c=; b=W+NKqbEvZ+I6M8anax7188qTo4pQNE6VBlbx0mJ1BNgqJ/rvrNI5S1jmaW0o3BB/6x NRNHAC4PwUFJ1AEQRNhj7RMjwu8DscQum04zYml1DE+PkVj3ucIG7EyVJlalgmRq42gV nArF0W6adiCKZu3QyAo4sdzaM+CM6Oo+53wh4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qBdnyVWP1J27KA/6C2MYOFwAsmP2Kaj2I8YDdtscb3c=; b=bjJh+eXiUAyXbOHkL/IaiYWCo/djpo59kaYv8t7fzSNqTGnpXbT1QaJlv+0b1H3M4Y ZzF8Ocxc7mWKpfIvTBMSoT5AkGBhKKdPfjMheHiP15bVeQg0knuAtGNvELWuJyrMreYv TVsJXgqyBX0jodJ4K0Im+ARtMl8s6ZYLmSn4HuTjvbApqP3DRe7jmeR3jJNsGPJDKtAT btWWaoqAJwqe0fJ9vGgMFvLNG1sOEQqbNBEh2b7tJcrKtX/4g+VzoEmnnaRvf/jJadO9 tYJ1C29vQoMkLPYFwnGBkFkmdyzpsX1UpyznJrnGyOb2WA2C/n4lT4jBC1EmByFfPJLz mxyQ== X-Gm-Message-State: AOAM530cl5NaShkhxXFV2VHv37vkkgNZVlYx2xNg5O8VpzPiLEkJDhfK /1Q6WziRu61PqhcJXHWEnzZlVfzhPfjedg== X-Google-Smtp-Source: ABdhPJz2Etq/VdCItvytwySZeYNU9DdNLQt38aSyU8uN7vAr1okT3k8u9isj29JKGUnQ+i/wSEGJnA== X-Received: by 2002:a17:90b:4c8b:: with SMTP id my11mr3416812pjb.220.1630391710752; Mon, 30 Aug 2021 23:35:10 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3c62:aba4:18ea:5441]) by smtp.gmail.com with ESMTPSA id d17sm16304027pfn.110.2021.08.30.23.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Aug 2021 23:35:10 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 31 Aug 2021 15:34:38 +0900 Message-Id: <20210831063438.785767-6-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog In-Reply-To: <20210831063438.785767-1-hiroh@chromium.org> References: <20210831063438.785767-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/5] android: encoder_libjpeg: Use MappedBuffer for the source frame 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" EncoderLibJpeg handles the source frame with Span. Since it is plane, MappedBuffer should be more appropriate interface for it. So this changes its type to MappedBuffer. Signed-off-by: Hirokazu Honda --- src/android/jpeg/encoder_libjpeg.cpp | 28 ++++++++++++++---------- src/android/jpeg/encoder_libjpeg.h | 7 +++--- src/android/jpeg/post_processor_jpeg.cpp | 6 ++--- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp index b8b01e20..d165fd6a 100644 --- a/src/android/jpeg/encoder_libjpeg.cpp +++ b/src/android/jpeg/encoder_libjpeg.cpp @@ -103,9 +103,10 @@ int EncoderLibJpeg::configure(const StreamConfiguration &cfg) return 0; } -void EncoderLibJpeg::compressRGB(Span frame) +void EncoderLibJpeg::compressRGB(const MappedBuffer &frame) { - unsigned char *src = const_cast(frame.data()); + ASSERT(frame.planes().size() == 1); + unsigned char *src = const_cast(frame.planes()[0].data()); /* \todo Stride information should come from buffer configuration. */ unsigned int stride = pixelFormatInfo_->stride(compress_.image_width, 0); @@ -121,7 +122,7 @@ void EncoderLibJpeg::compressRGB(Span 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(Span frame) +void EncoderLibJpeg::compressNV(const MappedBuffer &frame) { uint8_t tmprowbuf[compress_.image_width * 3]; @@ -143,8 +144,9 @@ void EncoderLibJpeg::compressNV(Span frame) unsigned int cb_pos = nvSwap_ ? 1 : 0; unsigned int cr_pos = nvSwap_ ? 0 : 1; - const unsigned char *src = frame.data(); - const unsigned char *src_c = src + y_stride * compress_.image_height; + ASSERT(frame.planes().size() == 2); + const unsigned char *src = frame.planes()[0].data(); + const unsigned char *src_c = frame.planes()[1].data(); JSAMPROW row_pointer[1]; row_pointer[0] = &tmprowbuf[0]; @@ -152,7 +154,7 @@ void EncoderLibJpeg::compressNV(Span frame) for (unsigned int y = 0; y < compress_.image_height; y++) { unsigned char *dst = &tmprowbuf[0]; - const unsigned char *src_y = src + y * compress_.image_width; + const unsigned char *src_y = src + y * y_stride; const unsigned char *src_cb = src_c + (y / vertSubSample) * c_stride + cb_pos; const unsigned char *src_cr = src_c + (y / vertSubSample) * c_stride + cr_pos; @@ -178,8 +180,10 @@ void EncoderLibJpeg::compressNV(Span frame) } } -int EncoderLibJpeg::encode(const FrameBuffer &source, Span dest, - Span exifData, unsigned int quality) +int EncoderLibJpeg::encode(const libcamera::FrameBuffer &source, + libcamera::Span destination, + libcamera::Span exifData, + unsigned int quality) { MappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read); if (!frame.isValid()) { @@ -188,10 +192,10 @@ int EncoderLibJpeg::encode(const FrameBuffer &source, Span dest, return frame.error(); } - return encode(frame.planes()[0], dest, exifData, quality); + return encode(frame, destination, exifData, quality); } -int EncoderLibJpeg::encode(Span src, Span dest, +int EncoderLibJpeg::encode(const MappedBuffer &source, Span dest, Span exifData, unsigned int quality) { unsigned char *destination = dest.data(); @@ -221,9 +225,9 @@ int EncoderLibJpeg::encode(Span src, Span dest, << "x" << compress_.image_height; if (nv_) - compressNV(src); + compressNV(source); else - compressRGB(src); + compressRGB(source); jpeg_finish_compress(&compress_); diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h index 61fbd1a6..13a47b72 100644 --- a/src/android/jpeg/encoder_libjpeg.h +++ b/src/android/jpeg/encoder_libjpeg.h @@ -10,6 +10,7 @@ #include "encoder.h" #include "libcamera/internal/formats.h" +#include "libcamera/internal/mapped_framebuffer.h" #include @@ -24,14 +25,14 @@ public: libcamera::Span destination, libcamera::Span exifData, unsigned int quality) override; - int encode(libcamera::Span source, + int encode(const libcamera::MappedBuffer &source, libcamera::Span destination, libcamera::Span exifData, unsigned int quality); private: - void compressRGB(libcamera::Span frame); - void compressNV(libcamera::Span frame); + void compressRGB(const libcamera::MappedBuffer &frame); + void compressNV(const libcamera::MappedBuffer &frame); struct jpeg_compress_struct compress_; struct jpeg_error_mgr jerr_; diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index 6eefce0f..a4e56b88 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -75,8 +75,7 @@ void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source, bufferSize += plane.size(); thumbnail->resize(bufferSize); - libcamera::Span rawThumbnailData(rawThumbnail->planes()[0].data(), bufferSize); - int jpeg_size = thumbnailEncoder_.encode(rawThumbnailData, + int jpeg_size = thumbnailEncoder_.encode(*rawThumbnail, *thumbnail, {}, quality); thumbnail->resize(jpeg_size); @@ -181,7 +180,8 @@ int PostProcessorJpeg::process(const FrameBuffer &source, const uint8_t quality = ret ? *entry.data.u8 : 95; resultMetadata->addEntry(ANDROID_JPEG_QUALITY, quality); - int jpeg_size = encoder_->encode(source, destination->plane(0), + int jpeg_size = encoder_->encode(source, + destination->plane(0), exif.data(), quality); if (jpeg_size < 0) { LOG(JPEG, Error) << "Failed to encode stream image";