Skip to content

Add premul_alpha method to surface#3276

Merged
MyreMylar merged 14 commits intomainfrom
surface-premul-alpha
Dec 11, 2022
Merged

Add premul_alpha method to surface#3276
MyreMylar merged 14 commits intomainfrom
surface-premul-alpha

Conversation

@MyreMylar
Copy link
Copy Markdown
Contributor

This should simplify working with the BLEND_PREMULTIPLIED blend mode.

This is an adaption and simplification of an old PR I had lying around. If I get some time before the 2.1.4 release, I will add an AVX2 version of the pre-multiplication - though it's not critical as this shouldn't normally be a critical path function like blit.

I also now kind of want to work up a little BEFORE and AFTER demo program showing how to use the same assets in the old school (normal alpha blending, blits()) way versus the new-ish (premul_alpha(), BLEND_PREMULTIPLED, ublits() - maybe threaded blitting?) way.

@MyreMylar
Copy link
Copy Markdown
Contributor Author

I added a bit more information to the documentation. I have a task to make a larger tutorial on pre-multiplied alpha as well to try and explain how to use it with some worked examples.

@Starbuck5
Copy link
Copy Markdown
Contributor

If you call premul-alpha on a surface twice, will the first second result be different from the first?

@MyreMylar
Copy link
Copy Markdown
Contributor Author

MyreMylar commented Jul 13, 2022 via email

@itzpr3d4t0r
Copy link
Copy Markdown
Contributor

Yes, the output surface will be different because you will multiply by the
alpha again.

Maybe add this to the docs?

@MyreMylar
Copy link
Copy Markdown
Contributor Author

Yes, the output surface will be different because you will multiply by the
alpha again.

Maybe add this to the docs?

I can do.

Copy link
Copy Markdown
Contributor

@Starbuck5 Starbuck5 left a comment

Choose a reason for hiding this comment

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

Left a couple minor things to do before merge, but otherwise I couldn't find anything wrong in the PR. Nice job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New API This pull request may need extra debate as it adds a new class or function to pygame SIMD Surface pygame.Surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants