Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added APIs #749

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 217 additions & 0 deletions libheif/heif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,12 @@ int heif_context_get_number_of_top_level_images(heif_context* ctx)
}


int heif_context_get_number_of_images(heif_context* ctx)
{
return (int) ctx->context->get_images().size();
}


int heif_context_get_list_of_top_level_image_IDs(struct heif_context* ctx,
heif_item_id* ID_array,
int count)
Expand All @@ -559,6 +565,29 @@ int heif_context_get_list_of_top_level_image_IDs(struct heif_context* ctx,
}


int heif_context_get_list_of_image_IDs(struct heif_context* ctx,
heif_item_id* ID_array,
int count)
{
if (ID_array == nullptr || count == 0 || ctx == nullptr) {
return 0;
}

// fill in ID values into output array

const std::map<heif_item_id, std::shared_ptr<HeifContext::Image>> imgs = ctx->context->get_images();
int n = (int) std::min(count, (int) imgs.size());

int i = 0;
for (auto itor = imgs.begin(); itor != imgs.end(); itor++) {
ID_array[i] = itor->second->get_id();
i += 1;
}

return n;
}


struct heif_error heif_context_get_image_handle(struct heif_context* ctx,
heif_item_id id,
struct heif_image_handle** imgHdl)
Expand Down Expand Up @@ -592,6 +621,103 @@ struct heif_error heif_context_get_image_handle(struct heif_context* ctx,
}


struct heif_error heif_context_get_image_handle_from_all_images2(struct heif_context* ctx,
heif_item_id id,
struct heif_image_handle** imgHdl)
{
if (!imgHdl) {
Error err(heif_error_Usage_error,
heif_suberror_Null_pointer_argument);
return err.error_struct(ctx->context.get());
}

std::map<heif_item_id, std::shared_ptr<HeifContext::Image>> images = ctx->context->get_images();

std::shared_ptr<HeifContext::Image> image;
for (auto& img : images) {
if (img.first == id) {
image = img.second;
break;
}
}

if (!image) {
Error err(heif_error_Usage_error, heif_suberror_Nonexisting_item_referenced);
return err.error_struct(ctx->context.get());
}

*imgHdl = new heif_image_handle();
(*imgHdl)->image = image;
(*imgHdl)->context = ctx->context;

return Error::Ok.error_struct(ctx->context.get());
}


struct heif_error heif_context_get_image_handle_from_all_images(struct heif_context* ctx,
heif_item_id id,
struct heif_image_handle** imgHdl)
{
if (!imgHdl) {
Error err(heif_error_Usage_error,
heif_suberror_Null_pointer_argument);
return err.error_struct(ctx->context.get());
}

std::map<heif_item_id, std::shared_ptr<HeifContext::Image>> images = ctx->context->get_images();

auto itor = images.find(id);
if (itor == images.end()) {
Error err(heif_error_Usage_error, heif_suberror_Nonexisting_item_referenced);
return err.error_struct(ctx->context.get());
}

auto image = itor->second;

*imgHdl = new heif_image_handle();
(*imgHdl)->image = image;
(*imgHdl)->context = ctx->context;

return Error::Ok.error_struct(ctx->context.get());
}


struct heif_error heif_image_handle_get_image_width(struct heif_context* ctx,
heif_item_id id,
uint32_t* width)
{
std::map<heif_item_id, std::shared_ptr<HeifContext::Image>> images = ctx->context->get_images();
auto itor = images.find(id);
if (itor == images.end()) {
Error err(heif_error_Usage_error, heif_suberror_Nonexisting_item_referenced);
return err.error_struct(ctx->context.get());
}

auto image = itor->second;
*width = image->get_width();

return Error::Ok.error_struct(ctx->context.get());
}


struct heif_error heif_image_handle_get_image_height(struct heif_context* ctx,
heif_item_id id,
uint32_t* height)
{
std::map<heif_item_id, std::shared_ptr<HeifContext::Image>> images = ctx->context->get_images();
auto itor = images.find(id);
if (itor == images.end()) {
Error err(heif_error_Usage_error, heif_suberror_Nonexisting_item_referenced);
return err.error_struct(ctx->context.get());
}

auto image = itor->second;
*height = image->get_height();

return Error::Ok.error_struct(ctx->context.get());
}


int heif_image_handle_is_primary_image(const struct heif_image_handle* handle)
{
return handle->image->is_primary();
Expand Down Expand Up @@ -743,6 +869,97 @@ int heif_image_handle_get_width(const struct heif_image_handle* handle)
}
}

enum heif_image_type heif_image_handle_get_item_type(const struct heif_image_handle* handle, heif_item_id ID) {
heif_image_type image_type = heif_image_type_none;
std::string item_type;

Error err = handle->context->get_image_type(ID, item_type);
if (err.error_code != heif_error_Ok) {
return heif_image_type_none;
}

if (item_type == "hvc1") {
image_type = heif_image_type_hvc1;
} else if (item_type == "av01") {
image_type = heif_image_type_av01;
} else if (item_type == "grid") {
image_type = heif_image_type_grid;
} else if (item_type == "iden") {
image_type = heif_image_type_iden;
} else if (item_type == "iovl") {
image_type = heif_image_type_iovl;
}

return image_type;
}

int heif_image_handle_get_compressed_image_data(const struct heif_image_handle* handle,
heif_item_id ID,
int pad_start_pattern,
uint8_t **out_img,
size_t *out_size)
{
heif_item_id id = handle->image->get_id();
uint8_t *img = handle->context->get_compressed_image_data(id, pad_start_pattern, out_size);
if (NULL == img) {
return 0;
}

*out_img = img;
return 1;
}


int heif_image_handle_fill_compressed_image_data(const struct heif_image_handle* handle,
heif_item_id ID,
int pad_start_pattern,
uint8_t *out_img,
size_t *out_size)
{
heif_item_id id = handle->image->get_id();
Error err = handle->context->fill_compressed_image_data(id, pad_start_pattern, out_img, out_size);
if (err.error_code != heif_error_Ok) {
return 0;
}

return 1;
}


int heif_image_handle_get_overlay_info(const struct heif_image_handle* handle,
heif_item_id ID,
struct heif_overlay_info *overlay_info)
{
if (NULL == overlay_info) {
return 0;
}

Error err = handle->context->get_overlay_info(ID, *overlay_info);
if (err.error_code != heif_error_Ok) {
return 0;
}

return 1;
}


int heif_image_handle_gcheck_not_compatible_but_moov_box(struct heif_context* ctx, const void* mem, size_t size)
{
if (ctx->context->check_not_compatible_but_moov_box(mem, size, true) == true) {
return 1;
}
return 0;
}


int heif_image_handle_get_alpha_image_id(struct heif_context* ctx, const heif_item_id ID, heif_item_id *alpha_img_id) {
if (false == ctx->context->get_alpha_image_id(ID, *alpha_img_id)) {
return 0;
}

return 1;
}


int heif_image_handle_get_height(const struct heif_image_handle* handle)
{
Expand Down
84 changes: 84 additions & 0 deletions libheif/heif.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,39 @@ enum heif_brand
heif_avis
};

enum heif_image_type
{
heif_image_type_hvc1,
heif_image_type_av01,
heif_image_type_grid,
heif_image_type_iden,
heif_image_type_iovl,
heif_image_type_none_image,
heif_image_type_none, // guardian
};

struct heif_offset
{
int32_t dx;
int32_t dy;
};

struct heif_overlay_info
{
uint32_t canvas_width;
uint32_t canvas_height;

uint16_t bg_color_r;
uint16_t bg_color_g;
uint16_t bg_color_b;
uint16_t bg_color_a;

uint32_t num_items;
struct heif_offset *offsets;
heif_item_id *IDs;
};


// input data should be at least 12 bytes
// DEPRECATED, use heif_read_main_brand() instead
LIBHEIF_API
Expand Down Expand Up @@ -535,6 +568,9 @@ struct heif_error heif_context_read_from_reader(struct heif_context*,
LIBHEIF_API
int heif_context_get_number_of_top_level_images(struct heif_context* ctx);

LIBHEIF_API
int heif_context_get_number_of_images(struct heif_context* ctx);

LIBHEIF_API
int heif_context_is_top_level_image_ID(struct heif_context* ctx, heif_item_id id);

Expand All @@ -545,6 +581,11 @@ int heif_context_get_list_of_top_level_image_IDs(struct heif_context* ctx,
heif_item_id* ID_array,
int count);

LIBHEIF_API
int heif_context_get_list_of_image_IDs(struct heif_context* ctx,
heif_item_id* ID_array,
int count);

LIBHEIF_API
struct heif_error heif_context_get_primary_image_ID(struct heif_context* ctx, heif_item_id* id);

Expand All @@ -560,6 +601,21 @@ struct heif_error heif_context_get_image_handle(struct heif_context* ctx,
heif_item_id id,
struct heif_image_handle**);

LIBHEIF_API
struct heif_error heif_context_get_image_handle_from_all_images(struct heif_context* ctx,
heif_item_id id,
struct heif_image_handle**);

LIBHEIF_API
struct heif_error heif_image_handle_get_image_width(struct heif_context* ctx,
heif_item_id id,
uint32_t* width);

LIBHEIF_API
struct heif_error heif_image_handle_get_image_height(struct heif_context* ctx,
heif_item_id id,
uint32_t* height);

// Print information about the boxes of a HEIF file to file descriptor.
// This is for debugging and informational purposes only. You should not rely on
// the output having a specific format. At best, you should not use this at all.
Expand Down Expand Up @@ -601,6 +657,34 @@ int heif_image_handle_is_primary_image(const struct heif_image_handle* handle);
LIBHEIF_API
int heif_image_handle_get_width(const struct heif_image_handle* handle);

LIBHEIF_API
enum heif_image_type heif_image_handle_get_item_type(const struct heif_image_handle* handle, heif_item_id ID);

LIBHEIF_API
int heif_image_handle_get_compressed_image_data(const struct heif_image_handle* handle,
heif_item_id ID,
int pad_start_pattern,
uint8_t **out_img,
size_t *out_size);

LIBHEIF_API
int heif_image_handle_fill_compressed_image_data(const struct heif_image_handle* handle,
heif_item_id ID,
int pad_start_pattern,
uint8_t *out_img,
size_t *out_size);

LIBHEIF_API
int heif_image_handle_get_overlay_info(const struct heif_image_handle* handle,
heif_item_id ID,
struct heif_overlay_info *overlay_info);

LIBHEIF_API
int heif_image_handle_gcheck_not_compatible_but_moov_box(struct heif_context* ctx, const void* mem, size_t size);

LIBHEIF_API
int heif_image_handle_get_alpha_image_id(struct heif_context* ctx, const heif_item_id ID, heif_item_id *alpha_img_id);

LIBHEIF_API
int heif_image_handle_get_height(const struct heif_image_handle* handle);

Expand Down
Loading