{"id":18122,"url":"https://patchwork.libcamera.org/api/patches/18122/?format=json","web_url":"https://patchwork.libcamera.org/patch/18122/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20230116002808.16014-6-laurent.pinchart@ideasonboard.com>","date":"2023-01-16T00:28:05","name":"[libcamera-devel,v9,5/8] android: jpeg: Move generateThumbnail from PostProcessorJpeg to Encoder","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"57f5f2264244b98ea94f25c63d2e747cc5aa7d3d","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/18122/mbox/","series":[{"id":3712,"url":"https://patchwork.libcamera.org/api/series/3712/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3712","date":"2023-01-16T00:28:00","name":"Add CrOS JEA implementation","version":9,"mbox":"https://patchwork.libcamera.org/series/3712/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18122/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18122/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 1A1E5BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 16 Jan 2023 00:28:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D7063625ED;\n\tMon, 16 Jan 2023 01:28:17 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DB169625ED\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Jan 2023 01:28:15 +0100 (CET)","from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi\n\t[213.243.189.158])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 65DF5997;\n\tMon, 16 Jan 2023 01:28:15 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1673828897;\n\tbh=hCooJpmA0EKWQFuR1X6So/CKwd7Gf4+on6DA8SWBGww=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=3gWaInUzVQ6rTkE0rc7KKiSC7IPKqlghCCsygxYQPtClotiG2kXLE0dxjbdt3OhXJ\n\t+SncFDsPTC8l7xf8UM0q8nRrY3J66jGq2LcDtp/Ihb6bF9JmqjvsbKIrCnMvaVfOaJ\n\thiwe14JSyarmytwcoySwD4lSNxKlGB0lsJGjonwAfdVnW6Jj5oUFbxfsK/sIXkJ/Z2\n\t736mUaOxddtOsvY3UC1T0fbIoG91wCzCzlDdctENJ/gonB7gdYf/NCDzHJTNWUvhhC\n\tsSe4+1pPsMLzkazm+Dl1BpscBI0vdlWpgRkTg2R5zW4tbhrXU3Htwgi3EAz3vhMXOF\n\taLo1R7w4Ui1ww==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1673828895;\n\tbh=hCooJpmA0EKWQFuR1X6So/CKwd7Gf4+on6DA8SWBGww=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=wHC430gM0aIcgXtUxIge3rslF5zrbmdTnLpQ/4tjguoROrjQVqTXvcli4p2wIOE55\n\tTp0fWxsJ20bDjZOvOCz2M4AYq96ZthkDmPztQ8+3xKXNAT8DxOnlhPim9T4ji6Nn48\n\tTtWurCL+f4r0tX+qC68ot1nFqYekkTgzIXfPJAmw="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"wHC430gM\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 16 Jan 2023 02:28:05 +0200","Message-Id":"<20230116002808.16014-6-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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v9 5/8] android: jpeg: Move\n\tgenerateThumbnail from PostProcessorJpeg to Encoder","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"Harvey Yang <chenghaoyang@chromium.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Harvey Yang <chenghaoyang@chromium.org>\n\nIn the following patch, generateThumbnail will have a different\nimplementation in the jea encoder. Therefore, this patch moves the\ngenerateThumbnail function from PostProcessorJpeg to Encoder.\n\nSigned-off-by: Harvey Yang <chenghaoyang@chromium.org>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/android/jpeg/encoder.h               |  4 ++\n src/android/jpeg/encoder_libjpeg.cpp     | 54 +++++++++++++++++++++---\n src/android/jpeg/encoder_libjpeg.h       | 15 ++++---\n src/android/jpeg/post_processor_jpeg.cpp | 52 +----------------------\n src/android/jpeg/post_processor_jpeg.h   | 10 +----\n 5 files changed, 65 insertions(+), 70 deletions(-)","diff":"diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h\nindex b974d367d8fa..5f9ef890023a 100644\n--- a/src/android/jpeg/encoder.h\n+++ b/src/android/jpeg/encoder.h\n@@ -22,4 +22,8 @@ public:\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;\n+\tvirtual void generateThumbnail(const libcamera::FrameBuffer &source,\n+\t\t\t\t       const libcamera::Size &targetSize,\n+\t\t\t\t       unsigned int quality,\n+\t\t\t\t       std::vector<unsigned char> *thumbnail) = 0;\n };\ndiff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp\nindex 69fd91122aa6..9bbf1abbe09c 100644\n--- a/src/android/jpeg/encoder_libjpeg.cpp\n+++ b/src/android/jpeg/encoder_libjpeg.cpp\n@@ -73,7 +73,7 @@ EncoderLibJpeg::~EncoderLibJpeg() = default;\n \n int EncoderLibJpeg::configure(const StreamConfiguration &cfg)\n {\n-\treturn encoder_.configure(cfg);\n+\treturn captureEncoder_.configure(cfg);\n }\n \n int EncoderLibJpeg::encode(const FrameBuffer &source, Span<uint8_t> dest,\n@@ -86,14 +86,56 @@ int EncoderLibJpeg::encode(const FrameBuffer &source, Span<uint8_t> dest,\n \t\treturn frame.error();\n \t}\n \n-\treturn encoder_.encode(frame.planes(), dest, exifData, quality);\n+\treturn captureEncoder_.encode(frame.planes(), dest, exifData, quality);\n }\n \n-int EncoderLibJpeg::encode(const std::vector<Span<uint8_t>> &src,\n-\t\t\t   Span<uint8_t> dest, Span<const uint8_t> exifData,\n-\t\t\t   unsigned int quality)\n+void EncoderLibJpeg::generateThumbnail(const libcamera::FrameBuffer &source,\n+\t\t\t\t       const libcamera::Size &targetSize,\n+\t\t\t\t       unsigned int quality,\n+\t\t\t\t       std::vector<unsigned char> *thumbnail)\n {\n-\treturn encoder_.encode(src, dest, exifData, quality);\n+\t/* Stores the raw scaled-down thumbnail bytes. */\n+\tstd::vector<unsigned char> rawThumbnail;\n+\n+\tthumbnailer_.createThumbnail(source, targetSize, &rawThumbnail);\n+\n+\tStreamConfiguration thCfg;\n+\tthCfg.size = targetSize;\n+\tthCfg.pixelFormat = thumbnailer_.pixelFormat();\n+\tint ret = thumbnailEncoder_.configure(thCfg);\n+\n+\tif (!rawThumbnail.empty() && !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+\n+\t\t/*\n+\t\t * Split planes manually as the encoder expects a vector of\n+\t\t * planes.\n+\t\t *\n+\t\t * \\todo Pass a vector of planes directly to\n+\t\t * Thumbnailer::createThumbnailer above and remove the manual\n+\t\t * planes split from here.\n+\t\t */\n+\t\tstd::vector<Span<uint8_t>> thumbnailPlanes;\n+\t\tconst PixelFormatInfo &formatNV12 =\n+\t\t\tPixelFormatInfo::info(formats::NV12);\n+\t\tsize_t yPlaneSize = formatNV12.planeSize(targetSize, 0);\n+\t\tsize_t uvPlaneSize = formatNV12.planeSize(targetSize, 1);\n+\t\tthumbnailPlanes.push_back({ rawThumbnail.data(), yPlaneSize });\n+\t\tthumbnailPlanes.push_back({ rawThumbnail.data() + yPlaneSize,\n+\t\t\t\t\t    uvPlaneSize });\n+\n+\t\tint jpegSize = thumbnailEncoder_.encode(thumbnailPlanes, *thumbnail,\n+\t\t\t\t\t\t\t{}, quality);\n+\t\tthumbnail->resize(jpegSize);\n+\n+\t\tLOG(JPEG, Debug)\n+\t\t\t<< \"Thumbnail compress returned \"\n+\t\t\t<< jpegSize << \" bytes\";\n+\t}\n }\n \n EncoderLibJpeg::Encoder::Encoder()\ndiff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h\nindex eba591633cbb..a022a72e02bf 100644\n--- a/src/android/jpeg/encoder_libjpeg.h\n+++ b/src/android/jpeg/encoder_libjpeg.h\n@@ -15,6 +15,8 @@\n \n #include <jpeglib.h>\n \n+#include \"thumbnailer.h\"\n+\n class EncoderLibJpeg : public Encoder\n {\n public:\n@@ -26,10 +28,10 @@ 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(const std::vector<libcamera::Span<uint8_t>> &planes,\n-\t\t   libcamera::Span<uint8_t> destination,\n-\t\t   libcamera::Span<const uint8_t> exifData,\n-\t\t   unsigned int quality);\n+\tvoid generateThumbnail(const libcamera::FrameBuffer &source,\n+\t\t\t       const libcamera::Size &targetSize,\n+\t\t\t       unsigned int quality,\n+\t\t\t       std::vector<unsigned char> *thumbnail) override;\n \n private:\n \tclass Encoder\n@@ -57,5 +59,8 @@ private:\n \t\tbool nvSwap_;\n \t};\n \n-\tEncoder encoder_;\n+\tEncoder captureEncoder_;\n+\tEncoder thumbnailEncoder_;\n+\n+\tThumbnailer thumbnailer_;\n };\ndiff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp\nindex 0cf567164f99..69b18a2e5945 100644\n--- a/src/android/jpeg/post_processor_jpeg.cpp\n+++ b/src/android/jpeg/post_processor_jpeg.cpp\n@@ -44,60 +44,11 @@ int PostProcessorJpeg::configure(const StreamConfiguration &inCfg,\n \n \tstreamSize_ = outCfg.size;\n \n-\tthumbnailer_.configure(inCfg.size, inCfg.pixelFormat);\n-\n \tencoder_ = std::make_unique<EncoderLibJpeg>();\n \n \treturn encoder_->configure(inCfg);\n }\n \n-void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source,\n-\t\t\t\t\t  const Size &targetSize,\n-\t\t\t\t\t  unsigned int quality,\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-\tthumbnailer_.createThumbnail(source, targetSize, &rawThumbnail);\n-\n-\tStreamConfiguration thCfg;\n-\tthCfg.size = targetSize;\n-\tthCfg.pixelFormat = thumbnailer_.pixelFormat();\n-\tint ret = thumbnailEncoder_.configure(thCfg);\n-\n-\tif (!rawThumbnail.empty() && !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-\n-\t\t/*\n-\t\t * Split planes manually as the encoder expects a vector of\n-\t\t * planes.\n-\t\t *\n-\t\t * \\todo Pass a vector of planes directly to\n-\t\t * Thumbnailer::createThumbnailer above and remove the manual\n-\t\t * planes split from here.\n-\t\t */\n-\t\tstd::vector<Span<uint8_t>> thumbnailPlanes;\n-\t\tconst PixelFormatInfo &formatNV12 = PixelFormatInfo::info(formats::NV12);\n-\t\tsize_t yPlaneSize = formatNV12.planeSize(targetSize, 0);\n-\t\tsize_t uvPlaneSize = formatNV12.planeSize(targetSize, 1);\n-\t\tthumbnailPlanes.push_back({ rawThumbnail.data(), yPlaneSize });\n-\t\tthumbnailPlanes.push_back({ rawThumbnail.data() + yPlaneSize, uvPlaneSize });\n-\n-\t\tint jpeg_size = thumbnailEncoder_.encode(thumbnailPlanes,\n-\t\t\t\t\t\t\t *thumbnail, {}, quality);\n-\t\tthumbnail->resize(jpeg_size);\n-\n-\t\tLOG(JPEG, Debug)\n-\t\t\t<< \"Thumbnail compress returned \"\n-\t\t\t<< jpeg_size << \" bytes\";\n-\t}\n-}\n-\n void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBuffer)\n {\n \tASSERT(encoder_);\n@@ -164,7 +115,8 @@ void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBu\n \n \t\tif (thumbnailSize != Size(0, 0)) {\n \t\t\tstd::vector<unsigned char> thumbnail;\n-\t\t\tgenerateThumbnail(source, thumbnailSize, quality, &thumbnail);\n+\t\t\tencoder_->generateThumbnail(source, thumbnailSize,\n+\t\t\t\t\t\t    quality, &thumbnail);\n \t\t\tif (!thumbnail.empty())\n \t\t\t\texif.setThumbnail(std::move(thumbnail), Exif::Compression::JPEG);\n \t\t}\ndiff --git a/src/android/jpeg/post_processor_jpeg.h b/src/android/jpeg/post_processor_jpeg.h\nindex 98309b012a3b..f09c9a1d8738 100644\n--- a/src/android/jpeg/post_processor_jpeg.h\n+++ b/src/android/jpeg/post_processor_jpeg.h\n@@ -8,12 +8,11 @@\n #pragma once\n \n #include \"../post_processor.h\"\n-#include \"encoder_libjpeg.h\"\n-#include \"thumbnailer.h\"\n \n #include <libcamera/geometry.h>\n \n class CameraDevice;\n+class Encoder;\n \n class PostProcessorJpeg : public PostProcessor\n {\n@@ -25,14 +24,7 @@ public:\n \tvoid process(Camera3RequestDescriptor::StreamBuffer *streamBuffer) override;\n \n private:\n-\tvoid generateThumbnail(const libcamera::FrameBuffer &source,\n-\t\t\t       const libcamera::Size &targetSize,\n-\t\t\t       unsigned int quality,\n-\t\t\t       std::vector<unsigned char> *thumbnail);\n-\n \tCameraDevice *const cameraDevice_;\n \tstd::unique_ptr<Encoder> encoder_;\n \tlibcamera::Size streamSize_;\n-\tEncoderLibJpeg thumbnailEncoder_;\n-\tThumbnailer thumbnailer_;\n };\n","prefixes":["libcamera-devel","v9","5/8"]}