Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* use inline function for calculating bytes-per-pixel from the depth
* add missing rgb formats to array

git-svn-id: https://xpra.org/svn/Xpra/trunk@15122 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 19, 2017
1 parent e03ced8 commit 2795f37
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/xpra/x11/bindings/ximage.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ ximagedebug = Logger("x11", "bindings", "ximage", "verbose")
cdef inline unsigned int roundup(unsigned int n, unsigned int m):
return (n + m - 1) & ~(m - 1)

cdef inline unsigned char BYTESPERPIXEL(unsigned int depth):
if depth>=24 and depth<=32:
return 4
elif depth==16:
return 2
elif depth==8:
return 1
#shouldn't happen!
return roundup(depth, 8)//8

cdef inline unsigned int MIN(unsigned int a, unsigned int b):
if a<=b:
return a
Expand Down Expand Up @@ -187,9 +197,9 @@ SBFirst = {
LSBFirst : "LSBFirst"
}

cdef const char *XRGB = "XRGB"
cdef const char *RGB565 = "RGB565"
cdef const char *BGR565 = "BGR565"
cdef const char *XRGB = "XRGB"
cdef const char *BGRX = "BGRX"
cdef const char *ARGB = "ARGB"
cdef const char *BGRA = "BGRA"
Expand All @@ -199,7 +209,7 @@ cdef const char *RGBX = "RGBX"
cdef const char *R210 = "R210"
cdef const char *r210 = "r210"

RGB_FORMATS = [XRGB, BGRX, ARGB, BGRA, RGB, RGBA, RGBX, R210, r210]
RGB_FORMATS = [XRGB, BGRX, ARGB, BGRA, RGB, RGBA, RGBX, R210, r210, RGB565, BGR565]


cdef int ximage_counter = 0
Expand Down Expand Up @@ -239,7 +249,6 @@ cdef class XImageWrapper(object):
self.sub = sub
self.pixels = <void *> pixels
self.timestamp = int(time.time()*1000)


cdef set_image(self, XImage* image):
assert not self.sub
Expand Down Expand Up @@ -321,9 +330,7 @@ cdef class XImageWrapper(object):
cdef void *src = self.get_pixels_ptr()
if src==NULL:
raise Exception("source image does not have pixels!")
cdef unsigned char Bpp = 4
if self.depth==16:
Bpp = 2
cdef unsigned char Bpp = BYTESPERPIXEL(self.depth)
cdef uintptr_t sub_ptr = (<uintptr_t> src) + x*Bpp + y*self.rowstride
return XImageWrapper(self.x+x, self.y+y, w, h, sub_ptr, self.pixel_format, self.depth, self.rowstride, 0, True, True)

Expand Down Expand Up @@ -630,9 +637,7 @@ cdef class XShmImageWrapper(XImageWrapper):
return NULL
assert self.height>0
#calculate offset (assuming 4 bytes "pixelstride"):
cdef unsigned char Bpp = 4
if self.depth==16:
Bpp = 2
cdef unsigned char Bpp = BYTESPERPIXEL(self.depth)
cdef void *ptr = image.data + (self.y * self.rowstride) + (Bpp * self.x)
xshmdebug("XShmImageWrapper.get_pixels_ptr()=%#x %s", <uintptr_t> ptr, self)
return ptr
Expand Down

0 comments on commit 2795f37

Please sign in to comment.