Skip to content

Commit

Permalink
Merge pull request #1370 from strukturag/tili-with-contained-properties
Browse files Browse the repository at this point in the history
Tili with contained properties
  • Loading branch information
farindk authored Nov 5, 2024
2 parents ab0565a + 9ce4f3e commit 4e774b0
Show file tree
Hide file tree
Showing 29 changed files with 264 additions and 113 deletions.
6 changes: 3 additions & 3 deletions libheif/api/libheif/heif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ void heif_image_get_content_light_level(const struct heif_image* image, struct h

int heif_image_handle_get_content_light_level(const struct heif_image_handle* handle, struct heif_content_light_level* out)
{
auto clli = handle->image->get_file()->get_property<Box_clli>(handle->image->get_id());
auto clli = handle->image->get_property<Box_clli>();
if (out && clli) {
*out = clli->clli;
}
Expand Down Expand Up @@ -1587,7 +1587,7 @@ void heif_image_get_mastering_display_colour_volume(const struct heif_image* ima

int heif_image_handle_get_mastering_display_colour_volume(const struct heif_image_handle* handle, struct heif_mastering_display_colour_volume* out)
{
auto mdcv = handle->image->get_file()->get_property<Box_mdcv>(handle->image->get_id());
auto mdcv = handle->image->get_property<Box_mdcv>();
if (out && mdcv) {
*out = mdcv->mdcv;
}
Expand Down Expand Up @@ -1664,7 +1664,7 @@ void heif_image_get_pixel_aspect_ratio(const struct heif_image* image, uint32_t*

int heif_image_handle_get_pixel_aspect_ratio(const struct heif_image_handle* handle, uint32_t* aspect_h, uint32_t* aspect_v)
{
auto pasp = handle->image->get_file()->get_property<Box_pasp>(handle->image->get_id());
auto pasp = handle->image->get_property<Box_pasp>();
if (pasp) {
*aspect_h = pasp->hSpacing;
*aspect_v = pasp->vSpacing;
Expand Down
10 changes: 5 additions & 5 deletions libheif/api/libheif/heif_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ struct heif_error heif_property_set_clock_info(struct heif_context* ctx,
}

// Create new taic if one doesn't exist for the itemId.
auto taic = ctx->context->get_heif_file()->get_property<Box_taic>(itemId);
auto taic = ctx->context->get_heif_file()->get_property_for_item<Box_taic>(itemId);
if (!taic) {
taic = std::make_shared<Box_taic>();
}
Expand Down Expand Up @@ -427,7 +427,7 @@ struct heif_error heif_property_get_clock_info(const struct heif_context* ctx,
}

// Check if taic exists for itemId
auto taic = file->get_property<Box_taic>(itemId);
auto taic = file->get_property_for_item<Box_taic>(itemId);
if (!taic) {
out_clock = nullptr;
return {heif_error_Usage_error, heif_suberror_Invalid_property, "TAI Clock property not found for itemId"};
Expand Down Expand Up @@ -462,7 +462,7 @@ struct heif_error heif_property_set_tai_timestamp(struct heif_context* ctx,
}

// Create new itai if one doesn't exist for the itemId.
auto itai = file->get_property<Box_itai>(itemId);
auto itai = file->get_property_for_item<Box_itai>(itemId);
if (!itai) {
itai = std::make_shared<Box_itai>();
}
Expand All @@ -475,7 +475,7 @@ struct heif_error heif_property_set_tai_timestamp(struct heif_context* ctx,
heif_property_id id = ctx->context->add_property(itemId, itai, false);

// Create new taic if one doesn't exist for the itemId.
auto taic = file->get_property<Box_taic>(itemId);
auto taic = file->get_property_for_item<Box_taic>(itemId);
if (!taic) {
taic = std::make_shared<Box_taic>();
ctx->context->add_property(itemId, taic, false);
Expand Down Expand Up @@ -505,7 +505,7 @@ struct heif_error heif_property_get_tai_timestamp(const struct heif_context* ctx
}

//Check if itai exists for itemId
auto itai = file->get_property<Box_itai>(itemId);
auto itai = file->get_property_for_item<Box_itai>(itemId);
if (!itai) {
out_timestamp = nullptr;
return {heif_error_Usage_error, heif_suberror_Invalid_property, "Timestamp property not found for itemId"};
Expand Down
30 changes: 16 additions & 14 deletions libheif/box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -899,22 +899,24 @@ Error Box::read_children(BitstreamRange& range, uint32_t max_number, const heif_
return error;
}

uint32_t max_children;
if (get_short_type() == fourcc("iinf")) {
max_children = limits->max_items;
}
else {
max_children = limits->max_children_per_box;
}
if (max_number == READ_CHILDREN_ALL) {
uint32_t max_children;
if (get_short_type() == fourcc("iinf")) {
max_children = limits->max_items;
}
else {
max_children = limits->max_children_per_box;
}

if (max_children && m_children.size() > max_children) {
std::stringstream sstr;
sstr << "Maximum number of child boxes (" << max_children << ") in '" << get_type_string() << "' box exceeded.";
if (max_children && m_children.size() > max_children) {
std::stringstream sstr;
sstr << "Maximum number of child boxes (" << max_children << ") in '" << get_type_string() << "' box exceeded.";

// Sanity check.
return Error(heif_error_Memory_allocation_error,
heif_suberror_Security_limit_exceeded,
sstr.str());
// Sanity check.
return Error(heif_error_Memory_allocation_error,
heif_suberror_Security_limit_exceeded,
sstr.str());
}
}

m_children.push_back(std::move(box));
Expand Down
20 changes: 11 additions & 9 deletions libheif/codecs/decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,37 +98,39 @@ Result<std::vector<uint8_t>> DataExtent::read_data(uint64_t offset, uint64_t siz
}


std::shared_ptr<Decoder> Decoder::alloc_for_infe_type(const HeifContext* ctx, heif_item_id id, uint32_t format_4cc)
std::shared_ptr<Decoder> Decoder::alloc_for_infe_type(const ImageItem* item)
{
uint32_t format_4cc = item->get_infe_type();

switch (format_4cc) {
case fourcc("hvc1"): {
auto hvcC = ctx->get_heif_file()->get_property<Box_hvcC>(id);
auto hvcC = item->get_property<Box_hvcC>();
return std::make_shared<Decoder_HEVC>(hvcC);
}
case fourcc("av01"): {
auto av1C = ctx->get_heif_file()->get_property<Box_av1C>(id);
auto av1C = item->get_property<Box_av1C>();
return std::make_shared<Decoder_AVIF>(av1C);
}
case fourcc("avc1"): {
auto avcC = ctx->get_heif_file()->get_property<Box_avcC>(id);
auto avcC = item->get_property<Box_avcC>();
return std::make_shared<Decoder_AVC>(avcC);
}
case fourcc("j2k1"): {
auto j2kH = ctx->get_heif_file()->get_property<Box_j2kH>(id);
auto j2kH = item->get_property<Box_j2kH>();
return std::make_shared<Decoder_JPEG2000>(j2kH);
}
case fourcc("vvc1"): {
auto vvcC = ctx->get_heif_file()->get_property<Box_vvcC>(id);
auto vvcC = item->get_property<Box_vvcC>();
return std::make_shared<Decoder_VVC>(vvcC);
}
case fourcc("jpeg"): {
auto jpgC = ctx->get_heif_file()->get_property<Box_jpgC>(id);
auto jpgC = item->get_property<Box_jpgC>();
return std::make_shared<Decoder_JPEG>(jpgC);
}
#if WITH_UNCOMPRESSED_CODEC
case fourcc("unci"): {
auto uncC = ctx->get_heif_file()->get_property<Box_uncC>(id);
auto cmpd = ctx->get_heif_file()->get_property<Box_cmpd>(id);
auto uncC = item->get_property<Box_uncC>();
auto cmpd = item->get_property<Box_cmpd>();
return std::make_shared<Decoder_uncompressed>(uncC,cmpd);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion libheif/codecs/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct DataExtent
class Decoder
{
public:
static std::shared_ptr<Decoder> alloc_for_infe_type(const HeifContext* ctx, heif_item_id, uint32_t format_4cc);
static std::shared_ptr<Decoder> alloc_for_infe_type(const ImageItem* item);


virtual ~Decoder() = default;
Expand Down
10 changes: 8 additions & 2 deletions libheif/codecs/uncompressed/decoder_abstract.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,16 @@ const Error AbstractDecoder::get_compressed_image_data_uncompressed(const HeifCo
uint32_t tile_idx,
const Box_iloc::Item* item) const
{
auto image = context->get_image(ID, false);
if (!image) {
return {heif_error_Invalid_input,
heif_suberror_Nonexisting_item_referenced};
}

// --- get codec configuration

std::shared_ptr<const Box_cmpC> cmpC_box = context->get_heif_file()->get_property<const Box_cmpC>(ID);
std::shared_ptr<const Box_icef> icef_box = context->get_heif_file()->get_property<const Box_icef>(ID);
std::shared_ptr<const Box_cmpC> cmpC_box = image->get_property<const Box_cmpC>();
std::shared_ptr<const Box_icef> icef_box = image->get_property<const Box_icef>();

if (!cmpC_box) {
// assume no generic compression
Expand Down
24 changes: 18 additions & 6 deletions libheif/codecs/uncompressed/unc_codec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,15 @@ Error UncompressedImageCodec::decode_uncompressed_image_tile(const HeifContext*
uint32_t tile_x0, uint32_t tile_y0)
{
auto file = context->get_heif_file();
std::shared_ptr<Box_ispe> ispe = file->get_property<Box_ispe>(ID);
std::shared_ptr<Box_cmpd> cmpd = file->get_property<Box_cmpd>(ID);
std::shared_ptr<Box_uncC> uncC = file->get_property<Box_uncC>(ID);
auto image = context->get_image(ID, false);
if (!image) {
return {heif_error_Invalid_input,
heif_suberror_Nonexisting_item_referenced};
}

std::shared_ptr<Box_ispe> ispe = image->get_property<Box_ispe>();
std::shared_ptr<Box_cmpd> cmpd = image->get_property<Box_cmpd>();
std::shared_ptr<Box_uncC> uncC = image->get_property<Box_uncC>();

Error error = check_header_validity(ispe, cmpd, uncC);
if (error) {
Expand Down Expand Up @@ -589,9 +595,15 @@ Error UncompressedImageCodec::decode_uncompressed_image(const HeifContext* conte
return error;
}

std::shared_ptr<Box_ispe> ispe = context->get_heif_file()->get_property<Box_ispe>(ID);
std::shared_ptr<Box_cmpd> cmpd = context->get_heif_file()->get_property<Box_cmpd>(ID);
std::shared_ptr<Box_uncC> uncC = context->get_heif_file()->get_property<Box_uncC>(ID);
auto image = context->get_image(ID, false);
if (!image) {
return {heif_error_Invalid_input,
heif_suberror_Nonexisting_item_referenced};
}

std::shared_ptr<Box_ispe> ispe = image->get_property<Box_ispe>();
std::shared_ptr<Box_cmpd> cmpd = image->get_property<Box_cmpd>();
std::shared_ptr<Box_uncC> uncC = image->get_property<Box_uncC>();

error = check_header_validity(ispe, cmpd, uncC);
if (error) {
Expand Down
18 changes: 16 additions & 2 deletions libheif/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,15 @@ Error HeifContext::interpret_heif_file()
m_top_level_images.push_back(image);
}

Error err = image->on_load_file();
std::vector<std::shared_ptr<Box>> properties;
Error err = m_heif_file->get_properties(id, properties);
if (err) {
return err;
}

image->set_properties(properties);

err = image->on_load_file();
if (err) {
return err;
}
Expand Down Expand Up @@ -555,7 +563,7 @@ Error HeifContext::interpret_heif_file()
// --- this is an auxiliary image
// check whether it is an alpha channel and attach to the main image if yes

std::shared_ptr<Box_auxC> auxC_property = m_heif_file->get_property<Box_auxC>(image->get_id());
std::shared_ptr<Box_auxC> auxC_property = image->get_property<Box_auxC>();
if (!auxC_property) {
std::stringstream sstr;
sstr << "No auxC property for image " << image->get_id();
Expand Down Expand Up @@ -1208,6 +1216,12 @@ Result<std::shared_ptr<ImageItem>> HeifContext::encode_image(const std::shared_p
}
}

std::vector<std::shared_ptr<Box>> properties;
err = m_heif_file->get_properties(output_image_item->get_id(), properties);
if (err) {
return err;
}
output_image_item->set_properties(properties);

m_heif_file->set_brand(encoder->plugin->compression_format,
output_image_item->is_miaf_compatible());
Expand Down
2 changes: 1 addition & 1 deletion libheif/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class HeifFile
std::vector<std::shared_ptr<Box>>& properties) const;

template<class BoxType>
std::shared_ptr<BoxType> get_property(heif_item_id imageID) const
std::shared_ptr<BoxType> get_property_for_item(heif_item_id imageID) const
{
std::vector<std::shared_ptr<Box>> properties;
Error err = get_properties(imageID, properties);
Expand Down
2 changes: 1 addition & 1 deletion libheif/image-items/avc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ std::shared_ptr<Decoder> ImageItem_AVC::get_decoder() const

Error ImageItem_AVC::on_load_file()
{
auto avcC_box = get_file()->get_property<Box_avcC>(get_id());
auto avcC_box = get_property<Box_avcC>();
if (!avcC_box) {
return Error{heif_error_Invalid_input,
heif_suberror_No_av1C_box};
Expand Down
4 changes: 2 additions & 2 deletions libheif/image-items/avif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

Error ImageItem_AVIF::on_load_file()
{
auto av1C_box = get_file()->get_property<Box_av1C>(get_id());
auto av1C_box = get_property<Box_av1C>();
if (!av1C_box) {
return Error{heif_error_Invalid_input,
heif_suberror_No_av1C_box};
Expand Down Expand Up @@ -102,7 +102,7 @@ Result<ImageItem::CodedImageData> ImageItem_AVIF::encode(const std::shared_ptr<H
}


Result<std::vector<uint8_t>> ImageItem_AVIF::read_bitstream_configuration_data(heif_item_id itemId) const
Result<std::vector<uint8_t>> ImageItem_AVIF::read_bitstream_configuration_data() const
{
return m_decoder->read_bitstream_configuration_data();
}
Expand Down
2 changes: 1 addition & 1 deletion libheif/image-items/avif.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ImageItem_AVIF : public ImageItem
enum heif_image_input_class input_class) override;

protected:
Result<std::vector<uint8_t>> read_bitstream_configuration_data(heif_item_id itemId) const override;
Result<std::vector<uint8_t>> read_bitstream_configuration_data() const override;

std::shared_ptr<class Decoder> get_decoder() const override;

Expand Down
11 changes: 8 additions & 3 deletions libheif/image-items/grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ Error ImageItem_Grid::add_image_tile(heif_item_id grid_id, uint32_t tile_x, uint
set_grid_tile_id(tile_x, tile_y, encoded_image->get_id());

// Add PIXI property (copy from first tile)
auto pixi = file->get_property<Box_pixi>(encoded_image->get_id());
auto pixi = encoded_image->get_property<Box_pixi>();
file->add_property(grid_id, pixi, true);

return Error::Ok;
Expand Down Expand Up @@ -715,6 +715,8 @@ Result<std::shared_ptr<ImageItem_Grid>> ImageItem_Grid::add_and_encode_full_grid

std::vector<heif_item_id> tile_ids;

std::shared_ptr<Box_pixi> pixi_property;

for (int i=0; i<rows*columns; i++) {
std::shared_ptr<ImageItem> out_tile;
auto encodingResult = ctx->encode_image(tiles[i],
Expand All @@ -728,6 +730,10 @@ Result<std::shared_ptr<ImageItem_Grid>> ImageItem_Grid::add_and_encode_full_grid
heif_item_id tile_id = out_tile->get_id();
file->get_infe_box(tile_id)->set_hidden_item(true); // only show the full grid
tile_ids.push_back(out_tile->get_id());

if (!pixi_property) {
pixi_property = out_tile->get_property<Box_pixi>();
}
}

// Create Grid Item
Expand All @@ -750,8 +756,7 @@ Result<std::shared_ptr<ImageItem_Grid>> ImageItem_Grid::add_and_encode_full_grid

// Add PIXI property (copy from first tile)

auto pixi = file->get_property<Box_pixi>(tile_ids[0]);
file->add_property(grid_id, pixi, true);
file->add_property(grid_id, pixi_property, true);

// Set Brands

Expand Down
4 changes: 2 additions & 2 deletions libheif/image-items/hevc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

Error ImageItem_HEVC::on_load_file()
{
auto hvcC_box = get_file()->get_property<Box_hvcC>(get_id());
auto hvcC_box = get_property<Box_hvcC>();
if (!hvcC_box) {
return Error{heif_error_Invalid_input,
heif_suberror_No_hvcC_box};
Expand Down Expand Up @@ -139,7 +139,7 @@ Result<ImageItem::CodedImageData> ImageItem_HEVC::encode(const std::shared_ptr<H
}


Result<std::vector<uint8_t>> ImageItem_HEVC::read_bitstream_configuration_data(heif_item_id itemId) const
Result<std::vector<uint8_t>> ImageItem_HEVC::read_bitstream_configuration_data() const
{
return m_decoder->read_bitstream_configuration_data();
}
Expand Down
2 changes: 1 addition & 1 deletion libheif/image-items/hevc.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ImageItem_HEVC : public ImageItem
void set_preencoded_hevc_image(const std::vector<uint8_t>& data);

protected:
Result<std::vector<uint8_t>> read_bitstream_configuration_data(heif_item_id itemId) const override;
Result<std::vector<uint8_t>> read_bitstream_configuration_data() const override;

std::shared_ptr<class Decoder> get_decoder() const override;

Expand Down
Loading

0 comments on commit 4e774b0

Please sign in to comment.