Skip to content

Commit

Permalink
msvc is the only compiler which correctly spotted that Py_ssize_t is …
Browse files Browse the repository at this point in the history
…a signed int

git-svn-id: https://xpra.org/svn/Xpra/trunk@10216 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Aug 4, 2015
1 parent fc4a71d commit 58e073b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/xpra/codecs/argb/argb.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# later version. See the file COPYING for details.


cdef argbdata_to_rgba(const unsigned char* argb, const unsigned int argb_len)
cdef argbdata_to_rgb(const unsigned char *argb, const unsigned int argb_len)
cdef bgradata_to_rgb(const unsigned char* bgra, const unsigned int bgra_len)
cdef bgradata_to_rgba(const unsigned char* bgra, const unsigned int bgra_len)
cdef argbdata_to_rgba(const unsigned char* argb, const int argb_len)
cdef argbdata_to_rgb(const unsigned char *argb, const int argb_len)
cdef bgradata_to_rgb(const unsigned char* bgra, const int bgra_len)
cdef bgradata_to_rgba(const unsigned char* bgra, const int bgra_len)
39 changes: 19 additions & 20 deletions src/xpra/codecs/argb/argb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ cdef inline unsigned char clamp(int v):
return 255
return <unsigned char> v

cdef argbdata_to_rgba(const unsigned char* argb, const unsigned int argb_len):
cdef argbdata_to_rgba(const unsigned char* argb, const int argb_len):
if argb_len <= 0:
return None
assert argb_len % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % argb_len
assert argb_len>0 and argb_len % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % argb_len
rgba = bytearray(argb_len)
#number of pixels:
cdef unsigned int i = 0
cdef int i = 0
while i < argb_len:
rgba[i] = argb[i+1] #R
rgba[i+1] = argb[i+2] #G
Expand All @@ -65,15 +65,15 @@ def argb_to_rgb(buf):
assert object_as_buffer(buf, <const void**> &cbuf, &cbuf_len)==0, "cannot convert %s to a readable buffer" % type(buf)
return argbdata_to_rgb(cbuf, cbuf_len)

cdef argbdata_to_rgb(const unsigned char *argb, const unsigned int argb_len):
cdef argbdata_to_rgb(const unsigned char *argb, const int argb_len):
if argb_len <= 0:
return None
assert argb_len % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % argb_len
assert argb_len>0 and argb_len % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % argb_len
#number of pixels:
cdef unsigned int mi = argb_len//4 #@DuplicateSignature
#3 bytes per pixel:
rgb = bytearray(mi*3)
cdef unsigned int i = 0, di = 0 #@DuplicateSignature
cdef int i = 0, di = 0 #@DuplicateSignature
while i < argb_len:
rgb[di] = argb[i+1] #R
rgb[di+1] = argb[i+2] #G
Expand All @@ -91,16 +91,15 @@ def bgra_to_rgb(buf):
assert object_as_buffer(buf, <const void**> &bgra_buf, &bgra_buf_len)==0, "cannot convert %s to a readable buffer" % type(buf)
return bgradata_to_rgb(bgra_buf, bgra_buf_len)

cdef bgradata_to_rgb(const unsigned char* bgra, const unsigned int bgra_len):
cdef bgradata_to_rgb(const unsigned char* bgra, const int bgra_len):
if bgra_len <= 0:
return None
assert bgra_len % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % bgra_len
assert bgra_len>0 and bgra_len % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % bgra_len
#number of pixels:
cdef unsigned int mi = bgra_len//4 #@DuplicateSignature
cdef int mi = bgra_len//4 #@DuplicateSignature
#3 bytes per pixel:
rgb = bytearray(mi*3)
cdef unsigned int di = 0 #@DuplicateSignature
cdef unsigned int si = 0 #@DuplicateSignature
cdef int di = 0, si = 0 #@DuplicateSignature
while si < bgra_len:
rgb[di] = bgra[si+2] #R
rgb[di+1] = bgra[si+1] #G
Expand All @@ -118,13 +117,13 @@ def bgra_to_rgba(buf):
assert object_as_buffer(buf, <const void**> &bgra_buf2, &bgra_buf_len2)==0, "cannot convert %s to a readable buffer" % type(buf)
return bgradata_to_rgba(bgra_buf2, bgra_buf_len2)

cdef bgradata_to_rgba(const unsigned char* bgra, const unsigned int bgra_len):
cdef bgradata_to_rgba(const unsigned char* bgra, const int bgra_len):
if bgra_len <= 0:
return None
assert bgra_len % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % bgra_len
assert bgra_len>0 and bgra_len % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % bgra_len
#same number of bytes:
rgba = bytearray(bgra_len)
cdef unsigned int i = 0 #@DuplicateSignature
cdef int i = 0 #@DuplicateSignature
while i < bgra_len:
rgba[i] = bgra[i+2] #R
rgba[i+1] = bgra[i+1] #G
Expand All @@ -149,8 +148,8 @@ cdef do_premultiply_argb_in_place(unsigned int *buf, Py_ssize_t argb_len):
cdef unsigned char a, r, g, b
cdef unsigned int argb
assert sizeof(int) == 4
assert argb_len % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % argb_len
cdef unsigned int i
assert argb_len>0 and argb_len % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % argb_len
cdef int i
for 0 <= i < argb_len / 4:
argb = buf[i]
a = (argb >> 24) & 0xff
Expand All @@ -174,11 +173,11 @@ def unpremultiply_argb_in_place(buf):
cdef do_unpremultiply_argb_in_place(unsigned int * buf, Py_ssize_t buf_len):
# cbuf contains non-premultiplied ARGB32 data in native-endian.
# We convert to premultiplied ARGB32 data, in-place.
cdef unsigned char a, r, g, b #@DuplicateSignature
cdef unsigned char a, r, g, b #@DuplicateSignature
cdef unsigned int argb #@DuplicateSignature
assert sizeof(int) == 4
assert buf_len % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % buf_len
cdef unsigned int i #@DuplicateSignature
assert buf_len>0 and buf_len % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % buf_len
cdef int i #@DuplicateSignature
for 0 <= i < buf_len // 4:
argb = buf[i]
a = (argb >> 24) & 0xff
Expand Down Expand Up @@ -215,7 +214,7 @@ cdef do_unpremultiply_argb(unsigned int * argb_in, Py_ssize_t argb_len):
cdef unsigned char a, r, g, b #@DuplicateSignature
cdef unsigned int argb #@DuplicateSignature
assert sizeof(int) == 4
assert argb_len % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % argb_len
assert argb_len>0 and argb_len % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % argb_len
argb_out = bytearray(argb_len)
cdef int i #@DuplicateSignature
for 0 <= i < argb_len // 4:
Expand Down

0 comments on commit 58e073b

Please sign in to comment.