[{"id":12153,"web_url":"https://patchwork.libcamera.org/comment/12153/","msgid":"<20200826004025.GA2440@pendragon.ideasonboard.com>","date":"2020-08-26T00:40:25","subject":"Re: [libcamera-devel] [PATCH v2 2/2] android: jpeg: Support a\n\tinitial set of EXIF metadata tags","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Umang,\n\nThank you for the patch.\n\nOn Tue, Aug 25, 2020 at 08:10:53PM +0000, Umang Jain wrote:\n> From: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> Add a Exif data placeholder inside CameraStream, to populate it\n> accordingly to the stream properties (size, orientation etc).\n> Static EXIF properties (such as make, model, size, orientation)\n> can be configured once when the stream is being configured.\n> Per-frame related metadata (such as timestamp) needs to set\n> just before encoding preferably in CameraDevice::requestComplete().\n\nAs explained in the review of 1/2, I don't think we can reuse the EXIF\ngenerator. Sorry :-(\n\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Signed-off-by: Umang Jain <email@uajain.com>\n> ---\n>  src/android/camera_device.cpp        | 22 +++++++++-\n>  src/android/camera_device.h          |  2 +\n>  src/android/jpeg/encoder.h           |  5 ++-\n>  src/android/jpeg/encoder_libjpeg.cpp |  9 +++-\n>  src/android/jpeg/encoder_libjpeg.h   |  3 +-\n>  src/android/jpeg/exif.cpp            | 66 ++++++++++++++++++++++++++++\n>  src/android/jpeg/exif.h              |  9 ++++\n>  7 files changed, 112 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index de6f86f..8789a9e 100644\n> --- a/src/android/camera_device.cpp\n> +++ b/src/android/camera_device.cpp\n> @@ -1245,6 +1245,17 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)\n>  \t\t\t\t\t<< \"Failed to configure encoder\";\n>  \t\t\t\treturn ret;\n>  \t\t\t}\n> +\n> +\t\t\t/*\n> +\t\t\t * Set EXIF metadata for various tags.\n> +\t\t\t * \\todo Discuss setMake String, maybe vendor ID?\n> +\t\t\t * KB suggested to leave it to \"libcamera\" for now.\n> +\t\t\t * setModel should use the 'model' property of the camera.\n\nActually this should use the vendor and model of the end-product. We\nwill need to load this from a platform config/data file. It can stay\nas-is for now.\n\n> +\t\t\t */\n> +\t\t\tcameraStream->exif.setMake(\"libcamera\");\n> +\t\t\tcameraStream->exif.setModel(\"cameraModel\");\n> +\t\t\tcameraStream->exif.setOrientation(orientation_);\n> +\t\t\tcameraStream->exif.setSize(cfg.size);\n>  \t\t}\n>  \t}\n>  \n> @@ -1434,7 +1445,16 @@ 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/*\n> +\t\t * We set the frame's EXIF timestamp as the time of encode. Since the\n\n\"the\" ? the precision ?\n\n> +\t\t * we need for EXIF is only one second, it is good enough.\n> +\t\t */\n> +\t\tstruct timespec tp;\n> +\t\tclock_gettime(CLOCK_REALTIME, &tp);\n> +\t\tcameraStream->exif.setTimestamp(tp.tv_sec);\n\nThis can be simplified to\n\n\t\tcameraStream->exif.setTimestamp(std::time(nullptr));\n\n> +\t\tSpan<uint8_t> exif_data = cameraStream->exif.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;\n> diff --git a/src/android/camera_device.h b/src/android/camera_device.h\n> index 3934f19..3e8a119 100644\n> --- a/src/android/camera_device.h\n> +++ b/src/android/camera_device.h\n> @@ -42,6 +42,8 @@ struct CameraStream {\n>  \tlibcamera::Size size;\n>  \n>  \tEncoder *jpeg;\n> +\n> +\tExif exif;\n>  };\n>  \n>  class CameraDevice : protected libcamera::Loggable\n> diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h\n> index f9eb88e..969f291 100644\n> --- a/src/android/jpeg/encoder.h\n> +++ b/src/android/jpeg/encoder.h\n> @@ -7,6 +7,8 @@\n>  #ifndef __ANDROID_JPEG_ENCODER_H__\n>  #define __ANDROID_JPEG_ENCODER_H__\n>  \n> +#include \"exif.h\"\n> +\n\nI don't think you need to include exif.h here.\n\n>  #include <libcamera/buffer.h>\n>  #include <libcamera/span.h>\n>  #include <libcamera/stream.h>\n> @@ -18,7 +20,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<uint8_t> &exif_data) = 0;\n\nThe variable should be named exitData, or just exif.\n\n>  };\n>  \n>  #endif /* __ANDROID_JPEG_ENCODER_H__ */\n> diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp\n> index 977538c..87464a4 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<uint8_t> &exif_data)\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 (exif_data.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 *>(exif_data.data()),\n> +\t\t\t\t  exif_data.size());\n> +\n>  \treturn size;\n>  }\n> diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h\n> index aed081a..88bc6e0 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<uint8_t> &exif_data) override;\n>  \n>  private:\n>  \tvoid compressRGB(const libcamera::MappedBuffer *frame);\n> diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp\n> index f6a9f5c..d2ef14e 100644\n> --- a/src/android/jpeg/exif.cpp\n> +++ b/src/android/jpeg/exif.cpp\n> @@ -160,6 +160,72 @@ 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[40];\n> +\tsize_t len = std::strftime(str, sizeof(str), \"%c %Z\",\n> +\t\t\t\t   std::localtime(&timestamp));\n\nThe EXIF specification requires dates to be in the \"YYYY:MM:DD HH:MM:SS\"\nformat. str can be shortened to 20.\n\n> +\tstd::string ts(str);\n> +\tint ret = -1;\n> +\n> +\tif (len > 0) {\n\nThis can't happen if str is large enough, so I'd skip this check.\n\n> +\t\tret = setString(EXIF_IFD_0, EXIF_TAG_DATE_TIME, EXIF_FORMAT_ASCII, ts);\n> +\t\tif (ret < 0)\n> +\t\t\treturn ret;\n> +\n> +\t\tret = setString(EXIF_IFD_EXIF, EXIF_TAG_DATE_TIME_ORIGINAL, EXIF_FORMAT_ASCII, ts);\n> +\t\tif (ret < 0)\n> +\t\t\treturn ret;\n> +\n> +\t\tret = setString(EXIF_IFD_EXIF, EXIF_TAG_DATE_TIME_DIGITIZED, EXIF_FORMAT_ASCII, ts);\n> +\t\tif (ret < 0)\n> +\t\t\treturn ret;\n> +\t}\n> +\n> +\treturn ret;\n> +}\n> +\n> +\n\nExtra blank line.\n\n> +int Exif::setOrientation(int orientation)\n> +{\n> +\t/* Orientation's tag value computed similar to Chrome HAL. */\n\nI don't think the Chrome OS HAL is relevant :-) What's relevant is\nturning the libcamera orientation into an EXIF 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>  Span<uint8_t> Exif::generate()\n>  {\n>  \tif (exif_data_) {\n> diff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h\n> index 7df83c7..6cca578 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> @@ -24,6 +26,13 @@ public:\n>  \tint setString(ExifIfd ifd, ExifTag tag, ExifFormat format, const std::string &item);\n>  \tint setRational(ExifIfd ifd, ExifTag tag, uint32_t numerator, uint32_t denominator);\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<uint8_t> generate();\n>  \tunsigned char *data() const { return exif_data_; }\n>  \tunsigned int size() const { return size_; }","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 B99A2BD87E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 26 Aug 2020 00:40:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4512362882;\n\tWed, 26 Aug 2020 02:40:47 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9DF8C616B1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Aug 2020 02:40:45 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 29A0153C;\n\tWed, 26 Aug 2020 02:40:45 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"icOlCk6z\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1598402445;\n\tbh=h7ScrPcQdzc1SwKl0Mql943vRdmSRVzVqZtm0PcK8mE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=icOlCk6zujuk/b9Vc+tJU40hSH4YsQ/8ZgxKIjc1H39qyM1ebQmGol05TyJ08mqQ/\n\t6JfYwWRrtoG0k1OZz+2b5vCGU6omGrP+EqUYVRodGNqQYhxYJ3gD5qEBtMk6xmtN7U\n\tC1QRZgjGZJ3EvSm6fZn4KrqwBgrZ4JYJMNGiZrOo=","Date":"Wed, 26 Aug 2020 03:40:25 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Umang Jain <email@uajain.com>","Message-ID":"<20200826004025.GA2440@pendragon.ideasonboard.com>","References":"<20200825201048.13608-1-email@uajain.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200825201048.13608-1-email@uajain.com>","Subject":"Re: [libcamera-devel] [PATCH v2 2/2] android: jpeg: Support a\n\tinitial set 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>","Cc":"libcamera-devel@lists.libcamera.org","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>"}},{"id":12157,"web_url":"https://patchwork.libcamera.org/comment/12157/","msgid":"<f0424667-14d0-5171-780d-9ca2e68df94d@ideasonboard.com>","date":"2020-08-26T08:11:55","subject":"Re: [libcamera-devel] [PATCH v2 2/2] android: jpeg: Support a\n\tinitial set of EXIF metadata tags","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Umang, Laurent,\n\nOn 26/08/2020 01:40, Laurent Pinchart wrote:\n> Hi Umang,\n> \n> Thank you for the patch.\n> \n> On Tue, Aug 25, 2020 at 08:10:53PM +0000, Umang Jain wrote:\n>> From: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>>\n>> Add a Exif data placeholder inside CameraStream, to populate it\n>> accordingly to the stream properties (size, orientation etc).\n>> Static EXIF properties (such as make, model, size, orientation)\n>> can be configured once when the stream is being configured.\n>> Per-frame related metadata (such as timestamp) needs to set\n>> just before encoding preferably in CameraDevice::requestComplete().\n> \n> As explained in the review of 1/2, I don't think we can reuse the EXIF\n> generator. Sorry :-(\n\nI'm not yet convinced, but if you really want it to be a new object each\ntime that can be done too, and I guess it keeps all the code setting the\nexif in camera_device in one place anyway.\n\n> \n>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>> Signed-off-by: Umang Jain <email@uajain.com>\n>> ---\n>>  src/android/camera_device.cpp        | 22 +++++++++-\n>>  src/android/camera_device.h          |  2 +\n>>  src/android/jpeg/encoder.h           |  5 ++-\n>>  src/android/jpeg/encoder_libjpeg.cpp |  9 +++-\n>>  src/android/jpeg/encoder_libjpeg.h   |  3 +-\n>>  src/android/jpeg/exif.cpp            | 66 ++++++++++++++++++++++++++++\n>>  src/android/jpeg/exif.h              |  9 ++++\n>>  7 files changed, 112 insertions(+), 4 deletions(-)\n>>\n>> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n>> index de6f86f..8789a9e 100644\n>> --- a/src/android/camera_device.cpp\n>> +++ b/src/android/camera_device.cpp\n>> @@ -1245,6 +1245,17 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)\n>>  \t\t\t\t\t<< \"Failed to configure encoder\";\n>>  \t\t\t\treturn ret;\n>>  \t\t\t}\n>> +\n>> +\t\t\t/*\n>> +\t\t\t * Set EXIF metadata for various tags.\n>> +\t\t\t * \\todo Discuss setMake String, maybe vendor ID?\n>> +\t\t\t * KB suggested to leave it to \"libcamera\" for now.\n>> +\t\t\t * setModel should use the 'model' property of the camera.\n> \n> Actually this should use the vendor and model of the end-product. We\n> will need to load this from a platform config/data file. It can stay\n> as-is for now.\n\nHrm, indeed I was overthinking the 'model' property from the pipeline\nhandler.\n\nI think we can adjust this to\n \\todo Set Make and Model from external vendor tags.\n\n\n> \n>> +\t\t\t */\n>> +\t\t\tcameraStream->exif.setMake(\"libcamera\");\n>> +\t\t\tcameraStream->exif.setModel(\"cameraModel\");\n>> +\t\t\tcameraStream->exif.setOrientation(orientation_);\n>> +\t\t\tcameraStream->exif.setSize(cfg.size);\n>>  \t\t}\n>>  \t}\n>>  \n>> @@ -1434,7 +1445,16 @@ 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/*\n>> +\t\t * We set the frame's EXIF timestamp as the time of encode. Since the\n> \n> \"the\" ? the precision ?\n> \n>> +\t\t * we need for EXIF is only one second, it is good enough.\n>> +\t\t */\n>> +\t\tstruct timespec tp;\n>> +\t\tclock_gettime(CLOCK_REALTIME, &tp);\n>> +\t\tcameraStream->exif.setTimestamp(tp.tv_sec);\n> \n> This can be simplified to\n> \n> \t\tcameraStream->exif.setTimestamp(std::time(nullptr));\n> \n>> +\t\tSpan<uint8_t> exif_data = cameraStream->exif.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;\n>> diff --git a/src/android/camera_device.h b/src/android/camera_device.h\n>> index 3934f19..3e8a119 100644\n>> --- a/src/android/camera_device.h\n>> +++ b/src/android/camera_device.h\n>> @@ -42,6 +42,8 @@ struct CameraStream {\n>>  \tlibcamera::Size size;\n>>  \n>>  \tEncoder *jpeg;\n>> +\n>> +\tExif exif;\n>>  };\n>>  \n>>  class CameraDevice : protected libcamera::Loggable\n>> diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h\n>> index f9eb88e..969f291 100644\n>> --- a/src/android/jpeg/encoder.h\n>> +++ b/src/android/jpeg/encoder.h\n>> @@ -7,6 +7,8 @@\n>>  #ifndef __ANDROID_JPEG_ENCODER_H__\n>>  #define __ANDROID_JPEG_ENCODER_H__\n>>  \n>> +#include \"exif.h\"\n>> +\n> \n> I don't think you need to include exif.h here.\n\nIndeed, the benefit of using the Span :-)\n\n> \n>>  #include <libcamera/buffer.h>\n>>  #include <libcamera/span.h>\n>>  #include <libcamera/stream.h>\n>> @@ -18,7 +20,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<uint8_t> &exif_data) = 0;\n> \n> The variable should be named exitData, or just exif.\n> \n>>  };\n>>  \n>>  #endif /* __ANDROID_JPEG_ENCODER_H__ */\n>> diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp\n>> index 977538c..87464a4 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<uint8_t> &exif_data)\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 (exif_data.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 *>(exif_data.data()),\n>> +\t\t\t\t  exif_data.size());\n>> +\n>>  \treturn size;\n>>  }\n>> diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h\n>> index aed081a..88bc6e0 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<uint8_t> &exif_data) override;\n>>  \n>>  private:\n>>  \tvoid compressRGB(const libcamera::MappedBuffer *frame);\n>> diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp\n>> index f6a9f5c..d2ef14e 100644\n>> --- a/src/android/jpeg/exif.cpp\n>> +++ b/src/android/jpeg/exif.cpp\n>> @@ -160,6 +160,72 @@ 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[40];\n>> +\tsize_t len = std::strftime(str, sizeof(str), \"%c %Z\",\n>> +\t\t\t\t   std::localtime(&timestamp));\n> \n> The EXIF specification requires dates to be in the \"YYYY:MM:DD HH:MM:SS\"\n> format. str can be shortened to 20.\n> \n>> +\tstd::string ts(str);\n>> +\tint ret = -1;\n>> +\n>> +\tif (len > 0) {\n> \n> This can't happen if str is large enough, so I'd skip this check.\n> \n>> +\t\tret = setString(EXIF_IFD_0, EXIF_TAG_DATE_TIME, EXIF_FORMAT_ASCII, ts);\n>> +\t\tif (ret < 0)\n>> +\t\t\treturn ret;\n>> +\n>> +\t\tret = setString(EXIF_IFD_EXIF, EXIF_TAG_DATE_TIME_ORIGINAL, EXIF_FORMAT_ASCII, ts);\n>> +\t\tif (ret < 0)\n>> +\t\t\treturn ret;\n>> +\n>> +\t\tret = setString(EXIF_IFD_EXIF, EXIF_TAG_DATE_TIME_DIGITIZED, EXIF_FORMAT_ASCII, ts);\n>> +\t\tif (ret < 0)\n>> +\t\t\treturn ret;\n>> +\t}\n>> +\n>> +\treturn ret;\n>> +}\n>> +\n>> +\n> \n> Extra blank line.\n> \n>> +int Exif::setOrientation(int orientation)\n>> +{\n>> +\t/* Orientation's tag value computed similar to Chrome HAL. */\n> \n> I don't think the Chrome OS HAL is relevant :-) What's relevant is\n> turning the libcamera orientation into an EXIF 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>>  Span<uint8_t> Exif::generate()\n>>  {\n>>  \tif (exif_data_) {\n>> diff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h\n>> index 7df83c7..6cca578 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>> @@ -24,6 +26,13 @@ public:\n>>  \tint setString(ExifIfd ifd, ExifTag tag, ExifFormat format, const std::string &item);\n>>  \tint setRational(ExifIfd ifd, ExifTag tag, uint32_t numerator, uint32_t denominator);\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<uint8_t> generate();\n>>  \tunsigned char *data() const { return exif_data_; }\n>>  \tunsigned int size() const { return size_; }\n>","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 59CDDBD87E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 26 Aug 2020 08:12:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D9CC4628DD;\n\tWed, 26 Aug 2020 10:11:59 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2BC8A6037A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Aug 2020 10:11:58 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9890B53C;\n\tWed, 26 Aug 2020 10:11:57 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"IRpesmL+\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1598429517;\n\tbh=gpkVm68R8RirCXpza1qwrGGyVUXwHiQG3911CDcser8=;\n\th=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=IRpesmL+Q0uw8sr+VmgKDKIpj/paFnGsIWSzXfRVXFSH7iNjWLOmNABGJGqu0ZD8r\n\t34uvfb4n9WuH5/eQqkwv+4E7pim288ewY2U6zCTxHgAu+ddLPXXqKTGq2rTvmlKfPk\n\t/WjAUJxtuUvEArO8/cyUt/+wRrBQP1wi1QMsKFu0=","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tUmang Jain <email@uajain.com>","References":"<20200825201048.13608-1-email@uajain.com>\n\t<20200826004025.GA2440@pendragon.ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tcSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf\n\tKr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8\n\tRXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko\n\tlPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+XoAN0w5Eqo4t6qEVbuettxx55gq\n\t8K8FieAjgjMSxngo/HST8TpFeqI5nVeq0/lqtBRQKumuIqDg+Bkr4L1V/PSB6XgQcOdhtd36\n\tOe9X9dXB8YSNt7VjOcO7BTmFn/Z8r92mSAfHXpb07YJWJosQOQARAQABtDBLaWVyYW4gQmlu\n\tZ2hhbSA8a2llcmFuLmJpbmdoYW1AaWRlYXNvbmJvYXJkLmNvbT6JAlcEEwEK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b/7PRYrZvBsr21EIQoIjXbZxDz/o7z95frkP71EaICttZ6k9q5oxxA5WC6sTXc\n\tMW8zs8avFNuA9VpXt0YupJd2ijtZy2mpZNG02fFVXhIn4G807G7+9mhuC4XG5rKlBBUXTvPU\n\tAfYnB4JBDLmLzBFavQfvonSfbitgXwCG3vS+9HEwAjU30Bar1PEOmIbiAoMzuKeRm2LVpmq4\n\tWZw01QYHU/GUV/zHJSFk","Organization":"Ideas on Board","Message-ID":"<f0424667-14d0-5171-780d-9ca2e68df94d@ideasonboard.com>","Date":"Wed, 26 Aug 2020 09:11:55 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101\n\tThunderbird/68.10.0","MIME-Version":"1.0","In-Reply-To":"<20200826004025.GA2440@pendragon.ideasonboard.com>","Content-Language":"en-GB","Subject":"Re: [libcamera-devel] [PATCH v2 2/2] android: jpeg: Support a\n\tinitial set 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>","Reply-To":"kieran.bingham@ideasonboard.com","Cc":"libcamera-devel@lists.libcamera.org","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>"}}]