obj.brushを両エンジンへ追加
このコミットが含まれているのは:
5ファイル変更
+151
-36
検索条件に一致するファイルはありません
@@ -74,7 +74,7 @@ namespace LuaScript
|
||||
|
||||
public Func<string, double, (byte[] Buffer, int Width, int Height)>? SceneImageLoader { get; set; }
|
||||
|
||||
public Func<string, double, double, (byte[] Buffer, int Width, int Height)>? BrushImageLoader { get; set; }
|
||||
public Func<string, double, double, IReadOnlyList<KeyValuePair<string, object>>, (byte[] Buffer, int Width, int Height)>? BrushImageLoader { get; set; }
|
||||
|
||||
private readonly Dictionary<string, string> _stringParameters = new(StringComparer.Ordinal);
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace LuaScript.Engine
|
||||
Func<string, (byte[] buffer, int w, int h)> loadImage,
|
||||
Func<string, double, (byte[] buffer, int w, int h)> loadMovie,
|
||||
Func<string, double, (byte[] buffer, int w, int h)> loadScene,
|
||||
Func<string, double, double, (byte[] buffer, int w, int h)> loadBrush,
|
||||
Func<string, double, double, IReadOnlyList<KeyValuePair<string, object>>, (byte[] buffer, int w, int h)> loadBrush,
|
||||
Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect,
|
||||
Action<DrawCommand> addDraw,
|
||||
Action<string, int, bool, int, double[]> setAnchor,
|
||||
@@ -324,7 +324,7 @@ namespace LuaScript.Engine
|
||||
Func<string, (byte[] buffer, int w, int h)> loadImage,
|
||||
Func<string, double, (byte[] buffer, int w, int h)> loadMovie,
|
||||
Func<string, double, (byte[] buffer, int w, int h)> loadScene,
|
||||
Func<string, double, double, (byte[] buffer, int w, int h)> loadBrush,
|
||||
Func<string, double, double, IReadOnlyList<KeyValuePair<string, object>>, (byte[] buffer, int w, int h)> loadBrush,
|
||||
Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect,
|
||||
Action<string, int, bool, int, double[]> setAnchor,
|
||||
Func<string, SceneValue> sceneGetValue,
|
||||
@@ -355,6 +355,9 @@ namespace LuaScript.Engine
|
||||
case NativeProtocol.CbKindLoadBrush:
|
||||
ResolveLoadBrushCallback(view, loadBrush);
|
||||
break;
|
||||
case NativeProtocol.CbKindBrush:
|
||||
ResolveBrushCallback(view, loadBrush);
|
||||
break;
|
||||
case NativeProtocol.CbKindEffect:
|
||||
ResolveEffectCallback(view, addEffect);
|
||||
break;
|
||||
@@ -810,20 +813,50 @@ namespace LuaScript.Engine
|
||||
view.Write(NativeProtocol.OffCallbackFound, 1);
|
||||
}
|
||||
|
||||
private static readonly KeyValuePair<string, object>[] s_noBrushArguments = [];
|
||||
|
||||
private void ResolveLoadBrushCallback(
|
||||
MemoryMappedViewAccessor view,
|
||||
Func<string, double, double, (byte[] buffer, int w, int h)> loadBrush)
|
||||
Func<string, double, double, IReadOnlyList<KeyValuePair<string, object>>, (byte[] buffer, int w, int h)> loadBrush)
|
||||
{
|
||||
int tagLen = Math.Clamp(view.ReadInt32(NativeProtocol.OffCallbackTagLen), 0, NativeProtocol.CallbackTagMax);
|
||||
view.ReadArray(NativeProtocol.CallbackTagOffset, _callbackTag, 0, tagLen);
|
||||
string name = Encoding.UTF8.GetString(_callbackTag, 0, tagLen);
|
||||
|
||||
WriteBrushResult(view, loadBrush, name, s_noBrushArguments);
|
||||
}
|
||||
|
||||
private void ResolveBrushCallback(
|
||||
MemoryMappedViewAccessor view,
|
||||
Func<string, double, double, IReadOnlyList<KeyValuePair<string, object>>, (byte[] buffer, int w, int h)> loadBrush)
|
||||
{
|
||||
int tagLen = Math.Clamp(view.ReadInt32(NativeProtocol.OffCallbackTagLen), 0, NativeProtocol.CallbackTagMax);
|
||||
view.ReadArray(NativeProtocol.CallbackTagOffset, _callbackTag, 0, tagLen);
|
||||
|
||||
var segments = Encoding.UTF8.GetString(_callbackTag, 0, tagLen).Split('\0');
|
||||
if (segments.Length == 0)
|
||||
{
|
||||
view.Write(NativeProtocol.OffLoadResultWidth, 0);
|
||||
view.Write(NativeProtocol.OffLoadResultHeight, 0);
|
||||
view.Write(NativeProtocol.OffCallbackFound, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
WriteBrushResult(view, loadBrush, segments[0], ParseNamedArguments(segments));
|
||||
}
|
||||
|
||||
private void WriteBrushResult(
|
||||
MemoryMappedViewAccessor view,
|
||||
Func<string, double, double, IReadOnlyList<KeyValuePair<string, object>>, (byte[] buffer, int w, int h)> loadBrush,
|
||||
string name,
|
||||
IReadOnlyList<KeyValuePair<string, object>> arguments)
|
||||
{
|
||||
long rOff = NativeProtocol.CallbackResultOffset;
|
||||
double width = view.ReadDouble(rOff + 0 * 8);
|
||||
double height = view.ReadDouble(rOff + 1 * 8);
|
||||
|
||||
(byte[] buffer, int w, int h) result;
|
||||
try { result = loadBrush(name, width, height); }
|
||||
try { result = loadBrush(name, width, height, arguments); }
|
||||
catch { result = ([], 0, 0); }
|
||||
|
||||
long pixelSize = (long)result.w * result.h * 4;
|
||||
@@ -841,16 +874,11 @@ namespace LuaScript.Engine
|
||||
view.Write(NativeProtocol.OffCallbackFound, 1);
|
||||
}
|
||||
|
||||
private void ResolveEffectCallback(MemoryMappedViewAccessor view, Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect)
|
||||
private static IReadOnlyList<KeyValuePair<string, object>> ParseNamedArguments(string[] segments)
|
||||
{
|
||||
int tagLen = Math.Clamp(view.ReadInt32(NativeProtocol.OffCallbackTagLen), 0, NativeProtocol.CallbackTagMax);
|
||||
view.ReadArray(NativeProtocol.CallbackTagOffset, _callbackTag, 0, tagLen);
|
||||
if (segments.Length < 3)
|
||||
return s_noBrushArguments;
|
||||
|
||||
var segments = Encoding.UTF8.GetString(_callbackTag, 0, tagLen).Split('\0');
|
||||
if (segments.Length == 0)
|
||||
return;
|
||||
|
||||
string effectName = segments[0];
|
||||
var arguments = new List<KeyValuePair<string, object>>();
|
||||
for (int i = 1; i + 1 < segments.Length; i += 2)
|
||||
{
|
||||
@@ -867,8 +895,19 @@ namespace LuaScript.Engine
|
||||
value = raw;
|
||||
arguments.Add(new KeyValuePair<string, object>(key, value));
|
||||
}
|
||||
return arguments;
|
||||
}
|
||||
|
||||
try { addEffect(effectName, arguments); }
|
||||
private void ResolveEffectCallback(MemoryMappedViewAccessor view, Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect)
|
||||
{
|
||||
int tagLen = Math.Clamp(view.ReadInt32(NativeProtocol.OffCallbackTagLen), 0, NativeProtocol.CallbackTagMax);
|
||||
view.ReadArray(NativeProtocol.CallbackTagOffset, _callbackTag, 0, tagLen);
|
||||
|
||||
var segments = Encoding.UTF8.GetString(_callbackTag, 0, tagLen).Split('\0');
|
||||
if (segments.Length == 0)
|
||||
return;
|
||||
|
||||
try { addEffect(segments[0], ParseNamedArguments(segments)); }
|
||||
catch { }
|
||||
view.Write(NativeProtocol.OffCallbackFound, 1);
|
||||
}
|
||||
|
||||
@@ -557,7 +557,8 @@ namespace LuaScript
|
||||
LoadBrush(
|
||||
args[1].String,
|
||||
args.Count > 2 ? args[2].CastToNumber() ?? 0d : 0d,
|
||||
args.Count > 3 ? args[3].CastToNumber() ?? 0d : 0d);
|
||||
args.Count > 3 ? args[3].CastToNumber() ?? 0d : 0d,
|
||||
s_noNamedArguments);
|
||||
break;
|
||||
}
|
||||
return DynValue.Void;
|
||||
@@ -873,9 +874,19 @@ namespace LuaScript
|
||||
if (_activeContext is null || args.Count == 0 || args[0].Type != DataType.String)
|
||||
return DynValue.Void;
|
||||
|
||||
string name = args[0].String;
|
||||
_activeContext.AddEffect(new AviUtlEffectRequest(args[0].String, CollectNamedArguments(args, 1)));
|
||||
return DynValue.Void;
|
||||
}
|
||||
|
||||
private static readonly KeyValuePair<string, object>[] s_noNamedArguments = [];
|
||||
|
||||
private static IReadOnlyList<KeyValuePair<string, object>> CollectNamedArguments(CallbackArguments args, int start)
|
||||
{
|
||||
if (start + 1 >= args.Count)
|
||||
return s_noNamedArguments;
|
||||
|
||||
var arguments = new List<KeyValuePair<string, object>>();
|
||||
for (int i = 1; i + 1 < args.Count; i += 2)
|
||||
for (int i = start; i + 1 < args.Count; i += 2)
|
||||
{
|
||||
if (args[i].Type != DataType.String)
|
||||
continue;
|
||||
@@ -889,8 +900,27 @@ namespace LuaScript
|
||||
};
|
||||
arguments.Add(new KeyValuePair<string, object>(args[i].String, boxed));
|
||||
}
|
||||
return arguments;
|
||||
}
|
||||
|
||||
_activeContext.AddEffect(new AviUtlEffectRequest(name, arguments));
|
||||
[LuaFunction("brush")]
|
||||
private DynValue Brush(CallbackArguments args)
|
||||
{
|
||||
_activeCancellation.ThrowIfCancellationRequested();
|
||||
if (_activeContext is null || args.Count == 0 || args[0].Type != DataType.String)
|
||||
return DynValue.Void;
|
||||
|
||||
int start = 1;
|
||||
double width = 0d;
|
||||
double height = 0d;
|
||||
if (args.Count > 2 && args[1].Type == DataType.Number && args[2].Type == DataType.Number)
|
||||
{
|
||||
width = args[1].Number;
|
||||
height = args[2].Number;
|
||||
start = 3;
|
||||
}
|
||||
|
||||
LoadBrush(args[0].String, width, height, CollectNamedArguments(args, start));
|
||||
return DynValue.Void;
|
||||
}
|
||||
|
||||
@@ -971,7 +1001,7 @@ namespace LuaScript
|
||||
RefreshObjDimensions();
|
||||
}
|
||||
|
||||
private void LoadBrush(string name, double width, double height)
|
||||
private void LoadBrush(string name, double width, double height, IReadOnlyList<KeyValuePair<string, object>> arguments)
|
||||
{
|
||||
var ctx = _activeContext!;
|
||||
var loader = ctx.BrushImageLoader;
|
||||
@@ -979,7 +1009,7 @@ namespace LuaScript
|
||||
return;
|
||||
double w = width > 0d ? width : ctx.ImageWidth;
|
||||
double h = height > 0d ? height : ctx.ImageHeight;
|
||||
var (buffer, bw, bh) = loader(name, w, h);
|
||||
var (buffer, bw, bh) = loader(name, w, h, arguments);
|
||||
if (bw <= 0 || bh <= 0)
|
||||
return;
|
||||
ctx.ReplaceBuffer(buffer, bw, bh);
|
||||
|
||||
@@ -8,11 +8,26 @@ namespace LuaScript
|
||||
{
|
||||
private const int MaxDimension = 8192;
|
||||
|
||||
private readonly Dictionary<string, IBrushSource?> _sources = new(StringComparer.Ordinal);
|
||||
private sealed class Entry(IBrushParameter parameter, IBrushSource source)
|
||||
{
|
||||
public IBrushParameter Parameter { get; } = parameter;
|
||||
public IBrushSource Source { get; } = source;
|
||||
public string[] AppliedKeys { get; set; } = [];
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, Entry?> _sources = new(StringComparer.Ordinal);
|
||||
private GraphicsDevicesAndContext? _ctx;
|
||||
private PixelBufferManager? _pixels;
|
||||
|
||||
public bool TryRender(TimelineItemSourceDescription desc, string name, int width, int height, out byte[] pixels, out int outWidth, out int outHeight)
|
||||
public bool TryRender(
|
||||
TimelineItemSourceDescription desc,
|
||||
string name,
|
||||
int width,
|
||||
int height,
|
||||
IReadOnlyList<KeyValuePair<string, object>> arguments,
|
||||
out byte[] pixels,
|
||||
out int outWidth,
|
||||
out int outHeight)
|
||||
{
|
||||
pixels = [];
|
||||
outWidth = 0;
|
||||
@@ -21,24 +36,42 @@ namespace LuaScript
|
||||
if (width <= 0 || height <= 0 || width > MaxDimension || height > MaxDimension)
|
||||
return false;
|
||||
|
||||
if (!_sources.TryGetValue(name, out var source))
|
||||
if (!_sources.TryGetValue(name, out var entry))
|
||||
{
|
||||
source = CreateSource(name);
|
||||
_sources[name] = source;
|
||||
entry = CreateEntry(name);
|
||||
_sources[name] = entry;
|
||||
}
|
||||
if (source is null)
|
||||
if (entry is null)
|
||||
return false;
|
||||
|
||||
if (!KeysMatch(entry.AppliedKeys, arguments))
|
||||
{
|
||||
entry.Source.Dispose();
|
||||
entry = CreateEntry(name);
|
||||
_sources[name] = entry;
|
||||
if (entry is null)
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
source.Update(desc);
|
||||
if (arguments.Count > 0)
|
||||
{
|
||||
Ymm4PropertyBinder.ApplyArguments(entry.Parameter, arguments);
|
||||
if (entry.AppliedKeys.Length != arguments.Count)
|
||||
entry.AppliedKeys = new string[arguments.Count];
|
||||
for (int i = 0; i < arguments.Count; i++)
|
||||
entry.AppliedKeys[i] = arguments[i].Key;
|
||||
}
|
||||
|
||||
entry.Source.Update(desc);
|
||||
_pixels ??= new PixelBufferManager(_ctx!);
|
||||
pixels = _pixels.LoadBrushPixels(source.Brush, width, height);
|
||||
pixels = _pixels.LoadBrushPixels(entry.Source.Brush, width, height);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_sources.Remove(name);
|
||||
source.Dispose();
|
||||
entry.Source.Dispose();
|
||||
pixels = [];
|
||||
return false;
|
||||
}
|
||||
@@ -48,22 +81,35 @@ namespace LuaScript
|
||||
return true;
|
||||
}
|
||||
|
||||
private IBrushSource? CreateSource(string name)
|
||||
private static bool KeysMatch(string[] appliedKeys, IReadOnlyList<KeyValuePair<string, object>> arguments)
|
||||
{
|
||||
if (appliedKeys.Length != arguments.Count)
|
||||
return false;
|
||||
for (int i = 0; i < appliedKeys.Length; i++)
|
||||
{
|
||||
if (!string.Equals(appliedKeys[i], arguments[i].Key, StringComparison.Ordinal))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private Entry? CreateEntry(string name)
|
||||
{
|
||||
foreach (var plugin in BrushFactory.Plugins)
|
||||
{
|
||||
if (!string.Equals(plugin.Name, name, StringComparison.Ordinal))
|
||||
continue;
|
||||
_ctx ??= new GraphicsDevicesAndContext(devices);
|
||||
return plugin.CreateBrushParameter().CreateBrush(_ctx);
|
||||
var parameter = plugin.CreateBrushParameter();
|
||||
return new Entry(parameter, parameter.CreateBrush(_ctx));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var source in _sources.Values)
|
||||
source?.Dispose();
|
||||
foreach (var entry in _sources.Values)
|
||||
entry?.Source.Dispose();
|
||||
_sources.Clear();
|
||||
_pixels?.Dispose();
|
||||
_ctx?.Dispose();
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace LuaScript
|
||||
private Func<string, (byte[] buffer, int w, int h)>? _nativeLoadImage;
|
||||
private Func<string, double, (byte[] buffer, int w, int h)>? _nativeLoadMovie;
|
||||
private Func<string, double, (byte[] Buffer, int Width, int Height)>? _loadSceneImage;
|
||||
private Func<string, double, double, (byte[] Buffer, int Width, int Height)>? _loadBrushImage;
|
||||
private Func<string, double, double, IReadOnlyList<KeyValuePair<string, object>>, (byte[] Buffer, int Width, int Height)>? _loadBrushImage;
|
||||
private SceneImageRenderer? _sceneImageRenderer;
|
||||
private BrushImageRenderer? _brushImageRenderer;
|
||||
private bool _sceneImageLoaded;
|
||||
@@ -1194,7 +1194,7 @@ namespace LuaScript
|
||||
}
|
||||
}
|
||||
|
||||
private (byte[] Buffer, int Width, int Height) LoadBrushImage(string name, double width, double height)
|
||||
private (byte[] Buffer, int Width, int Height) LoadBrushImage(string name, double width, double height, IReadOnlyList<KeyValuePair<string, object>> arguments)
|
||||
{
|
||||
var desc = _frameDesc;
|
||||
var devices = _hostDevices;
|
||||
@@ -1208,7 +1208,7 @@ namespace LuaScript
|
||||
try
|
||||
{
|
||||
_brushImageRenderer ??= new BrushImageRenderer(devices);
|
||||
if (!_brushImageRenderer.TryRender(desc, name, w, h, out var pixels, out int outWidth, out int outHeight))
|
||||
if (!_brushImageRenderer.TryRender(desc, name, w, h, arguments, out var pixels, out int outWidth, out int outHeight))
|
||||
return s_noLoadedImage;
|
||||
return (pixels, outWidth, outHeight);
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする