{"id":13575,"url":"https://patchwork.libcamera.org/api/1.1/patches/13575/?format=json","web_url":"https://patchwork.libcamera.org/patch/13575/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210831063438.785767-6-hiroh@chromium.org>","date":"2021-08-31T06:34:38","name":"[libcamera-devel,5/5] android: encoder_libjpeg: Use MappedBuffer for the source frame","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"6e431bab1669a67898529b8c2456b75ee295319b","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/1.1/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13575/mbox/","series":[{"id":2423,"url":"https://patchwork.libcamera.org/api/1.1/series/2423/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2423","date":"2021-08-31T06:34:33","name":"Improve/Clean up post processors code in android","version":1,"mbox":"https://patchwork.libcamera.org/series/2423/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13575/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13575/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C2A4BC3242\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 31 Aug 2021 06:35:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6ECE86916A;\n\tTue, 31 Aug 2021 08:35:15 +0200 (CEST)","from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com\n\t[IPv6:2607:f8b0:4864:20::62d])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8EDD26916D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 31 Aug 2021 08:35:12 +0200 (CEST)","by mail-pl1-x62d.google.com with SMTP id u1so6210383plq.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 30 Aug 2021 23:35:12 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:3c62:aba4:18ea:5441])\n\tby smtp.gmail.com with ESMTPSA id\n\td17sm16304027pfn.110.2021.08.30.23.35.09\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 30 Aug 2021 23:35:10 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"W+NKqbEv\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=qBdnyVWP1J27KA/6C2MYOFwAsmP2Kaj2I8YDdtscb3c=;\n\tb=W+NKqbEvZ+I6M8anax7188qTo4pQNE6VBlbx0mJ1BNgqJ/rvrNI5S1jmaW0o3BB/6x\n\tNRNHAC4PwUFJ1AEQRNhj7RMjwu8DscQum04zYml1DE+PkVj3ucIG7EyVJlalgmRq42gV\n\tnArF0W6adiCKZu3QyAo4sdzaM+CM6Oo+53wh4=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=qBdnyVWP1J27KA/6C2MYOFwAsmP2Kaj2I8YDdtscb3c=;\n\tb=bjJh+eXiUAyXbOHkL/IaiYWCo/djpo59kaYv8t7fzSNqTGnpXbT1QaJlv+0b1H3M4Y\n\tZzF8Ocxc7mWKpfIvTBMSoT5AkGBhKKdPfjMheHiP15bVeQg0knuAtGNvELWuJyrMreYv\n\tTVsJXgqyBX0jodJ4K0Im+ARtMl8s6ZYLmSn4HuTjvbApqP3DRe7jmeR3jJNsGPJDKtAT\n\tbtWWaoqAJwqe0fJ9vGgMFvLNG1sOEQqbNBEh2b7tJcrKtX/4g+VzoEmnnaRvf/jJadO9\n\ttYJ1C29vQoMkLPYFwnGBkFkmdyzpsX1UpyznJrnGyOb2WA2C/n4lT4jBC1EmByFfPJLz\n\tmxyQ==","X-Gm-Message-State":"AOAM530cl5NaShkhxXFV2VHv37vkkgNZVlYx2xNg5O8VpzPiLEkJDhfK\n\t/1Q6WziRu61PqhcJXHWEnzZlVfzhPfjedg==","X-Google-Smtp-Source":"ABdhPJz2Etq/VdCItvytwySZeYNU9DdNLQt38aSyU8uN7vAr1okT3k8u9isj29JKGUnQ+i/wSEGJnA==","X-Received":"by 2002:a17:90b:4c8b:: with SMTP id\n\tmy11mr3416812pjb.220.1630391710752; \n\tMon, 30 Aug 2021 23:35:10 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 5/5] android: encoder_libjpeg: Use\n\tMappedBuffer for the source frame","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"EncoderLibJpeg handles the source frame with Span<const uint8_t>.\nSince it is plane, MappedBuffer should be more appropriate interface\nfor it. So this changes its type to MappedBuffer.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/android/jpeg/encoder_libjpeg.cpp     | 28 ++++++++++++++----------\n src/android/jpeg/encoder_libjpeg.h       |  7 +++---\n src/android/jpeg/post_processor_jpeg.cpp |  6 ++---\n 3 files changed, 23 insertions(+), 18 deletions(-)","diff":"diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp\nindex b8b01e20..d165fd6a 100644\n--- a/src/android/jpeg/encoder_libjpeg.cpp\n+++ b/src/android/jpeg/encoder_libjpeg.cpp\n@@ -103,9 +103,10 @@ int EncoderLibJpeg::configure(const StreamConfiguration &cfg)\n \treturn 0;\n }\n \n-void EncoderLibJpeg::compressRGB(Span<const uint8_t> frame)\n+void EncoderLibJpeg::compressRGB(const MappedBuffer &frame)\n {\n-\tunsigned char *src = const_cast<unsigned char *>(frame.data());\n+\tASSERT(frame.planes().size() == 1);\n+\tunsigned char *src = const_cast<unsigned char *>(frame.planes()[0].data());\n \t/* \\todo Stride information should come from buffer configuration. */\n \tunsigned int stride = pixelFormatInfo_->stride(compress_.image_width, 0);\n \n@@ -121,7 +122,7 @@ void EncoderLibJpeg::compressRGB(Span<const uint8_t> frame)\n  * Compress the incoming buffer from a supported NV format.\n  * This naively unpacks the semi-planar NV12 to a YUV888 format for libjpeg.\n  */\n-void EncoderLibJpeg::compressNV(Span<const uint8_t> frame)\n+void EncoderLibJpeg::compressNV(const MappedBuffer &frame)\n {\n \tuint8_t tmprowbuf[compress_.image_width * 3];\n \n@@ -143,8 +144,9 @@ void EncoderLibJpeg::compressNV(Span<const uint8_t> frame)\n \tunsigned int cb_pos = nvSwap_ ? 1 : 0;\n \tunsigned int cr_pos = nvSwap_ ? 0 : 1;\n \n-\tconst unsigned char *src = frame.data();\n-\tconst unsigned char *src_c = src + y_stride * compress_.image_height;\n+\tASSERT(frame.planes().size() == 2);\n+\tconst unsigned char *src = frame.planes()[0].data();\n+\tconst unsigned char *src_c = frame.planes()[1].data();\n \n \tJSAMPROW row_pointer[1];\n \trow_pointer[0] = &tmprowbuf[0];\n@@ -152,7 +154,7 @@ void EncoderLibJpeg::compressNV(Span<const uint8_t> frame)\n \tfor (unsigned int y = 0; y < compress_.image_height; y++) {\n \t\tunsigned char *dst = &tmprowbuf[0];\n \n-\t\tconst unsigned char *src_y = src + y * compress_.image_width;\n+\t\tconst unsigned char *src_y = src + y * y_stride;\n \t\tconst unsigned char *src_cb = src_c + (y / vertSubSample) * c_stride + cb_pos;\n \t\tconst unsigned char *src_cr = src_c + (y / vertSubSample) * c_stride + cr_pos;\n \n@@ -178,8 +180,10 @@ void EncoderLibJpeg::compressNV(Span<const uint8_t> frame)\n \t}\n }\n \n-int EncoderLibJpeg::encode(const FrameBuffer &source, Span<uint8_t> dest,\n-\t\t\t   Span<const uint8_t> exifData, unsigned int quality)\n+int EncoderLibJpeg::encode(const libcamera::FrameBuffer &source,\n+\t\t\t   libcamera::Span<uint8_t> destination,\n+\t\t\t   libcamera::Span<const uint8_t> exifData,\n+\t\t\t   unsigned int quality)\n {\n \tMappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read);\n \tif (!frame.isValid()) {\n@@ -188,10 +192,10 @@ int EncoderLibJpeg::encode(const FrameBuffer &source, Span<uint8_t> dest,\n \t\treturn frame.error();\n \t}\n \n-\treturn encode(frame.planes()[0], dest, exifData, quality);\n+\treturn encode(frame, destination, exifData, quality);\n }\n \n-int EncoderLibJpeg::encode(Span<const uint8_t> src, Span<uint8_t> dest,\n+int EncoderLibJpeg::encode(const MappedBuffer &source, Span<uint8_t> dest,\n \t\t\t   Span<const uint8_t> exifData, unsigned int quality)\n {\n \tunsigned char *destination = dest.data();\n@@ -221,9 +225,9 @@ int EncoderLibJpeg::encode(Span<const uint8_t> src, Span<uint8_t> dest,\n \t\t\t << \"x\" << compress_.image_height;\n \n \tif (nv_)\n-\t\tcompressNV(src);\n+\t\tcompressNV(source);\n \telse\n-\t\tcompressRGB(src);\n+\t\tcompressRGB(source);\n \n \tjpeg_finish_compress(&compress_);\n \ndiff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h\nindex 61fbd1a6..13a47b72 100644\n--- a/src/android/jpeg/encoder_libjpeg.h\n+++ b/src/android/jpeg/encoder_libjpeg.h\n@@ -10,6 +10,7 @@\n #include \"encoder.h\"\n \n #include \"libcamera/internal/formats.h\"\n+#include \"libcamera/internal/mapped_framebuffer.h\"\n \n #include <jpeglib.h>\n \n@@ -24,14 +25,14 @@ public:\n \t\t   libcamera::Span<uint8_t> destination,\n \t\t   libcamera::Span<const uint8_t> exifData,\n \t\t   unsigned int quality) override;\n-\tint encode(libcamera::Span<const uint8_t> source,\n+\tint encode(const libcamera::MappedBuffer &source,\n \t\t   libcamera::Span<uint8_t> destination,\n \t\t   libcamera::Span<const uint8_t> exifData,\n \t\t   unsigned int quality);\n \n private:\n-\tvoid compressRGB(libcamera::Span<const uint8_t> frame);\n-\tvoid compressNV(libcamera::Span<const uint8_t> frame);\n+\tvoid compressRGB(const libcamera::MappedBuffer &frame);\n+\tvoid compressNV(const libcamera::MappedBuffer &frame);\n \n \tstruct jpeg_compress_struct compress_;\n \tstruct jpeg_error_mgr jerr_;\ndiff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp\nindex 6eefce0f..a4e56b88 100644\n--- a/src/android/jpeg/post_processor_jpeg.cpp\n+++ b/src/android/jpeg/post_processor_jpeg.cpp\n@@ -75,8 +75,7 @@ void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source,\n \t\t\tbufferSize += plane.size();\n \t\tthumbnail->resize(bufferSize);\n \n-\t\tlibcamera::Span rawThumbnailData(rawThumbnail->planes()[0].data(), bufferSize);\n-\t\tint jpeg_size = thumbnailEncoder_.encode(rawThumbnailData,\n+\t\tint jpeg_size = thumbnailEncoder_.encode(*rawThumbnail,\n \t\t\t\t\t\t\t *thumbnail, {}, quality);\n \t\tthumbnail->resize(jpeg_size);\n \n@@ -181,7 +180,8 @@ int PostProcessorJpeg::process(const FrameBuffer &source,\n \tconst uint8_t quality = ret ? *entry.data.u8 : 95;\n \tresultMetadata->addEntry(ANDROID_JPEG_QUALITY, quality);\n \n-\tint jpeg_size = encoder_->encode(source, destination->plane(0),\n+\tint jpeg_size = encoder_->encode(source,\n+\t\t\t\t\t destination->plane(0),\n \t\t\t\t\t exif.data(), quality);\n \tif (jpeg_size < 0) {\n \t\tLOG(JPEG, Error) << \"Failed to encode stream image\";\n","prefixes":["libcamera-devel","5/5"]}