Patch Detail
Show a patch.
GET /api/patches/10271/?format=api
{ "id": 10271, "url": "https://patchwork.libcamera.org/api/patches/10271/?format=api", "web_url": "https://patchwork.libcamera.org/patch/10271/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/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": "<20201027212447.131431-3-email@uajain.com>", "date": "2020-10-27T21:24:46", "name": "[libcamera-devel,v2,2/3] android: jpeg: Introduce a simple image thumbnailer", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "77687f8c598d4f6966a0a9024b6ff83815299549", "submitter": { "id": 1, "url": "https://patchwork.libcamera.org/api/people/1/?format=api", "name": "Umang Jain", "email": "email@uajain.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/10271/mbox/", "series": [ { "id": 1422, "url": "https://patchwork.libcamera.org/api/series/1422/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1422", "date": "2020-10-27T21:24:44", "name": "android: jpeg: exif: Embed a JPEG-encoded thumbnail", "version": 2, "mbox": "https://patchwork.libcamera.org/series/1422/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/10271/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/10271/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 07AA6C3B5C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 27 Oct 2020 21:25:05 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C833362230;\n\tTue, 27 Oct 2020 22:25:04 +0100 (CET)", "from mail.uajain.com (static.126.159.217.95.clients.your-server.de\n\t[95.217.159.126])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 011936216C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 27 Oct 2020 22:25:03 +0100 (CET)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=uajain.com header.i=@uajain.com\n\theader.b=\"fAk7YyWS\"; dkim-atps=neutral", "From": "Umang Jain <email@uajain.com>", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=uajain.com; s=mail;\n\tt=1603833902; bh=T/LjeiBLl++5Y/Z66rdwcekpyjy3ENs3epqqIei3wNY=;\n\th=From:To:Cc:Subject:In-Reply-To:References;\n\tb=fAk7YyWSNmesOUoSjrV8gG1f+go0UABgt8knpbQfSoz/RVrQ3jAGktwFhj7S7PgAU\n\tWdi2b0gChxsb3tlU8+WMWxUTs4+FOL5lENbYxxEqkDmKC7qU3yEHRrqulbPZuw7ATo\n\t/CFSoYuEptXIus78AXIcXNHuVozCS/EcV2kGFlnI57MwU9LXPkVi9Tg+IE0X4uV/Qy\n\theBcFoxzbBlcGEi88CELy+QL8efuTohVltRqZscn2aAD7b+6u7VPS+kIaavC1tk6g9\n\tfB+3ROUQDLKaTL0fCe7halDYr4sTZBIxbGZUB5e3/ymqHt+fjDZrcnHpQhRNmbCMR1\n\tDrrq/xQgPBrjw==", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 28 Oct 2020 02:54:46 +0530", "Message-Id": "<20201027212447.131431-3-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 2/3] android: jpeg: Introduce a simple\n\timage thumbnailer", "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>", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Add a basic image Thumbnailer class for the frames being captured.\nCurrently, the thumbnailer can scale NV12 frames. It shall be used\nto generate a thumbnail image for EXIF metadata, in the subsequent\ncommit.\n\nSigned-off-by: Umang Jain <email@uajain.com>\n---\n src/android/jpeg/thumbnailer.cpp | 113 +++++++++++++++++++++++++++++++\n src/android/jpeg/thumbnailer.h | 36 ++++++++++\n src/android/meson.build | 1 +\n 3 files changed, 150 insertions(+)\n create mode 100644 src/android/jpeg/thumbnailer.cpp\n create mode 100644 src/android/jpeg/thumbnailer.h", "diff": "diff --git a/src/android/jpeg/thumbnailer.cpp b/src/android/jpeg/thumbnailer.cpp\nnew file mode 100644\nindex 0000000..2e3c478\n--- /dev/null\n+++ b/src/android/jpeg/thumbnailer.cpp\n@@ -0,0 +1,113 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * thumbnailer.cpp - Simple image thumbnailer\n+ */\n+\n+#include \"thumbnailer.h\"\n+\n+#include <libcamera/formats.h>\n+\n+#include \"libcamera/internal/log.h\"\n+\n+using namespace libcamera;\n+\n+LOG_DEFINE_CATEGORY(Thumbnailer)\n+\n+Thumbnailer::Thumbnailer()\n+\t: valid_(false)\n+{\n+}\n+\n+void Thumbnailer::configure(const Size &sourceSize, PixelFormat pixelFormat)\n+{\n+\tsourceSize_ = sourceSize;\n+\tpixelFormat_ = pixelFormat;\n+\n+\tif (pixelFormat_ != formats::NV12) {\n+\t\tLOG (Thumbnailer, Error)\n+\t\t\t<< \"Failed to configure: Pixel Format \"\n+\t\t\t<< pixelFormat_.toString() << \" unsupported.\";\n+\t\treturn;\n+\t}\n+\n+\ttargetSize_ = computeThumbnailSize();\n+\n+\tvalid_ = true;\n+}\n+\n+/*\n+ * The Exif specification recommends the width of the thumbnail to be a\n+ * multiple of 16 (section 4.8.1). Hence, compute the corresponding height\n+ * keeping the aspect ratio same as of the source.\n+ */\n+Size Thumbnailer::computeThumbnailSize() const\n+{\n+\tunsigned int targetHeight;\n+\tconstexpr unsigned int kTargetWidth = 160;\n+\n+\ttargetHeight = kTargetWidth * sourceSize_.height / sourceSize_.width;\n+\n+\tif (targetHeight & 1)\n+\t\ttargetHeight++;\n+\n+\treturn Size(kTargetWidth, targetHeight);\n+}\n+\n+void\n+Thumbnailer::createThumbnail(const FrameBuffer &source,\n+\t\t\t std::vector<unsigned char> *destination)\n+{\n+\tMappedFrameBuffer frame(&source, PROT_READ);\n+\tif (!frame.isValid()) {\n+\t\tLOG(Thumbnailer, Error)\n+\t\t\t<< \"Failed to map FrameBuffer : \"\n+\t\t\t<< strerror(frame.error());\n+\t\treturn;\n+\t}\n+\n+\tif (!valid_) {\n+\t\tLOG(Thumbnailer, Error) << \"Config is unconfigured or invalid.\";\n+\t\treturn;\n+\t}\n+\n+\tconst unsigned int sw = sourceSize_.width;\n+\tconst unsigned int sh = sourceSize_.height;\n+\tconst unsigned int tw = targetSize_.width;\n+\tconst unsigned int th = targetSize_.height;\n+\n+\tASSERT(tw % 2 == 0 && th % 2 == 0);\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 *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+\n+\tfor (unsigned int y = 0; y < th; y += 2) {\n+\t\tunsigned int sourceY = (sh * y + th / 2) / th;\n+\n+\t\tdstY = dst + y * tw;\n+\t\tsrcY = src + sw * sourceY;\n+\t\tsrcCb = srcC + (sourceY / 2) * sw + 0;\n+\t\tsrcCr = srcC + (sourceY / 2) * sw + 1;\n+\n+\t\tfor (unsigned int x = 0; x < tw; x += 2) {\n+\t\t\tunsigned int sourceX = (sw * x + tw / 2) / tw;\n+\n+\t\t\tdstY[x] = srcY[sourceX];\n+\t\t\tdstY[tw + x] = srcY[sw + sourceX];\n+\t\t\tdstY[x + 1] = srcY[sourceX + 1];\n+\t\t\tdstY[tw + x + 1] = srcY[sw + sourceX + 1];\n+\n+\t\t\tdstC[(y / 2) * tw + x + 0] = srcCb[(sourceX / 2) * 2];\n+\t\t\tdstC[(y / 2) * tw + x + 1] = srcCr[(sourceX / 2) * 2];\n+\t\t}\n+\t}\n+}\ndiff --git a/src/android/jpeg/thumbnailer.h b/src/android/jpeg/thumbnailer.h\nnew file mode 100644\nindex 0000000..16e6951\n--- /dev/null\n+++ b/src/android/jpeg/thumbnailer.h\n@@ -0,0 +1,36 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * thumbnailer.h - Simple image thumbnailer\n+ */\n+#ifndef __ANDROID_JPEG_THUMBNAILER_H__\n+#define __ANDROID_JPEG_THUMBNAILER_H__\n+\n+#include <libcamera/geometry.h>\n+\n+#include \"libcamera/internal/buffer.h\"\n+#include \"libcamera/internal/formats.h\"\n+\n+class Thumbnailer\n+{\n+public:\n+\tThumbnailer();\n+\n+\tvoid configure(const libcamera::Size &sourceSize,\n+\t\t libcamera::PixelFormat pixelFormat);\n+\tvoid createThumbnail(const libcamera::FrameBuffer &source,\n+\t\t\t std::vector<unsigned char> *dest);\n+\tconst libcamera::Size& size() const { return targetSize_; }\n+\n+private:\n+\tlibcamera::Size computeThumbnailSize() const;\n+\n+\tlibcamera::PixelFormat pixelFormat_;\n+\tlibcamera::Size sourceSize_;\n+\tlibcamera::Size targetSize_;\n+\n+\tbool valid_;\n+};\n+\n+#endif /* __ANDROID_JPEG_THUMBNAILER_H__ */\ndiff --git a/src/android/meson.build b/src/android/meson.build\nindex f72376a..3d4d3be 100644\n--- a/src/android/meson.build\n+++ b/src/android/meson.build\n@@ -25,6 +25,7 @@ android_hal_sources = files([\n 'jpeg/encoder_libjpeg.cpp',\n 'jpeg/exif.cpp',\n 'jpeg/post_processor_jpeg.cpp',\n+ 'jpeg/thumbnailer.cpp',\n ])\n \n android_camera_metadata_sources = files([\n", "prefixes": [ "libcamera-devel", "v2", "2/3" ] }