def update_icon(self, width, height, coding, data): log("%s.update_icon(%s, %s, %s, %s bytes)", self, width, height, coding, len(data)) if coding == "premult_argb32": if unpremultiply_argb is not None: #we usually cannot do in-place and this is not performance critical data = byte_buffer_to_buffer(unpremultiply_argb(data)) pixbuf = gdk.pixbuf_new_from_data(data, gtk.gdk.COLORSPACE_RGB, True, 8, width, height, width * 4) else: # slower fallback: we round-trip through PNG. # This is ridiculous, but faster than doing a bunch of alpha # un-premultiplying and byte-swapping by hand in Python cairo_surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) cairo_surf.get_data()[:] = data loader = gdk.PixbufLoader() cairo_surf.write_to_png(loader) loader.close() pixbuf = loader.get_pixbuf() else: loader = gdk.PixbufLoader(coding) loader.write(data, len(data)) loader.close() pixbuf = loader.get_pixbuf() self.set_icon(pixbuf)
def unpremultiply(self, img_data): if type(img_data) == str: #cannot do in-place: assert unpremultiply_argb is not None, "missing argb.unpremultiply_argb" return byte_buffer_to_buffer(unpremultiply_argb(img_data)) #assume this is a writeable buffer (ie: ctypes from mmap): assert unpremultiply_argb_in_place is not None, "missing argb.unpremultiply_argb_in_place" unpremultiply_argb_in_place(img_data) return img_data
def unpremultiply(self, img_data): if type(img_data)==str: #cannot do in-place: assert unpremultiply_argb is not None, "missing argb.unpremultiply_argb" return byte_buffer_to_buffer(unpremultiply_argb(img_data)) #assume this is a writeable buffer (ie: ctypes from mmap): assert unpremultiply_argb is not None, "missing argb.unpremultiply_argb_in_place" unpremultiply_argb_in_place(img_data) return img_data
def update_icon(self, width, height, coding, data): log("%s.update_icon(%s, %s, %s, %s bytes)", self, width, height, coding, len(data)) coding = bytestostr(coding) if coding == "premult_argb32": if unpremultiply_argb is None: #we could use PIL here with mode 'RGBa' log.warn("cannot process premult_argb32 icon without the argb module") return #we usually cannot do in-place and this is not performance critical data = byte_buffer_to_buffer(unpremultiply_argb(data)) pixbuf = pixbuf_new_from_data(data, COLORSPACE_RGB, True, 8, width, height, width*4) else: loader = PixbufLoader() loader.write(data) loader.close() pixbuf = loader.get_pixbuf() log("%s.set_icon(%s)", self, pixbuf) self.set_icon(pixbuf)
def _do_paint_rgb32(self, img_data, x, y, width, height, rowstride, options, callbacks): #log.debug("do_paint_rgb32(%s bytes, %s, %s, %s, %s, %s, %s, %s) backing depth=%s", len(img_data), x, y, width, height, rowstride, options, callbacks, self._backing.get_depth()) #log.info("data head=%s", [hex(ord(v))[2:] for v in list(img_data[:500])]) if self._backing is None: return False from xpra.codecs.argb.argb import unpremultiply_argb, unpremultiply_argb_in_place, byte_buffer_to_buffer #@UnresolvedImport if type(img_data)==str or not hasattr(img_data, "raw"): #cannot do in-place: img_data = byte_buffer_to_buffer(unpremultiply_argb(img_data)) else: #assume this is a writeable buffer (ie: ctypes from mmap): unpremultiply_argb_in_place(img_data) pixbuf = gdk.pixbuf_new_from_data(img_data, gtk.gdk.COLORSPACE_RGB, True, 8, width, height, rowstride) cr = self._backing.cairo_create() cr.rectangle(x, y, width, height) cr.set_source_pixbuf(pixbuf, x, y) cr.set_operator(cairo.OPERATOR_SOURCE) cr.paint() return True
def _do_paint_rgb32(self, img_data, x, y, width, height, rowstride, options, callbacks): #log.debug("do_paint_rgb32(%s bytes, %s, %s, %s, %s, %s, %s, %s) backing depth=%s", len(img_data), x, y, width, height, rowstride, options, callbacks, self._backing.get_depth()) #log.info("data head=%s", [hex(ord(v))[2:] for v in list(img_data[:500])]) if self._backing is None: return False from xpra.codecs.argb.argb import unpremultiply_argb, unpremultiply_argb_in_place, byte_buffer_to_buffer #@UnresolvedImport if type(img_data) == str or not hasattr(img_data, "raw"): #cannot do in-place: img_data = byte_buffer_to_buffer(unpremultiply_argb(img_data)) else: #assume this is a writeable buffer (ie: ctypes from mmap): unpremultiply_argb_in_place(img_data) pixbuf = gdk.pixbuf_new_from_data(img_data, gtk.gdk.COLORSPACE_RGB, True, 8, width, height, rowstride) cr = self._backing.cairo_create() cr.rectangle(x, y, width, height) cr.set_source_pixbuf(pixbuf, x, y) cr.set_operator(cairo.OPERATOR_SOURCE) cr.paint() return True
def update_icon(self, width, height, coding, data): log("%s.update_icon(%s, %s, %s, %s bytes)", self, width, height, coding, len(data)) coding = bytestostr(coding) if coding == "premult_argb32": if unpremultiply_argb is None: #we could use PIL here with mode 'RGBa' log.warn( "cannot process premult_argb32 icon without the argb module" ) return #we usually cannot do in-place and this is not performance critical data = unpremultiply_argb(data) rgba = byte_buffer_to_buffer(bgra_to_rgba(data)) pixbuf = get_pixbuf_from_data(rgba, True, width, height, width * 4) else: loader = PixbufLoader() loader.write(data) loader.close() pixbuf = loader.get_pixbuf() log("%s.set_icon(%s)", self, pixbuf) self.set_icon(pixbuf)
def update_icon(self, width, height, coding, data): self.debug("update_icon(%s, %s, %s, %s bytes)", width, height, coding, len(data)) if coding == "premult_argb32": if unpremultiply_argb is not None: # we usually cannot do in-place and this is not performance critical data = byte_buffer_to_buffer(unpremultiply_argb(data)) pixbuf = gdk.pixbuf_new_from_data(data, gtk.gdk.COLORSPACE_RGB, True, 8, width, height, width * 4) else: # slower fallback: we round-trip through PNG. # This is ridiculous, but faster than doing a bunch of alpha # un-premultiplying and byte-swapping by hand in Python cairo_surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) cairo_surf.get_data()[:] = data loader = gdk.PixbufLoader() cairo_surf.write_to_png(loader) loader.close() pixbuf = loader.get_pixbuf() else: loader = gdk.PixbufLoader(coding) loader.write(data, len(data)) loader.close() pixbuf = loader.get_pixbuf() self.set_icon(pixbuf)
def unpremultiply(self, img_data): try: unpremultiply_argb_in_place(img_data) return img_data except: return byte_buffer_to_buffer(unpremultiply_argb(img_data))