Skip to content

Commit

Permalink
Merge branch 'master' into evc_boxes_2024-10-29
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk authored Nov 22, 2024
2 parents 2eb8e5d + 331bd06 commit 48d614f
Show file tree
Hide file tree
Showing 116 changed files with 27,797 additions and 18,970 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.16.3) # Oldest Ubuntu LTS (20.04 currently)

project(libheif LANGUAGES C CXX VERSION 1.19.1)
project(libheif LANGUAGES C CXX VERSION 1.19.5)

# compatibility_version is never allowed to be decreased for any specific SONAME.
# Libtool in the libheif-1.15.1 release had set it to 17.0.0, so we have to use this for the v1.x.y versions.
Expand Down Expand Up @@ -416,6 +416,9 @@ endif()
if (KVAZAAR_FOUND AND NOT (PLUGIN_LOADING_SUPPORTED_AND_ENABLED AND WITH_KVAZAAR_PLUGIN))
list(APPEND REQUIRES_PRIVATE "kvazaar")
endif()
if (OpenH264_FOUND AND (WITH_OpenH264_DECODER AND NOT (PLUGIN_LOADING_SUPPORTED_AND_ENABLED AND WITH_OpenH264_DECODER_PLUGIN)))
list(APPEND REQUIRES_PRIVATE "openh264")
endif()
if ((AOM_DECODER_FOUND AND NOT (PLUGIN_LOADING_SUPPORTED_AND_ENABLED AND WITH_AOM_DECODER_PLUGIN))
OR (AOM_ENCODER_FOUND AND NOT (PLUGIN_LOADING_SUPPORTED_AND_ENABLED AND WITH_AOM_ENCODER_PLUGIN)))
list(APPEND REQUIRES_PRIVATE "aom")
Expand All @@ -438,6 +441,9 @@ endif()
if (OpenJPEG_FOUND AND ((WITH_OpenJPEG_DECODER AND NOT (PLUGIN_LOADING_SUPPORTED_AND_ENABLED AND WITH_OpenJPEG_DECODER_PLUGIN)) OR (WITH_OpenJPEG_ENCODER AND NOT (PLUGIN_LOADING_SUPPORTED_AND_ENABLED AND WITH_OpenJPEG_ENCODER_PLUGIN))))
list(APPEND REQUIRES_PRIVATE "libopenjp2")
endif()
if (OPENJPH_FOUND AND (WITH_OPENJPH_ENCODER AND NOT (PLUGIN_LOADING_SUPPORTED_AND_ENABLED AND WITH_OPENJPH_ENCODER_PLUGIN)))
list(APPEND REQUIRES_PRIVATE "openjph")
endif()
if (LIBSHARPYUV_FOUND)
list(APPEND REQUIRES_PRIVATE "libsharpyuv")
endif()
Expand Down Expand Up @@ -543,6 +549,7 @@ if(ENABLE_COVERAGE)
endif()

option(BUILD_TESTING "" ON)
set(CMAKE_CTEST_ARGUMENTS "--output-on-failure")
include(CTest)
if(BUILD_TESTING)
# TODO: fix tests on windows.
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ before_build:
- mkdir build
- cd build
- cmake .. -A %arch% -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DWITH_DAV1D=ON -DWITH_AOM_DECODER=ON -DWITH_AOM_ENCODER=ON -DWITH_JPEG_DECODER=ON -DWITH_JPEG_ENCODER=ON -DWITH_UNCOMPRESSED_CODEC=ON -DWITH_HEADER_COMPRESSION=ON -DWITH_FFMPEG_DECODER=ON
- dir

build:
project: build\libheif.sln
parallel: true
verbosity: normal

Expand Down
9 changes: 6 additions & 3 deletions examples/heif_dec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -858,9 +858,12 @@ int main(int argc, char** argv)

decode_options->strict_decoding = strict_decoding;
decode_options->decoder_id = decoder_id;
decode_options->start_progress = start_progress;
decode_options->on_progress = on_progress;
decode_options->end_progress = end_progress;

if (!option_quiet) {
decode_options->start_progress = start_progress;
decode_options->on_progress = on_progress;
decode_options->end_progress = end_progress;
}

if (chroma_upsampling=="nearest-neighbor") {
decode_options->color_conversion_options.preferred_chroma_upsampling_algorithm = heif_chroma_upsampling_nearest_neighbor;
Expand Down
10 changes: 5 additions & 5 deletions examples/heif_enc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void show_help(const char* argv0)
<< " --tiled-image-height # override image height of tiled image\n"
<< " --tiled-input-x-y usually, the first number in the input tile filename should be the y position.\n"
<< " With this option, this can be swapped so that the first number is x, the second number y.\n"
#if ENABLE_EXPERIMENTAL_FEATURES
#if HEIF_ENABLE_EXPERIMENTAL_FEATURES
<< " --tiling-method METHOD choose one of these methods: grid, tili, unci. The default is 'grid'.\n"
<< " --add-pyramid-group when several images are given, put them into a multi-resolution pyramid group.\n"
#endif
Expand Down Expand Up @@ -749,7 +749,7 @@ heif_image_handle* encode_tiled(heif_context* ctx, heif_encoder* encoder, heif_e
return nullptr;
}
}
#if ENABLE_EXPERIMENTAL_FEATURES
#if HEIF_ENABLE_EXPERIMENTAL_FEATURES
else if (tiling_method == "tili") {
heif_tiled_image_parameters tiled_params{};
tiled_params.version = 1;
Expand All @@ -776,7 +776,7 @@ heif_image_handle* encode_tiled(heif_context* ctx, heif_encoder* encoder, heif_e
params.tile_height = tiling.tile_height;
params.compression = unci_compression;

std::string input_filename = tile_generator.filename(0, 0);
std::string input_filename = tile_generator.filename(0, 0).string();
InputImage prototype_image = load_image(input_filename, output_bit_depth);

heif_error error = heif_context_add_unci_image(ctx, &params, options, prototype_image.image.get(), &tiled_image);
Expand Down Expand Up @@ -974,7 +974,7 @@ int main(int argc, char** argv)
case OPTION_TILING_METHOD:
tiling_method = optarg;
if (tiling_method != "grid"
#if ENABLE_EXPERIMENTAL_FEATURES
#if HEIF_ENABLE_EXPERIMENTAL_FEATURES
&& tiling_method != "tili" && tiling_method != "unci"
#endif
) {
Expand Down Expand Up @@ -1393,7 +1393,7 @@ int main(int argc, char** argv)
heif_image_handle_release(primary_image_handle);
}

#if ENABLE_EXPERIMENTAL_FEATURES
#if HEIF_ENABLE_EXPERIMENTAL_FEATURES
if (add_pyramid_group && encoded_image_ids.size() > 1) {
error = heif_context_add_pyramid_entity_group(context.get(), encoded_image_ids.data(), encoded_image_ids.size(), nullptr);
if (error.code) {
Expand Down
5 changes: 3 additions & 2 deletions examples/heif_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ static struct option long_options[] = {
{0, 0, 0, 0}
};

const char* fourcc_to_string(uint32_t fourcc)
// Note: the same function is also exists in common_utils.h, but is not in the public API.
static const char* fourcc_to_string(uint32_t fourcc)
{
static char fcc[5];
fcc[0] = (char) ((fourcc >> 24) & 0xFF);
Expand Down Expand Up @@ -272,7 +273,7 @@ int main(int argc, char** argv)
if (err.code) {
std::cerr << "Error while trying to get image tiling information: " << err.message << "\n";
}
else if (tiling.num_columns > 0) {
else if (tiling.num_columns != 1 || tiling.num_rows != 1) {
std::cout << " tiles: " << tiling.num_columns << "x" << tiling.num_rows
<< ", tile size: " << tiling.tile_width << "x" << tiling.tile_height << "\n";
}
Expand Down
22 changes: 13 additions & 9 deletions fuzzing/color_conversion_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static bool read_plane(BitstreamRange* range,
if (!range->prepare_read(static_cast<size_t>(width) * height)) {
return false;
}
if (!image->add_plane(channel, width, height, bit_depth)) {
if (auto err = image->add_plane(channel, width, height, bit_depth, heif_get_disabled_security_limits())) {
return false;
}
uint32_t stride;
Expand All @@ -96,7 +96,7 @@ static bool read_plane_interleaved(BitstreamRange* range,
if (!range->prepare_read(static_cast<size_t>(width) * height * comps)) {
return false;
}
if (!image->add_plane(channel, width, height, bit_depth)) {
if (auto err = image->add_plane(channel, width, height, bit_depth, heif_get_disabled_security_limits())) {
return false;
}
uint32_t stride;
Expand Down Expand Up @@ -250,19 +250,23 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
int output_bpp = 0; // Same as input.
heif_encoding_options* options = heif_encoding_options_alloc();

auto out_image = convert_colorspace(in_image,
static_cast<heif_colorspace>(out_colorspace),
static_cast<heif_chroma>(out_chroma),
nullptr,
output_bpp,
options->color_conversion_options);
auto out_image_result = convert_colorspace(in_image,
static_cast<heif_colorspace>(out_colorspace),
static_cast<heif_chroma>(out_chroma),
nullptr,
output_bpp,
options->color_conversion_options,
heif_get_disabled_security_limits());

heif_encoding_options_free(options);

if (!out_image) {
if (out_image_result.error) {
// Conversion is not supported.
return 0;
}

auto out_image = *out_image_result;

assert(out_image->get_width() == width);
assert(out_image->get_height() == height);
assert(out_image->get_chroma_format() ==
Expand Down
6 changes: 5 additions & 1 deletion fuzzing/file_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ static void TestDecodeImage(struct heif_context* ctx,
heif_image_handle_get_metadata_type(handle, metadata_ids[i]);
heif_image_handle_get_metadata_content_type(handle, metadata_ids[i]);
size_t metadata_size = heif_image_handle_get_metadata_size(handle, metadata_ids[i]);
assert(metadata_size < filesize);

// This assertion is invalid. Metadata can in fact be larger than the file if there are several
// overlapping iloc extents. Does not make much sense, but it is technically valid.
//assert(metadata_size < filesize);

uint8_t* metadata_data = static_cast<uint8_t*>(malloc(metadata_size));
assert(metadata_data);
heif_image_handle_get_metadata(handle, metadata_ids[i], metadata_data);
Expand Down
2 changes: 1 addition & 1 deletion libheif/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ if (ENABLE_EXPERIMENTAL_FEATURES)

list(APPEND libheif_headers api/libheif/heif_experimental.h)

target_compile_definitions(heif PUBLIC ENABLE_EXPERIMENTAL_FEATURES)
target_compile_definitions(heif PUBLIC HEIF_ENABLE_EXPERIMENTAL_FEATURES)
endif()

# Needed to find libheif/heif_version.h while compiling the library
Expand Down
43 changes: 19 additions & 24 deletions libheif/api/libheif/heif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,8 @@ struct heif_error heif_image_handle_get_tile_size(const struct heif_image_handle


struct heif_entity_group* heif_context_get_entity_groups(const struct heif_context* ctx,
uint32_t type_filter, uint32_t item_filter,
uint32_t type_filter,
heif_item_id item_filter,
int* out_num_groups)
{
std::shared_ptr<Box_grpl> grplBox = ctx->context->get_heif_file()->get_grpl_box();
Expand Down Expand Up @@ -1557,7 +1558,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 +1588,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 +1665,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 Expand Up @@ -1773,7 +1774,7 @@ heif_error heif_image_crop(struct heif_image* img,
"Image size exceeds maximum supported size"};
}

auto cropResult = img->image->crop(left, static_cast<int>(w) - 1 - right, top, static_cast<int>(h) - 1 - bottom);
auto cropResult = img->image->crop(left, static_cast<int>(w) - 1 - right, top, static_cast<int>(h) - 1 - bottom, nullptr);
if (cropResult.error) {
return cropResult.error.error_struct(img->image.get());
}
Expand Down Expand Up @@ -1805,11 +1806,9 @@ int heif_image_has_channel(const struct heif_image* img, enum heif_channel chann
struct heif_error heif_image_add_plane(struct heif_image* image,
heif_channel channel, int width, int height, int bit_depth)
{
if (!image->image->add_plane(channel, width, height, bit_depth)) {
struct heif_error err = {heif_error_Memory_allocation_error,
heif_suberror_Unspecified,
"Cannot allocate memory for image plane"};
return err;
// Note: no security limit, because this is explicitly requested by the user.
if (auto err = image->image->add_plane(channel, width, height, bit_depth, nullptr)) {
return err.error_struct(image->image.get());
}
else {
return heif_error_success;
Expand All @@ -1822,7 +1821,7 @@ struct heif_error heif_image_add_channel(struct heif_image* image,
int width, int height,
heif_channel_datatype datatype, int bit_depth)
{
if (!image->image->add_channel(channel, width, height, datatype, bit_depth)) {
if (!image->image->add_channel(channel, width, height, datatype, bit_depth, nullptr)) {
struct heif_error err = {heif_error_Memory_allocation_error,
heif_suberror_Unspecified,
"Cannot allocate memory for image plane"};
Expand Down Expand Up @@ -1996,11 +1995,9 @@ int heif_image_is_premultiplied_alpha(struct heif_image* image)

struct heif_error heif_image_extend_padding_to_size(struct heif_image* image, int min_physical_width, int min_physical_height)
{
bool mem_alloc_success = image->image->extend_padding_to_size(min_physical_width, min_physical_height);
if (!mem_alloc_success) {
return heif_error{heif_error_Memory_allocation_error,
heif_suberror_Unspecified,
"Cannot allocate image memory."};
Error err = image->image->extend_padding_to_size(min_physical_width, min_physical_height, false, nullptr);
if (err) {
return err.error_struct(image->image.get());
}
else {
return heif_error_success;
Expand All @@ -2015,7 +2012,7 @@ struct heif_error heif_image_scale_image(const struct heif_image* input,
{
std::shared_ptr<HeifPixelImage> out_img;

Error err = input->image->scale_nearest_neighbor(out_img, width, height);
Error err = input->image->scale_nearest_neighbor(out_img, width, height, nullptr);
if (err) {
return err.error_struct(input->image.get());
}
Expand All @@ -2030,11 +2027,9 @@ struct heif_error heif_image_scale_image(const struct heif_image* input,
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."};
Error err = image->image->extend_to_size_with_zero(width, height, nullptr);
if (err) {
return err.error_struct(image->image.get());
}

return heif_error_ok;
Expand Down Expand Up @@ -3055,7 +3050,7 @@ heif_encoder_parameter_get_valid_integer_range(const struct heif_encoder_paramet
return heif_error_success;
}

LIBHEIF_API

struct heif_error heif_encoder_parameter_get_valid_integer_values(const struct heif_encoder_parameter* param,
int* have_minimum, int* have_maximum,
int* minimum, int* maximum,
Expand Down Expand Up @@ -3650,7 +3645,7 @@ struct heif_error heif_context_add_image_tile(struct heif_context* ctx,
}
#endif
else if (auto grid_item = std::dynamic_pointer_cast<ImageItem_Grid>(tiled_image->image)) {
Error err = grid_item->add_image_tile(tiled_image->image->get_id(), tile_x, tile_y, image->image, encoder);
Error err = grid_item->add_image_tile(tile_x, tile_y, image->image, encoder);
return err.error_struct(ctx->context.get());
}
else {
Expand Down
9 changes: 6 additions & 3 deletions libheif/api/libheif/heif.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extern "C" {
// 1.18 5 7 1 1 1 1
// 1.19 6 7 2 1 1 1

#if defined(_MSC_VER) && !defined(LIBHEIF_STATIC_BUILD)
#if (defined(_WIN32) || defined __CYGWIN__) && !defined(LIBHEIF_STATIC_BUILD)
#ifdef LIBHEIF_EXPORTS
#define LIBHEIF_API __declspec(dllexport)
#else
Expand Down Expand Up @@ -1324,7 +1324,10 @@ struct heif_entity_group
// Use 0 for `type_filter` or `item_filter` to disable the filter.
// Returns an array of heif_entity_group structs with *out_num_groups entries.
LIBHEIF_API
struct heif_entity_group* heif_context_get_entity_groups(const struct heif_context*, uint32_t type_filter, uint32_t item_filter, int* out_num_groups);
struct heif_entity_group* heif_context_get_entity_groups(const struct heif_context*,
uint32_t type_filter,
heif_item_id item_filter,
int* out_num_groups);

// Release an array of entity groups returned by heif_context_get_entity_groups().
LIBHEIF_API
Expand Down Expand Up @@ -2363,7 +2366,7 @@ struct heif_encoding_options

// Set this to the NCLX parameters to be used in the output image or set to NULL
// when the same parameters as in the input image should be used.
const struct heif_color_profile_nclx* output_nclx_profile;
struct heif_color_profile_nclx* output_nclx_profile;

uint8_t macOS_compatibility_workaround_no_nclx_profile;

Expand Down
Loading

0 comments on commit 48d614f

Please sign in to comment.