-
Notifications
You must be signed in to change notification settings - Fork 44
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
Fix save() in the quartz backend #645
Conversation
Implement the buffer interface and use PIL.Image.frombuffer()
We didn't have drawing tests for the quartz backend, so I added them. The drawing tests rely on |
Closing and opening the PR to trigger CI jobs. Not sure why but the PR has been stuck on Yellow for a while now i.e. "Waiting for status to be reported" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I can confirm the changes in this branch fixed the issues I was having with the quartz backend when running the benchmarking script.
|
||
# Previously this method checked for red pixels. However this is | ||
# not [currently] possible with the quartz backend because it writes | ||
# out image with premultiplied alpha and none of its pixels are the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is from the if 'A' in mode:
block in the above file correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not. The premultiplied alpha setting happens in the __init__
method of the graphics context. I couldn't find a way to have normal alpha, so I changed the test and added this note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So there are a few constraints here:
alpha_info
can only bekCGImageAlphaPremultipliedLast
orkCGImageAlphaPremultipliedFirst
ifsave()
is called on a graphics context.- From the "Supported Pixel Formats" table on this page, you can see that only 8, 16, and 32bit pixel formats are supported, so we can't even make a packed 24bit pixel buffer which would make alpha-free saving possible.
We can definitely implement saving RGB/BGR images, but it's a question of time allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thank you!
def __releasebuffer__(self, Py_buffer *buffer): | ||
""" When PyBuffer_Release is called on buffers from __getbuffer__. | ||
""" | ||
# Just deallocate the shape and strides allocated by __getbuffer__. | ||
# Since buffer.obj is a referenced counted reference to this object | ||
# (thus keeping this object alive as long a connected buffer exists) | ||
# and we don't mutate `self.data` outside of __init__ and __dealloc__, | ||
# we have nothing further to do here. | ||
PyMem_Free(buffer.shape) | ||
PyMem_Free(buffer.strides) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aaronayres35 A bit more detail for future readers 😉
Thanks for the feedback |
save()
doesn't work at all currently. Implement the buffer interface and usePIL.Image.frombuffer()