From cba29f45e519a8acf56540fb65b63b48c283876a Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 13 Sep 2026 11:16:25 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=97=E3=83=AD=E3=82=AD=E3=82=B7=E3=82=92?= =?UTF-8?q?=E9=96=8B=E3=81=84=E3=81=A6=E4=BD=8D=E7=BD=AE=E3=82=92=E5=90=88?= =?UTF-8?q?=E3=82=8F=E3=81=9B=E3=82=8B=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProxyForge/Sources/ProxyUpgrade.cs | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 ProxyForge/Sources/ProxyUpgrade.cs diff --git a/ProxyForge/Sources/ProxyUpgrade.cs b/ProxyForge/Sources/ProxyUpgrade.cs new file mode 100644 index 0000000..7927aad --- /dev/null +++ b/ProxyForge/Sources/ProxyUpgrade.cs @@ -0,0 +1,60 @@ +using System.Numerics; +using ProxyForge.Cache; +using ProxyForge.Encoding; +using YukkuriMovieMaker.Commons; +using YukkuriMovieMaker.Plugin.FileSource; + +namespace ProxyForge.Sources; + +internal readonly record struct OpenedProxy(IVideoFileSource Source, Matrix3x2 Transform, FrameRate FrameRate) +{ + public static Matrix3x2 Align(DisplayBounds proxy, ProxyCacheEntry entry) + => Matrix3x2.CreateTranslation(-proxy.Left, -proxy.Top) + * Matrix3x2.CreateScale(entry.DisplayWidth / proxy.Width, entry.DisplayHeight / proxy.Height) + * Matrix3x2.CreateTranslation(entry.DisplayLeft, entry.DisplayTop); + + public static OpenedProxy? Open(IGraphicsDevicesAndContext context, string proxyPath, ProxyCacheEntry entry, VideoSourceFactory factory) + { + var source = factory(context, proxyPath); + if (source is null) + return null; + + try + { + var frameRate = new FrameRate(entry.FrameRateNumerator, entry.FrameRateDenominator); + if (!frameRate.IsValid || entry.DisplayWidth <= 0f || entry.DisplayHeight <= 0f) + { + source.Dispose(); + return null; + } + + source.Update(frameRate.GetSampleTime(0)); + var bounds = DisplayBounds.Measure(context.DeviceContext, source.Output); + if (!bounds.IsUsable) + { + source.Dispose(); + return null; + } + + return new OpenedProxy(source, Align(bounds, entry), frameRate); + } + catch + { + source.Dispose(); + throw; + } + } +} + +internal sealed class ProxyUpgrade(IGraphicsDevicesAndContext context, OpenedProxy proxy) : IDisposable +{ + public IGraphicsDevicesAndContext Context { get; } = context; + + public OpenedProxy Proxy { get; } = proxy; + + public void Dispose() + { + Proxy.Source.Dispose(); + Context.Dispose(); + } +}