From 1bb435cb9c0361d26c9815fcf5974085c45bcdb3 Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Thu, 3 Oct 2024 01:10:23 +0200 Subject: [PATCH] replace all fourcc-type strings with uint32_t constants --- libheif/api/libheif/heif.cc | 20 ++++++++---- libheif/api/libheif/heif_items.cc | 8 ++++- libheif/box.cc | 41 ++++-------------------- libheif/box.h | 7 +--- libheif/codecs/avc.h | 2 +- libheif/codecs/avif.h | 2 +- libheif/codecs/grid.h | 2 +- libheif/codecs/hevc.h | 2 +- libheif/codecs/iden.h | 4 +-- libheif/codecs/image_item.h | 2 +- libheif/codecs/jpeg.h | 2 +- libheif/codecs/jpeg2000.h | 2 +- libheif/codecs/mask_image.h | 2 +- libheif/codecs/overlay.h | 2 +- libheif/codecs/tild.cc | 2 +- libheif/codecs/tild.h | 2 +- libheif/codecs/uncompressed/unc_boxes.cc | 4 +-- libheif/codecs/uncompressed/unc_image.cc | 6 ++-- libheif/codecs/uncompressed/unc_image.h | 2 +- libheif/codecs/vvc.h | 2 +- libheif/common_utils.cc | 12 +++++++ libheif/common_utils.h | 5 +-- libheif/context.cc | 16 ++++----- libheif/context.h | 2 +- libheif/file.cc | 25 ++++----------- libheif/file.h | 8 ++--- 26 files changed, 80 insertions(+), 104 deletions(-) diff --git a/libheif/api/libheif/heif.cc b/libheif/api/libheif/heif.cc index 9b79ac25e7..efda7895a9 100644 --- a/libheif/api/libheif/heif.cc +++ b/libheif/api/libheif/heif.cc @@ -292,13 +292,13 @@ heif_brand2 heif_read_main_brand(const uint8_t* data, int len) } -heif_brand2 heif_fourcc_to_brand(const char* fourcc) +heif_brand2 heif_fourcc_to_brand(const char* fourcc_string) { - if (fourcc == nullptr || !fourcc[0] || !fourcc[1] || !fourcc[2] || !fourcc[3]) { + if (fourcc_string == nullptr || !fourcc_string[0] || !fourcc_string[1] || !fourcc_string[2] || !fourcc_string[3]) { return 0; } - return fourcc_to_uint32(fourcc); + return fourcc(fourcc_string); } @@ -337,7 +337,7 @@ int heif_has_compatible_brand(const uint8_t* data, int len, const char* brand_fo return -2; } - return ftyp->has_compatible_brand(fourcc_to_uint32(brand_fourcc)) ? 1 : 0; + return ftyp->has_compatible_brand(fourcc(brand_fourcc)) ? 1 : 0; } @@ -3478,7 +3478,7 @@ struct heif_error heif_context_add_image_tile(struct heif_context* ctx, const struct heif_image* image, struct heif_encoder* encoder) { - if (tiled_image->image->get_infe_type() == std::string{"tili"}) { + if (tiled_image->image->get_infe_type() == fourcc("tili")) { Error err = ctx->context->add_tild_image_tile(tiled_image->image->get_id(), tile_x, tile_y, image->image, encoder); return err.error_struct(ctx->context.get()); } @@ -3642,8 +3642,14 @@ struct heif_error heif_context_add_generic_metadata(struct heif_context* ctx, const void* data, int size, const char* item_type, const char* content_type) { + if (item_type == nullptr || strlen(item_type) != 4) { + return {heif_error_Usage_error, + heif_suberror_Invalid_parameter_value, + "called heif_context_add_generic_metadata() with invalid 'item_type'."}; + } + Error error = ctx->context->add_generic_metadata(image_handle->image, data, size, - item_type, content_type, nullptr, heif_metadata_compression_off, nullptr); + fourcc(item_type), content_type, nullptr, heif_metadata_compression_off, nullptr); if (error != Error::Ok) { return error.error_struct(ctx->context.get()); } @@ -3660,7 +3666,7 @@ struct heif_error heif_context_add_generic_uri_metadata(struct heif_context* ctx heif_item_id* out_item_id) { Error error = ctx->context->add_generic_metadata(image_handle->image, data, size, - "uri ", nullptr, item_uri_type, heif_metadata_compression_off, out_item_id); + fourcc("uri "), nullptr, item_uri_type, heif_metadata_compression_off, out_item_id); if (error != Error::Ok) { return error.error_struct(ctx->context.get()); } diff --git a/libheif/api/libheif/heif_items.cc b/libheif/api/libheif/heif_items.cc index 1fd383f8ae..3a3b5836ba 100644 --- a/libheif/api/libheif/heif_items.cc +++ b/libheif/api/libheif/heif_items.cc @@ -238,7 +238,13 @@ struct heif_error heif_context_add_item(struct heif_context* ctx, const void* data, int size, heif_item_id* out_item_id) { - Result result = ctx->context->get_heif_file()->add_infe(item_type, (const uint8_t*) data, size); + if (item_type == nullptr || strlen(item_type) != 4) { + return {heif_error_Usage_error, + heif_suberror_Invalid_parameter_value, + "called heif_context_add_item() with invalid 'item_type'."}; + } + + Result result = ctx->context->get_heif_file()->add_infe(fourcc(item_type), (const uint8_t*) data, size); if (result && out_item_id) { *out_item_id = result.value; diff --git a/libheif/box.cc b/libheif/box.cc index 6a36380e8d..b71fbad530 100644 --- a/libheif/box.cc +++ b/libheif/box.cc @@ -161,25 +161,6 @@ bool Fraction::is_valid() const return denominator != 0; } -static uint32_t from_fourcc(const char* string) -{ - return ((string[0] << 24) | - (string[1] << 16) | - (string[2] << 8) | - (string[3])); -} - -std::string to_fourcc(uint32_t code) -{ - std::string str(" "); - str[0] = static_cast((code >> 24) & 0xFF); - str[1] = static_cast((code >> 16) & 0xFF); - str[2] = static_cast((code >> 8) & 0xFF); - str[3] = static_cast((code >> 0) & 0xFF); - - return str; -} - BoxHeader::BoxHeader() = default; @@ -2089,9 +2070,6 @@ Error Box_infe::parse(BitstreamRange& range) m_item_protection_index = range.read16(); m_item_type_4cc = range.read32(); - if (m_item_type_4cc != 0) { - m_item_type = to_fourcc(m_item_type_4cc); - } m_item_name = range.read_string(); if (m_item_type_4cc == fourcc("mime")) { @@ -2120,7 +2098,7 @@ void Box_infe::derive_box_version() } - if (m_item_type != "") { + if (m_item_type_4cc != 0) { min_version = std::max(min_version, 2); } @@ -2163,19 +2141,14 @@ Error Box_infe::write(StreamWriter& writer) const writer.write16(m_item_protection_index); - if (m_item_type.empty()) { - writer.write32(0); - } - else { - writer.write32(from_fourcc(m_item_type.c_str())); - } + writer.write32(m_item_type_4cc); writer.write(m_item_name); - if (m_item_type == "mime") { + if (m_item_type_4cc == fourcc("mime")) { writer.write(m_content_type); writer.write(m_content_encoding); } - else if (m_item_type == "uri ") { + else if (m_item_type_4cc == fourcc("uri ")) { writer.write(m_item_uri_type); } } @@ -2193,15 +2166,15 @@ std::string Box_infe::dump(Indent& indent) const sstr << indent << "item_ID: " << m_item_ID << "\n" << indent << "item_protection_index: " << m_item_protection_index << "\n" - << indent << "item_type: " << m_item_type << "\n" + << indent << "item_type: " << to_fourcc(m_item_type_4cc) << "\n" << indent << "item_name: " << m_item_name << "\n"; - if (m_item_type == "mime") { + if (m_item_type_4cc == fourcc("mime")) { sstr << indent << "content_type: " << m_content_type << "\n" << indent << "content_encoding: " << m_content_encoding << "\n"; } - if (m_item_type == "uri ") { + if (m_item_type_4cc == fourcc("uri ")) { sstr << indent << "item uri type: " << m_item_uri_type << "\n"; } diff --git a/libheif/box.h b/libheif/box.h index 6d07e0a219..b843c474e5 100644 --- a/libheif/box.h +++ b/libheif/box.h @@ -589,13 +589,9 @@ class Box_infe : public FullBox void set_item_ID(heif_item_id id) { m_item_ID = id; } - const std::string& get_item_type() const { return m_item_type; } - uint32_t get_item_type_4cc() const { return m_item_type_4cc; } - void set_item_type(const std::string& type) { m_item_type = type; m_item_type_4cc = fourcc_to_uint32(type.c_str()); } - - void set_item_type_4cc(uint32_t type) { m_item_type_4cc = type; m_item_type = to_fourcc(type); } + void set_item_type_4cc(uint32_t type) { m_item_type_4cc = type; } void set_item_name(const std::string& name) { m_item_name = name; } @@ -625,7 +621,6 @@ class Box_infe : public FullBox uint16_t m_item_protection_index = 0; uint32_t m_item_type_4cc = 0; - std::string m_item_type; // deprecated, prefer to use m_item_type_4cc std::string m_item_name; std::string m_content_type; std::string m_content_encoding; diff --git a/libheif/codecs/avc.h b/libheif/codecs/avc.h index 1bbbaddd4e..7836f313e9 100644 --- a/libheif/codecs/avc.h +++ b/libheif/codecs/avc.h @@ -97,7 +97,7 @@ class ImageItem_AVC : public ImageItem ImageItem_AVC(HeifContext* ctx) : ImageItem(ctx) {} - const char* get_infe_type() const override { return "avc1"; } + uint32_t get_infe_type() const override { return fourcc("avc1"); } const char* get_auxC_alpha_channel_type() const override { return "urn:mpeg:mpegB:cicp:systems:auxiliary:alpha"; } diff --git a/libheif/codecs/avif.h b/libheif/codecs/avif.h index 2a1f44c2bd..c3b6ce032b 100644 --- a/libheif/codecs/avif.h +++ b/libheif/codecs/avif.h @@ -159,7 +159,7 @@ class ImageItem_AVIF : public ImageItem ImageItem_AVIF(HeifContext* ctx) : ImageItem(ctx) {} - const char* get_infe_type() const override { return "av01"; } + uint32_t get_infe_type() const override { return fourcc("av01"); } const char* get_auxC_alpha_channel_type() const override { return "urn:mpeg:mpegB:cicp:systems:auxiliary:alpha"; } diff --git a/libheif/codecs/grid.h b/libheif/codecs/grid.h index dab6404a0f..ac18d30773 100644 --- a/libheif/codecs/grid.h +++ b/libheif/codecs/grid.h @@ -80,7 +80,7 @@ class ImageItem_Grid : public ImageItem ImageItem_Grid(HeifContext* ctx); - const char* get_infe_type() const override { return "grid"; } + uint32_t get_infe_type() const override { return fourcc("grid"); } // const heif_color_profile_nclx* get_forced_output_nclx() const override { return nullptr; } diff --git a/libheif/codecs/hevc.h b/libheif/codecs/hevc.h index ec06267c35..1b38a19bfb 100644 --- a/libheif/codecs/hevc.h +++ b/libheif/codecs/hevc.h @@ -128,7 +128,7 @@ class ImageItem_HEVC : public ImageItem ImageItem_HEVC(HeifContext* ctx) : ImageItem(ctx) {} - const char* get_infe_type() const override { return "hvc1"; } + uint32_t get_infe_type() const override { return fourcc("hvc1"); } // TODO: MIAF says that the *:hevc:* urn is deprecated and we should use "urn:mpeg:mpegB:cicp:systems:auxiliary:alpha" const char* get_auxC_alpha_channel_type() const override { return "urn:mpeg:hevc:2015:auxid:1"; } diff --git a/libheif/codecs/iden.h b/libheif/codecs/iden.h index c2a129ccc2..19cfd8901b 100644 --- a/libheif/codecs/iden.h +++ b/libheif/codecs/iden.h @@ -34,7 +34,7 @@ class ImageItem_iden : public ImageItem ImageItem_iden(HeifContext* ctx); - const char* get_infe_type() const override { return "iden"; } + uint32_t get_infe_type() const override { return fourcc("iden"); } // const heif_color_profile_nclx* get_forced_output_nclx() const override { return nullptr; } @@ -52,7 +52,7 @@ class ImageItem_iden : public ImageItem enum heif_image_input_class input_class) override { return Error{heif_error_Unsupported_feature, - heif_suberror_Unspecified, "Cannot encode image to 'iovl'"}; + heif_suberror_Unspecified, "Cannot encode image to 'iden'"}; } Result> decode_compressed_image(const struct heif_decoding_options& options, diff --git a/libheif/codecs/image_item.h b/libheif/codecs/image_item.h index a902bff1f7..42572320bd 100644 --- a/libheif/codecs/image_item.h +++ b/libheif/codecs/image_item.h @@ -66,7 +66,7 @@ class ImageItem : public ErrorBuffer struct heif_encoder* encoder, const struct heif_encoding_options& options); - virtual const char* get_infe_type() const { return "????"; } // TODO = 0; + virtual uint32_t get_infe_type() const { return 0; } virtual const char* get_auxC_alpha_channel_type() const { return "urn:mpeg:mpegB:cicp:systems:auxiliary:alpha"; } diff --git a/libheif/codecs/jpeg.h b/libheif/codecs/jpeg.h index ee1f04f86e..906ad984a2 100644 --- a/libheif/codecs/jpeg.h +++ b/libheif/codecs/jpeg.h @@ -59,7 +59,7 @@ class ImageItem_JPEG : public ImageItem ImageItem_JPEG(HeifContext* ctx) : ImageItem(ctx) { } - const char* get_infe_type() const override { return "jpeg"; } + uint32_t get_infe_type() const override { return fourcc("jpeg"); } const heif_color_profile_nclx* get_forced_output_nclx() const override; diff --git a/libheif/codecs/jpeg2000.h b/libheif/codecs/jpeg2000.h index 19cbf9d728..b62c9a3315 100644 --- a/libheif/codecs/jpeg2000.h +++ b/libheif/codecs/jpeg2000.h @@ -523,7 +523,7 @@ class ImageItem_JPEG2000 : public ImageItem ImageItem_JPEG2000(HeifContext* ctx) : ImageItem(ctx) {} - const char* get_infe_type() const override { return "j2k1"; } + uint32_t get_infe_type() const override { return fourcc("j2k1"); } heif_compression_format get_compression_format() const override { return heif_compression_JPEG2000; } diff --git a/libheif/codecs/mask_image.h b/libheif/codecs/mask_image.h index fc34f903d2..4b0fed6980 100644 --- a/libheif/codecs/mask_image.h +++ b/libheif/codecs/mask_image.h @@ -87,7 +87,7 @@ class ImageItem_mask : public ImageItem ImageItem_mask(HeifContext* ctx) : ImageItem(ctx) {} - const char* get_infe_type() const override { return "mski"; } + uint32_t get_infe_type() const override { return fourcc("mski"); } const heif_color_profile_nclx* get_forced_output_nclx() const override { return nullptr; } diff --git a/libheif/codecs/overlay.h b/libheif/codecs/overlay.h index a799e3551a..94c3ed3795 100644 --- a/libheif/codecs/overlay.h +++ b/libheif/codecs/overlay.h @@ -90,7 +90,7 @@ class ImageItem_Overlay : public ImageItem ImageItem_Overlay(HeifContext* ctx); - const char* get_infe_type() const override { return "iovl"; } + uint32_t get_infe_type() const override { return fourcc("iovl"); } // const heif_color_profile_nclx* get_forced_output_nclx() const override { return nullptr; } diff --git a/libheif/codecs/tild.cc b/libheif/codecs/tild.cc index 7ad936cefc..9d7e69dfcf 100644 --- a/libheif/codecs/tild.cc +++ b/libheif/codecs/tild.cc @@ -493,7 +493,7 @@ ImageItem_Tild::add_new_tild_item(HeifContext* ctx, const heif_tild_image_parame auto file = ctx->get_heif_file(); - heif_item_id tild_id = ctx->get_heif_file()->add_new_image("tild"); + heif_item_id tild_id = ctx->get_heif_file()->add_new_image(fourcc("tild")); auto tild_image = std::make_shared(ctx, tild_id); ctx->insert_new_image(tild_id, tild_image); diff --git a/libheif/codecs/tild.h b/libheif/codecs/tild.h index 5f833a5a85..2e5670040b 100644 --- a/libheif/codecs/tild.h +++ b/libheif/codecs/tild.h @@ -132,7 +132,7 @@ class ImageItem_Tild : public ImageItem ImageItem_Tild(HeifContext* ctx); - const char* get_infe_type() const override { return "tili"; } + uint32_t get_infe_type() const override { return fourcc("tili"); } // const heif_color_profile_nclx* get_forced_output_nclx() const override { return nullptr; } diff --git a/libheif/codecs/uncompressed/unc_boxes.cc b/libheif/codecs/uncompressed/unc_boxes.cc index ab304884c1..f5f7447404 100644 --- a/libheif/codecs/uncompressed/unc_boxes.cc +++ b/libheif/codecs/uncompressed/unc_boxes.cc @@ -201,14 +201,14 @@ Error Box_uncC::parse(BitstreamRange& range) parse_full_box_header(range); m_profile = range.read32(); if (get_version() == 1) { - if (m_profile == fourcc_to_uint32("rgb3")) { + if (m_profile == fourcc("rgb3")) { Box_uncC::Component component0 = {0, 8, component_format_unsigned, 0}; add_component(component0); Box_uncC::Component component1 = {1, 8, component_format_unsigned, 0}; add_component(component1); Box_uncC::Component component2 = {2, 8, component_format_unsigned, 0}; add_component(component2); - } else if ((m_profile == fourcc_to_uint32("rgba")) || (m_profile == fourcc_to_uint32("abgr"))) { + } else if ((m_profile == fourcc("rgba")) || (m_profile == fourcc("abgr"))) { Box_uncC::Component component0 = {0, 8, component_format_unsigned, 0}; add_component(component0); Box_uncC::Component component1 = {1, 8, component_format_unsigned, 0}; diff --git a/libheif/codecs/uncompressed/unc_image.cc b/libheif/codecs/uncompressed/unc_image.cc index b1fe15c996..316ff8f073 100644 --- a/libheif/codecs/uncompressed/unc_image.cc +++ b/libheif/codecs/uncompressed/unc_image.cc @@ -1777,9 +1777,9 @@ static void maybe_make_minimised_uncC(std::shared_ptr& uncC, const std return; } if (image->get_chroma_format() == heif_chroma_interleaved_RGBA) { - uncC->set_profile(fourcc_to_uint32("rgba")); + uncC->set_profile(fourcc("rgba")); } else { - uncC->set_profile(fourcc_to_uint32("rgb3")); + uncC->set_profile(fourcc("rgb3")); } uncC->set_version(1); } @@ -2039,7 +2039,7 @@ Result> ImageItem_uncompressed::add_unci auto file = ctx->get_heif_file(); - heif_item_id unci_id = ctx->get_heif_file()->add_new_image("unci"); + heif_item_id unci_id = ctx->get_heif_file()->add_new_image(fourcc("unci")); auto unci_image = std::make_shared(ctx, unci_id); ctx->insert_new_image(unci_id, unci_image); diff --git a/libheif/codecs/uncompressed/unc_image.h b/libheif/codecs/uncompressed/unc_image.h index 1e91033a8e..13cc3bd962 100644 --- a/libheif/codecs/uncompressed/unc_image.h +++ b/libheif/codecs/uncompressed/unc_image.h @@ -71,7 +71,7 @@ class ImageItem_uncompressed : public ImageItem ImageItem_uncompressed(HeifContext* ctx) : ImageItem(ctx) {} - const char* get_infe_type() const override { return "unci"; } + uint32_t get_infe_type() const override { return fourcc("unci"); } heif_compression_format get_compression_format() const override { return heif_compression_uncompressed; } diff --git a/libheif/codecs/vvc.h b/libheif/codecs/vvc.h index abb85524b9..fadfb3f020 100644 --- a/libheif/codecs/vvc.h +++ b/libheif/codecs/vvc.h @@ -112,7 +112,7 @@ class ImageItem_VVC : public ImageItem ImageItem_VVC(HeifContext* ctx) : ImageItem(ctx) {} - const char* get_infe_type() const override { return "vvc1"; } + uint32_t get_infe_type() const override { return fourcc("vvc1"); } const char* get_auxC_alpha_channel_type() const override { return "urn:mpeg:mpegB:cicp:systems:auxiliary:alpha"; } diff --git a/libheif/common_utils.cc b/libheif/common_utils.cc index 060cef4623..6346537de6 100644 --- a/libheif/common_utils.cc +++ b/libheif/common_utils.cc @@ -100,3 +100,15 @@ uint8_t compute_avif_profile(int bits_per_pixel, heif_chroma chroma) return 2; } } + + +std::string to_fourcc(uint32_t code) +{ + std::string str(" "); + str[0] = static_cast((code >> 24) & 0xFF); + str[1] = static_cast((code >> 16) & 0xFF); + str[2] = static_cast((code >> 8) & 0xFF); + str[3] = static_cast((code >> 0) & 0xFF); + + return str; +} diff --git a/libheif/common_utils.h b/libheif/common_utils.h index c6f43c16aa..b61fd2c1a4 100644 --- a/libheif/common_utils.h +++ b/libheif/common_utils.h @@ -32,7 +32,7 @@ #endif -constexpr inline uint32_t fourcc_to_uint32(const char* id) +constexpr inline uint32_t fourcc(const char* id) { return (((((uint32_t) id[0])&0xFF) << 24) | ((((uint32_t) id[1])&0xFF) << 16) | @@ -40,9 +40,6 @@ constexpr inline uint32_t fourcc_to_uint32(const char* id) ((((uint32_t) id[3])&0xFF) << 0)); } -// abbreviation -constexpr inline uint32_t fourcc(const char* id) { return fourcc_to_uint32(id); } - std::string to_fourcc(uint32_t code); diff --git a/libheif/context.cc b/libheif/context.cc index f34fb01b6e..70f68202cc 100644 --- a/libheif/context.cc +++ b/libheif/context.cc @@ -180,7 +180,7 @@ Error HeifContext::check_resolution(uint32_t width, uint32_t height) const { std::shared_ptr HeifContext::add_region_item(uint32_t reference_width, uint32_t reference_height) { - std::shared_ptr box = m_heif_file->add_new_infe_box("rgan"); + std::shared_ptr box = m_heif_file->add_new_infe_box(fourcc("rgan")); box->set_hidden_item(true); auto regionItem = std::make_shared(box->get_item_ID(), reference_width, reference_height); @@ -1183,7 +1183,7 @@ Error HeifContext::encode_grid(const std::vector } // Create Grid Item - heif_item_id grid_id = m_heif_file->add_new_image("grid"); + heif_item_id grid_id = m_heif_file->add_new_image(fourcc("grid")); out_grid_image = std::make_shared(this, grid_id); m_all_images.insert(std::make_pair(grid_id, out_grid_image)); const int construction_method = 1; // 0=mdat 1=idat @@ -1238,7 +1238,7 @@ Error HeifContext::add_grid_item(const std::vector& tile_ids, // Create Grid Item - heif_item_id grid_id = m_heif_file->add_new_image("grid"); + heif_item_id grid_id = m_heif_file->add_new_image(fourcc("grid")); out_grid_image = std::make_shared(this, grid_id); m_all_images.insert(std::make_pair(grid_id, out_grid_image)); const int construction_method = 1; // 0=mdat 1=idat @@ -1284,7 +1284,7 @@ Result> HeifContext::add_iovl_item(const Imag // Create IOVL Item - heif_item_id iovl_id = m_heif_file->add_new_image("iovl"); + heif_item_id iovl_id = m_heif_file->add_new_image(fourcc("iovl")); std::shared_ptr iovl_image = std::make_shared(this, iovl_id); m_all_images.insert(std::make_pair(iovl_id, iovl_image)); const int construction_method = 1; // 0=mdat 1=idat @@ -1516,19 +1516,19 @@ Error HeifContext::add_exif_metadata(const std::shared_ptr& master_im return add_generic_metadata(master_image, data_array.data(), (int) data_array.size(), - "Exif", nullptr, nullptr, heif_metadata_compression_off, nullptr); + fourcc("Exif"), nullptr, nullptr, heif_metadata_compression_off, nullptr); } Error HeifContext::add_XMP_metadata(const std::shared_ptr& master_image, const void* data, int size, heif_metadata_compression compression) { - return add_generic_metadata(master_image, data, size, "mime", "application/rdf+xml", nullptr, compression, nullptr); + return add_generic_metadata(master_image, data, size, fourcc("mime"), "application/rdf+xml", nullptr, compression, nullptr); } Error HeifContext::add_generic_metadata(const std::shared_ptr& master_image, const void* data, int size, - const char* item_type, const char* content_type, const char* item_uri_type, heif_metadata_compression compression, + uint32_t item_type, const char* content_type, const char* item_uri_type, heif_metadata_compression compression, heif_item_id* out_item_id) { // create an infe box describing what kind of data we are storing (this also creates a new ID) @@ -1559,7 +1559,7 @@ Error HeifContext::add_generic_metadata(const std::shared_ptr& master // only set metadata compression for MIME type data which has 'content_encoding' field if (compression != heif_metadata_compression_off && - strcmp(item_type, "mime") != 0) { + item_type != fourcc("mime")) { // TODO: error, compression not supported } diff --git a/libheif/context.h b/libheif/context.h index bd5f3dcf72..976763a7fd 100644 --- a/libheif/context.h +++ b/libheif/context.h @@ -184,7 +184,7 @@ class HeifContext : public ErrorBuffer Error add_XMP_metadata(const std::shared_ptr& master_image, const void* data, int size, heif_metadata_compression compression); Error add_generic_metadata(const std::shared_ptr& master_image, const void* data, int size, - const char* item_type, const char* content_type, const char* item_uri_type, + uint32_t item_type, const char* content_type, const char* item_uri_type, heif_metadata_compression compression, heif_item_id* out_item_id); heif_property_id add_property(heif_item_id targetItem, std::shared_ptr property, bool essential); diff --git a/libheif/file.cc b/libheif/file.cc index edcd051352..48b945350a 100644 --- a/libheif/file.cc +++ b/libheif/file.cc @@ -478,17 +478,6 @@ bool HeifFile::has_item_with_id(heif_item_id ID) const } -std::string HeifFile::get_item_type(heif_item_id ID) const -{ - auto infe_box = get_infe_box(ID); - if (!infe_box) { - return ""; - } - - return infe_box->get_item_type(); -} - - uint32_t HeifFile::get_item_type_4cc(heif_item_id ID) const { auto infe_box = get_infe_box(ID); @@ -831,21 +820,21 @@ heif_item_id HeifFile::get_unused_item_id() const } -heif_item_id HeifFile::add_new_image(const char* item_type) +heif_item_id HeifFile::add_new_image(uint32_t item_type) { auto box = add_new_infe_box(item_type); return box->get_item_ID(); } -std::shared_ptr HeifFile::add_new_infe_box(const char* item_type) +std::shared_ptr HeifFile::add_new_infe_box(uint32_t item_type) { heif_item_id id = get_unused_item_id(); auto infe = std::make_shared(); infe->set_item_ID(id); infe->set_hidden_item(false); - infe->set_item_type(item_type); + infe->set_item_type_4cc(item_type); m_infe_boxes[id] = infe; m_iinf_box->append_child_box(infe); @@ -963,7 +952,7 @@ void HeifFile::add_pixi_property(heif_item_id id, uint8_t c1, uint8_t c2, uint8_ } -Result HeifFile::add_infe(const char* item_type, const uint8_t* data, size_t size) +Result HeifFile::add_infe(uint32_t item_type, const uint8_t* data, size_t size) { Result result; @@ -987,7 +976,7 @@ Result HeifFile::add_infe_mime(const char* content_type, heif_meta // create an infe box describing what kind of data we are storing (this also creates a new ID) - auto infe_box = add_new_infe_box("mime"); + auto infe_box = add_new_infe_box(fourcc("mime")); infe_box->set_hidden_item(true); infe_box->set_content_type(content_type); @@ -1006,7 +995,7 @@ Result HeifFile::add_precompressed_infe_mime(const char* content_t // create an infe box describing what kind of data we are storing (this also creates a new ID) - auto infe_box = add_new_infe_box("mime"); + auto infe_box = add_new_infe_box(fourcc("mime")); infe_box->set_hidden_item(true); infe_box->set_content_type(content_type); @@ -1025,7 +1014,7 @@ Result HeifFile::add_infe_uri(const char* item_uri_type, const uin // create an infe box describing what kind of data we are storing (this also creates a new ID) - auto infe_box = add_new_infe_box("uri "); + auto infe_box = add_new_infe_box(fourcc("uri ")); infe_box->set_hidden_item(true); infe_box->set_item_uri_type(item_uri_type); diff --git a/libheif/file.h b/libheif/file.h index 47f1c2247d..720c0caa9d 100644 --- a/libheif/file.h +++ b/libheif/file.h @@ -82,8 +82,6 @@ class HeifFile bool has_item_with_id(heif_item_id ID) const; - std::string get_item_type(heif_item_id ID) const; - uint32_t get_item_type_4cc(heif_item_id ID) const; std::string get_content_type(heif_item_id ID) const; @@ -152,9 +150,9 @@ class HeifFile heif_item_id get_unused_item_id() const; - heif_item_id add_new_image(const char* item_type); + heif_item_id add_new_image(uint32_t item_type); - std::shared_ptr add_new_infe_box(const char* item_type); + std::shared_ptr add_new_infe_box(uint32_t item_type); void add_ispe_property(heif_item_id id, uint32_t width, uint32_t height, bool essential); @@ -168,7 +166,7 @@ class HeifFile heif_property_id add_property_without_deduplication(heif_item_id id, const std::shared_ptr& property, bool essential); - Result add_infe(const char* item_type, const uint8_t* data, size_t size); + Result add_infe(uint32_t item_type, const uint8_t* data, size_t size); Result add_infe_mime(const char* content_type, heif_metadata_compression content_encoding, const uint8_t* data, size_t size);