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 26th August 2005, 20:57   #41  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
tsp : thanks for the parser. But do you support ternary operators ( ? : ) ?
Quote:
I don't know how manao's parser handles that
Well, except for ? :, every operators are commutative. a b c ? is translated as a ? b : c.
Manao is offline   Reply With Quote
Old 26th August 2005, 21:12   #42  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
BTW, what is infix ? It doesn't take operator's priority into account, does it ? Because if so, your parser doesn't work ( 3 * 4 + 8 * 8 returns 3 4 8 8 * + * which is ((8 * 8) + 4) * 3 ).
Manao is offline   Reply With Quote
Old 26th August 2005, 23:18   #43  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
hmm your are right. Current the expressions is just evaluated from left to right so you have to set the parathesis the right place. I will fix that and also add support for the a?b:c notation currently it just works like a?b c -> a b c? so I only need to add support for the : . So any suggestions about the presedens. Maybe the same as c++ but does that means that ^ sin,cos,abs,log,exp etc. gets the same precedens before the / * or should maybe ^ have the highest precedens?
tsp is offline   Reply With Quote
Old 26th August 2005, 23:33   #44  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
I would have said:

unary functions
^
* /
+ -

With unary functions you would almost always expect to put brackets after them if they take a compound argument, i.e. sin(4*x), and the above reflects this behaviour.
__________________
a.k.a. Clouded. Come and help by making sure your favourite AVISynth filters and scripts are listed.
mg262 is offline   Reply With Quote
Old 26th August 2005, 23:50   #45  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
ok for some strange reason my calculator (a Texas Instrument 86) gives ^ the highest precedens
tsp is offline   Reply With Quote
Old 27th August 2005, 13:22   #46  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
Ok, finally, I managed to work with spirit. I must aknowledge it's great, though it takes times to compile. Anyway, here is the new build : alpha 5

Changelog :
Code:
 * added : helpers for creating string for inpand / expand custom modes :
   - mt_circle
   - mt_square
   - mt_diamond
   - mt_ellipse
   - mt_rectangle
   - mt_losange
 * added : helper for lut : consersion from infix to reverse polish notation : 
   - mt_polish
Manao is offline   Reply With Quote
Old 27th August 2005, 13:30   #47  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
Great! Is a losange the same as the diamond but with width and height allowed to differ?

(Not that it's really relevant but I think the English equivalent is lozenge ... it's not a word that is used very often.)
__________________
a.k.a. Clouded. Come and help by making sure your favourite AVISynth filters and scripts are listed.
mg262 is offline   Reply With Quote
Old 27th August 2005, 13:37   #48  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
Yep, it is. I wouldn't have thought it would be spelled differently, since it's originally a french word. But that way, it sounds almost alike.
Manao is offline   Reply With Quote
Old 27th August 2005, 14:11   #49  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
ok now it should work correct allthough I am not entirely sure how a? b+c:d+e is translated correct. I don't think it is possible to translate it correct without using the :

here is the code:
Code:
// ConvertTofix.cpp : Defines the entry point for the DLL application.
//

// ConvertToPostfix  Copyright 2005 Tonny Petersen

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
// http://www.gnu.org/copyleft/gpl.html .

#include "windows.h"
#include <string>
#include <algorithm>
#include <stack>
#include "avisynth.h"

using namespace std;

class Operator{
	string _op;
	int _precedens;
public:
	Operator(string _operator,int precedens):_op(_operator),_precedens(precedens){};
	bool operator==(const string& s) const{return s==_op;}
	bool operator>=(const Operator& o) const{return _precedens>=o._precedens;}
	operator string(){return _op;}
};

AVSValue __cdecl ConvertToPostFix(AVSValue args, void* user_data, IScriptEnvironment* env)
{
	const string numerics("0123456789,.()");
	const unsigned int NumberOfOperators=28;
	Operator o[NumberOfOperators]={Operator("+",50),Operator("-",50), Operator("/",60), Operator("*",60), Operator("^",70), Operator("%",60) , Operator("&",30), Operator("|",30), Operator("°",30), Operator("!&",40),Operator("<",40), Operator("<=",40), Operator(">",40), Operator(">=",40), Operator("=",40), Operator("!=",40),
		Operator("cos",80), Operator("sin",80), Operator("tan",80), Operator("acos",80), Operator("asin",80), Operator("atan",80), Operator("exp",80), Operator("log",80), Operator("abs",80), Operator("?",10),Operator(":",11),Operator("ENDOFLIST",-10)};//the last operator is a dummy operator to signal the end of the list. Also the first 2 characters of an Operator must be unique

	string input = args[0].AsString();
	transform (input.begin(),input.end(), input.begin(), tolower);
	int pos=0;
	while(string::npos !=(pos=input.find(' '))){
		input.erase(pos,1);
	}
	string temp("");
	string output;
	stack<Operator> operatorstack;
	for(unsigned int i=0;i<input.length();i++)
	{
		if(string::npos == numerics.find_first_of(input[i])&&!((input[i]=='x'||input[i]=='y')&&temp==""))
		{
			temp+=input[i];
			Operator* result;
			if((result = find(o,o+NumberOfOperators-1,temp))!=(o+NumberOfOperators-1)&&(find(o,o+NumberOfOperators-1,temp+input[i+1])==(o+NumberOfOperators-1))){
				if(output.length()&&output[output.length()-1]!=' ')
					output+=" ";
				if(operatorstack.size()==0)
					operatorstack.push(*result);
				else
				{
					while(operatorstack.size()&&operatorstack.top()>=*result)
					{
						if(!(operatorstack.top()==":")){
							output+=operatorstack.top();
							output+=" ";
						}
						operatorstack.pop();
					}
					operatorstack.push(*result);
				}
				temp="";
			}
		}
		else if(input[i]=='(')
			operatorstack.push(Operator("(",-100));
		else if(input[i]==')')
		{
			if(output.length()&&output[output.length()-1]!=' ')
				output+=" ";
			while(operatorstack.size()&&!(operatorstack.top()=="("))
			{
				output+=operatorstack.top();
				output+=" ";
				operatorstack.pop();
			}
			if(operatorstack.top()=="(")
				operatorstack.pop();
		}
		else
			output+=input[i];

	}
	if(operatorstack.size()&&output[output.length()-1]!=' ')
		output+=" ";
	while(operatorstack.size())
	{
		if(!(operatorstack.top()==":")){
			output+=operatorstack.top();
			if(operatorstack.size()>1)
				output+=" ";
		}
		operatorstack.pop();
	}
	return env->SaveString(output.c_str(),output.length());
}

extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env) {
	env->AddFunction("ConvertToPostFix","s", ConvertToPostFix, 0); 
	return 0;
}
and you don't need spaces in this version so 2*3+4*5+(6*(7+8)) is okay. Even expx is okay = exp(x)
[EDIT]
small change to the code. Should now recognise <= and >= also convert the input string to lowercase so case doesn't matter. Should parse ugly string like "E X p 23> =sIny* expX" correct

Last edited by tsp; 5th September 2005 at 13:40.
tsp is offline   Reply With Quote
Old 31st August 2005, 18:03   #50  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
Get ConvertToPostfix here if you want to try:
tsp is offline   Reply With Quote
Old 29th October 2005, 13:11   #51  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
Quick thought for the lookup table functions: as an alternative to using a string, would it be possible to take the name of a AVISynth function like

function myfunction(int argument) #returns an integer
or
function myfunction(int first, int second) #returns an integer

And using Invoke repeatedly, build up the lookup table?
mg262 is offline   Reply With Quote
Old 29th October 2005, 13:54   #52  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
mg262 : why do you want to use avisynth functions for ? or better put, what is missing in mt_lut that I could add

@all : a new version is up, fixing the mt_polish helper ( it was having some problem with functions ) :

http://manao4.free.fr/masktools-v2.0a6.zip
__________________
Manao is offline   Reply With Quote
Old 29th October 2005, 18:35   #53  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
Nested repeated subexpressions. For example, min(x,y) :

x y < x y ?

(I think!) This kind of thing crops up a lot in scripts, especially Didée's. In itself it is not a problem, but when these things start being nested then the string length grows exponentially for obvious reasons.

In particular, I wanted to write a filter that worked on masks of luma differences; often these are represented by adding 128, but there are advantages to using signed bytes, both for speed and simplicity. Because the input mask would nearly always come from YV12LUT, the unsigned to signed conversion could be incorporated at no speed cost -- but because you need to be careful about overflow, the resultant string could become so long that it was difficult to check its correctness.

Quote:
what is missing in mt_lut that I could add
min and max would help a bit? (lambda expressions would solve everything, but that's expecting a bit much!)

Don't worry about this one too much -- I can always do the signed<-->unsigned+128 conversion in separate filter.
mg262 is offline   Reply With Quote
Old 29th October 2005, 18:53   #54  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
Code:
function min(string x, string y)
{
  return "(" + x + ") < (" + y + ") ? (" + x + ") : (" + y + ")"
}

function max(string x, string y)
{
  return "(" + x + ") > (" + y + ") ? (" + x + ") : (" + y + ")"
}

my_expr = min(max("x", "y"), "x")

my_expr = mt_polish(my_expr)

return messageclip(my_expr)
Quote:
lambda expressions would solve everything
Can you be a little more specific ? you'd want to be able to define functions in order to use them in the expression ?

Edit : BTW, the string generated for min(max(x, y), x) is
Code:
x y > x y ? x < x y > x y ? x ?
So, indeed, min & max might prove usefull :P
__________________

Last edited by Manao; 29th October 2005 at 19:13.
Manao is offline   Reply With Quote
Old 29th October 2005, 19:13   #55  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
String functions will solve things nicely. Thank you!

Quote:
lambda expressions would solve everything
That wasn't really meant to be a serious suggestion -- sorry if it came across that way. Looking at postfix/prefix expressions always reminds me of LISP and variants,* which lets you create anonymous functions in the middle of expressions like this: (lambda (arg) (/ arg 50)) -- that term can be used just like any built-in function (e.g. cos). So you could write (cos 20) or ((lambda (arg) (/ arg 50)) 20). I wasn't seriously suggesting that you add something like this though -- it is not clearly necessary in this context.

*prefix not postfix, but the equivalence will be fairly clear.

I will create an appropriate string function -- probably directly postfix rather than using mt_polish. Thank you for the solution.
mg262 is offline   Reply With Quote
Old 30th October 2005, 04:02   #56  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,391
There seems to be a bug in the parser. On my side, multi-letter operators are not working.

last.mt_lut("x 128 - abs")

All of those "abs", "sin" and whatnotelse throw a "lut: invalid yexpr" and similar. Both for lut and lutxy.
Didn't work for me in a5, and doesn't in a6.
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 30th October 2005, 08:10   #57  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
Fixed ( i forgot to make the parser aware of the functions )
__________________
Manao is offline   Reply With Quote
Old 30th October 2005, 10:56   #58  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,391
Yup, much better now. Thanks a lot

Oh, and your signature is outdated. Still links to MT 2.0a5.
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 30th October 2005, 11:03   #59  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
What would I do without you ? Oh, yeah, sleep
__________________
Manao is offline   Reply With Quote
Old 3rd November 2005, 02:58   #60  |  Link
Socio
Registered User
 
Join Date: May 2004
Posts: 288
Quote:
Originally Posted by Didée
unskinnyboy - read the txt in the package, it cannot work out-of-the-box. All filter names have changed, so you'd have to edit all calls to MaskTools' filters in LS by yourself.
Kind of OT:

Well I am thoroughly confused with Mano's new naming structure, there is no function called DEdgeMask. There is a function called " mt_edge" which along with mt_motion and mt_mapped "are the counterpart of EdgeMask,
DEdgeMask, DEdgeMask2 and MotionMask".

I tried changing the calls in LS from DEdgeMask to mt_edge and it did not work, so what function call do you use to replace DEdgeMask in LS?

EDIT: Didee it looks like you may need to completely re-write your DEdgeMask call in LS to make this new version of masktools work.

Last edited by Socio; 3rd November 2005 at 03:09.
Socio 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 08:18.


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