Skip to content

Commit

Permalink
expose private function as heif_image_extend_to_size_fill_with_zero().
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Oct 13, 2024
1 parent c6d9d6c commit 52cd13b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
13 changes: 8 additions & 5 deletions examples/heif_enc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,6 @@ std::optional<input_tiles_generator> determine_input_images_tiling(const std::st
return generator;
}

#include <libheif/api_structs.h>

heif_image_handle* encode_tiled(heif_context* ctx, heif_encoder* encoder, heif_encoding_options* options,
int output_bit_depth,
Expand Down Expand Up @@ -834,15 +833,19 @@ heif_image_handle* encode_tiled(heif_context* ctx, heif_encoder* encoder, heif_e
tile_height = heif_image_get_primary_height(input_image.image.get());
}

input_image.image->image->extend_to_size_with_zero(tile_width, tile_height);
heif_error error;
error = heif_image_extend_to_size_fill_with_zero(input_image.image.get(), tile_width, tile_height);
if (error.code) {
std::cerr << error.message << "\n";
}

std::cout << "encoding tile " << ty+1 << " " << tx+1
<< " (of " << tile_generator.nRows() << "x" << tile_generator.nColumns() << ") \r";
std::cout.flush();

heif_error error = heif_context_add_image_tile(ctx, tiled_image, tx, ty,
input_image.image.get(),
encoder);
error = heif_context_add_image_tile(ctx, tiled_image, tx, ty,
input_image.image.get(),
encoder);
if (error.code != 0) {
std::cerr << "Could not encode HEIF/AVIF file: " << error.message << "\n";
return nullptr;
Expand Down
15 changes: 15 additions & 0 deletions libheif/api/libheif/heif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,21 @@ struct heif_error heif_image_scale_image(const struct heif_image* input,
return Error::Ok.error_struct(input->image.get());
}


struct heif_error heif_image_extend_to_size_fill_with_zero(struct heif_image* image,
uint32_t width, uint32_t height)
{
bool success = image->image->extend_to_size_with_zero(width, height);
if (!success) {
return heif_error{heif_error_Memory_allocation_error,
heif_suberror_Unspecified,
"Not enough memory to extend image size."};
}

return heif_error_ok;
}


struct heif_error heif_image_set_raw_color_profile(struct heif_image* image,
const char* color_profile_type_fourcc,
const void* profile_data,
Expand Down
6 changes: 6 additions & 0 deletions libheif/api/libheif/heif.h
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,12 @@ struct heif_error heif_image_scale_image(const struct heif_image* input,
int width, int height,
const struct heif_scaling_options* options);

// Extends the image size to match the given size by extending the right and bottom borders.
// The border areas are filled with zero.
LIBHEIF_API
struct heif_error heif_image_extend_to_size_fill_with_zero(struct heif_image* image,
uint32_t width, uint32_t height);

// The color profile is not attached to the image handle because we might need it
// for color space transform and encoding.
LIBHEIF_API
Expand Down

0 comments on commit 52cd13b

Please sign in to comment.