public static string Type(this AVSValue value) { if (value.IsArray()) { return("Array"); } if (value.IsBool()) { return("Bool"); } if (value.IsClip()) { return("Clip"); } if (value.IsFloat()) { return("Float"); } if (value.IsInt()) { return("Int"); } if (value.IsString()) { return("String"); } throw new InvalidOperationException(); }
public override void Initialize(AVSValue args, ScriptEnvironment env) { width = Child?.GetVideoInfo().width ?? args[1].AsInt(); height = Child?.GetVideoInfo().height ?? args[2].AsInt(); left = args[3].AsInt(left); top = args[4].AsInt(top); right = args[5].AsInt(right); bottom = args[6].AsInt(bottom); noise = args[7].AsBool(noise); gradient = args[8].AsBool(gradient); if (!noise && !gradient) { env.ThrowError("No gradient, no noise"); } seed = args[9].AsInt(seed); var vi = GetVideoInfo(); vi.width = width; vi.height = height; vi.pixel_type = Child?.GetVideoInfo().pixel_type ?? ColorSpaces.CS_BGR24; vi.num_frames = Child?.GetVideoInfo().num_frames ?? 1000; vi.fps_numerator = Child?.GetVideoInfo().fps_numerator ?? 25; vi.fps_denominator = Child?.GetVideoInfo().fps_denominator ?? 1; SetVideoInfo(ref vi); realPlanar = Child == null || OverlayUtils.IsRealPlanar(Child); //Y8 is interleaved rgb = GetVideoInfo().IsRGB(); }
protected override void Initialize(AVSValue args) { srcClip = args[1].AsClip(); overClip = args[2].AsClip(); srcSize = new Size(srcClip.GetVideoInfo().width, srcClip.GetVideoInfo().height); overSize = new Size(overClip.GetVideoInfo().width, overClip.GetVideoInfo().height); srcMaskClip = args[3].IsClip() ? args[3].AsClip() : null; overMaskClip = args[4].IsClip() ? args[4].AsClip() : null; lumaOnly = args[5].AsBool(lumaOnly); var width = args[6].AsInt(srcClip.GetVideoInfo().width); var height = args[7].AsInt(srcClip.GetVideoInfo().height); var vi = srcClip.GetVideoInfo(); vi.width = width; vi.height = height; vi.pixel_type = srcClip.GetVideoInfo().pixel_type; vi.num_frames = Child.GetVideoInfo().num_frames; SetVideoInfo(ref vi); gradient = args[8].AsInt(gradient); noise = args[9].AsInt(noise); dynamicNoise = args[10].AsBool(dynamicNoise); overlayMode = (OverlayMode)args[11].AsInt((int)overlayMode); opacity = args[12].AsFloat(opacity); colorAdjust = (ColorAdjustMode)args[13].AsInt((int)colorAdjust); matrix = args[14].AsString(matrix); upsizeFunc = args[15].AsString(upsizeFunc); downsizeFunc = args[16].AsString(downsizeFunc); rotateFunc = args[17].AsString(rotateFunc); debug = args[18].AsBool(debug); }
public sealed override void Initialize(AVSValue args, ScriptEnvironment env) { try { using (new DynamicEnvironment(env)) { OverlayUtils.InitArgs(this, args); Initialize(args); base.Initialize(args, env); } topLevel = new DynamicEnvironment(env, false); AfterInitialize(); topLevel.Detach(); } catch (Exception ex) { try { DisposeAll(); } catch { // ignored } finally { if (ex is SEHException) { throw new AvisynthException("Runtime function call error: " + DynamicEnvironment.LastError); } DynamicEnvironment.LastError = ex.Message; throw new AvisynthException(ex.Message); } } }
protected override int[] GetSkipFrames(AVSValue args, ScriptEnvironment env) { Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); string filename = args[1].AsString(); HashSet<int> f = new HashSet<int>(); int lineNo = 0; string line = "xx"; try { using (StreamReader sr = new StreamReader(filename)) { while ((line = sr.ReadLine()) != null) { lineNo++; f.Add(int.Parse(line)); } } } catch (Exception ex) { env.ThrowError(string.Format("line: {0:4} | {1} {2}\n", lineNo, ex.Message, line)); } return f.Distinct().OrderBy(key => key).ToArray<int>(); }
public sealed override void Initialize(AVSValue args, ScriptEnvironment env) { try { using (new DynamicEnvironment(env)) { OverlayUtils.InitArgs(this, args); Initialize(args); base.Initialize(args, env); } topLevel = new DynamicEnvironment(env, false); AfterInitialize(); topLevel.Detach(); } catch (Exception ex) { try { DisposeAll(); } finally { throw ex; } } }
protected override void Initialize(AVSValue args) { LimitedRange = LimitedRange && GetVideoInfo().IsPlanar(); planes = GetVideoInfo().pixel_type.HasFlag(ColorSpaces.CS_INTERLEAVED) ? new[] { default(YUVPlanes) } : (Channels ?? "yuv").ToCharArray().Select(p => Enum.Parse(typeof(YUVPlanes), "PLANAR_" + p, true)) .Cast <YUVPlanes>().ToArray(); realChannels = GetVideoInfo().IsPlanar() ? new[] { 0 } : (Channels ?? "rgb").ToLower().ToCharArray().Select(p => "bgr".IndexOf(p)).ToArray(); if (!OverlayUtils.IsRealPlanar(Child)) { planes = new[] { default(YUVPlanes) } } ; sampleBits = Sample.GetVideoInfo().pixel_type.GetBitDepth(); referenceBits = Reference.GetVideoInfo().pixel_type.GetBitDepth(); var vi = GetVideoInfo(); vi.pixel_type = vi.pixel_type.ChangeBitDepth(referenceBits); SetVideoInfo(ref vi); var cacheSize = tr * 2 + 1; var cacheKey = StaticEnv.GetEnv2() == null ? CacheType.CACHE_25_ALL : CacheType.CACHE_GENERIC; Child.SetCacheHints(cacheKey, cacheSize); Sample.SetCacheHints(cacheKey, cacheSize); Reference.SetCacheHints(cacheKey, cacheSize); SampleMask?.SetCacheHints(cacheKey, cacheSize); ReferenceMask?.SetCacheHints(cacheKey, cacheSize); if (Intensity < 1 && sampleBits != referenceBits) { throw new AvisynthException("Intensity < 1 is not allowed when sample and reference bit depth are not equal"); } }
public LocalDeleteFrame(AVSValue args, ScriptEnvironment env) : base(args, env) { vi = GetVideoInfo(); int[] skips = GetSkipFrames(args, env); List<int> f = new List<int>(); int length = vi.num_frames; int skipIdx = 0; for (int i = 0; i < length; i++) { if (skips[skipIdx] == i) { skipIdx++; if (skips.Length <= skipIdx) { skipIdx = 0; } vi.num_frames--; continue; } f.Add(i); } this.frames = f.ToArray(); SetVideoInfo(ref vi); }
protected override void Initialize(AVSValue args) { Width = Child?.GetVideoInfo().width ?? args[1].AsInt(); Height = Child?.GetVideoInfo().height ?? args[2].AsInt(); Left = args[3].AsInt(Left); Top = args[4].AsInt(Top); Right = args[5].AsInt(Right); Bottom = args[6].AsInt(Bottom); Noise = args[7].AsBool(Noise); Gradient = args[8].AsBool(Gradient); if (!Noise && !Gradient) { StaticEnv.ThrowError("No gradient, no noise"); } Seed = args[9].AsInt(Seed); var vi = GetVideoInfo(); vi.width = Width; vi.height = Height; vi.pixel_type = Child?.GetVideoInfo().pixel_type ?? ColorSpaces.CS_BGR24; vi.num_frames = Child?.GetVideoInfo().num_frames ?? (Noise ? 1000000 : 1); vi.fps_numerator = Child?.GetVideoInfo().fps_numerator ?? 25; vi.fps_denominator = Child?.GetVideoInfo().fps_denominator ?? 1; SetVideoInfo(ref vi); realPlanar = Child == null || Child.IsRealPlanar(); //Y8 is interleaved rgb = GetVideoInfo().IsRGB(); bitDepth = vi.pixel_type.GetBitDepth(); byteDepth = bitDepth == 8 ? 1 : 2; shortMaxValue = (ushort)((1 << bitDepth) - 1); }
protected override void Initialize(AVSValue args) { base.Initialize(args); MinOverlayArea = args[0].AsFloat(MinOverlayArea); MinSourceArea = args[1].AsFloat(MinSourceArea); AspectRatio1 = args[2].AsFloat(AspectRatio1); AspectRatio2 = args[3].AsFloat(AspectRatio2); Angle1 = args[4].AsFloat(Angle1); Angle2 = args[5].AsFloat(Angle2); MinSampleArea = args[6].AsInt(MinSampleArea); RequiredSampleArea = args[7].AsInt(RequiredSampleArea); MaxSampleDifference = args[8].AsFloat(MaxSampleDifference); Subpixel = args[9].AsInt(Subpixel); ScaleBase = args[10].AsFloat(ScaleBase); Branches = args[11].AsInt(Branches); AcceptableDiff = args[12].AsFloat(AcceptableDiff); Correction = args[13].AsInt(Correction); MinX = args[14].AsInt(MinX); MaxX = args[15].AsInt(MaxX); MinY = args[16].AsInt(MinY); MaxY = args[17].AsInt(MaxY); MinArea = args[18].AsInt(MinArea); MaxArea = args[19].AsInt(MaxArea); FixedAspectRatio = args[20].AsBool(FixedAspectRatio); debug = args[21].AsBool(debug); if (Math.Abs(AspectRatio1 - AspectRatio2) >= double.Epsilon && FixedAspectRatio) { throw new AvisynthException("Aspect ratio must be fixed"); } //if (Math.Abs(AspectRatio1 - AspectRatio2) < double.Epsilon && !args[20].Defined()) // FixedAspectRatio = true; }
public override void Initialize(AVSValue args, ScriptEnvironment env) { vi = GetVideoInfo(); vi.height *= 2; vi.width *= 2; SetVideoInfo(ref vi); }
protected override void Initialize(AVSValue args) { base.Initialize(args); var srcInfo = Source.GetVideoInfo(); var overInfo = Overlay.GetVideoInfo(); overlaySettings = new OverlayInfo { X = X, Y = Y, Angle = (int)Math.Round(Angle * 100), Width = OverlayWidth == 0 ? overInfo.width : OverlayWidth, Height = OverlayHeight == 0 ? overInfo.height : OverlayHeight, Diff = Diff, BaseWidth = overInfo.width, BaseHeight = overInfo.height, SourceWidth = srcInfo.width, SourceHeight = srcInfo.height }; overlaySettings.SetCrop(RectangleF.FromLTRB( (float)CropLeft, (float)CropTop, (float)CropRight, (float)CropBottom)); }
public override void Initialize(AVSValue args, ScriptEnvironment env) { low = args[1].AsInt(byte.MinValue); high = args[2].AsInt(byte.MaxValue); width = GetVideoInfo().width; height = GetVideoInfo().height; realPlanar = OverlayUtils.IsRealPlanar(Child); }
public static Clip InvokeClip(this ScriptEnvironment env, string function, IOrderedDictionary args) { var avsArgs = args.Values.Cast <object>().Select(p => p.ToAvsValue()).ToArray(); var avsArg = new AVSValue(avsArgs); var res = env.Invoke(function, avsArg, args.Keys.Cast <object>().Select(p => p as string).ToArray()); return(res.AsClip()); }
public static Clip InvokeClip(this ScriptEnvironment env, string function, params object[] args) { var avsArgs = args.Select(p => p.ToAvsValue()).ToArray(); var avsArg = new AVSValue(avsArgs); var res = env.Invoke(function, avsArg); return(res.AsClip()); }
public override void Initialize(AVSValue args, ScriptEnvironment env) { sampleClip = args[1].AsClip(); referenceClip = args[2].AsClip(); maskClip = args[3].IsClip() ? args[3].AsClip() : null; tr = args[4].AsInt(tr); limitedRange = args[5].AsBool(GetVideoInfo().IsPlanar()); }
public override void Initialize(AVSValue args, ScriptEnvironment env) { //Save the parameter for future use. //Remember index 0 is the child clip saved in base class. WindowVideo = args[1].AsClip(); SquareSize = args[2].AsInt(0); vi = GetVideoInfo(); }
public override void Initialize(AVSValue args, ScriptEnvironment env) { vi = GetVideoInfo(); string AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string ServerExePath = Path.Combine(AppPath, "InterProcessSample.exe"); server = Process.Start(ServerExePath); }
protected override void Initialize(AVSValue args) { base.Initialize(args); if (Math.Abs(AspectRatio1 - AspectRatio2) >= double.Epsilon && FixedAspectRatio) { throw new AvisynthException("Aspect ratio must be fixed"); } }
public override void Initialize(AVSValue args, ScriptEnvironment env) { var vi = Child.GetVideoInfo(); low = args[1].AsInt(0); high = args[2].AsInt((1 << vi.pixel_type.GetBitDepth()) - 1); realPlanar = Child.IsRealPlanar(); hdr = vi.pixel_type.GetBitDepth() > 8; greyMask = args[3].AsBool(true); }
public override void Initialize(AVSValue args, ScriptEnvironment env) { var vi = Child.GetVideoInfo(); low = args[1].AsInt(0); high = args[2].AsInt((1 << vi.pixel_type.GetBitDepth()) - 1); width = vi.width * (vi.IsRGB() ? 3 : 1); height = vi.height; realPlanar = Child.IsRealPlanar(); hdr = vi.pixel_type.GetBitDepth() > 8; }
public override void Initialize(AVSValue args, ScriptEnvironment env) { var vi = GetVideoInfo(); if (!Enum.TryParse("CS_" + args[1].AsString(), true, out vi.pixel_type)) { throw new AvisynthException("Wrong color space"); } vi.width = args[2].AsInt(vi.width); vi.height = args[3].AsInt(vi.height); SetVideoInfo(ref vi); }
public override AVSValue ExecuteBefore(AVSValue args, ref bool cancelLoad, ScriptEnvironment env) { cancelLoad = true; string P = args[1].AsString(""); if (P.Length > 0 && !P.EndsWith("\\")) { P += "\\"; } env.Invoke("LoadPlugin", new AVSValue(P + "KNLMeansCL.dll")); return(env.Invoke("KNLMeansCL", new AVSValue(args[0]))); }
protected override void Initialize(AVSValue args) { planes = GetVideoInfo().pixel_type.HasFlag(ColorSpaces.CS_INTERLEAVED) ? new[] { default(YUVPlanes) } : (Channels ?? "yuv").ToCharArray().Select(p => Enum.Parse(typeof(YUVPlanes), "PLANAR_" + p, true)) .Cast <YUVPlanes>().ToArray(); realChannels = GetVideoInfo().IsPlanar() ? new[] { 0 } : (Channels ?? "rgb").ToLower().ToCharArray().Select(p => "bgr".IndexOf(p)).ToArray(); var vi = Child.GetVideoInfo(); SetVideoInfo(ref vi); }
protected override void Initialize(AVSValue args) { var vi = Source.GetVideoInfo(); if (Width > 0) { vi.width = Width; } if (Height > 0) { vi.height = Height; } SetVideoInfo(ref vi); }
protected virtual void Initialize(AVSValue args) { var vi = new VideoInfo { width = 640, height = 320, pixel_type = ColorSpaces.CS_BGR32, fps_numerator = 25, fps_denominator = 1, num_frames = 1 }; SetVideoInfo(ref vi); }
protected override void Initialize(AVSValue args) { parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Threads == 0 ? -1 : Threads }; LimitedRange = LimitedRange && GetVideoInfo().IsPlanar(); planes = GetVideoInfo().pixel_type.HasFlag(ColorSpaces.CS_INTERLEAVED) ? new[] { default(YUVPlanes) } : (Channels ?? "yuv").ToCharArray().Select(p => Enum.Parse(typeof(YUVPlanes), "PLANAR_" + p, true)) .Cast <YUVPlanes>().ToArray(); realChannels = GetVideoInfo().IsPlanar() ? new[] { 0 } : (Channels ?? "rgb").ToLower().ToCharArray().Select(p => "bgr".IndexOf(p)).ToArray(); if (!Child.IsRealPlanar()) { planes = new[] { default(YUVPlanes) } } ; sampleBits = Sample.GetVideoInfo().pixel_type.GetBitDepth(); referenceBits = Reference.GetVideoInfo().pixel_type.GetBitDepth(); var vi = GetVideoInfo(); vi.pixel_type = vi.pixel_type.ChangeBitDepth(referenceBits); SetVideoInfo(ref vi); var cacheSize = AdjacentFramesCount * 2 + 1; var cacheKey = StaticEnv.GetEnv2() == null ? CacheType.CACHE_25_ALL : CacheType.CACHE_GENERIC; Child.SetCacheHints(cacheKey, cacheSize); Sample.SetCacheHints(cacheKey, cacheSize); Reference.SetCacheHints(cacheKey, cacheSize); SampleMask?.SetCacheHints(cacheKey, cacheSize); ReferenceMask?.SetCacheHints(cacheKey, cacheSize); if (Intensity < 1 && sampleBits != referenceBits) { throw new AvisynthException("Intensity < 1 is not allowed when sample and reference bit depth are not equal"); } histogramCache = !string.IsNullOrEmpty(CacheId) ? HistogramCache.Get(CacheId) : new HistogramCache(planes, realChannels, SIMD, LimitedRange, Sample.GetVideoInfo().pixel_type, Reference.GetVideoInfo().pixel_type, Child.GetVideoInfo().pixel_type, AdjacentFramesCount, GreyMask, parallelOptions); if (histogramCache == null) { throw new AvisynthException($"$Histogram cache with ID: {CacheId} not found"); } }
protected override void Initialize(AVSValue args) { base.Initialize(args); if (Invert) { if (ColorAdjust >= 0) { ColorAdjust = 1 - ColorAdjust; } Initialize(Overlay, Source); } else { Initialize(Source, Overlay); } }
public sealed override void Initialize(AVSValue args, ScriptEnvironment env) { using (new DynamicEnviroment(env)) { try { OverlayUtils.InitArgs(this, args); Initialize(args); base.Initialize(args, env); } catch { DisposeAll(); throw; } } }
protected override void Initialize(AVSValue args) { srcClip = args[0].AsClip(); overClip = args[1].AsClip(); overlaySettings = new OverlayInfo { X = args[2].AsInt(), Y = args[3].AsInt(), Angle = (int)Math.Round(args[4].AsFloat() * 100), Width = args[5].AsInt(overClip.GetVideoInfo().width), Height = args[6].AsInt(overClip.GetVideoInfo().height), Diff = args[11].AsFloat(-1) }; overlaySettings.SetCrop(RectangleF.FromLTRB( (float)args[7].AsFloat(), (float)args[8].AsFloat(), (float)args[9].AsFloat(), (float)args[10].AsFloat())); srcSize = new Size(srcClip.GetVideoInfo().width, srcClip.GetVideoInfo().height); overSize = new Size(overClip.GetVideoInfo().width, overClip.GetVideoInfo().height); srcMaskClip = args[12].IsClip() ? args[12].AsClip() : null; overMaskClip = args[13].IsClip() ? args[13].AsClip() : null; lumaOnly = args[14].AsBool(lumaOnly); var width = args[15].AsInt(srcClip.GetVideoInfo().width); var height = args[16].AsInt(srcClip.GetVideoInfo().height); var vi = srcClip.GetVideoInfo(); vi.width = width; vi.height = height; vi.pixel_type = srcClip.GetVideoInfo().pixel_type; SetVideoInfo(ref vi); gradient = args[17].AsInt(gradient); noise = args[18].AsInt(noise); dynamicNoise = args[19].AsBool(dynamicNoise); overlayMode = (OverlayMode)args[20].AsInt((int)overlayMode); opacity = args[21].AsFloat(opacity); colorAdjust = (ColorAdjustMode)args[22].AsInt((int)colorAdjust); matrix = args[23].AsString(matrix); upsizeFunc = args[24].AsString(upsizeFunc); downsizeFunc = args[25].AsString(downsizeFunc); rotateFunc = args[26].AsString(rotateFunc); debug = args[27].AsBool(debug); }
public static object AsObject(this AVSValue value) { if (value.IsArray()) { var length = value.ArraySize(); if (length == 0) { return(null); } var type = value[0].AsObject().GetType(); var arrayType = type.MakeArrayType(); var array = (Array)Activator.CreateInstance(arrayType, new object[length]); for (var i = 0; i < length; i++) { array.SetValue(value[i].AsObject(), i); } return(array); } if (!value.Defined()) { return(null); } if (value.IsString()) { return(value.AsString()); } if (value.IsClip()) { return(value.AsClip()); } if (value.IsInt()) { return(value.AsInt()); } if (value.IsFloat()) { return(value.AsFloat()); } if (value.IsBool()) { return(value.AsBool()); } throw new ArgumentException("Unrecognized AvsValue type"); }
protected override void Initialize(AVSValue args) { src = args[1].AsClip(); over = args[2].AsClip(); srcText = args[3].AsString(srcText); overText = args[4].AsString(overText); srcColor = args[5].AsInt(srcColor); overColor = args[6].AsInt(overColor); borderSize = args[7].AsInt(borderSize); opacity = args[8].AsFloat(opacity); var width = args[9].AsInt(src.GetVideoInfo().width); var height = args[10].AsInt(src.GetVideoInfo().height); var vi = src.GetVideoInfo(); vi.width = width; vi.height = height; SetVideoInfo(ref vi); info = args[11].AsBool(info); }
public ApplyDelFrm(AVSValue args, ScriptEnvironment env) : base(args, env) { }
protected virtual int[] GetSkipFrames(AVSValue args, ScriptEnvironment env) { int n = args[1].ArraySize(); HashSet<int> f = new HashSet<int>(); int max = vi.num_frames; for (int i = 0; i < n; ++i) { int skipFrm = args[1][i].AsInt(); if (vi.num_frames > skipFrm) { f.Add(skipFrm); } } return f.Distinct().OrderBy(key => key).ToArray<int>(); }