Skip to content

Commit

Permalink
Merge branch 'main' into avifenc-input-image-size-limit
Browse files Browse the repository at this point in the history
  • Loading branch information
wantehchang authored Jul 30, 2024
2 parents 8ece8cd + 2eb35fc commit 43f599f
Show file tree
Hide file tree
Showing 40 changed files with 448 additions and 271 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci-unix-shared-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ jobs:
codec-aom: 'LOCAL'
codec-dav1d: 'LOCAL'
gcc-version: ${{ matrix.gcc }}
libxml2: 'LOCAL'
libyuv: ${{ matrix.libyuv }}
recent-cmake: 'true'
- uses: ./.github/actions/setup-macos
if: runner.os == 'macOS'
with:
Expand All @@ -49,10 +51,14 @@ jobs:
cmake -G Ninja -S . -B build
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
-DAVIF_CODEC_AOM=LOCAL -DAVIF_CODEC_DAV1D=LOCAL
-DAVIF_LIBSHARPYUV=LOCAL -DAVIF_LIBXML2=LOCAL
-DAVIF_LIBYUV=${{ matrix.libyuv }}
-DAVIF_LIBSHARPYUV=LOCAL
-DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON
-DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_GTEST=LOCAL
-DAVIF_ENABLE_EXPERIMENTAL_YCGCO_R=ON
-DAVIF_ENABLE_EXPERIMENTAL_GAIN_MAP=ON
-DAVIF_ENABLE_EXPERIMENTAL_METAV1=ON
-DAVIF_ENABLE_EXPERIMENTAL_SAMPLE_TRANSFORM=ON
-DAVIF_ENABLE_WERROR=ON
- name: Build libavif (ninja)
working-directory: ./build
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ The changes are relative to the previous release, unless the baseline is specifi
## [Unreleased]

### Changed since 1.1.0
* In avif.h, fix clang-cl compilation errors of "AVIF_API AVIF_NODISCARD" on
* In avif.h, change "AVIF_API AVIF_NODISCARD" back to "AVIF_NODISCARD AVIF_API"
to fix clang-cl and MSVC compilation errors in the shared library build on
Windows.
* Fix -DAVIF_GTEST=SYSTEM, https://github.com/AOMediaCodec/libavif/issues/2258.
* Fix infe_type and codec_config_type wrongly read as byte-aligned fields in the
Expand All @@ -20,6 +21,13 @@ The changes are relative to the previous release, unless the baseline is specifi
* Fix CMake config shared library leaks
https://github.com/AOMediaCodec/libavif/issues/2264.
* Fix clang-cl compilation.
* Fix aom link flags so that transitive library link flags are included when
aom is a static library
https://github.com/AOMediaCodec/libavif/issues/2274.
* Fix out-of-order 'dimg' grid associations
https://github.com/AOMediaCodec/libavif/issues/2311.
* Report files with an item used in multiple 'dimg' boxes with
AVIF_RESULT_NOT_IMPLEMENTED instead of AVIF_RESULT_INVALID_IMAGE_GRID.
* avifenc: Allow large images to be encoded.

## [1.1.0] - 2024-07-11
Expand Down
121 changes: 62 additions & 59 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,31 @@ set_local_or_system_option(
"GTEST" OFF
"Build the GoogleTest framework by providing your own copy of the repo in ext/googletest (see Local Builds in README)"
)
option(AVIF_LOCAL_FUZZTEST
"Build the Google FuzzTest framework by providing your own copy of the repo in ext/fuzztest (see Local Builds in README)"
OFF
)

option(AVIF_BUILD_APPS "Build avif apps." OFF)
option(AVIF_BUILD_TESTS "Build avif tests." OFF)
option(
AVIF_ENABLE_COMPLIANCE_WARDEN
"Check all avifEncoderFinish() output for AVIF specification compliance. Depends on gpac/ComplianceWarden which can be added with ext/compliance_warden.sh"
OFF
)

set(AVIF_USE_CXX OFF)

if(AVIF_BUILD_APPS
OR AVIF_ENABLE_FUZZTEST
OR AVIF_ENABLE_GTEST
OR AVIF_CODEC_LIBGAV1 STREQUAL "LOCAL"
OR AVIF_CODEC_LIBGAV1 STREQUAL "SYSTEM"
option(
AVIF_ENABLE_GOLDEN_TESTS
"Build tests that compare encoding outputs to golden files. Needs AVIF_BUILD_APPS=ON and AVIF_BUILD_TESTS=ON, and depends on MP4box which can be built with ext/mp4box.sh"
OFF
)
set(AVIF_USE_CXX ON)
endif()
option(AVIF_ENABLE_GTEST
"Build avif C++ tests, which depend on GoogleTest. Requires GoogleTest. Has no effect unless AVIF_BUILD_TESTS is ON." ON
)
option(AVIF_ENABLE_FUZZTEST "Build avif fuzztest targets. Requires Google FuzzTest. Has no effect unless AVIF_BUILD_TESTS is ON."
OFF
)
option(AVIF_LOCAL_FUZZTEST
"Build the Google FuzzTest framework by providing your own copy of the repo in ext/fuzztest (see Local Builds in README)"
OFF
)

# Whether the libavif library uses c++ indirectly (e.g. through linking to libyuv).
set(AVIF_LIB_USE_CXX OFF)

if(APPLE)
set(XCRUN xcrun)
Expand Down Expand Up @@ -244,6 +248,7 @@ if(AVIF_LIBYUV_ENABLED)
target_compile_definitions(avif_obj PRIVATE -DAVIF_LIBYUV_ENABLED=1)
avif_target_link_library(yuv::yuv)
set(AVIF_PKG_CONFIG_EXTRA_LIBS_PRIVATE "${AVIF_PKG_CONFIG_EXTRA_LIBS_PRIVATE} -lyuv")
set(AVIF_LIB_USE_CXX ON)
endif(AVIF_LIBYUV_ENABLED)

set_local_or_system_option("LIBSHARPYUV" "OFF" "Use libsharpyuv.")
Expand Down Expand Up @@ -271,8 +276,7 @@ if(MSVC)
message(STATUS "libavif: Enabling warnings for MSVC")
target_compile_options(
avif_obj
PUBLIC $<BUILD_INTERFACE:
/W4 # For clang-cl, /W4 enables -Wall and -Wextra
PUBLIC $<BUILD_INTERFACE: /W4 # For clang-cl, /W4 enables -Wall and -Wextra
/wd4324 # Disable: structure was padded due to alignment specifier
>
)
Expand Down Expand Up @@ -325,9 +329,12 @@ if(AVIF_ENABLE_NODISCARD)
else()
unset(CMAKE_C_STANDARD)
set_property(TARGET avif_obj PROPERTY C_STANDARD)
target_compile_options(avif_obj PUBLIC $<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:C>:-std=gnu2x>>)
if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU")
target_compile_options(avif_obj PUBLIC $<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:C>:-std=gnu2x>>)
elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
target_compile_options(avif_obj PUBLIC $<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:C>:/std:clatest>>)
endif()
endif()
target_compile_options(avif_obj PUBLIC $<BUILD_INTERFACE:-Wunused-result>)
target_compile_definitions(avif_obj PUBLIC $<BUILD_INTERFACE:AVIF_ENABLE_NODISCARD=1>)
endif()

Expand Down Expand Up @@ -399,7 +406,7 @@ if(AVIF_ENABLE_COMPLIANCE_WARDEN)
message(FATAL_ERROR "AVIF_ENABLE_COMPLIANCE_WARDEN: ext/ComplianceWarden is missing, bailing out")
endif()

set(AVIF_USE_CXX ON)
set(AVIF_LIB_USE_CXX ON)
target_compile_definitions(avif_obj PRIVATE AVIF_ENABLE_COMPLIANCE_WARDEN)

list(
Expand Down Expand Up @@ -479,6 +486,7 @@ endif()

check_avif_option(AVIF_CODEC_LIBGAV1 TARGET libgav1::libgav1 PKG_NAME libgav1)
if(AVIF_CODEC_LIBGAV1_ENABLED)
set(AVIF_LIB_USE_CXX ON)
target_compile_definitions(avif_obj PRIVATE -DAVIF_CODEC_LIBGAV1=1)
target_sources(avif_obj PRIVATE src/codec_libgav1.c)
avif_target_link_library(libgav1::libgav1)
Expand Down Expand Up @@ -541,6 +549,11 @@ if(AVIF_CODEC_AOM_ENABLED)

message(STATUS "libavif: Codec enabled: aom (${AVIF_CODEC_AOM_ENCODE_DECODE_CONFIG})")
set(AVIF_PKG_CONFIG_EXTRA_REQUIRES_PRIVATE "${AVIF_PKG_CONFIG_EXTRA_REQUIRES_PRIVATE} aom")

get_target_property(AOM_INTERFACE_LINK_LIBRARIES aom INTERFACE_LINK_LIBRARIES)
if(AOM_INTERFACE_LINK_LIBRARIES MATCHES vmaf)
set(AVIF_LIB_USE_CXX ON)
endif()
endif()

check_avif_option(AVIF_CODEC_AVM TARGET aom PKG_NAME avm)
Expand Down Expand Up @@ -569,6 +582,17 @@ if(NOT AVIF_CODEC_AOM_ENABLED
message(WARNING "libavif: No decoding library is enabled.")
endif()

if(AVIF_LIB_USE_CXX OR (AVIF_BUILD_APPS AND AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP) OR (AVIF_BUILD_TESTS AND (AVIF_ENABLE_FUZZTEST
OR AVIF_ENABLE_GTEST))
)
enable_language(CXX)
if(AVIF_ENABLE_NODISCARD)
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 14)
endif()
endif()

set_target_properties(avif_obj PROPERTIES C_VISIBILITY_PRESET hidden)
target_include_directories(avif_obj PUBLIC $<BUILD_INTERFACE:${libavif_SOURCE_DIR}/include>)
if(NOT AVIF_LIBYUV_ENABLED)
Expand All @@ -589,7 +613,7 @@ target_link_libraries(avif PRIVATE avif_obj)
target_include_directories(avif PUBLIC $<BUILD_INTERFACE:${libavif_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
if(BUILD_SHARED_LIBS)
target_compile_definitions(avif INTERFACE AVIF_DLL)
if(AVIF_USE_CXX)
if(AVIF_LIB_USE_CXX)
set_target_properties(avif PROPERTIES LINKER_LANGUAGE "CXX")
endif()
endif()
Expand Down Expand Up @@ -620,7 +644,7 @@ if(AVIF_BUILD_EXAMPLES)

foreach(EXAMPLE ${AVIF_EXAMPLES})
add_executable(${EXAMPLE} examples/${EXAMPLE}.c)
if(AVIF_USE_CXX)
if(AVIF_LIB_USE_CXX)
set_target_properties(${EXAMPLE} PROPERTIES LINKER_LANGUAGE "CXX")
endif()
target_link_libraries(${EXAMPLE} avif)
Expand All @@ -635,39 +659,6 @@ if(NOT SKIP_INSTALL_ALL)
include(GNUInstallDirs)
endif()

if(AVIF_CODEC_AOM_ENABLED)
get_target_property(AOM_INTERFACE_LINK_LIBRARIES aom INTERFACE_LINK_LIBRARIES)
if(AOM_INTERFACE_LINK_LIBRARIES MATCHES vmaf)
# vmaf only affects the avifenc and avifdec targets below, not the avif library nor examples targets.
set(AVIF_USE_CXX ON)
endif()
endif()

if(AVIF_USE_CXX)
enable_language(CXX)
if(AVIF_ENABLE_NODISCARD)
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 14)
endif()
endif()

option(AVIF_BUILD_APPS "Build avif apps." OFF)
option(AVIF_BUILD_TESTS "Build avif tests." OFF)
option(
AVIF_ENABLE_GOLDEN_TESTS
"Build tests that compare encoding outputs to golden files. Needs AVIF_BUILD_APPS=ON, and depends on MP4box which can be built with ext/mp4box.sh"
OFF
)
option(AVIF_ENABLE_GTEST
"Build avif C++ tests, which depend on GoogleTest. Requires GoogleTest. Has no effect unless AVIF_BUILD_TESTS is ON." ON
)
option(
AVIF_ENABLE_FUZZTEST
"Build avif fuzztest targets. Requires Google FuzzTest. Has no effect unless AVIF_BUILD_TESTS and AVIF_ENABLE_GTEST are ON."
OFF
)

if(AVIF_BUILD_APPS OR (AVIF_BUILD_TESTS AND (AVIF_ENABLE_FUZZTEST OR AVIF_ENABLE_GTEST)))
if(AVIF_ZLIBPNG STREQUAL "OFF")
message(FATAL_ERROR "libavif: AVIF_ZLIBPNG cannot be OFF when AVIF_BUILD_APPS or AVIF_BUILD_TESTS is ON")
Expand All @@ -682,8 +673,8 @@ if(AVIF_BUILD_APPS OR (AVIF_BUILD_TESTS AND (AVIF_ENABLE_FUZZTEST OR AVIF_ENABLE
endif()

add_library(
avif_apps_obj OBJECT $<TARGET_OBJECTS:avif_obj> apps/shared/avifexif.c apps/shared/avifjpeg.c apps/shared/avifpng.c
apps/shared/avifutil.c apps/shared/iccmaker.c apps/shared/y4m.c third_party/iccjpeg/iccjpeg.c
avif_apps_obj OBJECT apps/shared/avifexif.c apps/shared/avifjpeg.c apps/shared/avifpng.c apps/shared/avifutil.c
apps/shared/iccmaker.c apps/shared/y4m.c third_party/iccjpeg/iccjpeg.c
)
# Instead of building avif_apps/avif_apps_internal and linking to avif/avif_internal, avif_apps_obj only does one compilation.
# Still, the compile definitions needs to be passed from avif to avif_apps. The following also passes them to avif_apps_internal but AVIF_DLL does not impact avif_apps_internal.
Expand Down Expand Up @@ -740,7 +731,7 @@ if(AVIF_BUILD_APPS)
target_link_options(avifenc PRIVATE /MANIFEST:NO)
endif()
endif()
if(AVIF_USE_CXX)
if(AVIF_LIB_USE_CXX)
set_target_properties(avifenc PROPERTIES LINKER_LANGUAGE "CXX")
endif()
target_link_libraries(avifenc avif_apps)
Expand All @@ -751,7 +742,7 @@ if(AVIF_BUILD_APPS)
target_link_options(avifdec PRIVATE /MANIFEST:NO)
endif()
endif()
if(AVIF_USE_CXX)
if(AVIF_LIB_USE_CXX)
set_target_properties(avifdec PROPERTIES LINKER_LANGUAGE "CXX")
endif()
target_link_libraries(avifdec avif_apps)
Expand Down Expand Up @@ -797,6 +788,18 @@ endif()
if(AVIF_BUILD_TESTS)
enable_testing() # Allow ctest to be called from top-level directory.
add_subdirectory(tests)
# An executable on Windows searches for DLLs it is linked with in the same
# directory where it resides and in the directories listed in the Path
# environment variable. For convenience, copy avif.dll to the tests binary
# directory to allow are_images_equal.exe and the test programs find it.
if(WIN32 AND BUILD_SHARED_LIBS)
add_custom_command(
TARGET avif
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:avif>" ${CMAKE_CURRENT_BINARY_DIR}/tests
COMMENT "Copying avif.dll to the tests binary directory"
)
endif()
endif()

option(AVIF_BUILD_MAN_PAGES "Build avif man pages." OFF)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ CMakeLists.txt files from the top-level folder:
cmake-format -i \
CMakeLists.txt \
tests/CMakeLists.txt \
cmake/Modules/Find*.cmake \
cmake/Modules/*.cmake \
contrib/CMakeLists.txt \
contrib/gdk-pixbuf/CMakeLists.txt \
android_jni/avifandroidjni/src/main/jni/CMakeLists.txt
Expand Down
11 changes: 6 additions & 5 deletions apps/avifgainmaputil/combine_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ avifResult CombineCommand::Run() {
arg_alternate_cicp_.value().matrix_coefficients;
}

const int downscaling = std::max<int>(1, arg_downscaling_);
const uint32_t gain_map_width = std::max<uint32_t>(
std::round((float)base_image->width / downscaling), 1u);
const uint32_t gain_map_height = std::max<uint32_t>(
std::round((float)base_image->height / downscaling), 1u);
const uint32_t downscaling = std::max<int>(1, arg_downscaling_);
const uint32_t rounding = downscaling / 2;
const uint32_t gain_map_width =
std::max((base_image->width + rounding) / downscaling, 1u);
const uint32_t gain_map_height =
std::max((base_image->height + rounding) / downscaling, 1u);
std::cout << "Creating a gain map of size " << gain_map_width << " x "
<< gain_map_height << "\n";

Expand Down
7 changes: 4 additions & 3 deletions apps/avifgainmaputil/swapbase_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ avifResult ChangeBase(const avifImage& image, int depth,
swapped->yuvFormat = yuvFormat;

const float headroom =
static_cast<double>(image.gainMap->metadata.alternateHdrHeadroomN) /
static_cast<float>(image.gainMap->metadata.alternateHdrHeadroomN) /
image.gainMap->metadata.alternateHdrHeadroomD;
const bool tone_mapping_to_sdr = (headroom == 0.0f);

Expand All @@ -38,8 +38,9 @@ avifResult ChangeBase(const avifImage& image, int depth,
AVIF_TRANSFER_CHARACTERISTICS_UNSPECIFIED) {
// Default to PQ for HDR and sRGB for SDR if unspecified.
const avifTransferCharacteristics transfer_characteristics =
tone_mapping_to_sdr ? AVIF_TRANSFER_CHARACTERISTICS_SRGB
: AVIF_TRANSFER_CHARACTERISTICS_PQ;
static_cast<avifTransferCharacteristics>(
tone_mapping_to_sdr ? AVIF_TRANSFER_CHARACTERISTICS_SRGB
: AVIF_TRANSFER_CHARACTERISTICS_PQ);
swapped->transferCharacteristics = transfer_characteristics;
}

Expand Down
8 changes: 4 additions & 4 deletions apps/avifgainmaputil/tonemap_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ avifResult TonemapCommand::Run() {
avifContentLightLevelInformationBox clli_box = {};
bool clli_set = false;
if (arg_clli_str_.value().size() > 0) {
std::vector<uint32_t> clli;
std::vector<uint16_t> clli;
if (!ParseList(arg_clli_str_, ',', 2, &clli)) {
std::cerr << "Invalid clli values, expected format: maxCLL,maxPALL where "
"both maxCLL and maxPALL are positive integers, got: "
Expand Down Expand Up @@ -129,9 +129,9 @@ avifResult TonemapCommand::Run() {
}
if (cicp.transfer_characteristics ==
AVIF_TRANSFER_CHARACTERISTICS_UNSPECIFIED) {
cicp.transfer_characteristics = tone_mapping_to_hdr
? AVIF_TRANSFER_CHARACTERISTICS_PQ
: AVIF_TRANSFER_CHARACTERISTICS_SRGB;
cicp.transfer_characteristics = static_cast<avifTransferCharacteristics>(
tone_mapping_to_hdr ? AVIF_TRANSFER_CHARACTERISTICS_PQ
: AVIF_TRANSFER_CHARACTERISTICS_SRGB);
}

// Determine output depth.
Expand Down
4 changes: 2 additions & 2 deletions apps/shared/avifjpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ static uint32_t avifJPEGReadUint32LittleEndian(const uint8_t * src)
// Reads a 2-byte unsigned integer in big-endian format from the raw bitstream src.
static uint16_t avifJPEGReadUint16BigEndian(const uint8_t * src)
{
return ((uint32_t)src[0] << 8) | ((uint32_t)src[1] << 0);
return (uint16_t)((src[0] << 8) | (src[1] << 0));
}

// Reads a 2-byte unsigned integer in little-endian format from the raw bitstream src.
static uint16_t avifJPEGReadUint16LittleEndian(const uint8_t * src)
{
return ((uint32_t)src[0] << 0) | ((uint32_t)src[1] << 8);
return (uint16_t)((src[0] << 0) | (src[1] << 8));
}

// Reads 'numBytes' at 'offset', stores them in 'bytes' and increases 'offset'.
Expand Down
Loading

0 comments on commit 43f599f

Please sign in to comment.