File: 0003-Compatibility-with-numpy2.patch

package info (click to toggle)
pylibtiff 0.6.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,132 kB
  • sloc: python: 9,938; ansic: 1,064; makefile: 15
file content (93 lines) | stat: -rw-r--r-- 3,780 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
From: Antonio Valentino <antonio.valentino@tiscali.it>
Date: Tue, 28 Jan 2025 07:25:47 +0000
Subject: Compatibility with numpy2

Forwarded: https://github.com/pearu/pylibtiff/pull/186
---
 libtiff/libtiff_ctypes.py | 16 ++++++++--------
 libtiff/test_bittools.py  |  4 +++-
 libtiff/tiff_image.py     |  2 +-
 libtiff/utils.py          |  1 +
 4 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/libtiff/libtiff_ctypes.py b/libtiff/libtiff_ctypes.py
index 5202747..c776846 100644
--- a/libtiff/libtiff_ctypes.py
+++ b/libtiff/libtiff_ctypes.py
@@ -659,13 +659,13 @@ class TIFF(ctypes.c_void_p):
         compression = self._fix_compression(compression)
 
         arr = np.ascontiguousarray(arr)
-        if arr.dtype in np.sctypes['float']:
+        if np.issubdtype(arr.dtype, np.floating):
             sample_format = SAMPLEFORMAT_IEEEFP
-        elif arr.dtype in np.sctypes['uint'] + [np.bool_]:
+        elif np.issubdtype(arr.dtype, np.unsignedinteger) or np.issubdtype(arr.dtype, np.bool_):
             sample_format = SAMPLEFORMAT_UINT
-        elif arr.dtype in np.sctypes['int']:
+        elif np.issubdtype(arr.dtype, np.signedinteger):
             sample_format = SAMPLEFORMAT_INT
-        elif arr.dtype in np.sctypes['complex']:
+        elif np.issubdtype(arr.dtype, np.complexfloating):
             sample_format = SAMPLEFORMAT_COMPLEXIEEEFP
         else:
             raise NotImplementedError(repr(arr.dtype))
@@ -746,13 +746,13 @@ class TIFF(ctypes.c_void_p):
                     compression=None, write_rgb=False):
         compression = self._fix_compression(compression)
 
-        if arr.dtype in np.sctypes['float']:
+        if np.issubdtype(arr.dtype, np.floating):
             sample_format = SAMPLEFORMAT_IEEEFP
-        elif arr.dtype in np.sctypes['uint'] + [np.bool_]:
+        elif np.issubdtype(arr.dtype, np.unsignedinteger) or np.issubdtype(arr.dtype, np.bool_):
             sample_format = SAMPLEFORMAT_UINT
-        elif arr.dtype in np.sctypes['int']:
+        elif np.issubdtype(arr.dtype, np.signedinteger):
             sample_format = SAMPLEFORMAT_INT
-        elif arr.dtype in np.sctypes['complex']:
+        elif np.issubdtype(arr.dtype, np.complexfloating):
             sample_format = SAMPLEFORMAT_COMPLEXIEEEFP
         else:
             raise NotImplementedError(repr(arr.dtype))
diff --git a/libtiff/test_bittools.py b/libtiff/test_bittools.py
index a173525..c6cba41 100644
--- a/libtiff/test_bittools.py
+++ b/libtiff/test_bittools.py
@@ -19,8 +19,10 @@ def test_setgetbit():
 
 
 def test_setgetword():
+    arange = numpy.arange(-256, 256)
     for dtype in [numpy.ubyte, numpy.int32, numpy.float64]:
-        arr = numpy.array(list(range(-256, 256)), dtype=dtype)
+        # arr = numpy.array(list(range(-256, 256)), dtype=dtype)
+        arr = arange.astype(dtype)
         arr2 = numpy.zeros(arr.shape, dtype=arr.dtype)
         for i in range(arr.nbytes):
             word, next = bittools.getword(arr, i * 8, 8)
diff --git a/libtiff/tiff_image.py b/libtiff/tiff_image.py
index 717370a..8e31d0e 100644
--- a/libtiff/tiff_image.py
+++ b/libtiff/tiff_image.py
@@ -437,7 +437,7 @@ class TIFFimage:
 
         if compressed_data_size != image_data_size:
             sdiff = image_data_size - compressed_data_size
-            total_size -= sdiff
+            total_size = int(total_size) - sdiff
             base = tif._mmap
             if base is None:
                 base = tif.base
diff --git a/libtiff/utils.py b/libtiff/utils.py
index 7fcfde4..d11d785 100644
--- a/libtiff/utils.py
+++ b/libtiff/utils.py
@@ -19,6 +19,7 @@ def isindisk(path):
 
 def bytes2str(bytes):
     lst = []
+    bytes = int(bytes)
     Pbytes = bytes // 1024**5
     if Pbytes:
         lst.append('%sPi' % (Pbytes))