From patchwork Wed Sep 9 15:32:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 9556 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 36569BDB1C for ; Wed, 9 Sep 2020 15:32:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AFED662C30; Wed, 9 Sep 2020 17:32:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="K+NQQRjF"; dkim-atps=neutral Received: from mail.uajain.com (static.126.159.217.95.clients.your-server.de [95.217.159.126]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AC80560534 for ; Wed, 9 Sep 2020 17:32:12 +0200 (CEST) From: Umang Jain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=uajain.com; s=mail; t=1599665531; bh=K8zEOPxYCxYGuLx+5Rn9EKmqM6HHzhGL9LVb30Edk5s=; h=From:To:Cc:Subject; b=K+NQQRjFzeKD5JcJmqtCji1kQdD35JIv3sM0JAsXljB0IFymrs+R8ImyuKpThH39u z0M5zrVafVrazXnahCNnoZBSSEn7EGYSkxuy637d5pcURXk8jeLL/+F1tUwif0kUoU QeepaLliHn3FC4BoOOh/8jYefDWPUsRP0qvqtl6bexWh9uzGOEP5kYWQ7H3tnkbq93 qNtRArT1POmDnigzCsPeKVs+GvgGAx4d8WWoPGj3CPynmYSD63okrKYbryik/sHhPt T+z5U/OZeug97LYscqHs97oSvSyLXGUT/wLzbjY4cbUljJ08HXWjRnWhenU0nsWnvM z2LhUTHOoj1ow== To: libcamera-devel@lists.libcamera.org Date: Wed, 9 Sep 2020 21:02:06 +0530 Message-Id: <20200909153206.7700-1-email@uajain.com> Mime-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH] android: jpeg: exif: Set timezone information X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Get timestamp information from the timestamp, although the resolution for EXIF_TAG_TIME_ZONE_OFFSET is fairly limtied (per-hour only). Experimentation with 'exiftool', commandline utility to read/write exif metadata on images, resulted in rounding off the hours if the minutes came out to >= 30. Hence, the behaviour is inspired from exiftool itself. For e.g., Timezone Tag's value +1015 => 10 +0945 => 10 -1145 => -12 Signed-off-by: Umang Jain --- src/android/jpeg/exif.cpp | 30 ++++++++++++++++++++++++++++++ src/android/jpeg/exif.h | 1 + 2 files changed, 31 insertions(+) diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp index 031f5f4..d8b4537 100644 --- a/src/android/jpeg/exif.cpp +++ b/src/android/jpeg/exif.cpp @@ -135,6 +135,16 @@ void Exif::setShort(ExifIfd ifd, ExifTag tag, uint16_t item) exif_entry_unref(entry); } +void Exif::setSShort(ExifIfd ifd, ExifTag tag, int16_t item) +{ + ExifEntry *entry = createEntry(ifd, tag); + if (!entry) + return; + + exif_set_sshort(entry->data, EXIF_BYTE_ORDER_INTEL, item); + exif_entry_unref(entry); +} + void Exif::setLong(ExifIfd ifd, ExifTag tag, uint32_t item) { ExifEntry *entry = createEntry(ifd, tag); @@ -194,6 +204,26 @@ void Exif::setTimestamp(time_t timestamp) setString(EXIF_IFD_0, EXIF_TAG_DATE_TIME, EXIF_FORMAT_ASCII, ts); setString(EXIF_IFD_EXIF, EXIF_TAG_DATE_TIME_ORIGINAL, EXIF_FORMAT_ASCII, ts); setString(EXIF_IFD_EXIF, EXIF_TAG_DATE_TIME_DIGITIZED, EXIF_FORMAT_ASCII, ts); + + /* If possible, query and set timezone information via + * EXIF_TAG_TIME_ZONE_OFFSET. There is only per-hour resolution for tag + * hence, round up hours if minutes >= 30. + */ + char tz[6]; + int r = std::strftime(tz, sizeof(tz), "%z", std::localtime(×tamp)); + if (r > 0) { + int16_t timezone = atoi(tz); + int16_t hour = timezone / 100; + int16_t min = abs(timezone) - (abs(hour) * 100); + + if (tz[0] == '-' && min >= 30) + hour--; + else if (min >= 30) + hour++; + + /* \todo Check if EXIF IFD is correct here or not. */ + setSShort(EXIF_IFD_EXIF, EXIF_TAG_TIME_ZONE_OFFSET, hour); + } } void Exif::setOrientation(int orientation) diff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h index 622de4c..4817815 100644 --- a/src/android/jpeg/exif.h +++ b/src/android/jpeg/exif.h @@ -37,6 +37,7 @@ private: unsigned long components, unsigned int size); void setShort(ExifIfd ifd, ExifTag tag, uint16_t item); + void setSShort(ExifIfd ifd, ExifTag tag, int16_t item); void setLong(ExifIfd ifd, ExifTag tag, uint32_t item); void setString(ExifIfd ifd, ExifTag tag, ExifFormat format, const std::string &item);