{"id":9409,"url":"https://patchwork.libcamera.org/api/1.1/patches/9409/?format=json","web_url":"https://patchwork.libcamera.org/patch/9409/","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":"<20200827094930.21662-3-email@uajain.com>","date":"2020-08-27T09:49:57","name":"[libcamera-devel,v3,2/2] android: jpeg: Support a initial set of EXIF metadata tags","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"bc558263bf894e35db95af4f0824ee740e8b08a1","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/9409/mbox/","series":[{"id":1246,"url":"https://patchwork.libcamera.org/api/1.1/series/1246/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1246","date":"2020-08-27T09:49:51","name":"Initial EXIF metadata support","version":3,"mbox":"https://patchwork.libcamera.org/series/1246/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9409/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9409/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 A1FB2BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 27 Aug 2020 09:50:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6EFD0628F3;\n\tThu, 27 Aug 2020 11:50:00 +0200 (CEST)","from o1.b.az.sendgrid.net (o1.b.az.sendgrid.net [208.117.55.133])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A49FF628EE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 27 Aug 2020 11:49:58 +0200 (CEST)","by filterdrecv-p3iad2-56cd58c948-klxrx with SMTP id\n\tfilterdrecv-p3iad2-56cd58c948-klxrx-19-5F4781C5-1F\n\t2020-08-27 09:49:57.457193922 +0000 UTC m=+41470.438757443","from mail.uajain.com (unknown)\n\tby ismtpd0001p1maa1.sendgrid.net (SG) with ESMTP\n\tid 8Hn06XtCS6agBN5D2UumrQ Thu, 27 Aug 2020 09:49:56.971 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=uajain.com header.i=@uajain.com\n\theader.b=\"mqpmjfck\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com;\n\th=from:subject:in-reply-to:references:mime-version:to:cc:\n\tcontent-transfer-encoding:content-type;\n\ts=s1; bh=CL8M3ZR4RQZWTlKSzmcm0YXa7L4iD7mVLRwY/N4znJ0=;\n\tb=mqpmjfck9axoH+Cegh0itPuhi8Co11YVd9NGZD0ZSt2/Gza8CRNXu/YpvMKmhQwykuxJ\n\tJLle0MoM4v6TUhipa1H/B7DC1rGbCp5k6+M0jVw+V/YRg+kIMtFuMGqsgm6/b/LiSKIdET\n\t+LGbdvkwEJKGj7LeCswOHmG1e6tEeyipA=","From":"Umang Jain <email@uajain.com>","Date":"Thu, 27 Aug 2020 09:49:57 +0000 (UTC)","Message-Id":"<20200827094930.21662-3-email@uajain.com>","In-Reply-To":"<20200827094930.21662-1-email@uajain.com>","References":"<20200827094930.21662-1-email@uajain.com>","Mime-Version":"1.0","X-SG-EID":"1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcZj5z9XHfwy1Ge6f/0y1LY4dIL4p7iA32g13uWqIA7L6xaE+fSo7Pg77wK9esz5zfIoUdJv/J3ceCl4YzUM+JjybTITjGsTJ58YoPRLkP33oSLVxCuMwNW2P9lRTt5qDFFSYKmxCzDep7d1MEl9zqx59AOApAuYBssEEHMQyjKA7tYZH8UzZuFv6fwTOm3WB0FPF9cAWQ45SfkdLPC1/l+g==","To":"libcamera-devel@lists.libcamera.org","Subject":"[libcamera-devel] [PATCH v3 2/2] android: jpeg: Support a 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":"From: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nCreate 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\nat 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>\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            | 62 ++++++++++++++++++++++++++++\n src/android/jpeg/exif.h              |  9 ++++\n 6 files changed, 100 insertions(+), 4 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..58bc1ca 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@@ -214,5 +215,11 @@ int EncoderLibJpeg::encode(const FrameBuffer *source,\n \n \tjpeg_finish_compress(&compress_);\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 \treturn size;\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 ce9c69b..56733fd 100644\n--- a/src/android/jpeg/exif.cpp\n+++ b/src/android/jpeg/exif.cpp\n@@ -157,6 +157,68 @@ int Exif::setString(ExifIfd ifd, ExifTag tag, ExifFormat format, const std::stri\n \treturn 0;\n }\n \n+int Exif::setMake(const std::string &make)\n+{\n+\treturn setString(EXIF_IFD_0, EXIF_TAG_MAKE, EXIF_FORMAT_ASCII, make);\n+}\n+\n+int Exif::setModel(const std::string &model)\n+{\n+\treturn setString(EXIF_IFD_0, EXIF_TAG_MODEL, EXIF_FORMAT_ASCII, model);\n+}\n+\n+int Exif::setSize(Size size)\n+{\n+\tsetShort(EXIF_IFD_0, EXIF_TAG_IMAGE_LENGTH, size.height);\n+\tsetLong(EXIF_IFD_EXIF, EXIF_TAG_PIXEL_Y_DIMENSION, size.height);\n+\n+\tsetShort(EXIF_IFD_0, EXIF_TAG_IMAGE_WIDTH, size.width);\n+\tsetLong(EXIF_IFD_EXIF, EXIF_TAG_PIXEL_X_DIMENSION, size.width);\n+\n+\treturn 0;\n+}\n+\n+int Exif::setTimestamp(const 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+\tint ret = -1;\n+\n+\tret = setString(EXIF_IFD_0, EXIF_TAG_DATE_TIME, EXIF_FORMAT_ASCII, ts);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\tret = setString(EXIF_IFD_EXIF, EXIF_TAG_DATE_TIME_ORIGINAL, EXIF_FORMAT_ASCII, ts);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\tret = setString(EXIF_IFD_EXIF, EXIF_TAG_DATE_TIME_DIGITIZED, EXIF_FORMAT_ASCII, ts);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\treturn ret;\n+}\n+\n+int 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+\treturn setShort(EXIF_IFD_0, EXIF_TAG_ORIENTATION, value);\n+}\n+\n int Exif::generate()\n {\n \tif (exif_data_) {\ndiff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h\nindex 3a132ba..102b07c 100644\n--- a/src/android/jpeg/exif.h\n+++ b/src/android/jpeg/exif.h\n@@ -9,8 +9,10 @@\n \n #include <libexif/exif-data.h>\n \n+#include <libcamera/geometry.h>\n #include <libcamera/span.h>\n \n+#include <ctime>\n #include <string>\n \n class Exif\n@@ -19,6 +21,13 @@ public:\n \tExif();\n \t~Exif();\n \n+\tint setMake(const std::string &make);\n+\tint setModel(const std::string &model);\n+\n+\tint setOrientation(int orientation);\n+\tint setSize(libcamera::Size size);\n+\tint setTimestamp(const time_t timestamp);\n+\n \tlibcamera::Span<const uint8_t> data() const { return { exif_data_, size_ }; }\n \tint generate();\n \n","prefixes":["libcamera-devel","v3","2/2"]}