Log in

View Full Version : Using plugins from plugins?


arnea
19th October 2021, 14:31
I'm writing (yet another) stabilization plugin. Last step of the processing would be panning the image. Basically I need to crop the image from one side and add borders to other side. I looked at the Crop and AddBorders plugins code - it's quite complicated, handles all the different formats and corner-cases, etc. I could just copypaste it, but I was wondering is it possible to actually call Crop and AddBorders from my own plugin to do the job? Sure, it's not so efficient, but the trying out things it would be sufficient.

StainlessS
19th October 2021, 19:09
Uglarm plugin:- https://forum.doom9.org/showthread.php?t=176891
does quite a few Invoke()'s, suggest take a peek at the source code.

here just a little bit


if(ShowMode >= 2) {
DPRINTF("ShowMode=%d",ShowMode)
ret = new Uglarm(ret,Pat_X,Pat_Y,Pat_W,Pat_H,SAR,BlurPower,Msk,xmod,ymod,hasChroma,ShowMode,env);
DPRINTF("Returned from Uglarm constructor")
// Blank Border
if(Blank) {
DPRINTF("Showing BLANK LetterBox")
// Letterbox (clip, int top, int bottom, [int left], [int right], int "color")
// un-named args NULL names
AVSValue LetterBox_Args[6] = { ret, ClipY, vi.height-ClipY-ClipH, ClipX, vi.width-ClipX-ClipW, 0x000000 };
const char* LetterBox_Names[6] = { NULL, NULL, NULL, NULL, NULL, "color" };
try {
DPRINTF("Calling Invoke LetterBox (Blank)")
ret = env->Invoke("LetterBox", AVSValue(LetterBox_Args,6),LetterBox_Names).AsClip();
DPRINTF("Invoke LetterBox Succeeds (Blank)")
} catch (IScriptEnvironment::NotFound) {
DPRINTF("Invoke LetterBox Fails (Blank)")
env->ThrowError("%sWhoa! Could not Invoke LetterBox! (Blank)",myName);
}
DPRINTF("Done Uglarm Blank")
}
} else {


The DPRINTF() calls just output some stuff to DebugView window [#ifdef BUG, otherwise outputs nothing].

and a bit more with crop

DPRINTF("Showing Hollow")
// Layer(c.crop(ClipX,ClipY,ClipW,ClipH).ExL_ResetMask,"add", Amount_Max, ClipX,ClipY) : Last # Hollow out non clipped area, with clip normal
AVSValue CropClip_Args[6] = { HollowSrc, ClipX, ClipY, ClipW, ClipH, true };
const char* CropClip_Names[6] = { NULL, NULL, NULL, NULL, NULL, "align" };
PClip CropClip;
try {
DPRINTF("Calling Invoke Crop (Hollow)")
CropClip = env->Invoke("Crop", AVSValue(CropClip_Args,6),CropClip_Names).AsClip();
DPRINTF("Invoke Crop Succeeds (Hollow)")
} catch (IScriptEnvironment::NotFound) {
DPRINTF("Invoke Crop Fails (Hollow)")
env->ThrowError("%sWhoa! Could not Invoke Crop! (Hollow)",myName);
}
if(vi.IsRGB32() || ConvRGB24) { // If RGB32 or RGB24 Converted to RGB32
DPRINTF("ResetMask on RGB32")
AVSValue ResetMask_Args[1] = { CropClip};
const char* ResetMask_Names[1] = { NULL};
try {
DPRINTF("Calling Invoke ResetMask (Hollow)")
CropClip = env->Invoke("ResetMask", AVSValue(ResetMask_Args,1),ResetMask_Names).AsClip();
DPRINTF("Invoke ResetMask Succeeds (Hollow)")
} catch (IScriptEnvironment::NotFound) {
DPRINTF("Invoke ResetMask Fails (Hollow)")
env->ThrowError("%sWhoa! Could not Invoke ResetMask! (Hollow)",myName);
}
}


EDIT: Above, CropClip_Names NULL's are for un-named args, the last one "align" is optional named.

EDIT: Invoke on wiki:- http://avisynth.nl/index.php/Filter_SDK/Env_Invoke

My code does some Invokes (eg ConvertToRGB32) in the 'Create_Uglarm' function which calls the constructor,
and then does more invokes on the clip returned from the constructor, to eg convert back to YV12 or whatever.

EDIT: Below, Wonkey suggests resizer rather than crop, yes, that is better than crop.

wonkey_monkey
19th October 2021, 19:10
For that you can use env->Invoke(...)

http://avisynth.nl/index.php/Filter_SDK/Env_Invoke

Crop and AddBorders will only get you pixel-accurate (or less, depending on colour format) panning, though. Instead you can use one of the resizers with offsets (be warned that bicubicresize will soften your image unless you set b = 0 and c = 0.5, if I remember correctly).