From patchwork Mon Jun 15 15:51:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 4039 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2B712603C4 for ; Mon, 15 Jun 2020 17:51:54 +0200 (CEST) X-Halon-ID: 1d518b12-af20-11ea-8fb8-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 1d518b12-af20-11ea-8fb8-005056917f90; Mon, 15 Jun 2020 17:51:52 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 15 Jun 2020 17:51:43 +0200 Message-Id: <20200615155143.2609284-1-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3] qcam: dng_writer: Record creation time in the EXIF directory 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: , X-List-Received-Date: Mon, 15 Jun 2020 15:51:54 -0000 If the EXIF directory is empty due to no metadata being available tools such as tiffinfo complains that the directory is malformed. TIFFFetchDirectory: Sanity check on directory count failed, this is probably not a valid IFD offset. TIFFReadCustomDirectory: Failed to read custom directory at offset 0. Always record the creation time in the EXIF directory instead of adding complexity to skip creating the EXIF directory if there is no metadata to record. This ensures there are at least some entries in the EXIF directory and that makes tiffinfo happy. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- * Changes since v1 - Also set EXIFTAG_DATETIMEORIGINAL * Changes since v2 - Add todo to not forget to add OffsetTimeOriginal and OffsetTimeDigitized once libtff learns about them. --- src/qcam/dng_writer.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/qcam/dng_writer.cpp b/src/qcam/dng_writer.cpp index 8470908816e3e408..d5667c863cada250 100644 --- a/src/qcam/dng_writer.cpp +++ b/src/qcam/dng_writer.cpp @@ -427,6 +427,23 @@ int DNGWriter::write(const char *filename, const Camera *camera, /* Create a new IFD for the EXIF data and fill it. */ TIFFCreateEXIFDirectory(tif); + /* Store creation time. */ + time_t rawtime; + struct tm *timeinfo; + char strTime[20]; + + time(&rawtime); + timeinfo = localtime(&rawtime); + strftime(strTime, 20, "%Y:%m:%d %H:%M:%S", timeinfo); + + /* + * \todo Handle timezone information by setting OffsetTimeOriginal and + * OffsetTimeDigitized once libtiff catches up to the specification and + * have EXIFTAG_ defines to handle them. + */ + TIFFSetField(tif, EXIFTAG_DATETIMEORIGINAL, strTime); + TIFFSetField(tif, EXIFTAG_DATETIMEDIGITIZED, strTime); + if (metadata.contains(controls::AnalogueGain)) { float gain = metadata.get(controls::AnalogueGain); uint16_t iso = std::min(std::max(gain * 100, 0.0f), 65535.0f);