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 = "1.1.0";
31 pyproject = true;
32
33 src = fetchFromGitHub {
34 owner = "bigcat88";
35 repo = "pillow_heif";
36 tag = "v${version}";
37 hash = "sha256-CY//orCEKBfgHF7lTTSMenDsvf9NOQo8iiQS3p9NMH8=";
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 disabledTests = [
78 # Time sensitive speed test, not reproducible
79 "test_decode_threads"
80 ]
81 ++ lib.optionals stdenv.hostPlatform.isDarwin [
82 # https://github.com/bigcat88/pillow_heif/issues/89
83 # not reproducible in nixpkgs
84 "test_opencv_crash"
85 ]
86 ++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) [
87 # RuntimeError: Encoder plugin generated an error: Unsupported bit depth: Bit depth not supported by x265
88 "test_open_heif_compare_non_standard_modes_data"
89 "test_open_save_disable_16bit"
90 "test_save_bgr_16bit_to_10_12_bit"
91 "test_save_bgra_16bit_to_10_12_bit"
92 "test_premultiplied_alpha"
93 "test_hdr_save"
94 "test_I_color_modes_to_10_12_bit"
95 ];
96
97 meta = {
98 changelog = "https://github.com/bigcat88/pillow_heif/releases/tag/${src.tag}";
99 description = "Python library for working with HEIF images and plugin for Pillow";
100 homepage = "https://github.com/bigcat88/pillow_heif";
101 license = with lib.licenses; [
102 bsd3
103 lgpl3
104 ];
105 maintainers = with lib.maintainers; [
106 dandellion
107 kuflierl
108 ];
109 };
110}