Skip to content

Commit

Permalink
replace all get_item_type() with get_item_type_4cc()
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Oct 2, 2024
1 parent 6a5b62c commit 1e64957
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 72 deletions.
14 changes: 4 additions & 10 deletions libheif/api/libheif/heif_items.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ int heif_context_get_list_of_item_IDs(const struct heif_context* ctx,

uint32_t heif_context_get_item_type(const struct heif_context* ctx, heif_item_id item_id)
{
auto type = ctx->context->get_heif_file()->get_item_type(item_id);
if (type.empty()) {
return 0;
}
else {
return fourcc(type.c_str());
}
return ctx->context->get_heif_file()->get_item_type_4cc(item_id);
}


Expand All @@ -88,7 +82,7 @@ const char* heif_context_get_mime_item_content_type(const struct heif_context* c
auto infe = ctx->context->get_heif_file()->get_infe_box(item_id);
if (!infe) { return nullptr; }

if (infe->get_item_type() != "mime") {
if (infe->get_item_type_4cc() != fourcc("mime")) {
return nullptr;
}

Expand All @@ -100,7 +94,7 @@ const char* heif_context_get_mime_item_content_encoding(const struct heif_contex
auto infe = ctx->context->get_heif_file()->get_infe_box(item_id);
if (!infe) { return nullptr; }

if (infe->get_item_type() != "mime") {
if (infe->get_item_type_4cc() != fourcc("mime")) {
return nullptr;
}

Expand All @@ -113,7 +107,7 @@ const char* heif_context_get_uri_item_uri_type(const struct heif_context* ctx, h
auto infe = ctx->context->get_heif_file()->get_infe_box(item_id);
if (!infe) { return nullptr; }

if (infe->get_item_type() != "uri ") {
if (infe->get_item_type_4cc() != fourcc("uri ")) {
return nullptr;
}

Expand Down
28 changes: 14 additions & 14 deletions libheif/codecs/image_item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,46 +101,46 @@ heif_compression_format ImageItem::compression_format_from_fourcc_infe_type(uint

std::shared_ptr<ImageItem> ImageItem::alloc_for_infe_box(HeifContext* ctx, const std::shared_ptr<Box_infe>& infe)
{
std::string item_type = infe->get_item_type();
uint32_t item_type = infe->get_item_type_4cc();
heif_item_id id = infe->get_item_ID();

if (item_type == "jpeg" ||
(item_type == "mime" && infe->get_content_type() == "image/jpeg")) {
if (item_type == fourcc("jpeg") ||
(item_type == fourcc("mime") && infe->get_content_type() == "image/jpeg")) {
return std::make_shared<ImageItem_JPEG>(ctx, id);
}
else if (item_type == "hvc1") {
else if (item_type == fourcc("hvc1")) {
return std::make_shared<ImageItem_HEVC>(ctx, id);
}
else if (item_type == "av01") {
else if (item_type == fourcc("av01")) {
return std::make_shared<ImageItem_AVIF>(ctx, id);
}
else if (item_type == "vvc1") {
else if (item_type == fourcc("vvc1")) {
return std::make_shared<ImageItem_VVC>(ctx, id);
}
else if (item_type == "avc1") {
else if (item_type == fourcc("avc1")) {
return std::make_shared<ImageItem_AVC>(ctx, id);
}
#if WITH_UNCOMPRESSED_CODEC
else if (item_type == "unci") {
else if (item_type == fourcc("unci")) {
return std::make_shared<ImageItem_uncompressed>(ctx, id);
}
#endif
else if (item_type == "j2k1") {
else if (item_type == fourcc("j2k1")) {
return std::make_shared<ImageItem_JPEG2000>(ctx, id);
}
else if (item_type == "mski") {
else if (item_type == fourcc("mski")) {
return std::make_shared<ImageItem_mask>(ctx, id);
}
else if (item_type == "grid") {
else if (item_type == fourcc("grid")) {
return std::make_shared<ImageItem_Grid>(ctx, id);
}
else if (item_type == "iovl") {
else if (item_type == fourcc("iovl")) {
return std::make_shared<ImageItem_Overlay>(ctx, id);
}
else if (item_type == "iden") {
else if (item_type == fourcc("iden")) {
return std::make_shared<ImageItem_iden>(ctx, id);
}
else if (item_type == "tild") {
else if (item_type == fourcc("tild")) {
return std::make_shared<ImageItem_Tild>(ctx, id);
}
else {
Expand Down
60 changes: 29 additions & 31 deletions libheif/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,21 @@ std::string HeifContext::debug_dump_boxes() const
}


static bool item_type_is_image(const std::string& item_type, const std::string& content_type)
static bool item_type_is_image(uint32_t item_type, const std::string& content_type)
{
return (item_type == "hvc1" ||
item_type == "av01" ||
item_type == "grid" ||
item_type == "tild" ||
item_type == "iden" ||
item_type == "iovl" ||
item_type == "avc1" ||
item_type == "unci" ||
item_type == "vvc1" ||
item_type == "jpeg" ||
(item_type == "mime" && content_type == "image/jpeg") ||
item_type == "j2k1" ||
item_type == "mski");
return (item_type == fourcc("hvc1") ||
item_type == fourcc("av01") ||
item_type == fourcc("grid") ||
item_type == fourcc("tild") ||
item_type == fourcc("iden") ||
item_type == fourcc("iovl") ||
item_type == fourcc("avc1") ||
item_type == fourcc("unci") ||
item_type == fourcc("vvc1") ||
item_type == fourcc("jpeg") ||
(item_type == fourcc("mime") && content_type == "image/jpeg") ||
item_type == fourcc("j2k1") ||
item_type == fourcc("mski"));
}


Expand Down Expand Up @@ -629,7 +629,7 @@ Error HeifContext::interpret_heif_file()
auto& image = pair.second;

std::shared_ptr<Box_infe> infe = m_heif_file->get_infe_box(image->get_id());
if (infe->get_item_type() == "hvc1") {
if (infe->get_item_type_4cc() == fourcc("hvc1")) {

auto ipma = m_heif_file->get_ipma_box();
auto ipco = m_heif_file->get_ipco_box();
Expand All @@ -640,7 +640,7 @@ Error HeifContext::interpret_heif_file()
"No hvcC property in hvc1 type image");
}
}
if (infe->get_item_type() == "vvc1") {
if (infe->get_item_type_4cc() == fourcc("vvc1")) {

auto ipma = m_heif_file->get_ipma_box();
auto ipco = m_heif_file->get_ipco_box();
Expand Down Expand Up @@ -669,7 +669,7 @@ Error HeifContext::interpret_heif_file()
break;
}

if (infe_box->get_item_type() == "grid") {
if (infe_box->get_item_type_4cc() == fourcc("grid")) {
std::vector<heif_item_id> image_references = iref_box->get_references(id, fourcc("dimg"));

if (image_references.empty()) {
Expand Down Expand Up @@ -698,12 +698,12 @@ Error HeifContext::interpret_heif_file()
// --- read metadata and assign to image

for (heif_item_id id : image_IDs) {
std::string item_type = m_heif_file->get_item_type(id);
uint32_t item_type = m_heif_file->get_item_type_4cc(id);
std::string content_type = m_heif_file->get_content_type(id);

// 'rgan': skip region annotations, handled next
// 'iden': iden images are no metadata
if (item_type_is_image(item_type, content_type) || item_type == "rgan") {
if (item_type_is_image(item_type, content_type) || item_type == fourcc("rgan")) {
continue;
}

Expand All @@ -713,13 +713,13 @@ Error HeifContext::interpret_heif_file()

std::shared_ptr<ImageMetadata> metadata = std::make_shared<ImageMetadata>();
metadata->item_id = id;
metadata->item_type = item_type;
metadata->item_type = to_fourcc(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) {
if (item_type == "Exif" || item_type == "mime") {
if (item_type == fourcc("Exif") || item_type == fourcc("mime")) {
// these item types should have data
return err;
}
Expand Down Expand Up @@ -771,8 +771,8 @@ Error HeifContext::interpret_heif_file()
// --- read region item and assign to image(s)

for (heif_item_id id : image_IDs) {
std::string item_type = m_heif_file->get_item_type(id);
if (item_type != "rgan") {
uint32_t item_type = m_heif_file->get_item_type_4cc(id);
if (item_type != fourcc("rgan")) {
continue;
}

Expand Down Expand Up @@ -875,8 +875,8 @@ bool HeifContext::has_alpha(heif_item_id ID) const

// TODO: move this into ImageItem

std::string image_type = m_heif_file->get_item_type(ID);
if (image_type == "grid") {
uint32_t image_type = m_heif_file->get_item_type_4cc(ID);
if (image_type == fourcc("grid")) {
std::vector<uint8_t> grid_data;
Error error = m_heif_file->get_compressed_image_data(ID, &grid_data);
if (error) {
Expand Down Expand Up @@ -937,10 +937,10 @@ bool HeifContext::has_alpha(heif_item_id ID) const

Error HeifContext::get_id_of_non_virtual_child_image(heif_item_id id, heif_item_id& out) const
{
std::string image_type = m_heif_file->get_item_type(id);
if (image_type == "grid" ||
image_type == "iden" ||
image_type == "iovl") {
uint32_t image_type = m_heif_file->get_item_type_4cc(id);
if (image_type == fourcc("grid") ||
image_type == fourcc("iden") ||
image_type == fourcc("iovl")) {
auto iref_box = m_heif_file->get_iref_box();
if (!iref_box) {
return Error(heif_error_Invalid_input,
Expand Down Expand Up @@ -974,8 +974,6 @@ Result<std::shared_ptr<HeifPixelImage>> HeifContext::decode_image(heif_item_id I
const struct heif_decoding_options& options,
bool decode_only_tile, uint32_t tx, uint32_t ty) const
{
std::string image_type = m_heif_file->get_item_type(ID);

std::shared_ptr<ImageItem> imginfo;
if (m_all_images.find(ID) != m_all_images.end()) {
imginfo = m_all_images.find(ID)->second;
Expand Down
45 changes: 28 additions & 17 deletions libheif/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,17 @@ std::string HeifFile::get_item_type(heif_item_id ID) const
}


uint32_t HeifFile::get_item_type_4cc(heif_item_id ID) const
{
auto infe_box = get_infe_box(ID);
if (!infe_box) {
return 0;
}

return infe_box->get_item_type_4cc();
}


std::string HeifFile::get_content_type(heif_item_id ID) const
{
auto infe_box = get_infe_box(ID);
Expand Down Expand Up @@ -590,43 +601,43 @@ Error HeifFile::get_compressed_image_data(heif_item_id ID, std::vector<uint8_t>*
}


std::string item_type = infe_box->get_item_type();
uint32_t item_type = infe_box->get_item_type_4cc();
std::string content_type = infe_box->get_content_type();

// --- get coded image data pointers

if (item_type == "hvc1") {
if (item_type == fourcc("hvc1")) {
// --- --- --- HEVC
assert(false);
}
else if (item_type == "vvc1") {
else if (item_type == fourcc("vvc1")) {
// --- --- --- VVC
assert(false);
}
else if (item_type == "av01") {
else if (item_type == fourcc("av01")) {
assert(false);
}
else if (item_type == "jpeg" ||
(item_type == "mime" && get_content_type(ID) == "image/jpeg")) {
else if (item_type == fourcc("jpeg") ||
(item_type == fourcc("mime") && get_content_type(ID) == "image/jpeg")) {
assert(false);
}
else if (item_type == "j2k1") {
else if (item_type == fourcc("j2k1")) {
assert(false);
}
#if WITH_UNCOMPRESSED_CODEC
else if (item_type == "unci") {
else if (item_type == fourcc("unci")) {
assert(false);
// return get_compressed_image_data_uncompressed(ID, data, item);
}
#endif
else if (true || // fallback case for all kinds of generic metadata (e.g. 'iptc')
item_type == "grid" ||
item_type == "iovl" ||
item_type == "Exif" ||
(item_type == "mime" && content_type == "application/rdf+xml")) {
item_type == fourcc("grid") ||
item_type == fourcc("iovl") ||
item_type == fourcc("Exif") ||
(item_type == fourcc("mime") && content_type == "application/rdf+xml")) {
Error error;
bool read_uncompressed = true;
if (item_type == "mime") {
if (item_type == fourcc("mime")) {
std::string encoding = infe_box->get_content_encoding();
if (encoding == "compress_zlib") {
#if HAVE_ZLIB
Expand Down Expand Up @@ -725,12 +736,12 @@ Error HeifFile::get_item_data(heif_item_id ID, std::vector<uint8_t>* out_data, h
heif_suberror_Nonexisting_item_referenced};
}

std::string item_type = infe_box->get_item_type();
uint32_t item_type = infe_box->get_item_type_4cc();
std::string content_type = infe_box->get_content_type();

// --- non 'mime' data (uncompressed)

if (item_type != "mime") {
if (item_type != fourcc("mime")) {
if (out_compression) {
*out_compression = heif_metadata_compression_off;
}
Expand Down Expand Up @@ -1037,7 +1048,7 @@ Error HeifFile::set_item_data(const std::shared_ptr<Box_infe>& item, const uint8

// only set metadata compression for MIME type data which has 'content_encoding' field
if (compression != heif_metadata_compression_off &&
item->get_item_type() != "mime") {
item->get_item_type_4cc() != fourcc("mime")) {
// TODO: error, compression not supported
}

Expand Down Expand Up @@ -1081,7 +1092,7 @@ Error HeifFile::set_precompressed_item_data(const std::shared_ptr<Box_infe>& ite
{
// only set metadata compression for MIME type data which has 'content_encoding' field
if (!content_encoding.empty() &&
item->get_item_type() != "mime") {
item->get_item_type_4cc() != fourcc("mime")) {
// TODO: error, compression not supported
}

Expand Down
2 changes: 2 additions & 0 deletions libheif/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class HeifFile

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;

std::string get_item_uri_type(heif_item_id ID) const;
Expand Down

0 comments on commit 1e64957

Please sign in to comment.