MJLives12
17th September 2013, 23:51
Added Levels to fastgauss from Didée function to brighten blur in SoftGlow.
function FastGauss(clip clp, float rx, float ry)
{ ox=clp.width()
oy=clp.height()
clp.Levels (0, 0.1, 127, 0, 255, false).bicubicresize(m4(ox/rx),m4(oy/ry)).bicubicresize(ox,oy,1,0)
}
function m4(float x) {x<16?16:int(round(x/4.0)*4)}
And an improved version of SoftGlow
##################################
## SoftGlow with constrained inputs and resizing
## original @ http://forum.doom9.org/showthread.php?p=1642381#post1642381
#
Function SoftGlow (clip c, int "radius"
\ , int "min", int "max", int "threshold", int "blur", float "sat", int "cont", float "mul") {
c
## (limits are set based on guesswork; please adjust if needed)
radius = Min(Max(2, Default (radius, 2)), Width / 2)
edges = (radius % 4) == 0 ? radius : radius + 4 - (radius % 4)
threshold = Min(Max(16, Round (Default (threshold, 200) * 219 / 255.0) + 16), 255)
min = Min(Max(threshold+1, Default (min, 254)), 254)
max = Min(Max(min+1, Default (max, min+1)), 255)
blur = Min(Max(0, Default (blur, 24)), 768)
sat = Min(Max(0.0, Default (sat, 1.0)), 4.0)
cont = Min(Max(1, Default (cont, 0)), 256)
mul = Min(Max(0.0, Float(Default (mul, 1.0))), 1.0)
rmax_set=255.0
rwmax=last.width/blur
rhmax=last.height/blur
rmax= (rwmax <= rhmax) ? rwmax : rhmax
radius=(((rmax-1)*(radius-1))/(rmax_set-1))+1
b=radius-1
b=b*b*b
b=b*192/rmax/rmax/rmax
width=Round(last.width/blur)
height=Round(last.height/blur)
Mask = Merge (last
\ ,MT_lutxy (last
\ ,ConvertToRGB32 ().RGBLevelsG (min, 1.0, max, 0, 255).ConvertToYV12 ()
\ .Tweak (sat = sat)
\ .AddBorders (edges, edges, edges, edges)
\ .FastGauss (blur, blur)
\ .Crop (edges, edges, edges * -1, edges * -1)
\ .Levels (0, 1.0, threshold, 0, 255, false)
\ ,uexpr = " y 128 < x y * 128 /"
\ ,vexpr = " y 128 < x y * 128 /", Y = 4, U = 3, V = 3), mul)
White = MT_lutxy (BlankClip (Mask, color_yuv = $FF8080)
\ ,Mask.ColorYUV (cont_u = cont, cont_v = cont)
\ ,yexpr = "256 0 x - 256 y - * 256 / -", Y = 3, U = 4, V = 4)
MT_Merge (White, Mask, chroma = "process")
}
Optional SoftGlow Test
## SoftGlow: fuzz test input args
## just keep frame stepping, see if anything breaks
## (also a neat way to explore different effects)
## warning this video may cause seizures - do not play in real time
##################################
## SoftGlow: fuzz test input args
#
function SoftGlow_Test(clip C) {
C
## random inputs
a_radius=Rand(Width/2)
a_min=Rand(254)
a_max=Rand(255)
a_threshold=Rand(255)
a_sat=Rand(400)/100.0
a_cont=Rand(400)
a_mul=Rand(100)/100.0
a_blur=Rand(180)
args="radius=" + String(a_radius,"%3.0f")
\ + ", min=" + String(a_min,"%3.0f") + ", max=" + String(a_max,"%3.0f") + ", threshold=" + String(a_threshold,"%3.0f")
\ + ", blur=" + String(a_blur) + ", sat=" + String(a_sat) + ", cont=" + String(a_cont)
/* the following should be a valid Avisynth statement */
stat="SoftGlow(" + args + ")"
RT_Debug("SoftGlow","["+string(current_frame)+"]",args,false)
# RT_TxtWriteFile(String(current_frame)+Chr(9)+args,g_logpath,Append=true)
/* write frame number + tab char + statement to logfile...? */
WriteFileStart(g_logpath,String(current_frame),"Chr(9)","args",append=True)
return Eval(stat).ShowFrameNumber
}
C = last
global g_logpath = "C:\<dir>\logfile.txt"
C=C.WriteFileStart(g_logpath, """ "frameno" """, "Chr(9)", """ "args " """,append=false)
C=C.WriteFileEnd(g_logpath, """ "#end" """)
ScriptClip(c, "SoftGlow_Test(c)")
Also FastCross (Plus effect version of Didée FastGauss
function FastCross(clip clp, float rx, float ry)
{ ox=clp.width()
oy=clp.height()
Merge (clp.Levels (0, 0.1, 127, 0, 255, false).bilinearresize(m4(ox/rx),m4(oy)).bicubicresize(ox,oy,1,0)
\ ,clp.Levels (0, 0.1, 127, 0, 255, false).bilinearresize(m4(ox),m4(ry/ry)).bicubicresize(ox,oy,0,1),0.5)
}
function m4(float x) {x<16?16:int(round(x/4.0)*4)}
Function PGlow (clip c, int "radius"
\ , int "min", int "max", int "threshold", int "blur", float "sat", int "cont", float "mul") {
c
## (limits are set based on guesswork; please adjust if needed)
radius = Min(Max(2, Default (radius, 2)), Width / 2)
edges = (radius % 4) == 0 ? radius : radius + 4 - (radius % 4)
threshold = Min(Max(16, Round (Default (threshold, 200) * 219 / 255.0) + 16), 255)
min = Min(Max(threshold+1, Default (min, 254)), 254)
max = Min(Max(min+1, Default (max, min+1)), 255)
blur = Min(Max(0, Default (blur, 24)), 768)
sat = Min(Max(0.0, Default (sat, 1.0)), 4.0)
cont = Min(Max(1, Default (cont, 0)), 256)
mul = Min(Max(0.0, Float(Default (mul, 1.0))), 1.0)
rmax_set=255.0
rwmax=last.width/blur
rhmax=last.height/blur
rmax= (rwmax <= rhmax) ? rwmax : rhmax
radius=(((rmax-1)*(radius-1))/(rmax_set-1))+1
b=radius-1
b=b*b*b
b=b*192/rmax/rmax/rmax
width=Round(last.width/blur)
height=Round(last.height/blur)
Mask = Merge (last
\ ,MT_lutxy (last
\ ,ConvertToRGB32 ().RGBLevelsG (min, 1.0, max, 0, 255).ConvertToYV12 ()
\ .Tweak (sat = sat)
\ .AddBorders (edges, edges, edges, edges)
\ .FastCross (blur, blur)
\ .Crop (edges, edges, edges * -1, edges * -1)
\ .Levels (0, 1.0, threshold, 0, 255, false)
\ ,uexpr = " y 128 < x y * 128 /"
\ ,vexpr = " y 128 < x y * 128 /", Y = 4, U = 3, V = 3), mul)
White = MT_lutxy (BlankClip (Mask, color_yuv = $FF8080)
\ ,Mask.ColorYUV (cont_u = cont, cont_v = cont)
\ ,yexpr = "256 0 x - 256 y - * 256 / -", Y = 3, U = 4, V = 4)
MT_Merge (White, Mask, chroma = "process")
}
## PGlow: fuzz test input args
## just keep frame stepping, see if anything breaks
## (also a neat way to explore different effects)
## warning this video may cause seizures - do not play in real time
##################################
## PGlow: fuzz test input args
#
function PGlow_Test(clip C) {
C
## random inputs
a_radius=Rand(Width/2)
a_min=Rand(254)
a_max=Rand(255)
a_threshold=Rand(255)
a_sat=Rand(400)/100.0
a_cont=Rand(400)
a_mul=Rand(100)/100.0
a_blur=Rand(180)
args="radius=" + String(a_radius,"%3.0f")
\ + ", min=" + String(a_min,"%3.0f") + ", max=" + String(a_max,"%3.0f") + ", threshold=" + String(a_threshold,"%3.0f")
\ + ", blur=" + String(a_blur) + ", sat=" + String(a_sat) + ", cont=" + String(a_cont)
/* the following should be a valid Avisynth statement */
stat="PGlow(" + args + ")"
# RT_Debug("SoftGlow","["+string(current_frame)+"]",args,false)
# RT_TxtWriteFile(String(current_frame)+Chr(9)+args,g_logpath,Append=true)
/* write frame number + tab char + statement to logfile...? */
WriteFileStart(g_logpath,String(current_frame),"Chr(9)","args",append=True)
return Eval(stat).ShowFrameNumber
}
C = last
global g_logpath = "C:\Fraps\movies\logfile.txt"
C=C.WriteFileStart(g_logpath, """ "frameno" """, "Chr(9)", """ "args " """,append=false)
C=C.WriteFileEnd(g_logpath, """ "#end" """)
ScriptClip(c, "PGlow_Test(c)")
Manuel Settings:
PGlow (radius=2,min=200,max=235,sat=1.0,mul=0.5,cont=512,blur=24,threshold=127)
logfile of random settings
MJLives12
18th September 2013, 18:14
RT_debug and RT_TxtWriteFile are functions from RT_Stats dll, runtime/compile time functions.
RT_Debug takes 1 or more strings, and outputs to debugview window so you can see debugging
information in real time.
DebugView from SysInternals, bought out by Microsoft, here:
http://technet.microsoft.com/en-gb/sysinternals/bb896647.aspx
Debugview is highly recommended if you develop scripts especially if you use either Scriptclip or GScript, you can see some example RT_Debug
output in post #50, 3rd code block, and the RT_Debug line in 1st code block of same post.
You can remove both RT_ funcs, as they are not now needed in your script.
Just downloaded the RT_Stats dll from Mediafire hyperlink, testing it out now with VirtualDub.:thanks:
C = last
global g_logpath = "C:\<dir>\logfile.txt"
C=C.WriteFileStart(g_logpath, """ "frameno" """, "Chr(9)", """ "args " """,append=false)
C=C.WriteFileEnd(g_logpath, """ "#end" """)
ScriptClip(c, "PGlow_Test(c)")
http://i.imgur.com/PwIJo0u.png?1
9047 radius=189, min=177, max=114, threshold= 64, blur=176, sat=3.560000, cont=240
PGlow (radius=189, min=177, max=114, threshold= 64, blur=176, sat=3.560000, cont=240)
MJLives12
26th December 2013, 03:32
Here's a faster version of using gaussian blur in realtime.
Function GBloom (clip c, int "radius", float "blur", int "w"
\ ,float "sat", float "cont", int "bright", "min", int "max", float "me") {
c
#Variable blur required http://forum.doom9.org/showthread.php?t=88645
#MVtools v2
#radius for BiCubicResize (higher radius use for speed up, 8)
#w for gaussian blur gfunc (set to 0 or 4 enhances lighting, luma and chroma)
#me luma gamma, set to 0.1 or up to 0.4 (brighter chroma and luma) and max to 250
#sat set to 0.5 if chroma is noisy and max to 250, me to 0.2
radius = Default (radius, Round (Width / 120.0))
blur = Default (blur, 1.0)
min = Default (min, 0)
max = Default (max, min +1)
me = Default (me, 0.1)
w = Default (w, 4)
sat = Default (sat, 1.0)
cont = Default (cont, 1.0)
bright = Default (bright, 0)
rmax_set=255
rwmax=last.width/radius
rhmax=last.height/radius
rmax= (rwmax <= rhmax) ? rwmax : rhmax
radius=(((rmax-1)*(radius-1))/(rmax_set-1))+1
old_wid = Width
old_hgt = height
new_wid = rwmax
new_hgt = rhmax
old_wid = Width
old_hgt = height
new_wid = rwmax
new_hgt = rhmax
new_wid = Min(Max(64, new_wid), old_wid / 2)
new_hgt = Min(Max(64, new_hgt), old_hgt / 2)
new_wid = new_wid + new_wid % 2
new_hgt = new_hgt + new_hgt % 2
Mask = BilinearResize(new_wid,new_hgt).ConvertToRGB32 ()
Mask = Mask.BLevels (min, me, max, 0, 255)
\ .GaussianBlur(blur,blur,gfunc=w,y=3,u=3,v=3)
\ .TweakRGB (sat=sat, cont=cont, bright=bright)
\ .ConvertToYV12 ().BilinearResize(old_wid,old_hgt)
MT_lutxy (Mask
\ ,yexpr = "248 256 x - 256 y - * 256 / -"
\ ,uexpr = " y 128 < x y * 128 /"
\ ,vexpr = " y 128 < x y * 128 /", U = 3, V = 3)
ColorYUV (levels="TV->PC")
}
function Blevels(clip c,
\ int input_low, float gamma, int input_high,
\ int output_low, int output_high)
{
c
LC = Levels(input_low, gamma, input_high
\ ,output_low, output_high, coring = true)
Overlay(LC,mode="blend")
}
function TweakRGB(clip last, float "cont", float "sat", int "bright") {
cont = Default (cont, 1.0)
sat = Default (sat, 1.0)
bright = Default (bright, 1)
ConvertToYV12().Tweak(sat=sat, bright=bright)
\ .ConvertToRGB32().RGBAdjust(cont,cont,cont,cont)
}
GBloom(radius=8,blur=6,me=0.4,max=250,sat=1.3,cont=0.8)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.