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.

 Doom9's Forum New Script: Binary Logic
 Register FAQ Calendar Search Today's Posts Mark Forums Read

 24th August 2011, 03:40 #1  |  Link jmac698 Registered User   Join Date: Jan 2006 Posts: 1,862 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 }``` If you can think of a simpler way to program this, let me know. It does the minimum loops necessary. Last edited by jmac698; 24th August 2011 at 10:53.
24th August 2011, 09:26   #2  |  Link
Gavino
Avisynth language lover

Join Date: Dec 2007
Location: Spain
Posts: 3,380
Quote:
 Originally Posted by jmac698 If you can think of a simpler way to program this, let me know.
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:
 Code: ` n==0?false:true`
You could just write n!=0 on its own.

Perhaps binbool should check for and reject negative arguments.
__________________
GScript and GRunT - complex Avisynth scripting made easier

Last edited by Gavino; 24th August 2011 at 09:30.

 24th August 2011, 10:55 #3  |  Link jmac698 Registered User   Join Date: Jan 2006 Posts: 1,862 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
StainlessS
HeartlessS Usurer

Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,792
Quote:
 Originally Posted by jmac698 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.
See Below from Avisynth SDK, file non-"clipsample.htm"
-----------------------------
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) {
return "sin";
}```
You don't even need a class/constructor, come to think of it. Include avisynth.h and that could be a whole plugin right there. (If not a terribly useful one.)
------------------------

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, 12:39 #5  |  Link IanB Avisynth Developer   Join Date: Jan 2003 Location: Melbourne, Australia Posts: 3,168 Probably something many have not noticed in the 2.6.0.2 release notes :-Add BitAnd(), BitNot(), BitOr() and BitXor() script functions.
24th August 2011, 13:59   #6  |  Link
Guest
Guest

Join Date: Jan 2002
Posts: 21,923
Quote:
 Originally Posted by jmac698 and still no one has written a tutorial for C++ plugin development
The creator of Avisynth, Ben Rudiak-Gould, wrote one. It is available at the mirror of his original site that I maintain:

http://neuron2.net/www.math.berkeley...xtensions.html

Also, see here, of course:

 24th August 2011, 15:01 #7  |  Link StainlessS HeartlessS Usurer     Join Date: Dec 2009 Location: Over the rainbow Posts: 5,792 @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, 15:47   #8  |  Link
Guest
Guest

Join Date: Jan 2002
Posts: 21,923
Quote:
 Originally Posted by StainlessS I'm pretty sure jmac698 means a C++ tutorial for C programmers
Huh? He said this: "tutorial for C++ plugin development ".

 24th August 2011, 16:19 #9  |  Link jmac698 Registered User   Join Date: Jan 2006 Posts: 1,862 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*
 24th August 2011, 19:59 #10  |  Link Guest Guest   Join Date: Jan 2002 Posts: 21,923 Use 2.5.8. 2.6.0 is not quite ready for prime time, IMHO.