From a7bdb75dbbdc78938a70db4fae01124cc6308102 Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Thu, 12 Oct 2023 16:38:15 +1100 Subject: [PATCH] add support for URI metadata type --- examples/heif_info.cc | 4 ++++ libheif/box.h | 2 ++ libheif/context.cc | 3 +++ libheif/context.h | 1 + libheif/file.cc | 10 ++++++++++ libheif/file.h | 2 ++ libheif/heif.cc | 13 +++++++++++++ libheif/heif.h | 4 ++++ 8 files changed, 39 insertions(+) diff --git a/examples/heif_info.cc b/examples/heif_info.cc index 905611ad06..30d9715ef6 100644 --- a/examples/heif_info.cc +++ b/examples/heif_info.cc @@ -426,10 +426,14 @@ int main(int argc, char** argv) for (int n = 0; n < numMetadata; n++) { std::string itemtype = heif_image_handle_get_metadata_type(handle, ids[n]); std::string contenttype = heif_image_handle_get_metadata_content_type(handle, ids[n]); + std::string item_uri_type = heif_image_handle_get_metadata_item_uri_type(handle, ids[n]); std::string ID{"unknown"}; if (itemtype == "Exif") { ID = itemtype; } + else if (itemtype == "uri ") { + ID = itemtype + "/" + item_uri_type; + } else if (contenttype == "application/rdf+xml") { ID = "XMP"; } diff --git a/libheif/box.h b/libheif/box.h index 4a4d5d24f1..e1f885232f 100644 --- a/libheif/box.h +++ b/libheif/box.h @@ -465,6 +465,8 @@ class Box_infe : public FullBox Error write(StreamWriter& writer) const override; + const std::string& get_item_uri_type() const { return m_item_uri_type; } + protected: Error parse(BitstreamRange& range) override; diff --git a/libheif/context.cc b/libheif/context.cc index f2474005f4..7eee73caaa 100644 --- a/libheif/context.cc +++ b/libheif/context.cc @@ -884,12 +884,15 @@ Error HeifContext::interpret_heif_file() } std::string content_type = m_heif_file->get_content_type(id); + std::string item_uri_type = m_heif_file->get_item_uri_type(id); + // we now assign all kinds of metadata to the image, not only 'Exif' and 'XMP' std::shared_ptr metadata = std::make_shared(); metadata->item_id = id; metadata->item_type = item_type; metadata->content_type = content_type; + metadata->item_uri_type = item_uri_type; Error err = m_heif_file->get_compressed_image_data(id, &(metadata->m_data)); if (err) { diff --git a/libheif/context.h b/libheif/context.h index 528a0b7803..debf599cda 100644 --- a/libheif/context.h +++ b/libheif/context.h @@ -53,6 +53,7 @@ class ImageMetadata heif_item_id item_id; std::string item_type; // e.g. "Exif" std::string content_type; + std::string item_uri_type; std::vector m_data; }; diff --git a/libheif/file.cc b/libheif/file.cc index 178a08e6a0..bed2d9bf8f 100644 --- a/libheif/file.cc +++ b/libheif/file.cc @@ -458,6 +458,16 @@ std::string HeifFile::get_content_type(heif_item_id ID) const return infe_box->get_content_type(); } +std::string HeifFile::get_item_uri_type(heif_item_id ID) const +{ + auto infe_box = get_infe(ID); + if (!infe_box) { + return ""; + } + + return infe_box->get_item_uri_type(); +} + Error HeifFile::get_properties(heif_item_id imageID, std::vector>& properties) const diff --git a/libheif/file.h b/libheif/file.h index cad841f9ba..b6330994c6 100644 --- a/libheif/file.h +++ b/libheif/file.h @@ -77,6 +77,8 @@ class HeifFile std::string get_content_type(heif_item_id ID) const; + std::string get_item_uri_type(heif_item_id ID) const; + Error get_compressed_image_data(heif_item_id ID, std::vector* out_data) const; diff --git a/libheif/heif.cc b/libheif/heif.cc index 826bd6e6fb..6dba476aec 100644 --- a/libheif/heif.cc +++ b/libheif/heif.cc @@ -1533,6 +1533,19 @@ const char* heif_image_handle_get_metadata_content_type(const struct heif_image_ } +const char* heif_image_handle_get_metadata_item_uri_type(const struct heif_image_handle* handle, + heif_item_id metadata_id) +{ + for (auto& metadata : handle->image->get_metadata()) { + if (metadata->item_id == metadata_id) { + return metadata->item_uri_type.c_str(); + } + } + + return nullptr; +} + + size_t heif_image_handle_get_metadata_size(const struct heif_image_handle* handle, heif_item_id metadata_id) { diff --git a/libheif/heif.h b/libheif/heif.h index 8da044bab8..8eea292ece 100644 --- a/libheif/heif.h +++ b/libheif/heif.h @@ -1209,6 +1209,10 @@ struct heif_error heif_image_handle_get_metadata(const struct heif_image_handle* heif_item_id metadata_id, void* out_data); +// Only valid for item type == "uri ", an absolute URI +LIBHEIF_API +const char* heif_image_handle_get_metadata_item_uri_type(const struct heif_image_handle* handle, + heif_item_id metadata_id); // ------------------------- color profiles -------------------------