-
Notifications
You must be signed in to change notification settings - Fork 29
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
Is the Overlay Blending Mode Implemented Correctly? #6
Comments
Hi @JohnTravolski, No definitive answers yet for now. But there is a possibility that soft light and overlay are implemented differently in the Adobe world and in GIMP. If the tests of this package pass it means that the method implementation in blend_modes matches GIMP's methods. Let me know if you find out more! |
I found an interesting line here: https://docs.gimp.org/en/gimp-concepts-layer-modes.html "In some versions of GIMP, “Overlay” mode and “Soft light” mode are identical." This is reinforced here: https://gimpchat.com/viewtopic.php?f=28&t=6248#p77599 In the images displayed in the first link, the pictures for soft light and overlay appear to be identical, so I'm wondering in what versions of GIMP they are different. It seems kind of pointless to have two identical blending modes with different names. Were the equations in the first link the ones you used to implement the blending modes? EDIT: I went through your source code and verified that your implementation of soft light and overlay are indeed identical. Overlay uses:
Here's the algebraic simplification: |
I took a look at Wikipedia's implementation of Overlay and used your code as a basis to implement it. For example, given your code, in the overlay function definition, if I replace: with (using the Wikipedia formula):
Then the overlay blending mode gives a result that is indeed different from Soft Light and looks just like the results that After Effects gives me. For my purposes, this is the version of Overlay that I prefer, even if it's not what GIMP uses. |
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: 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). |
Updated version that runs faster (about a 20% speedup) for 8K images (uses fused types instead of dereferencing a function pointer each time): |
@JohnTravolski, thanks for doing work on the overlay code. I will implement it! |
@JohnTravolski awesome work with the Cython implementation! I think this is something that others could profit from and we should make it part of the package. |
How can I use this Cython implementation? |
It seems the the overlay blending mode produces the exact same output as the soft light blending mode, or at least it does in all of my tests. Are you confident that it's implemented correctly?
For reference, in Photoshop and After Effects, soft light and overlay look noticeably different.
The text was updated successfully, but these errors were encountered: