Thread: Avisynth+
View Single Post
Old 30th September 2019, 12:56   #4883  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
@P, see here:- http://forum.doom9.org/showthread.ph...77#post1886177

Quote:
Note to Pinterf, ConditionalFilter Fails where uses Length=1 in BlankClip, dont think it should.
Code:
    InC = Last.BlankClip(Length=1,Color_YUV= InColor)    OutC= Last.BlankClip(Length=1,Color_YUV=OutColor)
Code:
ROW      = True
LIMITLO  =  74.0     # >= is Target
LIMITHI  = 100.0     # <= is Target
INCOLOR  = $008080   # Set where in target range
OUTCOLOR = $FF8080   # Not in target range
SHOW     = false     # Return StackHorizontal, original as Y8, and mask.
###############
Colorbars.Trim(0,-100).convertToY8
MskByRowAveY(Row=ROW,LimitLo=LIMITLO,LimitHi=LIMITHI,InColor=INCOLOR,OutColor=OUTCOLOR,Show=SHOW)
Return Last

Function  MskByRowAveY(clip c, Bool "Row", Float "LimitLo", Float "LimitHi", Int "InColor", Int "OutColor", Bool "Show") { # http://forum.doom9.org/showthread.php?p=1886177#post1886177
#   Where AveLuma of pixel Row/Coloumn is between LimitLo<===>LimitHi, then set to Incolor, else OutColor. Colors Specified as YUV, where only Y8 returned.
    c                                           myName="MskByRowAveY: "
    Row=Default(Row,true)                       LimitLo=Default(LimitLo,  0.0)          LimitHi=Default(LimitHi,127.5)
    InColor =Default(InColor ,$000000)          OutColor=Default(OutColor,$FF8080)      Show=Default(Show,False)
    Assert(0.0 <= LimitLo <= LimitHi,myName+String(LimitLo,"0.0 <= LimitLo(%f)") + String(LimitHi,"  <= LimitHi(%f)"))
    Assert(LimitHi <= 255.0,myName+String(LimitHi,"LimitHi(%f) <= 255.0"))
    ConvertToY8.KillAudio                       O=Last
    (Row) ? SeparateRows(O.Height)  : SeparateColumns(O.Width)
    InC = Last.BlankClip(Color_YUV= InColor)    OutC= Last.BlankClip(Color_YUV=OutColor)
    Last.ConditionalFilter(InC,OutC,String(LimitLo,"(%f<=AverageLuma<=")+String(LimitHi,"%f)"))
    (Row) ? WeaveRows(O.Height) : WeaveColumns(O.width)
    Return (SHOW) ? StackHorizontal(O,Last) : Last
}
EDIT: Easier for testing (Without SeperateRows)
Code:
FAIL = False  # Force Falure ?
C=0
For(i=0,255) {
    C2=BlankClip(Pixel_Type="Y8",Length=1,Color_YUV=(i*256+$80)*256+$80)
    C=(!c.IsClip) ? C2 : C ++ C2
}
C    # 256 frames, Y ascending

Len = (FAIL) ? 1 : FrameCount

K=Last.BlankClip(Length=Len,Pixel_Type="Y8",Color_YUV=$008080).Subtitle("[FAIL=" + String(FAIL) + "] Is NOT greater than 100.0",Align=5)
W=Last.BlankClip(Length=Len,Pixel_Type="Y8",Color_YUV=$FF8080).Subtitle("[FAIL=" + String(FAIL) + "] Is greater than 100.0",Align=5)

ConditionalFilter(W,K,"averageLuma >= 100.0 ",Show=true)
C=C.Scriptclip("""Subtitle(String(current_frame,"%.0f] Y=") + String(AverageLuma,"%.2f"))""")
StackHorizontal(C,Last)

#Trim(255,-1)    # Only show last frame where result should be WHITE.
With FAIL=False (on last frame 255 where input frame Y is 255.0)


With FAIL=True (on last frame 255 where input frame Y is 255.0)


EDIT: Only Fails when BOTH W and K clips are of single frame length, otherwise succeeds. [have not tried 0 length clips]
EDIT: Over the years I've had problems trying to use Conditional filters [maybe always this one and because of Length thing], and is the reason that I tend to use Scriptclip for nearly everything.

EDIT: And v2.60 Std does not have optional arg Show, whereas v2.61 does. [for Wiki Editor, not mentioned when Show was added]

For above Easier for testing (Without SeperateRows),
With v2.60 std, if you wrap for/next in GScript wrappers, and remove optional Show from conditionalFilter call, then it works as posted, but still has the Length error as in avs+.
Strangly, v2.61 std shows some kind of "Invalid arguments to conditionalFilter" type message where v2.60 standard works ok, Odd.

EDIT: Above in BLUE, I had Grunt in both v2.58 and v2.60Std plugins, but not in v2.61std, and as Grunt allows for differing args(string expression), v2.61 failed on single string expression without
the Operator and Expression2 strings.

Grunt docs
Quote:
ConditionalFilter

ConditionalFilter(clip testclip, clip source1, clip source2, string expression1, string operator, string expression2
[, bool showx, string args, bool local])
GConditionalFilter(clip testclip, clip source1, clip source2, string expression1, string operator, string expression2
[, bool show, string args, bool local])

ConditionalFilter(clip testclip, clip source1, clip source2, string expression
[, bool showx, string args, bool local])
GConditionalFilter(clip testclip, clip source1, clip source2, string expression
[, bool show, string args, bool local])

cf. AviSynth internal function ConditionalFilter
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 8th October 2019 at 10:20.
StainlessS is offline