-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Add transform.hsl()
#2398
Add transform.hsl()
#2398
Conversation
Looks fairly good, only thing really needed now is tests, and it should be good to go. |
Bulk of the work is done. I changed the algorithm for a 19% perf improvement, added tests and docs.
I still don't know the cause of the issue as it could be multiple sources, but the algorithm performs as expected for what I tested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this works well, I just have a couple of questions about surface locking and unlocking and as this seems to be done in several different ways all over the transform module. Looking up the python C API it seems to say:
Note Calling system I/O functions is the most common use case for releasing the GIL, but it can also be useful before calling long-running computations which don’t need access to Python objects, such as compression or cryptographic functions operating over memory buffers. For example, the standard zlib and hashlib modules release the GIL when compressing or hashing data.
Which I think all our transforms would qualify for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spent a bit of time looking into surface locking in SDL. Basically it is only needed when the surface has been RLE encoded.
As far as I can tell (though there is an open bug about it, but I agree with the last comment), MUST_LOCK(surf)
tells us whether the surface needs locking - which, if true, is something we should do before any direct pixel access.
I've added two suggestions to the code here that will lock the surface before accessing the pixels and then gate the call to unlock only if the surface is already locked.
Untested, but you could probably create a surface with RLE - blitting it to activate the RLE encoding on the surface - and then try running the hsl function post blit to create a good test of locking/unlocking.
Itzpr brought up a bug on discord where only changing lightness would lead to unexpected results. I see he's given this PR a "dont merge" label to reflect this, but I'm going to move it to draft just to take it off the review docket while this is resolved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, very good!
Closes #2310.
This PR implements a general purpose function that lets users modify Surface's hue, saturation and lighness values.