Show a patch.

GET /api/patches/9549/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 9549,
    "url": "https://patchwork.libcamera.org/api/patches/9549/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/9549/",
    "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": "<20200909111445.2908-2-email@uajain.com>",
    "date": "2020-09-09T11:14:44",
    "name": "[libcamera-devel,v7,1/2] android: jpeg: Add EXIF infrastructure",
    "commit_ref": "c3d1329b93f0e27cb4b58c998c540c92a8158f20",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "8185bd3318c2f3667565eaf6280b44576a68941c",
    "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/9549/mbox/",
    "series": [
        {
            "id": 1278,
            "url": "https://patchwork.libcamera.org/api/series/1278/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1278",
            "date": "2020-09-09T11:14:43",
            "name": "android: jpeg: Add EXIF infrastructure",
            "version": 7,
            "mbox": "https://patchwork.libcamera.org/series/1278/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/9549/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/9549/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 E5569BDB1D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  9 Sep 2020 11:14:57 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B27A662D04;\n\tWed,  9 Sep 2020 13:14:57 +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 097FF60534\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  9 Sep 2020 13:14:56 +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=\"cRU3klOi\"; 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=1599650095; bh=wItggernxYqx/0qdbms0u/2TVGnoK5ZXYfbxbGHOggw=;\n\th=From:To:Cc:Subject:In-Reply-To:References;\n\tb=cRU3klOi+O/mzG4OHtFFSOVpQWVqRyuzoRIe7RqZbbtbbQ9xX9c+MKmaGIpyJhlSS\n\tDT63R3oJs5R8pGjZBh0MQIAKc0Vl4aEItH3wH1Xak+m4KAEKpbya8qz4tlmIRA3tdW\n\tfwIMmI0/MXPcVC6qEisO6pqKjSuaRidqTum4/MmAUGDku3hNak0PKbi0KLQIPIY9sd\n\ts9KzcwKm5yt1V19xVSRpla0AcFM15tRLybPnpyH09IGiu0O42GHfeqTV4LpNFHtWqx\n\tRhftkRpNbEy8Z3ZrkkXuxafvh68CXybwTy/Y59WcHoC6ZHbphx+SgziuTBxJkbw7Rq\n\tkM/4HjOKlus8A==",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed,  9 Sep 2020 16:44:44 +0530",
        "Message-Id": "<20200909111445.2908-2-email@uajain.com>",
        "In-Reply-To": "<20200909111445.2908-1-email@uajain.com>",
        "References": "<20200909111445.2908-1-email@uajain.com>",
        "Mime-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v7 1/2] android: jpeg: Add EXIF\n\tinfrastructure",
        "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": "From: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nProvide helper classes to utilise the libexif interfaces and link\nagainst libexif to support tag additions when creating JPEG images.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nSigned-off-by: Umang Jain <email@uajain.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/android/jpeg/exif.cpp | 188 ++++++++++++++++++++++++++++++++++++++\n src/android/jpeg/exif.h   |  46 ++++++++++\n src/android/meson.build   |   2 +\n 3 files changed, 236 insertions(+)\n create mode 100644 src/android/jpeg/exif.cpp\n create mode 100644 src/android/jpeg/exif.h",
    "diff": "diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp\nnew file mode 100644\nindex 0000000..41ddf48\n--- /dev/null\n+++ b/src/android/jpeg/exif.cpp\n@@ -0,0 +1,188 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * exif.cpp - EXIF tag creation using libexif\n+ */\n+\n+#include \"exif.h\"\n+\n+#include \"libcamera/internal/log.h\"\n+\n+using namespace libcamera;\n+\n+LOG_DEFINE_CATEGORY(EXIF)\n+\n+/*\n+ * The Exif class should be instantiated and specific properties set\n+ * through the exposed public API.\n+ *\n+ * Once all desired properties have been set, the user shall call\n+ * generate() to process the entries and generate the Exif data.\n+ *\n+ * Calls to generate() must check the return code to determine if any error\n+ * occurred during the construction of the Exif data, and if successful the\n+ * data can be obtained using the data() method.\n+ */\n+Exif::Exif()\n+\t: valid_(false), data_(nullptr), exifData_(0), size_(0)\n+{\n+\t/* Create an ExifMem allocator to construct entries. */\n+\tmem_ = exif_mem_new_default();\n+\tif (!mem_) {\n+\t\tLOG(EXIF, Error) << \"Failed to allocate ExifMem Allocator\";\n+\t\treturn;\n+\t}\n+\n+\tdata_ = exif_data_new_mem(mem_);\n+\tif (!data_) {\n+\t\tLOG(EXIF, Error) << \"Failed to allocate an ExifData structure\";\n+\t\treturn;\n+\t}\n+\n+\tvalid_ = true;\n+\n+\texif_data_set_option(data_, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION);\n+\texif_data_set_data_type(data_, EXIF_DATA_TYPE_COMPRESSED);\n+\n+\t/*\n+\t * Big-Endian: EXIF_BYTE_ORDER_MOTOROLA\n+\t * Little Endian: EXIF_BYTE_ORDER_INTEL\n+\t */\n+\texif_data_set_byte_order(data_, EXIF_BYTE_ORDER_INTEL);\n+\n+\t/* Create the mandatory EXIF fields with default data. */\n+\texif_data_fix(data_);\n+}\n+\n+Exif::~Exif()\n+{\n+\tif (exifData_)\n+\t\tfree(exifData_);\n+\n+\tif (data_)\n+\t\texif_data_unref(data_);\n+\n+\tif (mem_)\n+\t\texif_mem_unref(mem_);\n+}\n+\n+ExifEntry *Exif::createEntry(ExifIfd ifd, ExifTag tag)\n+{\n+\tExifContent *content = data_->ifd[ifd];\n+\tExifEntry *entry = exif_content_get_entry(content, tag);\n+\n+\tif (entry) {\n+\t\texif_entry_ref(entry);\n+\t\treturn entry;\n+\t}\n+\n+\tentry = exif_entry_new_mem(mem_);\n+\tif (!entry) {\n+\t\tLOG(EXIF, Error) << \"Failed to allocated new entry\";\n+\t\tvalid_ = false;\n+\t\treturn nullptr;\n+\t}\n+\n+\texif_content_add_entry(content, entry);\n+\texif_entry_initialize(entry, tag);\n+\n+\treturn entry;\n+}\n+\n+ExifEntry *Exif::createEntry(ExifIfd ifd, ExifTag tag, ExifFormat format,\n+\t\t\t      unsigned long components, unsigned int size)\n+{\n+\tExifContent *content = data_->ifd[ifd];\n+\n+\t/* Replace any existing entry with the same tag. */\n+\tExifEntry *existing = exif_content_get_entry(content, tag);\n+\texif_content_remove_entry(content, existing);\n+\n+\tExifEntry *entry = exif_entry_new_mem(mem_);\n+\tif (!entry) {\n+\t\tLOG(EXIF, Error) << \"Failed to allocated new entry\";\n+\t\tvalid_ = false;\n+\t\treturn nullptr;\n+\t}\n+\n+\tvoid *buffer = exif_mem_alloc(mem_, size);\n+\tif (!buffer) {\n+\t\tLOG(EXIF, Error) << \"Failed to allocate buffer for variable entry\";\n+\t\texif_mem_unref(mem_);\n+\t\tvalid_ = false;\n+\t\treturn nullptr;\n+\t}\n+\n+\tentry->data = static_cast<unsigned char *>(buffer);\n+\tentry->components = components;\n+\tentry->format = format;\n+\tentry->size = size;\n+\tentry->tag = tag;\n+\n+\texif_content_add_entry(content, entry);\n+\n+\treturn entry;\n+}\n+\n+void Exif::setShort(ExifIfd ifd, ExifTag tag, uint16_t item)\n+{\n+\tExifEntry *entry = createEntry(ifd, tag);\n+\tif (!entry)\n+\t\treturn;\n+\n+\texif_set_short(entry->data, EXIF_BYTE_ORDER_INTEL, item);\n+\texif_entry_unref(entry);\n+}\n+\n+void Exif::setLong(ExifIfd ifd, ExifTag tag, uint32_t item)\n+{\n+\tExifEntry *entry = createEntry(ifd, tag);\n+\tif (!entry)\n+\t\treturn;\n+\n+\texif_set_long(entry->data, EXIF_BYTE_ORDER_INTEL, item);\n+\texif_entry_unref(entry);\n+}\n+\n+void Exif::setRational(ExifIfd ifd, ExifTag tag, ExifRational item)\n+{\n+\tExifEntry *entry = createEntry(ifd, tag);\n+\tif (!entry)\n+\t\treturn;\n+\n+\texif_set_rational(entry->data, EXIF_BYTE_ORDER_INTEL, item);\n+\texif_entry_unref(entry);\n+}\n+\n+void Exif::setString(ExifIfd ifd, ExifTag tag, ExifFormat format, const std::string &item)\n+{\n+\t/* Pad 1 extra byte for null-terminated string. */\n+\tsize_t length = item.length() + 1;\n+\n+\tExifEntry *entry = createEntry(ifd, tag, format, length, length);\n+\tif (!entry)\n+\t\treturn;\n+\n+\tmemcpy(entry->data, item.c_str(), length);\n+\texif_entry_unref(entry);\n+}\n+\n+[[nodiscard]] int Exif::generate()\n+{\n+\tif (exifData_) {\n+\t\tfree(exifData_);\n+\t\texifData_ = nullptr;\n+\t}\n+\n+\tif (!valid_) {\n+\t\tLOG(EXIF, Error) << \"Generated EXIF data is invalid\";\n+\t\treturn -1;\n+\t}\n+\n+\texif_data_save_data(data_, &exifData_, &size_);\n+\n+\tLOG(EXIF, Debug) << \"Created EXIF instance (\" << size_ << \" bytes)\";\n+\n+\treturn 0;\n+}\ndiff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h\nnew file mode 100644\nindex 0000000..8dfc324\n--- /dev/null\n+++ b/src/android/jpeg/exif.h\n@@ -0,0 +1,46 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * exif.h - EXIF tag creator using libexif\n+ */\n+#ifndef __ANDROID_JPEG_EXIF_H__\n+#define __ANDROID_JPEG_EXIF_H__\n+\n+#include <ctime>\n+#include <string>\n+\n+#include <libexif/exif-data.h>\n+\n+#include <libcamera/span.h>\n+\n+class Exif\n+{\n+public:\n+\tExif();\n+\t~Exif();\n+\n+\tlibcamera::Span<const uint8_t> data() const { return { exifData_, size_ }; }\n+\t[[nodiscard]] int generate();\n+\n+private:\n+\tExifEntry *createEntry(ExifIfd ifd, ExifTag tag);\n+\tExifEntry *createEntry(ExifIfd ifd, ExifTag tag, ExifFormat format,\n+\t\t\t       unsigned long components, unsigned int size);\n+\n+\tvoid setShort(ExifIfd ifd, ExifTag tag, uint16_t item);\n+\tvoid setLong(ExifIfd ifd, ExifTag tag, uint32_t item);\n+\tvoid setString(ExifIfd ifd, ExifTag tag, ExifFormat format,\n+\t\t       const std::string &item);\n+\tvoid setRational(ExifIfd ifd, ExifTag tag, ExifRational item);\n+\n+\tbool valid_;\n+\n+\tExifData *data_;\n+\tExifMem *mem_;\n+\n+\tunsigned char *exifData_;\n+\tunsigned int size_;\n+};\n+\n+#endif /* __ANDROID_JPEG_EXIF_H__ */\ndiff --git a/src/android/meson.build b/src/android/meson.build\nindex f7b81a4..ecb92f6 100644\n--- a/src/android/meson.build\n+++ b/src/android/meson.build\n@@ -7,6 +7,7 @@ android_hal_sources = files([\n     'camera_metadata.cpp',\n     'camera_ops.cpp',\n     'jpeg/encoder_libjpeg.cpp',\n+    'jpeg/exif.cpp',\n ])\n \n android_camera_metadata_sources = files([\n@@ -14,6 +15,7 @@ android_camera_metadata_sources = files([\n ])\n \n android_deps = [\n+    dependency('libexif'),\n     dependency('libjpeg'),\n ]\n \n",
    "prefixes": [
        "libcamera-devel",
        "v7",
        "1/2"
    ]
}