chachu
30th December 2010, 18:27
Hi,
( Sorry in advance for my english, I have just my school notions and "Google Translate" :p )
( Sorry in advance for my beginner function, it's my first true function. I would learn Avisynth :) )
/*
Description :
-----------
EasyAR() is a simple tool who can help to get rid of your boring calculations and resize image/video sources to a defined aspect ratio with 1 of this 3 methods :
-1 : Crop() and Spline64Resize()
0 : only Spline64Resize()
1 : Spline64Resize() and AddBorders()
Examples :
-----------
ImageReader("src.png")
#Crop() and Spline64Resize() to a 4:3 (16/12 = 4/3 ˜ 1.333)
EasyAR(16,12,-1)
ImageReader("src.png")
#only Spline64Resize() to a 16:9 (16/9 = 4/3*4/3 ˜ 1.778)
EasyAR(16,9)
ImageReader("src.png")
#Spline64Resize() and AddBorders() to a 10:16 (10/16 = 5/8 = 0.625)
EasyAR(10,16,1)
*/
function EasyAR(clip src, int "x", int "y", int "method") {
x = default(x,0)
y = default(y,0)
method = default(method,0)
Assert(x == 16 || y == 16,"x=16 or y=16")
Assert(1 <= x <= 16,"x=1~16")
Assert(1 <= y <= 16,"y=1~16")
Assert(method == -1 || method == 1 || method == 0,"method=-1 or method=0 or method=1")
w = Float(src.Width)
h = Float(src.Height)
(method == -1)
\ ?
\ (w > h/y*x)
\ ?
\ src.Crop( Round((w-(h/y*x))/4)*2 , 0 , -Round((w-(h/y*x))/4)*2 , -0 )
\ :
\ src.Crop( 0 , Round((h-(w/x*y))/4)*2 , -0 , -Round((h-(w/x*y))/4)*2 )
\ :
\ (method == 0)
\ ?
\ (w > h/y*x)
\ ?
\ src.Spline64Resize( Floor(Floor(w/x)/2)*2*x , Floor(Floor(w/x)/2)*2*y )
\ :
\ src.Spline64Resize( Floor(Floor(h/y)/2)*2*x , Floor(Floor(h/y)/2)*2*y )
\ :
\ (method == 1)
\ ?
\ (w > h/y*x)
\ ?
\ src.Spline64Resize( (Floor(Floor(w/x)/2)*2)*x , Floor(h/2)*2 )
\ :
\ src.Spline64Resize( Floor(w/2)*2 , (Floor(Floor(h/y)/2)*2)*y )
\ :
\ src
w = Float(last.Width)
h = Float(last.Height)
(method == -1)
\ ?
\ last.Spline64Resize( Round((w/x)/2)*2*x , Round((w/x)/2)*2*y )
\ :
\ (method == 1)
\ ?
\ (w > h/y*x)
\ ?
\ last.AddBorders( 0 , Int((((w/x)*y)-h)/2) , 0 , Int((((w/x)*y)-h)/2) )
\ :
\ last.AddBorders( Int((((h/y)*x)-w)/2) , 0 , Int((((h/y)*x)-w)/2) , 0 )
\ :
\ last
}
all constructive messages are welcome
( Sorry in advance for my english, I have just my school notions and "Google Translate" :p )
( Sorry in advance for my beginner function, it's my first true function. I would learn Avisynth :) )
/*
Description :
-----------
EasyAR() is a simple tool who can help to get rid of your boring calculations and resize image/video sources to a defined aspect ratio with 1 of this 3 methods :
-1 : Crop() and Spline64Resize()
0 : only Spline64Resize()
1 : Spline64Resize() and AddBorders()
Examples :
-----------
ImageReader("src.png")
#Crop() and Spline64Resize() to a 4:3 (16/12 = 4/3 ˜ 1.333)
EasyAR(16,12,-1)
ImageReader("src.png")
#only Spline64Resize() to a 16:9 (16/9 = 4/3*4/3 ˜ 1.778)
EasyAR(16,9)
ImageReader("src.png")
#Spline64Resize() and AddBorders() to a 10:16 (10/16 = 5/8 = 0.625)
EasyAR(10,16,1)
*/
function EasyAR(clip src, int "x", int "y", int "method") {
x = default(x,0)
y = default(y,0)
method = default(method,0)
Assert(x == 16 || y == 16,"x=16 or y=16")
Assert(1 <= x <= 16,"x=1~16")
Assert(1 <= y <= 16,"y=1~16")
Assert(method == -1 || method == 1 || method == 0,"method=-1 or method=0 or method=1")
w = Float(src.Width)
h = Float(src.Height)
(method == -1)
\ ?
\ (w > h/y*x)
\ ?
\ src.Crop( Round((w-(h/y*x))/4)*2 , 0 , -Round((w-(h/y*x))/4)*2 , -0 )
\ :
\ src.Crop( 0 , Round((h-(w/x*y))/4)*2 , -0 , -Round((h-(w/x*y))/4)*2 )
\ :
\ (method == 0)
\ ?
\ (w > h/y*x)
\ ?
\ src.Spline64Resize( Floor(Floor(w/x)/2)*2*x , Floor(Floor(w/x)/2)*2*y )
\ :
\ src.Spline64Resize( Floor(Floor(h/y)/2)*2*x , Floor(Floor(h/y)/2)*2*y )
\ :
\ (method == 1)
\ ?
\ (w > h/y*x)
\ ?
\ src.Spline64Resize( (Floor(Floor(w/x)/2)*2)*x , Floor(h/2)*2 )
\ :
\ src.Spline64Resize( Floor(w/2)*2 , (Floor(Floor(h/y)/2)*2)*y )
\ :
\ src
w = Float(last.Width)
h = Float(last.Height)
(method == -1)
\ ?
\ last.Spline64Resize( Round((w/x)/2)*2*x , Round((w/x)/2)*2*y )
\ :
\ (method == 1)
\ ?
\ (w > h/y*x)
\ ?
\ last.AddBorders( 0 , Int((((w/x)*y)-h)/2) , 0 , Int((((w/x)*y)-h)/2) )
\ :
\ last.AddBorders( Int((((h/y)*x)-w)/2) , 0 , Int((((h/y)*x)-w)/2) , 0 )
\ :
\ last
}
all constructive messages are welcome