Skip to content
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

Avoid an extra copy/resample if imshow input has no alpha #27562

Merged
merged 1 commit into from
Jan 10, 2024

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Dec 23, 2023

PR summary

This is probably the best we can do to fix #27554 at this time, without delving into re-writing the Agg resampler (which, as the Python code notes, does require RGBA.)

Also adds a test, as it appears that nothing checked an RGB input with transparent alpha (and my original suggestion from #27554 (comment) using 255/1.0 passed tests even though it didn't work.)

PR checklist

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

Can this get changed below as well in the else half of the interpolation_stage loop?

@tacaswell tacaswell added this to the v3.9.0 milestone Dec 26, 2023
This is probably the best we can do to fix matplotlib#27554 at this time, without
delving into re-writing the Agg resampler (which, as the Python code
notes, does require RGBA.)
@QuLogic
Copy link
Member Author

QuLogic commented Jan 3, 2024

This is in the else half, isn't it?

# No need to resample alpha or make a full array; NumPy will expand
# this out and cast to uint8 if necessary when it's assigned to the
# alpha channel below.
output_alpha = (255 * alpha) if A.dtype == np.uint8 else alpha
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't it be multiplying by 255 if it is a float, rather than if it is a uint8?

Copy link
Member Author

@QuLogic QuLogic Jan 9, 2024

Choose a reason for hiding this comment

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

alpha is always a 0-1 float; if the data is uint8, then output alpha must be 0-255 instead.

@jklymak jklymak merged commit 8542398 into matplotlib:main Jan 10, 2024
38 of 40 checks passed
@QuLogic QuLogic deleted the no-alpha-copy branch January 10, 2024 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Large image draw performance deterioration in recent releases
4 participants