8000 Windows support · libvips/pyvips@1af1e16 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1af1e16

Browse files
committed
Windows support
1 parent 9adb718 commit 1af1e16

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

pyvips/base.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@
44

55
import logging
66
import sys
7+
import os
78
from cffi import FFI
89

910
logger = logging.getLogger(__name__)
1011

1112
ffi = FFI()
1213

14+
_is_windows = os.name == 'nt'
15+
1316
# possibly use ctypes.util.find_library() to locate the lib
14-
# need a different name on windows? or os x?
15-
# on win, may need to explcitly load other libraries as well
16-
vips_lib = ffi.dlopen('libvips.so')
17-
gobject_lib = ffi.dlopen('libgobject-2.0.so')
17+
# need a different name on os x?
18+
vips_lib = ffi.dlopen('libvips-42.dll' if _is_windows else 'libvips.so')
19+
gobject_lib = ffi.dlopen('libgobject-2.0-0.dll' if _is_windows else 'libgobject-2.0.so')
20+
21+
if _is_windows:
22+
glib_lib = ffi.dlopen('libglib-2.0-0.dll')
23+
else:
24+
glib_lib = gobject_lib
1825

1926
logger.debug('Loaded lib {0}'.format(vips_lib))
2027
logger.debug('Loaded lib {0}'.format(gobject_lib))
@@ -116,6 +123,6 @@ def type_find(basename, nickname):
116123
def type_name(gtype):
117124
return to_string(ffi.string(gobject_lib.g_type_name(gtype)))
118125

119-
__all__ = ['ffi', 'vips_lib', 'gobject_lib', 'Error', 'leak_set',
120-
'to_bytes', 'to_string', 'type_find', 'type_name',
121-
'path_filename7', 'path_mode7', 'shutdown']
126+
__all__ = ['ffi', 'vips_lib', 'gobject_lib', 'glib_lib', 'Error',
127+
'leak_set', 'to_bytes', 'to_string', 'type_find',
128+
'type_name', 'path_filename7', 'path_mode7', 'shutdown']

pyvips/gvalue.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,16 @@ def set(self, value):
139139
vips_lib.vips_value_set_array_image(self.gvalue, len(value))
140140
array = vips_lib.vips_value_get_array_image(self.gvalue, ffi.NULL)
141141
for i, image in enumerate(value):
142-
vips_lib.g_object_ref(image.pointer)
142+
gobject_lib.g_object_ref(image.pointer)
143143
array[i] = image.pointer
144144
elif gtype == GValue.blob_type:
145145
# we need to set the blob to a copy of the string that vips_lib
146146
# can own
147-
memory = gobject_lib.g_malloc(len(value))
147+
memory = glib_lib.g_malloc(len(value))
148148
ffi.memmove(memory, value, len(value))
149149

150-
vips_lib.vips_value_set_blob(self.gvalue,
151-
gobject_lib.g_free, memory, len(value))
150+
vips_lib.vips_value_set_blob(self.gvalue,
151+
glib_lib.g_free, memory, len(value))
152152
else:
153153
raise Error('unsupported gtype for set {0}, fundamental {1}'.
154154
format(type_name(gtype), type_name(fundamental)))
@@ -219,7 +219,7 @@ def get(self):
219219
result = []
220220
for i in range(0, pint[0]):
221221
vi = array[i]
222-
vips_lib.g_object_ref(vi)
222+
gobject_lib.g_object_ref(vi)
223223
image = package_index['Image'](vi)
224224
result.append(image)
225225
elif gtype == GValue.blob_type:

pyvips/vimage.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,11 @@ def __exit__(self, type, value, traceback):
324324
def __getitem__(self, arg):
325325
if isinstance(arg, slice):
326326
i = 0
327-
if arg.start != None:
327+
if arg.start is not None:
328328
i = arg.start
329329

330330
n = self.bands - i
331-
if arg.stop != None:
331+
if arg.stop is not None:
332332
if arg.stop < 0:
333333
n = self.bands + arg.stop - i
334334
else:
@@ -468,14 +468,14 @@ def __le__(self, other):
468468

469469
def __eq__(self, other):
470470
# _eq version allows comparison to None
471-
if other == None:
471+
if other is None:
472472
return False
473473

474474
return _call_enum(self, other, 'relational', 'equal')
475475

476476
def __ne__(self, other):
477477
# _eq version allows comparison to None
478-
if other == None:
478+
if other is None:
479479
return True
480480

481481
return _call_enum(self, other, 'relational', 'noteq')
@@ -518,7 +518,7 @@ def bandjoin(self, other):
518518
if not isinstance(x, numbers.Number)),
519519
None)
520520

521-
if non_number == None:
521+
if non_number is None:
522522
return self.bandjoin_const(other)
523523
else:
524524
return Operation.call("bandjoin", [self] + other)

pyvips/voperation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _find_inside(pred, thing):
5151
for x in thing:
5252
result = _find_inside(pred, x)
5353

54-
if result != None:
54+
if result is not None:
5555
return result
5656

5757
return None

0 commit comments

Comments
 (0)
0