-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[MNT]: Replace BufferRegion/restore_region by (x, y, array) tuples and draw_image? #23882
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
Comments
Interesting. Have only put a little thought into this, but my initial reactions
|
I agree that As for removing |
I'm reminded that I wish the Image artist classes didn't do the subsetting/clipping for the renderer, and instead just passed the complete image (plus some way to know that the image itself hasn't changed). This would allow us to optimise the clipping using whatever tools are at our disposal in the renderer. There is no reason that the renderer couldn't call back to the image to do a software based clipping if the renderer doesn't want to implement anything itself (a reasonable default). I appreciate that this is off-topic for the issue, but just wanted to share this thought somewhere 💡 |
Summary
Based on the discussion at https://discourse.matplotlib.org/t/method-to-add-transparency-to-a-saved-bufferregion/23121 (thanks @raphaelquast), I realized it may be possible to get rid of the internal BufferRegion type and restore_region, in favor of copy_from_bbox returning a
tpl = (x, y, rgba_array)
tuple and usingcanvas.get_renderer().draw_image(gc, x, y, rgba_array)
to restore the region.draw_image
could specifically add support for passinggc = None
(i.e. create a throwaway gc just for this call), and then the restore call would becanvas.get_renderer().draw_image(None, *tpl)
which seems just fine. Or we can just keep restore_region as a canvas method (on FigureCanvasBase, without need of being overridden by backends) which does the right draw_image call on the renderer, only getting rid of Renderer.restore_region.Currently, restore_region just blindly copies the BufferRegion contents, without doing any alpha compositing; the new approach would instead alpha-composite against whatever was here before. However, most uses of copy_from_bbox/restore_region suppose opaque regions anyways, and callers can also modify the rgba_array's alpha channel as desired before calling draw_image. Hopefully the extra alpha compositing wouldn't be too much of a slowdown, or we could always extend draw_image to support rgb (not rgba) inputs and detect that in this case it can go through a fast path without alpha compositing.
The advantage of such a change would be to simplify the backend API (e.g. for third party backends), including removing the undocumented BufferRegion type. (Probably the correct transition path would be to first make the BufferRegion type fully opaque, by deprecating all its public methods.)
attn @tacaswell as I believe you have written quite a bit of docs about blitting.
Proposed fix
No response
The text was updated successfully, but these errors were encountered: