コミットを比較
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
381a717942
|
検索条件に一致するファイルはありません
+38
-89
@@ -1,112 +1,61 @@
|
|||||||
# v1.11.0 - Lua スクリプト for YMM4
|
# v1.10.0 - Lua スクリプト for YMM4
|
||||||
|
|
||||||
AviUtl 互換の描画 API を拡張したリリースです。`obj.draw` / `obj.drawpoly` の合成モード、
|
エフェクトパネルへ新しいパラメータ入力欄を追加したリリースです。整数スライダー 4 本と、
|
||||||
作業画像の出力可否を切り替える `draw_state`、描画先を `tmp` バッファへ切り替える
|
テキスト・フォント・フォルダ・ファイルの文字列入力をスクリプトから参照できるようにしました。
|
||||||
`drawtarget`、アンカー座標を Lua 変数として扱う `obj.setanchor` を追加しました。
|
文字列パラメータは MoonSharp とネイティブの両エンジンで同じ名前から参照でき、ネイティブでは
|
||||||
MoonSharp とネイティブの両エンジンで同じ API を使えるようにし、内蔵ドキュメントも
|
共有メモリの文字列領域を必要量に応じて拡張・縮小します。あわせて毎フレームのアロケーションを
|
||||||
各言語で更新しました。
|
見直し、補完候補を拡充しました。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 新機能・機能改善
|
## 新機能・機能改善
|
||||||
|
|
||||||
### 1. obj.setoption("blend", 合成モード)
|
### 1. 整数スライダー obj.slider0〜3
|
||||||
|
|
||||||
`obj.draw` / `obj.drawpoly` の合成モードを `obj.setoption("blend", 番号)` で指定できるように
|
数値スライダーを 4 本追加しました。各値は `obj.slider0`〜`obj.slider3` として参照できます。
|
||||||
しました。
|
|
||||||
|
|
||||||
- 番号は YMM4 のプロパティパネルにある「合成モード」の並びと同じで、0 から始まります。
|
- 値は整数で、小数は扱いません。表示範囲は `obj.slider0` が 1〜10、`obj.slider1` が 0〜100、
|
||||||
- 0 は通常、1 はディザ合成、2 は比較(暗)、3 は乗算、4 は焼き込みカラー、5 は
|
`obj.slider2` が 0〜1000、`obj.slider3` が -1000〜1000 です。
|
||||||
焼き込み(リニア)、6 は比較(明)、7 はスクリーン、8 は覆い焼きカラー、9 は
|
- 状態の切り替えなど、補間を伴わない整数値の受け渡しに使えます。
|
||||||
覆い焼き(リニア) - 加算、10 は加算、11 はオーバーレイ、12 はソフトライト、13 は
|
- MoonSharp・ネイティブ・CPU/GPU カーネルのいずれのレーンからも参照できます。
|
||||||
ハードライト、14 はビビッドライト、15 はリニアライト、16 はピンライト、17 は
|
|
||||||
ハードミックス、18 は差分、19 は除外、20 は減算、21 は除算、22 は色相、23 は彩度、
|
|
||||||
24 はカラー、25 は輝度、26 はカラー比較(明)、27 は背景、28 はカラー比較(暗)、
|
|
||||||
29 は削除、30 は背景でクリッピング、31 は重ならない部分のみ、32 は色反転マスクです。
|
|
||||||
- 範囲外の値や数値ではない値は通常として扱います。
|
|
||||||
- MoonSharp とネイティブの両エンジンで、`obj.draw` と `obj.drawpoly` の描画コマンドへ
|
|
||||||
合成モードを渡します。
|
|
||||||
|
|
||||||
### 2. obj.setoption("draw_state", true / false)
|
### 2. 文字列パラメータ obj.text / obj.font / obj.dir / obj.file_*
|
||||||
|
|
||||||
このエフェクトが作業画像を出力するかどうかを、スクリプトから明示できるようにしました。
|
テキスト・フォント・フォルダ・ファイルの入力欄を追加しました。
|
||||||
|
|
||||||
- `true` を指定すると、`setpixel` や `obj.draw` を使わない場合でも作業画像を出力します。
|
- `obj.text` はテキスト入力欄の文字列、`obj.font` はフォント名、`obj.dir` はフォルダのパスです。
|
||||||
- `false` を指定すると、このエフェクトの作業画像出力を抑制します。
|
- ファイル選択は種類ごとに `obj.file_video` / `obj.file_audio` / `obj.file_image` /
|
||||||
- 未指定の場合は従来どおり、ピクセル変更や描画コマンドの有無に従います。
|
`obj.file_project` / `obj.file_mp4` / `obj.file_exo` / `obj.file_subtitle` /
|
||||||
- MoonSharp とネイティブの両エンジンで動作します。
|
`obj.file_shader` で参照し、選択したファイルのパスを取得します。
|
||||||
|
- 取得したパスは `obj.load` へ渡して画像・動画の読み込みに使えます。
|
||||||
|
- MoonSharp とネイティブの両エンジンで同じ名前から参照できます。
|
||||||
|
|
||||||
### 3. obj.setoption("drawtarget", "framebuffer" / "tempbuffer")
|
### 3. 補完候補の拡充
|
||||||
|
|
||||||
`obj.draw` / `obj.drawpoly` の描画先を切り替えられるようにしました。
|
スクリプトエディタの補完候補へ `obj.slider0`〜`obj.slider3` と、追加した文字列パラメータの
|
||||||
|
各名前を加えました。
|
||||||
- `"framebuffer"` は既定の描画先です。描画コマンドはフレームバッファへ合成されます。
|
|
||||||
- `"tempbuffer"` を指定すると、描画コマンドは作業用の `tmp` バッファへその場で合成されます。
|
|
||||||
- `obj.setoption("drawtarget", "tempbuffer", w, h)` のように幅と高さを渡すと、そのサイズで
|
|
||||||
`tmp` バッファを用意します。
|
|
||||||
- `tmp` へ描いた結果は `obj.copybuffer("obj", "tmp")` で作業画像へ戻せます。
|
|
||||||
- `tempbuffer` への合成は通常のソースオーバーで行い、`blend` はフレームバッファへの描画に
|
|
||||||
適用します。
|
|
||||||
- 描画先は毎フレーム既定の `"framebuffer"` へ戻ります。
|
|
||||||
- MoonSharp とネイティブの両エンジンで動作します。
|
|
||||||
|
|
||||||
### 4. obj.setanchor(name, count [, option, ...])
|
|
||||||
|
|
||||||
アンカー座標を Lua 変数へ格納する `obj.setanchor` を追加しました。
|
|
||||||
|
|
||||||
- `name` で指定した名前の Lua 変数へ、`{x0, y0, x1, y1, ...}` の配列を作成します。
|
|
||||||
- `"xyz"` を指定した場合は `{x0, y0, z0, x1, y1, z1, ...}` の 3D 座標になります。
|
|
||||||
- `count` は 0〜32 に制限され、戻り値は実際に設置した個数です。
|
|
||||||
- 保存済みの座標がある場合はその値を使い、無い場合は 8 列の既定グリッド座標を使います。
|
|
||||||
- `"line"` / `"loop"` / `"star"` / `"arm"` の線結び指定と、`"xyz"` の 3D 指定を受け付けます。
|
|
||||||
- `name` に `"track"` を指定するトラックバー連携は未対応で、0 を返します。
|
|
||||||
- MoonSharp とネイティブの両エンジンで同じ座標テーブルを受け取れるようにしました。
|
|
||||||
|
|
||||||
### 5. 内蔵ドキュメントの更新
|
|
||||||
|
|
||||||
同梱される `LuaScript/docs/LuaScript.*.txt` を更新し、`blend`、`draw_state`、
|
|
||||||
`drawtarget`、`obj.setanchor` の説明を各言語へ追加しました。
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 互換性・後方互換
|
## 互換性・後方互換
|
||||||
|
|
||||||
- `blend` の既定値は 0 の通常です。指定しない既存スクリプトの合成結果は変わりません。
|
- スライダーと文字列パラメータは、スクリプト本体でそれらを参照したときだけエフェクトパネルへ
|
||||||
- `drawtarget` の既定値は `"framebuffer"` です。フレームをまたいで前回の描画先は持ち越しません。
|
表示されます。参照しない既存スクリプトの表示と挙動は変わりません。
|
||||||
- `draw_state` を指定しない場合は、従来どおりピクセル変更や描画コマンドに応じて出力します。
|
- CPU/GPU カーネルは数値計算に特化するため、文字列パラメータは扱いません。文字列を参照する
|
||||||
- `obj.setanchor` を含むスクリプトは、自動判定では描画 API を使うスクリプトとして扱います。
|
スクリプトは MoonSharp かネイティブで実行してください。
|
||||||
ネイティブで実行する場合は、従来どおり明示ディレクティブを使えます。
|
- トラックバー・チェックボックス・カラー・AviUtl 互換ヘッダの既存挙動は変わりません。
|
||||||
- `tempbuffer` への描画は通常合成です。`blend` による合成モード指定は、フレームバッファへの
|
|
||||||
`obj.draw` / `obj.drawpoly` に適用されます。
|
|
||||||
- `obj.setanchor("track", ...)` によるトラックバー連携は未対応で、0 を返します。
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 内部実装
|
## 内部実装
|
||||||
|
|
||||||
- YMM4 の `Blend` 列挙値へ番号を対応させる `BlendModeMap` を追加し、`DrawCommand` へ
|
- ネイティブの共有メモリへ文字列パラメータ領域を追加し、容量をワーカーの起動引数にしました。
|
||||||
合成モード番号を持たせました。
|
必要量が容量を超えると 2 倍へ拡張し、容量の半分以下に収まると縮小します。最小は 64KB で、
|
||||||
- `DrawCompositor` は通常以外の合成モードで `DrawImage` / `BlendImage` を使い、Opacity の
|
容量の変化はワーカーの再生成のみで完結します。
|
||||||
出力をキャッシュして毎描画ごとの COM オブジェクト確保を避けるようにしました。
|
- 文字列パラメータの変更検出をバージョン方式へ変更し、フレームごとの署名文字列の生成を
|
||||||
- `SoftwareCompositor` を追加し、MoonSharp 側で最近傍または線形補間による
|
やめました。値の参照が変わったときだけ版数を進めます。
|
||||||
`obj.draw` / `obj.drawpoly` の `tempbuffer` 合成を行えるようにしました。
|
- ネイティブの文字列書き込みで、名前のバイト列をキャッシュし、値のエンコード先バッファを
|
||||||
- ネイティブワーカー側にも同等のソフトウェア合成処理を追加しました。
|
再利用します。
|
||||||
- `AviUtlScriptContext` に `DrawStateOverride`、描画先状態、アンカー入力元、アンカー要求一覧を
|
- スライダーの値は MoonSharp の obj テーブル・ネイティブのフィールド・CPU/GPU カーネルの
|
||||||
追加しました。描画先が `tempbuffer` の場合は `DrawCommand` を通常の描画キューへ積まず、
|
ユニフォームへ配線しました。スクリプトの使用検出は obj メンバを汎用的に走査する方式へ
|
||||||
その場で `tmp` バッファへ合成します。
|
再設計しました。
|
||||||
- `LuaAnchorPoint` と `AnchorSupport` を追加し、アンカー数の制限、オプション解析、既定座標、
|
|
||||||
保存済み座標の解決、ドラッグ後の座標更新を分離しました。
|
|
||||||
- アンカー要求から生成した `VideoEffectController` を `DrawDescription.Controllers` へ追加し、
|
|
||||||
YMM4 のプレビュー操作へ渡すようにしました。
|
|
||||||
- アンカー座標の変更をキャッシュキーへ含めるため、エフェクト側へ `AnchorVersion` を追加しました。
|
|
||||||
- ネイティブプロトコルへ `draw_state` の書き戻しフィールドと `setanchor` コールバック種別を
|
|
||||||
追加しました。`LuaJitWorker` は `draw` / `drawpoly` の合成モード、`draw_state`、
|
|
||||||
`setanchor` の座標解決をワーカーとやり取りします。
|
|
||||||
- ネイティブワーカーでは `drawtarget` 用の `tmp` バッファ、`obj.setanchor`、
|
|
||||||
`draw_state` の書き戻しを実装しました。
|
|
||||||
- ネイティブワーカーの `obj.copybuffer` は、`tmp` や名前付きキャッシュへ書き込むときに
|
|
||||||
バッファを複製するようにしました。
|
|
||||||
- `ScriptDirective` は `obj.setanchor` を描画 API として検出します。
|
|
||||||
- `NativeFieldMap` から未使用の `Epsilon` 定数を削除しました。
|
|
||||||
- `AnchorSupportTests` と `SoftwareCompositorTests` を追加し、ネイティブ往復テストへ
|
|
||||||
`blend`、`draw_state`、`setanchor`、`drawtarget` の検証を追加しました。
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
========================================
|
========================================
|
||||||
Luaスクリプト for YMM4 v1.11.0
|
Luaスクリプト for YMM4 v1.10.0
|
||||||
========================================
|
========================================
|
||||||
YukkuriMovieMaker4(YMM4)上で動作する、Luaスクリプトで映像エフェクトのパラメータや
|
YukkuriMovieMaker4(YMM4)上で動作する、Luaスクリプトで映像エフェクトのパラメータや
|
||||||
ピクセルを直接制御できるプラグインです。
|
ピクセルを直接制御できるプラグインです。
|
||||||
|
|||||||
@@ -1,103 +0,0 @@
|
|||||||
using System.Collections.Immutable;
|
|
||||||
using LuaScript.Anchor;
|
|
||||||
|
|
||||||
namespace LuaScript.Tests
|
|
||||||
{
|
|
||||||
public class AnchorSupportTests
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public void ClampCount_LimitsToRange()
|
|
||||||
{
|
|
||||||
Assert.Equal(0, AnchorSupport.ClampCount(-5));
|
|
||||||
Assert.Equal(10, AnchorSupport.ClampCount(10));
|
|
||||||
Assert.Equal(AnchorSupport.MaxAnchors, AnchorSupport.ClampCount(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ApplyOption_SetsConnectionAndDimension()
|
|
||||||
{
|
|
||||||
var connection = AnchorConnection.None;
|
|
||||||
bool is3D = false;
|
|
||||||
|
|
||||||
AnchorSupport.ApplyOption("loop", ref connection, ref is3D);
|
|
||||||
AnchorSupport.ApplyOption("xyz", ref connection, ref is3D);
|
|
||||||
|
|
||||||
Assert.Equal(AnchorConnection.Loop, connection);
|
|
||||||
Assert.True(is3D);
|
|
||||||
|
|
||||||
AnchorSupport.ApplyOption("star", ref connection, ref is3D);
|
|
||||||
Assert.Equal(AnchorConnection.Star, connection);
|
|
||||||
|
|
||||||
AnchorSupport.ApplyOption("unknown", ref connection, ref is3D);
|
|
||||||
Assert.Equal(AnchorConnection.Star, connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void DefaultPosition_IsDeterministicGrid()
|
|
||||||
{
|
|
||||||
Assert.Equal(AnchorSupport.DefaultPosition(0), AnchorSupport.DefaultPosition(0));
|
|
||||||
Assert.NotEqual(AnchorSupport.DefaultPosition(0), AnchorSupport.DefaultPosition(1));
|
|
||||||
|
|
||||||
var (x8, y8) = AnchorSupport.DefaultPosition(8);
|
|
||||||
var (x0, y0) = AnchorSupport.DefaultPosition(0);
|
|
||||||
Assert.Equal(x0, x8);
|
|
||||||
Assert.True(y8 > y0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ResolvePosition_PrefersStoredThenDefault()
|
|
||||||
{
|
|
||||||
var source = ImmutableList.Create(new LuaAnchorPoint { Group = "pos", Index = 1, X = 12, Y = 34, Z = 56 });
|
|
||||||
|
|
||||||
AnchorSupport.ResolvePosition(source, "pos", 1, out double x, out double y, out double z);
|
|
||||||
Assert.Equal(12, x);
|
|
||||||
Assert.Equal(34, y);
|
|
||||||
Assert.Equal(56, z);
|
|
||||||
|
|
||||||
AnchorSupport.ResolvePosition(source, "pos", 0, out double dx, out double dy, out double dz);
|
|
||||||
var (ex, ey) = AnchorSupport.DefaultPosition(0);
|
|
||||||
Assert.Equal(ex, dx);
|
|
||||||
Assert.Equal(ey, dy);
|
|
||||||
Assert.Equal(0, dz);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ResolvePosition_IsGroupScoped()
|
|
||||||
{
|
|
||||||
var source = ImmutableList.Create(new LuaAnchorPoint { Group = "a", Index = 0, X = 5, Y = 5, Z = 0 });
|
|
||||||
|
|
||||||
AnchorSupport.ResolvePosition(source, "b", 0, out double x, out double y, out _);
|
|
||||||
var (ex, ey) = AnchorSupport.DefaultPosition(0);
|
|
||||||
Assert.Equal(ex, x);
|
|
||||||
Assert.Equal(ey, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ApplyDrag_UpdatesExistingPoint()
|
|
||||||
{
|
|
||||||
var source = ImmutableList.Create(new LuaAnchorPoint { Group = "pos", Index = 2, X = 10, Y = 20, Z = 30 });
|
|
||||||
|
|
||||||
var result = AnchorSupport.ApplyDrag(source, "pos", 2, 3, -4, 5);
|
|
||||||
|
|
||||||
Assert.Single(result);
|
|
||||||
Assert.Equal(13, result[0].X);
|
|
||||||
Assert.Equal(16, result[0].Y);
|
|
||||||
Assert.Equal(35, result[0].Z);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ApplyDrag_AddsNewPointFromDefault()
|
|
||||||
{
|
|
||||||
var source = ImmutableList<LuaAnchorPoint>.Empty;
|
|
||||||
|
|
||||||
var result = AnchorSupport.ApplyDrag(source, "pos", 3, 7, 8, 0);
|
|
||||||
|
|
||||||
Assert.Single(result);
|
|
||||||
var (bx, by) = AnchorSupport.DefaultPosition(3);
|
|
||||||
Assert.Equal("pos", result[0].Group);
|
|
||||||
Assert.Equal(3, result[0].Index);
|
|
||||||
Assert.Equal(bx + 7, result[0].X);
|
|
||||||
Assert.Equal(by + 8, result[0].Y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -33,9 +33,6 @@
|
|||||||
<Compile Include="..\LuaScript\Engine\LuaJitWorker.cs" Link="Linked\LuaJitWorker.cs" />
|
<Compile Include="..\LuaScript\Engine\LuaJitWorker.cs" Link="Linked\LuaJitWorker.cs" />
|
||||||
<Compile Include="..\LuaScript\DrawCommand.cs" Link="Linked\DrawCommand.cs" />
|
<Compile Include="..\LuaScript\DrawCommand.cs" Link="Linked\DrawCommand.cs" />
|
||||||
<Compile Include="..\LuaScript\DrawPolyMath.cs" Link="Linked\DrawPolyMath.cs" />
|
<Compile Include="..\LuaScript\DrawPolyMath.cs" Link="Linked\DrawPolyMath.cs" />
|
||||||
<Compile Include="..\LuaScript\SoftwareCompositor.cs" Link="Linked\SoftwareCompositor.cs" />
|
|
||||||
<Compile Include="..\LuaScript\Anchor\LuaAnchorPoint.cs" Link="Linked\LuaAnchorPoint.cs" />
|
|
||||||
<Compile Include="..\LuaScript\Anchor\AnchorSupport.cs" Link="Linked\AnchorSupport.cs" />
|
|
||||||
<Compile Include="..\LuaScript\SceneObjectInfo.cs" Link="Linked\SceneObjectInfo.cs" />
|
<Compile Include="..\LuaScript\SceneObjectInfo.cs" Link="Linked\SceneObjectInfo.cs" />
|
||||||
<Compile Include="..\LuaScript\SceneObjectQuery.cs" Link="Linked\SceneObjectQuery.cs" />
|
<Compile Include="..\LuaScript\SceneObjectQuery.cs" Link="Linked\SceneObjectQuery.cs" />
|
||||||
<Compile Include="..\LuaScript\AnimTableRegistrar.cs" Link="Linked\AnimTableRegistrar.cs" />
|
<Compile Include="..\LuaScript\AnimTableRegistrar.cs" Link="Linked\AnimTableRegistrar.cs" />
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ namespace LuaScript.Tests
|
|||||||
private static readonly Func<string, double, (byte[] buffer, int w, int h)> NoLoadMovie = (_, _) => ([], 1, 1);
|
private static readonly Func<string, double, (byte[] buffer, int w, int h)> NoLoadMovie = (_, _) => ([], 1, 1);
|
||||||
private static readonly Action<string, System.Collections.Generic.IReadOnlyList<System.Collections.Generic.KeyValuePair<string, object>>> NoAddEffect = (_, _) => { };
|
private static readonly Action<string, System.Collections.Generic.IReadOnlyList<System.Collections.Generic.KeyValuePair<string, object>>> NoAddEffect = (_, _) => { };
|
||||||
private static readonly Action<DrawCommand> NoAddDraw = _ => { };
|
private static readonly Action<DrawCommand> NoAddDraw = _ => { };
|
||||||
private static readonly Action<string, int, bool, int, double[]> NoSetAnchor = (_, _, _, _, _) => { };
|
|
||||||
private static readonly System.Collections.Generic.IReadOnlyDictionary<string, string> NoStringParams = new System.Collections.Generic.Dictionary<string, string>();
|
private static readonly System.Collections.Generic.IReadOnlyDictionary<string, string> NoStringParams = new System.Collections.Generic.Dictionary<string, string>();
|
||||||
|
|
||||||
private readonly LuaJitWorker _worker = new(NativeDir);
|
private readonly LuaJitWorker _worker = new(NativeDir);
|
||||||
@@ -42,7 +41,7 @@ namespace LuaScript.Tests
|
|||||||
|
|
||||||
bool ok = _worker.Execute(
|
bool ok = _worker.Execute(
|
||||||
"obj.rz = obj.time * 90\nobj.alpha = 128",
|
"obj.rz = obj.time * 90\nobj.alpha = 128",
|
||||||
fields, NoStringParams, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out bool dirty, out _, out _, out _, out _, out string? error);
|
fields, NoStringParams, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out bool dirty, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.False(dirty);
|
Assert.False(dirty);
|
||||||
@@ -65,7 +64,7 @@ namespace LuaScript.Tests
|
|||||||
|
|
||||||
bool ok = _worker.Execute(
|
bool ok = _worker.Execute(
|
||||||
"obj.x = string.len(obj.text) obj.alpha = string.len(obj.file_image)",
|
"obj.x = string.len(obj.text) obj.alpha = string.len(obj.file_image)",
|
||||||
fields, stringParameters, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out _, out _, out _, out _, out _, out string? error);
|
fields, stringParameters, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.Equal(5d, fields[NativeProtocol.X]);
|
Assert.Equal(5d, fields[NativeProtocol.X]);
|
||||||
@@ -84,7 +83,7 @@ namespace LuaScript.Tests
|
|||||||
var fieldsLarge = Fields(2, 2, 0d);
|
var fieldsLarge = Fields(2, 2, 0d);
|
||||||
bool ok = _worker.Execute(
|
bool ok = _worker.Execute(
|
||||||
"obj.x = string.len(obj.text)",
|
"obj.x = string.len(obj.text)",
|
||||||
fieldsLarge, large, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out _, out _, out _, out _, out _, out string? error);
|
fieldsLarge, large, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.Equal(big.Length, fieldsLarge[NativeProtocol.X]);
|
Assert.Equal(big.Length, fieldsLarge[NativeProtocol.X]);
|
||||||
|
|
||||||
@@ -92,7 +91,7 @@ namespace LuaScript.Tests
|
|||||||
var fieldsSmall = Fields(2, 2, 0d);
|
var fieldsSmall = Fields(2, 2, 0d);
|
||||||
ok = _worker.Execute(
|
ok = _worker.Execute(
|
||||||
"obj.x = string.len(obj.text)",
|
"obj.x = string.len(obj.text)",
|
||||||
fieldsSmall, small, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out _, out _, out _, out _, out _, out error);
|
fieldsSmall, small, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out error);
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.Equal(2d, fieldsSmall[NativeProtocol.X]);
|
Assert.Equal(2d, fieldsSmall[NativeProtocol.X]);
|
||||||
}
|
}
|
||||||
@@ -124,7 +123,7 @@ namespace LuaScript.Tests
|
|||||||
"local gray = r*0.299 + g*0.587 + b*0.114 " +
|
"local gray = r*0.299 + g*0.587 + b*0.114 " +
|
||||||
"obj.setpixel(x,y,gray,gray,gray,a) end end";
|
"obj.setpixel(x,y,gray,gray,gray,a) end end";
|
||||||
|
|
||||||
bool ok = _worker.Execute(script, fields, NoStringParams, pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out bool dirty, out _, out _, out _, out _, out string? error);
|
bool ok = _worker.Execute(script, fields, NoStringParams, pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out bool dirty, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.True(dirty);
|
Assert.True(dirty);
|
||||||
@@ -159,7 +158,7 @@ namespace LuaScript.Tests
|
|||||||
"local gray=r*0.299+g*0.587+b*0.114 " +
|
"local gray=r*0.299+g*0.587+b*0.114 " +
|
||||||
"pd:set(base+1,gray) pd:set(base+2,gray) pd:set(base+3,gray) end end";
|
"pd:set(base+1,gray) pd:set(base+2,gray) pd:set(base+3,gray) end end";
|
||||||
|
|
||||||
bool ok = _worker.Execute(script, fields, NoStringParams, pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out bool dirty, out _, out _, out _, out _, out string? error);
|
bool ok = _worker.Execute(script, fields, NoStringParams, pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out bool dirty, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.True(dirty);
|
Assert.True(dirty);
|
||||||
@@ -195,7 +194,7 @@ namespace LuaScript.Tests
|
|||||||
for (int k = 1; k <= 5; k++)
|
for (int k = 1; k <= 5; k++)
|
||||||
{
|
{
|
||||||
var fields = Fields(2, 2, k);
|
var fields = Fields(2, 2, k);
|
||||||
bool ok = _worker.Execute("obj.x = obj.time * 10", fields, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out _, out _, out _, out _, out _, out string? error);
|
bool ok = _worker.Execute("obj.x = obj.time * 10", fields, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.Equal(k * 10d, fields[NativeProtocol.X]);
|
Assert.Equal(k * 10d, fields[NativeProtocol.X]);
|
||||||
}
|
}
|
||||||
@@ -210,12 +209,12 @@ namespace LuaScript.Tests
|
|||||||
var fields = Fields(2, 2, 0d);
|
var fields = Fields(2, 2, 0d);
|
||||||
|
|
||||||
bool timedOut = _worker.Execute(
|
bool timedOut = _worker.Execute(
|
||||||
"local x=0 while true do x=x+1 end", fields, NoStringParams, pixels, 2, 2, 1500, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out _, out _, out _, out _, out _, out string? error);
|
"local x=0 while true do x=x+1 end", fields, NoStringParams, pixels, 2, 2, 1500, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||||
Assert.False(timedOut);
|
Assert.False(timedOut);
|
||||||
Assert.Contains("timed out", error);
|
Assert.Contains("timed out", error);
|
||||||
|
|
||||||
var fields2 = Fields(2, 2, 3d);
|
var fields2 = Fields(2, 2, 3d);
|
||||||
bool ok = _worker.Execute("obj.x = obj.time", fields2, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out _, out _, out _, out _, out _, out error);
|
bool ok = _worker.Execute("obj.x = obj.time", fields2, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out error);
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.Equal(3d, fields2[NativeProtocol.X]);
|
Assert.Equal(3d, fields2[NativeProtocol.X]);
|
||||||
}
|
}
|
||||||
@@ -237,7 +236,7 @@ namespace LuaScript.Tests
|
|||||||
"obj.zoom = o.zoom obj.rz = o.rz obj.alpha = o.alpha " +
|
"obj.zoom = o.zoom obj.rz = o.rz obj.alpha = o.alpha " +
|
||||||
"obj.sx = o.sy obj.rzr = o.rzr";
|
"obj.sx = o.sy obj.rzr = o.rzr";
|
||||||
|
|
||||||
bool ok = _worker.Execute(script, fields, NoStringParams, pixels, 2, 2, 5000, resolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out _, out _, out _, out _, out _, out string? error);
|
bool ok = _worker.Execute(script, fields, NoStringParams, pixels, 2, 2, 5000, resolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.Equal(12d, fields[NativeProtocol.X]);
|
Assert.Equal(12d, fields[NativeProtocol.X]);
|
||||||
@@ -269,13 +268,13 @@ namespace LuaScript.Tests
|
|||||||
"local b = obj.getobject(\"a\") " +
|
"local b = obj.getobject(\"a\") " +
|
||||||
"obj.x = a.x + b.x";
|
"obj.x = a.x + b.x";
|
||||||
|
|
||||||
bool ok = _worker.Execute(script, Fields(2, 2, 0d), NoStringParams, pixels, 2, 2, 5000, resolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out _, out _, out _, out _, out _, out string? error);
|
bool ok = _worker.Execute(script, Fields(2, 2, 0d), NoStringParams, pixels, 2, 2, 5000, resolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.Equal(1, calls);
|
Assert.Equal(1, calls);
|
||||||
var fields = Fields(2, 2, 0d);
|
var fields = Fields(2, 2, 0d);
|
||||||
|
|
||||||
x = 20d;
|
x = 20d;
|
||||||
ok = _worker.Execute(script, fields, NoStringParams, pixels, 2, 2, 5000, resolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out _, out _, out _, out _, out _, out error);
|
ok = _worker.Execute(script, fields, NoStringParams, pixels, 2, 2, 5000, resolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out error);
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.Equal(2, calls);
|
Assert.Equal(2, calls);
|
||||||
Assert.Equal(40d, fields[NativeProtocol.X]);
|
Assert.Equal(40d, fields[NativeProtocol.X]);
|
||||||
@@ -292,7 +291,7 @@ namespace LuaScript.Tests
|
|||||||
const string script =
|
const string script =
|
||||||
"local o = obj.getobject(\"missing\") obj.x = o == nil and 1 or 0";
|
"local o = obj.getobject(\"missing\") obj.x = o == nil and 1 or 0";
|
||||||
|
|
||||||
bool ok = _worker.Execute(script, fields, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out _, out _, out _, out _, out _, out string? error);
|
bool ok = _worker.Execute(script, fields, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.Equal(1d, fields[NativeProtocol.X]);
|
Assert.Equal(1d, fields[NativeProtocol.X]);
|
||||||
@@ -310,7 +309,7 @@ namespace LuaScript.Tests
|
|||||||
|
|
||||||
bool ok = _worker.Execute(
|
bool ok = _worker.Execute(
|
||||||
"obj.draw() obj.draw(10, 20, 30, 2, 0.5, 0.25)",
|
"obj.draw() obj.draw(10, 20, 30, 2, 0.5, 0.25)",
|
||||||
fields, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, addDraw, NoSetAnchor,
|
fields, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, addDraw,
|
||||||
out _, out _, out _, out _, out _, out string? error);
|
out _, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
@@ -331,7 +330,7 @@ namespace LuaScript.Tests
|
|||||||
|
|
||||||
bool ok = _worker.Execute(
|
bool ok = _worker.Execute(
|
||||||
"obj.drawpoly(0,0,0, 10,0,0, 10,10,0, 0,10,0)",
|
"obj.drawpoly(0,0,0, 10,0,0, 10,10,0, 0,10,0)",
|
||||||
fields, NoStringParams, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, addDraw, NoSetAnchor,
|
fields, NoStringParams, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, addDraw,
|
||||||
out _, out _, out _, out _, out _, out string? error);
|
out _, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
@@ -353,7 +352,7 @@ namespace LuaScript.Tests
|
|||||||
|
|
||||||
bool ok = _worker.Execute(
|
bool ok = _worker.Execute(
|
||||||
"obj.drawpoly(0,0,0, 8,0,0, 8,8,0, 0,8,0, 1,1, 3,1, 3,3, 1,3, 0.5)",
|
"obj.drawpoly(0,0,0, 8,0,0, 8,8,0, 0,8,0, 1,1, 3,1, 3,3, 1,3, 0.5)",
|
||||||
fields, NoStringParams, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, addDraw, NoSetAnchor,
|
fields, NoStringParams, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, addDraw,
|
||||||
out _, out _, out _, out _, out _, out string? error);
|
out _, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
@@ -374,7 +373,7 @@ namespace LuaScript.Tests
|
|||||||
|
|
||||||
bool ok = _worker.Execute(
|
bool ok = _worker.Execute(
|
||||||
"obj.setoption('antialias', 0) obj.x = obj.getoption('antialias') obj.y = obj.getoption('unset')",
|
"obj.setoption('antialias', 0) obj.x = obj.getoption('antialias') obj.y = obj.getoption('unset')",
|
||||||
fields, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
|
fields, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw,
|
||||||
out _, out _, out _, out _, out _, out string? error);
|
out _, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
@@ -393,7 +392,7 @@ namespace LuaScript.Tests
|
|||||||
|
|
||||||
bool ok = _worker.Execute(
|
bool ok = _worker.Execute(
|
||||||
"obj.draw() obj.setoption('antialias', 0) obj.draw()",
|
"obj.draw() obj.setoption('antialias', 0) obj.draw()",
|
||||||
Fields(2, 2, 0d), NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, addDraw, NoSetAnchor,
|
Fields(2, 2, 0d), NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, addDraw,
|
||||||
out _, out _, out _, out _, out _, out string? error);
|
out _, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
@@ -402,157 +401,6 @@ namespace LuaScript.Tests
|
|||||||
Assert.Equal(0d, commands[1].Antialias);
|
Assert.Equal(0d, commands[1].Antialias);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Draw_CarriesBlendFromOption()
|
|
||||||
{
|
|
||||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
|
||||||
|
|
||||||
var pixels = new byte[16];
|
|
||||||
var commands = new System.Collections.Generic.List<DrawCommand>();
|
|
||||||
Action<DrawCommand> addDraw = commands.Add;
|
|
||||||
|
|
||||||
bool ok = _worker.Execute(
|
|
||||||
"obj.draw() obj.setoption('blend', 3) obj.draw()",
|
|
||||||
Fields(2, 2, 0d), NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, addDraw, NoSetAnchor,
|
|
||||||
out _, out _, out _, out _, out _, out string? error);
|
|
||||||
|
|
||||||
Assert.True(ok, error);
|
|
||||||
Assert.Equal(2, commands.Count);
|
|
||||||
Assert.Equal(0d, commands[0].Blend);
|
|
||||||
Assert.Equal(3d, commands[1].Blend);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void DrawPoly_CarriesBlendFromOption()
|
|
||||||
{
|
|
||||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
|
||||||
|
|
||||||
var pixels = new byte[4 * 4 * 4];
|
|
||||||
var commands = new System.Collections.Generic.List<DrawCommand>();
|
|
||||||
Action<DrawCommand> addDraw = commands.Add;
|
|
||||||
|
|
||||||
bool ok = _worker.Execute(
|
|
||||||
"obj.setoption('blend', 11) obj.drawpoly(0,0,0, 10,0,0, 10,10,0, 0,10,0)",
|
|
||||||
Fields(4, 4, 0d), NoStringParams, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, addDraw, NoSetAnchor,
|
|
||||||
out _, out _, out _, out _, out _, out string? error);
|
|
||||||
|
|
||||||
Assert.True(ok, error);
|
|
||||||
Assert.Single(commands);
|
|
||||||
Assert.Equal(11d, commands[0].Blend);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void SetOption_DrawState_WritesBackFlag()
|
|
||||||
{
|
|
||||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
|
||||||
|
|
||||||
var pixels = new byte[16];
|
|
||||||
|
|
||||||
var fTrue = Fields(2, 2, 0d);
|
|
||||||
bool okTrue = _worker.Execute(
|
|
||||||
"obj.setoption('draw_state', true)",
|
|
||||||
fTrue, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
|
|
||||||
out _, out _, out _, out _, out _, out string? errorTrue);
|
|
||||||
Assert.True(okTrue, errorTrue);
|
|
||||||
Assert.Equal(1d, fTrue[NativeProtocol.DrawState]);
|
|
||||||
|
|
||||||
var fFalse = Fields(2, 2, 0d);
|
|
||||||
bool okFalse = _worker.Execute(
|
|
||||||
"obj.setoption('draw_state', false)",
|
|
||||||
fFalse, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
|
|
||||||
out _, out _, out _, out _, out _, out string? errorFalse);
|
|
||||||
Assert.True(okFalse, errorFalse);
|
|
||||||
Assert.Equal(2d, fFalse[NativeProtocol.DrawState]);
|
|
||||||
|
|
||||||
var fUnset = Fields(2, 2, 0d);
|
|
||||||
bool okUnset = _worker.Execute(
|
|
||||||
"obj.x = 1",
|
|
||||||
fUnset, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
|
|
||||||
out _, out _, out _, out _, out _, out string? errorUnset);
|
|
||||||
Assert.True(okUnset, errorUnset);
|
|
||||||
Assert.Equal(0d, fUnset[NativeProtocol.DrawState]);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void SetAnchor_FillsLuaVariableFromResolver()
|
|
||||||
{
|
|
||||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
|
||||||
|
|
||||||
var pixels = new byte[16];
|
|
||||||
var fields = Fields(2, 2, 0d);
|
|
||||||
|
|
||||||
string? capturedGroup = null;
|
|
||||||
int capturedCount = -1;
|
|
||||||
Action<string, int, bool, int, double[]> setAnchor = (group, count, is3D, connection, positions) =>
|
|
||||||
{
|
|
||||||
capturedGroup = group;
|
|
||||||
capturedCount = count;
|
|
||||||
int stride = is3D ? 3 : 2;
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
positions[i * stride + 0] = i * 10;
|
|
||||||
positions[i * stride + 1] = i * 10 + 5;
|
|
||||||
if (is3D)
|
|
||||||
positions[i * stride + 2] = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
string script =
|
|
||||||
"local n = obj.setanchor('pos', 2, 'loop')\n" +
|
|
||||||
"obj.x = n\n" +
|
|
||||||
"obj.y = pos[1]\n" +
|
|
||||||
"obj.z = pos[3]";
|
|
||||||
|
|
||||||
bool ok = _worker.Execute(script, fields, NoStringParams, pixels, 2, 2, 5000,
|
|
||||||
NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, setAnchor,
|
|
||||||
out _, out _, out _, out _, out _, out string? error);
|
|
||||||
|
|
||||||
Assert.True(ok, error);
|
|
||||||
Assert.Equal("pos", capturedGroup);
|
|
||||||
Assert.Equal(2, capturedCount);
|
|
||||||
Assert.Equal(2d, fields[NativeProtocol.X]);
|
|
||||||
Assert.Equal(0d, fields[NativeProtocol.Y]);
|
|
||||||
Assert.Equal(10d, fields[NativeProtocol.Z]);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void DrawTarget_TempBuffer_CompositesAndCopiesBack()
|
|
||||||
{
|
|
||||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
|
||||||
|
|
||||||
var pixels = new byte[2 * 2 * 4];
|
|
||||||
var fields = Fields(2, 2, 0d);
|
|
||||||
|
|
||||||
string script =
|
|
||||||
"obj.setpixel(0,0,255,0,0,255)\n" +
|
|
||||||
"obj.setpixel(1,0,0,255,0,255)\n" +
|
|
||||||
"obj.setpixel(0,1,0,0,255,255)\n" +
|
|
||||||
"obj.setpixel(1,1,255,255,0,255)\n" +
|
|
||||||
"obj.setoption('drawtarget','tempbuffer',2,2)\n" +
|
|
||||||
"obj.draw(1,1,0,1,1,0)\n" +
|
|
||||||
"obj.setoption('drawtarget','framebuffer')\n" +
|
|
||||||
"obj.copybuffer('obj','tmp')";
|
|
||||||
|
|
||||||
bool ok = _worker.Execute(
|
|
||||||
script, 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.True(dirty);
|
|
||||||
|
|
||||||
Assert.Equal(0, pixels[0]);
|
|
||||||
Assert.Equal(0, pixels[1]);
|
|
||||||
Assert.Equal(255, pixels[2]);
|
|
||||||
Assert.Equal(255, pixels[3]);
|
|
||||||
|
|
||||||
int i11 = (1 * 2 + 1) * 4;
|
|
||||||
Assert.Equal(0, pixels[i11]);
|
|
||||||
Assert.Equal(255, pixels[i11 + 1]);
|
|
||||||
Assert.Equal(255, pixels[i11 + 2]);
|
|
||||||
Assert.Equal(255, pixels[i11 + 3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LoadText_RoundTripsThroughCallback()
|
public void LoadText_RoundTripsThroughCallback()
|
||||||
{
|
{
|
||||||
@@ -581,7 +429,7 @@ namespace LuaScript.Tests
|
|||||||
|
|
||||||
bool ok = _worker.Execute(
|
bool ok = _worker.Execute(
|
||||||
"obj.setfont('Meiryo', 40, 3, 0x112233) obj.load('text', 'Hi')",
|
"obj.setfont('Meiryo', 40, 3, 0x112233) obj.load('text', 'Hi')",
|
||||||
fields, NoStringParams, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, loadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
|
fields, NoStringParams, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, loadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw,
|
||||||
out bool dirty, out bool bufferReplaced, out byte[]? newPixels, out int rw, out int rh, out string? error);
|
out bool dirty, out bool bufferReplaced, out byte[]? newPixels, out int rw, out int rh, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
@@ -621,7 +469,7 @@ namespace LuaScript.Tests
|
|||||||
|
|
||||||
bool ok = _worker.Execute(
|
bool ok = _worker.Execute(
|
||||||
"obj.load('image', 'C:/sample.png')",
|
"obj.load('image', 'C:/sample.png')",
|
||||||
fields, NoStringParams, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, loadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
|
fields, NoStringParams, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, loadImage, NoLoadMovie, NoAddEffect, NoAddDraw,
|
||||||
out bool dirty, out bool bufferReplaced, out byte[]? newPixels, out int rw, out int rh, out string? error);
|
out bool dirty, out bool bufferReplaced, out byte[]? newPixels, out int rw, out int rh, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
@@ -658,7 +506,7 @@ namespace LuaScript.Tests
|
|||||||
|
|
||||||
bool ok = _worker.Execute(
|
bool ok = _worker.Execute(
|
||||||
"obj.load('movie', 'C:/clip.mp4', 1.5)",
|
"obj.load('movie', 'C:/clip.mp4', 1.5)",
|
||||||
fields, NoStringParams, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, loadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
|
fields, NoStringParams, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, loadMovie, NoAddEffect, NoAddDraw,
|
||||||
out bool dirty, out bool bufferReplaced, out byte[]? newPixels, out int rw, out int rh, out string? error);
|
out bool dirty, out bool bufferReplaced, out byte[]? newPixels, out int rw, out int rh, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
@@ -683,7 +531,7 @@ namespace LuaScript.Tests
|
|||||||
|
|
||||||
bool ok = _worker.Execute(
|
bool ok = _worker.Execute(
|
||||||
"obj.x = obj.getvalue('track0') obj.y = obj.getvalue('alpha') obj.z = obj.getvalue('unknown')",
|
"obj.x = obj.getvalue('track0') obj.y = obj.getvalue('alpha') obj.z = obj.getvalue('unknown')",
|
||||||
fields, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
|
fields, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw,
|
||||||
out _, out _, out _, out _, out _, out string? error);
|
out _, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
@@ -710,7 +558,7 @@ namespace LuaScript.Tests
|
|||||||
"for y=0,obj.h-1 do for x=0,obj.w-1 do obj.setpixel(x,y,0,0,0,0) end end " +
|
"for y=0,obj.h-1 do for x=0,obj.w-1 do obj.setpixel(x,y,0,0,0,0) end end " +
|
||||||
"obj.copybuffer('obj','tmp')";
|
"obj.copybuffer('obj','tmp')";
|
||||||
|
|
||||||
bool ok = _worker.Execute(script, fields, NoStringParams, pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out bool dirty, out _, out _, out _, out _, out string? error);
|
bool ok = _worker.Execute(script, fields, NoStringParams, pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out bool dirty, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.True(dirty);
|
Assert.True(dirty);
|
||||||
@@ -729,11 +577,11 @@ namespace LuaScript.Tests
|
|||||||
stored[3] = 255; stored[7] = 255; stored[11] = 255; stored[15] = 255;
|
stored[3] = 255; stored[7] = 255; stored[11] = 255; stored[15] = 255;
|
||||||
|
|
||||||
var save = (byte[])stored.Clone();
|
var save = (byte[])stored.Clone();
|
||||||
bool ok = _worker.Execute("obj.copybuffer('cache:foo','obj')", Fields(w, h, 0d), NoStringParams, save, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out _, out _, out _, out _, out _, out string? error);
|
bool ok = _worker.Execute("obj.copybuffer('cache:foo','obj')", Fields(w, h, 0d), NoStringParams, save, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
|
|
||||||
var blank = new byte[w * h * 4];
|
var blank = new byte[w * h * 4];
|
||||||
ok = _worker.Execute("obj.copybuffer('obj','cache:foo')", Fields(w, h, 0d), NoStringParams, blank, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out bool dirty, out _, out _, out _, out _, out error);
|
ok = _worker.Execute("obj.copybuffer('obj','cache:foo')", Fields(w, h, 0d), NoStringParams, blank, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out bool dirty, out _, out _, out _, out _, out error);
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.True(dirty);
|
Assert.True(dirty);
|
||||||
Assert.Equal(stored, blank);
|
Assert.Equal(stored, blank);
|
||||||
@@ -747,12 +595,12 @@ namespace LuaScript.Tests
|
|||||||
var pixels = new byte[16];
|
var pixels = new byte[16];
|
||||||
var fields = Fields(2, 2, 0d);
|
var fields = Fields(2, 2, 0d);
|
||||||
|
|
||||||
bool ok = _worker.Execute("obj.x = missing.value", fields, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out _, out _, out _, out _, out _, out string? error);
|
bool ok = _worker.Execute("obj.x = missing.value", fields, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||||
Assert.False(ok);
|
Assert.False(ok);
|
||||||
Assert.False(string.IsNullOrEmpty(error));
|
Assert.False(string.IsNullOrEmpty(error));
|
||||||
|
|
||||||
var fields2 = Fields(2, 2, 7d);
|
var fields2 = Fields(2, 2, 7d);
|
||||||
bool ok2 = _worker.Execute("obj.x = obj.time", fields2, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out _, out _, out _, out _, out _, out error);
|
bool ok2 = _worker.Execute("obj.x = obj.time", fields2, NoStringParams, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out error);
|
||||||
Assert.True(ok2, error);
|
Assert.True(ok2, error);
|
||||||
Assert.Equal(7d, fields2[NativeProtocol.X]);
|
Assert.Equal(7d, fields2[NativeProtocol.X]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,89 +0,0 @@
|
|||||||
using LuaScript;
|
|
||||||
|
|
||||||
namespace LuaScript.Tests
|
|
||||||
{
|
|
||||||
public class SoftwareCompositorTests
|
|
||||||
{
|
|
||||||
private static byte[] Solid(int w, int h, byte b, byte g, byte r, byte a)
|
|
||||||
{
|
|
||||||
var buffer = new byte[w * h * 4];
|
|
||||||
for (int i = 0; i < w * h; i++)
|
|
||||||
{
|
|
||||||
buffer[i * 4] = b;
|
|
||||||
buffer[i * 4 + 1] = g;
|
|
||||||
buffer[i * 4 + 2] = r;
|
|
||||||
buffer[i * 4 + 3] = a;
|
|
||||||
}
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void DrawInto_NearestOpaque_BlitsSinglePixel()
|
|
||||||
{
|
|
||||||
var dst = new byte[3 * 3 * 4];
|
|
||||||
var src = Solid(1, 1, 255, 255, 255, 255);
|
|
||||||
|
|
||||||
SoftwareCompositor.DrawInto(dst, 3, 3, src, 1, 1, 1.5, 1.5, 1d, 0d, 1d, linear: false);
|
|
||||||
|
|
||||||
int center = (1 * 3 + 1) * 4;
|
|
||||||
Assert.Equal(255, dst[center]);
|
|
||||||
Assert.Equal(255, dst[center + 1]);
|
|
||||||
Assert.Equal(255, dst[center + 2]);
|
|
||||||
Assert.Equal(255, dst[center + 3]);
|
|
||||||
|
|
||||||
Assert.Equal(0, dst[0]);
|
|
||||||
Assert.Equal(0, dst[(0 * 3 + 0) * 4 + 3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void DrawInto_HalfAlphaOverOpaque_BlendsPremultiplied()
|
|
||||||
{
|
|
||||||
var dst = Solid(1, 1, 0, 0, 0, 255);
|
|
||||||
var src = Solid(1, 1, 255, 255, 255, 255);
|
|
||||||
|
|
||||||
SoftwareCompositor.DrawInto(dst, 1, 1, src, 1, 1, 0.5, 0.5, 1d, 0d, 0.5, linear: false);
|
|
||||||
|
|
||||||
Assert.Equal(127, dst[0]);
|
|
||||||
Assert.Equal(127, dst[1]);
|
|
||||||
Assert.Equal(127, dst[2]);
|
|
||||||
Assert.Equal(255, dst[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void DrawInto_OutOfBounds_LeavesDestinationUnchanged()
|
|
||||||
{
|
|
||||||
var dst = new byte[2 * 2 * 4];
|
|
||||||
var src = Solid(1, 1, 255, 255, 255, 255);
|
|
||||||
|
|
||||||
SoftwareCompositor.DrawInto(dst, 2, 2, src, 1, 1, 100d, 100d, 1d, 0d, 1d, linear: false);
|
|
||||||
|
|
||||||
foreach (var value in dst)
|
|
||||||
Assert.Equal(0, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void DrawPolyInto_IdentityAffine_CopiesSource()
|
|
||||||
{
|
|
||||||
var src = new byte[2 * 2 * 4];
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
src[i * 4] = (byte)(i + 1);
|
|
||||||
src[i * 4 + 1] = (byte)(i + 10);
|
|
||||||
src[i * 4 + 2] = (byte)(i + 20);
|
|
||||||
src[i * 4 + 3] = 255;
|
|
||||||
}
|
|
||||||
var dst = new byte[2 * 2 * 4];
|
|
||||||
|
|
||||||
double[] poly =
|
|
||||||
[
|
|
||||||
0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 2, 0,
|
|
||||||
0, 0, 2, 0, 2, 2, 0, 2,
|
|
||||||
1,
|
|
||||||
];
|
|
||||||
|
|
||||||
SoftwareCompositor.DrawPolyInto(dst, 2, 2, src, 2, 2, poly, 1d, linear: false);
|
|
||||||
|
|
||||||
Assert.Equal(src, dst);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.Immutable;
|
|
||||||
|
|
||||||
namespace LuaScript.Anchor
|
|
||||||
{
|
|
||||||
internal enum AnchorConnection
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Line,
|
|
||||||
Loop,
|
|
||||||
Star,
|
|
||||||
Arm,
|
|
||||||
}
|
|
||||||
|
|
||||||
internal readonly record struct AnchorOptions(AnchorConnection Connection, bool Is3D);
|
|
||||||
|
|
||||||
internal readonly record struct AnchorRequestData(string Group, int Count, AnchorConnection Connection, bool Is3D);
|
|
||||||
|
|
||||||
internal static class AnchorSupport
|
|
||||||
{
|
|
||||||
public const int MaxAnchors = 32;
|
|
||||||
public const string TrackGroup = "track";
|
|
||||||
|
|
||||||
public static int ClampCount(int count) => Math.Clamp(count, 0, MaxAnchors);
|
|
||||||
|
|
||||||
public static void ApplyOption(string option, ref AnchorConnection connection, ref bool is3D)
|
|
||||||
{
|
|
||||||
switch (option)
|
|
||||||
{
|
|
||||||
case "line": connection = AnchorConnection.Line; break;
|
|
||||||
case "loop": connection = AnchorConnection.Loop; break;
|
|
||||||
case "star": connection = AnchorConnection.Star; break;
|
|
||||||
case "arm": connection = AnchorConnection.Arm; break;
|
|
||||||
case "xyz": is3D = true; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static (double X, double Y) DefaultPosition(int index)
|
|
||||||
{
|
|
||||||
int col = index % 8;
|
|
||||||
int row = index / 8;
|
|
||||||
return ((col - 3.5) * 60d, (row - 1.5) * 60d);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ResolvePosition(IReadOnlyList<LuaAnchorPoint>? source, string group, int index,
|
|
||||||
out double x, out double y, out double z)
|
|
||||||
{
|
|
||||||
if (source is not null)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < source.Count; i++)
|
|
||||||
{
|
|
||||||
var a = source[i];
|
|
||||||
if (a.Index == index && string.Equals(a.Group, group, StringComparison.Ordinal))
|
|
||||||
{
|
|
||||||
x = a.X;
|
|
||||||
y = a.Y;
|
|
||||||
z = a.Z;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var (dx, dy) = DefaultPosition(index);
|
|
||||||
x = dx;
|
|
||||||
y = dy;
|
|
||||||
z = 0d;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ImmutableList<LuaAnchorPoint> ApplyDrag(
|
|
||||||
ImmutableList<LuaAnchorPoint> source, string group, int index, double dx, double dy, double dz)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < source.Count; i++)
|
|
||||||
{
|
|
||||||
var a = source[i];
|
|
||||||
if (a.Index == index && string.Equals(a.Group, group, StringComparison.Ordinal))
|
|
||||||
{
|
|
||||||
return source.SetItem(i, new LuaAnchorPoint
|
|
||||||
{
|
|
||||||
Group = group,
|
|
||||||
Index = index,
|
|
||||||
X = a.X + dx,
|
|
||||||
Y = a.Y + dy,
|
|
||||||
Z = a.Z + dz,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var (bx, by) = DefaultPosition(index);
|
|
||||||
return source.Add(new LuaAnchorPoint
|
|
||||||
{
|
|
||||||
Group = group,
|
|
||||||
Index = index,
|
|
||||||
X = bx + dx,
|
|
||||||
Y = by + dy,
|
|
||||||
Z = dz,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
namespace LuaScript.Anchor
|
|
||||||
{
|
|
||||||
public sealed class LuaAnchorPoint
|
|
||||||
{
|
|
||||||
public string Group { get; set; } = string.Empty;
|
|
||||||
public int Index { get; set; }
|
|
||||||
public double X { get; set; }
|
|
||||||
public double Y { get; set; }
|
|
||||||
public double Z { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +1,7 @@
|
|||||||
using LuaScript.Anchor;
|
|
||||||
|
|
||||||
namespace LuaScript
|
namespace LuaScript
|
||||||
{
|
{
|
||||||
internal sealed class AviUtlScriptContext
|
internal sealed class AviUtlScriptContext
|
||||||
{
|
{
|
||||||
public IReadOnlyList<LuaAnchorPoint>? AnchorSource { get; set; }
|
|
||||||
|
|
||||||
private readonly List<AnchorRequestData> _anchorRequests = [];
|
|
||||||
|
|
||||||
public IReadOnlyList<AnchorRequestData> AnchorRequests => _anchorRequests;
|
|
||||||
|
|
||||||
internal void AddAnchorRequest(in AnchorRequestData request) => _anchorRequests.Add(request);
|
|
||||||
|
|
||||||
internal void ClearAnchorRequests() => _anchorRequests.Clear();
|
|
||||||
|
|
||||||
public bool IsPlaying { get; set; }
|
public bool IsPlaying { get; set; }
|
||||||
public bool IsPaused { get; set; }
|
public bool IsPaused { get; set; }
|
||||||
public string SceneId { get; set; } = string.Empty;
|
public string SceneId { get; set; } = string.Empty;
|
||||||
@@ -54,8 +42,6 @@ namespace LuaScript
|
|||||||
public bool HasColor { get; set; }
|
public bool HasColor { get; set; }
|
||||||
public double ColorValue { get; set; }
|
public double ColorValue { get; set; }
|
||||||
|
|
||||||
public bool? DrawStateOverride { get; set; }
|
|
||||||
|
|
||||||
public double Time { get; set; }
|
public double Time { get; set; }
|
||||||
public int Frame { get; set; }
|
public int Frame { get; set; }
|
||||||
public int TotalFrame { get; set; }
|
public int TotalFrame { get; set; }
|
||||||
@@ -99,53 +85,6 @@ namespace LuaScript
|
|||||||
|
|
||||||
internal void ClearDraws() => _drawCommands.Clear();
|
internal void ClearDraws() => _drawCommands.Clear();
|
||||||
|
|
||||||
private bool _drawTargetTemp;
|
|
||||||
|
|
||||||
internal void ResetDrawTarget() => _drawTargetTemp = false;
|
|
||||||
|
|
||||||
internal void SetDrawTarget(bool temp, int width, int height, bool hasSize)
|
|
||||||
{
|
|
||||||
_drawTargetTemp = temp;
|
|
||||||
if (temp && hasSize)
|
|
||||||
{
|
|
||||||
int w = Math.Max(1, width);
|
|
||||||
int h = Math.Max(1, height);
|
|
||||||
_buffers["t"] = (new byte[w * h * 4], w, h);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void SubmitDraw(DrawCommand command)
|
|
||||||
{
|
|
||||||
if (!_drawTargetTemp)
|
|
||||||
{
|
|
||||||
_drawCommands.Add(command);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CompositeToTemp(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CompositeToTemp(DrawCommand command)
|
|
||||||
{
|
|
||||||
EnsurePixelBuffer();
|
|
||||||
var src = _pixelBuffer;
|
|
||||||
if (src is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!_buffers.TryGetValue("t", out var temp))
|
|
||||||
{
|
|
||||||
int w = Math.Max(1, ImageWidth);
|
|
||||||
int h = Math.Max(1, ImageHeight);
|
|
||||||
temp = (new byte[w * h * 4], w, h);
|
|
||||||
_buffers["t"] = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool linear = command.Antialias != 0d;
|
|
||||||
if (command.Poly is { } poly)
|
|
||||||
SoftwareCompositor.DrawPolyInto(temp.Data, temp.Width, temp.Height, src, ImageWidth, ImageHeight, poly, command.Alpha, linear);
|
|
||||||
else
|
|
||||||
SoftwareCompositor.DrawInto(temp.Data, temp.Width, temp.Height, src, ImageWidth, ImageHeight, command.Ox, command.Oy, command.Zoom, command.Aspect, command.Alpha, linear);
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly Dictionary<string, (byte[] Data, int Width, int Height)> _buffers = new(StringComparer.Ordinal);
|
private readonly Dictionary<string, (byte[] Data, int Width, int Height)> _buffers = new(StringComparer.Ordinal);
|
||||||
|
|
||||||
internal bool CopyBuffer(string dst, string src)
|
internal bool CopyBuffer(string dst, string src)
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
using YukkuriMovieMaker.Project;
|
|
||||||
|
|
||||||
namespace LuaScript.Compat
|
|
||||||
{
|
|
||||||
internal static class BlendModeMap
|
|
||||||
{
|
|
||||||
private static readonly Blend[] Order =
|
|
||||||
[
|
|
||||||
Blend.Normal,
|
|
||||||
Blend.Dissolve,
|
|
||||||
Blend.Darker,
|
|
||||||
Blend.Multiply,
|
|
||||||
Blend.ColorBurn,
|
|
||||||
Blend.LinearBurn,
|
|
||||||
Blend.Lighter,
|
|
||||||
Blend.Screen,
|
|
||||||
Blend.ColorDodge,
|
|
||||||
Blend.LinearDodge,
|
|
||||||
Blend.Add,
|
|
||||||
Blend.Overlay,
|
|
||||||
Blend.SoftLight,
|
|
||||||
Blend.HardLight,
|
|
||||||
Blend.VividLight,
|
|
||||||
Blend.LinearLight,
|
|
||||||
Blend.PinLight,
|
|
||||||
Blend.HardMix,
|
|
||||||
Blend.Difference,
|
|
||||||
Blend.Exclusion,
|
|
||||||
Blend.Subtract,
|
|
||||||
Blend.Division,
|
|
||||||
Blend.Hue,
|
|
||||||
Blend.Saturation,
|
|
||||||
Blend.Color,
|
|
||||||
Blend.Luminosity,
|
|
||||||
Blend.LighterColor,
|
|
||||||
Blend.DestinationOver,
|
|
||||||
Blend.DarkerColor,
|
|
||||||
Blend.DestinationOut,
|
|
||||||
Blend.SourceAtop,
|
|
||||||
Blend.XOR,
|
|
||||||
Blend.MaskInvert,
|
|
||||||
];
|
|
||||||
|
|
||||||
public static Blend Resolve(double value)
|
|
||||||
{
|
|
||||||
if (double.IsNaN(value))
|
|
||||||
return Blend.Normal;
|
|
||||||
|
|
||||||
int index = (int)value;
|
|
||||||
return (uint)index < (uint)Order.Length ? Order[index] : Blend.Normal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,6 +8,5 @@ namespace LuaScript
|
|||||||
double Alpha,
|
double Alpha,
|
||||||
double Aspect,
|
double Aspect,
|
||||||
double[]? Poly = null,
|
double[]? Poly = null,
|
||||||
double Antialias = 1d,
|
double Antialias = 1d);
|
||||||
double Blend = 0d);
|
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using LuaScript.Compat;
|
|
||||||
using Vortice.Direct2D1;
|
using Vortice.Direct2D1;
|
||||||
using Vortice.Direct2D1.Effects;
|
using Vortice.Direct2D1.Effects;
|
||||||
using YukkuriMovieMaker.Commons;
|
using YukkuriMovieMaker.Commons;
|
||||||
using YukkuriMovieMaker.Player;
|
|
||||||
using Blend = YukkuriMovieMaker.Project.Blend;
|
|
||||||
|
|
||||||
namespace LuaScript
|
namespace LuaScript
|
||||||
{
|
{
|
||||||
@@ -18,8 +15,6 @@ namespace LuaScript
|
|||||||
private ID2D1Bitmap1? _source;
|
private ID2D1Bitmap1? _source;
|
||||||
private ID2D1Bitmap1? _target;
|
private ID2D1Bitmap1? _target;
|
||||||
private AffineTransform2D? _placement;
|
private AffineTransform2D? _placement;
|
||||||
private Opacity? _opacityEffect;
|
|
||||||
private ID2D1Image? _opacityOutput;
|
|
||||||
private int _sourceWidth;
|
private int _sourceWidth;
|
||||||
private int _sourceHeight;
|
private int _sourceHeight;
|
||||||
private int _targetWidth;
|
private int _targetWidth;
|
||||||
@@ -82,14 +77,13 @@ namespace LuaScript
|
|||||||
var interpolation = cmd.Antialias != 0d
|
var interpolation = cmd.Antialias != 0d
|
||||||
? BitmapInterpolationMode.Linear
|
? BitmapInterpolationMode.Linear
|
||||||
: BitmapInterpolationMode.NearestNeighbor;
|
: BitmapInterpolationMode.NearestNeighbor;
|
||||||
var blend = BlendModeMap.Resolve(cmd.Blend);
|
|
||||||
|
|
||||||
if (cmd.Poly is { } poly)
|
if (cmd.Poly is { } poly)
|
||||||
{
|
{
|
||||||
if (!DrawPolyMath.TrySolveAffine(poly, out var affine))
|
if (!DrawPolyMath.TrySolveAffine(poly, out var affine))
|
||||||
continue;
|
continue;
|
||||||
rt.Transform = affine * toTarget;
|
rt.Transform = affine * toTarget;
|
||||||
DrawSource(rt, (float)Math.Clamp(poly[20], 0d, 1d), interpolation, blend);
|
rt.DrawBitmap(_source, (float)Math.Clamp(poly[20], 0d, 1d), interpolation);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +98,7 @@ namespace LuaScript
|
|||||||
Matrix3x2.CreateTranslation((float)(cmd.Ox - originX), (float)(cmd.Oy - originY));
|
Matrix3x2.CreateTranslation((float)(cmd.Ox - originX), (float)(cmd.Oy - originY));
|
||||||
|
|
||||||
rt.Transform = matrix;
|
rt.Transform = matrix;
|
||||||
DrawSource(rt, opacity, interpolation, blend);
|
rt.DrawBitmap(_source, opacity, interpolation);
|
||||||
}
|
}
|
||||||
rt.Transform = Matrix3x2.Identity;
|
rt.Transform = Matrix3x2.Identity;
|
||||||
dc.EndDraw();
|
dc.EndDraw();
|
||||||
@@ -114,25 +108,6 @@ namespace LuaScript
|
|||||||
return _placement.Output;
|
return _placement.Output;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawSource(ID2D1RenderTarget rt, float opacity, BitmapInterpolationMode interpolation, Blend blend)
|
|
||||||
{
|
|
||||||
if (blend == Blend.Normal)
|
|
||||||
{
|
|
||||||
rt.DrawBitmap(_source!, opacity, interpolation);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var interp = ToImageInterpolation(interpolation);
|
|
||||||
_opacityEffect!.Value = opacity;
|
|
||||||
if (blend.IsCompositionEffect())
|
|
||||||
_ctx.DeviceContext.DrawImage(_opacityOutput!, interpolationMode: interp, compositeMode: blend.ToD2DCompositionMode());
|
|
||||||
else
|
|
||||||
_ctx.DeviceContext.BlendImage(_opacityOutput!, blend.ToD2DBlendMode(), null, null, interp);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static InterpolationMode ToImageInterpolation(BitmapInterpolationMode mode) =>
|
|
||||||
mode == BitmapInterpolationMode.Linear ? InterpolationMode.Linear : InterpolationMode.NearestNeighbor;
|
|
||||||
|
|
||||||
private void EnsureSource(int width, int height)
|
private void EnsureSource(int width, int height)
|
||||||
{
|
{
|
||||||
if (_source is not null && _sourceWidth == width && _sourceHeight == height)
|
if (_source is not null && _sourceWidth == width && _sourceHeight == height)
|
||||||
@@ -142,13 +117,6 @@ namespace LuaScript
|
|||||||
_source = _ctx.DeviceContext.CreateEmptyBitmap(width, height, BitmapOptions.Target);
|
_source = _ctx.DeviceContext.CreateEmptyBitmap(width, height, BitmapOptions.Target);
|
||||||
_sourceWidth = width;
|
_sourceWidth = width;
|
||||||
_sourceHeight = height;
|
_sourceHeight = height;
|
||||||
|
|
||||||
if (_opacityEffect is null)
|
|
||||||
{
|
|
||||||
_opacityEffect = new Opacity(_ctx.DeviceContext);
|
|
||||||
_opacityOutput = _opacityEffect.Output;
|
|
||||||
}
|
|
||||||
_opacityEffect.SetInput(0, _source, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EnsureTarget(int width, int height)
|
private void EnsureTarget(int width, int height)
|
||||||
@@ -171,13 +139,9 @@ namespace LuaScript
|
|||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_placement?.Dispose();
|
_placement?.Dispose();
|
||||||
_opacityOutput?.Dispose();
|
|
||||||
_opacityEffect?.Dispose();
|
|
||||||
_source?.Dispose();
|
_source?.Dispose();
|
||||||
_target?.Dispose();
|
_target?.Dispose();
|
||||||
_placement = null;
|
_placement = null;
|
||||||
_opacityOutput = null;
|
|
||||||
_opacityEffect = null;
|
|
||||||
_source = null;
|
_source = null;
|
||||||
_target = null;
|
_target = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ namespace LuaScript.Engine
|
|||||||
|
|
||||||
private readonly byte[] _callbackTag = new byte[NativeProtocol.CallbackTagMax];
|
private readonly byte[] _callbackTag = new byte[NativeProtocol.CallbackTagMax];
|
||||||
private readonly byte[] _lastCallbackTag = new byte[NativeProtocol.CallbackTagMax];
|
private readonly byte[] _lastCallbackTag = new byte[NativeProtocol.CallbackTagMax];
|
||||||
private readonly double[] _anchorBuffer = new double[Anchor.AnchorSupport.MaxAnchors * 3];
|
|
||||||
private int _lastCallbackTagLength = -1;
|
private int _lastCallbackTagLength = -1;
|
||||||
private string _lastCallbackTagText = string.Empty;
|
private string _lastCallbackTagText = string.Empty;
|
||||||
private byte[]? _resultBuffer;
|
private byte[]? _resultBuffer;
|
||||||
@@ -60,7 +59,6 @@ namespace LuaScript.Engine
|
|||||||
Func<string, double, (byte[] buffer, int w, int h)> loadMovie,
|
Func<string, double, (byte[] buffer, int w, int h)> loadMovie,
|
||||||
Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect,
|
Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect,
|
||||||
Action<DrawCommand> addDraw,
|
Action<DrawCommand> addDraw,
|
||||||
Action<string, int, bool, int, double[]> setAnchor,
|
|
||||||
out bool pixelsDirty,
|
out bool pixelsDirty,
|
||||||
out bool bufferReplaced,
|
out bool bufferReplaced,
|
||||||
out byte[]? newPixels,
|
out byte[]? newPixels,
|
||||||
@@ -116,7 +114,7 @@ namespace LuaScript.Engine
|
|||||||
if (status != NativeProtocol.StatusCallback)
|
if (status != NativeProtocol.StatusCallback)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
DispatchCallback(view, resolveObject, loadFigure, loadText, loadImage, loadMovie, addEffect, addDraw, setAnchor);
|
DispatchCallback(view, resolveObject, loadFigure, loadText, loadImage, loadMovie, addEffect, addDraw);
|
||||||
_workEvent.Set();
|
_workEvent.Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,8 +130,6 @@ namespace LuaScript.Engine
|
|||||||
for (int i = NativeProtocol.FirstWritableField; i <= NativeProtocol.LastWritableField; i++)
|
for (int i = NativeProtocol.FirstWritableField; i <= NativeProtocol.LastWritableField; i++)
|
||||||
fields[i] = view.ReadDouble(NativeProtocol.FieldsOffset + i * 8);
|
fields[i] = view.ReadDouble(NativeProtocol.FieldsOffset + i * 8);
|
||||||
|
|
||||||
fields[NativeProtocol.DrawState] = view.ReadDouble(NativeProtocol.FieldsOffset + NativeProtocol.DrawState * 8);
|
|
||||||
|
|
||||||
resultWidth = view.ReadInt32(NativeProtocol.OffWidth);
|
resultWidth = view.ReadInt32(NativeProtocol.OffWidth);
|
||||||
resultHeight = view.ReadInt32(NativeProtocol.OffHeight);
|
resultHeight = view.ReadInt32(NativeProtocol.OffHeight);
|
||||||
bufferReplaced = resultWidth != width || resultHeight != height;
|
bufferReplaced = resultWidth != width || resultHeight != height;
|
||||||
@@ -221,8 +217,7 @@ namespace LuaScript.Engine
|
|||||||
Func<string, (byte[] buffer, int w, int h)> loadImage,
|
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)> loadMovie,
|
||||||
Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect,
|
Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect,
|
||||||
Action<DrawCommand> addDraw,
|
Action<DrawCommand> addDraw)
|
||||||
Action<string, int, bool, int, double[]> setAnchor)
|
|
||||||
{
|
{
|
||||||
int kind = view.ReadInt32(NativeProtocol.OffCallbackKind);
|
int kind = view.ReadInt32(NativeProtocol.OffCallbackKind);
|
||||||
switch (kind)
|
switch (kind)
|
||||||
@@ -251,33 +246,9 @@ namespace LuaScript.Engine
|
|||||||
case NativeProtocol.CbKindDrawPoly:
|
case NativeProtocol.CbKindDrawPoly:
|
||||||
ResolveDrawPolyCallback(view, addDraw);
|
ResolveDrawPolyCallback(view, addDraw);
|
||||||
break;
|
break;
|
||||||
case NativeProtocol.CbKindSetAnchor:
|
|
||||||
ResolveSetAnchorCallback(view, setAnchor);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResolveSetAnchorCallback(MemoryMappedViewAccessor view, Action<string, int, bool, int, double[]> setAnchor)
|
|
||||||
{
|
|
||||||
int tagLen = Math.Clamp(view.ReadInt32(NativeProtocol.OffCallbackTagLen), 0, NativeProtocol.CallbackTagMax);
|
|
||||||
view.ReadArray(NativeProtocol.CallbackTagOffset, _callbackTag, 0, tagLen);
|
|
||||||
string group = Encoding.UTF8.GetString(_callbackTag, 0, tagLen);
|
|
||||||
|
|
||||||
long rOff = NativeProtocol.CallbackResultOffset;
|
|
||||||
int count = Math.Clamp((int)view.ReadDouble(rOff + 0 * 8), 0, Anchor.AnchorSupport.MaxAnchors);
|
|
||||||
bool is3D = view.ReadDouble(rOff + 1 * 8) != 0d;
|
|
||||||
int connection = (int)view.ReadDouble(rOff + 2 * 8);
|
|
||||||
|
|
||||||
Array.Clear(_anchorBuffer, 0, _anchorBuffer.Length);
|
|
||||||
try { setAnchor(group, count, is3D, connection, _anchorBuffer); }
|
|
||||||
catch { }
|
|
||||||
|
|
||||||
int stride = is3D ? 3 : 2;
|
|
||||||
for (int i = 0; i < count * stride; i++)
|
|
||||||
view.Write(NativeProtocol.CallbackTagOffset + i * 8, _anchorBuffer[i]);
|
|
||||||
view.Write(NativeProtocol.OffCallbackFound, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ResolveDrawCallback(MemoryMappedViewAccessor view, Action<DrawCommand> addDraw)
|
private static void ResolveDrawCallback(MemoryMappedViewAccessor view, Action<DrawCommand> addDraw)
|
||||||
{
|
{
|
||||||
long rOff = NativeProtocol.CallbackResultOffset;
|
long rOff = NativeProtocol.CallbackResultOffset;
|
||||||
@@ -288,9 +259,8 @@ namespace LuaScript.Engine
|
|||||||
double alpha = view.ReadDouble(rOff + 4 * 8);
|
double alpha = view.ReadDouble(rOff + 4 * 8);
|
||||||
double aspect = view.ReadDouble(rOff + 5 * 8);
|
double aspect = view.ReadDouble(rOff + 5 * 8);
|
||||||
double antialias = view.ReadDouble(rOff + 6 * 8);
|
double antialias = view.ReadDouble(rOff + 6 * 8);
|
||||||
double blend = view.ReadDouble(rOff + 7 * 8);
|
|
||||||
|
|
||||||
try { addDraw(new DrawCommand(ox, oy, oz, zoom, alpha, aspect, null, antialias, blend)); }
|
try { addDraw(new DrawCommand(ox, oy, oz, zoom, alpha, aspect, null, antialias)); }
|
||||||
catch { }
|
catch { }
|
||||||
view.Write(NativeProtocol.OffCallbackFound, 1);
|
view.Write(NativeProtocol.OffCallbackFound, 1);
|
||||||
}
|
}
|
||||||
@@ -301,9 +271,8 @@ namespace LuaScript.Engine
|
|||||||
for (int i = 0; i < DrawPolyMath.Length; i++)
|
for (int i = 0; i < DrawPolyMath.Length; i++)
|
||||||
poly[i] = view.ReadDouble(NativeProtocol.CallbackTagOffset + i * 8);
|
poly[i] = view.ReadDouble(NativeProtocol.CallbackTagOffset + i * 8);
|
||||||
double antialias = view.ReadDouble(NativeProtocol.CallbackTagOffset + DrawPolyMath.Length * 8);
|
double antialias = view.ReadDouble(NativeProtocol.CallbackTagOffset + DrawPolyMath.Length * 8);
|
||||||
double blend = view.ReadDouble(NativeProtocol.CallbackTagOffset + (DrawPolyMath.Length + 1) * 8);
|
|
||||||
|
|
||||||
try { addDraw(new DrawCommand(0d, 0d, 0d, 1d, poly[20], 0d, poly, antialias, blend)); }
|
try { addDraw(new DrawCommand(0d, 0d, 0d, 1d, poly[20], 0d, poly, antialias)); }
|
||||||
catch { }
|
catch { }
|
||||||
view.Write(NativeProtocol.OffCallbackFound, 1);
|
view.Write(NativeProtocol.OffCallbackFound, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ namespace LuaScript.Engine
|
|||||||
{
|
{
|
||||||
internal static class NativeFieldMap
|
internal static class NativeFieldMap
|
||||||
{
|
{
|
||||||
|
private const double Epsilon = 1e-10;
|
||||||
|
|
||||||
public static void ToFields(AviUtlScriptContext ctx, double[] f)
|
public static void ToFields(AviUtlScriptContext ctx, double[] f)
|
||||||
{
|
{
|
||||||
f[NativeProtocol.W] = ctx.ImageWidth;
|
f[NativeProtocol.W] = ctx.ImageWidth;
|
||||||
@@ -91,13 +93,6 @@ namespace LuaScript.Engine
|
|||||||
f[NativeProtocol.Rxr],
|
f[NativeProtocol.Rxr],
|
||||||
f[NativeProtocol.Ryr],
|
f[NativeProtocol.Ryr],
|
||||||
f[NativeProtocol.Rzr]);
|
f[NativeProtocol.Rzr]);
|
||||||
|
|
||||||
ctx.DrawStateOverride = f[NativeProtocol.DrawState] switch
|
|
||||||
{
|
|
||||||
1d => true,
|
|
||||||
2d => false,
|
|
||||||
_ => null,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,6 @@ namespace LuaScript.Engine
|
|||||||
public const int CbKindLoadText = 5;
|
public const int CbKindLoadText = 5;
|
||||||
public const int CbKindLoadImage = 6;
|
public const int CbKindLoadImage = 6;
|
||||||
public const int CbKindLoadMovie = 7;
|
public const int CbKindLoadMovie = 7;
|
||||||
public const int CbKindSetAnchor = 8;
|
|
||||||
|
|
||||||
public const int CbExist = 0;
|
public const int CbExist = 0;
|
||||||
public const int CbX = 1;
|
public const int CbX = 1;
|
||||||
@@ -130,7 +129,6 @@ namespace LuaScript.Engine
|
|||||||
public const int Slider1 = 59;
|
public const int Slider1 = 59;
|
||||||
public const int Slider2 = 60;
|
public const int Slider2 = 60;
|
||||||
public const int Slider3 = 61;
|
public const int Slider3 = 61;
|
||||||
public const int DrawState = 62;
|
|
||||||
|
|
||||||
public const int FirstWritableField = X;
|
public const int FirstWritableField = X;
|
||||||
public const int LastWritableField = Rzr;
|
public const int LastWritableField = Rzr;
|
||||||
|
|||||||
@@ -24,8 +24,7 @@ namespace LuaScript.Engine
|
|||||||
|
|
||||||
public static bool UsesDrawingApi(string? script) =>
|
public static bool UsesDrawingApi(string? script) =>
|
||||||
script is not null &&
|
script is not null &&
|
||||||
(script.Contains("obj.setoption", StringComparison.Ordinal) ||
|
script.Contains("obj.setoption", StringComparison.Ordinal);
|
||||||
script.Contains("obj.setanchor", StringComparison.Ordinal));
|
|
||||||
|
|
||||||
private static bool TryGetDirective(string? script, out ScriptEngineKind kind)
|
private static bool TryGetDirective(string? script, out ScriptEngineKind kind)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Version>1.11.0</Version>
|
<Version>1.10.0</Version>
|
||||||
<Platforms>AnyCPU;x64</Platforms>
|
<Platforms>AnyCPU;x64</Platforms>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using LuaScript.Anchor;
|
|
||||||
using LuaScript.Compat;
|
using LuaScript.Compat;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using YukkuriMovieMaker.Commons;
|
using YukkuriMovieMaker.Commons;
|
||||||
@@ -295,19 +293,6 @@ namespace LuaScript
|
|||||||
return Color.FromRgb(r, g, b);
|
return Color.FromRgb(r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImmutableList<LuaAnchorPoint> Anchors
|
|
||||||
{
|
|
||||||
get => _anchors;
|
|
||||||
set { if (Set(ref _anchors, value ?? ImmutableList<LuaAnchorPoint>.Empty)) AnchorVersion++; }
|
|
||||||
}
|
|
||||||
ImmutableList<LuaAnchorPoint> _anchors = ImmutableList<LuaAnchorPoint>.Empty;
|
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
internal int AnchorVersion { get; private set; }
|
|
||||||
|
|
||||||
internal void ApplyAnchorDrag(string group, int index, double dx, double dy, double dz)
|
|
||||||
=> Anchors = AnchorSupport.ApplyDrag(Anchors, group, index, dx, dy, dz);
|
|
||||||
|
|
||||||
public override IEnumerable<string> CreateExoVideoFilters(int keyFrameIndex, ExoOutputDescription exoOutputDescription) => [];
|
public override IEnumerable<string> CreateExoVideoFilters(int keyFrameIndex, ExoOutputDescription exoOutputDescription) => [];
|
||||||
|
|
||||||
public override IVideoEffectProcessor CreateVideoEffect(IGraphicsDevicesAndContext devices)
|
public override IVideoEffectProcessor CreateVideoEffect(IGraphicsDevicesAndContext devices)
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
using System.Collections.Immutable;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using LuaScript.Anchor;
|
|
||||||
using LuaScript.Compat;
|
using LuaScript.Compat;
|
||||||
using LuaScript.Diagnostics;
|
using LuaScript.Diagnostics;
|
||||||
using LuaScript.Engine;
|
using LuaScript.Engine;
|
||||||
@@ -57,7 +55,6 @@ namespace LuaScript
|
|||||||
int GroupCount,
|
int GroupCount,
|
||||||
int TimelineTotalFrame,
|
int TimelineTotalFrame,
|
||||||
double TimelineTotalTime,
|
double TimelineTotalTime,
|
||||||
int AnchorVersion,
|
|
||||||
DrawDescription InputDesc
|
DrawDescription InputDesc
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -231,7 +228,6 @@ namespace LuaScript
|
|||||||
desc.GroupIndex, desc.GroupCount,
|
desc.GroupIndex, desc.GroupCount,
|
||||||
desc.TimelineDuration.Frame,
|
desc.TimelineDuration.Frame,
|
||||||
desc.TimelineDuration.Time.TotalSeconds,
|
desc.TimelineDuration.Time.TotalSeconds,
|
||||||
item.AnchorVersion,
|
|
||||||
inDesc);
|
inDesc);
|
||||||
|
|
||||||
_frameDesc = desc;
|
_frameDesc = desc;
|
||||||
@@ -307,8 +303,6 @@ namespace LuaScript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplyDrawState(ctx, bounds);
|
|
||||||
|
|
||||||
outDesc = BuildOutputDesc(inDesc, ctx);
|
outDesc = BuildOutputDesc(inDesc, ctx);
|
||||||
|
|
||||||
if (ctx.EffectRequests.Count > 0)
|
if (ctx.EffectRequests.Count > 0)
|
||||||
@@ -324,8 +318,6 @@ namespace LuaScript
|
|||||||
WarnEffectChainFailureOnce(ex);
|
WarnEffectChainFailureOnce(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outDesc = AddAnchorControllers(outDesc, ctx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (LuaScriptTimeoutException ex)
|
catch (LuaScriptTimeoutException ex)
|
||||||
@@ -472,10 +464,6 @@ namespace LuaScript
|
|||||||
ctx.ClearQueries();
|
ctx.ClearQueries();
|
||||||
ctx.ClearEffects();
|
ctx.ClearEffects();
|
||||||
ctx.ClearDraws();
|
ctx.ClearDraws();
|
||||||
ctx.ClearAnchorRequests();
|
|
||||||
ctx.AnchorSource = item.Anchors;
|
|
||||||
ctx.DrawStateOverride = null;
|
|
||||||
ctx.ResetDrawTarget();
|
|
||||||
|
|
||||||
ctx.ImageWidth = imgW;
|
ctx.ImageWidth = imgW;
|
||||||
ctx.ImageHeight = imgH;
|
ctx.ImageHeight = imgH;
|
||||||
@@ -536,143 +524,6 @@ namespace LuaScript
|
|||||||
return layout.GetTrack(index) is { } p ? Math.Clamp(value, p.Min, p.Max) : value;
|
return layout.GetTrack(index) is { } p ? Math.Clamp(value, p.Min, p.Max) : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImmutableList<VideoEffectController> _anchorControllers = ImmutableList<VideoEffectController>.Empty;
|
|
||||||
private AnchorRequestData[] _anchorSignature = [];
|
|
||||||
private IReadOnlyList<LuaAnchorPoint>? _anchorSignatureSource;
|
|
||||||
|
|
||||||
private ImmutableList<VideoEffectController> ResolveAnchorControllers(AviUtlScriptContext ctx)
|
|
||||||
{
|
|
||||||
var requests = ctx.AnchorRequests;
|
|
||||||
if (requests.Count == 0)
|
|
||||||
{
|
|
||||||
_anchorControllers = ImmutableList<VideoEffectController>.Empty;
|
|
||||||
_anchorSignature = [];
|
|
||||||
_anchorSignatureSource = null;
|
|
||||||
return _anchorControllers;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ReferenceEquals(_anchorSignatureSource, ctx.AnchorSource) && AnchorSignatureMatches(requests))
|
|
||||||
return _anchorControllers;
|
|
||||||
|
|
||||||
_anchorControllers = BuildAnchorControllers(ctx.AnchorSource, requests);
|
|
||||||
_anchorSignature = new AnchorRequestData[requests.Count];
|
|
||||||
for (int i = 0; i < requests.Count; i++)
|
|
||||||
_anchorSignature[i] = requests[i];
|
|
||||||
_anchorSignatureSource = ctx.AnchorSource;
|
|
||||||
return _anchorControllers;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool AnchorSignatureMatches(IReadOnlyList<AnchorRequestData> requests)
|
|
||||||
{
|
|
||||||
if (_anchorSignature.Length != requests.Count)
|
|
||||||
return false;
|
|
||||||
for (int i = 0; i < requests.Count; i++)
|
|
||||||
if (!_anchorSignature[i].Equals(requests[i]))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DrawDescription AddAnchorControllers(DrawDescription desc, AviUtlScriptContext ctx)
|
|
||||||
{
|
|
||||||
var controllers = ResolveAnchorControllers(ctx);
|
|
||||||
return controllers.Count == 0 ? desc : desc with { Controllers = desc.Controllers.AddRange(controllers) };
|
|
||||||
}
|
|
||||||
|
|
||||||
private ImmutableList<VideoEffectController> BuildAnchorControllers(
|
|
||||||
IReadOnlyList<LuaAnchorPoint>? source, IReadOnlyList<AnchorRequestData> requests)
|
|
||||||
{
|
|
||||||
var builder = ImmutableList.CreateBuilder<VideoEffectController>();
|
|
||||||
foreach (var request in requests)
|
|
||||||
{
|
|
||||||
if (request.Count <= 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
AddConnectionControllers(builder, source, request);
|
|
||||||
|
|
||||||
var group = request.Group;
|
|
||||||
bool is3D = request.Is3D;
|
|
||||||
for (int i = 0; i < request.Count; i++)
|
|
||||||
{
|
|
||||||
AnchorSupport.ResolvePosition(source, group, i, out double x, out double y, out double z);
|
|
||||||
int index = i;
|
|
||||||
var point = new ControllerPoint(
|
|
||||||
new Vector3((float)x, (float)y, (float)(is3D ? z : 0d)),
|
|
||||||
arg => item.ApplyAnchorDrag(group, index, arg.Delta.X, arg.Delta.Y, is3D ? arg.Delta.Z : 0d))
|
|
||||||
{
|
|
||||||
Shape = VideoControllerPointShape.Circle,
|
|
||||||
};
|
|
||||||
builder.Add(new VideoEffectController(item, [point]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return builder.ToImmutable();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AddConnectionControllers(
|
|
||||||
ImmutableList<VideoEffectController>.Builder builder, IReadOnlyList<LuaAnchorPoint>? source, in AnchorRequestData request)
|
|
||||||
{
|
|
||||||
switch (request.Connection)
|
|
||||||
{
|
|
||||||
case AnchorConnection.Line:
|
|
||||||
for (int i = 0; i + 1 < request.Count; i++)
|
|
||||||
AddEdge(builder, ConnectionPoint(source, request, i), ConnectionPoint(source, request, i + 1));
|
|
||||||
break;
|
|
||||||
case AnchorConnection.Loop:
|
|
||||||
for (int i = 0; i + 1 < request.Count; i++)
|
|
||||||
AddEdge(builder, ConnectionPoint(source, request, i), ConnectionPoint(source, request, i + 1));
|
|
||||||
if (request.Count >= 2)
|
|
||||||
AddEdge(builder, ConnectionPoint(source, request, request.Count - 1), ConnectionPoint(source, request, 0));
|
|
||||||
break;
|
|
||||||
case AnchorConnection.Star:
|
|
||||||
for (int i = 0; i < request.Count; i++)
|
|
||||||
AddEdge(builder, CenterPoint(), ConnectionPoint(source, request, i));
|
|
||||||
break;
|
|
||||||
case AnchorConnection.Arm:
|
|
||||||
if (request.Count >= 1)
|
|
||||||
AddEdge(builder, CenterPoint(), ConnectionPoint(source, request, 0));
|
|
||||||
for (int i = 0; i + 1 < request.Count; i++)
|
|
||||||
AddEdge(builder, ConnectionPoint(source, request, i), ConnectionPoint(source, request, i + 1));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AddEdge(ImmutableList<VideoEffectController>.Builder builder, ControllerPoint a, ControllerPoint b) =>
|
|
||||||
builder.Add(new VideoEffectController(item, [a, b]) { Connection = VideoControllerPointConnection.Line });
|
|
||||||
|
|
||||||
private static ControllerPoint CenterPoint() =>
|
|
||||||
new(Vector3.Zero) { Shape = VideoControllerPointShape.None };
|
|
||||||
|
|
||||||
private static ControllerPoint ConnectionPoint(IReadOnlyList<LuaAnchorPoint>? source, in AnchorRequestData request, int index)
|
|
||||||
{
|
|
||||||
AnchorSupport.ResolvePosition(source, request.Group, index, out double x, out double y, out double z);
|
|
||||||
return new ControllerPoint(new Vector3((float)x, (float)y, (float)(request.Is3D ? z : 0d)))
|
|
||||||
{
|
|
||||||
Shape = VideoControllerPointShape.None,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ApplyDrawState(AviUtlScriptContext ctx, RawRectF bounds)
|
|
||||||
{
|
|
||||||
if (ctx.DrawStateOverride is not { } drawn)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!drawn)
|
|
||||||
{
|
|
||||||
effectOutput = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (effectOutput is not null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ctx.EnsurePixelBuffer();
|
|
||||||
var buffer = ctx.GetPixelBuffer();
|
|
||||||
if (buffer is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_pixelManager!.WritePixelsToOutput(buffer, ctx.ImageWidth, ctx.ImageHeight);
|
|
||||||
effectOutput = _pixelManager.GetTransformOutput(bounds.Left, bounds.Top);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DrawDescription BuildOutputDesc(DrawDescription inDesc, AviUtlScriptContext ctx)
|
private static DrawDescription BuildOutputDesc(DrawDescription inDesc, AviUtlScriptContext ctx)
|
||||||
{
|
{
|
||||||
return inDesc with
|
return inDesc with
|
||||||
@@ -791,7 +642,6 @@ namespace LuaScript
|
|||||||
NativeLoadMovie,
|
NativeLoadMovie,
|
||||||
(name, args) => ctx.AddEffect(new AviUtlEffectRequest(name, args)),
|
(name, args) => ctx.AddEffect(new AviUtlEffectRequest(name, args)),
|
||||||
ctx.AddDraw,
|
ctx.AddDraw,
|
||||||
ResolveNativeAnchor,
|
|
||||||
out bool dirty, out bool bufferReplaced, out byte[]? newPixels,
|
out bool dirty, out bool bufferReplaced, out byte[]? newPixels,
|
||||||
out int resultW, out int resultH, out string? error);
|
out int resultW, out int resultH, out string? error);
|
||||||
|
|
||||||
@@ -842,22 +692,6 @@ namespace LuaScript
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResolveNativeAnchor(string group, int count, bool is3D, int connection, double[] positions)
|
|
||||||
{
|
|
||||||
_context.AddAnchorRequest(new AnchorRequestData(group, count, (AnchorConnection)connection, is3D));
|
|
||||||
|
|
||||||
int stride = is3D ? 3 : 2;
|
|
||||||
var source = _context.AnchorSource;
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
AnchorSupport.ResolvePosition(source, group, i, out double x, out double y, out double z);
|
|
||||||
positions[i * stride + 0] = x;
|
|
||||||
positions[i * stride + 1] = y;
|
|
||||||
if (is3D)
|
|
||||||
positions[i * stride + 2] = z;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private (byte[] buffer, int w, int h) NativeLoadText(string family, string text, double size, bool bold, bool italic, int color)
|
private (byte[] buffer, int w, int h) NativeLoadText(string family, string text, double size, bool bold, bool italic, int color)
|
||||||
{
|
{
|
||||||
_nativeTextRenderer ??= new TextRenderer();
|
_nativeTextRenderer ??= new TextRenderer();
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using LuaScript.Anchor;
|
|
||||||
using LuaScript.Compat;
|
using LuaScript.Compat;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
using MoonSharp.Interpreter.Debugging;
|
using MoonSharp.Interpreter.Debugging;
|
||||||
@@ -588,7 +587,7 @@ namespace LuaScript
|
|||||||
double alpha = args.Count > 4 ? args[4].CastToNumber() ?? 1d : 1d;
|
double alpha = args.Count > 4 ? args[4].CastToNumber() ?? 1d : 1d;
|
||||||
double aspect = args.Count > 5 ? args[5].CastToNumber() ?? 0d : 0d;
|
double aspect = args.Count > 5 ? args[5].CastToNumber() ?? 0d : 0d;
|
||||||
|
|
||||||
_activeContext.SubmitDraw(new DrawCommand(ox, oy, oz, zoom, alpha, aspect, null, CurrentAntialias(), CurrentBlend()));
|
_activeContext.AddDraw(new DrawCommand(ox, oy, oz, zoom, alpha, aspect, null, CurrentAntialias()));
|
||||||
return DynValue.Void;
|
return DynValue.Void;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -624,7 +623,7 @@ namespace LuaScript
|
|||||||
_ => 1d,
|
_ => 1d,
|
||||||
};
|
};
|
||||||
|
|
||||||
_activeContext.SubmitDraw(new DrawCommand(0d, 0d, 0d, 1d, poly[20], 0d, poly, CurrentAntialias(), CurrentBlend()));
|
_activeContext.AddDraw(new DrawCommand(0d, 0d, 0d, 1d, poly[20], 0d, poly, CurrentAntialias()));
|
||||||
return DynValue.Void;
|
return DynValue.Void;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -649,68 +648,12 @@ namespace LuaScript
|
|||||||
return value.Type == DataType.Number ? value : DynValue.NewNumber(0d);
|
return value.Type == DataType.Number ? value : DynValue.NewNumber(0d);
|
||||||
});
|
});
|
||||||
|
|
||||||
obj["setanchor"] = DynValue.NewCallback((_, args) =>
|
|
||||||
{
|
|
||||||
_activeCancellation.ThrowIfCancellationRequested();
|
|
||||||
if (_activeContext is null || _script is null || args.Count < 2 || args[0].Type != DataType.String)
|
|
||||||
return DynValue.NewNumber(0d);
|
|
||||||
|
|
||||||
var anchorName = args[0].String;
|
|
||||||
int count = AnchorSupport.ClampCount((int)(args[1].CastToNumber() ?? 0d));
|
|
||||||
if (string.Equals(anchorName, AnchorSupport.TrackGroup, StringComparison.Ordinal))
|
|
||||||
return DynValue.NewNumber(0d);
|
|
||||||
|
|
||||||
var connection = AnchorConnection.None;
|
|
||||||
bool is3D = false;
|
|
||||||
for (int i = 2; i < args.Count; i++)
|
|
||||||
{
|
|
||||||
if (args[i].Type == DataType.String)
|
|
||||||
AnchorSupport.ApplyOption(args[i].String, ref connection, ref is3D);
|
|
||||||
}
|
|
||||||
|
|
||||||
int stride = is3D ? 3 : 2;
|
|
||||||
var table = new Table(_script);
|
|
||||||
var source = _activeContext.AnchorSource;
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
AnchorSupport.ResolvePosition(source, anchorName, i, out double x, out double y, out double z);
|
|
||||||
table.Set(i * stride + 1, DynValue.NewNumber(x));
|
|
||||||
table.Set(i * stride + 2, DynValue.NewNumber(y));
|
|
||||||
if (is3D)
|
|
||||||
table.Set(i * stride + 3, DynValue.NewNumber(z));
|
|
||||||
}
|
|
||||||
_script.Globals.Set(anchorName, DynValue.NewTable(table));
|
|
||||||
|
|
||||||
_activeContext.AddAnchorRequest(new AnchorRequestData(anchorName, count, connection, is3D));
|
|
||||||
return DynValue.NewNumber(count);
|
|
||||||
});
|
|
||||||
|
|
||||||
obj["setoption"] = DynValue.NewCallback((_, args) =>
|
obj["setoption"] = DynValue.NewCallback((_, args) =>
|
||||||
{
|
{
|
||||||
_activeCancellation.ThrowIfCancellationRequested();
|
_activeCancellation.ThrowIfCancellationRequested();
|
||||||
if (args.Count == 0 || args[0].Type != DataType.String)
|
if (args.Count == 0 || args[0].Type != DataType.String)
|
||||||
return DynValue.Void;
|
return DynValue.Void;
|
||||||
var name = args[0].String;
|
_options[args[0].String] = args.Count > 1 ? args[1] : DynValue.True;
|
||||||
var value = args.Count > 1 ? args[1] : DynValue.True;
|
|
||||||
_options[name] = value;
|
|
||||||
if (name == "draw_state" && _activeContext is not null)
|
|
||||||
_activeContext.DrawStateOverride = value.Type == DataType.Boolean
|
|
||||||
? value.Boolean
|
|
||||||
: (value.CastToNumber() ?? 0d) != 0d;
|
|
||||||
if (name == "drawtarget" && _activeContext is not null)
|
|
||||||
{
|
|
||||||
if (value.Type == DataType.String && value.String == "tempbuffer")
|
|
||||||
{
|
|
||||||
bool hasSize = args.Count > 3;
|
|
||||||
int w = hasSize ? (int)(args[2].CastToNumber() ?? 0d) : 0;
|
|
||||||
int h = hasSize ? (int)(args[3].CastToNumber() ?? 0d) : 0;
|
|
||||||
_activeContext.SetDrawTarget(true, w, h, hasSize);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_activeContext.SetDrawTarget(false, 0, 0, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return DynValue.Void;
|
return DynValue.Void;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -737,11 +680,6 @@ namespace LuaScript
|
|||||||
? value.Number
|
? value.Number
|
||||||
: 1d;
|
: 1d;
|
||||||
|
|
||||||
private double CurrentBlend() =>
|
|
||||||
_options.TryGetValue("blend", out var value) && value.Type == DataType.Number
|
|
||||||
? value.Number
|
|
||||||
: 0d;
|
|
||||||
|
|
||||||
private void LoadFigure(string name, int color, double size, double line, double aspect)
|
private void LoadFigure(string name, int color, double size, double line, double aspect)
|
||||||
{
|
{
|
||||||
int boundingSize = Math.Max(1, (int)Math.Round(size));
|
int boundingSize = Math.Max(1, (int)Math.Round(size));
|
||||||
|
|||||||
@@ -1,138 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Numerics;
|
|
||||||
|
|
||||||
namespace LuaScript
|
|
||||||
{
|
|
||||||
internal static class SoftwareCompositor
|
|
||||||
{
|
|
||||||
public static void DrawInto(
|
|
||||||
byte[] dst, int dstW, int dstH,
|
|
||||||
byte[] src, int srcW, int srcH,
|
|
||||||
double ox, double oy, double zoom, double aspect, double alpha, bool linear)
|
|
||||||
{
|
|
||||||
if (srcW <= 0 || srcH <= 0 || dstW <= 0 || dstH <= 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
double clampedAspect = Math.Clamp(aspect, -1d, 1d);
|
|
||||||
double zx = zoom * (1d + clampedAspect);
|
|
||||||
double zy = zoom * (1d - clampedAspect);
|
|
||||||
if (zx == 0d || zy == 0d)
|
|
||||||
return;
|
|
||||||
|
|
||||||
double ka = Math.Clamp(alpha, 0d, 1d);
|
|
||||||
if (ka <= 0d)
|
|
||||||
return;
|
|
||||||
|
|
||||||
double halfW = srcW * 0.5;
|
|
||||||
double halfH = srcH * 0.5;
|
|
||||||
double spanX = Math.Abs(halfW * zx);
|
|
||||||
double spanY = Math.Abs(halfH * zy);
|
|
||||||
|
|
||||||
int x0 = Math.Max(0, (int)Math.Floor(ox - spanX));
|
|
||||||
int x1 = Math.Min(dstW - 1, (int)Math.Ceiling(ox + spanX));
|
|
||||||
int y0 = Math.Max(0, (int)Math.Floor(oy - spanY));
|
|
||||||
int y1 = Math.Min(dstH - 1, (int)Math.Ceiling(oy + spanY));
|
|
||||||
|
|
||||||
for (int py = y0; py <= y1; py++)
|
|
||||||
{
|
|
||||||
for (int px = x0; px <= x1; px++)
|
|
||||||
{
|
|
||||||
double u = (px + 0.5 - ox) / zx + halfW;
|
|
||||||
double v = (py + 0.5 - oy) / zy + halfH;
|
|
||||||
if (u < 0d || u >= srcW || v < 0d || v >= srcH)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Sample(src, srcW, srcH, u, v, linear, out double sb, out double sg, out double sr, out double sa);
|
|
||||||
CompositeOver(dst, (py * dstW + px) * 4, sb * ka, sg * ka, sr * ka, sa * ka);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void DrawPolyInto(
|
|
||||||
byte[] dst, int dstW, int dstH,
|
|
||||||
byte[] src, int srcW, int srcH,
|
|
||||||
double[] poly, double alpha, bool linear)
|
|
||||||
{
|
|
||||||
if (srcW <= 0 || srcH <= 0 || dstW <= 0 || dstH <= 0)
|
|
||||||
return;
|
|
||||||
if (!DrawPolyMath.TrySolveAffine(poly, out var forward))
|
|
||||||
return;
|
|
||||||
if (!Matrix3x2.Invert(forward, out var inverse))
|
|
||||||
return;
|
|
||||||
|
|
||||||
double ka = Math.Clamp(alpha, 0d, 1d);
|
|
||||||
if (ka <= 0d)
|
|
||||||
return;
|
|
||||||
|
|
||||||
DrawPolyMath.Bounds(poly, out double minX, out double minY, out double maxX, out double maxY);
|
|
||||||
int x0 = Math.Max(0, (int)Math.Floor(minX));
|
|
||||||
int x1 = Math.Min(dstW - 1, (int)Math.Ceiling(maxX));
|
|
||||||
int y0 = Math.Max(0, (int)Math.Floor(minY));
|
|
||||||
int y1 = Math.Min(dstH - 1, (int)Math.Ceiling(maxY));
|
|
||||||
|
|
||||||
for (int py = y0; py <= y1; py++)
|
|
||||||
{
|
|
||||||
for (int px = x0; px <= x1; px++)
|
|
||||||
{
|
|
||||||
var uv = Vector2.Transform(new Vector2(px + 0.5f, py + 0.5f), inverse);
|
|
||||||
double u = uv.X;
|
|
||||||
double v = uv.Y;
|
|
||||||
if (u < 0d || u >= srcW || v < 0d || v >= srcH)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Sample(src, srcW, srcH, u, v, linear, out double sb, out double sg, out double sr, out double sa);
|
|
||||||
CompositeOver(dst, (py * dstW + px) * 4, sb * ka, sg * ka, sr * ka, sa * ka);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void Sample(byte[] src, int srcW, int srcH, double u, double v, bool linear,
|
|
||||||
out double b, out double g, out double r, out double a)
|
|
||||||
{
|
|
||||||
if (!linear)
|
|
||||||
{
|
|
||||||
int su = Math.Clamp((int)Math.Floor(u), 0, srcW - 1);
|
|
||||||
int sv = Math.Clamp((int)Math.Floor(v), 0, srcH - 1);
|
|
||||||
int si = (sv * srcW + su) * 4;
|
|
||||||
b = src[si];
|
|
||||||
g = src[si + 1];
|
|
||||||
r = src[si + 2];
|
|
||||||
a = src[si + 3];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double fx = u - 0.5;
|
|
||||||
double fy = v - 0.5;
|
|
||||||
int x0 = (int)Math.Floor(fx);
|
|
||||||
int y0 = (int)Math.Floor(fy);
|
|
||||||
double tx = fx - x0;
|
|
||||||
double ty = fy - y0;
|
|
||||||
|
|
||||||
b = g = r = a = 0d;
|
|
||||||
for (int j = 0; j < 2; j++)
|
|
||||||
{
|
|
||||||
int sy = Math.Clamp(y0 + j, 0, srcH - 1);
|
|
||||||
double wy = j == 0 ? 1d - ty : ty;
|
|
||||||
for (int i = 0; i < 2; i++)
|
|
||||||
{
|
|
||||||
int sx = Math.Clamp(x0 + i, 0, srcW - 1);
|
|
||||||
double w = wy * (i == 0 ? 1d - tx : tx);
|
|
||||||
int si = (sy * srcW + sx) * 4;
|
|
||||||
b += src[si] * w;
|
|
||||||
g += src[si + 1] * w;
|
|
||||||
r += src[si + 2] * w;
|
|
||||||
a += src[si + 3] * w;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CompositeOver(byte[] dst, int di, double sb, double sg, double sr, double sa)
|
|
||||||
{
|
|
||||||
double inv = 1d - sa / 255d;
|
|
||||||
dst[di] = (byte)Math.Clamp(sb + dst[di] * inv, 0d, 255d);
|
|
||||||
dst[di + 1] = (byte)Math.Clamp(sg + dst[di + 1] * inv, 0d, 255d);
|
|
||||||
dst[di + 2] = (byte)Math.Clamp(sr + dst[di + 2] * inv, 0d, 255d);
|
|
||||||
dst[di + 3] = (byte)Math.Clamp(sa + dst[di + 3] * inv, 0d, 255d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -489,54 +489,10 @@
|
|||||||
الخيارات التي تؤثر على الرسم حالياً:
|
الخيارات التي تؤثر على الرسم حالياً:
|
||||||
"antialias" : 0 = أقرب جار، وإلا استيفاء خطّي
|
"antialias" : 0 = أقرب جار، وإلا استيفاء خطّي
|
||||||
(obj.draw / obj.drawpoly).
|
(obj.draw / obj.drawpoly).
|
||||||
"blend" : رقم وضع الدمج (obj.draw / obj.drawpoly). بنفس ترتيب
|
|
||||||
القائمة المنسدلة "وضع الدمج" في لوحة الخصائص في YMM4 (يبدأ من 0):
|
|
||||||
0=عادي,1=اكتمل الذوبان,2=أغمق,3=ضرب,4=حرق اللون,
|
|
||||||
5=احتراق خطي,6=معالجة (أخفّ),7=شاشة,8=تراكب اللون,
|
|
||||||
9=المزج الخطي (إضافة),10=إضافة,11=تراكب,12=ضوء ناعم,
|
|
||||||
13=ضوء قوي,14=ضوء حيوي,15=الضوء الخطي,16=ضوء دبوس,
|
|
||||||
17=مزج قوي,18=الفرق,19=استبعاد,20=طرح,21=القسمة,22=تدرج,
|
|
||||||
23=التشبع,24=لون,25=السطوع,26=لون أفتح,27=خلفية,
|
|
||||||
28=لون أغمق,29=مسح,30=القص حسب الخلفية,
|
|
||||||
31=فقط الأجزاء غير المتراكبة,32=قناع عكس الألوان.
|
|
||||||
القيم خارج النطاق أو غير الصالحة تُعامَل كـ 0 (عادي).
|
|
||||||
"draw_state" : قيمة منطقية تحدد ما إذا كان هذا التأثير يُخرج صورة
|
|
||||||
العمل. true تُخرج صورة العمل، وfalse تمرر الدخل كما هو. تُستخدم
|
|
||||||
لإخراج صورة العمل دون obj.draw أو setpixel، أو لإيقاف الإخراج.
|
|
||||||
تعمل في المحركين معاً.
|
|
||||||
"drawtarget" : يبدّل وجهة رسم obj.draw / obj.drawpoly.
|
|
||||||
"framebuffer" (الافتراضي) يركّب في مخزن الإطار. "tempbuffer"
|
|
||||||
يركّب في مخزن العمل tmp مباشرة. في
|
|
||||||
obj.setoption("drawtarget", "tempbuffer", w, h) تُحدد w, h حجم
|
|
||||||
تهيئة مخزن tmp، وحذفهما يُبقيه كما هو. أعِد نتيجة tmp إلى صورة
|
|
||||||
العمل عبر obj.copybuffer("obj", "tmp"). التركيب في tempbuffer
|
|
||||||
عادي (source-over)، وblend يُطبَّق على الرسم في framebuffer.
|
|
||||||
تعمل في المحركين معاً.
|
|
||||||
|
|
||||||
○ obj.pixeloption(name, value)
|
○ obj.pixeloption(name, value)
|
||||||
يحفظ خياراً لعمليات البكسل كحالة.
|
يحفظ خياراً لعمليات البكسل كحالة.
|
||||||
|
|
||||||
○ obj.setanchor(name, count [, option, ..])
|
|
||||||
يعرض نقاط الإرساء على المعاينة لضبط إحداثياتها بالسحب بالفأرة.
|
|
||||||
تُحفَظ الإحداثيات المعدّلة مع المشروع.
|
|
||||||
name : اسم متغير Lua الذي يستقبل الإحداثيات، كسلسلة نصية. يكون
|
|
||||||
المتغير بالترتيب pos={x0,y0,x1,y1,…}، أو {x0,y0,z0,x1,y1,z1,…}
|
|
||||||
مع "xyz". الإحداثيات بالنسبة إلى مركز الكائن.
|
|
||||||
count : عدد نقاط الإرساء. حتى 32.
|
|
||||||
option : تُذكَر كسلاسل نصية.
|
|
||||||
"line" : يصل نقاط الإرساء بخطوط.
|
|
||||||
"loop" : يصل نقاط الإرساء ويغلق الحلقة.
|
|
||||||
"star" : يصل كل نقطة إرساء بمركز الكائن.
|
|
||||||
"arm" : يصل مركز الكائن بكل نقطة إرساء بالترتيب.
|
|
||||||
"xyz" : يعامل النقاط كإحداثيات ثلاثية الأبعاد. الافتراضي ثنائي.
|
|
||||||
يعيد عدد نقاط الإرساء. يعمل في المحركين معاً.
|
|
||||||
وضع شريط "track" غير مدعوم حالياً ويعيد 0.
|
|
||||||
مثال:
|
|
||||||
num = obj.track0
|
|
||||||
obj.setanchor("pos", num, "loop")
|
|
||||||
for i = 0, num - 1 do
|
|
||||||
obj.draw(pos[i * 2 + 1], pos[i * 2 + 2])
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 Table -
|
- ymm4 Table -
|
||||||
|
|||||||
@@ -506,58 +506,10 @@
|
|||||||
Options that currently affect drawing:
|
Options that currently affect drawing:
|
||||||
"antialias" : 0 = nearest neighbor, otherwise linear interpolation
|
"antialias" : 0 = nearest neighbor, otherwise linear interpolation
|
||||||
(obj.draw / obj.drawpoly).
|
(obj.draw / obj.drawpoly).
|
||||||
"blend" : blend mode number (obj.draw / obj.drawpoly). Same order
|
|
||||||
(0-based) as YMM4's own "Blend mode" dropdown in the property
|
|
||||||
panel: 0=Normal,1=Dissolve,2=Darker,3=Multiply,4=Color burn,
|
|
||||||
5=Linear burn,6=Lighter,7=Screen,8=Color dodge,
|
|
||||||
9=Linear dodge (Add),10=Add,11=Overlay,12=Soft light,
|
|
||||||
13=Hard light,14=Vivid light,15=Linear light,16=Pin light,
|
|
||||||
17=Hard mix,18=Difference,19=Exclution,20=Subtract,
|
|
||||||
21=Division,22=Hue,23=Saturation,24=Color,25=Luminance,
|
|
||||||
26=Lighter color,27=Behind,28=Darker color,29=Clear,
|
|
||||||
30=Clipping by background,31=XOR,32=Color inversion mask.
|
|
||||||
Out-of-range or invalid values are treated as 0 (Normal).
|
|
||||||
"draw_state" : a boolean that decides whether this effect emits
|
|
||||||
its working image. true outputs the working image; false passes
|
|
||||||
the input through unchanged. Use it to emit the working image
|
|
||||||
without obj.draw or setpixel, or to suppress the output. It works
|
|
||||||
in both engines.
|
|
||||||
"drawtarget" : switches the destination of obj.draw / obj.drawpoly.
|
|
||||||
"framebuffer" (default) composites into the frame buffer.
|
|
||||||
"tempbuffer" composites into the working tmp buffer in place. In
|
|
||||||
obj.setoption("drawtarget", "tempbuffer", w, h) the w, h give the
|
|
||||||
size to initialize the tmp buffer; omit them to keep it. Bring the
|
|
||||||
tmp result back to the working image with
|
|
||||||
obj.copybuffer("obj", "tmp"). Compositing into tempbuffer is
|
|
||||||
normal (source-over); blend applies to framebuffer drawing. It
|
|
||||||
works in both engines.
|
|
||||||
|
|
||||||
o obj.pixeloption(name, value)
|
o obj.pixeloption(name, value)
|
||||||
Stores an option for pixel operations as state.
|
Stores an option for pixel operations as state.
|
||||||
|
|
||||||
o obj.setanchor(name, count [, option, ..])
|
|
||||||
Shows anchor points on the preview so their coordinates can be
|
|
||||||
adjusted by mouse dragging. The adjusted coordinates are saved with
|
|
||||||
the project.
|
|
||||||
name : the name of the Lua variable that receives the coordinates,
|
|
||||||
given as a string. The variable is laid out as
|
|
||||||
pos={x0,y0,x1,y1,…}, or {x0,y0,z0,x1,y1,z1,…} with "xyz".
|
|
||||||
Coordinates are relative to the object center.
|
|
||||||
count : the number of anchor points. Up to 32.
|
|
||||||
option : enumerated as strings.
|
|
||||||
"line" : connect the anchor points with lines.
|
|
||||||
"loop" : connect the anchor points and close the loop.
|
|
||||||
"star" : connect each anchor point to the object center.
|
|
||||||
"arm" : connect the object center to each anchor point in order.
|
|
||||||
"xyz" : treat the anchor points as 3D coordinates. 2D by default.
|
|
||||||
Returns the number of anchor points. It works in both engines.
|
|
||||||
The "track" trackbar mode is not supported yet and returns 0.
|
|
||||||
Example:
|
|
||||||
num = obj.track0
|
|
||||||
obj.setanchor("pos", num, "loop")
|
|
||||||
for i = 0, num - 1 do
|
|
||||||
obj.draw(pos[i * 2 + 1], pos[i * 2 + 2])
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 Table -
|
- ymm4 Table -
|
||||||
|
|||||||
@@ -505,62 +505,10 @@
|
|||||||
Opciones que afectan al dibujo actualmente:
|
Opciones que afectan al dibujo actualmente:
|
||||||
"antialias" : 0 = vecino más cercano, en otro caso interpolación
|
"antialias" : 0 = vecino más cercano, en otro caso interpolación
|
||||||
lineal (obj.draw / obj.drawpoly).
|
lineal (obj.draw / obj.drawpoly).
|
||||||
"blend" : número de modo de fusión (obj.draw / obj.drawpoly). El
|
|
||||||
mismo orden (empezando en 0) que la lista desplegable "Modo de
|
|
||||||
fusión" del panel de propiedades de YMM4:
|
|
||||||
0=Normal,1=Síntesis de interpolación,2=Comparación (oscura),
|
|
||||||
3=Multiplicar,4=Color de relleno,5=Burn-in (lineal),
|
|
||||||
6=Comparación (clara),7=Pantalla,8=Color sin máscara,
|
|
||||||
9=Sin máscara (lineal) - Aditivo,10=Adición,11=Superponer,
|
|
||||||
12=Luz suave,13=Luz dura,14=Luz viva,15=Luz lineal,
|
|
||||||
16=Pin Light,17=Mezcla dura,18=diferencia,19=Excluido,
|
|
||||||
20=Sustracción,21=División,22=Tono,23=Saturación,24=Color,
|
|
||||||
25=Luminosidad,26=Comparación de colores (claro),27=Fondo,
|
|
||||||
28=Comparación de colores (oscuro),29=Supresión,
|
|
||||||
30=Recorte en el fondo,31=Sólo partes no superpuestas,
|
|
||||||
32=Máscara de inversión de color. Los valores fuera de rango
|
|
||||||
o no válidos se tratan como 0 (Normal).
|
|
||||||
"draw_state" : un booleano que decide si este efecto emite su
|
|
||||||
imagen de trabajo. true emite la imagen de trabajo; false deja
|
|
||||||
pasar la entrada sin cambios. Sirve para emitir la imagen de
|
|
||||||
trabajo sin obj.draw ni setpixel, o para suprimir la salida.
|
|
||||||
Funciona en ambos motores.
|
|
||||||
"drawtarget" : cambia el destino de obj.draw / obj.drawpoly.
|
|
||||||
"framebuffer" (por defecto) compone en el búfer de fotograma.
|
|
||||||
"tempbuffer" compone en el búfer de trabajo tmp en el momento. En
|
|
||||||
obj.setoption("drawtarget", "tempbuffer", w, h) los valores w, h
|
|
||||||
dan el tamaño con que se inicializa el búfer tmp; omítelos para
|
|
||||||
conservarlo. Recupera el resultado de tmp a la imagen de trabajo
|
|
||||||
con obj.copybuffer("obj", "tmp"). La composición en tempbuffer es
|
|
||||||
normal (source-over); blend se aplica al dibujo en framebuffer.
|
|
||||||
Funciona en ambos motores.
|
|
||||||
|
|
||||||
o obj.pixeloption(nombre, valor)
|
o obj.pixeloption(nombre, valor)
|
||||||
Guarda como estado una opción para las operaciones de píxeles.
|
Guarda como estado una opción para las operaciones de píxeles.
|
||||||
|
|
||||||
o obj.setanchor(nombre, cantidad [, opción, ..])
|
|
||||||
Muestra puntos de anclaje en la vista previa para ajustar sus
|
|
||||||
coordenadas arrastrando con el ratón. Las coordenadas ajustadas se
|
|
||||||
guardan con el proyecto.
|
|
||||||
nombre : el nombre de la variable Lua que recibe las coordenadas,
|
|
||||||
como cadena. La variable se dispone como pos={x0,y0,x1,y1,…}, o
|
|
||||||
{x0,y0,z0,x1,y1,z1,…} con "xyz". Las coordenadas son relativas
|
|
||||||
al centro del objeto.
|
|
||||||
cantidad : el número de puntos de anclaje. Hasta 32.
|
|
||||||
opción : se enumeran como cadenas.
|
|
||||||
"line" : une los puntos de anclaje con líneas.
|
|
||||||
"loop" : une los puntos de anclaje y cierra el bucle.
|
|
||||||
"star" : une cada punto de anclaje con el centro del objeto.
|
|
||||||
"arm" : une el centro del objeto con cada punto en orden.
|
|
||||||
"xyz" : trata los puntos como coordenadas 3D. 2D por defecto.
|
|
||||||
Devuelve el número de puntos de anclaje. Funciona en ambos motores.
|
|
||||||
El modo de barra "track" aún no se admite y devuelve 0.
|
|
||||||
Ejemplo:
|
|
||||||
num = obj.track0
|
|
||||||
obj.setanchor("pos", num, "loop")
|
|
||||||
for i = 0, num - 1 do
|
|
||||||
obj.draw(pos[i * 2 + 1], pos[i * 2 + 2])
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 Table -
|
- ymm4 Table -
|
||||||
|
|||||||
@@ -501,61 +501,10 @@
|
|||||||
Opsi yang saat ini memengaruhi penggambaran:
|
Opsi yang saat ini memengaruhi penggambaran:
|
||||||
"antialias" : 0 = tetangga terdekat, selain itu interpolasi linear
|
"antialias" : 0 = tetangga terdekat, selain itu interpolasi linear
|
||||||
(obj.draw / obj.drawpoly).
|
(obj.draw / obj.drawpoly).
|
||||||
"blend" : nomor mode blend (obj.draw / obj.drawpoly). Urutan yang
|
|
||||||
sama (mulai dari 0) dengan dropdown "Mode blend" pada panel
|
|
||||||
properti YMM4:
|
|
||||||
0=Normal,1=Larut,2=Gelap,3=Multiply,4=Bakar warna,
|
|
||||||
5=Bakar linier,6=Terang,7=Layar,8=Peleburan warna,
|
|
||||||
9=Peleburan linier (tambah),10=Tambah,11=Overlay,
|
|
||||||
12=Cahaya lembut,13=Cahaya keras,14=Cahaya hidup,
|
|
||||||
15=Cahaya linier,16=Cahaya pin,17=Campuran keras,
|
|
||||||
18=Perbedaan,19=Ekslklusi,20=Pengurangan,21=Divisi,22=Hue,
|
|
||||||
23=Saturasi,24=Warna,25=Pencahayaan,26=Warna terang,
|
|
||||||
27=Belakang,28=Warna gelap,29=Bersih,
|
|
||||||
30=Potong dengan latar belakang,
|
|
||||||
31=Hanya bagian yang tidak tumpang tindih,32=Mask inversi warna.
|
|
||||||
Nilai di luar jangkauan atau tidak valid dianggap 0 (Normal).
|
|
||||||
"draw_state" : boolean yang menentukan apakah efek ini
|
|
||||||
mengeluarkan citra kerjanya. true mengeluarkan citra kerja;
|
|
||||||
false meneruskan input apa adanya. Berguna untuk mengeluarkan
|
|
||||||
citra kerja tanpa obj.draw atau setpixel, atau untuk menekan
|
|
||||||
keluaran. Bekerja pada kedua mesin.
|
|
||||||
"drawtarget" : mengganti tujuan gambar obj.draw / obj.drawpoly.
|
|
||||||
"framebuffer" (bawaan) mengomposit ke frame buffer. "tempbuffer"
|
|
||||||
mengomposit ke buffer kerja tmp secara langsung. Pada
|
|
||||||
obj.setoption("drawtarget", "tempbuffer", w, h), w, h adalah
|
|
||||||
ukuran untuk menginisialisasi buffer tmp; hilangkan untuk
|
|
||||||
mempertahankannya. Kembalikan hasil tmp ke citra kerja dengan
|
|
||||||
obj.copybuffer("obj", "tmp"). Komposit ke tempbuffer bersifat
|
|
||||||
normal (source-over); blend berlaku untuk gambar ke framebuffer.
|
|
||||||
Bekerja pada kedua mesin.
|
|
||||||
|
|
||||||
o obj.pixeloption(name, value)
|
o obj.pixeloption(name, value)
|
||||||
Menyimpan opsi untuk operasi piksel sebagai status.
|
Menyimpan opsi untuk operasi piksel sebagai status.
|
||||||
|
|
||||||
o obj.setanchor(name, count [, option, ..])
|
|
||||||
Menampilkan titik jangkar pada pratinjau agar koordinatnya dapat
|
|
||||||
disesuaikan dengan menyeret mouse. Koordinat yang disesuaikan
|
|
||||||
disimpan bersama proyek.
|
|
||||||
name : nama variabel Lua yang menerima koordinat, sebagai string.
|
|
||||||
Variabel disusun sebagai pos={x0,y0,x1,y1,…}, atau
|
|
||||||
{x0,y0,z0,x1,y1,z1,…} dengan "xyz". Koordinat relatif terhadap
|
|
||||||
pusat objek.
|
|
||||||
count : jumlah titik jangkar. Hingga 32.
|
|
||||||
option : dicantumkan sebagai string.
|
|
||||||
"line" : menghubungkan titik jangkar dengan garis.
|
|
||||||
"loop" : menghubungkan titik jangkar dan menutup lingkaran.
|
|
||||||
"star" : menghubungkan tiap titik jangkar ke pusat objek.
|
|
||||||
"arm" : menghubungkan pusat objek ke tiap titik secara berurutan.
|
|
||||||
"xyz" : memperlakukan titik sebagai koordinat 3D. Bawaan 2D.
|
|
||||||
Mengembalikan jumlah titik jangkar. Bekerja pada kedua mesin.
|
|
||||||
Mode bilah "track" belum didukung dan mengembalikan 0.
|
|
||||||
Contoh:
|
|
||||||
num = obj.track0
|
|
||||||
obj.setanchor("pos", num, "loop")
|
|
||||||
for i = 0, num - 1 do
|
|
||||||
obj.draw(pos[i * 2 + 1], pos[i * 2 + 2])
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 Table -
|
- ymm4 Table -
|
||||||
|
|||||||
@@ -490,57 +490,10 @@
|
|||||||
停止させません(getoption は設定値を返し、未設定は 0)。
|
停止させません(getoption は設定値を返し、未設定は 0)。
|
||||||
現在描画へ反映される項目:
|
現在描画へ反映される項目:
|
||||||
"antialias" : 0 で最近傍、それ以外で線形補間(obj.draw/drawpoly)。
|
"antialias" : 0 で最近傍、それ以外で線形補間(obj.draw/drawpoly)。
|
||||||
"blend" : obj.draw / obj.drawpoly の合成モードを番号で指定します。
|
|
||||||
YMM4 のプロパティパネルにある「合成モード」のドロップダウンと
|
|
||||||
並び順が同じで、番号は 0 から始まります。
|
|
||||||
0=通常,1=ディザ合成,2=比較(暗),3=乗算,4=焼き込みカラー,
|
|
||||||
5=焼き込み(リニア),6=比較(明),7=スクリーン,8=覆い焼きカラー,
|
|
||||||
9=覆い焼き(リニア) - 加算,10=加算,11=オーバーレイ,
|
|
||||||
12=ソフトライト,13=ハードライト,14=ビビッドライト,15=リニアライト,
|
|
||||||
16=ピンライト,17=ハードミックス,18=差分,19=除外,20=減算,21=除算,
|
|
||||||
22=色相,23=彩度,24=カラー,25=輝度,26=カラー比較(明),27=背景,
|
|
||||||
28=カラー比較(暗),29=削除,30=背景でクリッピング,
|
|
||||||
31=重ならない部分のみ,32=色反転マスク。
|
|
||||||
範囲外の値や数値以外を指定した場合は通常モードになります。
|
|
||||||
"draw_state" : このエフェクトが作業画像を出力するかどうかを
|
|
||||||
真偽値で決めます。true で作業画像を出力し、false で入力を
|
|
||||||
そのまま通します。obj.draw や setpixel を使わずに作業画像を
|
|
||||||
そのまま出力させたいときや、逆に出力を止めたいときに使います。
|
|
||||||
両エンジンで動きます。
|
|
||||||
"drawtarget" : obj.draw / obj.drawpoly の描画先を切り替えます。
|
|
||||||
"framebuffer"(既定)ではフレームバッファへ合成します。
|
|
||||||
"tempbuffer" では作業用の tmp バッファへその場で合成します。
|
|
||||||
obj.setoption("drawtarget", "tempbuffer", w, h) の w, h は
|
|
||||||
tmp バッファを初期化するサイズで、省略すると初期化しません。
|
|
||||||
tmp へ描いた結果は obj.copybuffer("obj", "tmp") で作業画像へ
|
|
||||||
戻せます。tempbuffer への合成は通常(ソースオーバー)で、blend は
|
|
||||||
framebuffer への描画に適用されます。両エンジンで動きます。
|
|
||||||
|
|
||||||
○obj.pixeloption(名前, 値)
|
○obj.pixeloption(名前, 値)
|
||||||
ピクセル操作のオプションを状態として保持します。
|
ピクセル操作のオプションを状態として保持します。
|
||||||
|
|
||||||
○obj.setanchor(名前, 個数 [, オプション, ..])
|
|
||||||
アンカーポイントをプレビュー上に表示し、マウスドラッグで座標を
|
|
||||||
調整できるようにします。調整した座標はプロジェクトへ保存されます。
|
|
||||||
名前 : 座標を格納する Lua 変数の名前を文字列で指定します。
|
|
||||||
変数は pos={x0,y0,x1,y1,…} の並びで、xyz 指定時は
|
|
||||||
{x0,y0,z0,x1,y1,z1,…} になります。座標はオブジェクトの
|
|
||||||
中心が原点です。
|
|
||||||
個数 : アンカーポイントの数を指定します。最大 32 個です。
|
|
||||||
オプション : 文字列で列挙できます。
|
|
||||||
"line" : アンカーポイントを線で結びます。
|
|
||||||
"loop" : アンカーポイントを線で結び一周させます。
|
|
||||||
"star" : 各アンカーポイントとオブジェクトの中心を線で結びます。
|
|
||||||
"arm" : オブジェクトの中心から各アンカーポイントへ順に線で結びます。
|
|
||||||
"xyz" : アンカーポイントを 3D 座標で扱います。既定は 2D です。
|
|
||||||
戻り値は設置したアンカーポイントの数です。両エンジンで動きます。
|
|
||||||
名前に "track" を指定するトラックバー連携は現在未対応で、0 を返します。
|
|
||||||
例:
|
|
||||||
num = obj.track0
|
|
||||||
obj.setanchor("pos", num, "loop")
|
|
||||||
for i = 0, num - 1 do
|
|
||||||
obj.draw(pos[i * 2 + 1], pos[i * 2 + 2])
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 テーブル -
|
- ymm4 テーブル -
|
||||||
|
|||||||
@@ -484,56 +484,10 @@
|
|||||||
스크립트를 중단시키지 않습니다(getoption은 설정값을 반환, 미설정은 0).
|
스크립트를 중단시키지 않습니다(getoption은 설정값을 반환, 미설정은 0).
|
||||||
현재 그리기에 반영되는 항목:
|
현재 그리기에 반영되는 항목:
|
||||||
"antialias" : 0이면 최근접, 그 외는 선형 보간(obj.draw / obj.drawpoly).
|
"antialias" : 0이면 최근접, 그 외는 선형 보간(obj.draw / obj.drawpoly).
|
||||||
"blend" : 합성 모드 번호(obj.draw / obj.drawpoly). YMM4 속성
|
|
||||||
패널의 "합성 모드" 드롭다운과 동일한 순서(0부터 시작):
|
|
||||||
0=보통,1=디졸브,2=비교(어두움),3=곱하기,4=색상번,
|
|
||||||
5=구워내기(선형),6=비교(밝음),7=화면,8=색상 닷지,
|
|
||||||
9=선형 닷지 ‐ 가산,10=가산,11=오버레이,12=소프트 라이트,
|
|
||||||
13=하드 라이트,14=선명한 라이트,15=리니어 라이트,16=핀 라이트,
|
|
||||||
17=하드 믹스,18=차분,19=제외,20=감산,21=디비전,22=색조,
|
|
||||||
23=채도,24=컬러,25=밝기,26=색상 비교(밝음),27=배경,
|
|
||||||
28=색상 비교(어두운),29=삭제,30=배경에서 클리핑,
|
|
||||||
31=겹치지 않는 부분만,32=색상 반전 마스크.
|
|
||||||
범위를 벗어나거나 잘못된 값은 0(보통)으로 처리합니다.
|
|
||||||
"draw_state" : 이 이펙트가 작업 이미지를 출력할지를 불리언으로
|
|
||||||
정합니다. true는 작업 이미지를 출력하고, false는 입력을 그대로
|
|
||||||
통과시킵니다. obj.draw나 setpixel을 쓰지 않고 작업 이미지를
|
|
||||||
출력하거나, 반대로 출력을 막을 때 사용합니다. 두 엔진 모두에서
|
|
||||||
동작합니다.
|
|
||||||
"drawtarget" : obj.draw / obj.drawpoly의 그리기 대상을 바꿉니다.
|
|
||||||
"framebuffer"(기본)는 프레임 버퍼에 합성합니다. "tempbuffer"는
|
|
||||||
작업용 tmp 버퍼에 즉시 합성합니다.
|
|
||||||
obj.setoption("drawtarget", "tempbuffer", w, h)의 w, h는 tmp
|
|
||||||
버퍼를 초기화하는 크기이며, 생략하면 초기화하지 않습니다. tmp에
|
|
||||||
그린 결과는 obj.copybuffer("obj", "tmp")로 작업 이미지에 되돌릴
|
|
||||||
수 있습니다. tempbuffer로의 합성은 보통(소스 오버)이며, blend는
|
|
||||||
framebuffer 그리기에 적용됩니다. 두 엔진 모두에서 동작합니다.
|
|
||||||
|
|
||||||
○ obj.pixeloption(이름, 값)
|
○ obj.pixeloption(이름, 값)
|
||||||
픽셀 조작 옵션을 상태로 보존합니다.
|
픽셀 조작 옵션을 상태로 보존합니다.
|
||||||
|
|
||||||
○ obj.setanchor(이름, 개수 [, 옵션, ..])
|
|
||||||
프리뷰에 앵커 포인트를 표시하고 마우스 드래그로 좌표를 조정할 수
|
|
||||||
있게 합니다. 조정한 좌표는 프로젝트에 저장됩니다.
|
|
||||||
이름 : 좌표를 받을 Lua 변수 이름을 문자열로 지정합니다. 변수는
|
|
||||||
pos={x0,y0,x1,y1,…} 배열이며, "xyz" 지정 시
|
|
||||||
{x0,y0,z0,x1,y1,z1,…}가 됩니다. 좌표는 오브젝트 중심이
|
|
||||||
원점입니다.
|
|
||||||
개수 : 앵커 포인트 수를 지정합니다. 최대 32개입니다.
|
|
||||||
옵션 : 문자열로 열거할 수 있습니다.
|
|
||||||
"line" : 앵커 포인트를 선으로 잇습니다.
|
|
||||||
"loop" : 앵커 포인트를 선으로 잇고 한 바퀴 닫습니다.
|
|
||||||
"star" : 각 앵커 포인트를 오브젝트 중심과 선으로 잇습니다.
|
|
||||||
"arm" : 오브젝트 중심에서 각 앵커 포인트로 차례로 잇습니다.
|
|
||||||
"xyz" : 앵커 포인트를 3D 좌표로 다룹니다. 기본은 2D입니다.
|
|
||||||
설치한 앵커 포인트 수를 반환합니다. 두 엔진 모두에서 동작합니다.
|
|
||||||
이름에 "track"을 지정하는 트랙바 연동은 현재 미지원이며 0을 반환합니다.
|
|
||||||
예:
|
|
||||||
num = obj.track0
|
|
||||||
obj.setanchor("pos", num, "loop")
|
|
||||||
for i = 0, num - 1 do
|
|
||||||
obj.draw(pos[i * 2 + 1], pos[i * 2 + 2])
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 테이블 -
|
- ymm4 테이블 -
|
||||||
|
|||||||
@@ -477,49 +477,10 @@
|
|||||||
(getoption 返回设置值,未设置为 0)。
|
(getoption 返回设置值,未设置为 0)。
|
||||||
当前会反映到绘制的项目:
|
当前会反映到绘制的项目:
|
||||||
"antialias" : 0 为最近邻,其它为线性插值(obj.draw / obj.drawpoly)。
|
"antialias" : 0 为最近邻,其它为线性插值(obj.draw / obj.drawpoly)。
|
||||||
"blend" : 合成模式编号(obj.draw / obj.drawpoly)。与 YMM4 属性
|
|
||||||
面板中「合成模式」下拉列表相同的顺序(从 0 开始):
|
|
||||||
0=普通,1=溶解,2=对比(暗),3=相乘,4=颜色加深,5=线性加深,
|
|
||||||
6=对比(明),7=画面,8=颜色减淡,9=线性减淡 (相加),10=相加,
|
|
||||||
11=覆盖,12=柔光,13=强光,14=亮光,15=明暗,16=点光,17=实色混合,
|
|
||||||
18=反差,19=排除,20=相减,21=相除,22=色相,23=饱和度,24=颜色,
|
|
||||||
25=亮度,26=颜色对比(明),27=背景,28=颜色对比(暗),29=清除,
|
|
||||||
30=按背景裁剪,31=异或,32=颜色反转遮罩。超出范围或无效的值
|
|
||||||
将按 0(普通)处理。
|
|
||||||
"draw_state" : 用布尔值决定该效果是否输出工作图像。true 输出
|
|
||||||
工作图像,false 则原样传递输入。可用于不使用 obj.draw 或
|
|
||||||
setpixel 也输出工作图像,或反过来抑制输出。两个引擎都可用。
|
|
||||||
"drawtarget" : 切换 obj.draw / obj.drawpoly 的绘制目标。
|
|
||||||
"framebuffer"(默认)合成到帧缓冲。"tempbuffer" 则就地合成到
|
|
||||||
工作用 tmp 缓冲。obj.setoption("drawtarget", "tempbuffer", w, h)
|
|
||||||
中的 w, h 是初始化 tmp 缓冲的尺寸,省略则不初始化。画到 tmp 的
|
|
||||||
结果可用 obj.copybuffer("obj", "tmp") 取回工作图像。合成到
|
|
||||||
tempbuffer 使用普通(源覆盖),blend 应用于 framebuffer 的绘制。
|
|
||||||
两个引擎都可用。
|
|
||||||
|
|
||||||
○ obj.pixeloption(名称, 值)
|
○ obj.pixeloption(名称, 值)
|
||||||
将像素操作的选项作为状态保存。
|
将像素操作的选项作为状态保存。
|
||||||
|
|
||||||
○ obj.setanchor(名称, 个数 [, 选项, ..])
|
|
||||||
在预览上显示锚点,可用鼠标拖动调整坐标。调整后的坐标会随工程保存。
|
|
||||||
名称 : 以字符串指定接收坐标的 Lua 变量名。变量排列为
|
|
||||||
pos={x0,y0,x1,y1,…},指定 "xyz" 时为 {x0,y0,z0,x1,y1,z1,…}。
|
|
||||||
坐标以对象中心为原点。
|
|
||||||
个数 : 指定锚点数量。最多 32 个。
|
|
||||||
选项 : 可用字符串列举。
|
|
||||||
"line" : 用线连接锚点。
|
|
||||||
"loop" : 用线连接锚点并闭合一圈。
|
|
||||||
"star" : 将每个锚点与对象中心用线连接。
|
|
||||||
"arm" : 从对象中心依次连接到各锚点。
|
|
||||||
"xyz" : 以 3D 坐标处理锚点。默认是 2D。
|
|
||||||
返回设置的锚点数量。两个引擎都可用。
|
|
||||||
名称指定 "track" 的轨道条联动暂不支持,返回 0。
|
|
||||||
示例:
|
|
||||||
num = obj.track0
|
|
||||||
obj.setanchor("pos", num, "loop")
|
|
||||||
for i = 0, num - 1 do
|
|
||||||
obj.draw(pos[i * 2 + 1], pos[i * 2 + 2])
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 表 -
|
- ymm4 表 -
|
||||||
|
|||||||
@@ -477,50 +477,10 @@
|
|||||||
(getoption 回傳設定值,未設定為 0)。
|
(getoption 回傳設定值,未設定為 0)。
|
||||||
目前會反映到繪製的項目:
|
目前會反映到繪製的項目:
|
||||||
"antialias" : 0 為最近鄰,其它為線性內插(obj.draw / obj.drawpoly)。
|
"antialias" : 0 為最近鄰,其它為線性內插(obj.draw / obj.drawpoly)。
|
||||||
"blend" : 合成模式編號(obj.draw / obj.drawpoly)。與 YMM4 屬性
|
|
||||||
面板中「合成模式」下拉選單相同的順序(從 0 開始):
|
|
||||||
0=一般,1=Dissolve,2=比較(暗),3=相乘,4=Color burn,5=陰影,
|
|
||||||
6=比較(亮),7=畫面,8=Color dodge,9=Linear dodge (Add),
|
|
||||||
10=相加,11=覆蓋,12=Soft light,13=Hard light,14=Vivid light,
|
|
||||||
15=明暗,16=Pin light,17=Hard mix,18=差異,19=Exclution,
|
|
||||||
20=相減,21=Division,22=Hue,23=Saturation,24=色,25=亮度,
|
|
||||||
26=Lighter color,27=Behind,28=Darker color,29=Clear,
|
|
||||||
30=Clipping by background,31=XOR,32=Color inversion mask。
|
|
||||||
超出範圍或無效的值將視為 0(一般)。
|
|
||||||
"draw_state" : 以布林值決定此效果是否輸出工作影像。true 輸出
|
|
||||||
工作影像,false 則原樣傳遞輸入。可用於不使用 obj.draw 或
|
|
||||||
setpixel 也輸出工作影像,或反過來抑制輸出。兩個引擎都可用。
|
|
||||||
"drawtarget" : 切換 obj.draw / obj.drawpoly 的繪製目標。
|
|
||||||
"framebuffer"(預設)合成到影格緩衝。"tempbuffer" 則就地合成到
|
|
||||||
工作用 tmp 緩衝。obj.setoption("drawtarget", "tempbuffer", w, h)
|
|
||||||
中的 w, h 是初始化 tmp 緩衝的尺寸,省略則不初始化。畫到 tmp 的
|
|
||||||
結果可用 obj.copybuffer("obj", "tmp") 取回工作影像。合成到
|
|
||||||
tempbuffer 使用一般(來源覆蓋),blend 套用於 framebuffer 的繪製。
|
|
||||||
兩個引擎都可用。
|
|
||||||
|
|
||||||
○ obj.pixeloption(名稱, 值)
|
○ obj.pixeloption(名稱, 值)
|
||||||
將像素操作的選項作為狀態保存。
|
將像素操作的選項作為狀態保存。
|
||||||
|
|
||||||
○ obj.setanchor(名稱, 個數 [, 選項, ..])
|
|
||||||
在預覽上顯示錨點,可用滑鼠拖曳調整座標。調整後的座標會隨專案保存。
|
|
||||||
名稱 : 以字串指定接收座標的 Lua 變數名。變數排列為
|
|
||||||
pos={x0,y0,x1,y1,…},指定 "xyz" 時為 {x0,y0,z0,x1,y1,z1,…}。
|
|
||||||
座標以物件中心為原點。
|
|
||||||
個數 : 指定錨點數量。最多 32 個。
|
|
||||||
選項 : 可用字串列舉。
|
|
||||||
"line" : 用線連接錨點。
|
|
||||||
"loop" : 用線連接錨點並閉合一圈。
|
|
||||||
"star" : 將每個錨點與物件中心用線連接。
|
|
||||||
"arm" : 從物件中心依序連接到各錨點。
|
|
||||||
"xyz" : 以 3D 座標處理錨點。預設是 2D。
|
|
||||||
回傳設置的錨點數量。兩個引擎都可用。
|
|
||||||
名稱指定 "track" 的軌道條連動暫不支援,回傳 0。
|
|
||||||
範例:
|
|
||||||
num = obj.track0
|
|
||||||
obj.setanchor("pos", num, "loop")
|
|
||||||
for i = 0, num - 1 do
|
|
||||||
obj.draw(pos[i * 2 + 1], pos[i * 2 + 2])
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 表 -
|
- ymm4 表 -
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ YukkuriMovieMaker4(YMM4)上で動作する、**Luaスクリプトでオブ
|
|||||||
|
|
||||||
座標・拡縮・回転・不透明度の制御に加えて、`obj.getpixel` / `obj.setpixel` / `obj.getpixeldata` によるピクセル単位の画像加工、アニメーション制作向けの数学ユーティリティ群(`anim` テーブル)、4 系統のトラックバー(Track0〜Track3)によるスクリプトへのパラメータ受け渡しに対応しています。
|
座標・拡縮・回転・不透明度の制御に加えて、`obj.getpixel` / `obj.setpixel` / `obj.getpixeldata` によるピクセル単位の画像加工、アニメーション制作向けの数学ユーティリティ群(`anim` テーブル)、4 系統のトラックバー(Track0〜Track3)によるスクリプトへのパラメータ受け渡しに対応しています。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -213,13 +213,12 @@ AviUtl のアニメーション効果スクリプト(`.anm` 系)のうち、
|
|||||||
- **`@` による複数セクション**: 1 つのスクリプトに `@名前` で複数の効果が定義されている場合、先頭のセクションのみを実行します。
|
- **`@` による複数セクション**: 1 つのスクリプトに `@名前` で複数の効果が定義されている場合、先頭のセクションのみを実行します。
|
||||||
- **`obj.rand(st, ed [, seed [, frame]])`**: 指定範囲(`st`〜`ed`)の整数を返す決定論的な乱数です。`seed` と `frame` が同じであれば常に同じ値を返し、`frame` を省略すると現在のフレームを用います。従来エンジン(MoonSharp)と高速ランタイム(LuaJIT)で同じ値を返します。
|
- **`obj.rand(st, ed [, seed [, frame]])`**: 指定範囲(`st`〜`ed`)の整数を返す決定論的な乱数です。`seed` と `frame` が同じであれば常に同じ値を返し、`frame` を省略すると現在のフレームを用います。従来エンジン(MoonSharp)と高速ランタイム(LuaJIT)で同じ値を返します。
|
||||||
- **`obj.load("figure", 名前, 色, サイズ [, ライン [, アスペクト]])`**: 円・四角形・三角形・五角形・六角形・星形を生成し、オブジェクトのバッファを置き換えて描画します(出力は図形サイズに合わせて生成され、中心に配置されます)。`ライン` を省略するか `0` で塗りつぶし、サイズ以上の値でも塗りつぶしになります。`アスペクト`(-1.0〜1.0)で幅・高さを歪曲できます。
|
- **`obj.load("figure", 名前, 色, サイズ [, ライン [, アスペクト]])`**: 円・四角形・三角形・五角形・六角形・星形を生成し、オブジェクトのバッファを置き換えて描画します(出力は図形サイズに合わせて生成され、中心に配置されます)。`ライン` を省略するか `0` で塗りつぶし、サイズ以上の値でも塗りつぶしになります。`アスペクト`(-1.0〜1.0)で幅・高さを歪曲できます。
|
||||||
- **描画・メディア・バッファ・オプション API**: `obj.draw` / `obj.drawpoly` による描画合成、`obj.load` の `"text"` / `"image"` / `"movie"`、`obj.setfont`、`obj.copybuffer`、`obj.effect`、`obj.getvalue`、`obj.setoption` / `obj.getoption` / `obj.pixeloption` に対応しています。これらは従来エンジン(MoonSharp)と高速ランタイム(LuaJIT)の双方で動作します。`obj.setoption` では `antialias` に加えて、`obj.draw` / `obj.drawpoly` の合成モードを YMM4 の並びで指定する `blend`、描画先を `"framebuffer"` / `"tempbuffer"` で切り替える `drawtarget`、作業画像の出力可否を切り替える `draw_state` に対応します。
|
- **描画・メディア・バッファ・オプション API**: `obj.draw` / `obj.drawpoly` による描画合成、`obj.load` の `"text"` / `"image"` / `"movie"`、`obj.setfont`、`obj.copybuffer`、`obj.effect`、`obj.getvalue`、`obj.setoption` / `obj.getoption` / `obj.pixeloption` に対応しています。これらは従来エンジン(MoonSharp)と高速ランタイム(LuaJIT)の双方で動作します。
|
||||||
- **`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"` を指定するトラックバー連携は未対応です。
|
|
||||||
- **`obj.effect` の AviUtl/AviUtl2 互換マップ**: `obj.effect("エフェクト名", "パラメータ名", 値, …)` はまず互換マップを参照し、AviUtl/AviUtl2 の名前として宣言したエフェクトを、対応する YMM4 の映像エフェクトとプロパティへ変換して適用します。値の倍率とオフセットの変換まで宣言できます。互換マップに宣言が無い名前は、従来どおり YMM4 のエフェクト名・キーワードでそのまま解決するため、既存の呼び出しはそのまま動きます。この互換マップは YMM4 自身が AviUtl の `.exo` へ書き出す変換を逆向きにたどって構築しているため、往復しても結果が一致します。対象のエンジンは指定子 `--!aviutl` または `--!aviutl2` で切り替え、指定子を書かないときは `--!aviutl` として扱います。互換マップが対応するエフェクト名の一覧はドキュメントの「obj の関数」を参照してください。
|
- **`obj.effect` の AviUtl/AviUtl2 互換マップ**: `obj.effect("エフェクト名", "パラメータ名", 値, …)` はまず互換マップを参照し、AviUtl/AviUtl2 の名前として宣言したエフェクトを、対応する YMM4 の映像エフェクトとプロパティへ変換して適用します。値の倍率とオフセットの変換まで宣言できます。互換マップに宣言が無い名前は、従来どおり YMM4 のエフェクト名・キーワードでそのまま解決するため、既存の呼び出しはそのまま動きます。この互換マップは YMM4 自身が AviUtl の `.exo` へ書き出す変換を逆向きにたどって構築しているため、往復しても結果が一致します。対象のエンジンは指定子 `--!aviutl` または `--!aviutl2` で切り替え、指定子を書かないときは `--!aviutl` として扱います。互換マップが対応するエフェクト名の一覧はドキュメントの「obj の関数」を参照してください。
|
||||||
|
|
||||||
次のような機能は、この互換層では対象外です(呼び出しを含むスクリプトは意図どおりには動作しません)。
|
次のような機能は、この互換層では対象外です(呼び出しを含むスクリプトは意図どおりには動作しません)。
|
||||||
|
|
||||||
- `scene.set` / `scene.get` などの未実装関数
|
- `obj.setanchor`、`scene.set` / `scene.get` などの未実装関数
|
||||||
- `require` によるモジュール読み込み、`io` / `dofile` などの任意ファイルアクセス(`obj.load("image"/"movie")` のみ、先頭ヘッダー検証付きで対応)
|
- `require` によるモジュール読み込み、`io` / `dofile` などの任意ファイルアクセス(`obj.load("image"/"movie")` のみ、先頭ヘッダー検証付きで対応)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
+1
-99
@@ -167,110 +167,12 @@ obj.load("text", "サンプル")</code></pre>
|
|||||||
<tr><td><code>obj.draw([ox, oy, oz, zoom, alpha, aspect])</code></td><td>現在のバッファをオフセット・拡大率・不透明度を指定して描画する</td></tr>
|
<tr><td><code>obj.draw([ox, oy, oz, zoom, alpha, aspect])</code></td><td>現在のバッファをオフセット・拡大率・不透明度を指定して描画する</td></tr>
|
||||||
<tr><td><code>obj.drawpoly(x0,y0,z0, x1,y1,z1, x2,y2,z2, x3,y3,z3 [, u0,v0, ... ,u3,v3] [, alpha])</code></td><td>4 頂点のテクスチャ付きポリゴンを描画する。UV を省略すると画像全体を使う</td></tr>
|
<tr><td><code>obj.drawpoly(x0,y0,z0, x1,y1,z1, x2,y2,z2, x3,y3,z3 [, u0,v0, ... ,u3,v3] [, alpha])</code></td><td>4 頂点のテクスチャ付きポリゴンを描画する。UV を省略すると画像全体を使う</td></tr>
|
||||||
<tr><td><code>obj.copybuffer(dst, src)</code></td><td>バッファ間でコピーする。ID は <code>obj</code>(作業画像)・<code>tmp</code>・<code>cache:名前</code>。書き込み先が <code>obj</code> のときのみ作業画像を置き換える</td></tr>
|
<tr><td><code>obj.copybuffer(dst, src)</code></td><td>バッファ間でコピーする。ID は <code>obj</code>(作業画像)・<code>tmp</code>・<code>cache:名前</code>。書き込み先が <code>obj</code> のときのみ作業画像を置き換える</td></tr>
|
||||||
<tr><td><code>obj.setoption(name [, value])</code></td><td>オプションを設定する。<code>antialias</code> は <code>obj.draw</code> で参照される。<code>blend</code> は <code>obj.draw</code>/<code>obj.drawpoly</code> の合成モードを番号で指定する。番号は下記の「合成モード」を参照。<code>draw_state</code> は真偽値で、<code>true</code> なら作業画像を出力し、<code>false</code> なら入力をそのまま通す。<code>drawtarget</code> は <code>obj.draw</code>/<code>obj.drawpoly</code> の描画先を <code>"framebuffer"</code> と <code>"tempbuffer"</code> で切り替える。詳細は下記の「描画先」を参照</td></tr>
|
<tr><td><code>obj.setoption(name [, value])</code></td><td>オプションを設定する。<code>antialias</code> は <code>obj.draw</code> で参照される</td></tr>
|
||||||
<tr><td><code>obj.getoption(name)</code></td><td>設定したオプションを取得する</td></tr>
|
<tr><td><code>obj.getoption(name)</code></td><td>設定したオプションを取得する</td></tr>
|
||||||
<tr><td><code>obj.getvalue(name)</code></td><td><code>obj</code> の数値メンバーを名前で取得する</td></tr>
|
<tr><td><code>obj.getvalue(name)</code></td><td><code>obj</code> の数値メンバーを名前で取得する</td></tr>
|
||||||
<tr><td><code>obj.pixeloption(name [, value])</code></td><td>ピクセル処理向けのオプションを設定する</td></tr>
|
<tr><td><code>obj.pixeloption(name [, value])</code></td><td>ピクセル処理向けのオプションを設定する</td></tr>
|
||||||
<tr><td><code>obj.setanchor(name, count [, option, ...])</code></td><td>プレビュー上にドラッグ可能なアンカーポイントを表示し、その座標を <code>name</code> の Lua 変数へ格納する。設置数を返す。詳細は下記の「アンカーポイント」を参照</td></tr>
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h3>合成モード</h3>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<code>obj.setoption("blend", 番号)</code> は <code>obj.draw</code>/<code>obj.drawpoly</code> の描画に合成モードを設定します。
|
|
||||||
番号は YMM4 のプロパティパネルにある「合成モード」のドロップダウンと並び順が同じで、0 から始まります。
|
|
||||||
範囲外の値や数値以外を指定したときは通常モードになります。
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<pre><code>obj.setoption("blend", 3)
|
|
||||||
obj.draw()</code></pre>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<tr><th>番号</th><th>合成モード</th></tr>
|
|
||||||
<tr><td><code>0</code></td><td>通常</td></tr>
|
|
||||||
<tr><td><code>1</code></td><td>ディザ合成</td></tr>
|
|
||||||
<tr><td><code>2</code></td><td>比較(暗)</td></tr>
|
|
||||||
<tr><td><code>3</code></td><td>乗算</td></tr>
|
|
||||||
<tr><td><code>4</code></td><td>焼き込みカラー</td></tr>
|
|
||||||
<tr><td><code>5</code></td><td>焼き込み(リニア)</td></tr>
|
|
||||||
<tr><td><code>6</code></td><td>比較(明)</td></tr>
|
|
||||||
<tr><td><code>7</code></td><td>スクリーン</td></tr>
|
|
||||||
<tr><td><code>8</code></td><td>覆い焼きカラー</td></tr>
|
|
||||||
<tr><td><code>9</code></td><td>覆い焼き(リニア) - 加算</td></tr>
|
|
||||||
<tr><td><code>10</code></td><td>加算</td></tr>
|
|
||||||
<tr><td><code>11</code></td><td>オーバーレイ</td></tr>
|
|
||||||
<tr><td><code>12</code></td><td>ソフトライト</td></tr>
|
|
||||||
<tr><td><code>13</code></td><td>ハードライト</td></tr>
|
|
||||||
<tr><td><code>14</code></td><td>ビビッドライト</td></tr>
|
|
||||||
<tr><td><code>15</code></td><td>リニアライト</td></tr>
|
|
||||||
<tr><td><code>16</code></td><td>ピンライト</td></tr>
|
|
||||||
<tr><td><code>17</code></td><td>ハードミックス</td></tr>
|
|
||||||
<tr><td><code>18</code></td><td>差分</td></tr>
|
|
||||||
<tr><td><code>19</code></td><td>除外</td></tr>
|
|
||||||
<tr><td><code>20</code></td><td>減算</td></tr>
|
|
||||||
<tr><td><code>21</code></td><td>除算</td></tr>
|
|
||||||
<tr><td><code>22</code></td><td>色相</td></tr>
|
|
||||||
<tr><td><code>23</code></td><td>彩度</td></tr>
|
|
||||||
<tr><td><code>24</code></td><td>カラー</td></tr>
|
|
||||||
<tr><td><code>25</code></td><td>輝度</td></tr>
|
|
||||||
<tr><td><code>26</code></td><td>カラー比較(明)</td></tr>
|
|
||||||
<tr><td><code>27</code></td><td>背景</td></tr>
|
|
||||||
<tr><td><code>28</code></td><td>カラー比較(暗)</td></tr>
|
|
||||||
<tr><td><code>29</code></td><td>削除</td></tr>
|
|
||||||
<tr><td><code>30</code></td><td>背景でクリッピング</td></tr>
|
|
||||||
<tr><td><code>31</code></td><td>重ならない部分のみ</td></tr>
|
|
||||||
<tr><td><code>32</code></td><td>色反転マスク</td></tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<h3>描画先</h3>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<code>obj.setoption("drawtarget", 先)</code> は <code>obj.draw</code>/<code>obj.drawpoly</code> の描画先を切り替えます。
|
|
||||||
<code>"framebuffer"</code>(既定)ではフレームバッファへ合成します。
|
|
||||||
<code>"tempbuffer"</code> では作業用の <code>tmp</code> バッファへその場で合成します。
|
|
||||||
<code>obj.setoption("drawtarget", "tempbuffer", w, h)</code> の <code>w, h</code> は <code>tmp</code> バッファを初期化するサイズで、省略すると初期化しません。
|
|
||||||
<code>tmp</code> へ描いた結果は <code>obj.copybuffer("obj", "tmp")</code> で作業画像へ戻せます。
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<code>tempbuffer</code> への合成は通常(ソースオーバー)で、<code>blend</code> は <code>framebuffer</code> への描画に適用されます。
|
|
||||||
描画先の切り替えは両エンジンで動きます。
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<pre><code>obj.setoption("drawtarget", "tempbuffer", obj.w, obj.h)
|
|
||||||
obj.draw()
|
|
||||||
obj.setoption("drawtarget", "framebuffer")
|
|
||||||
obj.copybuffer("obj", "tmp")</code></pre>
|
|
||||||
|
|
||||||
<h3>アンカーポイント</h3>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<code>obj.setanchor(name, count [, option, ...])</code> は、プレビュー上にドラッグ可能なアンカーポイントを表示します。
|
|
||||||
ドラッグで調整した座標はプロジェクトへ保存され、<code>name</code> で指定した Lua 変数へ格納されます。
|
|
||||||
変数は <code>pos={x0,y0,x1,y1,…}</code> の並びで、<code>"xyz"</code> を指定すると <code>{x0,y0,z0,x1,y1,z1,…}</code> になります。
|
|
||||||
座標はオブジェクトの中心が原点です。個数は最大 32 個です。
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<tr><th>オプション</th><th>意味</th></tr>
|
|
||||||
<tr><td><code>"line"</code></td><td>アンカーポイントを線で結ぶ</td></tr>
|
|
||||||
<tr><td><code>"loop"</code></td><td>アンカーポイントを線で結び一周させる</td></tr>
|
|
||||||
<tr><td><code>"star"</code></td><td>各アンカーポイントとオブジェクトの中心を線で結ぶ</td></tr>
|
|
||||||
<tr><td><code>"arm"</code></td><td>オブジェクトの中心から各アンカーポイントへ順に線で結ぶ</td></tr>
|
|
||||||
<tr><td><code>"xyz"</code></td><td>アンカーポイントを 3D 座標で扱う。既定は 2D</td></tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
戻り値は設置したアンカーポイントの数です。両エンジンで動きます。
|
|
||||||
<code>name</code> に <code>"track"</code> を指定するトラックバー連携は現在未対応で、<code>0</code> を返します。
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<pre><code>num = obj.track0
|
|
||||||
obj.setanchor("pos", num, "loop")
|
|
||||||
for i = 0, num - 1 do
|
|
||||||
obj.draw(pos[i * 2 + 1], pos[i * 2 + 2])
|
|
||||||
end</code></pre>
|
|
||||||
|
|
||||||
<h3>互換マップ</h3>
|
<h3>互換マップ</h3>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
+11
-211
@@ -69,7 +69,6 @@ local CB_KIND_DRAWPOLY = 4
|
|||||||
local CB_KIND_LOADTEXT = 5
|
local CB_KIND_LOADTEXT = 5
|
||||||
local CB_KIND_LOADIMAGE = 6
|
local CB_KIND_LOADIMAGE = 6
|
||||||
local CB_KIND_LOADMOVIE = 7
|
local CB_KIND_LOADMOVIE = 7
|
||||||
local CB_KIND_SETANCHOR = 8
|
|
||||||
|
|
||||||
assert(loadfile(shimPath))()
|
assert(loadfile(shimPath))()
|
||||||
|
|
||||||
@@ -88,131 +87,6 @@ local buffers = {}
|
|||||||
local options = {}
|
local options = {}
|
||||||
local pixeloptions = {}
|
local pixeloptions = {}
|
||||||
local dirty = false
|
local dirty = false
|
||||||
local drawTarget = "frame"
|
|
||||||
|
|
||||||
local function sampleSource(src, srcW, srcH, u, v, linear)
|
|
||||||
if not linear then
|
|
||||||
local su = clamp(math.floor(u), 0, srcW - 1)
|
|
||||||
local sv = clamp(math.floor(v), 0, srcH - 1)
|
|
||||||
local si = (sv * srcW + su) * 4
|
|
||||||
return src[si], src[si + 1], src[si + 2], src[si + 3]
|
|
||||||
end
|
|
||||||
local fx = u - 0.5
|
|
||||||
local fy = v - 0.5
|
|
||||||
local x0 = math.floor(fx)
|
|
||||||
local y0 = math.floor(fy)
|
|
||||||
local tx = fx - x0
|
|
||||||
local ty = fy - y0
|
|
||||||
local b, g, r, a = 0, 0, 0, 0
|
|
||||||
for j = 0, 1 do
|
|
||||||
local sy = clamp(y0 + j, 0, srcH - 1)
|
|
||||||
local wy = (j == 0) and (1 - ty) or ty
|
|
||||||
for i = 0, 1 do
|
|
||||||
local sx = clamp(x0 + i, 0, srcW - 1)
|
|
||||||
local w = wy * ((i == 0) and (1 - tx) or tx)
|
|
||||||
local si = (sy * srcW + sx) * 4
|
|
||||||
b = b + src[si] * w
|
|
||||||
g = g + src[si + 1] * w
|
|
||||||
r = r + src[si + 2] * w
|
|
||||||
a = a + src[si + 3] * w
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return b, g, r, a
|
|
||||||
end
|
|
||||||
|
|
||||||
local function compositeOver(dst, di, sb, sg, sr, sa)
|
|
||||||
local inv = 1 - sa / 255
|
|
||||||
dst[di] = math.floor(clamp(sb + dst[di] * inv, 0, 255))
|
|
||||||
dst[di + 1] = math.floor(clamp(sg + dst[di + 1] * inv, 0, 255))
|
|
||||||
dst[di + 2] = math.floor(clamp(sr + dst[di + 2] * inv, 0, 255))
|
|
||||||
dst[di + 3] = math.floor(clamp(sa + dst[di + 3] * inv, 0, 255))
|
|
||||||
end
|
|
||||||
|
|
||||||
local function compositeDrawInto(dst, dstW, dstH, src, srcW, srcH, ox, oy, zoom, aspect, alpha, linear)
|
|
||||||
if srcW <= 0 or srcH <= 0 or dstW <= 0 or dstH <= 0 then return end
|
|
||||||
local ca = clamp(aspect, -1, 1)
|
|
||||||
local zx = zoom * (1 + ca)
|
|
||||||
local zy = zoom * (1 - ca)
|
|
||||||
if zx == 0 or zy == 0 then return end
|
|
||||||
local ka = clamp(alpha, 0, 1)
|
|
||||||
if ka <= 0 then return end
|
|
||||||
local halfW = srcW * 0.5
|
|
||||||
local halfH = srcH * 0.5
|
|
||||||
local spanX = math.abs(halfW * zx)
|
|
||||||
local spanY = math.abs(halfH * zy)
|
|
||||||
local x0 = math.max(0, math.floor(ox - spanX))
|
|
||||||
local x1 = math.min(dstW - 1, math.ceil(ox + spanX))
|
|
||||||
local y0 = math.max(0, math.floor(oy - spanY))
|
|
||||||
local y1 = math.min(dstH - 1, math.ceil(oy + spanY))
|
|
||||||
for py = y0, y1 do
|
|
||||||
for px = x0, x1 do
|
|
||||||
local u = (px + 0.5 - ox) / zx + halfW
|
|
||||||
local v = (py + 0.5 - oy) / zy + halfH
|
|
||||||
if u >= 0 and u < srcW and v >= 0 and v < srcH then
|
|
||||||
local sb, sg, sr, sa = sampleSource(src, srcW, srcH, u, v, linear)
|
|
||||||
compositeOver(dst, (py * dstW + px) * 4, sb * ka, sg * ka, sr * ka, sa * ka)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function compositeDrawPolyInto(dst, dstW, dstH, src, srcW, srcH, poly, alpha, linear)
|
|
||||||
if srcW <= 0 or srcH <= 0 or dstW <= 0 or dstH <= 0 then return end
|
|
||||||
local x0p, y0p = poly[0], poly[1]
|
|
||||||
local x1p, y1p = poly[3], poly[4]
|
|
||||||
local x3p, y3p = poly[9], poly[10]
|
|
||||||
local u0, v0 = poly[12], poly[13]
|
|
||||||
local u1, v1 = poly[14], poly[15]
|
|
||||||
local u3, v3 = poly[18], poly[19]
|
|
||||||
local det = u0 * (v1 - v3) - v0 * (u1 - u3) + (u1 * v3 - v1 * u3)
|
|
||||||
if math.abs(det) < 1e-9 then return end
|
|
||||||
local inv = 1 / det
|
|
||||||
local a = (x0p * (v1 - v3) - v0 * (x1p - x3p) + (x1p * v3 - v1 * x3p)) * inv
|
|
||||||
local b = (u0 * (x1p - x3p) - x0p * (u1 - u3) + (u1 * x3p - x1p * u3)) * inv
|
|
||||||
local c = (u0 * (v1 * x3p - x1p * v3) - v0 * (u1 * x3p - x1p * u3) + x0p * (u1 * v3 - v1 * u3)) * inv
|
|
||||||
local d = (y0p * (v1 - v3) - v0 * (y1p - y3p) + (y1p * v3 - v1 * y3p)) * inv
|
|
||||||
local e = (u0 * (y1p - y3p) - y0p * (u1 - u3) + (u1 * y3p - y1p * u3)) * inv
|
|
||||||
local f = (u0 * (v1 * y3p - y1p * v3) - v0 * (u1 * y3p - y1p * u3) + y0p * (u1 * v3 - v1 * u3)) * inv
|
|
||||||
local adet = a * e - b * d
|
|
||||||
if math.abs(adet) < 1e-9 then return end
|
|
||||||
local ka = clamp(alpha, 0, 1)
|
|
||||||
if ka <= 0 then return end
|
|
||||||
local minX, minY, maxX, maxY = poly[0], poly[1], poly[0], poly[1]
|
|
||||||
for i = 0, 3 do
|
|
||||||
local xx = poly[i * 3]
|
|
||||||
local yy = poly[i * 3 + 1]
|
|
||||||
if xx < minX then minX = xx end
|
|
||||||
if xx > maxX then maxX = xx end
|
|
||||||
if yy < minY then minY = yy end
|
|
||||||
if yy > maxY then maxY = yy end
|
|
||||||
end
|
|
||||||
local bx0 = math.max(0, math.floor(minX))
|
|
||||||
local bx1 = math.min(dstW - 1, math.ceil(maxX))
|
|
||||||
local by0 = math.max(0, math.floor(minY))
|
|
||||||
local by1 = math.min(dstH - 1, math.ceil(maxY))
|
|
||||||
for py = by0, by1 do
|
|
||||||
for px = bx0, bx1 do
|
|
||||||
local dx = (px + 0.5) - c
|
|
||||||
local dy = (py + 0.5) - f
|
|
||||||
local u = (e * dx - b * dy) / adet
|
|
||||||
local v = (-d * dx + a * dy) / adet
|
|
||||||
if u >= 0 and u < srcW and v >= 0 and v < srcH then
|
|
||||||
local sb, sg, sr, sa = sampleSource(src, srcW, srcH, u, v, linear)
|
|
||||||
compositeOver(dst, (py * dstW + px) * 4, sb * ka, sg * ka, sr * ka, sa * ka)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function ensureTemp()
|
|
||||||
local t = buffers["t"]
|
|
||||||
if not t then
|
|
||||||
local n = width * height * 4
|
|
||||||
t = { data = ffi.new("uint8_t[?]", n), w = width, h = height }
|
|
||||||
buffers["t"] = t
|
|
||||||
end
|
|
||||||
return t
|
|
||||||
end
|
|
||||||
|
|
||||||
local function bufferKind(id)
|
local function bufferKind(id)
|
||||||
local c = id:match("^%s*(.)")
|
local c = id:match("^%s*(.)")
|
||||||
@@ -225,7 +99,6 @@ local function bufferKind(id)
|
|||||||
return c, c
|
return c, c
|
||||||
end
|
end
|
||||||
|
|
||||||
local sandbox
|
|
||||||
local obj = {}
|
local obj = {}
|
||||||
local scene = {}
|
local scene = {}
|
||||||
local ymm4 = {}
|
local ymm4 = {}
|
||||||
@@ -446,12 +319,6 @@ function obj.effect(name, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function obj.draw(ox, oy, oz, zoom, alpha, aspect)
|
function obj.draw(ox, oy, oz, zoom, alpha, aspect)
|
||||||
if drawTarget == "temp" then
|
|
||||||
local t = ensureTemp()
|
|
||||||
compositeDrawInto(t.data, t.w, t.h, pixels, width, height,
|
|
||||||
ox or 0, oy or 0, zoom or 1, aspect or 0, alpha or 1, (options.antialias or 1) ~= 0)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
cbResult[0] = ox or 0
|
cbResult[0] = ox or 0
|
||||||
cbResult[1] = oy or 0
|
cbResult[1] = oy or 0
|
||||||
cbResult[2] = oz or 0
|
cbResult[2] = oz or 0
|
||||||
@@ -459,7 +326,6 @@ function obj.draw(ox, oy, oz, zoom, alpha, aspect)
|
|||||||
cbResult[4] = alpha or 1
|
cbResult[4] = alpha or 1
|
||||||
cbResult[5] = aspect or 0
|
cbResult[5] = aspect or 0
|
||||||
cbResult[6] = options.antialias or 1
|
cbResult[6] = options.antialias or 1
|
||||||
cbResult[7] = options.blend or 0
|
|
||||||
i32[OFF_CB_KIND] = CB_KIND_DRAW
|
i32[OFF_CB_KIND] = CB_KIND_DRAW
|
||||||
i32[OFF_STATUS] = STATUS_CALLBACK
|
i32[OFF_STATUS] = STATUS_CALLBACK
|
||||||
k32.SetEvent(doneEvent)
|
k32.SetEvent(doneEvent)
|
||||||
@@ -470,15 +336,14 @@ function obj.drawpoly(...)
|
|||||||
local n = select("#", ...)
|
local n = select("#", ...)
|
||||||
if n < 12 then return end
|
if n < 12 then return end
|
||||||
local a = { ... }
|
local a = { ... }
|
||||||
local p = {}
|
for i = 0, 11 do cbTagD[i] = a[i + 1] or 0 end
|
||||||
for i = 0, 11 do p[i] = a[i + 1] or 0 end
|
|
||||||
if n >= 20 then
|
if n >= 20 then
|
||||||
for i = 0, 7 do p[12 + i] = a[13 + i] or 0 end
|
for i = 0, 7 do cbTagD[12 + i] = a[13 + i] or 0 end
|
||||||
else
|
else
|
||||||
p[12] = 0; p[13] = 0
|
cbTagD[12] = 0; cbTagD[13] = 0
|
||||||
p[14] = width; p[15] = 0
|
cbTagD[14] = width; cbTagD[15] = 0
|
||||||
p[16] = width; p[17] = height
|
cbTagD[16] = width; cbTagD[17] = height
|
||||||
p[18] = 0; p[19] = height
|
cbTagD[18] = 0; cbTagD[19] = height
|
||||||
end
|
end
|
||||||
local alpha = 1
|
local alpha = 1
|
||||||
if n == 13 then
|
if n == 13 then
|
||||||
@@ -486,15 +351,8 @@ function obj.drawpoly(...)
|
|||||||
elseif n >= 21 then
|
elseif n >= 21 then
|
||||||
alpha = a[21] or 1
|
alpha = a[21] or 1
|
||||||
end
|
end
|
||||||
p[20] = alpha
|
cbTagD[20] = alpha
|
||||||
if drawTarget == "temp" then
|
|
||||||
local t = ensureTemp()
|
|
||||||
compositeDrawPolyInto(t.data, t.w, t.h, pixels, width, height, p, alpha, (options.antialias or 1) ~= 0)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
for i = 0, 20 do cbTagD[i] = p[i] end
|
|
||||||
cbTagD[21] = options.antialias or 1
|
cbTagD[21] = options.antialias or 1
|
||||||
cbTagD[22] = options.blend or 0
|
|
||||||
i32[OFF_CB_KIND] = CB_KIND_DRAWPOLY
|
i32[OFF_CB_KIND] = CB_KIND_DRAWPOLY
|
||||||
i32[OFF_STATUS] = STATUS_CALLBACK
|
i32[OFF_STATUS] = STATUS_CALLBACK
|
||||||
k32.SetEvent(doneEvent)
|
k32.SetEvent(doneEvent)
|
||||||
@@ -508,22 +366,10 @@ function obj.getvalue(target)
|
|||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function obj.setoption(name, value, a, b)
|
function obj.setoption(name, value)
|
||||||
if type(name) ~= "string" then return end
|
if type(name) ~= "string" then return end
|
||||||
if value == nil then value = true end
|
if value == nil then value = true end
|
||||||
options[name] = value
|
options[name] = value
|
||||||
if name == "drawtarget" then
|
|
||||||
if value == "tempbuffer" then
|
|
||||||
drawTarget = "temp"
|
|
||||||
if a ~= nil and b ~= nil then
|
|
||||||
local w = math.max(1, math.floor(a))
|
|
||||||
local h = math.max(1, math.floor(b))
|
|
||||||
buffers["t"] = { data = ffi.new("uint8_t[?]", w * h * 4), w = w, h = h }
|
|
||||||
end
|
|
||||||
else
|
|
||||||
drawTarget = "frame"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function obj.getoption(name)
|
function obj.getoption(name)
|
||||||
@@ -539,52 +385,12 @@ function obj.pixeloption(name, value)
|
|||||||
pixeloptions[name] = value
|
pixeloptions[name] = value
|
||||||
end
|
end
|
||||||
|
|
||||||
function obj.setanchor(name, count, ...)
|
|
||||||
if type(name) ~= "string" then return 0 end
|
|
||||||
count = math.floor(count or 0)
|
|
||||||
if count < 0 then count = 0 elseif count > 32 then count = 32 end
|
|
||||||
if name == "track" then return 0 end
|
|
||||||
|
|
||||||
local connection, is3d = 0, false
|
|
||||||
local optCount = select("#", ...)
|
|
||||||
for i = 1, optCount do
|
|
||||||
local o = select(i, ...)
|
|
||||||
if o == "line" then connection = 1
|
|
||||||
elseif o == "loop" then connection = 2
|
|
||||||
elseif o == "star" then connection = 3
|
|
||||||
elseif o == "arm" then connection = 4
|
|
||||||
elseif o == "xyz" then is3d = true end
|
|
||||||
end
|
|
||||||
|
|
||||||
local len = #name
|
|
||||||
if len > CB_TAG_MAX then len = CB_TAG_MAX end
|
|
||||||
ffi.copy(base + CB_TAG_OFFSET, name, len)
|
|
||||||
i32[OFF_CB_TAGLEN] = len
|
|
||||||
cbResult[0] = count
|
|
||||||
cbResult[1] = is3d and 1 or 0
|
|
||||||
cbResult[2] = connection
|
|
||||||
i32[OFF_CB_KIND] = CB_KIND_SETANCHOR
|
|
||||||
i32[OFF_STATUS] = STATUS_CALLBACK
|
|
||||||
k32.SetEvent(doneEvent)
|
|
||||||
k32.WaitForSingleObject(workEvent, INFINITE)
|
|
||||||
|
|
||||||
local stride = is3d and 3 or 2
|
|
||||||
local pos = {}
|
|
||||||
for i = 0, count - 1 do
|
|
||||||
pos[i * stride + 1] = cbTagD[i * stride + 0]
|
|
||||||
pos[i * stride + 2] = cbTagD[i * stride + 1]
|
|
||||||
if is3d then pos[i * stride + 3] = cbTagD[i * stride + 2] end
|
|
||||||
end
|
|
||||||
sandbox[name] = pos
|
|
||||||
return count
|
|
||||||
end
|
|
||||||
|
|
||||||
function obj.copybuffer(dst, src)
|
function obj.copybuffer(dst, src)
|
||||||
if type(dst) ~= "string" or type(src) ~= "string" then return end
|
if type(dst) ~= "string" or type(src) ~= "string" then return end
|
||||||
local sk, skey = bufferKind(src)
|
local sk, skey = bufferKind(src)
|
||||||
local data, w, h
|
local data, w, h
|
||||||
if sk == "o" then
|
if sk == "o" then
|
||||||
data = pixels
|
data = ffi.string(pixels, width * height * 4)
|
||||||
w = width; h = height
|
w = width; h = height
|
||||||
elseif sk == "t" or sk == "c" then
|
elseif sk == "t" or sk == "c" then
|
||||||
local b = buffers[skey]
|
local b = buffers[skey]
|
||||||
@@ -607,10 +413,7 @@ function obj.copybuffer(dst, src)
|
|||||||
obj.cz = 0
|
obj.cz = 0
|
||||||
obj.diagonal = math.sqrt(w * w + h * h)
|
obj.diagonal = math.sqrt(w * w + h * h)
|
||||||
elseif dk == "t" or dk == "c" then
|
elseif dk == "t" or dk == "c" then
|
||||||
local n = w * h * 4
|
buffers[dkey] = { data = data, w = w, h = h }
|
||||||
local arr = ffi.new("uint8_t[?]", n)
|
|
||||||
ffi.copy(arr, data, n)
|
|
||||||
buffers[dkey] = { data = arr, w = w, h = h }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -657,7 +460,7 @@ function obj.getobject(tag, frame)
|
|||||||
return buildObject()
|
return buildObject()
|
||||||
end
|
end
|
||||||
|
|
||||||
sandbox = {
|
local sandbox = {
|
||||||
obj = obj, scene = scene, ymm4 = ymm4,
|
obj = obj, scene = scene, ymm4 = ymm4,
|
||||||
anim = anim, bit32 = bit32, rawlen = rawlen,
|
anim = anim, bit32 = bit32, rawlen = rawlen,
|
||||||
math = math, string = string, table = table,
|
math = math, string = string, table = table,
|
||||||
@@ -753,15 +556,12 @@ while true do
|
|||||||
cacheTag = nil
|
cacheTag = nil
|
||||||
for k in pairs(options) do options[k] = nil end
|
for k in pairs(options) do options[k] = nil end
|
||||||
for k in pairs(pixeloptions) do pixeloptions[k] = nil end
|
for k in pairs(pixeloptions) do pixeloptions[k] = nil end
|
||||||
drawTarget = "frame"
|
|
||||||
font.family = ""; font.size = 34; font.bold = false; font.italic = false; font.color = 0xFFFFFF
|
font.family = ""; font.size = 34; font.bold = false; font.italic = false; font.color = 0xFFFFFF
|
||||||
math.randomseed(f64[31])
|
math.randomseed(f64[31])
|
||||||
setfenv(compiledChunk, sandbox)
|
setfenv(compiledChunk, sandbox)
|
||||||
local ok, err = pcall(compiledChunk)
|
local ok, err = pcall(compiledChunk)
|
||||||
if ok then
|
if ok then
|
||||||
storeFields()
|
storeFields()
|
||||||
local ds = options.draw_state
|
|
||||||
if ds == nil then f64[62] = 0 elseif ds == false or ds == 0 then f64[62] = 2 else f64[62] = 1 end
|
|
||||||
i32[OFF_PIXELSDIRTY] = dirty and 1 or 0
|
i32[OFF_PIXELSDIRTY] = dirty and 1 or 0
|
||||||
i32[OFF_STATUS] = 1
|
i32[OFF_STATUS] = 1
|
||||||
k32.SetEvent(doneEvent)
|
k32.SetEvent(doneEvent)
|
||||||
|
|||||||
新しいイシューから参照
ユーザーをブロックする