Skip to content

Commit

Permalink
#909 improve performance 12x!
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@13751 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Sep 16, 2016
1 parent 20c0b54 commit 8fd37cb
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/xpra/codecs/argb/argb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ cdef inline unsigned char clamp(int v):
def r210_to_rgba(buf):
assert len(buf) % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % len(buf)
# buf is a Python buffer object
cdef const int* cbuf = <const int *> 0
cdef const unsigned int* cbuf = <const unsigned int *> 0
cdef Py_ssize_t cbuf_len = 0
assert object_as_buffer(buf, <const void**> &cbuf, &cbuf_len)==0, "cannot convert %s to a readable buffer" % type(buf)
return r210data_to_rgba(cbuf, cbuf_len)

cdef r210data_to_rgba(const int* r210, const int r210_len):
cdef r210data_to_rgba(const unsigned int* r210, const int r210_len):
if r210_len <= 0:
return None
assert r210_len>0 and r210_len % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % r210_len
rgba = bytearray(r210_len)
#number of pixels:
cdef int i = 0
cdef int v
cdef unsigned int i = 0
cdef unsigned int v
while i < r210_len:
v = r210[i//4]
rgba[i] = (v&0x000003ff) >> 2
rgba[i+1] = (v&0x000ffc00) >> 12
rgba[i+2] = (v&0x3ff00000) >> 22
rgba[i+3] = clamp(((v&0xc0000000) >> 30)*85)
rgba[i] = (v&0x000003ff) >> 2
rgba[i+1] = (v&0x000ffc00) >> 12
rgba[i+2] = (v&0x3ff00000) >> 22
rgba[i+3] = ((v&(<unsigned int>0xc0000000)) >> 30)*85
i = i + 4
return rgba

Expand All @@ -78,9 +78,9 @@ cdef r210data_to_rgb(const int* r210, const int r210_len):
cdef int v
while s < r210_len//4:
v = r210[s]
rgb[d] = (v&0x000003ff) >> 2
rgb[d+1] = (v&0x000ffc00) >> 12
rgb[d+2] = (v&0x3ff00000) >> 22
rgb[d] = (v&0x000003ff) >> 2
rgb[d+1] = (v&0x000ffc00) >> 12
rgb[d+2] = (v&0x3ff00000) >> 22
s += 1
d += 3
return rgb
Expand Down

0 comments on commit 8fd37cb

Please sign in to comment.