-
Notifications
You must be signed in to change notification settings - Fork 0
/
spout.pyx
62 lines (50 loc) · 2.02 KB
/
spout.pyx
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
#cython: language_level=3
# distutils: language = c++
from spout_native cimport SPOUTLIBRARY, GetSpout
from libcpp cimport bool, nullptr
cdef class Spout:
cdef SPOUTLIBRARY* c_spout
cdef bool use_opengl
cdef bool use_directx
def __init__(self, use_opengl = False, use_directx = False):
self.use_opengl = use_opengl
self.use_directx = use_directx
if self.use_opengl:
self.c_spout.CreateOpenGL()
if self.use_directx:
self.c_spout.OpenDirectX11(nullptr)
def __cinit__(self):
self.c_spout = GetSpout()
def __dealloc__(self):
if self.use_opengl:
self.c_spout.CloseOpenGL()
if self.use_directx:
self.c_spout.CloseDirectX()
self.c_spout.Release()
def set_sender_name(self, name: str):
py_byte_name = name.encode('utf-8')
cdef char* c_name = py_byte_name
return self.c_spout.SetSenderName(c_name)
def send_image(self, image, width, height, format, invert = False):
cdef unsigned char* c_image = image
return self.c_spout.SendImage(c_image, width, height, format, invert)
def send_image_ndarray(self, image, format, invert = False):
ravel = image.ravel()
cdef unsigned int width = image.shape[1]
cdef unsigned int height = image.shape[0]
cdef const unsigned char[::1] c_image = ravel.data
cdef unsigned int c_format = format
cdef bool c_invert = invert
with nogil:
result = self.c_spout.SendImage(&c_image[0], width, height, c_format, c_invert)
return result
def get_spout_version(self):
return self.c_spout.GetSpoutVersion()
def hold_fps(self, fps):
cdef int c_fps = fps
with nogil:
self.c_spout.HoldFps(c_fps)
def wait_frame_sync(self, name: str):
py_byte_name = name.encode('utf-8')
cdef char* c_name = py_byte_name
return self.c_spout.WaitFrameSync(c_name, 0)