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 pympler,
26 pytestCheckHook,
27}:
28
29buildPythonPackage rec {
30 pname = "pillow-heif";
31 version = "0.16.0";
32 pyproject = true;
33
34 src = fetchFromGitHub {
35 owner = "bigcat88";
36 repo = "pillow_heif";
37 rev = "refs/tags/v${version}";
38 hash = "sha256-TpK6VK2YoOtc4ueag33m5n1umcUWOUgcda/MZEEOR7g=";
39 };
40
41 postPatch = ''
42 sed -i '/addopts/d' pyproject.toml
43 '';
44
45 nativeBuildInputs = [
46 cmake
47 nasm
48 pkg-config
49 setuptools
50 ];
51
52 dontUseCmakeConfigure = true;
53
54 buildInputs = [
55 libaom
56 libde265
57 libheif
58 x265
59 ];
60
61 env = {
62 # clang-16: error: argument unused during compilation: '-fno-strict-overflow'
63 NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-Wno-unused-command-line-argument";
64
65 RELEASE_FULL_FLAG = 1;
66 };
67
68 propagatedBuildInputs = [ pillow ];
69
70 pythonImportsCheck = [ "pillow_heif" ];
71
72 nativeCheckInputs = [
73 opencv4
74 numpy
75 pympler
76 pytestCheckHook
77 ];
78
79 disabledTests =
80 [
81 # Time based
82 "test_decode_threads"
83 ]
84 ++ lib.optionals stdenv.isDarwin [
85 # https://github.com/bigcat88/pillow_heif/issues/89
86 # not reproducible in nixpkgs
87 "test_opencv_crash"
88 ]
89 ++ lib.optionals (stdenv.isLinux && stdenv.isAarch64) [
90 # RuntimeError: Encoder plugin generated an error: Unsupported bit depth: Bit depth not supported by x265
91 "test_open_heif_compare_non_standard_modes_data"
92 "test_open_save_disable_16bit"
93 "test_save_bgr_16bit_to_10_12_bit"
94 "test_save_bgra_16bit_to_10_12_bit"
95 "test_premultiplied_alpha"
96 "test_hdr_save"
97 "test_I_color_modes_to_10_12_bit"
98 ];
99
100 meta = {
101 changelog = "https://github.com/bigcat88/pillow_heif/releases/tag/v${version}";
102 description = "Python library for working with HEIF images and plugin for Pillow";
103 homepage = "https://github.com/bigcat88/pillow_heif";
104 license = with lib.licenses; [
105 bsd3
106 lgpl3
107 ];
108 maintainers = with lib.maintainers; [ dandellion ];
109 };
110}