From 902d729c195f37833faa6e67fe1d6ec5626b5d10 Mon Sep 17 00:00:00 2001 From: routersys Date: Fri, 3 Jul 2026 11:50:40 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=97=E3=83=A9=E3=82=B0=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E6=9C=AC=E4=BD=93=E3=82=92=E5=88=86=E9=9B=A2=E3=83=97=E3=83=AD?= =?UTF-8?q?=E3=82=B8=E3=82=A7=E3=82=AF=E3=83=88=E5=8F=82=E7=85=A7=E3=81=B8?= =?UTF-8?q?=E7=A7=BB=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript/LuaScript.csproj | 8 ++++--- LuaScript/LuaScriptEffectProcessor.cs | 2 +- LuaScript/MediaSourceLoader.cs | 34 +++++++++++++++++++++++++++ LuaScript/SceneObjectResolver.cs | 4 ++-- 4 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 LuaScript/MediaSourceLoader.cs diff --git a/LuaScript/LuaScript.csproj b/LuaScript/LuaScript.csproj index 83f2e82..7ed5b09 100644 --- a/LuaScript/LuaScript.csproj +++ b/LuaScript/LuaScript.csproj @@ -95,11 +95,13 @@ - + + + - + @@ -117,7 +119,7 @@ - + diff --git a/LuaScript/LuaScriptEffectProcessor.cs b/LuaScript/LuaScriptEffectProcessor.cs index aa4d2a5..660994b 100644 --- a/LuaScript/LuaScriptEffectProcessor.cs +++ b/LuaScript/LuaScriptEffectProcessor.cs @@ -66,7 +66,7 @@ namespace LuaScript private static string NativeDirectory => Path.Combine(Path.GetDirectoryName(typeof(LuaScriptEffectProcessor).Assembly.Location) ?? AppContext.BaseDirectory, "native"); - private readonly LuaScriptEngine _engine = new(); + private readonly LuaScriptEngine _engine = new(static () => new MediaSourceLoader()); private readonly SemaphoreSlim _pixelLoaderSemaphore = new(1, 1); private AviUtlScriptContext _context = new(); diff --git a/LuaScript/MediaSourceLoader.cs b/LuaScript/MediaSourceLoader.cs new file mode 100644 index 0000000..733e820 --- /dev/null +++ b/LuaScript/MediaSourceLoader.cs @@ -0,0 +1,34 @@ +namespace LuaScript +{ + internal sealed class MediaSourceLoader : IMediaSourceLoader + { + private TextRenderer? _textRenderer; + private ImageDecoder? _imageDecoder; + private MovieDecoder? _movieDecoder; + + public byte[] RenderText(string text, string fontFamily, double fontSize, bool bold, bool italic, int colorRgb, out int width, out int height) + { + _textRenderer ??= new TextRenderer(); + return _textRenderer.Render(text, fontFamily, fontSize, bold, italic, colorRgb, out width, out height); + } + + public byte[] DecodeImage(string path, out int width, out int height) + { + _imageDecoder ??= new ImageDecoder(); + return _imageDecoder.Decode(path, out width, out height); + } + + public byte[] DecodeMovie(string path, double time, out int width, out int height) + { + _movieDecoder ??= new MovieDecoder(); + return _movieDecoder.Decode(path, time, out width, out height); + } + + public void Dispose() + { + _textRenderer?.Dispose(); + _imageDecoder?.Dispose(); + _movieDecoder?.Dispose(); + } + } +} diff --git a/LuaScript/SceneObjectResolver.cs b/LuaScript/SceneObjectResolver.cs index a1b1f81..9ac23df 100644 --- a/LuaScript/SceneObjectResolver.cs +++ b/LuaScript/SceneObjectResolver.cs @@ -2,7 +2,7 @@ using YukkuriMovieMaker.Project.Items; namespace LuaScript { - internal sealed class SceneObjectResolver + internal sealed class SceneObjectResolver : ISceneObjectResolver { internal readonly record struct Entry(string Tag, int Frame, int Length, int Layer, VisualItem Item); @@ -15,7 +15,7 @@ namespace LuaScript _fps = fps; } - internal bool TryResolve(string tag, int timelineFrame, out SceneObjectInfo info) + public bool TryResolve(string tag, int timelineFrame, out SceneObjectInfo info) { int fallback = -1; for (int i = 0; i < _entries.Length; i++)