From 111158df594cd8caafc05b5de69744ca03df09b0 Mon Sep 17 00:00:00 2001 From: dukesook Date: Tue, 26 Mar 2024 11:18:52 -0600 Subject: [PATCH] removed struct. in progress: get_uuid() --- libheif/box.cc | 13 ++++++++ libheif/box.h | 3 ++ libheif/heif_properties.cc | 63 +++++++++++++++++++++++++++++++++----- libheif/heif_properties.h | 31 ++++++++++++++----- 4 files changed, 96 insertions(+), 14 deletions(-) diff --git a/libheif/box.cc b/libheif/box.cc index f79df7aecfb..1db9ce4d7d6 100644 --- a/libheif/box.cc +++ b/libheif/box.cc @@ -568,6 +568,10 @@ Error Box::read(BitstreamRange& range, std::shared_ptr* result) box = std::make_shared(); break; + case fourcc("uuid"): + box = std::make_shared(); + break; + case fourcc("jpgC"): box = std::make_shared(); break; @@ -3109,5 +3113,14 @@ Error Box_uuid::write(StreamWriter& writer) const return Error::Ok; } +Error Box_uuid::parse(BitstreamRange& range) +{ + printf("***********Box_uuid::parse()***************\n"); + size_t nBytes = range.get_remaining_bytes(); + printf("remaining: %lu\n", nBytes); + m_uuid_data.resize(nBytes); + range.read(m_uuid_data.data(), nBytes); + return Error::Ok; +} diff --git a/libheif/box.h b/libheif/box.h index ff59615f44c..15229241da5 100644 --- a/libheif/box.h +++ b/libheif/box.h @@ -1083,6 +1083,9 @@ class Box_uuid : public Box void set_uuid_data(const std::vector& uuid_data) { m_uuid_data = uuid_data; } +protected: + Error parse(BitstreamRange& range) override; + private: std::vector m_uuid_data; }; diff --git a/libheif/heif_properties.cc b/libheif/heif_properties.cc index d962da52224..a67698ec7d6 100644 --- a/libheif/heif_properties.cc +++ b/libheif/heif_properties.cc @@ -303,19 +303,20 @@ void heif_property_user_description_release(struct heif_property_user_descriptio struct heif_error heif_item_add_property_uuid(const struct heif_context* context, heif_item_id itemId, - const struct heif_property_uuid* uuid, + uint8_t* uuid_type, + uint8_t* data, size_t size, heif_property_id* out_propertyId) { - if (!context || !uuid || !uuid->data) { + if (!context || !uuid_type || !data) { return {heif_error_Usage_error, heif_suberror_Null_pointer_argument, "NULL argument passed in"}; } - std::vector data(static_cast(uuid->data), static_cast(uuid->data) + uuid->size); - std::vector uuid_type(uuid->uuid_type, uuid->uuid_type + 16); + std::vector data_vector(data, data + size); + std::vector uuid_type_vector(uuid_type, uuid_type + 16); auto uuid_box = std::make_shared(); - uuid_box->set_uuid_type(uuid_type); - uuid_box->set_uuid_data(data); + uuid_box->set_uuid_type(uuid_type_vector); + uuid_box->set_uuid_data(data_vector); heif_property_id id = context->context->add_property(itemId, uuid_box, false); @@ -324,4 +325,52 @@ struct heif_error heif_item_add_property_uuid(const struct heif_context* context } return heif_error_success; -} \ No newline at end of file +} + + +struct heif_error heif_item_get_property_uuid(const struct heif_context* context, + heif_item_id itemId, + heif_property_id propertyId, + const uint8_t** data_out, + size_t* size_out) +{ + if (!context || !data_out || !size_out) { + return {heif_error_Usage_error, heif_suberror_Null_pointer_argument, "NULL argument passed in"}; + } + + auto file = context->context->get_heif_file(); + + std::vector> properties; + Error err = file->get_properties(itemId, properties); + if (err) { + return err.error_struct(context->context.get()); + } + + if (propertyId - 1 < 0 || propertyId - 1 >= properties.size()) { + return {heif_error_Usage_error, heif_suberror_Invalid_property, "property index out of range"}; + } + + printf("heif-item_get_property_uuid: properties.size(): %lu\n", properties.size()); + for (size_t i = 0; i < properties.size(); i++) { + auto property = properties[i]; + std::string type = property->get_type_string(); + printf(" %lu) type: %s\n", i, type.c_str()); + } + printf("desired propertyId: %lu\n", (long unsigned) propertyId); + int property_index = propertyId - 1; + auto property = properties[property_index]; + Indent indent; + std::string dump = property->dump(indent); + printf("dump: %s\n", dump.c_str()); + auto uuid = std::dynamic_pointer_cast(property); + if (!uuid) { + return {heif_error_Usage_error, heif_suberror_Invalid_property, "Dynamic cast failed"}; + } + + *data_out = uuid->get_uuid_data().data(); + *size_out = uuid->get_uuid_data().size(); + + return heif_error_success; +} + + diff --git a/libheif/heif_properties.h b/libheif/heif_properties.h index e2bffe4f7a0..1e4230f098b 100644 --- a/libheif/heif_properties.h +++ b/libheif/heif_properties.h @@ -132,18 +132,35 @@ void heif_item_get_property_transform_crop_borders(const struct heif_context* co int image_width, int image_height, int* left, int* top, int* right, int* bottom); -struct heif_property_uuid -{ - void* data; - size_t size; - uint8_t uuid_type[16]; // The Extended Type -}; +/** + * @param context + * @param itemId The item to which the property should be added. + * @param uuid_type Identifies the type of UUID and how to parse the data. Assumed to be 16 bytes long. + * @param data + * @param size the size of the data + * @param out_propertyId + * @return whether the call succeeded, or there was an error + * + +*/ LIBHEIF_API struct heif_error heif_item_add_property_uuid(const struct heif_context* context, heif_item_id itemId, - const struct heif_property_uuid* uuid, + uint8_t* uuid_type, + uint8_t* data, size_t size, heif_property_id* out_propertyId); + +/** + * +*/ +LIBHEIF_API +struct heif_error heif_item_get_property_uuid(const struct heif_context* context, + heif_item_id itemId, + heif_property_id propertyId, + const uint8_t** data_out, + size_t* size_out); + #ifdef __cplusplus } #endif