Skip to content

Commit

Permalink
API: heif_item_add_property_uuid()
Browse files Browse the repository at this point in the history
  • Loading branch information
dukesook committed Nov 8, 2023
1 parent 82797ad commit 31c32c1
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 deletions.
24 changes: 24 additions & 0 deletions libheif/box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3087,3 +3087,27 @@ Error Box_udes::write(StreamWriter& writer) const
prepend_header(writer, box_start);
return Error::Ok;
}


std::string Box_uuid::dump(Indent& indent) const
{
std::ostringstream sstr;
sstr << Box::dump(indent);
sstr << indent << "uuid_type: ";
for (uint8_t byte: m_uuid_type) {
sstr << byte << " ";
}
sstr << "\n";
return sstr.str();
}

Error Box_uuid::write(StreamWriter& writer) const
{
size_t box_start = reserve_box_header_space(writer);
writer.write(m_uuid_data);
prepend_header(writer, box_start);
return Error::Ok;
}



31 changes: 30 additions & 1 deletion libheif/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class BoxHeader

void set_short_type(uint32_t type) { m_type = type; }

void set_uuid_type(const std::vector<uint8_t>& uuid_type) { m_uuid_type = uuid_type; }

Error parse_header(BitstreamRange& range);

Expand All @@ -140,9 +141,9 @@ class BoxHeader
uint64_t m_size = 0;

uint32_t m_type = 0;
std::vector<uint8_t> m_uuid_type;

protected:
std::vector<uint8_t> m_uuid_type;
uint32_t m_header_size = 0;
};

Expand Down Expand Up @@ -1058,4 +1059,32 @@ class Box_udes : public FullBox
std::string m_tags;
};

/**
* Universally Unique Identifier.
*
* A box of type "uuid" is used to store user-defined data.
* The uuid_type (aka extended_type) in the BoxHeader is used to identify the uuid_data.
*
* See ISO/IEC 14496-12 Section 4.2.2 and Section 11.1.
*/
class Box_uuid : public Box
{
public:
Box_uuid()
{
set_short_type(fourcc("uuid"));
}

std::string dump(Indent&) const override;

Error write(StreamWriter& writer) const override;

std::vector<uint8_t> get_uuid_data() const { return m_uuid_data; }

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

private:
std::vector<uint8_t> m_uuid_data;
};

#endif
25 changes: 25 additions & 0 deletions libheif/heif_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,28 @@ void heif_property_user_description_release(struct heif_property_user_descriptio
delete udes;
}


struct heif_error heif_item_add_property_uuid(const struct heif_context* context,
heif_item_id itemId,
const struct heif_property_uuid* uuid,
heif_property_id* out_propertyId)
{
if (!context || !uuid || !uuid->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);

auto uuid_box = std::make_shared<Box_uuid>();
uuid_box->set_uuid_type(uuid_type);
uuid_box->set_uuid_data(data);

heif_property_id id = context->context->add_property(itemId, uuid_box, false);

if (out_propertyId) {
*out_propertyId = id;
}

return heif_error_success;
}
15 changes: 14 additions & 1 deletion libheif/heif_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ enum heif_item_property_type
heif_item_property_type_transform_mirror = heif_fourcc('i', 'm', 'i', 'r'),
heif_item_property_type_transform_rotation = heif_fourcc('i', 'r', 'o', 't'),
heif_item_property_type_transform_crop = heif_fourcc('c', 'l', 'a', 'p'),
heif_item_property_type_image_size = heif_fourcc('i', 's', 'p', 'e')
heif_item_property_type_image_size = heif_fourcc('i', 's', 'p', 'e'),
heif_item_property_type_uuid = heif_fourcc('u', 'u', 'i', 'd'),
};

// Get the heif_property_id for a heif_item_id.
Expand Down Expand Up @@ -131,6 +132,18 @@ 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
};
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,
heif_property_id* out_propertyId);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 31c32c1

Please sign in to comment.