Skip to content

Commit

Permalink
wip: write 'tild' image tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Aug 9, 2024
1 parent 071cf61 commit a9b500f
Show file tree
Hide file tree
Showing 7 changed files with 387 additions and 11 deletions.
5 changes: 0 additions & 5 deletions libheif/api/libheif/heif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3202,9 +3202,6 @@ struct heif_error heif_context_add_tild_image(struct heif_context* ctx,
*out_grid_image_handle = new heif_image_handle;
(*out_grid_image_handle)->image = gridImageResult.value;
(*out_grid_image_handle)->context = ctx->context;

printf("heif_context_add_tild_image : handle: %p\n", *out_grid_image_handle);
printf("heif_context_add_tild_image : HeifContext::Image : %p\n", gridImageResult.value.get());
}

return heif_error_success;
Expand All @@ -3217,8 +3214,6 @@ struct heif_error heif_context_add_tild_image_tile(struct heif_context* ctx,
const struct heif_image* image,
struct heif_encoder* encoder)
{
printf("heif_context_add_tild_image_tile : handle %p\n", tild_image);
printf("heif_context_add_tild_image_tile : HeifContext::Image : %p\n", tild_image->image.get());
Error err = ctx->context->add_tild_image_tile(tild_image->image->get_id(), tile_x, tile_y, image->image, encoder);
return err.error_struct(ctx->context.get());
}
Expand Down
27 changes: 26 additions & 1 deletion libheif/box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ Box_iloc::Box_iloc()
{
set_short_type(fourcc("iloc"));

set_use_tmp_file(true);
set_use_tmp_file(false);
}


Expand Down Expand Up @@ -1584,6 +1584,31 @@ Error Box_iloc::append_data(heif_item_id item_ID,
}


Error Box_iloc::replace_data(heif_item_id item_ID,
uint64_t offset,
const std::vector<uint8_t>& data,
uint8_t construction_method)
{
assert(construction_method == 0); // TODO
assert(offset == 0); // TODO

// check whether this item ID already exists

size_t idx;
for (idx = 0; idx < m_items.size(); idx++) {
if (m_items[idx].item_ID == item_ID) {
break;
}
}

assert(idx != m_items.size());
assert(m_items[idx].extents[0].data.size() <= data.size()); // TODO
memcpy(m_items[idx].extents[0].data.data(), data.data(), data.size());

return Error::Ok;
}


void Box_iloc::derive_box_version()
{
int min_version = m_user_defined_min_version;
Expand Down
9 changes: 9 additions & 0 deletions libheif/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ class Box : public BoxHeader

void set_output_position(uint64_t pos) { m_output_position = pos; }

virtual bool is_essential() const { return false; } // only used for properties

protected:
virtual Error parse(BitstreamRange& range);

Expand Down Expand Up @@ -463,6 +465,11 @@ class Box_iloc : public FullBox
const std::vector<uint8_t>& data,
uint8_t construction_method = 0);

Error replace_data(heif_item_id item_ID,
uint64_t offset,
const std::vector<uint8_t>& data,
uint8_t construction_method);

// append bitstream data that already has been written (before iloc box)
// Error write_mdat_before_iloc(heif_image_id item_ID,
// std::vector<uint8_t>& data)
Expand Down Expand Up @@ -652,6 +659,8 @@ class Box_ispe : public FullBox

bool operator==(const Box& other) const override;

bool is_essential() const override { return true; }

protected:
Error parse(BitstreamRange& range) override;

Expand Down
Loading

0 comments on commit a9b500f

Please sign in to comment.