Patch Detail
Show a patch.
GET /api/patches/9905/?format=api
{ "id": 9905, "url": "https://patchwork.libcamera.org/api/patches/9905/?format=api", "web_url": "https://patchwork.libcamera.org/patch/9905/", "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": "<20201002103416.53623-2-email@uajain.com>", "date": "2020-10-02T10:34:14", "name": "[libcamera-devel,v1,1/3] android: jpeg: Add a basic NV12 image thumbnailer", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "4f44ec8cbfebe45c8f6ab3aeb75b715dbf148d38", "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/9905/mbox/", "series": [ { "id": 1346, "url": "https://patchwork.libcamera.org/api/series/1346/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1346", "date": "2020-10-02T10:34:13", "name": "Basic NV12 image thumbnailer", "version": 1, "mbox": "https://patchwork.libcamera.org/series/1346/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/9905/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/9905/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 013BEC3B5C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 2 Oct 2020 10:34:26 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C3C026035E;\n\tFri, 2 Oct 2020 12:34:25 +0200 (CEST)", "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 8DBB06035D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 2 Oct 2020 12:34:24 +0200 (CEST)" ], "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=\"UW2P319h\"; 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=1601634864; bh=zCGdyqe3kkvlrz9FbC68Dra0+l+7Uhw+EvRW0SbDDA0=;\n\th=From:To:Cc:Subject:In-Reply-To:References;\n\tb=UW2P319hahjwtn6Ox5RzI1OgEpAxSB1pLpXYV7ZwWXTRjJJUoukaZaKpimf1SEMHT\n\ty8ufOraDKnH/5gi6r9kS/Xa7WwTStG2qtLnD474xLl5f/Q/T3XCR8lSpGjMOHt0tlD\n\twkF+YBxNs3mvu/ko227AfdgH6In+v1H/8vSCjG/qiCo0dmlFm4BSgWd5AiO3ISVDcs\n\tteFj5g3xB7pRvEX0CiOLo7BwnhcN+jkbVyLVCBAKVdlPL/tWFVLlG+1zqe0l8uadEo\n\tpWMEcjbd6XV6TiIA0d8W+CtbIazRVDFbwkX7WMdjf+UdcDEgz2n6vVZqosWQicPFnr\n\tdBrPmh2a0OEQQ==", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 2 Oct 2020 16:04:14 +0530", "Message-Id": "<20201002103416.53623-2-email@uajain.com>", "In-Reply-To": "<20201002103416.53623-1-email@uajain.com>", "References": "<20201002103416.53623-1-email@uajain.com>", "Mime-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v1 1/3] android: jpeg: Add a basic NV12\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 for NV12 frames being captured.\nIt shall generate a thumbnail image to be embedded as a part of\nEXIF metadata of the frame. The output of the thumbnail will still\nbe NV12.\n\nSigned-off-by: Umang Jain <email@uajain.com>\n---\n src/android/jpeg/encoder_libjpeg.cpp | 12 +++\n src/android/jpeg/thumbnailer.cpp | 106 +++++++++++++++++++++++++++\n src/android/jpeg/thumbnailer.h | 34 +++++++++\n src/android/meson.build | 1 +\n 4 files changed, 153 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/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp\nindex 510613c..7d097c6 100644\n--- a/src/android/jpeg/encoder_libjpeg.cpp\n+++ b/src/android/jpeg/encoder_libjpeg.cpp\n@@ -6,6 +6,7 @@\n */\n \n #include \"encoder_libjpeg.h\"\n+#include \"thumbnailer.h\"\n \n #include <fcntl.h>\n #include <iomanip>\n@@ -214,6 +215,17 @@ int EncoderLibJpeg::encode(const FrameBuffer *source,\n \tLOG(JPEG, Debug) << \"JPEG Encode Starting:\" << compress_.image_width\n \t\t\t << \"x\" << compress_.image_height;\n \n+\tThumbnailer thScaler;\n+\tlibcamera::Span<uint8_t> thumbnail;\n+\tthScaler.configure(Size (compress_.image_width, compress_.image_height),\n+\t\t\t pixelFormatInfo_->format);\n+\tthScaler.scaleBuffer(source, thumbnail);\n+\t/*\n+\t * \\todo: Discuss if we require scaling here or one level above where\n+\t * exif data is set (setThumbnail()?).\n+\t * Setting thumbnailed scaled data seems a bit convulated initially.\n+\t */\n+\n \tif (nv_)\n \t\tcompressNV(&frame);\n \telse\ndiff --git a/src/android/jpeg/thumbnailer.cpp b/src/android/jpeg/thumbnailer.cpp\nnew file mode 100644\nindex 0000000..d706ea6\n--- /dev/null\n+++ b/src/android/jpeg/thumbnailer.cpp\n@@ -0,0 +1,106 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * thumbnailer.cpp - Basic image thumbnailer from NV12\n+ */\n+\n+#include \"thumbnailer.h\"\n+#include \"system/graphics.h\"\n+\n+#include \"libcamera/internal/file.h\"\n+#include \"libcamera/internal/log.h\"\n+\n+using namespace libcamera;\n+\n+LOG_DEFINE_CATEGORY(Thumbnailer)\n+\n+Thumbnailer::Thumbnailer()\n+\t: validConfiguration_(false)\n+{\n+}\n+\n+void Thumbnailer::configure(const Size &sourceSize, PixelFormat pixelFormat)\n+{\n+\tsourceSize_ = sourceSize;\n+\tpixelFormat_ = pixelFormat;\n+\n+\tif (pixelFormat_ .fourcc() == HAL_PIXEL_FORMAT_YV12) {\n+\t\tLOG (Thumbnailer, Error) << \"Failed to configure: Pixel Format \"\n+\t\t\t\t << pixelFormat_.toString() << \" unsupported.\";\n+\t\treturn;\n+\t}\n+\n+\tvalidConfiguration_ = true;\n+}\n+\n+/* Compute a thumbnail size with same aspect ratio as source. */\n+void Thumbnailer::computeThumbnailSize()\n+{\n+\tunsigned int baseWidth = 160;\n+\n+\tunsigned int width = baseWidth * sourceSize_.width / sourceSize_.height;\n+\ttargetSize_.width = width - (width % 16);\n+\ttargetSize_.height = targetSize_.width * sourceSize_.height\n+\t\t\t / sourceSize_.width;\n+\tif (targetSize_.height & 1)\n+\t\ttargetSize_.height++;\n+}\n+\n+int Thumbnailer::scaleBuffer(const FrameBuffer *source, Span<uint8_t> &dest)\n+{\n+\tMappedFrameBuffer frame(source, PROT_READ);\n+\tif (!frame.isValid()) {\n+\t\tLOG(Thumbnailer, Error) << \"Failed to map FrameBuffer : \"\n+\t\t\t\t << strerror(frame.error());\n+\t\treturn frame.error();\n+\t}\n+\n+\tif (!validConfiguration_) {\n+\t\tLOG(Thumbnailer, Error) << \"config is unconfigured or invalid.\";\n+\t\treturn -1;\n+\t}\n+\n+\tcomputeThumbnailSize();\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+\t/* Image scaling block implementing nearest-neighbour algorithm. */\n+\tunsigned char *src = static_cast<unsigned char *>(frame.maps()[0].data());\n+\tunsigned char *src_c = src + sh * sw;\n+\tunsigned int cb_pos = 0;\n+\tunsigned int cr_pos = 1;\n+\tunsigned char *src_cb, *src_cr;\n+\n+\tsize_t dstSize = (th * tw) + ((th/2) * tw);\n+\tunsigned char *destination = static_cast<unsigned char *>(malloc(dstSize));\n+\tunsigned char *dst = destination;\n+\tunsigned char *dst_c = destination + 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\tsrc_cb = src_c + (sourceY/2) * sw + cb_pos;\n+\t\tsrc_cr = src_c + (sourceY/2) * sw + cr_pos;\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\tdst[y * tw + x] = src[sw * sourceY + sourceX];\n+\t\t\tdst[(y+1) * tw + x] = src[sw * (sourceY+1) + sourceX];\n+\t\t\tdst[y * tw + (x+1)] = src[sw * sourceY + (sourceX+1)];\n+\t\t\tdst[(y+1) * tw + (x+1)] = src[sw * (sourceY+1) + (sourceX+1)];\n+\n+\t\t\tdst_c[(y/2) * tw + x + cb_pos] = src_cb[(sourceX/2) * 2];\n+\t\t\tdst_c[(y/2) * tw + x + cr_pos] = src_cr[(sourceX/2) * 2];\n+\t\t}\n+\t}\n+\n+\t/* Write scaled pixels to dest */\n+\tdest = { destination, dstSize };\n+\n+\treturn 0;\n+}\ndiff --git a/src/android/jpeg/thumbnailer.h b/src/android/jpeg/thumbnailer.h\nnew file mode 100644\nindex 0000000..8ba9816\n--- /dev/null\n+++ b/src/android/jpeg/thumbnailer.h\n@@ -0,0 +1,34 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * thumbnailer.h - Basic image thumbnailer from NV12\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+\tint scaleBuffer(const libcamera::FrameBuffer *source, libcamera::Span<uint8_t> &dest);\n+\n+private:\n+\tvoid computeThumbnailSize();\n+\n+\tlibcamera::PixelFormat pixelFormat_;\n+\tlibcamera::Size sourceSize_;\n+\tlibcamera::Size targetSize_;\n+\n+\tbool validConfiguration_;\n+};\n+\n+#endif /* __ANDROID_JPEG_THUMBNAILER_H__ */\ndiff --git a/src/android/meson.build b/src/android/meson.build\nindex 0293c20..f35ba04 100644\n--- a/src/android/meson.build\n+++ b/src/android/meson.build\n@@ -22,6 +22,7 @@ android_hal_sources = files([\n 'camera_ops.cpp',\n 'jpeg/encoder_libjpeg.cpp',\n 'jpeg/exif.cpp',\n+ 'jpeg/thumbnailer.cpp',\n ])\n \n android_camera_metadata_sources = files([\n", "prefixes": [ "libcamera-devel", "v1", "1/3" ] }