1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6
7 # build-system
8 cmake,
9 nasm,
10 pkg-config,
11 setuptools,
12
13 # native dependencies
14 libheif,
15 libaom,
16 libde265,
17 x265,
18
19 # dependencies
20 pillow,
21
22 # tests
23 opencv4,
24 numpy,
25 pytestCheckHook,
26}:
27
28buildPythonPackage rec {
29 pname = "pillow-heif";
30 version = "0.22.0";
31 pyproject = true;
32
33 src = fetchFromGitHub {
34 owner = "bigcat88";
35 repo = "pillow_heif";
36 tag = "v${version}";
37 hash = "sha256-xof6lFb0DhmWVmYuBNslcGZs82NRkcgZgt+SX9gsrBY=";
38 };
39
40 postPatch = ''
41 sed -i '/addopts/d' pyproject.toml
42 substituteInPlace setup.py \
43 --replace-warn ', "-Werror"' ""
44 '';
45
46 nativeBuildInputs = [
47 cmake
48 nasm
49 pkg-config
50 ];
51
52 build-system = [ setuptools ];
53
54 dontUseCmakeConfigure = true;
55
56 buildInputs = [
57 libaom
58 libde265
59 libheif
60 x265
61 ];
62
63 env = {
64 RELEASE_FULL_FLAG = 1;
65 };
66
67 dependencies = [ pillow ];
68
69 pythonImportsCheck = [ "pillow_heif" ];
70
71 nativeCheckInputs = [
72 opencv4
73 numpy
74 pytestCheckHook
75 ];
76
77 preCheck = ''
78 # https://github.com/bigcat88/pillow_heif/issues/325
79 rm tests/images/heif_other/L_xmp_latin1.heic
80 rm tests/images/heif/L_xmp.heif
81 '';
82
83 disabledTests =
84 [
85 # Time based
86 "test_decode_threads"
87 # Missing EXIF info on WEBP-AVIF variant
88 "test_exif_from_pillow"
89 ]
90 ++ lib.optionals stdenv.hostPlatform.isDarwin [
91 # https://github.com/bigcat88/pillow_heif/issues/89
92 # not reproducible in nixpkgs
93 "test_opencv_crash"
94 ]
95 ++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) [
96 # RuntimeError: Encoder plugin generated an error: Unsupported bit depth: Bit depth not supported by x265
97 "test_open_heif_compare_non_standard_modes_data"
98 "test_open_save_disable_16bit"
99 "test_save_bgr_16bit_to_10_12_bit"
100 "test_save_bgra_16bit_to_10_12_bit"
101 "test_premultiplied_alpha"
102 "test_hdr_save"
103 "test_I_color_modes_to_10_12_bit"
104 ];
105
106 meta = {
107 changelog = "https://github.com/bigcat88/pillow_heif/releases/tag/${src.tag}";
108 description = "Python library for working with HEIF images and plugin for Pillow";
109 homepage = "https://github.com/bigcat88/pillow_heif";
110 license = with lib.licenses; [
111 bsd3
112 lgpl3
113 ];
114 maintainers = with lib.maintainers; [ dandellion ];
115 };
116}