Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
22nd November 2007, 00:38 | #1 | Link |
Registered User
Join Date: Nov 2007
Posts: 27
|
Implement not filter, but function
Guys, tell me please, is it possible (using C++) implement not filter, but just a function, which will return not a clip, but something different: string or integer?
If it is - please tell me how: just point me, how to approach this. |
23rd November 2007, 03:43 | #4 | Link | |
Registered User
Join Date: Nov 2007
Posts: 27
|
Quote:
Code:
AVSValue __cdecl Create_Filter(AVSValue args, void* user_data, IScriptEnvironment* env) And how "script.cpp" can help me? Can you, please, show the exact place to me? Thank you beforehand. |
|
23rd November 2007, 06:35 | #5 | Link |
Angel of Night
Join Date: Nov 2004
Location: Tangled in the silks
Posts: 9,559
|
Here's a sample from script.cpp, edited for external use:
Code:
AVSValue Sin(AVSValue args, void* user_data, IScriptEnvironment* env) { return sin(args[0].AsFloat()); } extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env) { env->AddFunction("sin", "f", Sin, 0); return "sin"; } |
23rd November 2007, 16:11 | #6 | Link |
Registered User
Join Date: Nov 2007
Posts: 27
|
Thank you.
And for each instance of AviSynth each own instance of plugin will be loaded? The reason of this question is following - if I have to return string I need to allocate it somewhere else, except the local variable. Now I'm acting like this: char p[200]; AVSValue Filter(AVSValue args, void* user_data, IScriptEnvironment* env) { ... strcpy(p,...); return p; } What will be the most correct solution of such problem, which will keep me away from all probles with multiple instances etc? |
23rd November 2007, 18:48 | #8 | Link |
Registered User
Join Date: Aug 2004
Location: Denmark
Posts: 807
|
__________________
Get my avisynth filters @ http://www.avisynth.org/tsp/ |
23rd November 2007, 19:31 | #9 | Link |
Registered User
Join Date: Nov 2007
Posts: 27
|
Thanks, I got, concerning strings, but, nevertheless is it true that for each instance of AviSynth each own instance of plugin will be loaded? So can I leave data in the variable and rely that it will save it till next call?
|
25th November 2007, 04:57 | #11 | Link |
AviSynth Enthusiast
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
|
http://forum.doom9.org/showthread.php?t=130383
Anyway, a number of my plug-ins have functions that don't return clips, so you can use them as examples. |
25th November 2007, 12:22 | #12 | Link |
AviSynth plugger
Join Date: Nov 2003
Location: Russia
Posts: 2,183
|
to FilterSDK
I made several attempts to write non-clip plugin function without success. So, I created tutorial how to write non-clip function and placed it to FilterSDK.
http://avisynth.org/mediawiki/Filter...on-clip_sample He who can, does. He who cannot, teaches. George Bernard Shaw, Man and Superman (1903) "Maxims for Revolutionists" http://www.quotationspage.com/quote/290.html |
24th July 2015, 16:58 | #13 | Link |
Formerly davidh*****
Join Date: Jan 2004
Posts: 2,496
|
An 8 year bump, but this seemed to be the most appropriate place to ask.
The example given in this thread is of a plugin that returns a float value, although the actual return type of the function is declared as AVSValue. Does this mean, then, that any variable declared in an AviSynth script is, fundamentally, an AVSValue? Is there any way with env->AddFunction to create a function that takes an AVSValue (regardless of whether it may really be a string, int, float, or clip) as an input parameter? I can think of scenarios where this would be useful. Secondly, is a string stored as an AVSValue a null-terminated one? |
24th July 2015, 19:51 | #14 | Link | |||
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Quote:
It will then accept an AVSValue of any underlying type. Quote:
Use AsString() to get a pointer to the contained null-terminated string. |
|||
24th July 2015, 22:15 | #15 | Link | |
Formerly davidh*****
Join Date: Jan 2004
Posts: 2,496
|
Thanks Gavino!
Quote:
For example, say I have a pointer (void*) to a block of data (could be floats, ints, anything - my code will know what to do with it later), and I know the number of bytes. Can I turn that into a single AVSValue that can be returned by a plugin function and assigned to an in-script variable, either as a string (in which case I'd still need to get it back as a block of data plus number of bytes later) or in some other fashion? |
|
25th July 2015, 00:04 | #16 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
In principle, you could get away with it by passing your void* pointer to the AVSValue(const char*) constructor.
But things would go horribly wrong if anything in the script tried to treat the thing as a string, as it would be expecting it to be null-terminated. |
25th July 2015, 00:22 | #17 | Link | |
Excessively jovial fellow
Join Date: Jun 2004
Location: rude
Posts: 1,100
|
Quote:
or don't, and use a frameserver that actually supports passing arbitrary data around instead of insisting on using a tool that makes every problem look like a nail |
|
25th July 2015, 14:51 | #18 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
David, some RT funcs where using video frame as storage (as suggested by TheFluff above).
Code:
***************************************************** ******************* WEIRD FUNCTIONS ***************** ***************************************************** RT_FloatAsRGBA(float) Given a float arg, returns an int formatted as for use as a color to eg BlankClip. Can later be recovered from that clip using RT_RGB32AsFloat(). *** *** *** RT_RGB32AsFloat(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0) Compile/Runtime clip function. Given an RGB32 clip that had a pixel value created via RT_FloatAsRGBA(), gets that pixel and returns as the original float given to RT_FloatAsRGBA. By creating single pixel clips and stacking them horizontally/vertically, you can use a frame as a two dimensional array of float, perhaps use the frame number for a third dimension. *** *** *** RT_RGB32AsInt(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0) Compile/Runtime clip function. Given an RGB32 clip that had a pixel value created from an Int, gets that pixel and returns as the original Int. By creating single pixel clips and stacking them horizontally/vertically, you can use a frame as a two dimensional array of Int, perhaps use the frame number for a third dimension. Alternatively, you could perhaps use RT array (or DBase) for storage, it has type BIN (8 bit unsigned char [EDIT: returned as int 0-255]) and array size can be up to about 2GB single dimension array of BIN. Or, write your own file based data storage that could be accessed via self written run time funcs and also much faster for use in some kind of frame processing CPP func. EDIT: You would want some kind of header to ID as your own format BIN data, and offset via header size to access BIN data.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 25th July 2015 at 18:32. |
25th July 2015, 23:17 | #19 | Link |
Formerly davidh*****
Join Date: Jan 2004
Posts: 2,496
|
Thanks StainlessS.
Actually I am currently using clips as storage (with header IDs ) but I find it a little unsatisfactory as it seems unnecessarily abstract and open to accidental corruption. I will experiment with AVSValues (which will give me their own headaches, I'm sure) with Gavino's information and see what can be achieved. Last edited by wonkey_monkey; 25th July 2015 at 23:21. |
26th July 2015, 17:43 | #20 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
See also here (two page thread):- http://forum.doom9.org/showthread.ph...ta+AddFunction
(EDIT: mainly 2nd page) I've never actually used user_data for anything, could be used to allocate mem before AddFunction and pass as arg a pointer to your memblock, would need to use the Avisynth AtExit function to release mem when Avisynth closes down. Here the AddFunction used to add script function to Avisynth, user_data in blue: Code:
env->AddFunction("RT_TimerHP","",RT_TimerHP, 0); Code:
AVSValue __cdecl RT_TimerHP(AVSValue args, void* user_data, IScriptEnvironment* env) { return RT_TimerHP_Lo(); // Implicit type conversion to AVSValue float } user_data http://forum.doom9.org/showthread.ph...ta+AddFunction AtExit http://avisynth.nl/index.php/Filter_SDK/Non-clip_sample I am yet to see any good example that uses user_data, if you do choose to try out then post as would be fairly unique example for others and wiki. ############# env->SaveString:- http://avisynth.nl/index.php/Filter_SDK/Env_SaveString is written somewhere (in docs) that memory returned as string from plugin could be used by coder as general storage so long as you do not overrun allocated size, so could eg assign buffer to static pointer, and use other functions to access same pointer to edit/return contents, a bit dodgy looking but would work.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 26th July 2015 at 17:52. |
Thread Tools | Search this Thread |
Display Modes | |
|
|