Ticket #463: rgb-no-PIL.patch
File rgb-no-PIL.patch, 8.4 KB (added by , 7 years ago) |
---|
-
xpra/codecs/argb/argb.pxd
5 5 # later version. See the file COPYING for details. 6 6 7 7 8 cdef argbdata_to_pixdata(const unsigned long* data, int len)8 cdef argbdata_to_pixdata(const unsigned int* data, int len) -
xpra/codecs/argb/argb.pyx
30 30 31 31 def argb_to_rgba(buf): 32 32 # b is a Python buffer object 33 cdef const unsigned long * cbuf = <unsigned long*> 033 cdef const unsigned int * cbuf = <unsigned int *> 0 34 34 cdef Py_ssize_t cbuf_len = 0 35 35 assert sizeof(int) == 4 36 36 assert len(buf) % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % len(buf) 37 37 assert PyObject_AsReadBuffer(buf, <const void**> &cbuf, &cbuf_len)==0 38 38 return argbdata_to_pixdata(cbuf, cbuf_len) 39 39 40 cdef argbdata_to_pixdata(const unsigned long* data, int dlen):40 cdef argbdata_to_pixdata(const unsigned int* data, int dlen): 41 41 if dlen <= 0: 42 42 return None 43 43 assert dlen % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % dlen 44 44 b = make_byte_buffer(dlen) 45 45 cdef int offset = 0 46 46 cdef int i = 0 47 cdef unsigned longrgba48 cdef unsigned longargb47 cdef unsigned int rgba 48 cdef unsigned int argb 49 49 cdef unsigned char b1, b2, b3, b4 50 50 while i < dlen/4: 51 51 argb = data[i] & 0xffffffff 52 rgba = <unsigned long> ((argb << 8) | (argb >> 24)) & 0xffffffff52 rgba = <unsigned int> ((argb << 8) | (argb >> 24)) & 0xffffffff 53 53 b1 = (rgba >> 24) & 0xff 54 54 b2 = (rgba >> 16) & 0xff 55 55 b3 = (rgba >> 8) & 0xff … … 64 64 65 65 def argb_to_rgb(buf): 66 66 # b is a Python buffer object 67 cdef unsigned long * cbuf = <unsigned long*> 0 #@DuplicateSignature67 cdef unsigned int * cbuf = <unsigned int *> 0 #@DuplicateSignature 68 68 cdef Py_ssize_t cbuf_len = 0 #@DuplicateSignature 69 69 assert sizeof(int) == 4 70 70 assert len(buf) % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % len(buf) 71 71 assert PyObject_AsReadBuffer(buf, <const void**> &cbuf, &cbuf_len)==0 72 72 return argbdata_to_rgb(cbuf, cbuf_len) 73 73 74 cdef argbdata_to_rgb(const unsigned long* data, int dlen):74 cdef argbdata_to_rgb(const unsigned int* data, int dlen): 75 75 if dlen <= 0: 76 76 return None 77 77 assert dlen % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % dlen 78 78 b = make_byte_buffer(dlen*3/4) 79 79 cdef int offset = 0 #@DuplicateSignature 80 80 cdef int i = 0 #@DuplicateSignature 81 cdef unsigned long rgba#@DuplicateSignature82 cdef unsigned long argb#@DuplicateSignature81 cdef unsigned int rgba #@DuplicateSignature 82 cdef unsigned int argb #@DuplicateSignature 83 83 cdef unsigned char b1, b2, b3 #@DuplicateSignature 84 while i < dlen/4: 85 argb = data[i] & 0xffffffff 86 rgba = <unsigned long> ((argb << 8) | (argb >> 24)) & 0xffffffff 84 cdef int mi = dlen/4 85 while i < mi: 86 argb = data[i] 87 rgba = <unsigned int> ((argb << 8) | (argb >> 24)) & 0xffffffff 87 88 b1 = (rgba >> 24) & 0xff 88 89 b2 = (rgba >> 16) & 0xff 89 90 b3 = (rgba >> 8) & 0xff … … 95 96 return b 96 97 97 98 99 def bgra_to_rgb(buf): 100 assert len(buf) % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % len(buf) 101 # buf is a Python buffer object 102 cdef unsigned int * bgra_buf = <unsigned int *> 0 #@DuplicateSignature 103 cdef Py_ssize_t bgra_buf_len = 0 #@DuplicateSignature 104 assert sizeof(int) == 4 105 assert PyObject_AsReadBuffer(buf, <const void**> &bgra_buf, &bgra_buf_len)==0 106 return bgradata_to_rgb(bgra_buf, bgra_buf_len) 107 108 cdef bgradata_to_rgb(const unsigned int* data, int dlen): 109 if dlen <= 0: 110 return None 111 assert dlen % 4 == 0, "invalid buffer size: %s is not a multiple of 4" % dlen 112 buf = make_byte_buffer(dlen*3/4) 113 cdef int bo = 0 #@DuplicateSignature 114 cdef int di = 0 #@DuplicateSignature 115 cdef unsigned int bgra #@DuplicateSignature 116 cdef unsigned char r, g, b #@DuplicateSignature 117 cdef int mdi = dlen/4 118 while di < mdi: 119 bgra = data[di] 120 b = (bgra >> 24) & 0xff 121 g = (bgra >> 16) & 0xff 122 r = (bgra >> 8) & 0xff 123 buf[bo] = r 124 buf[bo+1] = g 125 buf[bo+2] = b 126 bo = bo + 3 127 di = di + 1 128 return buf 129 130 98 131 def premultiply_argb_in_place(buf): 99 132 # b is a Python buffer object 100 133 cdef unsigned int * cbuf = <unsigned int *> 0 -
xpra/codecs/loader.py
57 57 return 58 58 loaded = True 59 59 debug("loading codecs") 60 codec_import_check("PIL", "Python Imaging Library", "PIL", "PIL", "Image")61 add_codec_version("PIL", "PIL.Image", "VERSION")60 #codec_import_check("PIL", "Python Imaging Library", "PIL", "PIL", "Image") 61 #add_codec_version("PIL", "PIL.Image", "VERSION") 62 62 63 63 codec_import_check("enc_vpx", "vpx encoder", "xpra.codecs.vpx", "xpra.codecs.vpx.encoder", "Encoder") 64 64 codec_import_check("dec_vpx", "vpx decoder", "xpra.codecs.vpx", "xpra.codecs.vpx.decoder", "Decoder") -
xpra/server/window_source.py
45 45 from xpra.codecs.xor import xor_str #@UnresolvedImport 46 46 except: 47 47 xor_str = None 48 try: 49 from xpra.codecs.argb.argb import bgra_to_rgb, argb_to_rgb 50 except: 51 bgra_to_rgb = None 52 argb_to_rgb = None 48 53 from xpra.os_util import StringIOClass 49 54 from xpra.codecs.loader import get_codec, has_codec, NEW_ENCODING_NAMES_TO_OLD 50 55 … … 1065 1070 def rgb_reformat(self, image): 1066 1071 #need to convert to a supported format! 1067 1072 pixel_format = image.get_pixel_format() 1073 pixels = image.get_pixels() 1074 PIL = get_codec("PIL") 1075 if not PIL: 1076 #fallback to argb module if we have the pixel format: 1077 if bgra_to_rgb and pixel_format in ("BGRX", "BGRA") and "RGB" in self.rgb_formats: 1078 image.set_pixels(bgra_to_rgb(pixels)) 1079 image.set_pixel_format("RGB") 1080 return True 1081 if argb_to_rgb and pixel_format in ("XRGB", "ARGB") and "RGB" in self.rgb_formats: 1082 image.set_pixels(argb_to_rgb(pixels)) 1083 image.set_pixel_format("RGB") 1084 return True 1085 self.warn_encoding_once(pixel_format+"-format-not-handled", "no PIL and no matching argb function, cannot convert %s to one of: %s" % (pixel_format, self.rgb_formats)) 1086 return False 1087 1068 1088 target_format = { 1069 1089 "XRGB" : "RGB", 1070 1090 "BGRX" : "RGB", … … 1076 1096 start = time.time() 1077 1097 w = image.get_width() 1078 1098 h = image.get_height() 1079 pixels = image.get_pixels()1080 PIL = get_codec("PIL")1081 if not PIL:1082 self.warn_encoding_once("no-PIL-module", "no PIL module, cannot convert %s to one of: %s" % (pixel_format, self.rgb_formats))1083 return False1084 1099 img = PIL.Image.frombuffer(target_format, (w, h), pixels, "raw", pixel_format, image.get_rowstride()) 1085 1100 rowstride = w*len(target_format) #number of characters is number of bytes per pixel! 1086 1101 data = img.tostring("raw", target_format) -
xpra/x11/bindings/keyboard_bindings.pyx
688 688 if image==NULL: 689 689 return None 690 690 l = image.width*image.height*4 691 pixels = argbdata_to_pixdata(<const unsigned long*> image.pixels, l)691 pixels = argbdata_to_pixdata(<const unsigned int*> image.pixels, l) 692 692 name = str(image.name) 693 693 return [image.x, image.y, image.width, image.height, image.xhot, image.yhot, 694 694 image.cursor_serial, pixels, name]