8000 start adding streamiu support · libvips/pyvips@7679a07 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7679a07

Browse files
committed
start adding streamiu support
1 parent 9cb2886 commit 7679a07

File tree

2 files changed

+76
-22
lines changed

2 files changed

+76
-22
lines changed

pyvips/decls.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,19 @@ def cdefs(features):
431431
VipsStreami* vips_streami_new_from_memory (const void* data,
432432
size_t size);
433433
434+
typedef struct _VipsStreamiu {
435+
VipsStreami parent_object;
436+
437+
// more
438+
} VipsStreamiu;
439+
440+
VipsStreami* vips_streamiu_new (void);
441+
442+
extern "Python" gint64 _marshall_read (VipsStreamiu*,
443+
void*, gint64, void*);
444+
extern "Python" gint64 _marshall_seek (VipsStreamiu*,
445+
gint64, int, void*);
446+
434447
typedef struct _VipsStreamo {
435448
VipsStream parent_object;
436449
@@ -441,9 +454,20 @@ def cdefs(features):
441454
VipsStreamo* vips_streamo_new_to_filename (const char* filename);
442455
VipsStreamo* vips_streamo_new_to_memory (void);
443456
457+
typedef struct _VipsStreamou {
458+
VipsStreamo parent_object;
459+
460+
// more
461+
} VipsStreamou;
462+
463+
VipsStreami* vips_streamou_new (void);
464+
444465
const char* vips_foreign_find_load_stream (VipsStreami *streami);
445466
const char* vips_foreign_find_save_stream (const char* suffix);
446467
468+
extern "Python" gint64 _marshall_write (VipsStreamou*,
469+
void*, gint64, void*);
470+
extern "Python" void _marshall_finish (VipsStreamou*, void*);
447471
448472
'''
449473

pyvips/gobject.py

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,64 @@
77

88
logger = logging.getLogger(__name__)
99

10-
# the python marshallers for gobject signal handling
10+
# the python marshalers for gobject signal handling
1111
# we keep a ref to each callback to stop them being GCd
1212

1313
if pyvips.API_mode:
1414
@ffi.def_extern()
15-
def _marshall_image_progress(vi, pointer, handle):
16-
# the image we're passed is not reffed for us, so make a ref for us
17-
gobject_lib.g_object_ref(vi)
18-
image = pyvips.Image(vi)
19-
callback = ffi.from_handle(handle)
20-
progress = ffi.cast('VipsProgress*', pointer)
21-
callback(image, progress)
22-
23-
_marshall_image_progress_cb = \
24-
ffi.cast('GCallback', gobject_lib._marshall_image_progress)
15+
def _marshal_image_progress(vi, pointer, handle):
16+
# the image we're passed is not reffed for us, so make a ref for us
17+
gobject_lib.g_object_ref(vi)
18+
image = pyvips.Image(vi)
19+
callback = ffi.from_handle(handle)
20+
progress = ffi.cast('VipsProgress*', pointer)
21+
callback(image, progress)
22+
23+
if pyvips.API_mode:
24+
_marshal_image_progress_cb = \
25+
ffi.cast('GCallback', gobject_lib._marshal_image_progress)
2526
else:
26-
def _marshall_image_progress(vi, pointer, handle):
27-
# the image we're passed is not reffed for us, so make a ref for us
28-
gobject_lib.g_object_ref(vi)
29-
image = pyvips.Image(vi)
30-
callback = ffi.from_handle(handle)
31-
progress = ffi.cast('VipsProgress*', pointer)
32-
callback(image, progress)
33-
34-
_marshall_image_progress_cb = \
27+
_marshal_image_progress_cb = \
3528
ffi.cast('GCallback',
3629
ffi.callback('void(VipsImage*, void*, void*)',
37-
_marshall_image_progress))
30+
_marshal_image_progress))
31+
32+
if pyvips.API_mode:
33+
@ffi.def_extern()
34+
def _marshal_read(streamiu, pointer, length, handle):
35+
buf = ffi.buffer(pointer, length)
36+
callback = ffi.from_handle(handle)
37+
callback(streamiu, buf)
38+
39+
if pyvips.API_mode:
40+
_marshal_read_cb = \
41+
ffi.cast('GCallback', gobject_lib._marshal_read)
42+
else:
43+
_marshal_read_cb = \
44+
ffi.cast('GCallback',
45+
ffi.callback('gint64(VipsStreamiu*, void*, gint64, void*)',
46+
_marshal_read))
47+
48+
_marshalers = [
49+
"image_progress": _marshal_image_progress_cb,
50+
"read": _marshal_read_cb,
51+
"seek": _marshal_seek_cb,
52+
]
53+
54+
if pyvips.API_mode:
55+
@ffi.def_extern()
56+
def _marshal_seek(streamiu, offset, whence, handle):
57+
callback = ffi.from_handle(handle)
58+
callback(streamiu, offset, whence)
59+
60+
if pyvips.API_mode:
61+
_marshal_read_cb = \
62+
ffi.cast('GCallback', gobject_lib._marshal_seek)
63+
else:
64+
_marshal_read_cb = \
65+
ffi.cast('GCallback',
66+
ffi.callback('gint64(VipsStreamiu*, gint64, int, void*)',
67+
_marshal_seek))
3868

3969

4070
class GObject(object):
@@ -77,7 +107,7 @@ def signal_connect(self, name, callback):
77107
self._handles.append(handle)
78108

79109
gobject_lib.g_signal_connect_data(go, _to_bytes(name),
80-
_marshall_image_progress_cb,
110+
_marshal_image_progress_cb,
81111
handle, ffi.NULL, 0)
82112

83113

0 commit comments

Comments
 (0)
0