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.01k stars 407 forks source link

Alpha Blending Usage Question #243

Closed robashton closed 1 year ago

robashton commented 1 year ago

Apologies if this is has a really obvious answer, I suspect this is just a difference of expectations WRT the API and desired usage and my lack of familiarity with such data oriented APIs.

We've got a scenario whereby we're needing to compose two images based on the alpha channel (in the second, it's assumed the background image is opaque).

Before we reach the composition function, one of these images is YUV420 (or similar), and the other is RGBA. In our naive rust implementation of 'compose', we convert to RGBA before doing the operation, and in our GPU accelerated implementation we convert to RGBA before doing the operation - this is obviously quite a simple matter of going through pixel by pixel (or blocks of pixels) and doing the standard alpha blending function on each pixel by unpacking the u8 byte for each channel and doing the maths in u16.

We'd like to add this library to our alternative path (and indeed, if it's faster which it probably will be, replace our rust code with it).

I'm not sure how to actually use it though, I think the operation I'm looking for is SimdAlphaBlending, but I see that that, as well as the other operations assumes that the alpha channel is provided separately from the two images being blended.

Should I be staying in YUV and using the alpha channel to do the blend operation on the planes in thw two images, or should I be constructing something different for the RGB + A operation? That sounds like a fair bit of copying which doesn't seem right so I'm assuming that I've just missed the point.

More concisely, if I've got

uint8_t* pImageRgba1 = ...
uint8_t* pImageRgba2 = ...

How do you want me to get from that format into something suitable to call SimdAlphaBlending with? Again - this is a really mundane and obvious question that I feel I should have been able to obviously gleam from the docs, but clearly I'm missing a fundamental somewhere about the place!

Cheers

ermig1979 commented 1 year ago

Hi! As I can see thу alpha blending of BGRA (ARGB) images to YUV420P is in demand. So I will add the functionality in the nearest future.

robashton commented 1 year ago

That would be even more amazing than you know, saving us a conversion per frame would be a game changer, never mind the (probably) increased speed of using your library in the first place.

ermig1979 commented 1 year ago

I added function AlphaBlendingBgraToYuv420p (no optimizations, only base implementation). Could you check it functionality before I start make its optimizations?

robashton commented 1 year ago

Super - I will do, but it'll be a couple of days while I finish with a different task and return to this!

ermig1979 commented 1 year ago

I added SSE4.1, AVX2 and AVX-512BW optimizations.

robashton commented 1 year ago

<3 - I'm coming up for air on [current task] today, and this is next on my list, if you don't hear from me again that means it worked great and I'm forever grateful for this addition.

robashton commented 1 year ago

I can't help myself, I've gotta come back and say thanks - I've integrated this into our code and it's looking very good indeed. :)