Improve handling of alpha when saving to jpeg. - #15437
Conversation
timhoffm
left a comment
There was a problem hiding this comment.
Temporarily changing the figure background and manually calculating the alpha-shading towards white is more low-level. It's harder to understand what's going on and it might be more susceptible of introducing bugs in the future.
Is the performance gain worth it?
There was a problem hiding this comment.
The comment needs to be adapted.
There was a problem hiding this comment.
well, this is still pasting the figure over a white background.
|
Actually, another motivation for the change is to make buffer_rgba() return an array that can be directly passed to imsave() -- essentially doing the same thing as in #15435, but for jpeg. |
| over *quality*, *optimize* and *progressive*. | ||
| """ | ||
| FigureCanvasAgg.draw(self) | ||
| # The image is "pasted" onto a white background to handle transparency. |
There was a problem hiding this comment.
I think the term "paste" is a bit misleading
| # The image is "pasted" onto a white background to handle transparency. | |
| # Remove transparency by alpha-blending on an assumed white background |
There was a problem hiding this comment.
sure, sounds good, edited accordingly
We can compose the figure facecolor against a white background before rendering the image, rather than after. This saves an image composition step.
|
Will this cause weird flickering on interactive views (maybe not regular figures that composite on white, but embedded/notebook/something else)? |
|
I'm not sure why it would? |

We can compose the figure facecolor against a white background before
rendering the image, rather than after. This saves an image composition
step.
PR Summary
PR Checklist