diff --git a/src/xpra/codecs/argb/argb.pxd b/src/xpra/codecs/argb/argb.pxd index 814394efcc..b5e8a45407 100644 --- a/src/xpra/codecs/argb/argb.pxd +++ b/src/xpra/codecs/argb/argb.pxd @@ -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) diff --git a/src/xpra/codecs/argb/argb.pyx b/src/xpra/codecs/argb/argb.pyx index fc424fd534..e5bf338db7 100644 --- a/src/xpra/codecs/argb/argb.pyx +++ b/src/xpra/codecs/argb/argb.pyx @@ -42,13 +42,13 @@ cdef inline unsigned char clamp(int v): return 255 return 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 @@ -65,15 +65,15 @@ def argb_to_rgb(buf): assert object_as_buffer(buf, &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 @@ -91,16 +91,15 @@ def bgra_to_rgb(buf): assert object_as_buffer(buf, &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 @@ -118,13 +117,13 @@ def bgra_to_rgba(buf): assert object_as_buffer(buf, &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 @@ -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 @@ -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 @@ -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: