ermig1979 / Simd

C++ image processing and machine learning library with using of SIMD: SSE, AVX, AVX-512, AMX for x86/x64, VMX(Altivec) and VSX(Power7) for PowerPC, NEON for ARM.
http://ermig1979.github.io/Simd
MIT License
2.04k stars 407 forks source link

YUV equivalent of AlphaBlend #169

Closed mikeversteeg closed 3 years ago

mikeversteeg commented 3 years ago

Hi Ihar! I need to blend two images together to create a dissolve effect. My bitmaps are yuv420p, all same size. Doing a conversion to bgr, use AlphaBlend, and convert back to yuv420p, is too slow. I've gone over the documentation but see no function for this. Any chance you add this function to your library?

Thanks.

ermig1979 commented 3 years ago

Hi! I think that: 1) yuv to bgr and backward conversion is linear operation, 2) alpha blending is also linear operation. It seems that it is possible to skip conversion operation and apply alpha blending directly to yuv image.

mikeversteeg commented 3 years ago

Yes, I considered that too. But Windows' AlphaBlend takes handles to bgra bitmaps so I'm not sure if I can fake that. At the very least I still have to convert to/from yuva420 non-planar. Of course it is easy to write the algorithm myself, but that would be even slower as it is not SIMD.

mikeversteeg commented 3 years ago

Oh, I now see there is an alpha blend function in your library, cool! I did not find it even though I used the documentation's search function with proper keywords.. I will give it a try.

mikeversteeg commented 3 years ago

There is no way to set the alpha used to blend the two images? If I understand correctly I need to create a 3rd image where every pixel has same alpha value? Seems like overkill?

ermig1979 commented 3 years ago

Did you mean the blending with constant alpha? I can add this function.

mikeversteeg commented 3 years ago

Yes, to blend two yuv images and create dissolve effect (see my original post).

ermig1979 commented 3 years ago

I have done it. It gives up to 30% gain.

mikeversteeg commented 3 years ago

Wow, that was fast. Thank you! I'm looking forward to the release!

mikeversteeg commented 3 years ago

Did not want to wait until September so downloaded your "master" and can confirm your SimdAlphaBlendingUniform does exactly what I needed, thank you! Here's another virtual donation 🎁 :).