flrs / blend_modes

Python package that implements image blend modes
MIT License
140 stars 28 forks source link

Add Cython implementation #9

Open flrs opened 5 years ago

flrs commented 5 years ago

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 https://github.com/flrs/blend_modes/issues/6#issuecomment-453372593_

flrs commented 5 years ago

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

AeroDEmi commented 1 year ago

Any news on the Numba side?

json7 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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