Skip to content

Commit

Permalink
git merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
dukesook committed Oct 15, 2024
2 parents 25fadd5 + 009c34e commit 6065687
Show file tree
Hide file tree
Showing 303 changed files with 23,260 additions and 8,451 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/coverity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ name: coverity

on:
push:
branches: [ coverity ]
branches: [ master, coverity ]

jobs:
scan:
runs-on: ubuntu-20.04
env:
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
WITH_AOM: 1
WITH_DAV1D: 1
WITH_GRAPHICS: 1
WITH_LIBDE265: 1
WITH_RAV1E: 1
WITH_X265: 1
steps:
- uses: actions/checkout@v4
Expand All @@ -21,7 +23,7 @@ jobs:
with:
path: |
coverity_tool.tar.gz
key: ${{ runner.os }}
key: coverity_tool-${{ runner.os }}

- name: Download Coverity build tool
run: |
Expand All @@ -39,10 +41,13 @@ jobs:
- name: Build with Coverity build tool
run: |
export PATH=`pwd`/coverity_tool/bin:$PATH
cov-build --dir cov-int make
export PATH=$(pwd)/coverity_tool/bin:$PATH
export PKG_CONFIG_PATH="$(pwd)/libde265/dist/lib/pkgconfig/:$(pwd)/third-party/rav1e/dist/lib/pkgconfig/:$(pwd)/third-party/dav1d/dist/lib/x86_64-linux-gnu/pkgconfig/"
cmake --preset=develop .
cov-build --dir cov-int make -j$(nproc)
- name: Submit build result to Coverity Scan
if: github.ref == 'refs/heads/coverity'
run: |
tar czvf libheif.tar.gz cov-int
curl --form token=$TOKEN \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/emscripten.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
emscripten:
env:
EMSCRIPTEN_VERSION: 3.1.47
EMSCRIPTEN_VERSION: 3.1.61
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
build:
strategy:
matrix:
runner: [ macos-12, macos-14 ]
runner: [ macos-13, macos-15 ]
env:
- { NAME: "nothing" }
- { NAME: "cmake", WITH_GRAPHICS: 1, WITH_X265: 1, WITH_AOM: 1, WITH_LIBDE265: 1 }
Expand Down
96 changes: 85 additions & 11 deletions 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.18.0)
project(libheif LANGUAGES C CXX VERSION 1.18.2)

# 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 All @@ -25,10 +25,15 @@ if (HAVE_UNISTD_H)
add_definitions(-DHAVE_UNISTD_H)
endif()

set(CMAKE_COMPILE_WARNING_AS_ERROR ON CACHE BOOL "Treat compilation warning as error")

if(NOT MSVC)
# cmake 3.24 introduces this variable, but for backward compatibility, we set it explicitly
if (CMAKE_COMPILE_WARNING_AS_ERROR)
add_definitions(-Werror)
endif ()

add_definitions(-Wall)
add_definitions(-Werror)
add_definitions(-Wsign-compare)
add_definitions(-Wconversion)
add_definitions(-Wno-sign-conversion)
Expand All @@ -41,7 +46,7 @@ if(NOT MSVC)
endif ()
endif()

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand Down Expand Up @@ -70,11 +75,19 @@ add_compile_definitions(IS_BIG_ENDIAN=${IS_BIG_ENDIAN})
# --- codec plugins

option(ENABLE_PLUGIN_LOADING "Support loading of plugins" ON)
set(PLUGIN_DIRECTORY "${CMAKE_INSTALL_FULL_LIBDIR}/libheif" CACHE STRING "Plugin install directory")
set(PLUGIN_DIRECTORY "${CMAKE_INSTALL_FULL_LIBDIR}/libheif" CACHE STRING "Plugin directory")
set(PLUGIN_INSTALL_DIRECTORY "" CACHE STRING "Plugin install directory (leaving it empty will use PLUGIN_DIRECTORY)")

if (ENABLE_PLUGIN_LOADING)
set(PLUGIN_LOADING_SUPPORTED_AND_ENABLED TRUE)
install(DIRECTORY DESTINATION ${PLUGIN_DIRECTORY} DIRECTORY_PERMISSIONS

if (PLUGIN_INSTALL_DIRECTORY STREQUAL "")
set(COMPUTED_PLUGIN_INSTALL_DIRECTORY ${PLUGIN_DIRECTORY})
else ()
set(COMPUTED_PLUGIN_INSTALL_DIRECTORY ${PLUGIN_INSTALL_DIRECTORY})
endif ()

install(DIRECTORY DESTINATION ${COMPUTED_PLUGIN_INSTALL_DIRECTORY} DIRECTORY_PERMISSIONS
OWNER_WRITE OWNER_READ OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
Expand Down Expand Up @@ -153,6 +166,37 @@ if (WITH_VVDEC)
endif()
endif ()

# vvenc

plugin_option(VVENC "vvenc VVC encoder (experimental)" OFF OFF)
if (WITH_VVENC)
# TODO: how to do configure vvenc cleanly?
find_package(Threads REQUIRED)
find_package(vvenc 1.12.0)
if (vvenc_FOUND)
set(vvenc_LIBRARIES vvenc::vvenc)
endif()
endif ()

# openh264 decoder

plugin_option(OpenH264_DECODER "OpenH264 decoder" ON OFF)
# plugin_option(OpenH264_ENCODER "OpenH264 encoder" ON OFF)
if (WITH_OpenH264_ENCODER OR WITH_OpenH264_DECODER)
find_package(OpenH264)

# When decoding/encoding is disabled, overwrite the *_FOUND variables, because they are used to ultimately decide what to build.
# TODO
if (OpenH264_FOUND AND WITH_OpenH264_DECODER)
set(OpenH264_DECODER_FOUND TRUE)
endif()
# if (OpenH264_FOUND AND WITH_OpenH264_ENCODER)
# set(OpenH264_ENCODER_FOUND TRUE)
# endif()
endif()



# dav1d

plugin_option(DAV1D "Dav1d AV1 decoder" OFF ON)
Expand Down Expand Up @@ -240,11 +284,14 @@ plugin_compilation_info(SvtEnc SvtEnc "SVT AV1 encoder")
plugin_compilation_info(RAV1E RAV1E "Rav1e AV1 encoder")
plugin_compilation_info(JPEG_DECODER JPEG "JPEG decoder")
plugin_compilation_info(JPEG_ENCODER JPEG "JPEG encoder")
plugin_compilation_info(OpenH264_DECODER OpenH264_DECODER "OpenH264 decoder")
# plugin_compilation_info(OpenH264_ENCODER OpenH264_ENCODER "OpenH264 encoder")
plugin_compilation_info(OpenJPEG_DECODER OpenJPEG "OpenJPEG J2K decoder")
plugin_compilation_info(OpenJPEG_ENCODER OpenJPEG "OpenJPEG J2K encoder")
# plugin_compilation_info(OPENJPH_DECODER OPENJPH "OpenJPH HT-J2K decoder")
plugin_compilation_info(OPENJPH_ENCODER OPENJPH "OpenJPH HT-J2K encoder")
plugin_compilation_info(UVG266_ENCODER UVG266 "uvg266 VVC enc. (experimental)")
plugin_compilation_info(VVENC vvenc "vvenc VVC enc. (experimental)")
plugin_compilation_info(VVDEC vvdec "vvdec VVC dec. (experimental)")

# --- show summary which formats are supported
Expand Down Expand Up @@ -301,9 +348,18 @@ endif()
if (OPENJPH_FOUND AND WITH_OPENJPH_DECODER)
set(SUPPORTS_J2K_HT_ENCODING TRUE)
endif()
if (UVG266_FOUND)
if (UVG266_FOUND OR vvenc_FOUND)
set(SUPPORTS_VVC_ENCODING TRUE)
endif()
if (vvdec_FOUND AND WITH_VVDEC)
set(SUPPORTS_VVC_DECODING TRUE)
endif()
if (OpenH264_DECODER_FOUND)
set(SUPPORTS_AVC_DECODING TRUE)
endif()
if (OpenH264_ENCODER_FOUND)
set(SUPPORTS_AVC_ENCODING TRUE)
endif()

if (WITH_UNCOMPRESSED_CODEC)
set(SUPPORTS_UNCOMPRESSED_DECODING TRUE)
Expand All @@ -312,13 +368,15 @@ endif()

message("\n=== Supported formats ===")
message("format decoding encoding")
format_compilation_info("HEIC" SUPPORTS_HEIC_DECODING SUPPORTS_HEIC_ENCODING)
format_compilation_info("AVC" SUPPORTS_AVC_DECODING SUPPORTS_AVC_ENCODING)
format_compilation_info("AVIF" SUPPORTS_AVIF_DECODING SUPPORTS_AVIF_ENCODING)
format_compilation_info("VVC" FALSE SUPPORTS_VVC_ENCODING)
format_compilation_info("HEIC" SUPPORTS_HEIC_DECODING SUPPORTS_HEIC_ENCODING)
format_compilation_info("JPEG" SUPPORTS_JPEG_DECODING SUPPORTS_JPEG_ENCODING)
format_compilation_info("JPEG2000" SUPPORTS_J2K_DECODING SUPPORTS_J2K_ENCODING)
format_compilation_info("JPEG2000-HT" SUPPORTS_J2K_HT_DECODING SUPPORTS_J2K_HT_ENCODING)
format_compilation_info("Uncompressed" SUPPORTS_UNCOMPRESSED_DECODING SUPPORTS_UNCOMPRESSED_ENCODING)
format_compilation_info("VVC" SUPPORTS_VVC_DECODING SUPPORTS_VVC_ENCODING)

message("")

# --- Libsharpyuv color space transforms
Expand Down Expand Up @@ -383,8 +441,22 @@ endif()
if (LIBSHARPYUV_FOUND)
list(APPEND REQUIRES_PRIVATE "libsharpyuv")
endif()
if (WITH_DEFLATE_HEADER_COMPRESSION)
list(APPEND REQUIRES_PRIVATE "zlib")
if (WITH_HEADER_COMPRESSION OR WITH_UNCOMPRESSED_CODEC)
find_package(ZLIB)
if (ZLIB_FOUND)
message("zlib found")
list(APPEND REQUIRES_PRIVATE "zlib")
else()
message("zlib not found")
endif()

find_package(Brotli)
if (Brotli_FOUND)
message("Brotli found")
list(APPEND REQUIRES_PRIVATE "libbrotlidec")
else()
message("Brotli not found")
endif()
endif()

list(JOIN REQUIRES_PRIVATE " " REQUIRES_PRIVATE)
Expand All @@ -409,7 +481,7 @@ option(WITH_GDK_PIXBUF "Build gdk-pixbuf plugin" ON)

option(WITH_REDUCED_VISIBILITY "Reduced symbol visibility in library" ON)

option(WITH_DEFLATE_HEADER_COMPRESSION OFF)
option(WITH_HEADER_COMPRESSION OFF)
option(ENABLE_MULTITHREADING_SUPPORT "Switch off for platforms without multithreading support" ON)
option(ENABLE_PARALLEL_TILE_DECODING "Will launch multiple decoders to decode tiles in parallel (requires ENABLE_MULTITHREADING_SUPPORT)" ON)

Expand All @@ -419,6 +491,8 @@ else ()
set(CMAKE_CXX_VISIBILITY_PRESET default)
endif ()

add_subdirectory(heifio)

if(WITH_EXAMPLES)
add_subdirectory (examples)
endif()
Expand Down
7 changes: 4 additions & 3 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"CMAKE_BUILD_TYPE": "Debug",
"BUILD_SHARED_LIBS": "ON",
"BUILD_TESTING" : "ON",
"WITH_EXPERIMENTAL_FEATURES" : "ON",

"ENABLE_PLUGIN_LOADING" : "OFF",
"WITH_AOM_DECODER" : "ON",
Expand Down Expand Up @@ -45,7 +46,7 @@
"WITH_FFMPEG_DECODER_PLUGIN" : "OFF",

"WITH_REDUCED_VISIBILITY" : "OFF",
"WITH_DEFLATE_HEADER_COMPRESSION" : "ON",
"WITH_HEADER_COMPRESSION" : "ON",
"WITH_LIBSHARPYUV" : "ON",
"WITH_EXAMPLES": "ON",
"WITH_FUZZERS": "OFF"
Expand Down Expand Up @@ -91,7 +92,7 @@
"WITH_FFMPEG_DECODER_PLUGIN" : "ON",

"WITH_REDUCED_VISIBILITY" : "ON",
"WITH_DEFLATE_HEADER_COMPRESSION" : "ON",
"WITH_HEADER_COMPRESSION" : "ON",
"WITH_LIBSHARPYUV" : "ON",
"WITH_EXAMPLES": "ON",
"WITH_FUZZERS": "OFF"
Expand Down Expand Up @@ -123,7 +124,7 @@
"WITH_FFMPEG_DECODER" : "OFF",

"WITH_REDUCED_VISIBILITY" : "ON",
"WITH_DEFLATE_HEADER_COMPRESSION" : "OFF",
"WITH_HEADER_COMPRESSION" : "OFF",
"WITH_LIBSHARPYUV" : "ON",
"WITH_EXAMPLES": "ON",
"WITH_FUZZERS": "OFF"
Expand Down
47 changes: 30 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ For AVIF, libaom, dav1d, svt-av1, or rav1e are used as codecs.

libheif has support for:

* HEIC, AVIF, JPEG-in-HEIF, JPEG2000, uncompressed (ISO/IEC 23001-17:2023)
* HEIC, AVIF, VVC, AVC, JPEG-in-HEIF, JPEG2000, uncompressed (ISO/IEC 23001-17:2024) codecs
* alpha channels, depth maps, thumbnails, auxiliary images
* multiple images in a file
* tiled images with decoding individual tiles and encoding tiled images by adding tiles one after another
* HDR images, correct color transform according to embedded color profiles
* image transformations (crop, mirror, rotate), overlay images
* plugin interface to add alternative codecs
Expand All @@ -26,22 +27,23 @@ libheif has support for:
* decoding of files while downloading (e.g. extract image size before file has been completely downloaded)

Supported codecs:
| Format | Decoders | Encoders |
|:-------------|:-------------------:|:---------------------:|
| HEIC | libde265, ffmpeg | x265, kvazaar |
| AVIF | AOM, dav1d | AOM, rav1e, svt-av1 |
| VVC | vvdec (experimental)| uvg266 (experimental) |
| JPEG | libjpeg(-turbo) | libjpeg(-turbo) |
| JPEG2000 | OpenJPEG | OpenJPEG |
| uncompressed | built-in | built-in |
| Format | Decoders | Encoders |
|:-------------|:-------------------:|:----------------------------:|
| HEIC | libde265, ffmpeg | x265, kvazaar |
| AVIF | AOM, dav1d | AOM, rav1e, svt-av1 |
| VVC | vvdec | vvenc, uvg266 |
| AVC | openh264 | - |
| JPEG | libjpeg(-turbo) | libjpeg(-turbo) |
| JPEG2000 | OpenJPEG | OpenJPEG |
| uncompressed | built-in | built-in |

## API

The library has a C API for easy integration and wide language support.

The decoder automatically supports both HEIF and AVIF through the same API. No changes are required to existing code to support AVIF.
The decoder automatically supports both HEIF and AVIF (and the other compression formats) through the same API. The same code decoding code can be used to decode any of them.
The encoder can be switched between HEIF and AVIF simply by setting `heif_compression_HEVC` or `heif_compression_AV1`
to `heif_context_get_encoder_for_format()`.
to `heif_context_get_encoder_for_format()`, or using any of the other compression formats.

Loading the primary image in an HEIF file is as easy as this:

Expand Down Expand Up @@ -112,6 +114,13 @@ Code using the C++ API is much less verbose than using the C API directly.

There is also an experimental Go API, but this is not stable yet.

### Reading and Writing Tiled Images

For very large resolution images, it is not always feasible to process the whole image.
In this case, `libheif` can process the image tile by tile.
See [this tutorial](https://github.com/strukturag/libheif/wiki/Reading-and-Writing-Tiled-Images) on how to use the API for this.


## Compiling

This library uses the CMake build system (the earlier autotools build files have been removed in v1.16.0).
Expand Down Expand Up @@ -155,22 +164,25 @@ For each codec, there are two configuration variables:
* `WITH_{codec}_PLUGIN`: when enabled, the codec is compiled as a separate plugin.

In order to use dynamic plugins, also make sure that `ENABLE_PLUGIN_LOADING` is enabled.
The placeholder `{codec}` can have these values: `LIBDE265`, `X265`, `AOM_DECODER`, `AOM_ENCODER`, `SvtEnc`, `DAV1D`, `FFMPEG_DECODER`, `JPEG_DECODER`, `JPEG_ENCODER`, `KVAZAAR`, `OpenJPEG_DECODER`, `OpenJPEG_ENCODER`, `OPENJPH_ENCODER`, `UVG266`, `VVDEC`.
The placeholder `{codec}` can have these values: `LIBDE265`, `X265`, `AOM_DECODER`, `AOM_ENCODER`, `SvtEnc`, `DAV1D`, `FFMPEG_DECODER`, `JPEG_DECODER`, `JPEG_ENCODER`, `KVAZAAR`, `OpenJPEG_DECODER`, `OpenJPEG_ENCODER`, `OPENJPH_ENCODER`, `VVDEC`, `VVENC`, `UVG266`.

Further options are:

* `WITH_UNCOMPRESSED_CODEC`: enable support for uncompressed images according to ISO/IEC 23001-17:2023. This is *experimental*
and not available as a dynamic plugin.
* `WITH_DEFLATE_HEADER_COMPRESSION`: enables support for compressed metadata. When enabled, it adds a dependency to `zlib`.
* `WITH_UNCOMPRESSED_CODEC`: enable support for uncompressed images according to ISO/IEC 23001-17:2024. This is *experimental*
and not available as a dynamic plugin. When enabled, it adds a dependency to `zlib`, and optionally will use `brotli`.
* `WITH_HEADER_COMPRESSION`: enables support for compressed metadata. When enabled, it adds a dependency to `zlib`.
Note that header compression is not widely supported yet.
* `WITH_LIBSHARPYUV`: enables high-quality YCbCr/RGB color space conversion algorithms (requires `libsharpyuv`,
e.g. from the `third-party` directory).
* `WITH_EXPERIMENTAL_FEATURES`: enables functions that are currently in development and for which the API is not stable yet.
When this is enabled, a header `heif_experimental.h` will be installed that contains this unstable API.
Distributions that rely on a stable API should not enable this.
* `ENABLE_MULTITHREADING_SUPPORT`: can be used to disable any multithreading support, e.g. for embedded platforms.
* `ENABLE_PARALLEL_TILE_DECODING`: when enabled, libheif will decode tiled images in parallel to speed up compilation.
* `PLUGIN_DIRECTORY`: the directory where libheif will search for dynamic plugins when the environment
variable `LIBHEIF_PLUGIN_PATH` is not set.
* `WITH_REDUCED_VISIBILITY`: only export those symbols into the library that are public API.
Has to be turned off for running the tests.
Has to be turned off for running some tests.

### macOS

Expand Down Expand Up @@ -347,6 +359,7 @@ to update the gdk-pixbuf loader database.
* [darktable](https://www.darktable.org)
* [digiKam 7.0.0](https://www.digikam.org/)
* [libvips](https://github.com/libvips/libvips)
* [kImageFormats](https://api.kde.org/frameworks/kimageformats/html/index.html)
* [libGD](https://libgd.github.io/)
* [Kodi HEIF image decoder plugin](https://kodi.wiki/view/Add-on:HEIF_image_decoder)
* [bimg](https://github.com/h2non/bimg)
Expand Down Expand Up @@ -377,5 +390,5 @@ The sample applications are distributed under the terms of the MIT License.
See COPYING for more details.
Copyright (c) 2017-2020 Struktur AG</br>
Copyright (c) 2017-2023 Dirk Farin</br>
Copyright (c) 2017-2024 Dirk Farin</br>
Contact: Dirk Farin <[email protected]>
Loading

0 comments on commit 6065687

Please sign in to comment.