Skip to content

Commit

Permalink
correct way to release gil: only do it if the image is thread safe
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@26941 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jul 10, 2020
1 parent 3652e93 commit 3a9dd81
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/xpra/codecs/csc_cython/colorspace_converter.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,22 @@ cdef inline unsigned char clamp(const long v) nogil:
else:
return <unsigned char> (v>>shift)

cdef inline void r210_to_BGR48_copy(unsigned short *bgr48, const unsigned int *r210,
unsigned int w, unsigned int h,
unsigned int src_stride, unsigned int dst_stride) nogil:
cdef unsigned int y = 0
cdef unsigned int i = 0
cdef unsigned int v
for y in range(h):
i = y*dst_stride//2
for x in range(w):
v = r210[x]
bgr48[i] = v&0x000003ff
bgr48[i+1] = (v&0x000ffc00) >> 10
bgr48[i+2] = (v&0x3ff00000) >> 20
i = i + 3
r210 = <unsigned int*> ((<uintptr_t> r210) + src_stride)


cdef class ColorspaceConverter:
cdef unsigned int src_width
Expand Down Expand Up @@ -537,23 +553,14 @@ cdef class ColorspaceConverter:

cdef unsigned int w = self.src_width
cdef unsigned int h = self.src_height
cdef unsigned int dst_stride = self.dst_strides[0]
cdef unsigned int src_stride = image.get_rowstride()
cdef unsigned int dst_stride = self.dst_strides[0]

cdef unsigned int y = 0
cdef unsigned int i = 0
cdef unsigned int v
#enable nogil if image is thread safe?
#with nogil:
for y in range(h):
i = y*dst_stride//2
for x in range(w):
v = r210[x]
bgr48[i] = v&0x000003ff
bgr48[i+1] = (v&0x000ffc00) >> 10
bgr48[i+2] = (v&0x3ff00000) >> 20
i = i + 3
r210 = <unsigned int*> ((<uintptr_t> r210) + src_stride)
if image.is_thread_safe():
with nogil:
r210_to_BGR48_copy(bgr48, r210, w, h, src_stride, dst_stride)
else:
r210_to_BGR48_copy(bgr48, r210, w, h, src_stride, dst_stride)

bgr48_buffer = memory_as_pybuffer(<void *> bgr48, self.dst_sizes[0], True)
cdef double elapsed = time.time()-start
Expand Down

0 comments on commit 3a9dd81

Please sign in to comment.