Patch Detail
Show a patch.
GET /api/1.1/patches/13306/?format=api
{ "id": 13306, "url": "https://patchwork.libcamera.org/api/1.1/patches/13306/?format=api", "web_url": "https://patchwork.libcamera.org/patch/13306/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20210811124015.2116188-6-hiroh@chromium.org>", "date": "2021-08-11T12:40:15", "name": "[libcamera-devel,RFC,5/5] WIP: android: jpeg: Use maps() and clean up", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "ca54c50837b1ee4ea01209eea266106d75476c7f", "submitter": { "id": 63, "url": "https://patchwork.libcamera.org/api/1.1/people/63/?format=api", "name": "Hirokazu Honda", "email": "hiroh@chromium.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/13306/mbox/", "series": [ { "id": 2339, "url": "https://patchwork.libcamera.org/api/1.1/series/2339/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2339", "date": "2021-08-11T12:40:10", "name": "MappedFrameBuffer::maps() returns the plane address", "version": 1, "mbox": "https://patchwork.libcamera.org/series/2339/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/13306/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/13306/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 48BFEC3242\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 11 Aug 2021 12:40:35 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DF4C96888F;\n\tWed, 11 Aug 2021 14:40:34 +0200 (CEST)", "from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com\n\t[IPv6:2607:f8b0:4864:20::102e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AA6906884D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 11 Aug 2021 14:40:33 +0200 (CEST)", "by mail-pj1-x102e.google.com with SMTP id\n\thv22-20020a17090ae416b0290178c579e424so4587628pjb.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 11 Aug 2021 05:40:33 -0700 (PDT)", "from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:ba11:c25e:242c:485d])\n\tby smtp.gmail.com with ESMTPSA id\n\tp30sm15722876pfh.116.2021.08.11.05.40.30\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 11 Aug 2021 05:40:31 -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=\"kkHIv9xN\"; 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=7KSQpt515bp2ZRdRFLOpnhZCNt2r9Wb+3ftNdr4TIMA=;\n\tb=kkHIv9xNK009p3ansmvWn/+iW6ipCnTdqL3quEfGxLqL7Z3XrOMo11XpvcChsX6hzZ\n\tb9QVpwPsUtV7Df44dLO/BEV7Q9v4KBG/saN8L/MSrq1M/tx+tPjDzjLNIDsTduPh7+Ir\n\tyUKcrQeUo6e6OQx3p9LYg1+FJR8wkIWqGrc3E=", "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=7KSQpt515bp2ZRdRFLOpnhZCNt2r9Wb+3ftNdr4TIMA=;\n\tb=YFh7i4xT2pzmTNTJHdAxugyjUj2bFLv9Mqy2Uxu/tTB8eRlJnhVwLV8KMwxRBXKQKa\n\ticTKKBPVrCP//q9GqVK+IEj8U7wKure6AB8c/wDTq2WjKcumeXo0DO8rjkjsfe9CLEsS\n\tuiyQnK0c2N8f96KOEhnAI681MENGvleV6nH/cJEe2d4hg3+ZkL/2am0lMAeeWPzWl2lC\n\tR2R2J05MG2pQ33/Y7zPv1Rrjri6aTUfQP+UA5da/JEa69b1bml0xcXuNmN04OL58ZIvy\n\tIp/LnaAZJNYBIchl5lge+5Zkd5adrqspc9F1VNX1Fjw2KH2qEwhzLqLCJbWwIdxneWeX\n\tuW2A==", "X-Gm-Message-State": "AOAM531RtGFxNjtx5LR3YxqsiJZHG+ZMcYl7BSs6KdSsXFkSrzen8KTT\n\tIzYsFWvGP/bxLD95GyCF8Pi1/aQtqkGlSw==", "X-Google-Smtp-Source": "ABdhPJw9Aup2jFjCmI8wOd8N3UaVggincMC6Of0XL4y8N0/4IWcmRH8RH0oRPSxYUpLOctQAjI+gpw==", "X-Received": "by 2002:a63:2217:: with SMTP id i23mr820672pgi.448.1628685631929;\n\tWed, 11 Aug 2021 05:40:31 -0700 (PDT)", "From": "Hirokazu Honda <hiroh@chromium.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 11 Aug 2021 21:40:15 +0900", "Message-Id": "<20210811124015.2116188-6-hiroh@chromium.org>", "X-Mailer": "git-send-email 2.32.0.605.g8dce9f2422-goog", "In-Reply-To": "<20210811124015.2116188-1-hiroh@chromium.org>", "References": "<20210811124015.2116188-1-hiroh@chromium.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [RFC PATCH 5/5] WIP: android: jpeg: Use maps()\n\tand clean up", "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": "WIP\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/android/jpeg/encoder.h | 7 +++--\n src/android/jpeg/encoder_libjpeg.cpp | 32 ++++++---------------\n src/android/jpeg/encoder_libjpeg.h | 10 ++-----\n src/android/jpeg/post_processor_jpeg.cpp | 21 ++++++++++----\n src/android/jpeg/thumbnailer.cpp | 36 ++++++++++++++++++++----\n src/android/jpeg/thumbnailer.h | 4 ++-\n src/libcamera/mapped_framebuffer.cpp | 2 ++\n 7 files changed, 66 insertions(+), 46 deletions(-)", "diff": "diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h\nindex a28522f4..2b9b8fca 100644\n--- a/src/android/jpeg/encoder.h\n+++ b/src/android/jpeg/encoder.h\n@@ -8,17 +8,18 @@\n #define __ANDROID_JPEG_ENCODER_H__\n \n #include <libcamera/base/span.h>\n-\n-#include <libcamera/framebuffer.h>\n #include <libcamera/stream.h>\n \n+#include \"libcamera/internal/framebuffer.h\"\n+#include \"libcamera/internal/mapped_framebuffer.h\"\n+\n class Encoder\n {\n public:\n \tvirtual ~Encoder() = default;\n \n \tvirtual int configure(const libcamera::StreamConfiguration &cfg) = 0;\n-\tvirtual int encode(const libcamera::FrameBuffer &source,\n+\tvirtual int encode(const libcamera::MappedFrameBuffer &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) = 0;\ndiff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp\nindex a7a63601..188aabdb 100644\n--- a/src/android/jpeg/encoder_libjpeg.cpp\n+++ b/src/android/jpeg/encoder_libjpeg.cpp\n@@ -94,7 +94,6 @@ int EncoderLibJpeg::configure(const StreamConfiguration &cfg)\n \tcompress_.input_components = info.colorSpace == JCS_GRAYSCALE ? 1 : 3;\n \n \tjpeg_set_defaults(&compress_);\n-\n \tpixelFormatInfo_ = &info.pixelFormatInfo;\n \n \tnv_ = pixelFormatInfo_->numPlanes() == 2;\n@@ -103,9 +102,9 @@ 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 libcamera::MappedFrameBuffer &frame)\n {\n-\tunsigned char *src = const_cast<unsigned char *>(frame.data());\n+\tunsigned char *src = const_cast<unsigned char *>(frame.maps()[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 +120,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 libcamera::MappedFrameBuffer &frame)\n {\n \tuint8_t tmprowbuf[compress_.image_width * 3];\n \n@@ -143,8 +142,8 @@ 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+\tconst unsigned char *src = frame.maps()[0].data();\n+\tconst unsigned char *src_c = frame.maps()[1].data();\n \n \tJSAMPROW row_pointer[1];\n \trow_pointer[0] = &tmprowbuf[0];\n@@ -152,7 +151,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,20 +177,7 @@ 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-{\n-\tMappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read);\n-\tif (!frame.isValid()) {\n-\t\tLOG(JPEG, Error) << \"Failed to map FrameBuffer : \"\n-\t\t\t\t << strerror(frame.error());\n-\t\treturn frame.error();\n-\t}\n-\n-\treturn encode(frame.maps()[0], dest, exifData, quality);\n-}\n-\n-int EncoderLibJpeg::encode(Span<const uint8_t> src, Span<uint8_t> dest,\n+int EncoderLibJpeg::encode(const MappedFrameBuffer &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 +207,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..588756aa 100644\n--- a/src/android/jpeg/encoder_libjpeg.h\n+++ b/src/android/jpeg/encoder_libjpeg.h\n@@ -20,18 +20,14 @@ public:\n \t~EncoderLibJpeg();\n \n \tint configure(const libcamera::StreamConfiguration &cfg) override;\n-\tint encode(const libcamera::FrameBuffer &source,\n+\tint encode(const libcamera::MappedFrameBuffer &source,\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-\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::MappedFrameBuffer &frame);\n+\tvoid compressNV(const libcamera::MappedFrameBuffer &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 3160a784..354e4fdd 100644\n--- a/src/android/jpeg/post_processor_jpeg.cpp\n+++ b/src/android/jpeg/post_processor_jpeg.cpp\n@@ -56,8 +56,7 @@ void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source,\n \t\t\t\t\t std::vector<unsigned char> *thumbnail)\n {\n \t/* Stores the raw scaled-down thumbnail bytes. */\n-\tstd::vector<unsigned char> rawThumbnail;\n-\n+\tstd::unique_ptr<MappedFrameBuffer> rawThumbnail;\n \tthumbnailer_.createThumbnail(source, targetSize, &rawThumbnail);\n \n \tStreamConfiguration thCfg;\n@@ -65,14 +64,17 @@ void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source,\n \tthCfg.pixelFormat = thumbnailer_.pixelFormat();\n \tint ret = thumbnailEncoder_.configure(thCfg);\n \n-\tif (!rawThumbnail.empty() && !ret) {\n+\tif (rawThumbnail && !ret) {\n \t\t/*\n \t\t * \\todo Avoid value-initialization of all elements of the\n \t\t * vector.\n \t\t */\n-\t\tthumbnail->resize(rawThumbnail.size());\n+\t\tsize_t thumbnail_size = 0;\n+\t\tfor (const MappedBuffer::Plane &plane : rawThumbnail->maps())\n+\t\t\tthumbnail_size += plane.size();\n+\t\tthumbnail->resize(thumbnail_size);\n \n-\t\tint jpeg_size = thumbnailEncoder_.encode(rawThumbnail,\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@@ -177,7 +179,14 @@ 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+\tMappedFrameBuffer mapped(&source, MappedFrameBuffer::MapFlag::Read);\n+\tif (!mapped.isValid()) {\n+\t\tLOG(JPEG, Error) << \"Failed to map FrameBuffer : \"\n+\t\t\t\t << strerror(mapped.error());\n+\t\treturn mapped.error();\n+\t}\n+\n+\tint jpeg_size = encoder_->encode(mapped, 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\";\ndiff --git a/src/android/jpeg/thumbnailer.cpp b/src/android/jpeg/thumbnailer.cpp\nindex 79d83926..e8fa9f84 100644\n--- a/src/android/jpeg/thumbnailer.cpp\n+++ b/src/android/jpeg/thumbnailer.cpp\n@@ -8,6 +8,7 @@\n #include \"thumbnailer.h\"\n \n #include <libcamera/base/log.h>\n+#include <libcamera/base/span.h>\n \n #include <libcamera/formats.h>\n \n@@ -17,6 +18,24 @@ using namespace libcamera;\n \n LOG_DEFINE_CATEGORY(Thumbnailer)\n \n+namespace {\n+class MappedThumbnailBuffer : public MappedFrameBuffer\n+{\n+public:\n+\tMappedThumbnailBuffer(std::vector<uint8_t> buffer,\n+\t\t\t const std::vector<Span<uint8_t>> &planes)\n+\t\t: MappedFrameBuffer(nullptr, MapFlag::Read),\n+\t\t buffer_(std::move(buffer))\n+\t{\n+\t\tplanes_ = planes;\n+\t}\n+\n+private:\n+\tstd::vector<uint8_t> buffer_;\n+};\n+\n+} // namespace\n+\n Thumbnailer::Thumbnailer()\n \t: valid_(false)\n {\n@@ -39,7 +58,7 @@ void Thumbnailer::configure(const Size &sourceSize, PixelFormat pixelFormat)\n \n void Thumbnailer::createThumbnail(const FrameBuffer &source,\n \t\t\t\t const Size &targetSize,\n-\t\t\t\t std::vector<unsigned char> *destination)\n+\t\t\t\t std::unique_ptr<MappedFrameBuffer> *destination)\n {\n \tMappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read);\n \tif (!frame.isValid()) {\n@@ -63,14 +82,19 @@ void Thumbnailer::createThumbnail(const FrameBuffer &source,\n \n \t/* Image scaling block implementing nearest-neighbour algorithm. */\n \tunsigned char *src = static_cast<unsigned char *>(frame.maps()[0].data());\n-\tunsigned char *srcC = src + sh * sw;\n+\tunsigned char *srcC = static_cast<unsigned char *>(frame.maps()[1].data());\n \tunsigned char *srcCb, *srcCr;\n \tunsigned char *dstY, *srcY;\n \n-\tsize_t dstSize = (th * tw) + ((th / 2) * tw);\n-\tdestination->resize(dstSize);\n-\tunsigned char *dst = destination->data();\n-\tunsigned char *dstC = dst + th * tw;\n+\tstd::vector<uint8_t> buffer(th * tw + (th / 2) * tw);\n+\tstd::vector<Span<uint8_t>> dstPlanes = {\n+\t\t{ buffer.data(), th * tw },\n+\t\t{ buffer.data() + th * tw, (th / 2) * tw }\n+\t};\n+\tunsigned char *dst = static_cast<unsigned char *>(dstPlanes[0].data());\n+\tunsigned char *dstC = static_cast<unsigned char *>(dstPlanes[1].data());\n+\t*destination = std::make_unique<MappedThumbnailBuffer>(std::move(buffer),\n+\t\t\t\t\t\t\t dstPlanes);\n \n \tfor (unsigned int y = 0; y < th; y += 2) {\n \t\tunsigned int sourceY = (sh * y + th / 2) / th;\ndiff --git a/src/android/jpeg/thumbnailer.h b/src/android/jpeg/thumbnailer.h\nindex 4d086c49..9c938588 100644\n--- a/src/android/jpeg/thumbnailer.h\n+++ b/src/android/jpeg/thumbnailer.h\n@@ -11,6 +11,7 @@\n #include <libcamera/geometry.h>\n \n #include \"libcamera/internal/formats.h\"\n+#include \"libcamera/internal/mapped_framebuffer.h\"\n \n class Thumbnailer\n {\n@@ -21,7 +22,8 @@ public:\n \t\t libcamera::PixelFormat pixelFormat);\n \tvoid createThumbnail(const libcamera::FrameBuffer &source,\n \t\t\t const libcamera::Size &targetSize,\n-\t\t\t std::vector<unsigned char> *dest);\n+\t\t\t std::unique_ptr<libcamera::MappedFrameBuffer> *dest);\n+\n \tconst libcamera::PixelFormat &pixelFormat() const { return pixelFormat_; }\n \n private:\ndiff --git a/src/libcamera/mapped_framebuffer.cpp b/src/libcamera/mapped_framebuffer.cpp\nindex 5d5b02f1..e5647127 100644\n--- a/src/libcamera/mapped_framebuffer.cpp\n+++ b/src/libcamera/mapped_framebuffer.cpp\n@@ -177,6 +177,8 @@ MappedBuffer::~MappedBuffer()\n */\n MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags)\n {\n+\tif (!buffer)\n+\t\treturn;\n \tASSERT(!buffer->planes().empty());\n \tplanes_.reserve(buffer->planes().size());\n \n", "prefixes": [ "libcamera-devel", "RFC", "5/5" ] }