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

Add Cython implementation #9

Open
flrs opened this issue Mar 9, 2019 · 5 comments
Open

Add Cython implementation #9

flrs opened this issue Mar 9, 2019 · 5 comments
Assignees

Comments

@flrs
Copy link
Owner

flrs commented Mar 9, 2019

You mentioned that these could be sped up if implemented in Cython. If you're interested, I have done so here, and gotten a pretty good speed improvement:
https://pastebin.com/fAD9avjP
If there're any obvious optimizations that I'm not seeing in the Cython code, feel free to let me know. I have successfully implemented all of Photoshop's blending modes, as well as yours, except the "Darker Color, Lighter Color, Hue, Saturation, Color, and Luminosity" blending modes (from Photoshop). I attempted hue, but couldn't quite figure it out; you'll see remnants of my attempt in the code.

The only implementation difference from yours is that each blend mode function already expects the input image to be divided by 255, and the output image is not multiplied by 255. This makes it easier to blend multiple layers together without unnecessary computation. So you have to do those division and multiplication steps manually before and after blending. They also don't require the input images to have an alpha channel (but it still works if either do).

Originally posted by @JohnTravolski in #6 (comment)

@flrs
Copy link
Owner Author

flrs commented Jul 14, 2019

Instead of Cython, something like https://numba.pydata.org/ can also be explored for use.

@AeroDEmi
Copy link

AeroDEmi commented Dec 5, 2022

Any news on the Numba side?

@json7
Copy link

json7 commented Apr 20, 2023

After I changed to the cython library you provided, the overlay effect was incorrect, which is different from the previous pure Python implementation. Why is this

@flrs
Copy link
Owner Author

flrs commented May 1, 2023

@AeroDEmi unfortunately no. I do not have resources to implement this change and I am looking for a community member to step up and help maintaining the project. See here.

@flrs
Copy link
Owner Author

flrs commented May 1, 2023

@json7 I would suggest you to add a new issue so the community can work on this question separately.

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

No branches or pull requests

3 participants