コミットを比較
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
004041b342
|
||
|
|
08f69cf76d
|
||
|
|
e10bfbe406
|
||
|
|
1a46a76b59
|
||
|
|
e2f32a6722
|
||
|
|
5a23f4329e
|
||
|
|
f5fd6cebdb
|
||
|
|
48f6711f1a
|
||
|
|
859046f5aa
|
||
|
|
7c7a60807f
|
||
|
|
1b23b2937e
|
||
|
|
4135f52499
|
||
|
|
8fda0bfec5
|
||
|
|
7e353053c7
|
||
|
|
d744d218fb
|
||
|
|
772fa6b678
|
||
|
|
154bc6a5c0
|
||
|
|
593939c2d4
|
||
|
|
6730c8ce70
|
||
|
|
b6a1e6e43c
|
||
|
|
fd06fdafe7
|
検索条件に一致するファイルはありません
+45
-18
@@ -1,35 +1,62 @@
|
||||
# v1.16.3 - Lua スクリプト for YMM4
|
||||
# v1.17.0 - Lua スクリプト for YMM4
|
||||
|
||||
再生中の毎フレームのヒープ割り当てを一箇所排除した保守リリースです。エフェクトプロセッサは、キャッシュが一致しないフレームの末尾で、シーンの照会の結果を配列へ写し取り、次フレームの一致判定に備えます。再生中はフレーム番号が毎フレーム変わるため描画鍵が必ず変化し、この末尾が毎フレーム実行されます。従来はここで、シーンのオブジェクトやシーン共有値を照会するスクリプトのために SceneObjectQuery と SceneValueQuery の配列を毎フレーム新規に確保していました。本リリースでは、照会の個数が安定している通常の場合にスナップショットの配列を使い回し、この場合の毎フレームの割り当てをゼロにします。実行結果に変更はなく、スクリプトの挙動もエンジンの振り分けも従来のままです。
|
||||
YMM4 のシーンと模様(ブラシ)をスクリプトから利用できるようにしたリリースです。obj.load へ読込種別 "scene" と "brush" を追加し、プロジェクト内の別シーンの映像と、模様で塗り潰した画像を、オブジェクトの画像として読み込めるようにしました。さらに obj.brush を追加し、obj.effect と同じ「名前と値の組」で模様のパラメータを変更しながら描画できるようにしました。いずれも AviUtl / AviUtl2 の obj.load と obj には存在しない YMM4 向けの独自拡張で、シーンの描画も模様の描画も YMM4 のプラグイン公開 API だけで実装しています。従来エンジン(MoonSharp)と高速ランタイム(LuaJIT)の両方で動作し、実行結果は両エンジンで一致します。
|
||||
|
||||
---
|
||||
|
||||
## パフォーマンス
|
||||
## 新機能
|
||||
|
||||
### シーンの照会のスナップショットの配列の使い回し
|
||||
### obj.load("scene", シーン名 [, 時間])
|
||||
|
||||
エフェクトプロセッサの非キャッシュ経路の末尾で毎フレーム起きていた配列の確保を、通常の場合に排除しました。
|
||||
プロジェクト内の別シーンを指定時刻で描画し、オブジェクトのバッファを置き換えます。
|
||||
|
||||
- エフェクトプロセッサは、描画鍵と照会の結果が前フレームと一致するときは前フレームの出力をそのまま返し、一致しないときだけスクリプトを実行します。再生中はフレーム番号が毎フレーム変わり描画鍵が必ず変化するため、非キャッシュ経路が毎フレーム走ります。この経路の末尾では、次フレームの一致判定のために、そのフレームで行われたシーンの照会の結果をスナップショットとして配列へ写し取ります。
|
||||
- 従来はこの写し取りを毎フレーム新しい配列の確保で行っていました。obj.getoption などでシーンのオブジェクトを照会するスクリプトや、シーン共有値を読むスクリプトでは、SceneObjectQuery または SceneValueQuery の配列がフレームごとに確保され、ガベージコレクションの圧力になっていました。
|
||||
- 本リリースでは、照会の個数が前フレームと同じであればスナップショットの配列を使い回し、要素だけを書き戻します。同じスクリプトが同じ個数の照会を行う通常の場合、毎フレームの割り当てが起きなくなります。個数が変わったフレームだけ新しい配列を確保します。
|
||||
- 照会を一切行わないスクリプトは、従来どおり共有の空配列を用い、割り当ては起きません。
|
||||
- 対象はエフェクトプロセッサの内部の毎フレームの固定費だけです。カーネルレーン、高速ランタイム、MoonSharp のいずれの実行経路も、選び方も、実行結果も変わりません。
|
||||
obj.load("scene", "サブシーン", obj.time)
|
||||
|
||||
- シーン名には YMM4 のシーン一覧に表示される名前を指定します。時間は秒で、省略すると obj.time を用います。読み込み後は obj.w / obj.h などの寸法がシーンの解像度へ更新され、load 直後の getpixel でも参照できます。
|
||||
- シーンの描画には YMM4 のプラグイン公開 API である ISceneInfo.TryCreateVideoSource を用います。YMM4 本体のシーンアイテムと同じ経路で描画するため、シーンの内容もエフェクトもそのまま反映されます。
|
||||
- 現在のオブジェクトが乗っているシーン自身は指定できません。シーン描画の中からさらにシーンを読み込む形も拒否し、シーン同士の相互参照による無限再帰を防ぎます。
|
||||
- 参照先シーンの内容の変化は描画鍵では検知できないため、シーンを読み込んだフレームは描画キャッシュを使わず毎回再実行します。編集中の参照先シーンの変更が、そのまま次の描画へ反映されます。
|
||||
|
||||
### obj.load("brush", 模様名 [, 幅, 高さ])
|
||||
|
||||
YMM4 の模様(ブラシ)で塗り潰した画像を生成し、オブジェクトのバッファを置き換えます。
|
||||
|
||||
obj.load("brush", "縞模様", 400, 300)
|
||||
|
||||
- 模様名には YMM4 の模様一覧に表示される名前を指定します。ブラシプラグインで追加した模様もそのまま使えます。
|
||||
- 幅と高さを省略すると現在の obj.w / obj.h を用います。模様のパラメータは既定値で描画されます。
|
||||
- 塗り潰しは Direct2D のブラシで中心原点の矩形に対して行い、生成した画像は他の読込種別と同じ乗算済みアルファの BGRA として扱われます。
|
||||
|
||||
### obj.brush(模様名 [, 幅, 高さ] [, パラメータ名, 値, ...])
|
||||
|
||||
模様のパラメータを変更しながら描画します。描画は obj.load("brush") と同じで、加えて obj.effect と同じ「名前と値の組」を受け付けます。
|
||||
|
||||
obj.brush("縞模様", "Angle", 45, "Color1", 0xff3366)
|
||||
|
||||
- パラメータ名には模様の設定項目の表示名、または内部のプロパティ名を指定します。値は数値・真偽値・文字列に対応し、色は 0xRRGGBB の数値で指定します。
|
||||
- 模様名の直後に数値を 2 つ並べたときだけ、それを幅と高さとして解釈します。パラメータ名は常に文字列のため、サイズと組が曖昧になることはありません。
|
||||
- 指定しなかったパラメータは既定値で描画されます。組をすべて省略した呼び出しは obj.load("brush") と同じです。
|
||||
- パラメータの解決は obj.effect と同じ仕組みです。表示名と内部名の両方を受け付け、対応しない名前の組は無視されます。
|
||||
|
||||
---
|
||||
|
||||
## 互換性・後方互換
|
||||
|
||||
- 実行結果に変更はありません。本変更は毎フレームの割り当ての排除だけを目的とし、スクリプトの挙動、出力、描画記述のいずれも変わりません。
|
||||
- スナップショットの配列は、そのフレームで行われた照会の結果を毎フレームすべて書き戻すため、使い回しても内容は毎フレーム新規に確保していた従来と同一です。一致判定に使う値に差は生じません。
|
||||
- エンジンの自動振り分け、エンジン指定ディレクティブの仕様と優先順位、カーネル化の対象、v1.16.2 までの構文拡張と既存の API に変更はありません。
|
||||
- 既存の読込種別 "figure" / "text" / "image" / "movie" の挙動に変更はありません。新設の読込に失敗した場合は、従来の読込の失敗時と同様に現在の画像を保持します。
|
||||
- "scene" / "brush" / obj.brush は AviUtl / AviUtl2 に存在しない YMM4 向けの独自拡張です。AviUtl 向けに書かれた既存スクリプトへの影響はありません。
|
||||
- obj.effect のパラメータ適用の実装を模様と共有する形へ整理しましたが、名前の解決規則、値の変換、互換マップの扱いのいずれも従来のままで、適用結果は変わりません。
|
||||
- エンジンの自動振り分け、エンジン指定ディレクティブの仕様と優先順位、カーネル化の対象、v1.16.3 までの構文拡張と既存の API に変更はありません。
|
||||
|
||||
---
|
||||
|
||||
## 内部実装
|
||||
|
||||
- 追加した `SnapshotQueries<T>(IReadOnlyList<T> source, T[] existing)` は、照会の個数が 0 のときは共有の空配列を返し、既存の配列の長さが個数と一致するときはその配列へ要素を書き戻し、一致しないときだけ新しい配列を確保します。照会の個数はスクリプトが同じであればフレーム間で安定するため、その場合は毎フレームの割り当てが起きません。
|
||||
- 使い回しが安全なのは、SceneObjectQuery と SceneValueQuery がいずれも readonly record struct の値であり、前フレームのスナップショットが当該フレームのキャッシュの一致判定で読み終えた後に上書きされるためです。判定より前に上書きが起きることはなく、配列の使い回しによる別名の干渉はありません。既存の compute-once / zero per-frame allocation の設計思想に沿った統一的な変更です。
|
||||
- あわせて、他の毎フレームの経路がいずれも自らのレーンの中で割り当てを持たないことを再確認しました。GPU カーネルの適用は定数の緩衝と出力を再利用し、CPU カーネルと SIMD、ネイティブレーンのワーカー、カーネルのユニフォームの充填、ネイティブのフィールドの写し取り、コンテキストの充填、構造体の複製による出力記述の生成のいずれにも毎フレームの割り当てはありません。
|
||||
- 精査の上で見送った項目があります。ネイティブレーンの文字列パラメータの毎フレームの再エンコードは、短い文字列に対する処理であり、それが乗るプロセス間の往復に比べて無視できる量のため据え置きました。ディレクティブ解決の二重の走査は、参照の同一性でキャッシュされスクリプトの編集ごとに一度だけ走るため据え置きました。MoonSharp レーンの数値のボックス化は、低速フォールバック専用として従来どおり据え置きました。
|
||||
- テストは 3317 件で変更はありません。本変更は実行結果を変えないため、既存のキャッシュとシーンの照会の一致判定の検証で挙動が担保されます。ソリューションは Release x64 で 0 個の警告、0 個のエラーです。
|
||||
- シーンの描画は新設の SceneImageRenderer が担います。シーン ID ごとに ITimelineSource をキャッシュし、専用のデバイスコンテキストで描画した出力をステージングビットマップ経由で読み戻します。読み戻し用の緩衝は伸長のみの再利用で、定常状態の毎フレームの割り当てはありません。入れ子のシーン読込の拒否はスレッド静的な深さガードで行い、同一スレッド上の再帰だけを対象にするため競合はありません。
|
||||
- 模様の描画は新設の BrushImageRenderer が担います。模様名ごとにブラシのパラメータとソースの組をキャッシュし、PixelBufferManager へ追加した LoadBrushPixels で中心原点の矩形を塗り潰して読み戻します。ブラシのソースは Update のたびにパラメータの現在値を読み直すため、キャッシュしたソースへのパラメータ変更がそのまま反映されます。
|
||||
- obj.brush のパラメータの組が前回の呼び出しと異なる名前の集合になったときは、パラメータを既定値から作り直してから適用します。結果が現在の呼び出しの引数だけで決まり、以前の呼び出しで変更した値が残らないようにするためです。同じ名前の集合の間は値の上書きだけで済ませ、毎フレームの作り直しを避けます。
|
||||
- パラメータの適用機構は VideoEffectChain から Ymm4PropertyBinder へ抽出し、obj.effect と obj.brush が同じ実装を共有します。プロパティ表のキャッシュは、エフェクトの適用が描画スレッド、模様の適用がスクリプトの実行スレッドで走るようになったため、ロックで保護しました。
|
||||
- どちらのレンダラーもエフェクトプロセッサの画素読込セマフォの中で実行し、実行スレッドと描画スレッドの Direct2D の競合を既存の合成経路と同じ方法で防ぎます。
|
||||
- 高速ランタイムにはプロセス間手順の呼出種別 CbKindLoadScene / CbKindLoadBrush / CbKindBrush を追加しました。シーンは動画読込と同じ経路、obj.brush は obj.effect と同じ名前と値の符号化に幅と高さを添えた経路で、ホスト側の描画結果を共有メモリへ書き戻します。名前と値の組の符号化と復号は、ワーカー側もホスト側も obj.effect の実装と共有しています。
|
||||
- MoonSharp レーンはコンテキストへ追加した読込委譲 SceneImageLoader / BrushImageLoader を経由してホスト側のレンダラーを呼び出します。委譲が未設定のテスト環境では読込は無操作になります。
|
||||
- ドキュメントは付属の 8 言語、サイトの obj の関数・リファレンス・トップのページ、README を更新しました。
|
||||
- テストは 3332 件です。v1.16.3 の 3317 件から、MoonSharp レーンの scene / brush 読込の委譲の往復・時間とサイズの既定値・失敗時の画像保持、obj.brush の組の解析・先頭サイズの解釈・組なしの呼び出し、高速ランタイムの scene / brush / obj.brush の呼出種別の往復の検証を追加しました。ソリューションは x64 で 0 個の警告、0 個のエラーです。
|
||||
@@ -1,5 +1,5 @@
|
||||
========================================
|
||||
Luaスクリプト for YMM4 v1.16.3
|
||||
Luaスクリプト for YMM4 v1.17.0
|
||||
========================================
|
||||
YukkuriMovieMaker4(YMM4)上で動作する、Luaスクリプトで映像エフェクトのパラメータや
|
||||
ピクセルを直接制御できるプラグインです。
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.16.3</Version>
|
||||
<Version>1.17.0</Version>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.16.3</Version>
|
||||
<Version>1.17.0</Version>
|
||||
<IsRoslynComponent>true</IsRoslynComponent>
|
||||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.16.3</Version>
|
||||
<Version>1.17.0</Version>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.16.3</Version>
|
||||
<Version>1.17.0</Version>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
|
||||
@@ -72,6 +72,10 @@ namespace LuaScript
|
||||
|
||||
public Func<ISceneObjectResolver>? ResolverProvider { get; set; }
|
||||
|
||||
public Func<string, double, (byte[] Buffer, int Width, int Height)>? SceneImageLoader { 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);
|
||||
|
||||
public IReadOnlyDictionary<string, string> StringParameters => _stringParameters;
|
||||
|
||||
@@ -71,6 +71,8 @@ namespace LuaScript.Engine
|
||||
Func<string, string, double, bool, bool, int, (byte[] buffer, int w, int h)> loadText,
|
||||
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, 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,
|
||||
@@ -160,7 +162,7 @@ namespace LuaScript.Engine
|
||||
}
|
||||
else
|
||||
{
|
||||
DispatchCallback(view, resolveObject, loadFigure, loadText, loadImage, loadMovie, addEffect, setAnchor, sceneGetValue, sceneSetValue, runPixelShader);
|
||||
DispatchCallback(view, resolveObject, loadFigure, loadText, loadImage, loadMovie, loadScene, loadBrush, addEffect, setAnchor, sceneGetValue, sceneSetValue, runPixelShader);
|
||||
}
|
||||
_workEvent.Set();
|
||||
}
|
||||
@@ -321,6 +323,8 @@ namespace LuaScript.Engine
|
||||
Func<string, string, double, bool, bool, int, (byte[] buffer, int w, int h)> loadText,
|
||||
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, 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,
|
||||
@@ -345,6 +349,15 @@ namespace LuaScript.Engine
|
||||
case NativeProtocol.CbKindLoadMovie:
|
||||
ResolveLoadMovieCallback(view, loadMovie);
|
||||
break;
|
||||
case NativeProtocol.CbKindLoadScene:
|
||||
ResolveLoadSceneCallback(view, loadScene);
|
||||
break;
|
||||
case NativeProtocol.CbKindLoadBrush:
|
||||
ResolveLoadBrushCallback(view, loadBrush);
|
||||
break;
|
||||
case NativeProtocol.CbKindBrush:
|
||||
ResolveBrushCallback(view, loadBrush);
|
||||
break;
|
||||
case NativeProtocol.CbKindEffect:
|
||||
ResolveEffectCallback(view, addEffect);
|
||||
break;
|
||||
@@ -772,16 +785,100 @@ namespace LuaScript.Engine
|
||||
view.Write(NativeProtocol.OffCallbackFound, 1);
|
||||
}
|
||||
|
||||
private void ResolveEffectCallback(MemoryMappedViewAccessor view, Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect)
|
||||
private void ResolveLoadSceneCallback(
|
||||
MemoryMappedViewAccessor view,
|
||||
Func<string, double, (byte[] buffer, int w, int h)> loadScene)
|
||||
{
|
||||
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);
|
||||
double time = view.ReadDouble(NativeProtocol.CallbackResultOffset);
|
||||
|
||||
(byte[] buffer, int w, int h) result;
|
||||
try { result = loadScene(name, time); }
|
||||
catch { result = ([], 0, 0); }
|
||||
|
||||
long pixelSize = (long)result.w * result.h * 4;
|
||||
if (result.w <= 0 || result.h <= 0 || pixelSize > PixelRegionCapacity)
|
||||
{
|
||||
view.Write(NativeProtocol.OffLoadResultWidth, 0);
|
||||
view.Write(NativeProtocol.OffLoadResultHeight, 0);
|
||||
view.Write(NativeProtocol.OffCallbackFound, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
view.Write(NativeProtocol.OffLoadResultWidth, result.w);
|
||||
view.Write(NativeProtocol.OffLoadResultHeight, result.h);
|
||||
WritePixelRegion(result.buffer, (int)pixelSize);
|
||||
view.Write(NativeProtocol.OffCallbackFound, 1);
|
||||
}
|
||||
|
||||
private static readonly KeyValuePair<string, object>[] s_noBrushArguments = [];
|
||||
|
||||
private void ResolveLoadBrushCallback(
|
||||
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);
|
||||
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, arguments); }
|
||||
catch { result = ([], 0, 0); }
|
||||
|
||||
long pixelSize = (long)result.w * result.h * 4;
|
||||
if (result.w <= 0 || result.h <= 0 || pixelSize > PixelRegionCapacity)
|
||||
{
|
||||
view.Write(NativeProtocol.OffLoadResultWidth, 0);
|
||||
view.Write(NativeProtocol.OffLoadResultHeight, 0);
|
||||
view.Write(NativeProtocol.OffCallbackFound, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
view.Write(NativeProtocol.OffLoadResultWidth, result.w);
|
||||
view.Write(NativeProtocol.OffLoadResultHeight, result.h);
|
||||
WritePixelRegion(result.buffer, (int)pixelSize);
|
||||
view.Write(NativeProtocol.OffCallbackFound, 1);
|
||||
}
|
||||
|
||||
private static IReadOnlyList<KeyValuePair<string, object>> ParseNamedArguments(string[] segments)
|
||||
{
|
||||
if (segments.Length < 3)
|
||||
return s_noBrushArguments;
|
||||
|
||||
string effectName = segments[0];
|
||||
var arguments = new List<KeyValuePair<string, object>>();
|
||||
for (int i = 1; i + 1 < segments.Length; i += 2)
|
||||
{
|
||||
@@ -798,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);
|
||||
}
|
||||
|
||||
@@ -548,6 +548,18 @@ namespace LuaScript
|
||||
args[1].String,
|
||||
args.Count > 2 ? args[2].CastToNumber() ?? _activeContext.Time : _activeContext.Time);
|
||||
break;
|
||||
case "scene" when args.Count > 1 && args[1].Type == DataType.String:
|
||||
LoadScene(
|
||||
args[1].String,
|
||||
args.Count > 2 ? args[2].CastToNumber() ?? _activeContext.Time : _activeContext.Time);
|
||||
break;
|
||||
case "brush" when args.Count > 1 && args[1].Type == DataType.String:
|
||||
LoadBrush(
|
||||
args[1].String,
|
||||
args.Count > 2 ? args[2].CastToNumber() ?? 0d : 0d,
|
||||
args.Count > 3 ? args[3].CastToNumber() ?? 0d : 0d,
|
||||
s_noNamedArguments);
|
||||
break;
|
||||
}
|
||||
return DynValue.Void;
|
||||
}
|
||||
@@ -862,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;
|
||||
@@ -878,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;
|
||||
}
|
||||
|
||||
@@ -947,6 +988,34 @@ namespace LuaScript
|
||||
RefreshObjDimensions();
|
||||
}
|
||||
|
||||
private void LoadScene(string name, double time)
|
||||
{
|
||||
var ctx = _activeContext!;
|
||||
var loader = ctx.SceneImageLoader;
|
||||
if (loader is null)
|
||||
return;
|
||||
var (buffer, w, h) = loader(name, time);
|
||||
if (w <= 0 || h <= 0)
|
||||
return;
|
||||
ctx.ReplaceBuffer(buffer, w, h);
|
||||
RefreshObjDimensions();
|
||||
}
|
||||
|
||||
private void LoadBrush(string name, double width, double height, IReadOnlyList<KeyValuePair<string, object>> arguments)
|
||||
{
|
||||
var ctx = _activeContext!;
|
||||
var loader = ctx.BrushImageLoader;
|
||||
if (loader is null)
|
||||
return;
|
||||
double w = width > 0d ? width : ctx.ImageWidth;
|
||||
double h = height > 0d ? height : ctx.ImageHeight;
|
||||
var (buffer, bw, bh) = loader(name, w, h, arguments);
|
||||
if (bw <= 0 || bh <= 0)
|
||||
return;
|
||||
ctx.ReplaceBuffer(buffer, bw, bh);
|
||||
RefreshObjDimensions();
|
||||
}
|
||||
|
||||
private void LoadMovie(string path, double time)
|
||||
{
|
||||
_mediaLoader ??= _mediaLoaderFactory();
|
||||
|
||||
@@ -63,6 +63,9 @@ namespace LuaScript.Engine
|
||||
public const int CbKindSceneSet = 12;
|
||||
public const int CbKindPixelShaderStage = 13;
|
||||
public const int CbKindPixelShaderRun = 14;
|
||||
public const int CbKindLoadScene = 15;
|
||||
public const int CbKindLoadBrush = 16;
|
||||
public const int CbKindBrush = 17;
|
||||
|
||||
public const int DrawRingCapacity = 4096;
|
||||
public const int DrawEntryDoubles = 24;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.16.3</Version>
|
||||
<Version>1.17.0</Version>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace LuaScript.Tests
|
||||
"obj.setfont", "obj.draw", "obj.drawpoly", "obj.copybuffer",
|
||||
"obj.pixelshader",
|
||||
"obj.getvalue", "obj.setoption", "obj.getoption", "obj.pixeloption",
|
||||
"obj.setanchor", "obj.effect", "obj.getinfo"
|
||||
"obj.setanchor", "obj.effect", "obj.brush", "obj.getinfo"
|
||||
]),
|
||||
("math", [
|
||||
"math.abs", "math.ceil", "math.cos", "math.exp", "math.floor",
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
using LuaScript;
|
||||
|
||||
namespace LuaScript.Tests
|
||||
{
|
||||
public sealed class LuaScriptEngineSceneBrushLoadTests
|
||||
{
|
||||
private sealed class StubMediaLoader : IMediaSourceLoader
|
||||
{
|
||||
public byte[] RenderText(string text, string fontFamily, double fontSize, bool bold, bool italic, int colorRgb, out int width, out int height)
|
||||
{
|
||||
width = 1;
|
||||
height = 1;
|
||||
return new byte[4];
|
||||
}
|
||||
|
||||
public byte[] DecodeImage(string path, out int width, out int height)
|
||||
{
|
||||
width = 1;
|
||||
height = 1;
|
||||
return new byte[4];
|
||||
}
|
||||
|
||||
public byte[] DecodeMovie(string path, double time, out int width, out int height)
|
||||
{
|
||||
width = 1;
|
||||
height = 1;
|
||||
return new byte[4];
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
}
|
||||
|
||||
private static LuaScriptEngine CreateEngine() => new(static () => new StubMediaLoader());
|
||||
|
||||
private static AviUtlScriptContext NewContext()
|
||||
{
|
||||
return new AviUtlScriptContext
|
||||
{
|
||||
ImageWidth = 6,
|
||||
ImageHeight = 4,
|
||||
Time = 1.5,
|
||||
Framerate = 30,
|
||||
};
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadScene_ReplacesBufferAndUpdatesObjDimensions()
|
||||
{
|
||||
using var engine = CreateEngine();
|
||||
var ctx = NewContext();
|
||||
|
||||
string? capturedName = null;
|
||||
double capturedTime = -1;
|
||||
var rendered = new byte[2 * 3 * 4];
|
||||
ctx.SceneImageLoader = (name, time) =>
|
||||
{
|
||||
capturedName = name;
|
||||
capturedTime = time;
|
||||
return (rendered, 2, 3);
|
||||
};
|
||||
|
||||
engine.Execute("obj.load('scene', 'サブ', 4.25); obj.x = obj.w; obj.y = obj.h", ctx);
|
||||
|
||||
Assert.Equal("サブ", capturedName);
|
||||
Assert.Equal(4.25d, capturedTime);
|
||||
Assert.True(ctx.BufferReplaced);
|
||||
Assert.Same(rendered, ctx.GetPixelBuffer());
|
||||
Assert.Equal(2, ctx.ImageWidth);
|
||||
Assert.Equal(3, ctx.ImageHeight);
|
||||
Assert.Equal(2d, ctx.X);
|
||||
Assert.Equal(3d, ctx.Y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadScene_DefaultsTimeToObjTime()
|
||||
{
|
||||
using var engine = CreateEngine();
|
||||
var ctx = NewContext();
|
||||
|
||||
double capturedTime = -1;
|
||||
ctx.SceneImageLoader = (_, time) =>
|
||||
{
|
||||
capturedTime = time;
|
||||
return ([], 0, 0);
|
||||
};
|
||||
|
||||
engine.Execute("obj.load('scene', 'サブ')", ctx);
|
||||
|
||||
Assert.Equal(1.5d, capturedTime);
|
||||
Assert.False(ctx.BufferReplaced);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadScene_WithoutLoader_IsNoOp()
|
||||
{
|
||||
using var engine = CreateEngine();
|
||||
var ctx = NewContext();
|
||||
|
||||
engine.Execute("obj.load('scene', 'サブ'); obj.x = obj.w", ctx);
|
||||
|
||||
Assert.False(ctx.BufferReplaced);
|
||||
Assert.Equal(6d, ctx.X);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadBrush_ReplacesBufferWithRequestedSize()
|
||||
{
|
||||
using var engine = CreateEngine();
|
||||
var ctx = NewContext();
|
||||
|
||||
string? capturedName = null;
|
||||
double capturedW = -1, capturedH = -1;
|
||||
var rendered = new byte[8 * 5 * 4];
|
||||
ctx.BrushImageLoader = (name, w, h, _) =>
|
||||
{
|
||||
capturedName = name;
|
||||
capturedW = w;
|
||||
capturedH = h;
|
||||
return (rendered, 8, 5);
|
||||
};
|
||||
|
||||
engine.Execute("obj.load('brush', '縞模様', 8, 5); obj.x = obj.w; obj.y = obj.h", ctx);
|
||||
|
||||
Assert.Equal("縞模様", capturedName);
|
||||
Assert.Equal(8d, capturedW);
|
||||
Assert.Equal(5d, capturedH);
|
||||
Assert.True(ctx.BufferReplaced);
|
||||
Assert.Same(rendered, ctx.GetPixelBuffer());
|
||||
Assert.Equal(8d, ctx.X);
|
||||
Assert.Equal(5d, ctx.Y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadBrush_DefaultsSizeToObjectDimensions()
|
||||
{
|
||||
using var engine = CreateEngine();
|
||||
var ctx = NewContext();
|
||||
|
||||
double capturedW = -1, capturedH = -1;
|
||||
ctx.BrushImageLoader = (_, w, h, _) =>
|
||||
{
|
||||
capturedW = w;
|
||||
capturedH = h;
|
||||
return ([], 0, 0);
|
||||
};
|
||||
|
||||
engine.Execute("obj.load('brush', '市松模様')", ctx);
|
||||
|
||||
Assert.Equal(6d, capturedW);
|
||||
Assert.Equal(4d, capturedH);
|
||||
Assert.False(ctx.BufferReplaced);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Brush_PassesParameterPairs()
|
||||
{
|
||||
using var engine = CreateEngine();
|
||||
var ctx = NewContext();
|
||||
|
||||
string? capturedName = null;
|
||||
double capturedW = -1, capturedH = -1;
|
||||
List<KeyValuePair<string, object>>? captured = null;
|
||||
var rendered = new byte[6 * 4 * 4];
|
||||
ctx.BrushImageLoader = (name, w, h, arguments) =>
|
||||
{
|
||||
capturedName = name;
|
||||
capturedW = w;
|
||||
capturedH = h;
|
||||
captured = [.. arguments];
|
||||
return (rendered, 6, 4);
|
||||
};
|
||||
|
||||
engine.Execute("obj.brush('縞模様', '色1', 0xff0000, 'ズーム', 250, '有効', true, 'ラベル', 'abc')", ctx);
|
||||
|
||||
Assert.Equal("縞模様", capturedName);
|
||||
Assert.Equal(6d, capturedW);
|
||||
Assert.Equal(4d, capturedH);
|
||||
Assert.NotNull(captured);
|
||||
Assert.Equal(4, captured!.Count);
|
||||
Assert.Equal(new KeyValuePair<string, object>("色1", (double)0xff0000), captured[0]);
|
||||
Assert.Equal(new KeyValuePair<string, object>("ズーム", 250d), captured[1]);
|
||||
Assert.Equal(new KeyValuePair<string, object>("有効", true), captured[2]);
|
||||
Assert.Equal(new KeyValuePair<string, object>("ラベル", "abc"), captured[3]);
|
||||
Assert.True(ctx.BufferReplaced);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Brush_AcceptsLeadingSizeBeforePairs()
|
||||
{
|
||||
using var engine = CreateEngine();
|
||||
var ctx = NewContext();
|
||||
|
||||
double capturedW = -1, capturedH = -1;
|
||||
List<KeyValuePair<string, object>>? captured = null;
|
||||
ctx.BrushImageLoader = (_, w, h, arguments) =>
|
||||
{
|
||||
capturedW = w;
|
||||
capturedH = h;
|
||||
captured = [.. arguments];
|
||||
return ([], 0, 0);
|
||||
};
|
||||
|
||||
engine.Execute("obj.brush('市松模様', 320, 240, 'ズーム', 50)", ctx);
|
||||
|
||||
Assert.Equal(320d, capturedW);
|
||||
Assert.Equal(240d, capturedH);
|
||||
Assert.NotNull(captured);
|
||||
Assert.Equal(new KeyValuePair<string, object>("ズーム", 50d), Assert.Single(captured!));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Brush_WithoutPairs_UsesObjectDimensions()
|
||||
{
|
||||
using var engine = CreateEngine();
|
||||
var ctx = NewContext();
|
||||
|
||||
double capturedW = -1, capturedH = -1;
|
||||
int capturedCount = -1;
|
||||
ctx.BrushImageLoader = (_, w, h, arguments) =>
|
||||
{
|
||||
capturedW = w;
|
||||
capturedH = h;
|
||||
capturedCount = arguments.Count;
|
||||
return ([], 0, 0);
|
||||
};
|
||||
|
||||
engine.Execute("obj.brush('市松模様')", ctx);
|
||||
|
||||
Assert.Equal(6d, capturedW);
|
||||
Assert.Equal(4d, capturedH);
|
||||
Assert.Equal(0, capturedCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadBrush_FailureKeepsCurrentImage()
|
||||
{
|
||||
using var engine = CreateEngine();
|
||||
var ctx = NewContext();
|
||||
|
||||
ctx.BrushImageLoader = (_, _, _, _) => ([], 0, 0);
|
||||
|
||||
engine.Execute("obj.load('brush', '不明'); obj.x = obj.w; obj.y = obj.h", ctx);
|
||||
|
||||
Assert.False(ctx.BufferReplaced);
|
||||
Assert.Equal(6d, ctx.X);
|
||||
Assert.Equal(4d, ctx.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ namespace LuaScript.Tests
|
||||
|
||||
private readonly LuaJitWorker _worker = new(NativeDir, ScriptPath);
|
||||
|
||||
private Func<string, double, (byte[] buffer, int w, int h)> _loadScene = (_, _) => ([], 0, 0);
|
||||
private Func<string, double, double, System.Collections.Generic.IReadOnlyList<System.Collections.Generic.KeyValuePair<string, object>>, (byte[] buffer, int w, int h)> _loadBrush = (_, _, _, _) => ([], 0, 0);
|
||||
private Func<string, SceneValue> _sceneGet = _ => SceneValue.Nil;
|
||||
private Action<string, SceneValue> _sceneSet = (_, _) => { };
|
||||
private PixelShaderInvoke? _runPixelShader;
|
||||
@@ -70,7 +72,7 @@ namespace LuaScript.Tests
|
||||
System.Runtime.InteropServices.Marshal.Copy(uploaded, 0, address, uploaded.Length);
|
||||
},
|
||||
width, height, timeoutMs,
|
||||
resolveObject, loadFigure, loadText, loadImage, loadMovie, addEffect, addDraw, setAnchor,
|
||||
resolveObject, loadFigure, loadText, loadImage, loadMovie, _loadScene, _loadBrush, addEffect, addDraw, setAnchor,
|
||||
_sceneGet, _sceneSet,
|
||||
_runPixelShader,
|
||||
out pixelsDirty, out bufferReplaced, out resultWidth, out resultHeight, out error);
|
||||
@@ -106,7 +108,7 @@ namespace LuaScript.Tests
|
||||
observedCapacity = capacity;
|
||||
System.Runtime.InteropServices.Marshal.Copy(pixels, 0, address, pixels.Length);
|
||||
},
|
||||
w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
|
||||
w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, _loadScene, _loadBrush, NoAddEffect, NoAddDraw, NoSetAnchor,
|
||||
_sceneGet, _sceneSet,
|
||||
_runPixelShader,
|
||||
out _, out _, out _, out _, out string? error);
|
||||
@@ -1027,6 +1029,215 @@ namespace LuaScript.Tests
|
||||
Assert.Equal(frame, newPixels!.AsSpan(0, frame.Length).ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadScene_RoundTripsNameAndTime()
|
||||
{
|
||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
||||
|
||||
const int sw = 2, sh = 2;
|
||||
var rendered = new byte[sw * sh * 4];
|
||||
for (int i = 0; i < rendered.Length; i++)
|
||||
rendered[i] = (byte)((i * 13 + 1) & 0xFF);
|
||||
|
||||
string? capturedName = null;
|
||||
double capturedTime = -1;
|
||||
_loadScene = (name, time) =>
|
||||
{
|
||||
capturedName = name;
|
||||
capturedTime = time;
|
||||
return (rendered, sw, sh);
|
||||
};
|
||||
|
||||
var pixels = new byte[4 * 4 * 4];
|
||||
var fields = Fields(4, 4, 0d);
|
||||
|
||||
bool ok = RunWorker(
|
||||
"obj.load('scene', 'サブシーン', 2.5)",
|
||||
fields, NoStringParams, () => pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
|
||||
out bool dirty, out bool bufferReplaced, out byte[]? newPixels, out int rw, out int rh, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal("サブシーン", capturedName);
|
||||
Assert.Equal(2.5d, capturedTime);
|
||||
Assert.True(dirty);
|
||||
Assert.True(bufferReplaced);
|
||||
Assert.Equal(sw, rw);
|
||||
Assert.Equal(sh, rh);
|
||||
Assert.NotNull(newPixels);
|
||||
Assert.Equal(rendered, newPixels!.AsSpan(0, rendered.Length).ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadScene_DefaultsTimeToObjTime_AndKeepsImageOnFailure()
|
||||
{
|
||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
||||
|
||||
double capturedTime = -1;
|
||||
_loadScene = (_, time) =>
|
||||
{
|
||||
capturedTime = time;
|
||||
return ([], 0, 0);
|
||||
};
|
||||
|
||||
var pixels = new byte[16];
|
||||
var fields = Fields(2, 2, 1.25d);
|
||||
|
||||
bool ok = RunWorker(
|
||||
"obj.load('scene', 'missing') obj.x = obj.w",
|
||||
fields, NoStringParams, () => pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
|
||||
out bool dirty, out bool bufferReplaced, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(1.25d, capturedTime);
|
||||
Assert.False(dirty);
|
||||
Assert.False(bufferReplaced);
|
||||
Assert.Equal(2d, fields[NativeProtocol.X]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadBrush_RoundTripsNameAndSize()
|
||||
{
|
||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
||||
|
||||
const int bw = 3, bh = 2;
|
||||
var rendered = new byte[bw * bh * 4];
|
||||
for (int i = 0; i < rendered.Length; i++)
|
||||
rendered[i] = (byte)((i * 11 + 2) & 0xFF);
|
||||
|
||||
string? capturedName = null;
|
||||
double capturedW = -1, capturedH = -1;
|
||||
_loadBrush = (name, w, h, _) =>
|
||||
{
|
||||
capturedName = name;
|
||||
capturedW = w;
|
||||
capturedH = h;
|
||||
return (rendered, bw, bh);
|
||||
};
|
||||
|
||||
var pixels = new byte[4 * 4 * 4];
|
||||
var fields = Fields(4, 4, 0d);
|
||||
|
||||
bool ok = RunWorker(
|
||||
"obj.load('brush', '縞模様', 3, 2)",
|
||||
fields, NoStringParams, () => pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
|
||||
out bool dirty, out bool bufferReplaced, out byte[]? newPixels, out int rw, out int rh, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal("縞模様", capturedName);
|
||||
Assert.Equal(3d, capturedW);
|
||||
Assert.Equal(2d, capturedH);
|
||||
Assert.True(dirty);
|
||||
Assert.True(bufferReplaced);
|
||||
Assert.Equal(bw, rw);
|
||||
Assert.Equal(bh, rh);
|
||||
Assert.NotNull(newPixels);
|
||||
Assert.Equal(rendered, newPixels!.AsSpan(0, rendered.Length).ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Brush_RoundTripsPairsAndDefaultSize()
|
||||
{
|
||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
||||
|
||||
const int bw = 2, bh = 2;
|
||||
var rendered = new byte[bw * bh * 4];
|
||||
for (int i = 0; i < rendered.Length; i++)
|
||||
rendered[i] = (byte)((i * 7 + 4) & 0xFF);
|
||||
|
||||
string? capturedName = null;
|
||||
double capturedW = -1, capturedH = -1;
|
||||
System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<string, object>>? captured = null;
|
||||
_loadBrush = (name, w, h, arguments) =>
|
||||
{
|
||||
capturedName = name;
|
||||
capturedW = w;
|
||||
capturedH = h;
|
||||
captured = [.. arguments];
|
||||
return (rendered, bw, bh);
|
||||
};
|
||||
|
||||
var pixels = new byte[4 * 2 * 4];
|
||||
var fields = Fields(4, 2, 0d);
|
||||
|
||||
bool ok = RunWorker(
|
||||
"obj.brush('縞模様', '色1', 0xff0000, '有効', true, 'ラベル', 'abc')",
|
||||
fields, NoStringParams, () => pixels, 4, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
|
||||
out bool dirty, out bool bufferReplaced, out byte[]? newPixels, out int rw, out int rh, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal("縞模様", capturedName);
|
||||
Assert.Equal(4d, capturedW);
|
||||
Assert.Equal(2d, capturedH);
|
||||
Assert.NotNull(captured);
|
||||
Assert.Equal(3, captured!.Count);
|
||||
Assert.Equal(new System.Collections.Generic.KeyValuePair<string, object>("色1", (double)0xff0000), captured[0]);
|
||||
Assert.Equal(new System.Collections.Generic.KeyValuePair<string, object>("有効", true), captured[1]);
|
||||
Assert.Equal(new System.Collections.Generic.KeyValuePair<string, object>("ラベル", "abc"), captured[2]);
|
||||
Assert.True(dirty);
|
||||
Assert.True(bufferReplaced);
|
||||
Assert.Equal(bw, rw);
|
||||
Assert.Equal(bh, rh);
|
||||
Assert.NotNull(newPixels);
|
||||
Assert.Equal(rendered, newPixels!.AsSpan(0, rendered.Length).ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Brush_RoundTripsLeadingSize()
|
||||
{
|
||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
||||
|
||||
double capturedW = -1, capturedH = -1;
|
||||
int capturedCount = -1;
|
||||
_loadBrush = (_, w, h, arguments) =>
|
||||
{
|
||||
capturedW = w;
|
||||
capturedH = h;
|
||||
capturedCount = arguments.Count;
|
||||
return ([], 0, 0);
|
||||
};
|
||||
|
||||
var pixels = new byte[16];
|
||||
var fields = Fields(2, 2, 0d);
|
||||
|
||||
bool ok = RunWorker(
|
||||
"obj.brush('市松模様', 320, 240, 'ズーム', 50)",
|
||||
fields, NoStringParams, () => pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
|
||||
out bool dirty, out _, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(320d, capturedW);
|
||||
Assert.Equal(240d, capturedH);
|
||||
Assert.Equal(1, capturedCount);
|
||||
Assert.False(dirty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadBrush_DefaultsSizeToObjectDimensions()
|
||||
{
|
||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
||||
|
||||
double capturedW = -1, capturedH = -1;
|
||||
_loadBrush = (_, w, h, _) =>
|
||||
{
|
||||
capturedW = w;
|
||||
capturedH = h;
|
||||
return ([], 0, 0);
|
||||
};
|
||||
|
||||
var pixels = new byte[4 * 2 * 4];
|
||||
var fields = Fields(4, 2, 0d);
|
||||
|
||||
bool ok = RunWorker(
|
||||
"obj.load('brush', '市松模様')",
|
||||
fields, NoStringParams, () => pixels, 4, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
|
||||
out bool dirty, out _, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(4d, capturedW);
|
||||
Assert.Equal(2d, capturedH);
|
||||
Assert.False(dirty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetValue_ReturnsObjFields()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
using YukkuriMovieMaker.Commons;
|
||||
using YukkuriMovieMaker.Player.Video;
|
||||
using YukkuriMovieMaker.Plugin.Brush;
|
||||
|
||||
namespace LuaScript
|
||||
{
|
||||
internal sealed class BrushImageRenderer(IGraphicsDevicesAndContext devices) : IDisposable
|
||||
{
|
||||
private const int MaxDimension = 8192;
|
||||
|
||||
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,
|
||||
IReadOnlyList<KeyValuePair<string, object>> arguments,
|
||||
out byte[] pixels,
|
||||
out int outWidth,
|
||||
out int outHeight)
|
||||
{
|
||||
pixels = [];
|
||||
outWidth = 0;
|
||||
outHeight = 0;
|
||||
|
||||
if (width <= 0 || height <= 0 || width > MaxDimension || height > MaxDimension)
|
||||
return false;
|
||||
|
||||
if (!_sources.TryGetValue(name, out var entry))
|
||||
{
|
||||
entry = CreateEntry(name);
|
||||
_sources[name] = entry;
|
||||
}
|
||||
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
|
||||
{
|
||||
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(entry.Source.Brush, width, height);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_sources.Remove(name);
|
||||
entry.Source.Dispose();
|
||||
pixels = [];
|
||||
return false;
|
||||
}
|
||||
|
||||
outWidth = width;
|
||||
outHeight = height;
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
var parameter = plugin.CreateBrushParameter();
|
||||
return new Entry(parameter, parameter.CreateBrush(_ctx));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var entry in _sources.Values)
|
||||
entry?.Source.Dispose();
|
||||
_sources.Clear();
|
||||
_pixels?.Dispose();
|
||||
_ctx?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,32 @@ namespace LuaScript
|
||||
{
|
||||
EnsureBitmaps(width, height);
|
||||
RenderToStaging(input, bounds);
|
||||
return ReadStagingPixels(width, height);
|
||||
}
|
||||
|
||||
public byte[] LoadBrushPixels(ID2D1Brush brush, int width, int height)
|
||||
{
|
||||
EnsureBitmaps(width, height);
|
||||
|
||||
var dc = _ctx.DeviceContext;
|
||||
var rt = (ID2D1RenderTarget)dc;
|
||||
using var savedTarget = dc.Target;
|
||||
|
||||
dc.Target = _renderTarget;
|
||||
dc.BeginDraw();
|
||||
dc.Clear(null);
|
||||
rt.Transform = Matrix3x2.CreateTranslation(width / 2f, height / 2f);
|
||||
rt.FillRectangle(new RawRectF(-width / 2f, -height / 2f, width / 2f, height / 2f), brush);
|
||||
rt.Transform = Matrix3x2.Identity;
|
||||
dc.EndDraw();
|
||||
dc.Target = savedTarget;
|
||||
|
||||
_stagingBitmap!.CopyFromBitmap(_renderTarget!);
|
||||
return ReadStagingPixels(width, height);
|
||||
}
|
||||
|
||||
private unsafe byte[] ReadStagingPixels(int width, int height)
|
||||
{
|
||||
var mapped = _stagingBitmap!.Map(MapOptions.Read);
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Windows.Media;
|
||||
using Vortice.Direct2D1;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
using YukkuriMovieMaker.Player.Video;
|
||||
@@ -23,11 +19,8 @@ namespace LuaScript
|
||||
public required int RequestIndex;
|
||||
}
|
||||
|
||||
private static readonly AviUtlParameterMapping Identity = new(string.Empty, string.Empty, 1d, 0d);
|
||||
|
||||
private static Dictionary<string, Type>? _typeRegistry;
|
||||
private static Dictionary<string, Type>? _nameRegistry;
|
||||
private static readonly Dictionary<Type, Dictionary<string, PropertyInfo>> _propertyCache = [];
|
||||
|
||||
private readonly IGraphicsDevicesAndContext _devices;
|
||||
private readonly List<Node> _nodes = [];
|
||||
@@ -190,34 +183,29 @@ namespace LuaScript
|
||||
map.TryAdd(Normalize(key), type);
|
||||
}
|
||||
|
||||
private static string Normalize(string value) => value.Trim().ToLowerInvariant();
|
||||
private static string Normalize(string value) => Ymm4PropertyBinder.Normalize(value);
|
||||
|
||||
private static void ApplyParameters(IVideoEffect model, AviUtlEffectMapping? mapping, IReadOnlyList<KeyValuePair<string, object>> arguments)
|
||||
{
|
||||
if (arguments.Count == 0)
|
||||
return;
|
||||
|
||||
var properties = GetProperties(model.GetType());
|
||||
if (mapping is null)
|
||||
{
|
||||
Ymm4PropertyBinder.ApplyArguments(model, arguments);
|
||||
return;
|
||||
}
|
||||
|
||||
var properties = Ymm4PropertyBinder.GetProperties(model.GetType());
|
||||
foreach (var (key, value) in arguments)
|
||||
{
|
||||
PropertyInfo? property;
|
||||
AviUtlParameterMapping parameter;
|
||||
if (mapping is not null)
|
||||
{
|
||||
if (!mapping.TryGetParameter(key, out parameter) ||
|
||||
!properties.TryGetValue(Normalize(parameter.Property), out property))
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!properties.TryGetValue(Normalize(key), out property))
|
||||
continue;
|
||||
parameter = Identity;
|
||||
}
|
||||
if (!mapping.TryGetParameter(key, out var parameter) ||
|
||||
!properties.TryGetValue(Normalize(parameter.Property), out var property))
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
SetValue(model, property, value, parameter);
|
||||
Ymm4PropertyBinder.SetValue(model, property, value, parameter);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -225,99 +213,6 @@ namespace LuaScript
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<string, PropertyInfo> GetProperties(Type type)
|
||||
{
|
||||
if (_propertyCache.TryGetValue(type, out var cached))
|
||||
return cached;
|
||||
|
||||
var map = new Dictionary<string, PropertyInfo>(StringComparer.Ordinal);
|
||||
foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
||||
{
|
||||
if (property.GetIndexParameters().Length != 0)
|
||||
continue;
|
||||
bool usable = property.PropertyType == typeof(Animation) || property.GetSetMethod() is not null;
|
||||
if (!usable)
|
||||
continue;
|
||||
|
||||
map.TryAdd(Normalize(property.Name), property);
|
||||
try
|
||||
{
|
||||
var display = property.GetCustomAttribute<DisplayAttribute>()?.GetName();
|
||||
if (!string.IsNullOrWhiteSpace(display))
|
||||
map.TryAdd(Normalize(display), property);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
_propertyCache[type] = map;
|
||||
return map;
|
||||
}
|
||||
|
||||
private static void SetValue(IVideoEffect model, PropertyInfo property, object value, AviUtlParameterMapping parameter)
|
||||
{
|
||||
var type = property.PropertyType;
|
||||
|
||||
if (type == typeof(Animation))
|
||||
{
|
||||
if (property.GetValue(model) is Animation animation)
|
||||
animation.CopyFrom(new Animation(parameter.Transform(ToDouble(value))));
|
||||
return;
|
||||
}
|
||||
if (type == typeof(bool))
|
||||
{
|
||||
property.SetValue(model, ToBool(value));
|
||||
return;
|
||||
}
|
||||
if (type.IsEnum)
|
||||
{
|
||||
property.SetValue(model, ToEnum(type, value));
|
||||
return;
|
||||
}
|
||||
if (type == typeof(Color))
|
||||
{
|
||||
property.SetValue(model, ToColor(value));
|
||||
return;
|
||||
}
|
||||
if (type == typeof(double) || type == typeof(float) || type == typeof(int) || type == typeof(long) || type == typeof(short))
|
||||
{
|
||||
property.SetValue(model, Convert.ChangeType(parameter.Transform(ToDouble(value)), type, CultureInfo.InvariantCulture));
|
||||
return;
|
||||
}
|
||||
if (type == typeof(string))
|
||||
property.SetValue(model, value?.ToString());
|
||||
}
|
||||
|
||||
private static double ToDouble(object value) => value switch
|
||||
{
|
||||
double d => d,
|
||||
bool b => b ? 1d : 0d,
|
||||
string s => double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var r) ? r : 0d,
|
||||
_ => 0d,
|
||||
};
|
||||
|
||||
private static bool ToBool(object value) => value switch
|
||||
{
|
||||
bool b => b,
|
||||
double d => d != 0d,
|
||||
string s => s.Equals("true", StringComparison.OrdinalIgnoreCase) || s == "1",
|
||||
_ => false,
|
||||
};
|
||||
|
||||
private static object ToEnum(Type type, object value)
|
||||
{
|
||||
if (value is string s && Enum.TryParse(type, s, true, out var parsed))
|
||||
return parsed;
|
||||
return Enum.ToObject(type, (int)ToDouble(value));
|
||||
}
|
||||
|
||||
private static Color ToColor(object value)
|
||||
{
|
||||
int rgb = (int)ToDouble(value);
|
||||
return Color.FromRgb((byte)((rgb >> 16) & 0xFF), (byte)((rgb >> 8) & 0xFF), (byte)(rgb & 0xFF));
|
||||
}
|
||||
|
||||
private void DisposeNodes()
|
||||
{
|
||||
foreach (var node in _nodes)
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Windows.Media;
|
||||
using LuaScript.Compat;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
|
||||
namespace LuaScript
|
||||
{
|
||||
internal static class Ymm4PropertyBinder
|
||||
{
|
||||
public static readonly AviUtlParameterMapping Identity = new(string.Empty, string.Empty, 1d, 0d);
|
||||
|
||||
private static readonly Dictionary<Type, Dictionary<string, PropertyInfo>> s_propertyCache = [];
|
||||
|
||||
public static string Normalize(string value) => value.Trim().ToLowerInvariant();
|
||||
|
||||
public static Dictionary<string, PropertyInfo> GetProperties(Type type)
|
||||
{
|
||||
lock (s_propertyCache)
|
||||
{
|
||||
if (s_propertyCache.TryGetValue(type, out var cached))
|
||||
return cached;
|
||||
}
|
||||
|
||||
var map = new Dictionary<string, PropertyInfo>(StringComparer.Ordinal);
|
||||
foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
||||
{
|
||||
if (property.GetIndexParameters().Length != 0)
|
||||
continue;
|
||||
bool usable = property.PropertyType == typeof(Animation) || property.GetSetMethod() is not null;
|
||||
if (!usable)
|
||||
continue;
|
||||
|
||||
map.TryAdd(Normalize(property.Name), property);
|
||||
try
|
||||
{
|
||||
var display = property.GetCustomAttribute<DisplayAttribute>()?.GetName();
|
||||
if (!string.IsNullOrWhiteSpace(display))
|
||||
map.TryAdd(Normalize(display), property);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
lock (s_propertyCache)
|
||||
{
|
||||
s_propertyCache[type] = map;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void ApplyArguments(object model, IReadOnlyList<KeyValuePair<string, object>> arguments)
|
||||
{
|
||||
if (arguments.Count == 0)
|
||||
return;
|
||||
|
||||
var properties = GetProperties(model.GetType());
|
||||
foreach (var (key, value) in arguments)
|
||||
{
|
||||
if (!properties.TryGetValue(Normalize(key), out var property))
|
||||
continue;
|
||||
try
|
||||
{
|
||||
SetValue(model, property, value, Identity);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetValue(object model, PropertyInfo property, object value, AviUtlParameterMapping parameter)
|
||||
{
|
||||
var type = property.PropertyType;
|
||||
|
||||
if (type == typeof(Animation))
|
||||
{
|
||||
if (property.GetValue(model) is Animation animation)
|
||||
animation.CopyFrom(new Animation(parameter.Transform(ToDouble(value))));
|
||||
return;
|
||||
}
|
||||
if (type == typeof(bool))
|
||||
{
|
||||
property.SetValue(model, ToBool(value));
|
||||
return;
|
||||
}
|
||||
if (type.IsEnum)
|
||||
{
|
||||
property.SetValue(model, ToEnum(type, value));
|
||||
return;
|
||||
}
|
||||
if (type == typeof(Color))
|
||||
{
|
||||
property.SetValue(model, ToColor(value));
|
||||
return;
|
||||
}
|
||||
if (type == typeof(double) || type == typeof(float) || type == typeof(int) || type == typeof(long) || type == typeof(short))
|
||||
{
|
||||
property.SetValue(model, Convert.ChangeType(parameter.Transform(ToDouble(value)), type, CultureInfo.InvariantCulture));
|
||||
return;
|
||||
}
|
||||
if (type == typeof(string))
|
||||
property.SetValue(model, value?.ToString());
|
||||
}
|
||||
|
||||
private static double ToDouble(object value) => value switch
|
||||
{
|
||||
double d => d,
|
||||
bool b => b ? 1d : 0d,
|
||||
string s => double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var r) ? r : 0d,
|
||||
_ => 0d,
|
||||
};
|
||||
|
||||
private static bool ToBool(object value) => value switch
|
||||
{
|
||||
bool b => b,
|
||||
double d => d != 0d,
|
||||
string s => s.Equals("true", StringComparison.OrdinalIgnoreCase) || s == "1",
|
||||
_ => false,
|
||||
};
|
||||
|
||||
private static object ToEnum(Type type, object value)
|
||||
{
|
||||
if (value is string s && Enum.TryParse(type, s, true, out var parsed))
|
||||
return parsed;
|
||||
return Enum.ToObject(type, (int)ToDouble(value));
|
||||
}
|
||||
|
||||
private static Color ToColor(object value)
|
||||
{
|
||||
int rgb = (int)ToDouble(value);
|
||||
return Color.FromRgb((byte)((rgb >> 16) & 0xFF), (byte)((rgb >> 8) & 0xFF), (byte)(rgb & 0xFF));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,6 +138,11 @@ namespace LuaScript
|
||||
private Func<string, string, double, bool, bool, int, (byte[] buffer, int w, int h)>? _nativeLoadText;
|
||||
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, IReadOnlyList<KeyValuePair<string, object>>, (byte[] Buffer, int Width, int Height)>? _loadBrushImage;
|
||||
private SceneImageRenderer? _sceneImageRenderer;
|
||||
private BrushImageRenderer? _brushImageRenderer;
|
||||
private bool _sceneImageLoaded;
|
||||
private Action<string, IReadOnlyList<KeyValuePair<string, object>>>? _nativeAddEffect;
|
||||
private Action<DrawCommand>? _nativeAddDraw;
|
||||
private Action<string, int, bool, int, double[]>? _nativeSetAnchor;
|
||||
@@ -182,6 +187,8 @@ namespace LuaScript
|
||||
_pixelShaderRunner = new PixelShaderRunner { Compositor = _bufferCompositor };
|
||||
_context.ResolverProvider = GetFrameResolver;
|
||||
_context.Compositor = _bufferCompositor;
|
||||
_context.SceneImageLoader = _loadSceneImage ??= LoadSceneImage;
|
||||
_context.BrushImageLoader = _loadBrushImage ??= LoadBrushImage;
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -193,6 +200,8 @@ namespace LuaScript
|
||||
var context = new AviUtlScriptContext { ResolverProvider = GetFrameResolver };
|
||||
if (_bufferCompositor is not null)
|
||||
context.Compositor = _bufferCompositor;
|
||||
context.SceneImageLoader = _loadSceneImage ??= LoadSceneImage;
|
||||
context.BrushImageLoader = _loadBrushImage ??= LoadBrushImage;
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -469,6 +478,11 @@ namespace LuaScript
|
||||
LuaScriptDiagnostics.Instance.Report(script, diagnostics);
|
||||
|
||||
_isFirst = false;
|
||||
if (_sceneImageLoaded)
|
||||
{
|
||||
_sceneImageLoaded = false;
|
||||
_isFirst = true;
|
||||
}
|
||||
_cachedKey = key;
|
||||
_cachedQueries = SnapshotQueries(ctx.ObjectQueries, _cachedQueries);
|
||||
_cachedSceneValueQueries = SnapshotQueries(ctx.SceneValueQueries, _cachedSceneValueQueries);
|
||||
@@ -981,6 +995,8 @@ namespace LuaScript
|
||||
_nativeLoadText ??= NativeLoadText;
|
||||
_nativeLoadImage ??= NativeLoadImage;
|
||||
_nativeLoadMovie ??= NativeLoadMovie;
|
||||
_loadSceneImage ??= LoadSceneImage;
|
||||
_loadBrushImage ??= LoadBrushImage;
|
||||
_nativeAddEffect ??= (name, args) => _context.AddEffect(new AviUtlEffectRequest(name, args));
|
||||
_nativeAddDraw ??= command => _context.AddDraw(command);
|
||||
_nativeSetAnchor ??= ResolveNativeAnchor;
|
||||
@@ -998,6 +1014,8 @@ namespace LuaScript
|
||||
_nativeLoadText,
|
||||
_nativeLoadImage,
|
||||
_nativeLoadMovie,
|
||||
_loadSceneImage,
|
||||
_loadBrushImage,
|
||||
_nativeAddEffect,
|
||||
_nativeAddDraw,
|
||||
_nativeSetAnchor,
|
||||
@@ -1152,6 +1170,54 @@ namespace LuaScript
|
||||
return (buffer, w, h);
|
||||
}
|
||||
|
||||
private static readonly (byte[] Buffer, int Width, int Height) s_noLoadedImage = ([], 0, 0);
|
||||
|
||||
private (byte[] Buffer, int Width, int Height) LoadSceneImage(string name, double time)
|
||||
{
|
||||
var desc = _frameDesc;
|
||||
var devices = _hostDevices;
|
||||
if (desc is null || devices is null)
|
||||
return s_noLoadedImage;
|
||||
|
||||
_pixelLoaderSemaphore.Wait();
|
||||
try
|
||||
{
|
||||
_sceneImageRenderer ??= new SceneImageRenderer(devices);
|
||||
if (!_sceneImageRenderer.TryRender(desc, name, time, out var pixels, out int width, out int height))
|
||||
return s_noLoadedImage;
|
||||
_sceneImageLoaded = true;
|
||||
return (pixels, width, height);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_pixelLoaderSemaphore.Release();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
if (desc is null || devices is null)
|
||||
return s_noLoadedImage;
|
||||
|
||||
int w = (int)Math.Round(width);
|
||||
int h = (int)Math.Round(height);
|
||||
|
||||
_pixelLoaderSemaphore.Wait();
|
||||
try
|
||||
{
|
||||
_brushImageRenderer ??= new BrushImageRenderer(devices);
|
||||
if (!_brushImageRenderer.TryRender(desc, name, w, h, arguments, out var pixels, out int outWidth, out int outHeight))
|
||||
return s_noLoadedImage;
|
||||
return (pixels, outWidth, outHeight);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_pixelLoaderSemaphore.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private (byte[] buffer, int w, int h) NativeLoadMovie(string path, double time)
|
||||
{
|
||||
_nativeMovieDecoder ??= new MovieDecoder();
|
||||
@@ -1199,6 +1265,8 @@ namespace LuaScript
|
||||
_bufferCompositor?.Dispose();
|
||||
_nativeTextRenderer?.Dispose();
|
||||
_nativeImageDecoder?.Dispose();
|
||||
_sceneImageRenderer?.Dispose();
|
||||
_brushImageRenderer?.Dispose();
|
||||
_pixelLoaderSemaphore.Dispose();
|
||||
_pixelManager?.Dispose();
|
||||
_pixelManager = null;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.16.3</Version>
|
||||
<Version>1.17.0</Version>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
using Vortice;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
using YukkuriMovieMaker.Player.Video;
|
||||
|
||||
namespace LuaScript
|
||||
{
|
||||
internal sealed class SceneImageRenderer(IGraphicsDevicesAndContext devices) : IDisposable
|
||||
{
|
||||
[ThreadStatic]
|
||||
private static bool t_rendering;
|
||||
|
||||
private readonly Dictionary<Guid, ITimelineSource> _sources = [];
|
||||
private GraphicsDevicesAndContext? _ctx;
|
||||
private PixelBufferManager? _pixels;
|
||||
|
||||
public bool TryRender(EffectDescription desc, string name, double time, out byte[] pixels, out int width, out int height)
|
||||
{
|
||||
pixels = [];
|
||||
width = 0;
|
||||
height = 0;
|
||||
|
||||
if (t_rendering)
|
||||
return false;
|
||||
|
||||
var info = FindScene(desc, name);
|
||||
if (info is null)
|
||||
return false;
|
||||
|
||||
_ctx ??= new GraphicsDevicesAndContext(devices);
|
||||
if (!_sources.TryGetValue(info.ID, out var source))
|
||||
{
|
||||
if (!info.TryCreateVideoSource(_ctx, out source))
|
||||
return false;
|
||||
_sources[info.ID] = source;
|
||||
}
|
||||
|
||||
int w = Math.Max(1, info.Width);
|
||||
int h = Math.Max(1, info.Height);
|
||||
|
||||
t_rendering = true;
|
||||
try
|
||||
{
|
||||
source.Update(TimeSpan.FromSeconds(time), desc.Usage);
|
||||
_pixels ??= new PixelBufferManager(_ctx);
|
||||
pixels = _pixels.LoadInputPixels(source.Output, new RawRectF(-w / 2f, -h / 2f, w / 2f, h / 2f), w, h);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_sources.Remove(info.ID);
|
||||
source.Dispose();
|
||||
pixels = [];
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
t_rendering = false;
|
||||
}
|
||||
|
||||
width = w;
|
||||
height = h;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static ISceneInfo? FindScene(EffectDescription desc, string name)
|
||||
{
|
||||
foreach (var info in desc.Scenes)
|
||||
{
|
||||
if (info.ID != desc.SceneId && string.Equals(info.Name, name, StringComparison.Ordinal))
|
||||
return info;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var source in _sources.Values)
|
||||
source.Dispose();
|
||||
_sources.Clear();
|
||||
_pixels?.Dispose();
|
||||
_ctx?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -451,9 +451,11 @@
|
||||
|
||||
○ obj.load(الهدف، ...)
|
||||
يستبدل مخزن الكائن بمحتوى مُولَّد. تُدعم الأهداف "figure" و"text"
|
||||
و"image" (ملف صورة) و"movie" (ملف فيديو). بعد التحميل تُحدَّث
|
||||
و"image" (ملف صورة) و"movie" (ملف فيديو) و"scene" (مشهد المشروع)
|
||||
و"brush" (نمط YMM4). بعد التحميل تُحدَّث
|
||||
obj.w / obj.h وغيرها إلى الحجم المُولَّد، ويمكن قراءتها بـ getpixel
|
||||
مباشرة بعد التحميل. يعمل على محرك MoonSharp والمحرك السريع (LuaJIT).
|
||||
※ "scene" و"brush" امتدادان خاصان بـ YMM4 لا وجود لهما في AviUtl.
|
||||
|
||||
obj.load("figure", name, color, size [, line [, aspect]])
|
||||
يُولّد شكلاً ويستبدل المخزن (متوسَّطاً).
|
||||
@@ -485,6 +487,42 @@
|
||||
الفيديو الأصلية (MP4 / MOV / MKV / WebM / AVI / FLV / ASF).
|
||||
مثال: obj.load("movie", "C:\\mov\\clip.mp4", obj.time)
|
||||
|
||||
obj.load("scene", sceneName [, time])
|
||||
يرسم مشهداً آخر من المشروع ويستبدل المخزن.
|
||||
sceneName : الاسم الظاهر في قائمة المشاهد.
|
||||
time : بالثواني. الافتراضي obj.time عند الحذف.
|
||||
※ لا يمكن تحديد المشهد الذي يقع عليه الكائن الحالي، كما
|
||||
يُرفض تحميل مشهد من داخل رسم مشهد آخر.
|
||||
※ الإطارات التي تُحمِّل مشهداً تتجاوز ذاكرة التخزين المؤقت
|
||||
للرسم ويُعاد تنفيذها في كل مرة.
|
||||
مثال: obj.load("scene", "مشهد فرعي", obj.time)
|
||||
|
||||
obj.load("brush", patternName [, width [, height]])
|
||||
يُولّد صورة مملوءة بنمط (فرشاة) من YMM4 ويستبدل المخزن.
|
||||
يمكن أيضاً استخدام الأنماط المضافة عبر إضافات الفرش.
|
||||
patternName : الاسم الظاهر في قائمة الأنماط.
|
||||
width, height : حجم الإخراج بالبكسل. الافتراضي
|
||||
obj.w / obj.h الحاليان عند الحذف.
|
||||
※ يُرسم النمط بمعاملاته الافتراضية.
|
||||
مثال: obj.load("brush", "خطوط", 400, 300)
|
||||
|
||||
○ obj.brush(patternName [, width, height] [, paramName, value, ...])
|
||||
يرسم نمطاً (فرشاة) من YMM4 مع تحديد المعاملات ويستبدل المخزن.
|
||||
الرسم مطابق لـ obj.load("brush")، ويمكن إضافة إلى ذلك تغيير
|
||||
معاملات النمط بأزواج الاسم والقيمة نفسها المستخدمة في obj.effect.
|
||||
patternName : الاسم الظاهر في قائمة الأنماط.
|
||||
width, height : حجم الإخراج بالبكسل. الافتراضي obj.w / obj.h
|
||||
الحاليان. يُفسَّران كحجم فقط عندما يُعطى كلاهما
|
||||
كرقمين.
|
||||
paramName : الاسم الظاهر لإعداد النمط، أو اسم الخاصية
|
||||
الداخلي.
|
||||
value : رقم أو قيمة منطقية أو نص. الألوان أرقام بصيغة
|
||||
0xRRGGBB.
|
||||
※ المعاملات غير المحددة تُرسم بقيمها الافتراضية. الاستدعاء بلا
|
||||
أزواج يعادل obj.load("brush").
|
||||
※ هذا امتداد خاص بـ YMM4 لا وجود له في AviUtl.
|
||||
مثال: obj.brush("خطوط", "Angle", 45, "Color1", 0xff3366)
|
||||
|
||||
○ obj.setfont(font [, size [, style [, color]]])
|
||||
يحدد الخط المستخدم في obj.load("text").
|
||||
style : أعلام بِتّية. 1=عريض، 2=مائل، 3=عريض+مائل.
|
||||
|
||||
@@ -463,10 +463,13 @@
|
||||
|
||||
o obj.load(target, ...)
|
||||
Replaces the object buffer with generated content. The targets
|
||||
"figure", "text", "image" (image file) and "movie" (video file)
|
||||
are supported. After loading, obj.w / obj.h, etc. are updated to the
|
||||
"figure", "text", "image" (image file), "movie" (video file),
|
||||
"scene" (project scene) and "brush" (YMM4 pattern) are supported.
|
||||
After loading, obj.w / obj.h, etc. are updated to the
|
||||
generated size and can be read by getpixel right after the load.
|
||||
Works on both the MoonSharp and the fast (LuaJIT) engine.
|
||||
* "scene" and "brush" are YMM4-only extensions that do not exist
|
||||
in AviUtl.
|
||||
|
||||
obj.load("figure", name, color, size [, line [, aspect]])
|
||||
Generates a shape and replaces the buffer (centered).
|
||||
@@ -498,6 +501,44 @@
|
||||
videos (MP4 / MOV / MKV / WebM / AVI / FLV / ASF) are loaded.
|
||||
Example: obj.load("movie", "C:\\mov\\clip.mp4", obj.time)
|
||||
|
||||
obj.load("scene", sceneName [, time])
|
||||
Renders another scene of the project and replaces the buffer.
|
||||
sceneName : The name shown in the scene list.
|
||||
time : Seconds. Defaults to obj.time when omitted.
|
||||
* The scene the current object belongs to cannot be specified.
|
||||
Loading a scene from inside a scene render is also rejected.
|
||||
* Frames that load a scene bypass the render cache and are
|
||||
re-executed every time.
|
||||
Example: obj.load("scene", "Sub Scene", obj.time)
|
||||
|
||||
obj.load("brush", patternName [, width [, height]])
|
||||
Generates an image filled with a YMM4 pattern (brush) and
|
||||
replaces the buffer. Patterns added by brush plugins can
|
||||
also be used.
|
||||
patternName : The name shown in the pattern list.
|
||||
width, height : Output size in pixels. Defaults to the
|
||||
current obj.w / obj.h when omitted.
|
||||
* The pattern is drawn with its default parameters.
|
||||
Example: obj.load("brush", "Stripe", 400, 300)
|
||||
|
||||
o obj.brush(patternName [, width, height] [, paramName, value, ...])
|
||||
Draws a YMM4 pattern (brush) with parameter overrides and replaces
|
||||
the buffer. The drawing is the same as obj.load("brush"), and in
|
||||
addition the pattern parameters can be changed with the same
|
||||
name-and-value pairs as obj.effect.
|
||||
patternName : The name shown in the pattern list.
|
||||
width, height : Output size in pixels. Defaults to the current
|
||||
obj.w / obj.h. Interpreted as the size only when
|
||||
both are given as numbers.
|
||||
paramName : The display name of a pattern setting, or its
|
||||
internal property name.
|
||||
value : A number, a boolean or a string. Colors are
|
||||
0xRRGGBB numbers.
|
||||
* Parameters that are not specified are drawn with their default
|
||||
values. A call without pairs equals obj.load("brush").
|
||||
* This is a YMM4-only extension that does not exist in AviUtl.
|
||||
Example: obj.brush("Stripe", "Angle", 45, "Color1", 0xff3366)
|
||||
|
||||
o obj.setfont(font [, size [, style [, color]]])
|
||||
Sets the font used by obj.load("text").
|
||||
style : Bit flags. 1=bold, 2=italic, 3=bold+italic.
|
||||
|
||||
@@ -466,10 +466,13 @@
|
||||
|
||||
o obj.load(target, ...)
|
||||
Reemplaza el búfer del objeto con contenido generado. Se admiten los
|
||||
targets "figure", "text", "image" (archivo de imagen) y "movie"
|
||||
(archivo de vídeo). Tras la carga, obj.w / obj.h, etc. se actualizan al
|
||||
targets "figure", "text", "image" (archivo de imagen), "movie"
|
||||
(archivo de vídeo), "scene" (escena del proyecto) y "brush"
|
||||
(patrón de YMM4). Tras la carga, obj.w / obj.h, etc. se actualizan al
|
||||
tamaño generado y pueden leerse con getpixel justo después de la carga.
|
||||
Funciona en el motor MoonSharp y en el motor rápido (LuaJIT).
|
||||
* "scene" y "brush" son extensiones exclusivas de YMM4 que no
|
||||
existen en AviUtl.
|
||||
|
||||
obj.load("figure", name, color, size [, line [, aspect]])
|
||||
Genera una forma y reemplaza el búfer (centrada).
|
||||
@@ -501,6 +504,45 @@
|
||||
vídeos genuinos (MP4 / MOV / MKV / WebM / AVI / FLV / ASF).
|
||||
Ejemplo: obj.load("movie", "C:\\mov\\clip.mp4", obj.time)
|
||||
|
||||
obj.load("scene", nombreEscena [, tiempo])
|
||||
Dibuja otra escena del proyecto y reemplaza el búfer.
|
||||
nombreEscena : El nombre mostrado en la lista de escenas.
|
||||
tiempo : Segundos. Por defecto obj.time.
|
||||
* No se puede indicar la escena a la que pertenece el objeto
|
||||
actual, ni cargar una escena desde dentro del dibujado de
|
||||
otra escena.
|
||||
* Los fotogramas que cargan una escena omiten la caché de
|
||||
dibujado y se vuelven a ejecutar cada vez.
|
||||
Ejemplo: obj.load("scene", "Subescena", obj.time)
|
||||
|
||||
obj.load("brush", nombrePatron [, ancho [, alto]])
|
||||
Genera una imagen rellenada con un patrón (pincel) de YMM4 y
|
||||
reemplaza el búfer. También pueden usarse patrones añadidos
|
||||
por plugins de pincel.
|
||||
nombrePatron : El nombre mostrado en la lista de patrones.
|
||||
ancho, alto : Tamaño generado en píxeles. Por defecto los
|
||||
obj.w / obj.h actuales.
|
||||
* El patrón se dibuja con sus parámetros por defecto.
|
||||
Ejemplo: obj.load("brush", "Rayas", 400, 300)
|
||||
|
||||
o obj.brush(nombrePatron [, ancho, alto] [, nombreParam, valor, ...])
|
||||
Dibuja un patrón (pincel) de YMM4 con parámetros indicados y
|
||||
reemplaza el búfer. El dibujado es el mismo que obj.load("brush"),
|
||||
y además los parámetros del patrón pueden cambiarse con los mismos
|
||||
pares de nombre y valor que obj.effect.
|
||||
nombrePatron : El nombre mostrado en la lista de patrones.
|
||||
ancho, alto : Tamaño generado en píxeles. Por defecto los
|
||||
obj.w / obj.h actuales. Solo se interpreta como
|
||||
tamaño cuando ambos se dan como números.
|
||||
nombreParam : El nombre mostrado de un ajuste del patrón, o su
|
||||
nombre de propiedad interno.
|
||||
valor : Un número, un booleano o una cadena. Los colores
|
||||
son números 0xRRGGBB.
|
||||
* Los parámetros no indicados se dibujan con sus valores por
|
||||
defecto. Una llamada sin pares equivale a obj.load("brush").
|
||||
* Es una extensión exclusiva de YMM4 que no existe en AviUtl.
|
||||
Ejemplo: obj.brush("Rayas", "Angle", 45, "Color1", 0xff3366)
|
||||
|
||||
o obj.setfont(fuente [, tamaño [, estilo [, color]]])
|
||||
Establece la fuente usada por obj.load("text").
|
||||
estilo : Bits. 1=negrita, 2=cursiva, 3=negrita+cursiva.
|
||||
|
||||
@@ -463,10 +463,13 @@
|
||||
|
||||
o obj.load(target, ...)
|
||||
Mengganti buffer objek dengan konten yang dihasilkan. Target "figure",
|
||||
"text", "image" (berkas gambar) dan "movie" (berkas video) didukung.
|
||||
"text", "image" (berkas gambar), "movie" (berkas video), "scene"
|
||||
(adegan proyek) dan "brush" (pola YMM4) didukung.
|
||||
Setelah dimuat, obj.w / obj.h, dll. diperbarui ke ukuran yang
|
||||
dihasilkan dan dapat dibaca oleh getpixel tepat setelah pemuatan.
|
||||
Berfungsi pada mesin MoonSharp maupun mesin cepat (LuaJIT).
|
||||
* "scene" dan "brush" adalah ekstensi khusus YMM4 yang tidak ada
|
||||
di AviUtl.
|
||||
|
||||
obj.load("figure", name, color, size [, line [, aspect]])
|
||||
Menghasilkan bentuk dan mengganti buffer (dipusatkan).
|
||||
@@ -498,6 +501,45 @@
|
||||
(MP4 / MOV / MKV / WebM / AVI / FLV / ASF) yang dimuat.
|
||||
Contoh: obj.load("movie", "C:\\mov\\clip.mp4", obj.time)
|
||||
|
||||
obj.load("scene", namaAdegan [, waktu])
|
||||
Menggambar adegan lain dalam proyek dan mengganti buffer.
|
||||
namaAdegan : Nama yang ditampilkan pada daftar adegan.
|
||||
waktu : Detik. Default obj.time bila dihilangkan.
|
||||
* Adegan tempat objek saat ini berada tidak dapat dipilih,
|
||||
dan memuat adegan dari dalam penggambaran adegan juga
|
||||
ditolak.
|
||||
* Frame yang memuat adegan melewati cache render dan
|
||||
dijalankan ulang setiap kali.
|
||||
Contoh: obj.load("scene", "Sub Adegan", obj.time)
|
||||
|
||||
obj.load("brush", namaPola [, lebar [, tinggi]])
|
||||
Menghasilkan gambar yang diisi pola (kuas) YMM4 dan
|
||||
mengganti buffer. Pola yang ditambahkan oleh plugin kuas
|
||||
juga dapat digunakan.
|
||||
namaPola : Nama yang ditampilkan pada daftar pola.
|
||||
lebar, tinggi : Ukuran keluaran dalam piksel. Default
|
||||
obj.w / obj.h saat ini bila dihilangkan.
|
||||
* Pola digambar dengan parameter default.
|
||||
Contoh: obj.load("brush", "Garis-garis", 400, 300)
|
||||
|
||||
o obj.brush(namaPola [, lebar, tinggi] [, namaParam, nilai, ...])
|
||||
Menggambar pola (kuas) YMM4 dengan parameter yang ditentukan dan
|
||||
mengganti buffer. Penggambarannya sama dengan obj.load("brush"),
|
||||
dan parameter pola dapat diubah dengan pasangan nama dan nilai
|
||||
yang sama seperti obj.effect.
|
||||
namaPola : Nama yang ditampilkan pada daftar pola.
|
||||
lebar, tinggi : Ukuran keluaran dalam piksel. Default
|
||||
obj.w / obj.h saat ini. Hanya ditafsirkan sebagai
|
||||
ukuran bila keduanya diberikan sebagai angka.
|
||||
namaParam : Nama tampilan pengaturan pola, atau nama properti
|
||||
internalnya.
|
||||
nilai : Angka, boolean atau string. Warna adalah angka
|
||||
0xRRGGBB.
|
||||
* Parameter yang tidak ditentukan digambar dengan nilai default.
|
||||
Panggilan tanpa pasangan sama dengan obj.load("brush").
|
||||
* Ini adalah ekstensi khusus YMM4 yang tidak ada di AviUtl.
|
||||
Contoh: obj.brush("Garis-garis", "Angle", 45, "Color1", 0xff3366)
|
||||
|
||||
o obj.setfont(font [, size [, style [, color]]])
|
||||
Mengatur font yang digunakan oleh obj.load("text").
|
||||
style : Flag bit. 1=tebal, 2=miring, 3=tebal+miring.
|
||||
|
||||
@@ -453,9 +453,12 @@
|
||||
○obj.load(対象, ...)
|
||||
オブジェクトのバッファを生成した内容に置き換えます。
|
||||
対象は "figure"(図形) / "text"(テキスト) / "image"(画像ファイル) /
|
||||
"movie"(動画ファイル) に対応します。生成後 obj.w / obj.h 等は生成
|
||||
サイズへ更新され、load 直後の getpixel でも参照できます。
|
||||
"movie"(動画ファイル) / "scene"(シーン) / "brush"(模様) に対応
|
||||
します。生成後 obj.w / obj.h 等は生成サイズへ更新され、load 直後
|
||||
の getpixel でも参照できます。
|
||||
従来エンジン・高速エンジンの両方で動作します。
|
||||
※ "scene" と "brush" は AviUtl に存在しない YMM4 向けの独自拡張
|
||||
です。
|
||||
|
||||
obj.load("figure", 名前, 色, サイズ [, ライン [, アスペクト]])
|
||||
図形を生成してバッファを置き換えます(中心に配置)。
|
||||
@@ -488,6 +491,43 @@
|
||||
読み込みます。
|
||||
例:obj.load("movie", "C:\\mov\\clip.mp4", obj.time)
|
||||
|
||||
obj.load("scene", シーン名 [, 時間])
|
||||
プロジェクト内の別シーンを描画してバッファを置き換えます。
|
||||
シーン名 : シーン一覧に表示される名前。
|
||||
時間 : 秒。省略時は obj.time。
|
||||
※ 現在のオブジェクトが乗っているシーン自身は指定でき
|
||||
ません。シーン描画の中からさらにシーンを読み込むこと
|
||||
もできません。
|
||||
※ シーンを読み込んだフレームは描画キャッシュを使わず
|
||||
毎回再実行されます。
|
||||
例:obj.load("scene", "サブシーン", obj.time)
|
||||
|
||||
obj.load("brush", 模様名 [, 幅 [, 高さ]])
|
||||
YMM4 の模様(ブラシ)で塗り潰した画像を生成してバッファを
|
||||
置き換えます。模様プラグインで追加した模様も使えます。
|
||||
模様名 : 模様一覧に表示される名前(例:縞模様、市松模様)。
|
||||
幅、高さ : 生成サイズ(ピクセル)。省略時は現在の
|
||||
obj.w / obj.h。
|
||||
※ 模様のパラメータは既定値で描画されます。
|
||||
例:obj.load("brush", "縞模様", 400, 300)
|
||||
|
||||
○obj.brush(模様名 [, 幅, 高さ] [, パラメータ名, 値, ...])
|
||||
YMM4 の模様(ブラシ)をパラメータ指定付きで描画してバッファを
|
||||
置き換えます。描画は obj.load("brush") と同じで、加えて
|
||||
obj.effect と同じ「名前と値の組」で模様のパラメータを変更
|
||||
できます。
|
||||
模様名 : 模様一覧に表示される名前。
|
||||
幅、高さ : 生成サイズ(ピクセル)。省略時は現在の
|
||||
obj.w / obj.h。両方を数値で並べたときだけ
|
||||
サイズとして解釈します。
|
||||
パラメータ名 : 模様の設定項目の表示名、または内部の
|
||||
プロパティ名。
|
||||
値 : 数値、真偽値、文字列。色は 0xRRGGBB の数値。
|
||||
※ 指定しなかったパラメータは既定値で描画されます。組を
|
||||
すべて省略した呼び出しは obj.load("brush") と同じです。
|
||||
※ AviUtl に存在しない YMM4 向けの独自拡張です。
|
||||
例:obj.brush("縞模様", "Angle", 45, "Color1", 0xff3366)
|
||||
|
||||
○obj.setfont(フォント名 [, サイズ [, スタイル [, 色]]])
|
||||
obj.load("text") で使用するフォントを設定します。
|
||||
スタイル : ビット和。1=太字, 2=斜体, 3=太字+斜体。
|
||||
|
||||
@@ -448,10 +448,13 @@
|
||||
|
||||
○ obj.load(대상, ...)
|
||||
오브젝트 버퍼를 생성한 내용으로 교체합니다. "figure"(도형) /
|
||||
"text"(텍스트) / "image"(이미지 파일) / "movie"(동영상 파일)를
|
||||
"text"(텍스트) / "image"(이미지 파일) / "movie"(동영상 파일) /
|
||||
"scene"(씬) / "brush"(무늬)를
|
||||
지원합니다. 로드 후 obj.w / obj.h 등은 생성 크기로 갱신되며, 로드
|
||||
직후의 getpixel로도 참조할 수 있습니다. 기존 엔진과 고속 엔진
|
||||
양쪽에서 동작합니다.
|
||||
※ "scene"과 "brush"는 AviUtl에 존재하지 않는 YMM4 전용
|
||||
확장입니다.
|
||||
|
||||
obj.load("figure", 이름, 색, 크기 [, 라인 [, 종횡비]])
|
||||
도형을 생성하여 버퍼를 교체합니다(중심 배치).
|
||||
@@ -483,6 +486,40 @@
|
||||
(MP4 / MOV / MKV / WebM / AVI / FLV / ASF)만 읽습니다.
|
||||
예: obj.load("movie", "C:\\mov\\clip.mp4", obj.time)
|
||||
|
||||
obj.load("scene", 씬이름 [, 시간])
|
||||
프로젝트 안의 다른 씬을 그려 버퍼를 교체합니다.
|
||||
씬이름 : 씬 목록에 표시되는 이름.
|
||||
시간 : 초. 생략 시 obj.time.
|
||||
※ 현재 오브젝트가 놓인 씬 자신은 지정할 수 없으며, 씬
|
||||
그리기 도중에 다시 씬을 로드할 수도 없습니다.
|
||||
※ 씬을 로드한 프레임은 렌더 캐시를 사용하지 않고 매번
|
||||
다시 실행됩니다.
|
||||
예: obj.load("scene", "서브 씬", obj.time)
|
||||
|
||||
obj.load("brush", 무늬이름 [, 너비 [, 높이]])
|
||||
YMM4의 무늬(브러시)로 채운 이미지를 생성하여 버퍼를
|
||||
교체합니다. 브러시 플러그인으로 추가한 무늬도 사용할 수
|
||||
있습니다.
|
||||
무늬이름 : 무늬 목록에 표시되는 이름.
|
||||
너비, 높이 : 생성 크기(픽셀). 생략 시 현재 obj.w / obj.h.
|
||||
※ 무늬는 기본 매개변수로 그려집니다.
|
||||
예: obj.load("brush", "줄무늬", 400, 300)
|
||||
|
||||
○ obj.brush(무늬이름 [, 너비, 높이] [, 매개변수명, 값, ...])
|
||||
YMM4의 무늬(브러시)를 매개변수 지정과 함께 그려 버퍼를
|
||||
교체합니다. 그리기는 obj.load("brush")와 같고, 추가로
|
||||
obj.effect와 같은 「이름과 값의 쌍」으로 무늬의 매개변수를
|
||||
변경할 수 있습니다.
|
||||
무늬이름 : 무늬 목록에 표시되는 이름.
|
||||
너비, 높이 : 생성 크기(픽셀). 생략 시 현재 obj.w / obj.h.
|
||||
둘 다 숫자로 주어졌을 때만 크기로 해석합니다.
|
||||
매개변수명 : 무늬 설정 항목의 표시 이름, 또는 내부 속성 이름.
|
||||
값 : 숫자, 불리언, 문자열. 색은 0xRRGGBB 숫자.
|
||||
※ 지정하지 않은 매개변수는 기본값으로 그려집니다. 쌍을 모두
|
||||
생략한 호출은 obj.load("brush")와 같습니다.
|
||||
※ AviUtl에 존재하지 않는 YMM4 전용 확장입니다.
|
||||
예: obj.brush("줄무늬", "Angle", 45, "Color1", 0xff3366)
|
||||
|
||||
○ obj.setfont(글꼴 [, 크기 [, 스타일 [, 색]]])
|
||||
obj.load("text")에서 사용할 글꼴을 설정합니다.
|
||||
스타일 : 비트 플래그. 1=굵게, 2=기울임, 3=굵게+기울임.
|
||||
|
||||
@@ -439,8 +439,10 @@
|
||||
|
||||
○ obj.load(目标, ...)
|
||||
将对象缓冲区替换为生成的内容。支持 "figure"(图形) / "text"(文本) /
|
||||
"image"(图像文件) / "movie"(视频文件)。加载后 obj.w / obj.h 等会更新为
|
||||
"image"(图像文件) / "movie"(视频文件) / "scene"(场景) /
|
||||
"brush"(图案)。加载后 obj.w / obj.h 等会更新为
|
||||
生成尺寸,紧接着的 getpixel 也可读取。传统引擎与高速引擎均可运行。
|
||||
※ "scene" 与 "brush" 是 AviUtl 中不存在的 YMM4 专用扩展。
|
||||
|
||||
obj.load("figure", 名称, 颜色, 大小 [, 线宽 [, 纵横比]])
|
||||
生成图形并替换缓冲区(居中)。
|
||||
@@ -472,6 +474,37 @@
|
||||
(MP4 / MOV / MKV / WebM / AVI / FLV / ASF)。
|
||||
示例:obj.load("movie", "C:\\mov\\clip.mp4", obj.time)
|
||||
|
||||
obj.load("scene", 场景名 [, 时间])
|
||||
绘制项目内的另一个场景并替换缓冲区。
|
||||
场景名 : 场景列表中显示的名称。
|
||||
时间 : 秒。省略时为 obj.time。
|
||||
※ 不能指定当前对象所在的场景本身,也不能在场景绘制
|
||||
过程中再次加载场景。
|
||||
※ 加载了场景的帧不使用绘制缓存,每次都会重新执行。
|
||||
示例:obj.load("scene", "子场景", obj.time)
|
||||
|
||||
obj.load("brush", 图案名 [, 宽 [, 高]])
|
||||
以 YMM4 的图案(笔刷)填充生成图像并替换缓冲区。
|
||||
通过笔刷插件添加的图案也可以使用。
|
||||
图案名 : 图案列表中显示的名称(例:条纹、棋盘格)。
|
||||
宽、高 : 生成尺寸(像素)。省略时为当前 obj.w / obj.h。
|
||||
※ 图案以默认参数绘制。
|
||||
示例:obj.load("brush", "条纹", 400, 300)
|
||||
|
||||
○ obj.brush(图案名 [, 宽, 高] [, 参数名, 值, ...])
|
||||
以带参数指定的方式绘制 YMM4 的图案(笔刷)并替换缓冲区。
|
||||
绘制与 obj.load("brush") 相同,另外可以用与 obj.effect 相同的
|
||||
「名称与值的组」修改图案的参数。
|
||||
图案名 : 图案列表中显示的名称。
|
||||
宽、高 : 生成尺寸(像素)。省略时为当前 obj.w / obj.h。仅当两者
|
||||
都以数值给出时才解释为尺寸。
|
||||
参数名 : 图案设置项的显示名称,或其内部属性名。
|
||||
值 : 数值、布尔值、字符串。颜色为 0xRRGGBB 的数值。
|
||||
※ 未指定的参数以默认值绘制。省略所有组的调用与
|
||||
obj.load("brush") 相同。
|
||||
※ 这是 AviUtl 中不存在的 YMM4 专用扩展。
|
||||
示例:obj.brush("条纹", "Angle", 45, "Color1", 0xff3366)
|
||||
|
||||
○ obj.setfont(字体 [, 大小 [, 样式 [, 颜色]]])
|
||||
设置 obj.load("text") 使用的字体。
|
||||
样式 : 位标志。1=粗体, 2=斜体, 3=粗斜体。
|
||||
|
||||
@@ -439,8 +439,10 @@
|
||||
|
||||
○ obj.load(目標, ...)
|
||||
將物件緩衝區替換為產生的內容。支援 "figure"(圖形) / "text"(文字) /
|
||||
"image"(影像檔) / "movie"(影片檔)。載入後 obj.w / obj.h 等會更新為產生
|
||||
"image"(影像檔) / "movie"(影片檔) / "scene"(場景) /
|
||||
"brush"(圖樣)。載入後 obj.w / obj.h 等會更新為產生
|
||||
尺寸,緊接著的 getpixel 亦可讀取。傳統引擎與高速引擎皆可執行。
|
||||
※ "scene" 與 "brush" 是 AviUtl 中不存在的 YMM4 專用擴充。
|
||||
|
||||
obj.load("figure", 名稱, 顏色, 大小 [, 線寬 [, 長寬比]])
|
||||
產生圖形並替換緩衝區(置中)。
|
||||
@@ -472,6 +474,37 @@
|
||||
(MP4 / MOV / MKV / WebM / AVI / FLV / ASF)。
|
||||
範例:obj.load("movie", "C:\\mov\\clip.mp4", obj.time)
|
||||
|
||||
obj.load("scene", 場景名 [, 時間])
|
||||
繪製專案內的另一個場景並替換緩衝區。
|
||||
場景名 : 場景清單中顯示的名稱。
|
||||
時間 : 秒。省略時為 obj.time。
|
||||
※ 不能指定目前物件所在的場景本身,也不能在場景繪製
|
||||
過程中再次載入場景。
|
||||
※ 載入了場景的影格不使用繪製快取,每次都會重新執行。
|
||||
範例:obj.load("scene", "子場景", obj.time)
|
||||
|
||||
obj.load("brush", 圖樣名 [, 寬 [, 高]])
|
||||
以 YMM4 的圖樣(筆刷)填滿產生影像並替換緩衝區。
|
||||
透過筆刷外掛新增的圖樣亦可使用。
|
||||
圖樣名 : 圖樣清單中顯示的名稱(例:條紋、棋盤格)。
|
||||
寬、高 : 產生尺寸(像素)。省略時為目前的 obj.w / obj.h。
|
||||
※ 圖樣以預設參數繪製。
|
||||
範例:obj.load("brush", "條紋", 400, 300)
|
||||
|
||||
○ obj.brush(圖樣名 [, 寬, 高] [, 參數名, 值, ...])
|
||||
以帶參數指定的方式繪製 YMM4 的圖樣(筆刷)並替換緩衝區。
|
||||
繪製與 obj.load("brush") 相同,另外可以用與 obj.effect 相同的
|
||||
「名稱與值的組」修改圖樣的參數。
|
||||
圖樣名 : 圖樣清單中顯示的名稱。
|
||||
寬、高 : 產生尺寸(像素)。省略時為目前的 obj.w / obj.h。僅當兩者
|
||||
都以數值給出時才解釋為尺寸。
|
||||
參數名 : 圖樣設定項目的顯示名稱,或其內部屬性名。
|
||||
值 : 數值、布林值、字串。顏色為 0xRRGGBB 的數值。
|
||||
※ 未指定的參數以預設值繪製。省略所有組的呼叫與
|
||||
obj.load("brush") 相同。
|
||||
※ 這是 AviUtl 中不存在的 YMM4 專用擴充。
|
||||
範例:obj.brush("條紋", "Angle", 45, "Color1", 0xff3366)
|
||||
|
||||
○ obj.setfont(字型 [, 大小 [, 樣式 [, 顏色]]])
|
||||
設定 obj.load("text") 使用的字型。
|
||||
樣式 : 位元旗標。1=粗體, 2=斜體, 3=粗斜體。
|
||||
|
||||
@@ -218,6 +218,8 @@ AviUtl のアニメーション効果スクリプト(`.anm` 系)のうち、
|
||||
- **`@` による複数セクション**: 1 つのスクリプトに `@名前` で複数の効果が定義されている場合、先頭のセクションのみを実行します。
|
||||
- **`obj.rand(st, ed [, seed [, frame]])`**: 指定範囲(`st`〜`ed`)の整数を返す決定論的な乱数です。`seed` と `frame` が同じであれば常に同じ値を返し、`frame` を省略すると現在のフレームを用います。従来エンジン(MoonSharp)と高速ランタイム(LuaJIT)で同じ値を返します。
|
||||
- **`obj.load("figure", 名前, 色, サイズ [, ライン [, アスペクト]])`**: 円・四角形・三角形・五角形・六角形・星形を生成し、オブジェクトのバッファを置き換えて描画します(出力は図形サイズに合わせて生成され、中心に配置されます)。`ライン` を省略するか `0` で塗りつぶし、サイズ以上の値でも塗りつぶしになります。`アスペクト`(-1.0〜1.0)で幅・高さを歪曲できます。
|
||||
- **`obj.brush(模様名 [, 幅, 高さ] [, パラメータ名, 値, ...])`**: AviUtl に存在しない YMM4 向けの独自拡張です。YMM4 の模様(ブラシ)をパラメータ指定付きで描画してオブジェクトの画像を置き換えます。描画は `obj.load("brush")` と同じで、加えて `obj.effect` と同じ「名前と値の組」で模様のパラメータを変更できます。パラメータ名には設定項目の表示名または内部のプロパティ名を指定し、値は数値・真偽値・文字列に対応します。色は `0xRRGGBB` の数値で指定します。指定しなかったパラメータは既定値で描画され、組をすべて省略した呼び出しは `obj.load("brush")` と同じです。従来エンジン(MoonSharp)と高速ランタイム(LuaJIT)の双方で動作します。
|
||||
- **`obj.load("scene", シーン名 [, 時間])` と `obj.load("brush", 模様名 [, 幅, 高さ])`**: AviUtl に存在しない YMM4 向けの独自拡張です。`"scene"` はプロジェクト内の別シーンを指定時刻(省略時は `obj.time`)で描画してオブジェクトのバッファを置き換えます。シーン名にはシーン一覧に表示される名前を指定します。現在のオブジェクトが乗っているシーン自身は読み込めず、シーン描画の中からさらにシーンを読み込むこともできません。シーンを読み込んだフレームは描画キャッシュを使わず毎回再実行されます。`"brush"` は YMM4 の模様(ブラシ)で塗り潰した画像を生成してバッファを置き換えます。模様名には模様一覧に表示される名前を指定し、ブラシプラグインで追加した模様も使えます。サイズを省略すると現在の `obj.w` / `obj.h` を用い、模様のパラメータは既定値で描画されます。どちらも従来エンジン(MoonSharp)と高速ランタイム(LuaJIT)の双方で動作します。
|
||||
- **描画・メディア・バッファ・オプション API**: `obj.draw` / `obj.drawpoly` による描画合成、`obj.load` の `"text"` / `"image"` / `"movie"`、`obj.setfont`、`obj.copybuffer`、`obj.effect`、`obj.getvalue`、`obj.getinfo`、`obj.setoption` / `obj.getoption` / `obj.pixeloption` に対応しています。これらは従来エンジン(MoonSharp)と高速ランタイム(LuaJIT)の双方で動作します。`obj.getinfo` は `"script_path"` / `"filter"` / `"saving"` / `"image_max"` / `"bpm"` / `"clock"` / `"script_time"` / `"version"` の環境情報を名前で取得します。`obj.setoption` では `antialias` に加えて、`obj.draw` / `obj.drawpoly` の合成モードを YMM4 の並びで指定する `blend`、描画先を `"framebuffer"` / `"tempbuffer"` で切り替える `drawtarget`、作業画像の出力可否を切り替える `draw_state` に対応します。MoonSharp では `tempbuffer` への合成を GPU で実行し、GPU を利用できない環境では CPU の合成へ自動的に切り替わります。丸めの違いにより、合成の結果はエンジン間でごく僅かに異なることがあります。
|
||||
- **`obj.setanchor(name, count [, option, ...])`**: プレビュー上にドラッグ可能なアンカーポイントを表示し、その座標を `name` の Lua 変数(`pos={x0,y0,x1,y1,…}`、`"xyz"` 指定時は `{x0,y0,z0,…}`)へ格納します。座標はオブジェクトの中心が原点で、ドラッグで調整した値はプロジェクトへ保存されます。最大 32 個で、`"line"` / `"loop"` / `"star"` / `"arm"` の線結びと `"xyz"` の 3D 指定に対応します。設置数を返し、従来エンジン(MoonSharp)と高速ランタイム(LuaJIT)の双方で動作します。`name` に `"track"` を指定した場合も対応し、個数 0 は 1 個として設置します。選択中のアンカーは「アンカー」グループの `X` / `Y` / `Z` スライダーで数値調整できます。
|
||||
- **`obj.effect` の AviUtl/AviUtl2 互換マップ**: `obj.effect("エフェクト名", "パラメータ名", 値, …)` はまず互換マップを参照し、AviUtl/AviUtl2 の名前として宣言したエフェクトを、対応する YMM4 の映像エフェクトとプロパティへ変換して適用します。値の倍率とオフセットの変換まで宣言できます。互換マップに宣言が無い名前は、従来どおり YMM4 のエフェクト名・キーワードでそのまま解決するため、既存の呼び出しはそのまま動きます。この互換マップは YMM4 自身が AviUtl の `.exo` へ書き出す変換を逆向きにたどって構築しているため、往復しても結果が一致します。対象のエンジンは指定子 `--!aviutl` または `--!aviutl2` で切り替え、指定子を書かないときは `--!aviutl` として扱います。互換マップが対応するエフェクト名の一覧はドキュメントの「obj の関数」を参照してください。
|
||||
|
||||
+2
-2
@@ -63,8 +63,8 @@ Lua 5.2 互換の MoonSharp はフォールバックとして使われます。
|
||||
<tr><td>アニメーション補間・波・ノイズ・色</td><td><code>anim.lerp</code>, <code>anim.ease_in_out</code>, <code>anim.noise</code>, <code>anim.hsv_to_rgb</code></td><td><a href="anim.html">anim</a></td></tr>
|
||||
<tr><td>他アイテムの参照</td><td><code>obj.getobject</code></td><td><a href="obj-functions.html">obj の関数</a></td></tr>
|
||||
<tr><td>ピクセル操作</td><td><code>obj.getpixel</code>, <code>obj.setpixel</code>, <code>obj.getpixeldata</code></td><td><a href="pixels.html">ピクセル操作</a></td></tr>
|
||||
<tr><td>図形・テキスト・画像・動画の読み込み</td><td><code>obj.load</code>, <code>obj.setfont</code></td><td><a href="obj-functions.html">obj の関数</a></td></tr>
|
||||
<tr><td>他エフェクトの適用・描画</td><td><code>obj.effect</code>, <code>obj.draw</code>, <code>obj.drawpoly</code></td><td><a href="obj-functions.html">obj の関数</a></td></tr>
|
||||
<tr><td>図形・テキスト・画像・動画・シーン・模様の読み込み</td><td><code>obj.load</code>, <code>obj.setfont</code></td><td><a href="obj-functions.html">obj の関数</a></td></tr>
|
||||
<tr><td>他エフェクトの適用・描画</td><td><code>obj.effect</code>, <code>obj.brush</code>, <code>obj.draw</code>, <code>obj.drawpoly</code></td><td><a href="obj-functions.html">obj の関数</a></td></tr>
|
||||
<tr><td>シーン・環境情報</td><td><code>scene.width</code>, <code>ymm4.is_saving</code></td><td><a href="scene-ymm4.html">scene / ymm4</a></td></tr>
|
||||
<tr><td>パラメータ UI の定義</td><td><code>--track@</code>, <code>--check@</code>, <code>--color@</code>, <code>--dialog:</code></td><td><a href="directives.html">パラメータ指定子</a></td></tr>
|
||||
<tr><td>高速化エンジンの選択</td><td><code>--!native</code>, <code>--!cpu</code>, <code>--!gpu</code></td><td><a href="engines.html">エンジンと高速化</a></td></tr>
|
||||
|
||||
+34
-1
@@ -114,7 +114,7 @@ end</code></pre>
|
||||
<code>anim.noise</code> が便利です。<code>obj.rand</code> は整数を返す AviUtl 互換の乱数です。
|
||||
</div>
|
||||
|
||||
<h2>obj.load — 図形・テキスト・画像・動画の読み込み</h2>
|
||||
<h2>obj.load — 図形・テキスト・画像・動画・シーン・模様の読み込み</h2>
|
||||
|
||||
<p>
|
||||
<code>obj.load(種類, ...)</code> は、対象の画像バッファを生成した内容で置き換えます。
|
||||
@@ -127,8 +127,41 @@ end</code></pre>
|
||||
<tr><td><code>obj.load("text", str)</code></td><td>文字列を描画。フォントは <code>obj.setfont</code> の設定を使う</td></tr>
|
||||
<tr><td><code>obj.load("image", path)</code></td><td>画像ファイルを読み込む</td></tr>
|
||||
<tr><td><code>obj.load("movie", path [, time])</code></td><td>動画の指定時刻のフレームを読み込む(既定は現在時刻)</td></tr>
|
||||
<tr><td><code>obj.load("scene", name [, time])</code></td><td>プロジェクト内の別シーンを指定時刻で描画して読み込む(既定は現在時刻)</td></tr>
|
||||
<tr><td><code>obj.load("brush", name [, w, h])</code></td><td>YMM4 の模様(ブラシ)で塗り潰した画像を読み込む(既定サイズは現在の <code>obj.w</code> / <code>obj.h</code>)</td></tr>
|
||||
</table>
|
||||
|
||||
<div class="note">
|
||||
<code>"scene"</code> と <code>"brush"</code> は AviUtl に存在しない YMM4 向けの独自拡張です。
|
||||
シーン名と模様名には、それぞれ YMM4 のシーン一覧と模様一覧に表示される名前を指定します。
|
||||
現在のオブジェクトが乗っているシーン自身は読み込めず、シーン描画の中からさらにシーンを読み込むこともできません。
|
||||
シーンを読み込んだフレームは描画キャッシュを使わず毎回再実行されます。
|
||||
模様はブラシプラグインで追加したものも使えますが、パラメータは既定値で描画されます。
|
||||
パラメータを変更したいときは <code>obj.brush</code> を使います。
|
||||
</div>
|
||||
|
||||
<h2>obj.brush — 模様のパラメータ指定付き描画</h2>
|
||||
|
||||
<p>
|
||||
<code>obj.brush(模様名 [, 幅, 高さ] [, パラメータ名, 値, ...])</code> は、YMM4 の模様(ブラシ)を
|
||||
パラメータ指定付きで描画してオブジェクトの画像を置き換えます。描画は <code>obj.load("brush", ...)</code> と同じで、
|
||||
加えて <code>obj.effect</code> と同じ「名前と値の組」で模様のパラメータを変更できます。
|
||||
AviUtl に存在しない YMM4 向けの独自拡張です。
|
||||
</p>
|
||||
|
||||
<table>
|
||||
<tr><th>引数</th><th>説明</th></tr>
|
||||
<tr><td><code>模様名</code></td><td>模様一覧に表示される名前</td></tr>
|
||||
<tr><td><code>幅, 高さ</code></td><td>生成サイズ(px)。省略時は現在の <code>obj.w</code> / <code>obj.h</code>。両方を数値で並べたときだけサイズとして解釈する</td></tr>
|
||||
<tr><td><code>パラメータ名, 値</code></td><td>模様の設定項目の表示名または内部のプロパティ名と、その値の組。値は数値・真偽値・文字列で、色は <code>0xRRGGBB</code> の数値</td></tr>
|
||||
</table>
|
||||
|
||||
<pre><code>obj.brush("縞模様", "Angle", 45, "Color1", 0xff3366)</code></pre>
|
||||
|
||||
<div class="note">
|
||||
指定しなかったパラメータは既定値で描画されます。組をすべて省略した呼び出しは <code>obj.load("brush")</code> と同じです。
|
||||
</div>
|
||||
|
||||
<p><code>obj.load("figure", ...)</code> で指定できる図形名は次のとおりです。</p>
|
||||
|
||||
<table>
|
||||
|
||||
+2
-1
@@ -83,9 +83,10 @@
|
||||
<tr><td><code>obj.getpixeldata()</code></td><td>ピクセル直接アクセスプロキシ</td></tr>
|
||||
<tr><td><code>obj.putpixeldata()</code></td><td>互換用の空実装</td></tr>
|
||||
<tr><td><code>obj.rand(a, b [, seed [, frame]])</code></td><td>整数の安定した乱数</td></tr>
|
||||
<tr><td><code>obj.load(種類, ...)</code></td><td>図形 / テキスト / 画像 / 動画の読み込み</td></tr>
|
||||
<tr><td><code>obj.load(種類, ...)</code></td><td>図形 / テキスト / 画像 / 動画 / シーン / 模様の読み込み</td></tr>
|
||||
<tr><td><code>obj.setfont(name [, size [, type [, color]]])</code></td><td>フォント設定</td></tr>
|
||||
<tr><td><code>obj.effect(name, key, val, ...)</code></td><td>AviUtl/AviUtl2 互換マップ経由でエフェクトを適用</td></tr>
|
||||
<tr><td><code>obj.brush(name [, w, h] [, key, val, ...])</code></td><td>YMM4 の模様をパラメータ指定付きで描画</td></tr>
|
||||
<tr><td><code>obj.draw([ox, oy, oz, zoom, alpha, aspect])</code></td><td>バッファの描画</td></tr>
|
||||
<tr><td><code>obj.drawpoly(...)</code></td><td>4 頂点ポリゴンの描画</td></tr>
|
||||
<tr><td><code>obj.copybuffer(dst, src)</code></td><td>バッファのコピー</td></tr>
|
||||
|
||||
+78
-15
@@ -95,6 +95,9 @@ local CB_KIND_SCENEGET = 11
|
||||
local CB_KIND_SCENESET = 12
|
||||
local CB_KIND_PIXELSHADER_STAGE = 13
|
||||
local CB_KIND_PIXELSHADER_RUN = 14
|
||||
local CB_KIND_LOADSCENE = 15
|
||||
local CB_KIND_LOADBRUSH = 16
|
||||
local CB_KIND_BRUSH = 17
|
||||
local MAX_PIXEL_BUFFER = 3840 * 2160 * 4
|
||||
local SHADER_META_DOUBLES = 20
|
||||
local SHADER_CONSTANTS_MAX = 1024
|
||||
@@ -519,25 +522,39 @@ local function loadMovie(path, time)
|
||||
applyLoadResult()
|
||||
end
|
||||
|
||||
function obj.load(kind, ...)
|
||||
if kind == "figure" then
|
||||
loadFigure(...)
|
||||
elseif kind == "text" then
|
||||
loadText(...)
|
||||
elseif kind == "image" then
|
||||
loadImage(...)
|
||||
elseif kind == "movie" then
|
||||
loadMovie(...)
|
||||
end
|
||||
local function loadScene(name, time)
|
||||
local payload = tostring(name or "")
|
||||
local len = #payload
|
||||
if len > CB_TAG_MAX then len = CB_TAG_MAX end
|
||||
ffi.copy(base + CB_TAG_OFFSET, payload, len)
|
||||
i32[OFF_CB_TAGLEN] = len
|
||||
i32[OFF_CB_KIND] = CB_KIND_LOADSCENE
|
||||
cbResult[0] = time or obj.time or 0
|
||||
i32[OFF_STATUS] = STATUS_CALLBACK
|
||||
k32.SetEvent(doneEvent)
|
||||
k32.WaitForSingleObject(workEvent, INFINITE)
|
||||
applyLoadResult()
|
||||
end
|
||||
|
||||
function obj.effect(name, ...)
|
||||
if type(name) ~= "string" then return end
|
||||
local args = { ... }
|
||||
local n = select("#", ...)
|
||||
local function loadBrush(name, w, h)
|
||||
local payload = tostring(name or "")
|
||||
local len = #payload
|
||||
if len > CB_TAG_MAX then len = CB_TAG_MAX end
|
||||
ffi.copy(base + CB_TAG_OFFSET, payload, len)
|
||||
i32[OFF_CB_TAGLEN] = len
|
||||
i32[OFF_CB_KIND] = CB_KIND_LOADBRUSH
|
||||
cbResult[0] = w or width
|
||||
cbResult[1] = h or height
|
||||
i32[OFF_STATUS] = STATUS_CALLBACK
|
||||
k32.SetEvent(doneEvent)
|
||||
k32.WaitForSingleObject(workEvent, INFINITE)
|
||||
applyLoadResult()
|
||||
end
|
||||
|
||||
local function writeNamedArgs(name, args, first, n)
|
||||
local parts = { name }
|
||||
local pos = #name + 1
|
||||
for i = 1, n - 1, 2 do
|
||||
for i = first, n - 1, 2 do
|
||||
local k = tostring(args[i])
|
||||
local v = args[i + 1]
|
||||
local encoded
|
||||
@@ -559,6 +576,30 @@ function obj.effect(name, ...)
|
||||
local len = #payload
|
||||
if len > CB_TAG_MAX then len = CB_TAG_MAX end
|
||||
ffi.copy(base + CB_TAG_OFFSET, payload, len)
|
||||
return len
|
||||
end
|
||||
|
||||
function obj.load(kind, ...)
|
||||
if kind == "figure" then
|
||||
loadFigure(...)
|
||||
elseif kind == "text" then
|
||||
loadText(...)
|
||||
elseif kind == "image" then
|
||||
loadImage(...)
|
||||
elseif kind == "movie" then
|
||||
loadMovie(...)
|
||||
elseif kind == "scene" then
|
||||
loadScene(...)
|
||||
elseif kind == "brush" then
|
||||
loadBrush(...)
|
||||
end
|
||||
end
|
||||
|
||||
function obj.effect(name, ...)
|
||||
if type(name) ~= "string" then return end
|
||||
local args = { ... }
|
||||
local n = select("#", ...)
|
||||
local len = writeNamedArgs(name, args, 1, n)
|
||||
i32[OFF_CB_TAGLEN] = len
|
||||
i32[OFF_CB_KIND] = CB_KIND_EFFECT
|
||||
i32[OFF_STATUS] = STATUS_CALLBACK
|
||||
@@ -566,6 +607,28 @@ function obj.effect(name, ...)
|
||||
k32.WaitForSingleObject(workEvent, INFINITE)
|
||||
end
|
||||
|
||||
function obj.brush(name, ...)
|
||||
if type(name) ~= "string" then return end
|
||||
local args = { ... }
|
||||
local n = select("#", ...)
|
||||
local first = 1
|
||||
local w, h
|
||||
if n >= 2 and type(args[1]) == "number" and type(args[2]) == "number" then
|
||||
w = args[1]
|
||||
h = args[2]
|
||||
first = 3
|
||||
end
|
||||
local len = writeNamedArgs(name, args, first, n)
|
||||
i32[OFF_CB_TAGLEN] = len
|
||||
i32[OFF_CB_KIND] = CB_KIND_BRUSH
|
||||
cbResult[0] = w or width
|
||||
cbResult[1] = h or height
|
||||
i32[OFF_STATUS] = STATUS_CALLBACK
|
||||
k32.SetEvent(doneEvent)
|
||||
k32.WaitForSingleObject(workEvent, INFINITE)
|
||||
applyLoadResult()
|
||||
end
|
||||
|
||||
function obj.draw(ox, oy, oz, zoom, alpha, aspect)
|
||||
if drawTarget == "temp" then
|
||||
ensurePixels()
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする