Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve handling of alpha when saving to jpeg.#15437

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
QuLogic merged 1 commit intomatplotlib:masterfromanntzer:jpegalpha
Mar 24, 2020

Conversation

anntzer
Copy link
Contributor

@anntzeranntzer commentedOct 18, 2019
edited
Loading

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

  • Has Pytest style unit tests
  • Code isFlake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

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?

@@ -563,23 +563,26 @@ def print_jpg(self, filename_or_obj, *args, dryrun=False, pil_kwargs=None,
`PIL.Image.save` when saving the figure. These take precedence
over *quality*, *optimize* and *progressive*.
"""
FigureCanvasAgg.draw(self)
if dryrun:
return
# The image is "pasted" onto a white background image to safely
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The comment needs to be adapted.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

well, this is still pasting the figure over a white background.

@anntzer
Copy link
ContributorAuthor

anntzer commentedOct 18, 2019
edited
Loading

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.
Also, I think using more mpl/numpy APIs and fewer Pillow APIs (Image.paste) is actually clearer, not lower-level.

@@ -563,23 +563,25 @@ def print_jpg(self, filename_or_obj, *args, dryrun=False, pil_kwargs=None,
`PIL.Image.save` when saving the figure. These take precedence
over *quality*, *optimize* and *progressive*.
"""
FigureCanvasAgg.draw(self)
# The image is "pasted" onto a white background to handle transparency.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think the term "paste" is a bit misleading

Suggested change
#The image is "pasted" onto awhite background to handle transparency.
#Remove transparency by alpha-blending on an assumedwhite background

Copy link
ContributorAuthor

@anntzeranntzerOct 18, 2019
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

sure, sounds good, edited accordingly

We can compose the figure facecolor against a white background beforerendering the image, rather than after.  This saves an image compositionstep.
@QuLogic
Copy link
Member

Will this cause weird flickering on interactive views (maybe not regular figures that composite on white, but embedded/notebook/something else)?

@anntzer
Copy link
ContributorAuthor

I'm not sure why it would?

@QuLogic
Copy link
Member

I was thinking of stuff like changing the DPI, but I see setting the canvas manager is handled in the call stack above this one.

@QuLogicQuLogic merged commitbba7763 intomatplotlib:masterMar 24, 2020
@anntzeranntzer deleted the jpegalpha branchMarch 24, 2020 20:03
@QuLogicQuLogic added this to thev3.3.0 milestoneMar 24, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.3.0
Development

Successfully merging this pull request may close these issues.

3 participants
@anntzer@QuLogic@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp