Skip to content

Commit d2bd9bf

Browse files
authored
Added encoding of 10 and 12 bit images to Windows builds. (#24)
1 parent e1bf36b commit d2bd9bf

File tree

14 files changed

+222
-38
lines changed

14 files changed

+222
-38
lines changed

.github/workflows/build-cache-deps.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
name: Build cache for dependecies
1+
name: Build cache for dependencies
22

33
on:
44
push:
55
branches: [master]
66
paths:
7-
- 'libheif/**'
7+
- 'libheif/*.py'
8+
- 'libheif/heif.h'
89
schedule:
910
- cron: '59 23 * * 5' # Every Friday at 23:59 (GMT+2)
1011
workflow_dispatch:

.github/workflows/create-release-draft.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,38 @@ jobs:
99
name: Wheels • windows • x86_64
1010
runs-on: windows-2019
1111
env:
12-
VCPKG_PREFIX: "C:/vcpkg/installed/x64-windows"
12+
VCPKG_PREFIX: "C:/temp/msys64/mingw64"
1313

1414
steps:
1515
- uses: actions/checkout@v3
16-
- name: Install requirements and dependencies
16+
17+
- name: Python preparing
18+
run: python3 -m pip install cibuildwheel twine
19+
20+
- uses: msys2/setup-msys2@v2
21+
with:
22+
location: C:/temp
23+
install: >-
24+
patch
25+
mingw-w64-x86_64-binutils
26+
27+
- name: Build libheif and dependencies
28+
shell: msys2 {0}
1729
run: |
18-
python3 -m pip install cibuildwheel twine
19-
vcpkg install aom libheif --triplet=x64-windows
30+
cd libheif/mingw-w64-libheif
31+
sed -i 's/^M//' *
32+
makepkg-mingw --syncdeps --noconfirm -f
33+
pacman -U mingw-w64-x86_64-libheif-1.12.0-9-any.pkg.tar.zst --noconfirm
34+
35+
- name: Remove DLL trailing data
36+
run: ${{ env.VCPKG_PREFIX }}/bin/strip -s ${{ env.VCPKG_PREFIX }}/bin/*.dll
2037

2138
- name: Run cibuildwheel
2239
run: cibuildwheel
2340
env:
2441
CIBW_BUILD: "cp37-* cp38-* cp39-* cp310-*"
2542
CIBW_ARCHS_WINDOWS: "AMD64"
26-
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -v -w {dest_dir} {wheel} --add-path ${{ env.VCPKG_PREFIX }}/bin"
43+
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -vv -w {dest_dir} {wheel} --add-path ${{ env.VCPKG_PREFIX }}/bin"
2744

2845
- name: Check built wheels
2946
run: twine check wheelhouse/*

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ repos:
44
hooks:
55
- id: check-yaml
66
- id: end-of-file-fixer
7+
exclude: libheif/mingw-w64-libheif/.*
78
- id: trailing-whitespace
9+
exclude: libheif/mingw-w64-libheif/.*
810
- id: check-toml
911
- id: mixed-line-ending
1012

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
77
### Added
88

99
- (HeifImagePlugin) - support for `PIL.ImageFile.LOAD_TRUNCATED_IMAGES` flag.
10+
- (Windows, encoder) - encoding of `10` and `12` bit images.
1011

1112
### Changed
1213

MANIFEST.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
include libheif/*
21
include README.md
32
include CHANGELOG.md
43
include pyproject.toml
54

5+
graft libheif
66
graft tests
77
graft examples
88

@@ -13,3 +13,5 @@ exclude SECURITY.md
1313

1414
prune docs
1515
prune docker
16+
17+
recursive-exclude **/__pycache__ *

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Python bindings to [libheif](https://github.com/strukturag/libheif) for working
2222

2323
Features:
2424
* Decoding of `8`, `10`, `12` bit HEIF images.
25-
* Encoding of `8`, `10`, `12` bit HEIF images. *On windows currently only encoding of 8 bit images supported*
25+
* Encoding of `8`, `10`, `12` bit HEIF images.
2626
* `EXIF`, `XMP`, `IPTC` metadata support.
2727
* Support multiple images in one file, e.g **HEIC** files.
2828
* HEIF `native thumbnails` support.

docs/installation.rst

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Wheels are present for all systems supported by `cibuildwheel <https://cibuildwh
1919
Building From Source
2020
--------------------
2121

22+
All **pillow-heif's** **PyPi** packages are build on GitHub Actions, so you can take a look at `it <https://github.com/bigcat88/pillow_heif/blob/master/.github/workflows/create-release-draft.yml>`_.
23+
2224
.. role:: bash(code)
2325
:language: bash
2426

@@ -27,7 +29,7 @@ Linux
2729

2830
.. note::
2931

30-
| For installing external libraries, you should run install with **root** rights.
32+
| For installing external libraries, you should run install with **root** privileges.
3133
| See `build_libs.py <https://github.com/bigcat88/pillow_heif/blob/master/libheif/build_libs.py>`_ for
3234
additional info what will happen during installing from source...
3335
| Here is a
@@ -71,18 +73,23 @@ Windows
7173

7274
.. note::
7375
| On Windows installation is a bit tricky...
74-
| First install `vcpkg <https://vcpkg.io/en/getting-started.html>`_, if it is not installed.
75-
| By default, build script assumes that **vcpkg** builds libs in *C:\\vcpkg\\installed\\x64-windows*
76+
| First install `msys2 <https://www.msys2.org/>`_, if it is not installed.
77+
| By default, build script assumes that **msys2** builds libs in :bash:`C:\msys64\mingw64`
7678
| You can set **VCPKG_PREFIX** environment variable to your custom path, e.g.:
77-
| :bash:`setx VCPKG_PREFIX "D:\vcpkg\installed\x64-windows"`
79+
| :bash:`setx VCPKG_PREFIX "D:\msys64\mingw64"`
80+
81+
Using **msys2** terminal change working directory and install `libheif`::
7882

79-
Using **vcpkg** install required libraries::
83+
cd .../pillow_heif/libheif/mingw-w64-libheif
84+
makepkg-mingw --syncdeps
85+
pacman -U mingw-w64-x86_64-libheif-1.12.0-9-any.pkg.tar.zst
8086

81-
vcpkg install aom libheif --triplet=x64-windows
87+
.. note::
88+
This is needed, so we dont want to `dav1d` or `rav1e` to be installed as dependencies.
8289

8390
Now install Pillow-Heif with::
8491

8592
python3 -m pip install --upgrade pillow-heif --no-binary :all:
8693

87-
| After that copy **heif.dll**, **aom.dll**, **libde265.dll** and **libx265.dll** from
88-
*vcpkg\\installed\\x64-windows\\bin* to site-packages root.
94+
| After that copy **libheif.dll**, **libaom.dll**, **libde265.dll** and **libx265.dll** from
95+
*msys64\\mingw6\\bin* to site-packages root or simply add **...\\msys2\\mingw64\\bin** to dll load path.

libheif/build.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from os import getenv, path
2+
from pathlib import Path
3+
from shutil import copy
24
from subprocess import DEVNULL, PIPE, run
35
from sys import platform
46
from warnings import warn
@@ -37,21 +39,26 @@
3739
elif platform.lower() == "win32":
3840
include_path_prefix = getenv("VCPKG_PREFIX")
3941
if include_path_prefix is None:
40-
include_path_prefix = "C:\\vcpkg\\installed\\x64-windows"
42+
include_path_prefix = "C:\\msys64\\mingw64"
4143
warn(f"VCPKG_PREFIX environment variable is not set. Assuming `VCPKG_PREFIX={include_path_prefix}`")
4244
else:
4345
include_path_prefix = build_libs.build_libs_linux()
4446

45-
if include_path_prefix:
46-
include_path_prefix_include = path.join(include_path_prefix, "include")
47-
if include_path_prefix_include not in include_dirs:
48-
include_dirs.append(include_path_prefix_include)
49-
include_path_prefix_lib = path.join(include_path_prefix, "lib")
50-
if include_path_prefix_lib not in library_dirs:
51-
library_dirs.append(include_path_prefix_lib)
47+
# Need to include "lib" directory to find "heif" library.
48+
include_path_prefix_lib = path.join(include_path_prefix, "lib")
49+
if include_path_prefix_lib not in library_dirs:
50+
library_dirs.append(include_path_prefix_lib)
5251

53-
if platform.lower() in ("darwin", "win32"):
54-
include_dirs.append(path.dirname(path.dirname(path.abspath(__file__))))
52+
# MSYS2: rename "libheif.dll.a" to "libheif.lib"
53+
if platform.lower() == "win32":
54+
lib_export_file = Path(path.join(include_path_prefix_lib, "libheif.dll.a"))
55+
if lib_export_file.is_file():
56+
copy(lib_export_file, path.join(include_path_prefix_lib, "libheif.lib"))
57+
else:
58+
warn("If you build this with MSYS2, you should not see this warning.")
59+
60+
# Adds project root to `include` path
61+
include_dirs.append(path.dirname(path.dirname(path.abspath(__file__))))
5562

5663
ffi.set_source(
5764
"_pillow_heif_cffi",
@@ -60,7 +67,7 @@
6067
""",
6168
include_dirs=include_dirs,
6269
library_dirs=library_dirs,
63-
libraries=["heif"],
70+
libraries=["libheif"] if platform.lower() == "win32" else ["heif"],
6471
extra_compile_args=["/d2FH4-"] if platform.lower() == "win32" else [],
6572
)
6673

libheif/build_libs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def build_lib_linux(url: str, name: str, musl: bool = False):
203203
run("ldconfig", check=True)
204204

205205

206-
def build_libs_linux():
206+
def build_libs_linux() -> str:
207207
_install_flag = path.join(BUILD_DIR_PREFIX, "was_installed.flag")
208208
if path.isfile(_install_flag):
209209
print("Tools & Libraries already installed.", flush=True)

libheif/heif.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -621,13 +621,13 @@ struct heif_error heif_image_handle_get_metadata(const struct heif_image_handle*
621621
heif_item_id metadata_id,
622622
void* out_data);
623623

624-
//enum heif_color_profile_type
625-
//{
626-
// heif_color_profile_type_not_present = 0,
627-
// heif_color_profile_type_nclx = heif_fourcc('n', 'c', 'l', 'x'),
628-
// heif_color_profile_type_rICC = heif_fourcc('r', 'I', 'C', 'C'),
629-
// heif_color_profile_type_prof = heif_fourcc('p', 'r', 'o', 'f')
630-
//};
624+
enum heif_color_profile_type // Do not use this in Python directly, LO/HO byte order can differ.
625+
{
626+
heif_color_profile_type_not_present = 0,
627+
heif_color_profile_type_nclx = 0x6E636C78, // nclx -> "xlcn"
628+
heif_color_profile_type_rICC = 0x72494343, // rICC -> "CCIr"
629+
heif_color_profile_type_prof = 0x70726F66 // prof -> "forp"
630+
};
631631

632632

633633
// Returns 'heif_color_profile_type_not_present' if there is no color profile.

0 commit comments

Comments
 (0)