Log in

View Full Version : Using another filter's parameters in a function?


qyot27
6th October 2010, 21:55
I'm looking for a way for Overlay's mode and opacity parameters to be used transparently in a new function. Calling these parameters will then perform Overlay's equivalent tasks on the implicitly-specified original and overlay clips, where the overlay clip has already had other filtering done to it that the function also controls. The parameters need to be transparently passed so that the different blend modes and opacity strength can be selected by the user instead of needing to hardcode them into the function.

I've not seen any sort of explanation or example (that I could understand, anyway) about how to do this correctly. I was able to get the initial manipulation for the overlay clip to call another function (.avsi) and mirror it's parameter correctly with some help from the function's author, but with Overlay I've seemingly hit an impasse, as the tactic to do that doesn't appear to work with Overlay's options.

Gavino
6th October 2010, 23:33
Not sure if I fully understand the question, but if what you want to do is have your function call Overlay, using mode and opacity from parameters supplied to your function, all you need is something like this:
function MyFunc(..., float "opacity", string "mode") {
... # set up clips to be used
...
Overlay(..., mode=mode, opacity=opacity)
}
There's no need even to check for default values for those parameters if you just want your function to have the same defaults as Overlay.

If I have misunderstood and instead you want something more complicated, please post an outline script of what you are trying to achieve.

qyot27
7th October 2010, 03:44
Not sure if I fully understand the question, but if what you want to do is have your function call Overlay, using mode and opacity from parameters supplied to your function, all you need is something like this:
function MyFunc(..., float "opacity", string "mode") {
... # set up clips to be used
...
Overlay(..., mode=mode, opacity=opacity)
}
There's no need even to check for default values for those parameters if you just want your function to have the same defaults as Overlay.

If I have misunderstood and instead you want something more complicated, please post an outline script of what you are trying to achieve.
Thanks, it took a couple more tries but the sample code got me thinking in the correct fashion to get it working. Turns out I wasn't too far off, it was a problem with argument order and a return command in the function that was causing Overlay not to function at all.


In any case, I've posted the pretty much completed version below:
# FrostedGlow, version 2010-10-07
#
# Applies blur to the clip, then blends the blurred clip back onto the original.
#
# Range of the effect varies according to the blend mode used; the name of the function
# derives from the appearance when using Darken mode at low levels (the function's default).
#
# Generally, colors get hazier while dark lines become more distinct, although the haze's
# brightness and the overall effect on color is dependent on the mode used.
#
# Requirements:
# BlurMod function by Phantasmagoriat
# gradfun2db
#
# Usage:
# FrostedGlow(clip c, float blurstrength, float opacity, string mode)
#
# All three of the function's parameters are the same as the options they
# correspond with in their source filters.
#
# 'blurstrength' acts the same as BlurMod(x), where 'x' is a float.
# Recommended values for blurstrength are between 1 and 5, at least from my limited testing.
# Default is blurstrength=1
#
# 'mode' and 'opacity' control the way Overlay treats the video.
#
# 'mode' changes the method by which the blurred video is overlaid onto the source.
# Default is mode="darken"
#
# 'opacity' changes the degree of transparency of the blurred video.
# Default is opacity=1.0
#
# Refer to Overlay's documentation for more about the use of the 'mode' parameter,
# as well as a complete list of available modes:
# http://avisynth.org/mediawiki/Overlay

function FrostedGlow(clip c, float "blurstrength", float "opacity", string "mode")
{
blurstrength = default(blurstrength, 1.0)
opacity = default(opacity, 1.0)
mode = default(mode, "darken")

blur = c.BlurMod(blurstrength)
Overlay(c,blur,opacity=opacity,mode=mode)
}

Update 2010-10-07:
Added default values. FrostedGlow() is equivalent to FrostedGlow(1,1.0,"darken") now.
Comments revised to reflect changes.