Log in

View Full Version : What formula is used by the Overlay filter?


viper_room
30th April 2012, 12:05
Hi

I need to multiply one video by another.
I can't upload images so I made a doc to explain it
https://docs.google.com/document/pub?id=1OA3dVAHEkQhPUy7W8t96TVbVNUNnxUCy884QyrfK-5A

I guess Overlay(origine,fixations, mode="multiply", opacity = 1.0) does it but I have to be bit-accurate and I can't find the "formula" that Overlay uses to merges files in multiply mode (I couldn't find the source).
Can someone please tell me what the formula is or where I can find the source?

Thanks!
CLaire

cretindesalpes
30th April 2012, 12:40
Multiply mode source code is here (http://avisynth2.cvs.sourceforge.net/viewvc/avisynth2/avisynth/src/filters/overlay/OF_multiply.cpp?view=markup).

int Y = (baseY[x] * ovY[x])>>8;
int U = (baseU[x] * ovY[x] + 128 * (256-ovY[x]) ) >> 8;
int V = (baseV[x] * ovY[x] + 128 * (256-ovY[x]) ) >> 8;

viper_room
30th April 2012, 12:55
Great!!
Thanks!!!

Gavino
30th April 2012, 14:00
Bear in mind that Overlay converts everything into an internal 4:4:4 format, so chroma is not exactly preserved.

If you want precise control of the calculation, use mt_lutxy.