From 24f80f14af50872c2294bce96da97492ca41f72f Mon Sep 17 00:00:00 2001 From: Paul Elder Date: Fri, 16 Jul 2021 18:38:44 +0900 Subject: android: metadata: Add hasEntry and entryContains Add convenience functions for checking if an entry is present in a CameraMetadata instance, and to check if an array entry includes a specific value. Signed-off-by: Paul Elder Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/android/camera_metadata.cpp | 20 ++++++++++++++++++++ src/android/camera_metadata.h | 4 ++++ 2 files changed, 24 insertions(+) (limited to 'src') diff --git a/src/android/camera_metadata.cpp b/src/android/camera_metadata.cpp index 3fc7cf27..075b6a22 100644 --- a/src/android/camera_metadata.cpp +++ b/src/android/camera_metadata.cpp @@ -121,6 +121,26 @@ bool CameraMetadata::resize(size_t count, size_t size) return true; } +template<> bool CameraMetadata::entryContains(uint32_t tag, uint8_t value) const +{ + camera_metadata_ro_entry_t entry; + if (!getEntry(tag, &entry)) + return false; + + for (unsigned int i = 0; i < entry.count; i++) { + if (entry.data.u8[i] == value) + return true; + } + + return false; +} + +bool CameraMetadata::hasEntry(uint32_t tag) const +{ + camera_metadata_ro_entry_t entry; + return getEntry(tag, &entry); +} + bool CameraMetadata::addEntry(uint32_t tag, const void *data, size_t count, size_t elementSize) { diff --git a/src/android/camera_metadata.h b/src/android/camera_metadata.h index 3b7c9e24..03b3e701 100644 --- a/src/android/camera_metadata.h +++ b/src/android/camera_metadata.h @@ -29,6 +29,10 @@ public: bool isValid() const { return valid_; } bool getEntry(uint32_t tag, camera_metadata_ro_entry_t *entry) const; + template bool entryContains(uint32_t tag, T value) const; + + bool hasEntry(uint32_t tag) const; + template> * = nullptr> bool addEntry(uint32_t tag, const T &data) -- cgit v1.2.1