{"id":9550,"url":"https://patchwork.libcamera.org/api/1.1/patches/9550/?format=json","web_url":"https://patchwork.libcamera.org/patch/9550/","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":"<20200909111445.2908-3-email@uajain.com>","date":"2020-09-09T11:14:45","name":"[libcamera-devel,v7,2/2] android: jpeg: Support an initial set of EXIF metadata tags","commit_ref":"6f09a619cca412f029c124cff8bbf1647d3d68cf","pull_url":null,"state":"accepted","archived":false,"hash":"9158c4f988045efd33d6e0fb5ba19b5bc83ec066","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/9550/mbox/","series":[{"id":1278,"url":"https://patchwork.libcamera.org/api/1.1/series/1278/?format=json","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/9550/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9550/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 6371EBDB1D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  9 Sep 2020 11:15:01 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 26DDC62D04;\n\tWed,  9 Sep 2020 13:15:01 +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 461AD60534\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  9 Sep 2020 13:14:59 +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=\"lNcrKMwl\"; 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=1599650098; bh=HXfl74Ub4unjnDXzvEXI+JVm7aO40eI9WU8+rENreME=;\n\th=From:To:Cc:Subject:In-Reply-To:References;\n\tb=lNcrKMwlH3wJ8boXcsHed/be07nTsaZSG+ybUrKzGooAZWb/Plp6UodeI51CfnDgi\n\tDvjb/DsPZRoI21a9lukUZVBi8GEbPwjbYJAbCswDQ6rkNUofageDCD3g4iOK5gUDnS\n\tYj2KCRUGS7AzyzpWCJJSXMwuPd2h6XifZHvyWzvhkw7BcRf8JT+ZGp5XRFLQ9CXcp2\n\ts4p2Tq6TvLN9JGT0I+BxKDA874lSeYaHDKr2FqSt86vYUwwQyMM3nWNBjuSGsQGnOz\n\ty5paMea5uDqPRBCUIxbng0ZZX3Aa6HbSDg81fOCliJvzQ2yltHCj0obJPRATCoDv+B\n\tOJnyQgCUPLOwQ==","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  9 Sep 2020 16:44:45 +0530","Message-Id":"<20200909111445.2908-3-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 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>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/android/camera_device.cpp        | 19 ++++++++++-\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            | 50 ++++++++++++++++++++++++++++\n src/android/jpeg/exif.h              |  8 +++++\n 6 files changed, 88 insertions(+), 4 deletions(-)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex de6f86f..9443688 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,23 @@ 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\tif (exif.generate() != 0)\n+\t\t\tLOG(HAL, Error) << \"Failed to generate valid EXIF data\";\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 41ddf48..031f5f4 100644\n--- a/src/android/jpeg/exif.cpp\n+++ b/src/android/jpeg/exif.cpp\n@@ -168,6 +168,56 @@ void Exif::setString(ExifIfd ifd, ExifTag tag, ExifFormat format, const std::str\n \texif_entry_unref(entry);\n }\n \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;\n+\tswitch (orientation) {\n+\tcase 0:\n+\tdefault:\n+\t\tvalue = 1;\n+\t\tbreak;\n+\tcase 90:\n+\t\tvalue = 8;\n+\t\tbreak;\n+\tcase 180:\n+\t\tvalue = 3;\n+\t\tbreak;\n+\tcase 270:\n+\t\tvalue = 6;\n+\t\tbreak;\n+\t}\n+\n+\tsetShort(EXIF_IFD_0, EXIF_TAG_ORIENTATION, value);\n+}\n+\n [[nodiscard]] int Exif::generate()\n {\n \tif (exifData_) {\ndiff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h\nindex 8dfc324..622de4c 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 \t[[nodiscard]] int generate();\n \n","prefixes":["libcamera-devel","v7","2/2"]}