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" |
aaronayres35
left a comment
There was a problem hiding this comment.
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.
This is from the if 'A' in mode: block in the above file correct?
There was a problem hiding this comment.
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.
So there are a few constraints here:
alpha_infocan only bekCGImageAlphaPremultipliedLastorkCGImageAlphaPremultipliedFirstifsave()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.
| 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.
@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()