Skip to content

Commit

Permalink
removed struct. in progress: get_uuid()
Browse files Browse the repository at this point in the history
  • Loading branch information
dukesook committed Mar 26, 2024
1 parent 31c32c1 commit 111158d
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 14 deletions.
13 changes: 13 additions & 0 deletions libheif/box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,10 @@ Error Box::read(BitstreamRange& range, std::shared_ptr<Box>* result)
box = std::make_shared<Box_udes>();
break;

case fourcc("uuid"):
box = std::make_shared<Box_uuid>();
break;

case fourcc("jpgC"):
box = std::make_shared<Box_jpgC>();
break;
Expand Down Expand Up @@ -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;
}


3 changes: 3 additions & 0 deletions libheif/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,9 @@ class Box_uuid : public Box

void set_uuid_data(const std::vector<uint8_t>& uuid_data) { m_uuid_data = uuid_data; }

protected:
Error parse(BitstreamRange& range) override;

private:
std::vector<uint8_t> m_uuid_data;
};
Expand Down
63 changes: 56 additions & 7 deletions libheif/heif_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> data(static_cast<uint8_t*>(uuid->data), static_cast<uint8_t*>(uuid->data) + uuid->size);
std::vector<uint8_t> uuid_type(uuid->uuid_type, uuid->uuid_type + 16);
std::vector<uint8_t> data_vector(data, data + size);
std::vector<uint8_t> uuid_type_vector(uuid_type, uuid_type + 16);

auto uuid_box = std::make_shared<Box_uuid>();
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);

Expand All @@ -324,4 +325,52 @@ struct heif_error heif_item_add_property_uuid(const struct heif_context* context
}

return heif_error_success;
}
}


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<std::shared_ptr<Box>> 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<Box_uuid>(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;
}


31 changes: 24 additions & 7 deletions libheif/heif_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 111158d

Please sign in to comment.