def test_premultiply_argb_in_place(self): import array ar = array.array("I", [0x80ffffff, 0x306090b0]) l.premultiply_argb_in_place(ar) # Got each byte by calculating e.g.: # hex(int(0xb0 * (0x30 / 255.))) == 0x21 assert ar[0] == 0x80808080 assert ar[1] == 0x30121b21
# transmitted as CARDINALs, that's what we get. It might seem more # sensible to use ImageSurface.create_for_data (at least it did to me!) # but then you end up with a surface that refers to the memory you pass in # directly, and also .get_data() doesn't work on it, and it breaks the # test suite and blah. This at least works, as odd as it is: surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) # old versions of cairo do not have this method, just ignore it if not hasattr(surf, "get_data"): log.warn("Your Cairo is too old! Carrying on as best I can, " "but don't expect a miracle") return None surf.get_data()[:] = bytes # Cairo uses premultiplied alpha. EWMH actually doesn't specify what it # uses, but apparently the de-facto standard is non-premultiplied. (At # least that's what Compiz's sources say.) premultiply_argb_in_place(surf.get_data()) return (width * height, surf) # This returns a cairo ImageSurface which contains the largest icon defined in # a _NET_WM_ICON property. def NetWMIcons(disp, data): icons = [] stream = StringIO(data) while True: size_image = _read_image(disp, stream) if size_image is None: break icons.append(size_image) if not icons: return None icons.sort()
# transmitted as CARDINALs, that's what we get. It might seem more # sensible to use ImageSurface.create_for_data (at least it did to me!) # but then you end up with a surface that refers to the memory you pass in # directly, and also .get_data() doesn't work on it, and it breaks the # test suite and blah. This at least works, as odd as it is: surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) # old versions of cairo do not have this method, just ignore it if not hasattr(surf, "get_data"): log.warn("Your Cairo is too old! Carrying on as best I can, " "but don't expect a miracle") return None surf.get_data()[:] = bytes # Cairo uses premultiplied alpha. EWMH actually doesn't specify what it # uses, but apparently the de-facto standard is non-premultiplied. (At # least that's what Compiz's sources say.) premultiply_argb_in_place(surf.get_data()) return (width * height, surf) # This returns a cairo ImageSurface which contains the largest icon defined in # a _NET_WM_ICON property. def NetWMIcons(disp, data): icons = [] stream = StringIO(data) while True: size_image = _read_image(disp, stream) if size_image is None: break icons.append(size_image) if not icons: return None