diff --git a/examples/heif_enc.cc b/examples/heif_enc.cc index ad8066e4ed..5a5273cd93 100644 --- a/examples/heif_enc.cc +++ b/examples/heif_enc.cc @@ -751,7 +751,6 @@ std::optional determine_input_images_tiling(const std::st return generator; } -#include heif_image_handle* encode_tiled(heif_context* ctx, heif_encoder* encoder, heif_encoding_options* options, int output_bit_depth, @@ -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; diff --git a/libheif/api/libheif/heif.cc b/libheif/api/libheif/heif.cc index 661a7d4c96..72bd5f7d58 100644 --- a/libheif/api/libheif/heif.cc +++ b/libheif/api/libheif/heif.cc @@ -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, diff --git a/libheif/api/libheif/heif.h b/libheif/api/libheif/heif.h index d39c8bfb7e..14af0eea30 100644 --- a/libheif/api/libheif/heif.h +++ b/libheif/api/libheif/heif.h @@ -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