-
TL;DR: can we add some more "native byte order" raw unpacking modes other than I'm having a problem specifically coming from pycairo. Specifically, pycairo's I eventually constructed the formulation: buf = cairo_surface.get_data() # either aRGB or BGRa
pil_image = Image.frombuffer("I", size, bytes(buf), "raw", "I;32B", 0, 1)
fixed_buf = pil_image.tobytes("raw", "I;32S") # implied "native"; definitely aRGB
pygame_image = pygame.image.frombuffer(fixed_buf2, size, "ARGB")
pygame_screen.blit(pygame_image, (0,0), special_flags=pygame.BLEND_PREMULTIPLIED) Which gets the job done, technically, but really isn't clear at all, especially since I really wanted to read buf = cairo_surface.get_data() # either aRGB or BGRa
pil_image = Image.frombuffer("I", size, bytes(buf), "raw", "I;32", 0, 1) # now using little-endian
fixed_buf = pil_image.tobytes("raw", "I;32S") # implied "native"; definitely BGRa
pil_image2 = Image.frombuffer("RGBA", size, fixed_buf, "raw", "BGRa", 0, 1)
fixed_buf2 = pil_image2.tobytes("raw", "RGBA")
pygame_image = pygame.image.frombuffer(fixed_buf2, size, "RGBA")
pygame_screen.blit(pygame_image, (0,0)) (What I really, truly, actually wanted was for cairo's So my questions here are:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Why isn't https://pycairo.readthedocs.io/en/latest/integration.html#pillow-pil-cairo sufficient for your purposes? Or, if you're only using Pillow as a stepping stone, https://pycairo.readthedocs.io/en/latest/tutorial/pygame.html#pygame-imagesurface seems like it would solve your problem. |
Beta Was this translation helpful? Give feedback.
-
With PR #6974, this should work with Pillow 9.5.0. |
Beta Was this translation helpful? Give feedback.
-
The closest we have at the moment is "RGBa;16N". However, looking at the code, it becomes clear that the channel order isn't swapped depending on the endianness, simply the values of each channel individually. Pillow/src/libImaging/Unpack.c Lines 1619 to 1634 in e7fa309 Pillow/src/libImaging/Unpack.c Lines 842 to 888 in e7fa309 So I'd be reluctant to introduce confusion into the process by introducing this new kind of unpacker. I think that answers all of your questions. Let us know if not. |
Beta Was this translation helpful? Give feedback.
Why isn't https://pycairo.readthedocs.io/en/latest/integration.html#pillow-pil-cairo sufficient for your purposes?
Or, if you're only using Pillow as a stepping stone, https://pycairo.readthedocs.io/en/latest/tutorial/pygame.html#pygame-imagesurface seems like it would solve your problem.