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

Simplified for loop for some image manipulation functions #3712

Merged
merged 1 commit into from
Jan 6, 2024

Conversation

Minnowo
Copy link
Contributor

@Minnowo Minnowo commented Jan 6, 2024

The image manipulation functions ImageColorInvert, ImageColorBrightness, ImageColorReplace, and ImageColorTint all used a nested for loop with some math to index the 1d array of pixels.

These loops could be simplified to a single loop with a counter. I think this is not only more readable, but it has also shown some slight speed increases for very large images. My numbers below using the diff of time.h's clock function for a 7096 x 10031 image:

before:

brightness 0.932933
replace 0.910925
tint 1.116619
invert 0.785766

after:

brightness 0.784316
replace 0.782897
tint 0.934186
invert 0.699755

@raysan5 raysan5 merged commit be0ea89 into raysan5:master Jan 6, 2024
@raysan5
Copy link
Owner

raysan5 commented Jan 6, 2024

@Minnowo Nice improvement! Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants