Skip to content
Merged
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v0.7.0

- Replace deps.sh by cmake/Modules.
- Bump the versions of dependencies.
- Add emscripten build support for CCGEN_ENABLE_JPEG=ON, CCGEN_ENABLE_WEBP=ON
and CCGEN_ENABLE_WEBP2=ON.

## v0.6.7

- Support images of dimensions below 8 pixels despite some distortion metrics.
Expand Down
503 changes: 369 additions & 134 deletions CMakeLists.txt

Large diffs are not rendered by default.

61 changes: 53 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@ Build `tools/ccgen.cc` and look at the description given by the `--help` flag.

The `libccgen` API entrypoint lies in `src/framework.h`.

## CMake build
## Build

The following instructions are used to build the library and the `ccgen` command
line tool.

### Requirements

```sh
# For libjxl
sudo apt install libhwy-dev
```

### Instructions

Clone the codec-compare-gen repository. Then run from its root folder:

```sh
./deps.sh
cmake -S . -B build -DCMAKE_CXX_COMPILER=clang++
cmake -S . -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
cmake --build build --parallel
```

Expand Down Expand Up @@ -59,20 +67,57 @@ build/ccgen \
## Tests

The following instructions are used to make sure the unit tests pass.
`libgtest-dev` must be installed on the system. Run `deps.sh` if not done yet.
`libgtest-dev` must be installed on the system.

```sh
cmake -S . -B build -DBUILD_TESTING=ON -DCMAKE_CXX_COMPILER=clang++
cmake --build build --parallel
ctest --test-dir build --output-on-failure -j7
cmake -S . -B build \
-DCCGEN_BUILD_TESTING=ON \
-DCCGEN_ENABLE_AVIF=ON \
-DCCGEN_ENABLE_HEIF=ON \
-DCCGEN_ENABLE_JPEG=ON \
-DCCGEN_ENABLE_JPEG2000=ON \
-DCCGEN_ENABLE_JPEGXL=ON \
-DCCGEN_ENABLE_WEBP=ON \
-DCCGEN_ENABLE_WEBP2=ON \
-DCCGEN_ENABLE_FFV1=ON \
-DCCGEN_ENABLE_BASIS=ON \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5
cmake --build build -j$(nproc)
ctest --test-dir build --output-on-failure -j$(nproc)
```

## WASM/emscripten build

```sh
emcmake cmake -S . -B build_wasm \
-DCCGEN_ENABLE_JPEGXL=OFF \
-DCCGEN_ENABLE_WEBP2=ON \
-DCCGEN_ENABLE_DSSIM=OFF \
-DCCGEN_WASM=ON \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF
emmake cmake --build build_wasm -j$(nproc)
```

### Typescript tests

```sh
emcmake cmake -S . -B build_wasm \
-DCCGEN_BUILD_TESTING=ON -DCCGEN_ENABLE_JPEG=ON -DCCGEN_ENABLE_JPEGXL=OFF \
-DCCGEN_ENABLE_WEBP=ON -DCCGEN_ENABLE_WEBP2=ON -DCCGEN_ENABLE_DSSIM=OFF \
-DCCGEN_WASM=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF
emmake cmake --build build_wasm -j$(nproc)
ctest --test-dir build --output-on-failure -j$(nproc)
```

## C++ style

Use the following to format the code:

```sh
clang-format -style=file -i src/*.cc src/*.h tests/*.cc tools/*.cc tools/*.h
clang-format -style=file -i src/* tests/*.cc tools/ wasm/*.cc
cmake-format -i CMakeLists.txt cmake/Modules/*
```

## License
Expand Down
22 changes: 22 additions & 0 deletions cmake/Modules/CcgenFetchContent.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
include(FetchContent)

function(ccgen_fetchcontent_makeavailable name)
FetchContent_GetProperties(${name})
if(NOT ${name}_POPULATED)
set(BUILD_SHARED_LIBS OFF)
set(BUILD_TESTING OFF)

FetchContent_MakeAvailable(${name})

FetchContent_GetProperties(${name})
set(${name}_SOURCE_DIR
${${name}_SOURCE_DIR}
PARENT_SCOPE)
set(${name}_BINARY_DIR
${${name}_BINARY_DIR}
PARENT_SCOPE)
set(${name}_POPULATED
${${name}_POPULATED}
PARENT_SCOPE)
endif()
endfunction()
19 changes: 19 additions & 0 deletions cmake/Modules/LocalBasisuniversal.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
include(FetchContent)
include(CcgenFetchContent)

FetchContent_Declare(
libbasisu
GIT_REPOSITORY "https://github.com/BinomialLLC/basis_universal.git"
GIT_TAG v2_1_0
GIT_PROGRESS ON
GIT_SHALLOW ON
UPDATE_COMMAND "")

set(BASISU_SSE
ON
CACHE INTERNAL "")

ccgen_fetchcontent_makeavailable(libbasisu)

target_include_directories(basisu_encoder
INTERFACE $<BUILD_INTERFACE:${libbasisu_SOURCE_DIR}>)
11 changes: 11 additions & 0 deletions cmake/Modules/LocalDssim.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include(FetchContent)

FetchContent_Declare(
dssim URL https://github.com/kornelski/dssim/archive/refs/tags/3.4.0.tar.gz
DOWNLOAD_EXTRACT_TIMESTAMP false)
FetchContent_MakeAvailable(dssim)

add_custom_target(
dssim_binary
COMMAND cargo build --release
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/_deps/dssim-src)
48 changes: 48 additions & 0 deletions cmake/Modules/LocalLibavif.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
include(FetchContent)
include(CcgenFetchContent)

FetchContent_Declare(
libavif
GIT_REPOSITORY "https://github.com/AOMediaCodec/libavif.git"
# GIT_TAG v1.4.1 does not contain the latest AVM tag.
GIT_TAG 257b1e45f979491d905786d80691ba33a7597290
GIT_PROGRESS ON
GIT_SHALLOW OFF
UPDATE_COMMAND "")

set(AVIF_BUILD_APPS
OFF
CACHE INTERNAL "")
set(AVIF_BUILD_EXAMPLES
OFF
CACHE INTERNAL "")
set(AVIF_BUILD_TESTS
OFF
CACHE INTERNAL "")
set(AVIF_CODEC_AOM
LOCAL
CACHE INTERNAL "")
set(AVIF_CODEC_DAV1D
LOCAL
CACHE INTERNAL "")
set(AVIF_CODEC_AVM
LOCAL
CACHE INTERNAL "")
set(AVIF_LIBYUV
LOCAL
CACHE INTERNAL "")
set(AVIF_LIBSHARPYUV
LOCAL
CACHE INTERNAL "")
set(AVIF_ENABLE_EXPERIMENTAL_MINI
ON
CACHE INTERNAL "")

include_directories("${CMAKE_BINARY_DIR}/flatbuffers/include")

ccgen_fetchcontent_makeavailable(libavif)

if(CCGEN_ENABLE_WEBP)
# To avoid building libsharpyuv twice.
add_dependencies(avif webp)
endif()
55 changes: 55 additions & 0 deletions cmake/Modules/LocalLibheif.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
include(FetchContent)
include(CcgenFetchContent)

FetchContent_Declare(
libheif
GIT_REPOSITORY "https://github.com/strukturag/libheif.git"
GIT_TAG v1.21.2
GIT_PROGRESS ON
GIT_SHALLOW ON
UPDATE_COMMAND "")

set(ENABLE_PLUGIN_LOADING
OFF
CACHE INTERNAL "")
set(WITH_AOM_DECODER
OFF
CACHE INTERNAL "")
set(WITH_AOM_ENCODER
ON
CACHE INTERNAL "")
set(WITH_DAV1D
ON
CACHE INTERNAL "")
set(WITH_LIBSHARPYUV
OFF
CACHE INTERNAL "")
set(ENABLE_MULTITHREADING_SUPPORT
OFF
CACHE INTERNAL "")
set(ENABLE_PARALLEL_TILE_DECODING
OFF
CACHE INTERNAL "")

# Reuse the libaom and dav1d dependencies from libavif.
set(AOM_INCLUDE_DIR
"${CMAKE_BINARY_DIR}/_deps/libaom-src/"
CACHE INTERNAL "")
set(AOM_LIBRARY
"${CMAKE_BINARY_DIR}/_deps/libaom-build/libaom.a"
CACHE INTERNAL "")
set(DAV1D_INCLUDE_DIR
"${CMAKE_BINARY_DIR}/_deps/dav1d-install/include/"
CACHE INTERNAL "")
set(DAV1D_LIBRARY
"${CMAKE_BINARY_DIR}/_deps/dav1d-install/lib/libdav1d.a"
CACHE INTERNAL "")

ccgen_fetchcontent_makeavailable(libheif)

target_include_directories(
heif INTERFACE $<BUILD_INTERFACE:${libheif_SOURCE_DIR}>/libheif/api)
target_include_directories(heif
INTERFACE $<BUILD_INTERFACE:${libheif_BINARY_DIR}>)

add_dependencies(heif aom dav1d)
68 changes: 68 additions & 0 deletions cmake/Modules/LocalLibjxl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
include(FetchContent)
include(CcgenFetchContent)

FetchContent_Declare(
libjxl
GIT_REPOSITORY "https://github.com/libjxl/libjxl.git"
GIT_TAG v0.11.2
GIT_PROGRESS ON
GIT_SHALLOW ON
UPDATE_COMMAND "")

set(JPEGXL_ENABLE_BENCHMARK
OFF
CACHE INTERNAL "")
set(JPEGXL_ENABLE_DOXYGEN
OFF
CACHE INTERNAL "")
set(JPEGXL_ENABLE_EXAMPLES
OFF
CACHE INTERNAL "")
set(JPEGXL_ENABLE_JNI
OFF
CACHE INTERNAL "")
set(JPEGXL_ENABLE_MANPAGES
OFF
CACHE INTERNAL "")
set(JPEGXL_ENABLE_OPENEXR
OFF
CACHE INTERNAL "")
set(JPEGXL_ENABLE_SJPEG
OFF
CACHE INTERNAL "")
set(JPEGXL_ENABLE_TRANSCODE_JPEG
OFF
CACHE INTERNAL "")
set(JPEGXL_ENABLE_WASM_THREADS
OFF
CACHE INTERNAL "")
set(JPEGXL_FORCE_SYSTEM_BROTLI
OFF
CACHE INTERNAL "")
set(JPEGXL_FORCE_SYSTEM_HWY
OFF
CACHE INTERNAL "")

# jpegli was still part of libjxl in v0.11.2 but will be removed. See
# https://github.com/libjxl/libjxl/pull/4657.
set(JPEGXL_ENABLE_JPEGLI
ON
CACHE INTERNAL "")
set(JPEGXL_ENABLE_JPEGLI_LIBJPEG
OFF
CACHE INTERNAL "")

# JPEGXL_ENABLE_DEVTOOLS=ON for Butteraugli and SSIMULACRA2 metric binaries. See
# https://github.com/cloudinary/ssimulacra2/blob/d2be72505ddc5c92aeb30f4a7f3ab53db45b314b/build_ssimulacra_from_libjxl_repo
set(JPEGXL_ENABLE_DEVTOOLS
ON
CACHE INTERNAL "")
# JPEGXL_ENABLE_DEVTOOLS=ON somehow requires JPEGXL_ENABLE_TOOLS=ON.
set(JPEGXL_ENABLE_TOOLS
ON
CACHE INTERNAL "")

ccgen_fetchcontent_makeavailable(libjxl)

target_include_directories(jxl
INTERFACE $<BUILD_INTERFACE:${libjxl_SOURCE_DIR}>)
30 changes: 30 additions & 0 deletions cmake/Modules/LocalLibpng.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
include(FetchContent)
include(CcgenFetchContent)

FetchContent_Declare(
PNG
GIT_REPOSITORY "https://github.com/pnggroup/libpng"
GIT_TAG v1.6.58
GIT_PROGRESS ON
UPDATE_COMMAND "" OVERRIDE_FIND_PACKAGE SYSTEM)

set(PNG_SHARED
OFF
CACHE INTERNAL "")
set(ZLIB_USE_STATIC_LIBS
ON
CACHE INTERNAL "")

ccgen_fetchcontent_makeavailable(PNG)

target_include_directories(png_static
INTERFACE "$<BUILD_INTERFACE:${png_SOURCE_DIR}>")
target_link_libraries(png_static PRIVATE zlibstatic)
target_link_libraries(png_static PRIVATE ZLIB::ZLIB)

add_library(PNG::PNG ALIAS png_static)

add_dependencies(png_static zlibstatic)

set(PNG_INCLUDE_DIRS ${PNG_SOURCE_DIR})
set(PNG_LIBRARIES png_static)
Loading