Skip to content

proposed fix for transparency issue #27173 #27406

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

Closed
wants to merge 1 commit into from

Conversation

JakobRing
Copy link

Suggestion by @Wuzuw, another friend and me for the closing of #27173

We suggest to check if the pillowwriter is used. If so we use the fix by @tacaswell in #19040 and if ffmpeg is used we use the standard rgba-values because ffmpeg can deal with transparency.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@tacaswell
Copy link
Member

@JakobRing @Wuzuw do you have any interest in coming back to this PR? It seems reasonable but needs a bit of work (use isinstance, remove the print, is there anyway we can test this?)

@tacaswell tacaswell added this to the v3.10.0 milestone Jul 5, 2024
@@ -1079,7 +1079,11 @@ def func(current_frame: int, total_frames: int) -> Any

def _pre_composite_to_white(color):
r, g, b, a = mcolors.to_rgba(color)
return a * np.array([r, g, b]) + 1 - a
if type(writer) == PillowWriter:
Copy link
Member

Choose a reason for hiding this comment

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

this needs to be addressed

Suggested change
if type(writer) == PillowWriter:
if isinstance(writer, PillowWriter):

@@ -1079,7 +1079,11 @@ def func(current_frame: int, total_frames: int) -> Any

def _pre_composite_to_white(color):
r, g, b, a = mcolors.to_rgba(color)
return a * np.array([r, g, b]) + 1 - a
if type(writer) == PillowWriter:
print("no true transparency using pillow")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
print("no true transparency using pillow")

print("no true transparency using pillow")
return a * np.array([r, g, b]) + 1 - a
else:
return np.array([r, g, b, a])

savefig_kwargs['facecolor'] = _pre_composite_to_white(facecolor)
Copy link
Member

Choose a reason for hiding this comment

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

Given the name of the internal function _pre_composite_to_white, I think it makes more sense to put the conditional around this bit of code (and just not call the function if we don't need it) rather than make the function actually do "maybe pre-composite with white based on the type of something in my outer scope".

@tacaswell
Copy link
Member

Another question here is that is it better to have a "known bad" list or a "known good" list? I'm inclined to think it should be "known good" and the check should probably be more through than just the type of the writer (re-skimming the linked issues I think it depends on the encoding used not just the program).

@tacaswell
Copy link
Member

We probably also need to add a keyword arguement to save that defaults to None (we try to guess) and then True/False to control if we do the pre-compositing.

@tacaswell
Copy link
Member

This is superseded by #29024 . Thank you for your work @JakobRing and hopefully we will hear from you again.

@tacaswell tacaswell closed this Oct 30, 2024
@tacaswell tacaswell removed this from the v3.10.0 milestone Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for author
Development

Successfully merging this pull request may close these issues.

3 participants