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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 24th August 2011, 03:40   #1  |  Link
jmac698
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
}
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.
jmac698 is offline   Reply With Quote
Old 24th August 2011, 09:26   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by jmac698 View Post
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.
Gavino is offline   Reply With Quote
Old 24th August 2011, 10:55   #3  |  Link
jmac698
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.
jmac698 is offline   Reply With Quote
Old 24th August 2011, 11:24   #4  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by jmac698 View Post
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) {
    env->AddFunction("sin", "f", Sin, 0);
    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 ???
StainlessS is offline   Reply With Quote
Old 24th August 2011, 13:59   #5  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
Quote:
Originally Posted by jmac698 View Post
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:

http://forum.doom9.org/showthread.php?t=48261
Guest is offline   Reply With Quote
Old 24th August 2011, 12:39   #6  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Probably something many have not noticed in the 2.6.0.2 release notes :-
  • Add BitAnd(), BitNot(), BitOr() and BitXor() script functions.
IanB is offline   Reply With Quote
Old 24th August 2011, 15:01   #7  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
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.
StainlessS is offline   Reply With Quote
Old 24th August 2011, 15:47   #8  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
Quote:
Originally Posted by StainlessS View Post
I'm pretty sure jmac698 means a C++ tutorial for C programmers
Huh? He said this: "tutorial for C++ plugin development ".
Guest is offline   Reply With Quote
Old 24th August 2011, 16:19   #9  |  Link
jmac698
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*
jmac698 is offline   Reply With Quote
Old 24th August 2011, 19:59   #10  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
Use 2.5.8. 2.6.0 is not quite ready for prime time, IMHO.
Guest is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 22:56.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.