Skip to content

Refactor alphablit #3404

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

Merged
merged 6 commits into from
Jun 18, 2025
Merged

Conversation

MightyJosip
Copy link
Member

Current alphablit has way too many repetitive code. For example, in each blend blitter, around 90% of the code is the same. So I decided to move it into the macro, and by that, reduce the file by around 40% of the lines.

The good side of this commit is that if we do eventual change on the blitter code, we only need to do it in the one place, the code became more modular. However, macros probably make the code harder to read, so we need to decide will we proceed with this change

@MightyJosip MightyJosip requested a review from a team as a code owner April 19, 2025 08:47
@MightyJosip MightyJosip added the Code quality/robustness Code quality and resilience to changes label Apr 19, 2025
@Starbuck5
Copy link
Member

Hi JoKing, this PR is a good modernization effort idea.

One thing I've learned in my experience with macros in the pygame-ce codebase is that it's nice when the function names are not macro-ed, because then you can use your editor to jump to them or just search for them. Like after this PR if I want to go see what blit_blend_add does I only find where it's called, not the definition. (I also see the declarations with little warnings that the function is not defined anywhere).

This PR also has a merge conflict at this point.

@MightyJosip
Copy link
Member Author

Thanks. Yea I agree with you, makes sense, I will change it a bit

Copy link
Member

@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.

This looks good, thanks @MightyJosip.

I made a couple enhancements to the implementation in my own 2 commits, I figured it was just easier to commit what I had in mind than send the idea over to you. But I simplified the macros a bit (they don't need to be written like function calls, temp variables can be declared outside), and I also renamed the arguments to be more descriptive and match macro naming conventions (all caps). If you disagree with those changes feel free to revert my commits (it's your branch after all).

@MightyJosip
Copy link
Member Author

Yea sure, thanks for helping, the commit is better now

@ankith26 ankith26 added this to the 2.5.6 milestone Jun 18, 2025
Copy link
Member

@ankith26 ankith26 left a comment

Choose a reason for hiding this comment

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

+470 and -1725, I love seeing PRs with huge negative diffs 😄

great cleanups and duplication removals, I did a side by side compare of alphablit.c after expanding macros and didn't find any issues (infact I think this PR fixes a minor issue, there were duplicated SDL_MapRGB calls before this PR in some places)

@ankith26 ankith26 merged commit 2adc056 into pygame-community:main Jun 18, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code quality/robustness Code quality and resilience to changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants