From patchwork Tue Mar 9 08:52:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 11532 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 A1A7BBD1F1 for ; Tue, 9 Mar 2021 08:52:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4DDF968AA4; Tue, 9 Mar 2021 09:52:50 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="YtXTgkCs"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ADC0D68A9C for ; Tue, 9 Mar 2021 09:52:48 +0100 (CET) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 52174E9; Tue, 9 Mar 2021 09:52:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1615279968; bh=wjkwOVoxdfkJ39hk4Ydbh+ClyuFqckZZ7/MZlKLT//c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YtXTgkCs8J9OP+DQyuG2ND/n8J/GFtMUPybw1bLzqs/VSCkdOqbBKDMz6xa4QH7qR ki0J0q085fa7DrsggWzO/ySof71fNAHMTxv9CcJppaRg7tyNVF8UzynA51dAULgp7g iU8BfNCayMH8O9mXyVS/ARICtW56WttANIsjz+64= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Tue, 9 Mar 2021 17:52:32 +0900 Message-Id: <20210309085235.106691-2-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210309085235.106691-1-paul.elder@ideasonboard.com> References: <20210309085235.106691-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/4] android: jpeg: exif: Fix and expand setRational 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" setRational was not working properly for EXIF tags in the GPS IFD due to libexif not supporting those tags in exif_entry_initialize(). Manually specify the size of the EXIF entry to fix this. While at it, add support for setting multiple rationals, as that is a common use case for rational EXIF tags. As Rational types are no longer initialized by libexif directly, the EXIF_TAG_{X,Y}_RESOLUTION exif tags will not have their default values populated. This allows the GPS altitude to be set properly, and is part of the fix to allow the following CTS test to pass: - android.hardware.cts.CameraTest#testJpegExif Signed-off-by: Paul Elder Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- Changes in v2: - use span instead of size + array - expand commit message --- src/android/jpeg/exif.cpp | 15 +++++++++++++-- src/android/jpeg/exif.h | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp index fdd46070..929ac542 100644 --- a/src/android/jpeg/exif.cpp +++ b/src/android/jpeg/exif.cpp @@ -14,6 +14,8 @@ #include #include +#include + #include "libcamera/internal/log.h" #include "libcamera/internal/utils.h" @@ -187,11 +189,20 @@ void Exif::setLong(ExifIfd ifd, ExifTag tag, uint32_t item) void Exif::setRational(ExifIfd ifd, ExifTag tag, ExifRational item) { - ExifEntry *entry = createEntry(ifd, tag); + setRational(ifd, tag, Span{ &item, 1 }); +} + +void Exif::setRational(ExifIfd ifd, ExifTag tag, Span items) +{ + ExifEntry *entry = createEntry(ifd, tag, EXIF_FORMAT_RATIONAL, + items.size(), + items.size() * sizeof(ExifRational)); if (!entry) return; - exif_set_rational(entry->data, order_, item); + for (size_t i = 0; i < items.size(); i++) + exif_set_rational(entry->data + i * sizeof(ExifRational), + order_, items[i]); exif_entry_unref(entry); } diff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h index b0d61402..8aa1b123 100644 --- a/src/android/jpeg/exif.h +++ b/src/android/jpeg/exif.h @@ -89,6 +89,8 @@ private: const std::string &item, StringEncoding encoding = NoEncoding); void setRational(ExifIfd ifd, ExifTag tag, ExifRational item); + void setRational(ExifIfd ifd, ExifTag tag, + libcamera::Span items); std::tuple degreesToDMS(double decimalDegrees); void setGPSDMS(ExifIfd ifd, ExifTag tag, int deg, int min, int sec); From patchwork Tue Mar 9 08:52:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 11533 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 216A6BD1F1 for ; Tue, 9 Mar 2021 08:52:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D6B3768AAA; Tue, 9 Mar 2021 09:52:52 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="RdWEs5zX"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E8E6B6051F for ; Tue, 9 Mar 2021 09:52:50 +0100 (CET) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0C6ACE9; Tue, 9 Mar 2021 09:52:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1615279970; bh=C4hqdlpSYb4dsLo6isL7YvbpbWEdY1MG8rHWrr+uiQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RdWEs5zXiKAqlDPo2GFUx+zoGoczTlNhhmfWUOMiNx61rzkEECaKkfUmFAozRYPfL UeUf9o8N98Ep2mo8+KVwKkUJfOtMPV2FL8mY8E7mw7W/FelCI1Bc+qLo5nEzcQjd3p JstfqjyrjdXdXOB1IcRA1eVYZb8ACo4kUHvh7C1o= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Tue, 9 Mar 2021 17:52:33 +0900 Message-Id: <20210309085235.106691-3-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210309085235.106691-1-paul.elder@ideasonboard.com> References: <20210309085235.106691-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/4] android: jpeg: exif: Simplify setGPSDateTimestamp and setGPSDMS 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" Now that setRational() supports setting multiple rational values, use that in setGPSDateTimestamp and setGPSDMS which previously set every rational manually. Signed-off-by: Paul Elder Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- Changes in v2: - use Span --- src/android/jpeg/exif.cpp | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp index 929ac542..cf9e632a 100644 --- a/src/android/jpeg/exif.cpp +++ b/src/android/jpeg/exif.cpp @@ -347,24 +347,14 @@ void Exif::setGPSDateTimestamp(time_t timestamp) EXIF_FORMAT_ASCII, tsStr); /* Set GPS_TIME_STAMP */ - ExifEntry *entry = - createEntry(EXIF_IFD_GPS, - static_cast(EXIF_TAG_GPS_TIME_STAMP), - EXIF_FORMAT_RATIONAL, 3, 3 * sizeof(ExifRational)); - if (!entry) - return; - ExifRational ts[] = { { static_cast(tm.tm_hour), 1 }, { static_cast(tm.tm_min), 1 }, { static_cast(tm.tm_sec), 1 }, }; - for (int i = 0; i < 3; i++) - exif_set_rational(entry->data + i * sizeof(ExifRational), - order_, ts[i]); - - exif_entry_unref(entry); + setRational(EXIF_IFD_GPS, static_cast(EXIF_TAG_GPS_TIME_STAMP), + Span{ ts, 3 }); } std::tuple Exif::degreesToDMS(double decimalDegrees) @@ -378,22 +368,13 @@ std::tuple Exif::degreesToDMS(double decimalDegrees) void Exif::setGPSDMS(ExifIfd ifd, ExifTag tag, int deg, int min, int sec) { - ExifEntry *entry = createEntry(ifd, tag, EXIF_FORMAT_RATIONAL, 3, - 3 * sizeof(ExifRational)); - if (!entry) - return; - ExifRational coords[] = { { static_cast(deg), 1 }, { static_cast(min), 1 }, { static_cast(sec), 1 }, }; - for (int i = 0; i < 3; i++) - exif_set_rational(entry->data + i * sizeof(ExifRational), - order_, coords[i]); - - exif_entry_unref(entry); + setRational(ifd, tag, Span{ coords, 3 }); } /* From patchwork Tue Mar 9 08:52:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 11534 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 D04E8BD1F1 for ; Tue, 9 Mar 2021 08:52:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8417668AA8; Tue, 9 Mar 2021 09:52:54 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tdibM1Xt"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6597468AA8 for ; Tue, 9 Mar 2021 09:52:53 +0100 (CET) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 56B54E9; Tue, 9 Mar 2021 09:52:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1615279973; bh=2NWnuGYHN3lnxeDsUgtdtfmwU59ERSvgp7s+88w3+zs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tdibM1XtEOL26q/sibknbDUHH0QKHFI+tpMT4tJPCJT87Ngsj4iRH2vCaeB19ARnt gDaXZU0kEFpsgTJg13eU0oWl93uPcJM8D/v5MDhDriXwO9avXmaPp/1t58mzShwejL aV1QhT4Cvj63wjwx4/0Qv4sZAyaRh6Bls/hvl1f4= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Tue, 9 Mar 2021 17:52:34 +0900 Message-Id: <20210309085235.106691-4-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210309085235.106691-1-paul.elder@ideasonboard.com> References: <20210309085235.106691-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/4] android: jpeg: exif: Fix setGPSLocation longitude 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" There was a copy-paste error that caused the latitude to be set twice and the longitude never. Fix this. This is part of the fix that allows the following CTS test to pass: - android.hardware.cts.CameraTest#testJpegExif Signed-off-by: Paul Elder Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- No change in v2 --- src/android/jpeg/exif.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp index cf9e632a..628382a9 100644 --- a/src/android/jpeg/exif.cpp +++ b/src/android/jpeg/exif.cpp @@ -395,7 +395,7 @@ void Exif::setGPSLocation(const double *coords) std::tie(deg, min, sec) = degreesToDMS(coords[1]); setString(EXIF_IFD_GPS, static_cast(EXIF_TAG_GPS_LONGITUDE_REF), EXIF_FORMAT_ASCII, deg >= 0 ? "E" : "W"); - setGPSDMS(EXIF_IFD_GPS, static_cast(EXIF_TAG_GPS_LATITUDE), + setGPSDMS(EXIF_IFD_GPS, static_cast(EXIF_TAG_GPS_LONGITUDE), std::abs(deg), min, sec); setByte(EXIF_IFD_GPS, static_cast(EXIF_TAG_GPS_ALTITUDE_REF), From patchwork Tue Mar 9 08:52:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 11535 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 28A9DBD1F1 for ; Tue, 9 Mar 2021 08:52:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E249568A92; Tue, 9 Mar 2021 09:52:56 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="W43/I5rB"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1852E6051F for ; Tue, 9 Mar 2021 09:52:55 +0100 (CET) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AC4B9E9; Tue, 9 Mar 2021 09:52:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1615279974; bh=l1RGlMbdoKHxpVPwWd3MMI2bk7jjinegN9FwaDFYsK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W43/I5rBGB1WMUqUNnt1RKe3atgn9pT9U+VQj/L1ktZ8sFmo11VDB61yZGQCUbtv9 RrKLQDrVlKXHRjJyJCHGwbLN281W6UgUqco1MEdOGVHvB1/PgoZvJpiKr7Tt21f4er CxyI0ZliwMpYZTm8z2AtR3P0xYpn3c3S9+s5bSAE= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Tue, 9 Mar 2021 17:52:35 +0900 Message-Id: <20210309085235.106691-5-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210309085235.106691-1-paul.elder@ideasonboard.com> References: <20210309085235.106691-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/4] android: jpeg: exif: change GPS method encoding from ASCII to NoEncoding 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" According to the EXIF specification, the GPS method should be UNDEFINED, and the first 8 bytes will designate the type. However, CTS expects the first 8 bytes to be part of the data. Remove the 8-byte encoding designator by changing the encoding to NoEncoding to appease CTS. This is part of the fix that allows the following CTS test to pass: - android.hardware.cts.CameraTest#testJpegExif Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- Changes in v2: - keep UNDEFINED instead of changing it to ASCII, and use NoEncoding --- src/android/jpeg/exif.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp index 628382a9..7e47c1ac 100644 --- a/src/android/jpeg/exif.cpp +++ b/src/android/jpeg/exif.cpp @@ -407,7 +407,7 @@ void Exif::setGPSLocation(const double *coords) void Exif::setGPSMethod(const std::string &method) { setString(EXIF_IFD_GPS, static_cast(EXIF_TAG_GPS_PROCESSING_METHOD), - EXIF_FORMAT_UNDEFINED, method, Unicode); + EXIF_FORMAT_UNDEFINED, method, NoEncoding); } void Exif::setOrientation(int orientation)