Skip to content

Commit

Permalink
Move patent-encumbered HEVC dependencies to a plugin (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke authored Sep 28, 2020
1 parent 2006d72 commit 380da94
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 91 deletions.
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ Same as libvips-web + these extra dependencies:
| [fftw] | 3.3.8 | GPLv2 |
| [hdf5] | 1.12.0 | BSD-like |
| [imagemagick] | 6.9.11-30 | [ImageMagick License] (GPL-like) |
| [libde265] | 1.0.7 | LGPLv3 |
| [libheif] | 1.9.1 | LGPLv3 |
| [matio] | 1.5.18 | BSD 2-Clause |
| [nifticlib] | 2.0.0 | Public domain |
Expand All @@ -85,7 +84,6 @@ Same as libvips-web + these extra dependencies:
| [openslide] | 3.4.1 | LGPLv3 |
| [poppler] | 20.09.0 | GPLv2 |
| [sqlite] | 3.33.0 | Public domain |
| [x265] | 3.4 | GPLv2 |

[aom]: https://aomedia.googlesource.com/aom/
[Alliance for Open Media Patent License 1.0]: https://aomedia.org/license/patent-license/
Expand All @@ -94,7 +92,6 @@ Same as libvips-web + these extra dependencies:
[fftw]: https://github.com/FFTW/fftw3
[imagemagick]: https://github.com/ImageMagick/ImageMagick6
[ImageMagick License]: https://www.imagemagick.org/script/license.php
[libde265]: https://github.com/strukturag/libde265
[libheif]: https://github.com/strukturag/libheif
[matio]: https://github.com/tbeu/matio
[nifticlib]: https://nifti.nimh.nih.gov/
Expand All @@ -103,7 +100,6 @@ Same as libvips-web + these extra dependencies:
[openslide]: https://github.com/openslide/openslide
[poppler]: https://gitlab.freedesktop.org/poppler/poppler
[sqlite]: https://www.sqlite.org/
[x265]: https://bitbucket.org/multicoreware/x265_git/wiki/Home

## MozJPEG

Expand All @@ -124,3 +120,23 @@ argument. For example:
to maintain binary compatibility with libjpeg-turbo.

[mozjpeg]: https://github.com/mozilla/mozjpeg

## HEVC-related dependencies

The above "all" variant can optionally be built with libde265 and x265 to process
HEIC/HEIF images. This can be turned on with the `--with-hevc` argument. For example:

```bash
./build.sh all --with-hevc
```

These dependencies include HEVC-related logic and are therefore not included in the
prebuilt binaries while it is patent-encumbered.

| Dependency | Version | Used under the terms of |
|-----------------|-----------|--------------------------------------------------------------|
| [libde265] | 1.0.7 | LGPLv3 |
| [x265] | 3.4 | GPLv2 |

[libde265]: https://github.com/strukturag/libde265
[x265]: https://bitbucket.org/multicoreware/x265_git/wiki/Home
13 changes: 13 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Build libvips for Windows in a Docker container
OPTIONS:
--help Show the help and exit
--with-mozjpeg Build with MozJPEG instead of libjpeg-turbo
--with-hevc Build libheif with the HEVC-related dependencies
--with-llvm Build with llvm-mingw
DEPS:
Expand Down Expand Up @@ -53,6 +54,12 @@ else
with_mozjpeg=false
fi

if [[ "$*" == *--with-hevc* ]]; then
with_hevc=true
else
with_hevc=false
fi

if [[ "$*" == *--with-llvm* ]]; then
# This indicates that we don't need to force C++03
# compilication for some packages, we can safely use
Expand All @@ -76,6 +83,11 @@ else
with_llvm=false
fi

if [ "$with_hevc" = "true" ] && [ "$deps" = "web" ]; then
echo "ERROR: The HEVC-related dependencies can only be built for the \"all\" variant."
exit 1
fi

if [ "$type" = "static" ] && [ "$deps" = "all" ]; then
echo "ERROR: Distributing a statically linked library against GPL libraries, without releasing the code as GPL, violates the GPL license."
exit 1
Expand All @@ -102,6 +114,7 @@ docker run --rm -t \
-u $(id -u):$(id -g) \
-v $PWD/build:/data \
-e "MOZJPEG=$with_mozjpeg" \
-e "HEVC=$with_hevc" \
-e "LLVM=$with_llvm" \
libvips-build-win-mxe \
$deps \
Expand Down
4 changes: 4 additions & 0 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ if [ "$MOZJPEG" = "true" ]; then
plugins+=" $work_dir/plugins/mozjpeg"
fi

if [ "$HEVC" = "true" ]; then
plugins+=" $work_dir/plugins/hevc"
fi

# Avoid shipping the gettext DLL (libintl-8.dll),
# use a statically build dummy implementation instead.
# This intentionally disables the i18n features of (GNU)
Expand Down
2 changes: 1 addition & 1 deletion build/libheif.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ $(PKG)_VERSION := 1.9.1
$(PKG)_CHECKSUM := 5f65ca2bd2510eed4e13bdca123131c64067e9dd809213d7aef4dc5e37948bca
$(PKG)_PATCHES := $(realpath $(sort $(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/patches/$(PKG)-[0-9]*.patch)))
$(PKG)_GH_CONF := strukturag/libheif/releases,v
$(PKG)_DEPS := cc aom libde265 x265
$(PKG)_DEPS := cc aom

define $(PKG)_BUILD
# Disable multithreading when building with Win32 threads to
Expand Down
84 changes: 0 additions & 84 deletions build/overrides.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ imagemagick_CHECKSUM := 581e861341ec577daec8d0e2e5d69d8cb09b7fbda1e730169f4a0e20
imagemagick_PATCHES := $(realpath $(sort $(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/patches/imagemagick-[0-9]*.patch)))
imagemagick_GH_CONF := ImageMagick/ImageMagick6/tags

# upstream version is 2.4
x265_VERSION := 3.4
x265_CHECKSUM := c2047f23a6b729e5c70280d23223cb61b57bfe4ad4e8f1471eeee2a61d148672
x265_PATCHES := $(realpath $(sort $(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/patches/x265-[0-9]*.patch)))
x265_SUBDIR := x265_$(x265_VERSION)
x265_FILE := x265_$(x265_VERSION).tar.gz
# https://bitbucket.org/multicoreware/x265_git/issues/553/tarball-for-34-release-not-in-x265_git
x265_URL := https://bitbucket.org/multicoreware/x265/downloads/$(x265_FILE)
#x265_URL_2 := https://download.videolan.org/pub/videolan/x265/$(x265_FILE)
x265_URL_2 := https://ftp.osuosl.org/pub/blfs/conglomeration/x265/$(x265_FILE)

# upstream version is 2.40.5
librsvg_VERSION := 2.50.0
librsvg_CHECKSUM := b3fadba240f09b9c9898ab20cb7311467243e607cf8f928b7c5f842474ee3df4
Expand Down Expand Up @@ -227,8 +216,6 @@ zlib_PATCHES := $(realpath $(sort $(wildcard $(dir $(lastword $(MAKEFILE_LIST)))
# hdf5:
# Added: $(BUILD)~cmake
# Removed: pthreads
# x265:
# Replaced: yasm with $(BUILD)~nasm
# libjpeg-turbo:
# Replaced: yasm with $(BUILD)~nasm
# libxml2:
Expand All @@ -255,7 +242,6 @@ poppler_DEPS := cc mingw-std-threads cairo libjpeg-turbo freetype gli
librsvg_DEPS := $(filter-out libcroco libgsf ,$(librsvg_DEPS)) libxml2 rust
cairo_DEPS := cc fontconfig freetype-bootstrap glib libpng pixman zlib
hdf5_DEPS := $(filter-out pthreads ,$(hdf5_DEPS)) $(BUILD)~cmake
x265_DEPS := $(subst yasm,$(BUILD)~nasm,$(x265_DEPS))
libjpeg-turbo_DEPS := $(subst yasm,$(BUILD)~nasm,$(libjpeg-turbo_DEPS))
libxml2_DEPS := $(filter-out xz ,$(libxml2_DEPS))
fontconfig_DEPS := $(filter-out gettext,$(fontconfig_DEPS))
Expand Down Expand Up @@ -859,73 +845,3 @@ define hdf5_BUILD
echo 'set(HDF5_CXX_COMPILER_EXECUTABLE $(PREFIX)/bin/$(TARGET)-h5c++)'; \
) > '$(CMAKE_TOOLCHAIN_DIR)/$(PKG).cmake'
endef

# `-DENABLE_DYNAMIC_HDR10=ON` -> `-DENABLE_HDR10_PLUS=ON`
# x265 requires nasm 2.13 or newer (instead than yasm) after release 2.6.
define x265_BUILD
cd '$(BUILD_DIR)' && mkdir -p 10bit 12bit

# Fix ARM NEON includes when building the 10/12bit libraries
# https://bitbucket.org/multicoreware/x265_git/issues/549/fail-to-build-for-aarch64-and-armhf
$(if $(IS_ARM), \
$(foreach ARCH,aarch64 arm, \
$(SED) -i 's/PFX(\(.*\))/x265_\1/g' '$(SOURCE_DIR)/source/common/$(ARCH)/asm-primitives.cpp';) \
$(SED) -i 's/PFX(\(.*_neon\))/x265_\1/g' '$(SOURCE_DIR)/source/common/arm/dct8.h';)

# 12 bit
cd '$(BUILD_DIR)/12bit' && $(TARGET)-cmake '$(SOURCE_DIR)/source' \
-DHIGH_BIT_DEPTH=ON \
-DEXPORT_C_API=OFF \
-DENABLE_SHARED=OFF \
-DENABLE_ASSEMBLY=$(if $(call seq,64,$(BITS)),ON,OFF) \
-DENABLE_CLI=OFF \
-DENABLE_HDR10_PLUS=ON \
-DMAIN12=ON \
$(if $(IS_ARM), -DCROSS_COMPILE_ARM=ON)

$(MAKE) -C '$(BUILD_DIR)/12bit' -j '$(JOBS)'
cp '$(BUILD_DIR)/12bit/libx265.a' '$(BUILD_DIR)/libx265_main12.a'

# 10 bit
cd '$(BUILD_DIR)/10bit' && $(TARGET)-cmake '$(SOURCE_DIR)/source' \
-DHIGH_BIT_DEPTH=ON \
-DEXPORT_C_API=OFF \
-DENABLE_SHARED=OFF \
-DENABLE_ASSEMBLY=$(if $(call seq,64,$(BITS)),ON,OFF) \
-DENABLE_CLI=OFF \
-DENABLE_HDR10_PLUS=ON \
$(if $(IS_ARM), -DCROSS_COMPILE_ARM=ON)

$(MAKE) -C '$(BUILD_DIR)/10bit' -j '$(JOBS)'
cp '$(BUILD_DIR)/10bit/libx265.a' '$(BUILD_DIR)/libx265_main10.a'

# 8bit
cd '$(BUILD_DIR)' && $(TARGET)-cmake '$(SOURCE_DIR)/source' \
-DHIGH_BIT_DEPTH=OFF \
-DEXPORT_C_API=ON \
-DENABLE_SHARED=$(CMAKE_SHARED_BOOL) \
-DENABLE_ASSEMBLY=$(if $(call seq,64,$(BITS)),ON,OFF) \
-DENABLE_CLI=OFF \
-DENABLE_HDR10_PLUS=ON \
-DEXTRA_LIB='x265_main10.a;x265_main12.a' \
-DEXTRA_LINK_FLAGS=-L'$(BUILD_DIR)' \
-DLINKED_10BIT=ON \
-DLINKED_12BIT=ON \
$(if $(IS_ARM), -DCROSS_COMPILE_ARM=ON)

$(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)' install

$(if $(BUILD_SHARED), \
rm -f '$(PREFIX)/$(TARGET)/lib/libx265.a' && \
$(SED) -i 's/^\(Cflags:.* \)/\1-DX265_API_IMPORTS=1 /g' '$(PREFIX)/$(TARGET)/lib/pkgconfig/x265.pc' \
$(else), \
$(INSTALL) '$(BUILD_DIR)/libx265_main12.a' '$(PREFIX)/$(TARGET)/lib/libx265_main12.a' && \
$(INSTALL) '$(BUILD_DIR)/libx265_main10.a' '$(PREFIX)/$(TARGET)/lib/libx265_main10.a' && \
$(SED) -i 's|-lx265|-lx265 -lx265_main10 -lx265_main12|' '$(PREFIX)/$(TARGET)/lib/pkgconfig/x265.pc')

'$(TARGET)-gcc' \
-W -Wall -Werror \
'$(TOP_DIR)/src/$(PKG)-test.c' \
-o '$(PREFIX)/$(TARGET)/bin/test-$(PKG).exe' \
`$(TARGET)-pkg-config --cflags --libs $(PKG)`
endef
4 changes: 4 additions & 0 deletions build/package-vipsdev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ if [ "$MOZJPEG" = "true" ]; then
zip_suffix+="-mozjpeg"
fi

if [ "$HEVC" = "true" ]; then
zip_suffix+="-hevc"
fi

if [ "$LLVM" = "true" ] && [[ "$arch" != "arm"* ]]; then
zip_suffix+="-llvm"
fi
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions build/plugins/hevc/overrides.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$(PLUGIN_HEADER)

IS_HEVC := $(true)

# Override sub-dependencies
libheif_DEPS := $(libheif_DEPS) libde265 x265
File renamed without changes.
File renamed without changes.
File renamed without changes.
90 changes: 90 additions & 0 deletions build/plugins/hevc/x265.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
PKG := x265
$(PKG)_WEBSITE := http://x265.org/
$(PKG)_DESCR := H.265/HEVC video stream encoder.
$(PKG)_IGNORE :=
$(PKG)_VERSION := 3.4
$(PKG)_CHECKSUM := c2047f23a6b729e5c70280d23223cb61b57bfe4ad4e8f1471eeee2a61d148672
$(PKG)_PATCHES := $(realpath $(sort $(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/patches/x265-[0-9]*.patch)))
$(PKG)_SUBDIR := x265_$($(PKG)_VERSION)
$(PKG)_FILE := x265_$($(PKG)_VERSION).tar.gz
# https://bitbucket.org/multicoreware/x265_git/issues/553/tarball-for-34-release-not-in-x265_git
$(PKG)_URL := https://bitbucket.org/multicoreware/x265/downloads/$($(PKG)_FILE)
#$(PKG)_URL_2 := https://download.videolan.org/pub/videolan/x265/$(x265_FILE)
$(PKG)_URL_2 := https://ftp.osuosl.org/pub/blfs/conglomeration/x265/$(x265_FILE)
$(PKG)_DEPS := cc $(BUILD)~nasm

define $(PKG)_UPDATE
$(WGET) -q -O- https://download.videolan.org/pub/videolan/x265/ | \
$(SED) -n 's,.*">x265_\([0-9][^<]*\)\.t.*,\1,p' | \
tail -1
endef

# `-DENABLE_DYNAMIC_HDR10=ON` -> `-DENABLE_HDR10_PLUS=ON`
# x265 requires nasm 2.13 or newer (instead than yasm) after release 2.6.
define $(PKG)_BUILD
cd '$(BUILD_DIR)' && mkdir -p 10bit 12bit

# Fix ARM NEON includes when building the 10/12bit libraries
# https://bitbucket.org/multicoreware/x265_git/issues/549/fail-to-build-for-aarch64-and-armhf
$(if $(IS_ARM), \
$(foreach ARCH,aarch64 arm, \
$(SED) -i 's/PFX(\(.*\))/x265_\1/g' '$(SOURCE_DIR)/source/common/$(ARCH)/asm-primitives.cpp';) \
$(SED) -i 's/PFX(\(.*_neon\))/x265_\1/g' '$(SOURCE_DIR)/source/common/arm/dct8.h';)

# 12 bit
cd '$(BUILD_DIR)/12bit' && $(TARGET)-cmake '$(SOURCE_DIR)/source' \
-DHIGH_BIT_DEPTH=ON \
-DEXPORT_C_API=OFF \
-DENABLE_SHARED=OFF \
-DENABLE_ASSEMBLY=$(if $(call seq,64,$(BITS)),ON,OFF) \
-DENABLE_CLI=OFF \
-DENABLE_HDR10_PLUS=ON \
-DMAIN12=ON \
$(if $(IS_ARM), -DCROSS_COMPILE_ARM=ON)

$(MAKE) -C '$(BUILD_DIR)/12bit' -j '$(JOBS)'
cp '$(BUILD_DIR)/12bit/libx265.a' '$(BUILD_DIR)/libx265_main12.a'

# 10 bit
cd '$(BUILD_DIR)/10bit' && $(TARGET)-cmake '$(SOURCE_DIR)/source' \
-DHIGH_BIT_DEPTH=ON \
-DEXPORT_C_API=OFF \
-DENABLE_SHARED=OFF \
-DENABLE_ASSEMBLY=$(if $(call seq,64,$(BITS)),ON,OFF) \
-DENABLE_CLI=OFF \
-DENABLE_HDR10_PLUS=ON \
$(if $(IS_ARM), -DCROSS_COMPILE_ARM=ON)

$(MAKE) -C '$(BUILD_DIR)/10bit' -j '$(JOBS)'
cp '$(BUILD_DIR)/10bit/libx265.a' '$(BUILD_DIR)/libx265_main10.a'

# 8bit
cd '$(BUILD_DIR)' && $(TARGET)-cmake '$(SOURCE_DIR)/source' \
-DHIGH_BIT_DEPTH=OFF \
-DEXPORT_C_API=ON \
-DENABLE_SHARED=$(CMAKE_SHARED_BOOL) \
-DENABLE_ASSEMBLY=$(if $(call seq,64,$(BITS)),ON,OFF) \
-DENABLE_CLI=OFF \
-DENABLE_HDR10_PLUS=ON \
-DEXTRA_LIB='x265_main10.a;x265_main12.a' \
-DEXTRA_LINK_FLAGS=-L'$(BUILD_DIR)' \
-DLINKED_10BIT=ON \
-DLINKED_12BIT=ON \
$(if $(IS_ARM), -DCROSS_COMPILE_ARM=ON)

$(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)' install

$(if $(BUILD_SHARED), \
rm -f '$(PREFIX)/$(TARGET)/lib/libx265.a' && \
$(SED) -i 's/^\(Cflags:.* \)/\1-DX265_API_IMPORTS=1 /g' '$(PREFIX)/$(TARGET)/lib/pkgconfig/x265.pc' \
$(else), \
$(INSTALL) '$(BUILD_DIR)/libx265_main12.a' '$(PREFIX)/$(TARGET)/lib/libx265_main12.a' && \
$(INSTALL) '$(BUILD_DIR)/libx265_main10.a' '$(PREFIX)/$(TARGET)/lib/libx265_main10.a' && \
$(SED) -i 's|-lx265|-lx265 -lx265_main10 -lx265_main12|' '$(PREFIX)/$(TARGET)/lib/pkgconfig/x265.pc')

'$(TARGET)-gcc' \
-W -Wall -Werror \
'$(TOP_DIR)/src/$(PKG)-test.c' \
-o '$(PREFIX)/$(TARGET)/bin/test-$(PKG).exe' \
`$(TARGET)-pkg-config --cflags --libs $(PKG)`
endef
4 changes: 2 additions & 2 deletions build/vips-all.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ define $(PKG)_PRE_CONFIGURE
printf ' "aom": "$(aom_VERSION)",\n'; \
printf ' "cairo": "$(cairo_VERSION)",\n'; \
printf ' "cfitsio": "$(cfitsio_VERSION)",\n'; \
printf ' "de265": "$(libde265_VERSION)",\n'; \
$(if $(IS_HEVC),printf ' "de265": "$(libde265_VERSION)"$(comma)\n';) \
printf ' "exif": "$(libexif_VERSION)",\n'; \
printf ' "expat": "$(expat_VERSION)",\n'; \
printf ' "ffi": "$(libffi_VERSION)",\n'; \
Expand Down Expand Up @@ -56,7 +56,7 @@ define $(PKG)_PRE_CONFIGURE
printf ' "tiff": "$(tiff_VERSION)",\n'; \
printf ' "vips": "$(vips-all_VERSION)",\n'; \
printf ' "webp": "$(libwebp_VERSION)",\n'; \
printf ' "x265": "$(x265_VERSION)",\n'; \
$(if $(IS_HEVC),printf ' "x265": "$(x265_VERSION)"$(comma)\n';) \
printf ' "xml": "$(libxml2_VERSION)",\n'; \
printf ' "zlib": "$(zlib_VERSION)"\n'; \
printf '}';) \
Expand Down

0 comments on commit 380da94

Please sign in to comment.