{"id":9476,"url":"https://patchwork.libcamera.org/api/1.1/patches/9476/?format=json","web_url":"https://patchwork.libcamera.org/patch/9476/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20200903163216.6359-3-email@uajain.com>","date":"2020-09-03T16:32:16","name":"[libcamera-devel,v5,2/2] android: jpeg: Support an initial set of EXIF metadata tags","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"ad17f778681c01642a52c9d344d1314f511f0352","submitter":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/people/1/?format=json","name":"Umang Jain","email":"email@uajain.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/9476/mbox/","series":[{"id":1260,"url":"https://patchwork.libcamera.org/api/1.1/series/1260/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1260","date":"2020-09-03T16:32:14","name":"Initial EXIF metadata support","version":5,"mbox":"https://patchwork.libcamera.org/series/1260/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9476/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9476/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 B7FA6BF019\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  3 Sep 2020 16:32:29 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8181362901;\n\tThu,  3 Sep 2020 18:32:29 +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 CFA3B62901\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  3 Sep 2020 18:32:28 +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=\"YTZ8er5U\"; 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=1599150748; bh=gjbuH+iRUn6dWP7d4ynK9rOqnVWTXc481AZerdeQ5D0=;\n\th=From:To:Cc:Subject:In-Reply-To:References;\n\tb=YTZ8er5UcH2cg02elK/yY5j8jpz0aSNhWr9wyx7PzVWnpj6UZte7ktdoefNHvRCcR\n\tx9JVFco4cyNkGOWzwMcxSeuKtiA2bofMixJXKS8qCT8XnM5UlIpPgzVSkIaNYA6XWe\n\trznAQT37LUpt8w9fnQmEanwBtmrXVbz3CJYMgpbVVLpNFObyL/CuGGQem468Z05byx\n\tumhNsb2/XVL0EU9lNS6A1C3SpaF7/xn5tDEfBv3iyEuApp4O/+aif7ie+/LJLiSrc5\n\tES1v4ghBGgNPEn3so90WcIg52oxsTaA0+lknJvHhIZvbQ2HUwFqlQcafPPGsUViTb0\n\txtbyZ89PJk2qQ==","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  3 Sep 2020 22:02:16 +0530","Message-Id":"<20200903163216.6359-3-email@uajain.com>","In-Reply-To":"<20200903163216.6359-1-email@uajain.com>","References":"<20200903163216.6359-1-email@uajain.com>","Mime-Version":"1.0","Subject":"[libcamera-devel] [PATCH v5 2/2] android: jpeg: Support an initial\n\tset of EXIF metadata tags","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":"Create a Exif object with various metadata tags set, just before\nthe encoder starts to encode the frame. The object is passed\ndirectly as libcamera::Span<> to make sure EXIF tags can be set\nin a single place i.e. in CameraDevice and the encoder only has\nthe job to write the data in the final output.\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>\n---\n src/android/camera_device.cpp        | 18 ++++++++++-\n src/android/jpeg/encoder.h           |  3 +-\n src/android/jpeg/encoder_libjpeg.cpp |  9 +++++-\n src/android/jpeg/encoder_libjpeg.h   |  3 +-\n src/android/jpeg/exif.cpp            | 48 +++++++++++++++++++++++++++-\n src/android/jpeg/exif.h              |  8 +++++\n 6 files changed, 84 insertions(+), 5 deletions(-)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex de6f86f..54ca9c6 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -24,6 +24,7 @@\n #include \"system/graphics.h\"\n \n #include \"jpeg/encoder_libjpeg.h\"\n+#include \"jpeg/exif.h\"\n \n using namespace libcamera;\n \n@@ -1434,7 +1435,22 @@ void CameraDevice::requestComplete(Request *request)\n \t\t\tcontinue;\n \t\t}\n \n-\t\tint jpeg_size = encoder->encode(buffer, mapped.maps()[0]);\n+\t\t/* Set EXIF metadata for various tags. */\n+\t\tExif exif;\n+\t\t/* \\todo Set Make and Model from external vendor tags. */\n+\t\texif.setMake(\"libcamera\");\n+\t\texif.setModel(\"cameraModel\");\n+\t\texif.setOrientation(orientation_);\n+\t\texif.setSize(cameraStream->size);\n+\t\t/*\n+\t\t * We set the frame's EXIF timestamp as the time of encode.\n+\t\t * Since the precision we need for EXIF timestamp is only one\n+\t\t * second, it is good enough.\n+\t\t */\n+\t\texif.setTimestamp(std::time(nullptr));\n+\t\texif.generate();\n+\n+\t\tint jpeg_size = encoder->encode(buffer, mapped.maps()[0], exif.data());\n \t\tif (jpeg_size < 0) {\n \t\t\tLOG(HAL, Error) << \"Failed to encode stream image\";\n \t\t\tstatus = CAMERA3_BUFFER_STATUS_ERROR;\ndiff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h\nindex f9eb88e..cf26d67 100644\n--- a/src/android/jpeg/encoder.h\n+++ b/src/android/jpeg/encoder.h\n@@ -18,7 +18,8 @@ public:\n \n \tvirtual int configure(const libcamera::StreamConfiguration &cfg) = 0;\n \tvirtual int encode(const libcamera::FrameBuffer *source,\n-\t\t\t   const libcamera::Span<uint8_t> &destination) = 0;\n+\t\t\t   const libcamera::Span<uint8_t> &destination,\n+\t\t\t   const libcamera::Span<const uint8_t> &exifData) = 0;\n };\n \n #endif /* __ANDROID_JPEG_ENCODER_H__ */\ndiff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp\nindex 977538c..510613c 100644\n--- a/src/android/jpeg/encoder_libjpeg.cpp\n+++ b/src/android/jpeg/encoder_libjpeg.cpp\n@@ -180,7 +180,8 @@ void EncoderLibJpeg::compressNV(const libcamera::MappedBuffer *frame)\n }\n \n int EncoderLibJpeg::encode(const FrameBuffer *source,\n-\t\t\t   const libcamera::Span<uint8_t> &dest)\n+\t\t\t   const libcamera::Span<uint8_t> &dest,\n+\t\t\t   const libcamera::Span<const uint8_t> &exifData)\n {\n \tMappedFrameBuffer frame(source, PROT_READ);\n \tif (!frame.isValid()) {\n@@ -204,6 +205,12 @@ int EncoderLibJpeg::encode(const FrameBuffer *source,\n \n \tjpeg_start_compress(&compress_, TRUE);\n \n+\tif (exifData.size())\n+\t\t/* Store Exif data in the JPEG_APP1 data block. */\n+\t\tjpeg_write_marker(&compress_, JPEG_APP0 + 1,\n+\t\t\t\t  static_cast<const JOCTET *>(exifData.data()),\n+\t\t\t\t  exifData.size());\n+\n \tLOG(JPEG, Debug) << \"JPEG Encode Starting:\" << compress_.image_width\n \t\t\t << \"x\" << compress_.image_height;\n \ndiff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h\nindex aed081a..1e8df05 100644\n--- a/src/android/jpeg/encoder_libjpeg.h\n+++ b/src/android/jpeg/encoder_libjpeg.h\n@@ -22,7 +22,8 @@ public:\n \n \tint configure(const libcamera::StreamConfiguration &cfg) override;\n \tint encode(const libcamera::FrameBuffer *source,\n-\t\t   const libcamera::Span<uint8_t> &destination) override;\n+\t\t   const libcamera::Span<uint8_t> &destination,\n+\t\t   const libcamera::Span<const uint8_t> &exifData) override;\n \n private:\n \tvoid compressRGB(const libcamera::MappedBuffer *frame);\ndiff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp\nindex 9d8d9bc..5def7e3 100644\n--- a/src/android/jpeg/exif.cpp\n+++ b/src/android/jpeg/exif.cpp\n@@ -169,7 +169,53 @@ void Exif::setString(ExifIfd ifd, ExifTag tag, ExifFormat format, const std::str\n \texif_entry_unref(entry);\n }\n \n-int Exif::generate()\n+void Exif::setMake(const std::string &make)\n+{\n+\tsetString(EXIF_IFD_0, EXIF_TAG_MAKE, EXIF_FORMAT_ASCII, make);\n+}\n+\n+void Exif::setModel(const std::string &model)\n+{\n+\tsetString(EXIF_IFD_0, EXIF_TAG_MODEL, EXIF_FORMAT_ASCII, model);\n+}\n+\n+void Exif::setSize(const Size &size)\n+{\n+\tsetLong(EXIF_IFD_EXIF, EXIF_TAG_PIXEL_Y_DIMENSION, size.height);\n+\tsetLong(EXIF_IFD_EXIF, EXIF_TAG_PIXEL_X_DIMENSION, size.width);\n+}\n+\n+void Exif::setTimestamp(time_t timestamp)\n+{\n+\tchar str[20];\n+\tstd::strftime(str, sizeof(str), \"%Y:%m:%d %H:%M:%S\",\n+\t\t      std::localtime(&timestamp));\n+\tstd::string ts(str);\n+\n+\tsetString(EXIF_IFD_0, EXIF_TAG_DATE_TIME, EXIF_FORMAT_ASCII, ts);\n+\tsetString(EXIF_IFD_EXIF, EXIF_TAG_DATE_TIME_ORIGINAL, EXIF_FORMAT_ASCII, ts);\n+\tsetString(EXIF_IFD_EXIF, EXIF_TAG_DATE_TIME_DIGITIZED, EXIF_FORMAT_ASCII, ts);\n+}\n+\n+void Exif::setOrientation(int orientation)\n+{\n+\tint value = 1;\n+\tswitch (orientation) {\n+\tcase 90:\n+\t\tvalue = 6;\n+\t\tbreak;\n+\tcase 180:\n+\t\tvalue = 3;\n+\t\tbreak;\n+\tcase 270:\n+\t\tvalue = 8;\n+\t\tbreak;\n+\t}\n+\n+\tsetShort(EXIF_IFD_0, EXIF_TAG_ORIENTATION, value);\n+}\n+\n+void Exif::generate()\n {\n \tif (exifData_) {\n \t\tfree(exifData_);\ndiff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h\nindex 8fb8ffd..6113ca6 100644\n--- a/src/android/jpeg/exif.h\n+++ b/src/android/jpeg/exif.h\n@@ -12,6 +12,7 @@\n \n #include <libexif/exif-data.h>\n \n+#include <libcamera/geometry.h>\n #include <libcamera/span.h>\n \n class Exif\n@@ -20,6 +21,13 @@ public:\n \tExif();\n \t~Exif();\n \n+\tvoid setMake(const std::string &make);\n+\tvoid setModel(const std::string &model);\n+\n+\tvoid setOrientation(int orientation);\n+\tvoid setSize(const libcamera::Size &size);\n+\tvoid setTimestamp(time_t timestamp);\n+\n \tlibcamera::Span<const uint8_t> data() const { return { exifData_, size_ }; }\n \tint [[nodiscard]]  generate();\n \n","prefixes":["libcamera-devel","v5","2/2"]}