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. |
|
24th August 2011, 03:40 | #1 | Link |
Registered User
Join Date: Jan 2006
Posts: 1,867
|
New Script: Binary Logic
This is a utility to perform binary logic in Avisynth Script:
Code:
#Binary Logic Ver. 1.1 by jmac698 #Perform binary logic functions and/or #1.1: handle negative arguments, simplify code (thanks to suggestions by Gavino) a1=5 b1=1 op1="AND" c1=binbool(a1,b1,op1) a2=4 b2=2 op2="|" c2=binbool(a2,b2,op2) messageclip(string(a1)+op1+string(b1)+"="+string(c1)+", "+string(a2)+op2+string(b2)+"="+string(c2)) function binbool(int a, int b, string op){ #Find the binary AND or OR on a and b op=lcase(op) op=op=="or"?"||" : \ op=="and"?"&&" : \ strlen(op)==1?op+op:op binbool2(abs(a), abs(b), op, 0) } function binbool2(int a, int b, string op, int currresult){ m=max(a,b) pwr2=int(pow(2,floor(log(m)/log(2)))) bit_a=floor(a/pwr2) bit_b=floor(b/pwr2) t=eval(string(bool(bit_a))+op+string(bool(bit_b)))?pwr2:0 currresult=currresult+t a=a-bit_a*pwr2 b=b-bit_b*pwr2 a+b==0?currresult:binbool2(a, b, op, currresult) } function bool(int n){ #Return false if n=0, true otherwise n!=0 } Last edited by jmac698; 24th August 2011 at 10:53. |
24th August 2011, 09:26 | #2 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
It would be far simpler - trivial, even - to do this as a plugin.
Doing it in script language is an interesting exercise, but somewhat masochistic. Quote:
Perhaps binbool should check for and reject negative arguments. Last edited by Gavino; 24th August 2011 at 09:30. |
|
24th August 2011, 10:55 | #3 | Link |
Registered User
Join Date: Jan 2006
Posts: 1,867
|
Updated. I don't think I could have written a C plugin faster, and still no one has written a tutorial for C++ plugin development. But even better - this should have been in avisynth. I should make a suggestion for 2.6.
|
24th August 2011, 11:24 | #4 | Link | |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Quote:
----------------------------- Non-clip Sample Non-clip functions in plugins Unlike usual clip functions, non-clip functions return not frames of clip but single (scalar) value as AVSValue (variant of float, integer, boolean, string). Numeric function example Here's a sample from script.cpp, edited for external use (by foxyshadis, see discussion): 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"; } ------------------------ This is just a small excerpt from the file. The active part is "return sin(args[0].AsFloat());"
__________________
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 ??? |
|
24th August 2011, 13:59 | #5 | Link | |
Guest
Join Date: Jan 2002
Posts: 21,901
|
Quote:
http://neuron2.net/www.math.berkeley...xtensions.html Also, see here, of course: http://forum.doom9.org/showthread.php?t=48261 |
|
24th August 2011, 15:01 | #7 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
@neuron2
I'm pretty sure jmac698 means a C++ tutorial for C programmers, to explain all the fluffy stuff of C++. EDIT: I did start doing something along those lines in response to a PM session with jmac698, A guide to Avisynth C++ interface for C programmers, by a C++ novice. C++ guys are more likely to forget the differences, and may perhaps be less than best (oh no there's that word, forgive me) for such a task. EDIT: A tutorial on the C++ interface for C programmers.
__________________
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 August 2011 at 12:38. |
24th August 2011, 16:19 | #9 | Link |
Registered User
Join Date: Jan 2006
Posts: 1,867
|
He's knows what I mean, I was asking him to explain it to me before. I don't think I've seen that guide though...
http://sourceforge.net/projects/avis...0%5B110525%5D/ looks good, do you think it's ready to use yet? Am I going to lose compatibility with plugins? I meant to check it out but I forgot about the new release *shame* |
Thread Tools | Search this Thread |
Display Modes | |
|
|