{"id":9412,"url":"https://patchwork.libcamera.org/api/patches/9412/?format=json","web_url":"https://patchwork.libcamera.org/patch/9412/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20200828065727.9909-3-email@uajain.com>","date":"2020-08-28T06:57:40","name":"[libcamera-devel,v4,2/2] android: jpeg: Support an initial set of EXIF metadata tags","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"6f6bc96d0512cee9a48809b5d8e6f026068f252f","submitter":{"id":1,"url":"https://patchwork.libcamera.org/api/people/1/?format=json","name":"Umang Jain","email":"email@uajain.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/9412/mbox/","series":[{"id":1247,"url":"https://patchwork.libcamera.org/api/series/1247/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1247","date":"2020-08-28T06:57:32","name":"Initial EXIF metadata support","version":4,"mbox":"https://patchwork.libcamera.org/series/1247/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9412/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9412/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 E8B48BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 28 Aug 2020 06:57:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B47526291C;\n\tFri, 28 Aug 2020 08:57:44 +0200 (CEST)","from wrqvntvw.outbound-mail.sendgrid.net\n\t(wrqvntvw.outbound-mail.sendgrid.net [149.72.39.137])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CF47462912\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Aug 2020 08:57:42 +0200 (CEST)","by filterdrecv-p3iad2-787bb5c9bc-cng2v with SMTP id\n\tfilterdrecv-p3iad2-787bb5c9bc-cng2v-18-5F48AAE4-42\n\t2020-08-28 06:57:40.883462972 +0000 UTC m=+46676.936842979","from mail.uajain.com (unknown)\n\tby ismtpd0002p1maa1.sendgrid.net (SG) with ESMTP\n\tid oHLMjahNRPu79rz860xaVA Fri, 28 Aug 2020 06:57:40.343 +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=\"nSdsCNuy\"; 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=WMj9Iz2+s63Udg4LMiUKcsGdbRtB/kwzChwJ9NZre80=;\n\tb=nSdsCNuy1jdZ1hOonczdkhdwGMabnN4s8R4Dg5djgQlkDj81BhVAcuAl+UA8de9DQJne\n\trN6gYcCWdZDVT19FawOo9RC5Snl3DbNP9K1c0n6fEMVxxiURZxv52kLIzv2zljmmuVOKq6\n\t68ELw+Q6Ug6C+bkQElJ5KVKk2iX9MNTAk=","From":"Umang Jain <email@uajain.com>","Date":"Fri, 28 Aug 2020 06:57:40 +0000 (UTC)","Message-Id":"<20200828065727.9909-3-email@uajain.com>","In-Reply-To":"<20200828065727.9909-1-email@uajain.com>","References":"<20200828065727.9909-1-email@uajain.com>","Mime-Version":"1.0","X-SG-EID":"1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcHcG1g99dnq0SJ9KzJgHEPjqPnnLrM0z8UvL0mAr1Vjr0sVVwjEB4jQK4+wCgGGfY8aiyEX4bYwGIf8Scs7Q8hKPxF7EmRYfNmtFMZ5nf1O9zqlkpbCFHnXgtb0SL7fYBqS5AdPIrRezgdFPCK5jbYtNJ3Xt3HbulidUQdXOSDVVedLMZTGYLSxH63230NE939b7HT1CNYOrgL10sX6IIkg==","To":"libcamera-devel@lists.libcamera.org","Subject":"[libcamera-devel] [PATCH v4 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            | 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..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 b49b538..3fbb117 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 (exifData_) {\ndiff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h\nindex 6c10f94..f15afb9 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 { exifData_, size_ }; }\n \tint generate();\n \n","prefixes":["libcamera-devel","v4","2/2"]}