{"id":9744,"url":"https://patchwork.libcamera.org/api/1.1/patches/9744/?format=json","web_url":"https://patchwork.libcamera.org/patch/9744/","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":"<20200922162624.32321-1-email@uajain.com>","date":"2020-09-22T16:26:24","name":"[libcamera-devel,RFC,v1] android: jpeg: exif: Set timezone information","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"4e06ae1ecea6f85969b9faf532b94ce6bef51256","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/9744/mbox/","series":[{"id":1310,"url":"https://patchwork.libcamera.org/api/1.1/series/1310/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1310","date":"2020-09-22T16:26:24","name":"[libcamera-devel,RFC,v1] android: jpeg: exif: Set timezone information","version":1,"mbox":"https://patchwork.libcamera.org/series/1310/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9744/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9744/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 DC206C3B5C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 22 Sep 2020 16:26:32 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4961B62FD8;\n\tTue, 22 Sep 2020 18:26:32 +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 D9D936036A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 22 Sep 2020 18:26:30 +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=\"ozmYENnL\"; 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=1600791990; bh=eJcgU5nj7I+fnhaul8s4ybYXiwqWfU+Y2+iTU2aK1Kg=;\n\th=From:To:Cc:Subject:In-Reply-To:References;\n\tb=ozmYENnLaX4jrqV/dq0TSGD5G3et7kaT0hNpTRFcbXufAIdPU3k2XlxX+osHQ5xLK\n\tFKegpG6Fwb6rsU5dnQRRRd7JdDZMJt4BpygVQTzT9Q9RWKpSNEURSF6hHm6IJoa0pc\n\tv5fb2q/Nz67vQvMiVjCWBbn0M2MxFwSZvUpemRt+NFR6SI6u4RFu09AYpuW5ljI3AZ\n\t9WqwTFbJnoZXd0GlScGxyfF5dgNazlSd1QeeEXN8x3l0kTd1MsYFDrOvZHyMfaMnKh\n\tryjEqPpNnQU7Um7OTG+Opl9fNbbLRDMtSUnDt5SkW9DggM2XB8595li5Fdbg4mcedS\n\tAGpyYvx9fyvCw==","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 22 Sep 2020 21:56:24 +0530","Message-Id":"<20200922162624.32321-1-email@uajain.com>","In-Reply-To":"<20200909153206.7700-1-email@uajain.com>","References":"<20200909153206.7700-1-email@uajain.com>","Mime-Version":"1.0","Subject":"[libcamera-devel] [RFC v1 PATCH] android: jpeg: exif: Set timezone\n\tinformation","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":"Get timezone information from the timestamp, although the resolution\nfor EXIF_TAG_TIME_ZONE_OFFSET is fairly limited (per-hour only).\n\nExperimentation with 'exiftool', commandline utility to read/write\nexif metadata on images, resulted in rounding off the hours if the\nminutes came out to >= 30. Hence, the behaviour is inspired from\nexiftool itself. For e.g.,\n\nTimezone      Tag's value\n +1015     =>     10\n +0945     =>     10\n -1145     =>    -12\n\nThe EXIF specification defines three other tags (OffsetTime,\nOffsetTimeOriginal, OffsetTimeDigitized), in the EXIF IFD.\nThese are not supported by libexif yet.\n\nSigned-off-by: Umang Jain <email@uajain.com>\n---\n src/android/jpeg/exif.cpp | 31 +++++++++++++++++++++++++++++++\n src/android/jpeg/exif.h   |  1 +\n 2 files changed, 32 insertions(+)\n\n---\n\nHi Laurent/Kieran,\n\nCan you soft review(or test) this patch to see if anything\nis wrong with it?\nThe reason I am asking, because I cannot make it work :(\nexiftool with a captured frame shows empty Timezone Offset tag as:\n```\nTime Zone Offset                : \n```\n\nexif tool shows nothing.\n\nI made sure a valid value being generated for timezone\noffset in setTimeStamp().\nI also checked the case where it might be preset using\nexif_data_fix and not been able to re-set again.\nBut no, that doesn't seem the problem in my testing.","diff":"diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp\nindex c0dbfcc..9c23cfb 100644\n--- a/src/android/jpeg/exif.cpp\n+++ b/src/android/jpeg/exif.cpp\n@@ -7,6 +7,8 @@\n \n #include \"exif.h\"\n \n+#include <stdlib.h>\n+\n #include \"libcamera/internal/log.h\"\n \n using namespace libcamera;\n@@ -135,6 +137,16 @@ void Exif::setShort(ExifIfd ifd, ExifTag tag, uint16_t item)\n \texif_entry_unref(entry);\n }\n \n+void Exif::setSShort(ExifIfd ifd, ExifTag tag, int16_t item)\n+{\n+\tExifEntry *entry = createEntry(ifd, tag);\n+\tif (!entry)\n+\t\treturn;\n+\n+\texif_set_sshort(entry->data, EXIF_BYTE_ORDER_INTEL, item);\n+\texif_entry_unref(entry);\n+}\n+\n void Exif::setLong(ExifIfd ifd, ExifTag tag, uint32_t item)\n {\n \tExifEntry *entry = createEntry(ifd, tag);\n@@ -196,6 +208,25 @@ void Exif::setTimestamp(time_t timestamp)\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+\t/*\n+\t * If possible, query and set timezone information via\n+\t * EXIF_TAG_TIME_ZONE_OFFSET. There is only per-hour resolution for tag\n+\t * hence, round up hours if minutes >= 30.\n+\t */\n+\tint r = strftime(str, sizeof(str), \"%z\", &tm);\n+\tif (r > 0) {\n+\t\tint16_t timezone = atoi(str);\n+\t\tint16_t hour = timezone / 100;\n+\t\tint16_t min = timezone % 100;;\n+\n+\t\tif (min <= -30)\n+\t\t\thour--;\n+\t\telse if (min >= 30)\n+\t\t\thour++;\n+\n+\t\tsetSShort(EXIF_IFD_0, EXIF_TAG_TIME_ZONE_OFFSET, hour);\n+\t}\n }\n \n void Exif::setOrientation(int orientation)\ndiff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h\nindex f04cefc..9c9cc3b 100644\n--- a/src/android/jpeg/exif.h\n+++ b/src/android/jpeg/exif.h\n@@ -37,6 +37,7 @@ private:\n \t\t\t       unsigned long components, unsigned int size);\n \n \tvoid setShort(ExifIfd ifd, ExifTag tag, uint16_t item);\n+\tvoid setSShort(ExifIfd ifd, ExifTag tag, int16_t item);\n \tvoid setLong(ExifIfd ifd, ExifTag tag, uint32_t item);\n \tvoid setString(ExifIfd ifd, ExifTag tag, ExifFormat format,\n \t\t       const std::string &item);\n","prefixes":["libcamera-devel","RFC","v1"]}