[libcamera-devel] [RFC PATCH v4 02/21] android: metadata: Add hasEntry and entryContains
Jacopo Mondi
jacopo at jmondi.org
Sat Jul 17 11:49:39 CEST 2021
Hi Paul,
On Fri, Jul 16, 2021 at 07:56:12PM +0900, Paul Elder wrote:
> Add convenience functions for checking if the an entry is present in a
s/if the an/if an/
> CameraMetadata instance, and to check if an array entry includes a
> specific value.
>
Nice
> Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
>
> ---
> New in v4
> ---
> src/android/camera_metadata.cpp | 21 +++++++++++++++++++++
> src/android/camera_metadata.h | 4 ++++
> 2 files changed, 25 insertions(+)
>
> diff --git a/src/android/camera_metadata.cpp b/src/android/camera_metadata.cpp
> index 3fc7cf27..47199b68 100644
> --- a/src/android/camera_metadata.cpp
> +++ b/src/android/camera_metadata.cpp
> @@ -121,6 +121,27 @@ bool CameraMetadata::resize(size_t count, size_t size)
> return true;
> }
>
> +template<> bool CameraMetadata::entryContains<uint8_t>(uint32_t tag, uint8_t value) const
> +{
> + camera_metadata_ro_entry_t entry;
> +
> + if (!getEntry(tag, &entry))
> + return false;
> +
I would specialize only the part here below with spcializations of
private
template<typename T>
bool entryContainsOne(const camera_metadata_ro_entry_t &entry, T value) const;
To be specialized in the C++ file as
template<>
bool entryContainsOne<uint8_t>(const camera_metadata_ro_entry_t &entry,
uint8_t value) const
{
for (unsigned int i = 0; i < entry.count; i++) {
if (entry.data.u8[i] == value)
return true;
}
return false;
}
template<>
bool entryContainsOne<int32_t>(const camera_metadata_ro_entry_t &entry,
int32_t value) const
{
for (unsigned int i = 0; i < entry.count; i++) {
if (entry.data.i32[i] == value)
return true;
}
return false;
}
...
And keep the main function in-line as
template<typename T>
bool entryContains(uint32_t tag, T value) const
{
camera_metadata_ro_entry_t entry;
if (!getEntry(tag, &entry))
return false;
return entryContainsOne<T>(entry, value);
}
Disclaimer: not compiled
Is it worth it in your opinion ?
> + for (unsigned int i = 0; i < entry.count; i++)
> + if (entry.data.u8[i] == value)
> + return true;
braces please if the block is two levels nested
> +
> + return false;
> +}
> +
> +
Double empy line
> +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<typename T> bool entryContains(uint32_t tag, T value) const;
> +
> + bool hasEntry(uint32_t tag) const;
> +
> template<typename T,
> std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>
> bool addEntry(uint32_t tag, const T &data)
> --
> 2.27.0
>
More information about the libcamera-devel
mailing list