Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 24th July 2012, 18:53   #1  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,203
RT_Stats, Compile-time/Runtime Functions v1.43 - 08 Oct 2014

Code:
    Some parts may be liberated from Avisynth source code.
    http://avisynth2.cvs.sourceforge.net/avisynth2/

    v1.00, Implemented RGB with internal RGB -> YUV-Y conversion.
    v1.01, Added RT_Debug function.
    v1.02, Added several more functions.
    v1.03, Added several more functions.
    v1.04, Added RT_Call.
    v1.05, Added RT_YInRange. Ucase bug fixed.
    v1.07beta, 11 Dec 2012. Added Lots of stuff, Testing 1-2-3.
    v1.08  Add some funcs
    v1.09  Fixed RT_RgbChanAve w==1 bug (always blue channel).
    v1.10  Added funcs. Fixed RT_TxtSort null string bug, Matrix default now all (width<=720?2:3)
    v1.11  Fixed broken RT_LumaDifference & RT_LumaCorrelation, "must have two clips" bug.
           Added temporary RT_LumaSNSSD()
    v1.12  Added RT_LumaSSSD(), left RT_LumaSNSSD() in situ, probably removed in next version.
    v1.13  RT_QueryBorderCrop CropLess/More modified. Experimental RT_LumaSSSD removed.
    v1.14, Added RT_FindStr. Mods:- RT_Debug, StrReplace fns, RT_NumberValue and RT_HexValue.
    v1.15, RT_YInRangeLocate, internally, Baffle separately limited to dimensions on both axis.
    v1.16, RT_LumaSceneChange added.
    v1.17, Added RT_LumaMovement. RT_Ord mod.
    v1.18, Fixed RT_QueryBorderCrop RGB "Matrix NOT @ PC levels - Check!" bug.
           Added RT_ColorSpaceXMod/YMod. Added RT_RgbChan family.
    v1.19, RT_LumaSceneChange() moved cap @ 255.0 to just before return instead of on Lut, better metrics.
              Originally like:- mt_lutxy(mt_polish("((x-y)/4)^2")).AverageLuma()
           Changed RT_QueryBorderCrop() Thresh Massaging.
    v1.20, Changed the way RT_LumaSceneChange works. Added Bias->Pord args. Added RT_Subtitle().
    v1.21, RT_Subtitle FIX: single backslash @ end of '\n' terminated string let '\n' pass without conversion to '\r'.
               Mod, Strictly eg "\n" and not "\N" interpreted as linefeed etc.
           Added FSEL functions.
    v1.22, Fixed RT_RGBChanXXXX channels. Changed RT_YStdev() to Standard Deviation from Sample Standard Deviation.
    v1.23, Mod RT_Debug, added Repeat arg.
           Mod RT_YInRangeLocate, added Baffle_W and Baffle_H args.
           Added RT_RgbInRange func.
           Added RT_RgbInRangeLocate func.

    v1.24, 28/9/13, Fixed Interlaced Y stepping.
           Added Mask args to Y/RGB stats, Added RT_YPNorm, RT_RgbChanPNorm.
           Added RT_TxtFindStr and RT_FileFindStr and RT_String.
    v1.25, 28/9/13, Afterthough, changed RT_string(bool Esc) to int.
    v1.26, 15/10/13, Fixed typo, XTRA_MASKMIN should have been XTRA_MASKMAX.
           Convert all default func matrix args to switch rec709 if height >= 600
    v1.27, Added RT_FunctionExist, RT_DebugF. Changed all returned Global vars to Local vars except for RT_SignalDAR.
    v1.28, Added Array Funcs + lots of others. Added Esc arg to RT_Subtitle.
    v1.30, 19 Dec 2013, Added DBase Functions, Increased Array attributes to 256, improved error messages.
    v1.40, 9 Sept 2014, Fixed, RT_DBaseGetAttrib returned float instead of Int (for int attrib).
           Added args Start and End to RT_QueryBorderCrop and RT_QueryLumaMinMax. Added RT_WriteFile + other funcs.
           Now 1024 Array & DBase Attributes. Array and DBase now supports type double as private type for RT_Stats
           internal routines, set or get as type Float from Avisynth script.
           DBase max number of fields increased to 1024. Added DBase/Array String Attributes.
           Added RT_QwikScan + other stuff.
    v1.41, 15 Sept 2014, Fixed borked v1.40, (released wrong source + binary), RT_QwikScan PC, PD related stuff.
           Changed RT_QwikScan LumaTol arg to float.
    v1.42, 19 Sept 2014. Modified Float LumaTol imlementation. Added additional XP mode to RT_QwikScan, and affects
           BEST MATCH results. Added RT_AvgLumaDif.
    v1.43, 07 Oct 2014. Added Dbase/Array ID and RT_QwikScanEstimateLumaTol().
See post #2 for a (OLD) stripped down partial version of docs due to draconian 16kb limit.

Code:
Zip contains v2.58 and v2.60 dll's, + source + avs scripts.
RT_YStats_TestTimer.avs  # Speed comparison script (eg YPlaneMin/RT_YPlaneMin).
ImageSplicer.avs
PlanetCrop.avs
QueryBorderCrop.avs
QueryLumaMinMax.avs
YInRangeLocate.avs
DAR.avs
LocateFrames.avs
MatchFrames.avs
s_ExLogo()                    # RT_Stats NOT required
TweenFramesI.avs
SecurityCamExtractMotion.AVS # v1.2, Update
DynaCrop.avs                 # New, with SC_SCSelect()
RT_LumaSceneChange_Graffer  # added, + vb source
v1.21
 Added FSel_DEMO avs files.
Code:
        RT_Stats_Function_List v1.43


There follows a list of all function names together with CPP style argument specifiers that inform
Avisynth the argument types and optional names. Optional arguments have square brackets surrounding
their name as in [name] and are followed by a type specifier character that gives the type.
Unnamed arguments are not optional. eg "cc[arg1]b[arg2]i" would be two compulsory unnamed clip args,
followed by optional 'arg1' of type bool and optional 'arg2' of type int.

# Argument type specifier strings.
 c - Video Clip
 i - Integer number
 f - Float number
 s - String
 b - boolean
 . - Any type (dot)
# Array Specifiers
 i* - Integer Array, zero or more
 i+ - Integer Array, one or more
 .* - Any type Array, zero or more
 .+ - Any type Array, one or more
#    Etc
###################################


RT_ColorSpaceXMod           "c"
RT_ColorSpaceYMod           "c[Laced]b"
RT_Stats                    "c"
RT_GraphLink                "cc+b*"
RT_Subtitle                 "cs.*[align]i[x]i[y]i[vcent]b[expx]b[expy]b[esc]i"
RT_BitNOT                   "i"
RT_BitAND                   "ii"
RT_BitOR                    "ii"
RT_BitXOR                   "ii"
RT_BitASL                   "ii"
RT_BitASR                   "ii"
RT_BitLSL                   "ii"
RT_BitLSR                   "ii"
RT_BitTST                   "ii"
RT_BitCLR                   "ii"
RT_BitSET                   "ii"
RT_BitCHG                   "ii"
RT_BitROR                   "ii"
RT_BitROL                   "ii"
RT_BitSetCount              "i"
RT_Hex                      "i[width]i"
RT_HexValue                 "s[pos]i"
RT_NumberString             "i[base]i[width]i"
RT_NumberValue              "s[base]i[pos]i"
RT_Call                     "s[Hide]b[Debug]b"
RT_GetLastError             ""
RT_GetLastErrorString       ""
RT_Debug                    "s+[name]b[repeat]b"
RT_DebugF                   "s.*[name]s[tabsz]i"
RT_GetProcessName           "[Parent]b[debug]b"
RT_Undefined                ""
RT_VarExist                 "s"
RT_FunctionExist            "s"
RT_Ord                      "s[pos]i"
RT_Timer                    ""
RT_IncrGlobal               "s[Init]i"
RT_Version                  ""
RT_VersionString            ""
RT_VersionDll               ""
RT_PluginDir                ""
RT_PluginFunctions          ""
RT_InternalFunctions        ""
RT_ScriptName               ""
RT_ScriptFile               ""
RT_ScriptDir                ""
RT_PluginParam              "s"
RT_GetSystemEnv             "s"
RT_GetFileTime              "si"
RT_LocalTimeString          "[file]b"
RT_VarType                  "."
RT_VarIsSame                "..+[sig]b"
RT_TimerHP                  ""
RT_FileQueryLines           "s"
RT_ReadTxtFromFile          "s[Lines]i[Start]i"
RT_WriteFileList            "ss[append]b"
RT_TxtWriteFile             "ss[append]b"
RT_FileDelete               "s"
RT_FileFindStr              "ss[sig]b[pos]i[start]i[lines]i"
RT_WriteFile                "ss.*[Append]b"
RT_FileRename               "ss"
RT_FSelOpen                 "[title]s[dir]s[filt]s[fn]s[multi]b[debug]b"
RT_FSelSaveAs               "[title]s[dir]s[filt]s[fn]s[debug]b"
RT_FSelFolder               "[title]s[dir]s[debug]b"
RT_YDifference              "c[n]i[delta]i[x]i[y]i[w]i[h]i[x2]i[y2]i[Interlaced]b[matrix]i"
RT_LumaCorrelation          "cc[n]i[delta]i[x]i[y]i[w]i[h]i[n2]i[delta2]i[x2]i[y2]i[Interlaced]b[matrix]i"
RT_LumaDifference           "cc[n]i[delta]i[x]i[y]i[w]i[h]i[n2]i[delta2]i[x2]i[y2]i[Interlaced]b[matrix]i"
RT_LumaSceneChange          "cc[n]i[delta]i[x]i[y]i[w]i[h]i[n2]i[delta2]i[x2]i[y2]i[Interlaced]b[matrix]i[Bias]f[Gain]f[Cont]f[RPow]f[SPow]f"
                            "[SPMid]f[Pord]b"
RT_LumaMovement             "cc[n]i[delta]i[x]i[y]i[w]i[h]i[n2]i[delta2]i[x2]i[y2]i[Interlaced]b[matrix]i[mode]i[blkw]i[blkh]i[Bias]f[Gain]f"
                            "[Cont]f[RPow]f[SPow]f[SPMid]f[Pord]b"
RT_RGB32AsFloat             "c[n]i[delta]i[x]i[y]i"
RT_RGB32AsInt               "c[n]i[delta]i[x]i[y]i"
RT_FloatAsRGBA              "f"
RT_YankChain                "c[n]i[delta]i"
RT_TxtQueryLines            "s"
RT_TxtGetLine               "s[Line]i"
RT_StrAddStr                "ss+"
RT_TxtAddStr                "ss+"
RT_QuoteStr                 "s"
RT_StrReplace               "sss[sig]b"
RT_StrReplaceDeep           "sss[sig]b"
RT_StrReplaceMulti          "sss[sig]b"
RT_StrPad                   "si[c]s"
RT_FindStr                  "ss[sig]b[pos]i"
RT_TxtFindStr               "ss[sig]b[pos]i[start]i[lines]i"
RT_String                   "s.*[esc]i"
RT_TxtSort                  "s[mode]i"
RT_GetWorkingDir            ""
RT_FilenameSplit            "s[get]i"
RT_GetFullPathName          "s"
RT_GetFileExtension         "s"
RT_QueryLumaMinMax          "c[Samples]i[Ignore]f[Prefix]s[Debug]b[X]i[Y]i[W]i[H]i[Matrix]i[Start]i[End]i"
RT_QueryBorderCrop          "c[Samples]i[Thresh]f[Laced]b[xMod]i[yMod]i[wMod]i[hMod]i[Relative]b[Prefix]s[RLBT]i[Debug]b[Ignore]f[Matrix]i"
                            "[ScanPerc]f[Baffle]i[ScaleAutoThreshRGB]b[ScaleAutoThreshYUV]b[ATM]f[Start]i[End]i"
RT_YInRangeLocate           "c[n]i[delta]i[x]i[y]i[w]i[h]i[baffle]i[thresh]f[lo]i[hi]i[matrix]i[prefix]s[debug]b[baffle_w]i[baffle_h]i"
RT_RgbInRange               "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[Rlo]i[Rhi]i[Glo]i[Ghi]i[Blo]i[Bhi]i"
RT_RGBInRangeLocate         "c[n]i[delta]i[x]i[y]i[w]i[h]i[baffle]i[thresh]f[Rlo]i[Rhi]i[Glo]i[Ghi]i[Blo]i[Bhi]i[prefix]s[debug]b[baffle_w]i"
                            "[baffle_h]i"
RT_GetSAR                   "cf"
RT_GetDAR                   "cf"
RT_SignalDAR                "f"
RT_SignalDAR2               "ii"
RT_GetCropDAR               "cf[x]f[y]f[w]f[h]f"
RT_ArrayAlloc               "s[Type]i[Dim1]i[Dim2]i[Dim3]i[StringLenMax]i"
RT_ArrayGetDim              "s[Dim]i"
RT_ArrayGetType             "s"
RT_ArrayGetElSize           "s"
RT_ArrayGetNels             "s"
RT_ArrayGetNelMax           "s"
RT_ArrayGetDim1Max          "s"
RT_ArrayGet                 "si[ix2]i[ix3]i"
RT_ArraySet                 "s.i[ix2]i[ix3]i"
RT_ArrayExtend              "s[Add]i"
RT_ArrayAppend              "s."
RT_ArrayGetAttrib           "si"
RT_ArraySetAttrib           "si."
RT_ArrayGetStrAttrib        "si"
RT_ArraySetStrAttrib        "sis"
RT_ArrayTypeName            "i"
RT_ArrayGetID               "si"
RT_ArraySetID               "si."
RT_DBaseAlloc               "sis[StringLenMax]i"
RT_DBaseFields              "s"
RT_DBaseFieldType           "si"
RT_DBaseFieldSize           "si"
RT_DBaseRecords             "s"
RT_DBaseRecordSize          "s"
RT_DBaseRecordsMax          "s"
RT_DBaseGetField            "sii"
RT_DBaseSetField            "sii."
RT_DBaseSet                 "si.+"
RT_DBaseExtend              "s[Add]i"
RT_DBaseAppend              "s.+"
RT_DBaseGetAttrib           "si"
RT_DBaseSetAttrib           "si."
RT_DBaseGetStrAttrib        "si"
RT_DBaseSetStrAttrib        "sis"
RT_DBaseTypeName            "i"
RT_DBaseGetID               "si"
RT_DBaseSetID               "si."
RT_RgbChanMin               "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[threshold]f[Chan]i[mask]c[maskmin]i[maskmax]i"
RT_RgbChanMax               "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[threshold]f[Chan]i[mask]c[maskmin]i[maskmax]i"
RT_RgbChanMinMaxDifference  "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[threshold]f[Chan]i[mask]c[maskmin]i[maskmax]i"
RT_RgbChanMedian            "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[Chan]i[mask]c[maskmin]i[maskmax]i"
RT_RgbChanAve               "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[Chan]i[mask]c[maskmin]i[maskmax]i"
RT_RgbChanStdev             "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[Chan]i[mask]c[maskmin]i[maskmax]i"
RT_RgbChanInRange           "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[Chan]i[lo]i[hi]i[mask]c[maskmin]i[maskmax]i"
RT_RgbChanPNorm             "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[Chan]i[mu]f[d]i[p]i[u]i[mask]c[maskmin]i[maskmax]i"
RT_RgbChanStats             "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[threshold]f[Chan]i[lo]i[hi]i[flgs]i[prefix]s[mu]f[d]i"
                            "[p]i[u]i[mask]c[maskmin]i[maskmax]i"
RT_YPlaneMin                "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[threshold]f[matrix]i[mask]c[maskmin]i[maskmax]i"
RT_YPlaneMax                "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[threshold]f[matrix]i[mask]c[maskmin]i[maskmax]i"
RT_YPlaneMinMaxDifference   "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[threshold]f[matrix]i[mask]c[maskmin]i[maskmax]i"
RT_YPlaneMedian             "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[matrix]i[mask]c[maskmin]i[maskmax]i"
RT_AverageLuma              "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[matrix]i[mask]c[maskmin]i[maskmax]i"
RT_YPlaneStdev              "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[matrix]i[mask]c[maskmin]i[maskmax]i"
RT_YInRange                 "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[matrix]i[lo]i[hi]i[mask]c[maskmin]i[maskmax]i"
RT_YPNorm                   "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[matrix]i[mu]f[d]i[p]i[u]i[mask]c[maskmin]i[maskmax]i"
RT_YStats                   "c[n]i[delta]i[x]i[y]i[w]i[h]i[Interlaced]b[threshold]f[matrix]i[lo]i[hi]i[flgs]i[prefix]s[mu]f[d]i"
                            "[p]i[u]i[mask]c[maskmin]i[maskmax]i"
RT_ChanAve                  "c[n]i[Prefix]s"
RT_FrameDifference          "cc[n]i[n2]i[ChromaWeight]f"
RT_LumaPixelsDifferentCount "cc[n]i[delta]i[x]i[y]i[w]i[h]i[n2]i[delta2]i[x2]i[y2]i[Interlaced]b[matrix]i[Thresh]i"
RT_LumaPixelsDifferent      "cc[n]i[delta]i[x]i[y]i[w]i[h]i[n2]i[delta2]i[x2]i[y2]i[Interlaced]b[matrix]i[Thresh]i"
RT_QwikScanCreate           "cs[PrevDB]s[NextDB]s[Matrix]i[Debug]b"
RT_QwikScan                 "ciciss[LumaTol]f[Flags]i[LC]f[LD]f[FD]f[PD]f[PC]i[XP]i[ChromaWeight]f[PDThresh]i[MaxDistance]i[Inclusive]b"
                            "[Prefix]s"
RT_QwikScanEstimateLumaTol  "cc[n]i[n2]i[matrix]i"
RT_AvgLumaDif               "c[n]i[slices]b[matrix]i"
EDIT: RT_Stats v2.00 Beta 12 also available via sig below.
See MediaFire or SendSpace in sig.
__________________
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; 25th November 2018 at 09:35. Reason: update
StainlessS is online now   Reply With Quote
Old 24th July 2012, 19:18   #2  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,203
RT_Stats, Short description: EDIT: Many additions missing, see later posts. (again hit 16kb limit)
Code:
RT_GraphLink(clip source, clip c1, ... , clip cn, bool b1, ... , bool bn) Equiv "Echo()" in 2.6a4
The clips, c1 to cn are by default forcibly linked into the filter graph. 

RT_Debug(string s1, ... , string sn,bool "name"=true)
Takes one or more strings, outputs the combined string to OutputDebugString()

RT_Call(String Cmd,bool "Hide"=false,bool "Debug"=false)
Run an external program using supplied command.

RT_YankChain(clip,int "n"=current_frame,int "delta"=0)
Process frame (n + delta) of a clip ie forcibly process the filter graph chain for frame n + delta.

RT_GetProcessName(bool "parent"=false,bool "debug"=false)
Returns string, name of current process.

RT_StrAddStr(String, String s1, ... , String sn)
Function to concatenate 2 or more strings.

RT_TxtAddStr(String, String s1, ... , String sn)
Function to concatenate 2 or more strings with Chr(10) line separators.

RT_TxtQueryLines(String)
String, the multiline string that you require a line count from.
Returns the number of Newline [Chr(10)] separated lines in a multiline string.

RT_TxtGetLine(String, Int "Line"=0)
Extract a single line from a multiline Newline[Chr(10)] separated string.

RT_StrReplace(string source,string find,string replace,bool "sig"=True)
Takes a source string, searches for all occurrences of find string and replaces the found strings with the replace string.

RT_StrReplaceDeep(string source,string find,string replace,bool "sig"=True)
Takes a source string, searches for all occurrences of find string and replaces the found strings with the replace string.
Can use "" in replace string (only in replace) to delete the found substrings from the source string.
Differs from RT_StringReplace in that if length of replace < length of find string will rescan after a replacement to see if
the replaced string combines with currently existing string to create another find string, If length replace >= find, then calls
RT_StringReplace instead. Useful to replace eg "  " with " ", (two spaces with 1 space), where more than two consecutive
spaces would end up with more than one consecutive resulting space if using plain RT_StrReplace.

RT_StrReplaceMulti(string source,string find,string replace,bool "sig"=True)
Takes a source string, searches for all occurrences of find substrings and replaces the found substrings with the replace substrings.
Find string and Replace string are both multiline [Chr(10) separated] strings, both of n lines where find[i] and replace[i]
are matched pairs, ie the first line of a multiline find is replaced by the first line of a multiline found, etc.
Can use "" in replace string (only in replace) to delete the found substrings from the source string.
Differs from RT_StrReplace, in that both find and replace strings are multiline strings and MUST match in number of lines.
Cannot use either carriage return [Chr(13)] or newline [Chr(10)] in find or replace as these are interpreted as end of current line,
you would need to use RT_StrReplace() instead.

RT_QuoteStr(string)
Encloses supplied string arg in double quotes.

RT_TxtSort(String,int 'mode'=0)
Function to sort a Chr(10) separated multiline string, 12 modes.

RT_FileQueryLines(String)
Returns number of lines in a text file.

RT_TxtWriteFile(String,String,bool "append"=false)
The first arg is a string of text that you want to write to a file.
The second arg is the output filename.

RT_ReadTxtFromFile(String ,Int "Lines"=0,Int "Start"=0)
String Filename, Name of text file to load into a string.

RT_WriteFileList(String,String,bool "append"=false)
Writes to a file, a list of filenames matching a wildacard eg "D:\Pics\*.BMP|JP*G|PNG"

RT_Hex(int , int "width"=0)
First arg is an integer to convert to a hexadecimal string.
Width, (0, 0 -> 8) is the minimum width of the returned string.

RT_HexValue(String,"pos"=1)
Returns an int conversion of the supplied hexadecimal string.

RT_NumberString(int ,int "base"=10, int "width"=0)
Converts a number (base 2->36) into a string. 

RT_NumberValue(String,int "base"=10,"pos"=1)
Returns an int conversion of the supplied number base string.
Base, (10, 2 -> 36) is the number base that the string uses.

RT_BitNOT(int)
Returns the integer result of a bitwise NOT operation on it's int argument.

RT_BitAND(int, int)
Returns the integer result of a bitwise AND operation on the two int arguments.

RT_BitOR(int, int)
Returns the integer result of a bitwise OR operation on the two int arguments.

RT_BitXOR(int, int)
Returns the integer result of a bitwise XOR operation on the two int arguments.

RT_BitLSL(int, int)
Returns the integer result of a Logical Shift Left on the first integer, by a shift count of the second int.
An Arithmetic Shift Left and a Logical Shift Left, are essentially the same.

RT_BitLSR(int, int)
Returns the integer result of a Logical Shift Right on the first integer, by a shift count of the second int.
Logical shift right will shift zeros into the high bits.

RT_BitASL(int, int)
Returns the integer result of an Arithmetic Shift Left on the first integer, by a shift count of the second int.
An Arithmetic Shift Left and a Logical Shift Left, are essentially the same.

RT_BitASR(int, int)
Returns the integer result of an Arithmetic Shift Right on the first integer, by a shift count of the second int.
Arithmetic shift right will shift into the high bits, zeros for a +ve number and ones for a -ve number, so -ve
numbers will stay -ve and +ve stay +ve.

RT_BitTST(int, int)
Returns the bool result of a bit test on first integer, the bit number is given in the second int.
A zero in the bit returns False and a 1 returns True.

RT_BitCLR(int, int)
Returns the integer result of a bit clear (make 0) on first integer, the bit number is given in the second int.

RT_BitSET(int, int)
Returns the integer result of a bit Set (make 1) on first integer, the bit number is given in the second int.

RT_BitCHG(int, int)
Returns the integer result of a bit change (0->1, 1->0) on first integer, the bit number is given in the second int.

RT_BitROR(int, int)
Returns the integer result of a bit Rotate Right on first integer, the bit rotate count is given in the second int.

RT_BitROL(int, int)
Returns the integer result of a bit Rotate Left on first integer, the bit rotate count is given in the second int.

RT_BitSetCount(int)
Return an int, the count of the number of set bits (1's) in arg int.

RT_Undefined()
Returns same as undefined() in v2.6. Defined(RT_Undefined()) would return false.

RT_FloatAsRGBA(float)
Given a float arg, returns an int formatted as for use as a color to eg BlankClip.
Can later be recovered from that clip using RT_RGB32AsFloat().

RT_RGB32AsFloat(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0)
Given an RGB32 clip that had a pixel value created via RT_FloatAsRGBA(), gets that pixel and returns as the
original float given to RT_FloatAsRGBA.

RT_RGB32AsInt(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0)
Given an RGB32 clip that had a pixel value created from an Int, gets that pixel and returns as the
original Int.

RT_RgbChanAve(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0, int "h"=0,bool "interlaced"=false,int "chan"=0)
Return the float average value (0.0 -> 255.0) for an RGB channel in frame(n+delta) for area x,y,w,h. (RGB 24/32).

RT_AverageLuma(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,bool "interlaced"=false,int "Matrix"=(width<=720?2:3))
Returns FLOAT value average luma (0.0 -> 255.0) in frame(n+delta) for area x,y,w,h.

RT_YPlaneMin(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,bool "interlaced"=false,
  float "threshold"=0.0,int "Matrix"=)
Returns int value minimum luma (0 -> 255) in frame(n+delta) for area x,y,w,h.
Threshold is a percentage, stating how many percent of the pixels are allowed below minimum. The threshold is optional and defaults to 0.0

RT_YPlaneMax(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,bool "interlaced"=false,
  float "threshold"=0.0,int "Matrix"=)
Returns int value maximum luma (0 -> 255) in frame(n+delta) for area x,y,w,h.
Threshold is a percentage, stating how many percent of the pixels are allowed above maximum. The threshold defaults to 0.0

RT_YPlaneMinMaxDifference(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,
    bool "interlaced"=false,float "threshold"=0.0,int "Matrix"=)
Returns int value luma range (maximum - minimum difference) (0 -> 255) in frame(n+delta) for area x,y,w,h.
Threshold is a percentage, stating how many percent of the pixels are allowed below minimum or above maximum. The threshold defaults to 0.0

RT_YPlaneMedian(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,bool "interlaced"=false,int "Matrix"=)
Returns int value luma median [equiv RT_YPlaneMin(threshold=50.0)] (0 -> 255) in frame(n+delta) for area x,y,w,h.
Threshold is a percentage, stating how many percent of the pixels are allowed above or below minimum. The threshold is optional and defaults
to 0.0

RT_YPlaneStdev(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,bool "interlaced"=false,int "Matrix"=)
Returns FLOAT value luma Standard Deviation (0.0 -> 255.0) in frame(n+delta) for area x,y,w,h.

RT_YDifference(clip,int "n"=current_frame,int "delta"=1,int "x"=0,int "y"=0,int "w"=0,int "h"=0,int "x2"=x,int "y2"=y,
  bool "interlaced"=false,int "Matrix"=)
Returns FLOAT value luma difference (0.0 -> 255.0) between frame n area x,y,w,h, and frame (n+delta) area x2,y2,w,h.
Note, by default it will be equivalent to YDifferenceToNext as delta defaults to 1 and x,y,w,h defaults full frame.
Note, 'x2' and 'y2' default to 'x' and 'y' respectively.

RT_LumaDifference(clip,clip2,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,
    int "n2"=current_frame,int "delta2"=0,int "x2"=x,int "y2"=y,bool "interlaced"=false,int "Matrix"=)
Returns FLOAT value luma difference (0.0 -> 255.0) between clip frame (n+delta) area x,y,w,h, and clip2 frame (n2+delta2) area x2,y2,w,h.
Note, 'x2' and 'y2' default to 'x' and 'y' respectively.

RT_YInRange(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,bool "interlaced"=false,int "Matrix"=,
    int "lo"=128,int "hi"=lo)
Returns float value (0.0 -> 1.0) being the amount of pixels in the range "lo" to "hi" (inclusive), 1.0 is equivalent to 100%.
Implemented as requested by Martin53 (thank you), NOTE, differs from other funcs that return range 0.0 to 255.0.
NOTE, "hi" defaults to "lo".

RT_LumaCorrelation(clip,clip2,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,int "n2"=current_frame,
    int "delta2"=0,int "x2"=x,int "y2"=y,bool "interlaced"=false,int "Matrix"=(width>=720?2:3))
Returns FLOAT value luma correlation (-1.0 -> 1.0) between clip frame (n+delta) area x,y,w,h, and clip2 frame (n2+delta2) area x2,y2,w,h.
Note, 'x2' and 'y2' default to 'x' and 'y' respectively.

RT_GetLastError()
 Return a error number describing previous system error (if available). Perhaps use after eg RT_Call.

RT_GetLastErrorString()
 Return a string describing previous system error (if available).

RT_StrPad(String,Int n,string "c"=" ")
Pads an unnamed string to at least int n (unnamed) length with first character of string c (Default SPACE).

RT_GetWorkingDir()
 Return current Working directory, directory of script, or dir set by SetWorkingDir().

RT_GetFullPathName(string "name")
 Creates an absolute or full path name for the specified relative path 'name'.

RT_FilenameSplit(string filename,int "get"=15)
 Splits the un-named filename string into component parts selected by 'get' bit flags arg and returns the parts joined together.

RT_GetFileExtension(string s)
 Returns filename extension from the supplied filename, including '.' prefix.

RT_FileDelete(string fn)
 Delete unnamed file fn.

RT_VarExist(string)
 Given the name (string) of the variable that you want to test for existence, returns true if exists, else false.

RT_Ord(string)
 Returns same as 'Ord' in v2.6, the ASCII code for the 1st letter in string (0 if empty string "").

RT_Timer()
 Returns time in seconds since start of process.

RT_Ystats(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,bool "interlaced"=false,
      float "threshold"=0.0,int "Matrix"=(width<=720?2:3),int "lo"=128,int "hi"=lo,int "flgs"=127,string "prefix"="YS_")
  Returns multiple results as for above single frame Luma sampling functions as Global Variables (prefixed with the prefix string arg).

RT_GetSAR(clip,dar float)
  Gets Sample (pixel) Aspect Ratio from DAR Display Aspect Ratio.

RT_GetDAR(clip,sar float)
  Gets DAR Display Aspect Ratio from SAR, Sample (pixel) Aspect Ratio.

RT_SignalDAR(float) # See Megui wiki (name change from SetDAR)
  Signal DAR to MEGUI. Sets global vars MeGUI_darX and MeGUI_darY which are read during MEGUI loading of AVS file.

RT_GetCropDAR(clip,float DAR,float "X"=0,float "Y"=0,Float"W"=0,float "H"=0)
  Call prior to Crop/Resize with (possibly fractional) cropping to calc resultant DAR, X,Y,W,H are cropping coords

RT_QueryLumaMinMax(clip c,int "Samples"=24,float "Ignore"=0.2,String "Prefix"="QLMM",bool "DEBUG"=false,int "X"=0,int "Y"=0,int "W"=0,int "H"=0, \
     int "Matrix"=(width<=720?2:3))
  Prescan function to get Luma Min,Max for clip scanning Samples frames area x,y,w,h.

Function RT_QueryBorderCrop(clip c,int "Samples"=24,Float "Thresh"=-32,bool "Laced"=true,int "XMod",int "YMod",int "WMod",int "HMod",  \
    bool "Relative"=false, String "Prefix"="QBCrop",int "RLBT"=15,bool "DEBUG"=false,float "Ignore"=0.2,int "Matrix"=(width<=720?2:3), \
    Float "ScanPerc"=49.0,int "Baffle"=4, bool "ScaleAutoThreshRGB"=true,bool "ScaleAutoThreshYUV"=false)
 Prescan function to get coords for eg cropping black borders by sampling Samples frames.

Function RT_YInRangeLocate(clip c,int "n"=current_frame,int "Delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,int "Baffle"=8,float "Thresh"=0.0, \
    int "Lo"=128,int "Hi"=255,Int "Matrix"=(width<=720?2:3),String "Prefix"="YIRL_",bool "Debug"=false)
 Clip function to scan frame n+delta for an area where percentage of pixels in luma range Lo to Hi (inclusive) breaks a threshold over at least Baffle
 consecutive number of scanlines (all four sides).

RT_FindStr(String S,string Substr,bool "Sig"=True,int "Pos"=1)
 Finds unnamed string Substr in unnamed string S.
 Optional bool Sig: Default=True, does case significant comparison, insignificant if false.
 Optional int Pos: Default=1, is start position in string S to find string Substr. If Pos smaller than 1 or greater than length of string s,
  then will return 0, Not Found. 
 Returns position (1 relative) of found string within the FULL LENGTH string S, or 0 if not found.
 Differs from Avisynth FindStr in Sig and Pos args and in that if either string S or string Substr is "" then will ALWAYS return 0, 'Not Found'.

ADDED IN v1.16

RT_LumaSceneChange(clip,clip2,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,
    int "n2"=current_frame,int "delta2"=0,int "x2"=x,int "y2"=y,bool "interlaced"=false,int "Matrix"=(width<=720?2:3))
  Returns FLOAT value (0.0 -> 255.0) scene change detection between clip frame (n+delta) area x,y,w,h, and clip2 frame (n2+delta2) area x2,y2,w,h.
  Note, 'x2' and 'y2' default to 'x' and 'y' respectively.
  Is implemented sort of like:- mt_lutxy(mt_polish("((x-y)/4)^2")).AverageLuma() where x=(n+delta) and y=(n2+delta2).
List of All function names current @ v1.23 here:
http://forum.doom9.org/showthread.ph...48#post1643148
__________________
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 September 2013 at 14:12.
StainlessS is online now   Reply With Quote
Old 25th July 2012, 09:50   #3  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,377
Nice work, Mr S.

Quote:
Originally Posted by StainlessS View Post
Runtime Filters v0.0b 24 July "012.
It's worth pointing out that these are not just runtime filters(*), but (by virtue of the n and n2 parameters) can also be used at compile-time, as your example with GScript shows.

As I have previously described, this can be done with the standard runtime functions by manually setting current_frame, but this is really 'cheating' the runtime environment. Your functions allow this to be done more cleanly.

(*)Actually, they are not strictly filters either, as they don't return a clip.
The wiki distinguishes runtime filters (eg ScriptClip) from the runtime functions (like AverageLuma).
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 25th July 2012, 17:36   #4  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,203
Arh Mr G,
A rose by any other name would smell as sweet, No Not You, the damn filters/functions.

OK, Ill edit the description, good job I only gave them an 'RT_' prefix.

Unfortunately, I'm getting something like '-IND000000' errors in the correlation thing which
I think is some kind of 'NaN' Not A Number type error. I might have to resort to the two pass
method which uses a lot less huge numbers, but I'm not gonna give up just yet, trying to
force it into working correctly. I used the 4th equation in the 1st link provided which can be done
in one scan of the frame.
A line that might produce the error (especially at eg 'fade to black'):

RT_Correlation(last,last.invert)

on live video.
__________________
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; 25th July 2012 at 17:50.
StainlessS is online now   Reply With Quote
Old 25th July 2012, 19:09   #5  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,313
Quote:
A line that might produce the error (especially at eg 'fade to black'):

RT_Correlation(last,last.invert)
Code:
double div	= sqrt((double)(Pixels * Sx2 - (Sx*Sx))) * sqrt((double)(Pixels * Sy2 - (Sy*Sy)));
Perhaps the stuff in the sqrt gets negative for some reason?
Wilbert is offline   Reply With Quote
Old 25th July 2012, 19:14   #6  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,862
I hope you realize that's it's normal to get a 0 for divisor when doing a correlation. It is valid for a correlation to be undefined. I think you could get this by comparing, 2,3 and 2,2.
jmac698 is offline   Reply With Quote
Old 25th July 2012, 20:12   #7  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,203
Quote:
Originally Posted by Wilbert View Post
Code:
double div	= sqrt((double)(Pixels * Sx2 - (Sx*Sx))) * sqrt((double)(Pixels * Sy2 - (Sy*Sy)));
Perhaps the stuff in the sqrt gets negative for some reason?
Yep, -ve in one of the sqrt fns, I think one of subracts ran out of
precision producing a -ve result [Sy2 -(Sy*Sy)], I think.
EDIT: You must have magical powers, my mediafire account shows zero downloads for the plug.

Quote:
Originally Posted by jmac698 View Post
I hope you realize that's it's normal to get a 0 for divisor when doing a correlation. It is valid for a correlation to be undefined. I think you could get this by comparing, 2,3 and 2,2.
Problem is, I dont know how to check for eg '-IND00000000' or
whatever it was.

EDIT: Gotta be 20 years since I last did much floating point stuff.

EDIT: Found this in Float.h, looks like what I want.

Code:
/* IEEE recommended functions */

_CRTIMP double __cdecl _copysign (double, double);
_CRTIMP double __cdecl _chgsign (double);
_CRTIMP double __cdecl _scalb(double, long);
_CRTIMP double __cdecl _logb(double);
_CRTIMP double __cdecl _nextafter(double, double);
_CRTIMP int    __cdecl _finite(double);
_CRTIMP int    __cdecl _isnan(double);
_CRTIMP int    __cdecl _fpclass(double);

#define _FPCLASS_SNAN   0x0001  /* signaling NaN */
#define _FPCLASS_QNAN   0x0002  /* quiet NaN */
#define _FPCLASS_NINF   0x0004  /* negative infinity */
#define _FPCLASS_NN     0x0008  /* negative normal */
#define _FPCLASS_ND     0x0010  /* negative denormal */
#define _FPCLASS_NZ     0x0020  /* -0 */
#define _FPCLASS_PZ     0x0040  /* +0 */
#define _FPCLASS_PD     0x0080  /* positive denormal */
#define _FPCLASS_PN     0x0100  /* positive normal */
#define _FPCLASS_PINF   0x0200  /* positive infinity */
__________________
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; 25th July 2012 at 20:43.
StainlessS is online now   Reply With Quote
Old 25th July 2012, 20:52   #8  |  Link
mastrboy
Registered User
 
Join Date: Sep 2008
Posts: 287
Quote:
Originally Posted by StainlessS View Post
No assembler opimizations, so slower.
I see, so is assembler (sse[x]) optimizations on the roadmap?
mastrboy is offline   Reply With Quote
Old 25th July 2012, 20:57   #9  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,203
@Mastrboy,

Not by me, sorry. (would feel like going back to Z80 assembler, I feel sick just thinking about it. M68K spoilt me).
__________________
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; 25th July 2012 at 21:26.
StainlessS is online now   Reply With Quote
Old 25th July 2012, 22:04   #10  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,313
Code:
double div	= sqrt((double)(Pixels * Sx2 - (Sx*Sx))) * sqrt((double)(Pixels * Sy2 - (Sy*Sy)));
if (div==0)	{div=.000001;}	
return (float)(num/div);
Something like the following should do it

Code:
double div;
double div1 = abs(Pixels * Sx2 - Sx*Sx);
double div2 = abs(Pixels * Sy2 - Sy*Sy);
if ((div1<0.0001)||(div2<0.0001))
{
  div = .000001;
} else {
  div = sqrt(div1) * sqrt(div2);
}	
return (float)(num/div);
Wilbert is offline   Reply With Quote
Old 25th July 2012, 22:19   #11  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,203
Thankyou Wilbert, very close to what I currently have.
EDIT: Although I forgot about the 'abs'
EDIT: (which should have been 'fabs', did fabs by hand rather
than calling function).
Works fine.
__________________
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; 25th July 2012 at 23:08.
StainlessS is online now   Reply With Quote
Old 25th July 2012, 23:21   #12  |  Link
mastrboy
Registered User
 
Join Date: Sep 2008
Posts: 287
Quote:
Originally Posted by StainlessS View Post
@Mastrboy,

Not by me, sorry. (would feel like going back to Z80 assembler, I feel sick just thinking about it. M68K spoilt me).
Lol, M68K isn't that the CPU used in the sega megadrive? what the hell did you code for that? :P
mastrboy is offline   Reply With Quote
Old 26th July 2012, 00:24   #13  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,203
MC68K Used in eg Sinclair QL and family, Atari ST and family, Commodore Amiga and family, early Mac's.
Up until joining D9, had not done any coding for about 14/15 years. (EDIT: unless you count a little vb)
EDIT: Sega Megadrive, no idea.

New Version, see first post.
__________________
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; 26th July 2012 at 00:33.
StainlessS is online now   Reply With Quote
Old 26th July 2012, 16:58   #14  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,203
Having perused the source, I think I would be happy to remove the beta status of the plugin immediately.
__________________
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 ???
StainlessS is online now   Reply With Quote
Old 27th July 2012, 15:21   #15  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,203
SEE Update Version Here:
http://forum.doom9.org/showthread.ph...57#post1586857

Here's a nice little script function written using both GScript and RT_Stats, I suspect that those
two plugins are quite often going to be used together. The function, "QueryBorderCrop()" returns the crop coords
to remove letter boxing or other black bars around the edges of a clip.
The return value is a string and you can 'read' the values in Avisynth by using an Eval on the string.

Heres the script:

Code:
Function QueryBorderCrop(clip c,int "Samples",Float "Thresh",bool "Laced",int "XMod",int "YMod",int "WMod",int "HMod",bool "CropMore", \
    bool "Relative", String "Prefix",int "RLBT",bool "DEBUG") {
# QueryBorderCrop v1.06, By StainlessS, Requires GScript & RT_Stats v1.01 Plugins.
# Prescan function to get coords for cropping black borders. Planar, YUY2, RGB.
# Returns a string holding crop coords eg "QBCropX=10 QBCropY=8 QBCropW=640 QBCropH=480", can use eg Eval(QueryBorderCrop()) to set values
# into QBCropX, QBCropY,QBCropW,QBCropH variables. v1.05 Added return variable eg QBCropThresh, perhaps useful if auto Thresh used.
# http://forum.doom9.org/showthread.php?p=1584626#post1584626
#
# Samples=32, Number of frames to sample from source clip c
# Thresh= -18.0, Average luma value below or equal to which is considered possible black border, above considered definitely image.
#   A zero or negative value is 'AutoThresh', will prescan 'Samples' frames (in suspect border area eg height/100), looking for minimum
#   pixel luma value (but ignoring the darkest 1%) and set 'Thresh' to that value plus the negated AutoThresh value,
#   ie default sets Thresh to minimum found Y value + 18.0.
#   Auto cropping will likely fail on END CREDITS ONLY clips, where on black background, and will probably crop off the sides that are no
#   different in average luma to any letterbox borders, if you cannot see the borders, then neither can QueryBorderCrop(), even setting the
#   auto Thresh to eg -1.0 or 0.0 is quite likely to fail. (See RLBT edge bitflags).
# Laced=true, set true for Interlaced.  (Modifies defaults for YMod,HMod, explicit YMod/HMod will override).
# XMod, Default: Planar 2, YUY2=2, RGB=1
# YMod, Default: Planar=2, YUY2=1, RGB=1: BUT, Doubled if laced=true.
# WMod, Default: Planar=4, YUY2=2, RGB=1
# HMod, Default: Planar=2, YUY2=1, RGB=1: BUT, Doubled if laced=true.
# CropMore=false, False = Leave some black for XMod,YMod,WMod,HMod, true=Crop off all black and a bit of image for XMod,WMod,WMod,HMod.
# Relative=false, False returns Width and Height, true returns Width/Height relative eg QBCropW=-6 QBCropH=-4.
# Prefix="QBCrop", string for returned variable names, only use valid variable name characters eg NO SPACES. Default returns eg "QBCropX".
# RLBT=15=All Borders, Bitflags of edges to crop, 15 ($0F) crops all four. Each letter in the name 'RLBT' represents an edge and bit position
# starting with 'R' in bit 3 representing the value 8 (2^3=8). 'L' = bit 2=4 (2^2=4), 'B' = bit 1=2 (2^1=2), 'T' = bit 0=1 (2^0=1).
# To calculate the RLBT bitflags, for 'R'(Right) add 8, for 'L'(Left) add 4, for 'B'(Bottom) add 2, and for 'T'(Top) add 1. 
# Add all of the bit flags together 8+4+2+1 (=15) crops all four edges, 8+4 crops only Right & Left, and 2+1 crops only Bottom & Top.
# DEBUG=False=No Debug. Set True for debugging info, need DebugView: http://technet.microsoft.com/en-gb/sysinternals/bb545027
#
# If not cropping enough border, then increase Samples. If cropping too much border, then decrease Thresh.
    VERS="QueryBorderCrop v1.06 - 7 Aug 2012"
    c
    Laced = Default(Laced,True)  
    XM = IsPlanar() ? 2 : IsYUY2() ? 2 : 1      WM = IsPlanar() ? 4 : IsYUY2() ? 2 : 1
    YM = IsPlanar() ? 2 : IsYUY2() ? 1 : 1      YM = (Laced) ? 2 * YM : YM
    Samples = Default(Samples,32)       Thresh= Float(Default(Thresh,-18.0))    DEBUG=default(DEBUG,False)
    XMod  = Default(XMod,XM)            YMod  = Default(YMod,YM)
    WMod  = Default(WMod,WM)            HMod  = Default(HMod,YM)
    Prefix= Default(Prefix,"QBCrop")
    CropMore = Default(CropMore,false)  Relative= Default(Relative,false)  RLBT=Default(RLBT,15)
    w=Width     h=Height    Frames = Framecount()
    Assert((Samples >= 1), "QueryBorderCrop: Requires Samples>=1")
    Assert(XMod>0 && YMod>0 && WMod>0 && HMod>0,"QueryBorderCrop: XMod,YMod,WMod,HMod Must be at least 1")
    Assert(RLBT>=1 && RLBT<=15,"QueryBorderCrop: RLBT 1->15 Only")
    flgR=(RLBT>=8) RLBT=RLBT % 8    flgL=(RLBT>=4) RLBT=RLBT % 4    flgB=(RLBT>=2) RLBT=RLBT % 2    flgT=(RLBT>=1)
    Samples = (Samples > Frames)? Frames : Samples
    CX=0 CY=0 CW=0 CH=0 Rgt=w/2 Bot=h/2 Lft=Rgt-1 Top=Bot-1
    GScript("""
        if(DEBUG){RT_Debug(":") RT_Debug(VERS,"- By StainlessS") RT_Debug(":")}
        if(Thresh <= 0.0) {
            thmin=255.0 prw=(w/100>=1) ? w/100 : 1  prh=(h/100>=1) ? h/100 : 1
            for(Samp = 1,Samples) {
                Frm = int(Samp * ((Frames - 1.0) / (Samples+1)) + 0.5)          
                if(flgT){th=c.RT_YPlaneMin(Frm,h=prh,  threshold=1.0)    if (thmin>th){thmin=th}}
                if(flgB){th=c.RT_YPlaneMin(Frm,y=h-prh,threshold=1.0)    if (thmin>th){thmin=th}}
                if(flgL){th=c.RT_YPlaneMin(Frm,w=prw,  threshold=1.0)    if (thmin>th){thmin=th}}
                if(flgR){th=c.RT_YPlaneMin(Frm,x=w-prw,threshold=1.0)    if (thmin>th){thmin=th}}
                if(DEBUG){RT_Debug("QBC_AutoThresh:",String(Samp)+")","["+String(Frm)+"]","YPlaneMin="+String(thmin))}
                if(thmin==0.0){Samp = Samples + 1} # No smaller possible, Break.
            }
            Thresh = thmin + (-Thresh) if(DEBUG){RT_Debug("QBC_AutoThresh:","Thresh="+String(Thresh))}
        }
        for(Samp = 1,Samples) {
            Frm = int(Samp * ((Frames - 1.0) / (Samples+1)) + 0.5)
            if(flgT){cnt=0 For(y=0,Top){th=c.RT_AverageLuma(Frm,y=y,h=1,x=CX,w=CW) if(th>Thresh){if(Cnt>=2){Top=y-2 CY=Top y=h
                        if(DEBUG){RT_Debug("QBC_Top:",String(Samp)+")","["+String(Frm)+"]","AveY="+String(th),"CY="+String(CY))}
                        } else {Cnt=Cnt+1}} else {Cnt=0}}}
            if(flgB){cnt=0 For(y=h-1,Bot,-1){th=c.RT_AverageLuma(Frm,y=y,h=1,x=CX,w=CW) if(th>Thresh){if(Cnt>=2){Bot=y+2 CH=-(h-1-Bot) y=0
                        if(DEBUG){RT_Debug("QBC_Bot:",String(Samp)+")","["+String(Frm)+"]","AveY="+String(th),"CH="+String(CH))}
                        } else {Cnt=Cnt+1}}else {Cnt=0}}}
            if(flgL){cnt=0 For(x=0,Lft){th=c.RT_AverageLuma(Frm,x=x,w=1,y=CY,h=CH) if(th>Thresh){if(Cnt>=2){Lft=x-2 CX=Lft x=w
                        if(DEBUG){RT_Debug("QBC_Lft:",String(Samp)+")","["+String(Frm)+"]","AveY="+String(th),"CX="+String(CX))}
                        } else {Cnt=Cnt+1}}else {Cnt=0}}}
            if(flgR){cnt=0 For(x=w-1,Rgt,-1){th=c.RT_AverageLuma(Frm,x=x,w=1,y=CY,h=CH) if(th>Thresh){if(Cnt>=2){Rgt=x+2 CW=-(w-Rgt-1) x=0
                        if(DEBUG){RT_Debug("QBC_Rgt:",String(Samp)+")","["+String(Frm)+"]","AveY="+String(th),"CW="+String(CW))}
                        } else {Cnt=Cnt+1}}else {Cnt=0}}}
#            if((!flgT||Top==0) && (!flgB||Lft==0) && (!flgL||Bot==h-1) && (!flgR||Rgt==w-1))  # Ooops v1.05
            if((!flgT||Top==0) && (!flgL||Lft==0) && (!flgB||Bot==h-1) && (!flgR||Rgt==w-1))
                {Samp = Samples + 1} # Does Not Require Cropping, Break.
        }
        XMode = (CropMore) ? XMod-1 : 0                  YMode = (CropMore) ? YMod-1 : 0        
        CX = int((CX+XMode)/XMod)*XMod                   CY = int((CY+YMode)/YMod)*YMod
        WW = w  - CX    HH = h  - CY    CW = WW + CW     CH = HH + CH
        WMode = (CropMore)?0:(WMod-1 < WW-CW) ? WMod-1 : WW-CW
        HMode = (CropMore)?0:(HMod-1 < HH-CH) ? HMod-1 : HH-CH
        CW = int((CW+WMode)/WMod)*WMod                   CH = int((CH+HMode)/HMod)*HMod
        if(Relative) {CW = -(WW -  CW)                   CH = -(HH - CH)}
        RS=Prefix+"X="+String(CX) + " " + Prefix+"Y=" + String(CY) + " " + Prefix+"W=" + String(CW) + " " + Prefix+"H=" + String(CH)
        RS=RS+ " " + Prefix+"Thresh="+String(Thresh)   # Return used Thresh, might be useful to avoid 2nd prescan for AutoThresh.
        if(DEBUG){RT_Debug("QBC_Return:",RS)}
    """)
    Return RS
}
And a test snippit:
Code:
import("D:\avs\bank\QueryBorderCrop.avs")
avisource("D:\avs\avi\1.avi")
Addborders(10,8,6,4)

DEBUG=True # Need DebugView: http://technet.microsoft.com/en-gb/sysinternals/bb545027

CropString=QueryBorderCrop(debug=DEBUG)

Eval(CropString)   # Assign return values to QBCropX QBCropY QBCropW QBCropH and QBCropThresh
Crop(QBCropX,QBCropY,QBCropW,QBCropH)
Subtitle(String(QBCropX),Align=7)
Subtitle(String(QBCropY),Align=8)
Subtitle(String(Width),Align=9)
Subtitle(String(Height),Align=2)
Subtitle(String(CropString),Align=5)
return last
v1.03, Added auto 'Thresh' functionality.
v1.04, Added RLBT edge Bitflags.
v1.05, Now returns used Thresh as eg QBCropThresh. Added Debug mode.
v1.06, EDIT: Fixed silly bug in v1.05, hilighted in source

SEE Update v1.07 Version Here:
http://forum.doom9.org/showthread.php?p=1586857#post1586857

If you want the coords for a resize without any black (instead of cropping of image) then set
XMod, YMod, WMod and HMod to 1 and use returned coords in a resize function. The below linked
function can be called with the crop coords prior to resize, to calculate the resultant Display Aspect Ratio
after resize and signaled to MeGUI so that you do not have to set DAR manually in MeGUI.

Below a post with script function to calc resultant Display Aspect Ratio after crop/resize with crop.
http://forum.doom9.org/showthread.ph...93#post1576193
__________________
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; 23rd August 2012 at 02:07. Reason: update
StainlessS is online now   Reply With Quote
Old 28th July 2012, 14:31   #16  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,203
Previous post update for "QueryCrop()"
__________________
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 ???
StainlessS is online now   Reply With Quote
Old 28th July 2012, 19:36   #17  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,377
Quote:
Originally Posted by StainlessS View Post
Code:
avisource("D:\avs\avi\1.avi")
Addborders(10,8,6,4)
CropString=QueryCrop()

Eval(CropString)   # Assign return values to CROPX CROPY, CROPW and CROPH
Crop(CropX,CropY,CropW,CropH)
ScriptClip("""
   Subtitle(String(CropX),Align=7)
   Subtitle(String(CropY),Align=8)
   Subtitle(String(CropW),Align=9)
   Subtitle(String(CropH),Align=2)
   Subtitle(String(CropString),Align=5)
""")
return last
Why do you use ScriptClip() here when CropX, etc are calculated once only and fixed at compile time?
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 28th July 2012, 20:34   #18  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,862
It would apply if crop changes, but better to pick a few frames at compile time and see what the most frequent answer is and use that.
Some dark scenes could mess it up, also scrolling credits.
This wouldn't work as is on a real letterboxed movie.
jmac698 is offline   Reply With Quote
Old 28th July 2012, 21:25   #19  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,203
@Gavino, Thanks. I modded an existing script and guess I did not give that part any thought. Fixed.

@JMac,
If croppings change, then would pick outermost cropping, ie least cropped.
If dark scenes, then would have to be real dark and all of the way though the clip.
You could always play with the Thresh & samples options. If a clip consisted of purely credits then would
fail, but what is the likely hood of that and that would likely defeat any attempt as autocropping.

Quote:
This wouldn't work as is on a real letterboxed movie.
Care to elaborate.

EDIT: Had previously only tried on example provided, just tried it on NTSC version of Return Of The King, No problem.

EDIT: Tried 6 more PAL DVDs and all cropped correctly without issue, perhaps you can ID a DVD that fails
(I don't have that much time to waste on trying to find one, suggest look for clip at night time in a coal mine with the lights out.).

EDIT: Tried on 6 DVDs trimming out everything but credits. Failed quite badly on all of them, but, I probably could not tell
where left and right borders were with vertically scrolling credits. Advise is, dont use on DVDs that consist solely of credits.
__________________
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; 5th August 2012 at 18:07.
StainlessS is online now   Reply With Quote
Old 30th July 2012, 14:23   #20  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,203
New Version RT_Stats, See first post.




Quote:
Originally Posted by Gavino View Post
Why do you use ScriptClip() here when CropX, etc are calculated once only and fixed at compile time?
Just twigged, I seem to do it all of the time. Go Figure.
__________________
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; 13th August 2012 at 22:35.
StainlessS is online now   Reply With Quote
Reply

Tags
averageluma, correlation, lumadifference, runtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 18:55.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.