Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BGRa for compatibility with cairo #2053

Closed
wants to merge 5 commits into from

Conversation

arjennienhuis
Copy link
Contributor

Cairo uses BGRa format as its CAIRO_FORMAT_ARGB32

each pixel is a 32-bit quantity, with alpha in the upper 8 bits, then red, then green, then blue. The 32-bit quantities are stored native-endian. Pre-multiplied alpha is used. (That is, 50% transparent red is 0x80800000, not 0x80ff0000.)

This patch makes it possible to this:

Image.frombuffer("RGBA", (im.width, im.height), data, "raw", "BGRa", im.stride, 1)

instead of this:

im = Image.frombuffer("RGBA", (im.width, im.height), data, "raw", "RGBa", im.stride, 1)
r, g, b, a = im.split()
im = Image.merge("RGBA", (b, g, r, a))

@wiredfool
Copy link
Member

Question: Since the 32 bit quantities are native endian, are there any modes that would be required for similar streamlining on a bigendian machine?

@arjennienhuis
Copy link
Contributor Author

Yes, this needs tests. Can you give me a pointer how I do that? Can I just test the high level interfaces like Image.frombuffer() and tobytes()?

@arjennienhuis
Copy link
Contributor Author

For bigendian it would be "aRGB" I guess. I have no machine to test this on though. What uses bigendian that I could find?

@homm
Copy link
Member

homm commented Aug 7, 2016

I'm against adding new modes just for compatibility with something. This is just extra code to support, no one will do this. I'm closing in favor of #2055.

@homm homm closed this Aug 7, 2016
@homm
Copy link
Member

homm commented Aug 7, 2016

By the way, even in the current versions you can do the followings:

Image.frombuffer("RGBa", (im.width, im.height), data, "raw", "BGRa", im.stride, 1).convert('RGBA')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants