Tuesday
1st May 2006, 05:14
Hey,
After some brain twisting i've come up with my first ever script, the docs explain it all and i hope some one finds it useful.
I know it's pretty simple but i find it comes in handy.
# Resizer v1.0
# Created by Bear
#
# Just a simple function to make resizing videos that little bit easier.
#
# Arguments:
# ==========
#
# x & y = desired output size (Defualt: input size)
# AR = desired aspect ratio in the decomal form ie. 1.78 or 2.36,
# NOT 16:9 (Default: input AR)
# mod = number the final dimensions will be a multiple of ie, mod8,
# mod16 etc. (Default: 16)
# type = resizer used (Default: Bicubic)
# 1 = point
# 2 = bilinear
# 3 = bicubic
# 4 = lanczos
# b & c = parameters for bicubic resizer (if used)
# (Defualt: b=0.333, c=0.666)
#
# Usage:
# ======
#
# Using no arguments just makes the output mod16.
#
# If only X or Y dimension is input the output will scale using the input
# videos aspect ratio to meet this.
#
# If only an AR is entered the output will scale the X dimension to meet this.
#
# If only a mod is entered the output will be as close to the input as possible
# while meeting this.
#
# If an X AND Y dimension are specified the video will be scaled to as near as
# possible as this taking "mod" into account.
#
# I hope someone else finds this useful too, it's my first script
function Resizer( clip clp, int "x", int "y", float "AR", int "mod", int "type", float "b", float "c")
{
# Set defaults
xdest = default(x, clp.width)
ydest = default(y, clp.height)
AR = default(AR, (clp.width / clp.height))
mod = default(mod, 16)
type = default(type, 3)
b = default(b, 0.333)
c = default(c, 0.666)
# Sort out AR
xdest = (AR != (clp.width / clp.height) && xdest == clp.width) ? round(ydest * AR) : xdest
ydest = (AR != (clp.width / clp.height) && ydest == clp.height) ? round(xdest / AR) : ydest
# Modulize dimensions
xdiff = xdest % mod
x = (xdiff < (mod / 2)) ? xdest - xdiff : xdest + (mod - xdiff)
ydiff = ydest % mod
y = (ydiff < (mod / 2)) ? ydest - ydiff : ydest + (mod - ydiff)
# Select resizer
(type == 1) ? PointResize(clp, x, y) : NOP
(type == 2) ? BilinearResize(clp, x, y) : NOP
(type == 3) ? BicubicResize(clp, x, y, b, c) : NOP
(type == 4) ? LanczosResize(clp, x, y) : NOP
# Output
return last
}
Any comments are welcome, props to Wilbert & IanB for tips.
After some brain twisting i've come up with my first ever script, the docs explain it all and i hope some one finds it useful.
I know it's pretty simple but i find it comes in handy.
# Resizer v1.0
# Created by Bear
#
# Just a simple function to make resizing videos that little bit easier.
#
# Arguments:
# ==========
#
# x & y = desired output size (Defualt: input size)
# AR = desired aspect ratio in the decomal form ie. 1.78 or 2.36,
# NOT 16:9 (Default: input AR)
# mod = number the final dimensions will be a multiple of ie, mod8,
# mod16 etc. (Default: 16)
# type = resizer used (Default: Bicubic)
# 1 = point
# 2 = bilinear
# 3 = bicubic
# 4 = lanczos
# b & c = parameters for bicubic resizer (if used)
# (Defualt: b=0.333, c=0.666)
#
# Usage:
# ======
#
# Using no arguments just makes the output mod16.
#
# If only X or Y dimension is input the output will scale using the input
# videos aspect ratio to meet this.
#
# If only an AR is entered the output will scale the X dimension to meet this.
#
# If only a mod is entered the output will be as close to the input as possible
# while meeting this.
#
# If an X AND Y dimension are specified the video will be scaled to as near as
# possible as this taking "mod" into account.
#
# I hope someone else finds this useful too, it's my first script
function Resizer( clip clp, int "x", int "y", float "AR", int "mod", int "type", float "b", float "c")
{
# Set defaults
xdest = default(x, clp.width)
ydest = default(y, clp.height)
AR = default(AR, (clp.width / clp.height))
mod = default(mod, 16)
type = default(type, 3)
b = default(b, 0.333)
c = default(c, 0.666)
# Sort out AR
xdest = (AR != (clp.width / clp.height) && xdest == clp.width) ? round(ydest * AR) : xdest
ydest = (AR != (clp.width / clp.height) && ydest == clp.height) ? round(xdest / AR) : ydest
# Modulize dimensions
xdiff = xdest % mod
x = (xdiff < (mod / 2)) ? xdest - xdiff : xdest + (mod - xdiff)
ydiff = ydest % mod
y = (ydiff < (mod / 2)) ? ydest - ydiff : ydest + (mod - ydiff)
# Select resizer
(type == 1) ? PointResize(clp, x, y) : NOP
(type == 2) ? BilinearResize(clp, x, y) : NOP
(type == 3) ? BicubicResize(clp, x, y, b, c) : NOP
(type == 4) ? LanczosResize(clp, x, y) : NOP
# Output
return last
}
Any comments are welcome, props to Wilbert & IanB for tips.