45 コミット
作成者 SHA1 メッセージ 日付
routersys d9070bdeac バージョンをv1.1.2へ更新する
リリース / build-and-release (workflow_dispatch) Actions がタグ v1.1.2 のコミットから作成しました
2026-10-03 17:22:48 +09:00
routersys 2b7a929669 資源が回収された後の処理器の描画の試験を追加する 2026-10-03 17:04:22 +09:00
routersys eb67256ca1 格子の資源が回収された後に計算し直す試験を追加する 2026-10-03 17:04:22 +09:00
routersys 8a5f7b53e1 格子の資源が回収された後の描画の試験を追加する 2026-10-03 17:04:21 +09:00
routersys 9c116a1260 回収された格子の資源を描画の前に作り直す
・GPUのメモリが逼迫して資源が回収された後に、描画が失敗し続ける不具合を修正-F
2026-10-03 17:04:21 +09:00
routersys 79862b930d 変異試験の失敗の閾値を55にする 2026-09-24 13:08:59 +09:00
routersys 81b545739b 余白が収まらない長い画像の試験を追加する 2026-09-24 11:54:28 +09:00
routersys ee7a85cd9c パイプラインを作れないときは試験を飛ばさずに失敗させる 2026-09-24 11:52:25 +09:00
routersys 9ec24b00fe 透明な画像に形が現れたときの試験を追加する 2026-09-24 10:41:43 +09:00
routersys ff13c1a766 広がりを変えた処理器が新しいものと同じ絵を描く試験を追加する 2026-09-24 10:41:34 +09:00
routersys 0cdcf11fbe 到達距離が長辺を基準にする試験を追加する 2026-09-24 10:41:22 +09:00
routersys dd06777c08 インクが画像と一緒に動く試験を追加する 2026-09-24 10:41:11 +09:00
routersys 1e18582f44 インクの色の試験を追加する 2026-09-24 10:41:00 +09:00
routersys 4252c58810 大きさを変えて使い回したパイプラインの試験を追加する 2026-09-24 10:40:50 +09:00
routersys 60b2370b82 インクが無いときの可視範囲の試験を追加する 2026-09-24 10:40:41 +09:00
routersys 7a0034f3ad 広がりに応じて可視範囲が狭まる試験を追加する 2026-09-24 10:40:31 +09:00
routersys 1a21a9e60c 可視範囲がインクに沿う試験を追加する 2026-09-24 10:40:21 +09:00
routersys 33cc856772 可視範囲の試験に到達距離の端まで届く場合を加える 2026-09-24 10:40:10 +09:00
routersys bff0005769 格子の長辺の分割数の試験を追加する 2026-09-24 10:39:58 +09:00
routersys 81ce384127 変異試験の並列数と制限時間をGPUに合わせる 2026-09-24 09:24:07 +09:00
routersys b0d741c590 シェーダーを変異試験の対象から外す 2026-09-23 19:23:39 +09:00
routersys 13c92459e4 本体の参照でプラットフォームを固定しない 2026-09-23 19:09:33 +09:00
routersys a9dcc62828 WPFアプリケーションの外での挙動の試験を追加する 2026-09-23 14:50:41 +09:00
routersys cef5bdd32f 処理器の試験を追加する 2026-09-23 14:50:23 +09:00
routersys 26da97454b カスタムエフェクトの試験を追加する 2026-09-23 14:49:54 +09:00
routersys de2e58b75d 文言の試験を追加する 2026-09-23 14:49:27 +09:00
routersys 5d76712859 パラメータの試験を既存群の形で書き直す 2026-09-23 14:49:09 +09:00
routersys daa74d6a66 相互運用の試験を土台の上に書き直す 2026-09-23 14:48:42 +09:00
routersys b348f039d8 浸透計算の試験を分ける 2026-09-23 14:48:00 +09:00
routersys b68951b020 格子の試験を分ける 2026-09-23 14:47:08 +09:00
routersys 87de86e372 管理メモリの試験を暖機の揺れに左右されない形にする 2026-09-23 14:46:53 +09:00
routersys b6fdbdb6ca 設定値の試験を分ける 2026-09-23 14:38:51 +09:00
routersys 4181291a5a 試験の土台を追加する 2026-09-23 14:37:52 +09:00
routersys c7188970d6 テストプロジェクトの設定を既存群に揃える 2026-09-23 14:37:27 +09:00
routersys 6f93866bb2 Stryker.NETで変異試験を行う 2026-09-23 14:36:46 +09:00
routersys 7ee8eaf92a テストの依存関係を最新にする 2026-09-23 14:32:55 +09:00
routersys ceee21d1b1 プルリクエストのテンプレートを追加する 2026-09-23 13:31:21 +09:00
routersys 8943b353bd Issueのテンプレートを追加する 2026-09-23 13:31:21 +09:00
routersys f3eafcb2f2 スポンサーの設定を追加する 2026-09-23 13:31:20 +09:00
routersys 76237f3fe9 貢献の手引きを追加する 2026-09-23 13:31:20 +09:00
routersys 7bc3784133 セキュリティポリシーを追加する 2026-09-23 13:31:20 +09:00
routersys 1c09cde8d1 行動規範を追加する 2026-09-23 13:31:19 +09:00
routersys ea67ece300 サムネイル画像の一新 2026-09-23 11:26:32 +09:00
routersys 86b7446190 説明文章の拡大縮小を83%へ変更 2026-09-23 10:18:37 +09:00
routersys 7b74727703 サムネイル画像の更新 2026-09-23 10:15:06 +09:00
35個のファイルの変更、2515行の追加、706行の削除

検索条件に一致するファイルはありません

+13
ファイルの表示
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-stryker": {
"version": "5.0.0",
"commands": [
"dotnet-stryker"
],
"rollForward": false
}
}
}
+1
ファイルの表示
@@ -0,0 +1 @@
github: routersys
+102
ファイルの表示
@@ -0,0 +1,102 @@
name: 不具合の報告
description: エラーが出る、強制終了する、出力が乱れる、README と違う動きをする、といった不具合を報告します。
title: "[Bug] "
labels: ["bug"]
body:
- type: markdown
attributes:
value: |
脆弱性はここに書かず、リポジトリのセキュリティポリシーに従って非公開で報告してください。
README と実際の動きが違い、文書のほうが誤りだと考えるときは、文書の不備を使ってください。
- type: input
id: plugin-version
attributes:
label: プラグインのバージョン
description: GitHub のリリースか、配布パッケージの Readme.txt の見出しで確かめられます。
placeholder: v1.0.0
validations:
required: true
- type: input
id: ymm4-version
attributes:
label: YukkuriMovieMaker4 のバージョン
description: YukkuriMovieMaker4 のメインウィンドウのタイトルに表示されるバージョンを、そのまま書いてください。
placeholder: v4.56.1.0 Lite
validations:
required: true
- type: input
id: os
attributes:
label: Windows のバージョン
description: winver を実行し、ビルド番号まで書いてください。
placeholder: Windows 11 24H2, 26100.2605
validations:
required: true
- type: input
id: gpu
attributes:
label: GPU とドライバー
description: 描画や GPU に関わる不具合では必ず書いてください。デバイスマネージャーか dxdiag に表示される GPU の名前と、ドライバーのバージョンです。
- type: textarea
id: expected
attributes:
label: 期待した動き
description: 何が起きると考えたか。README に根拠があれば、その箇所も書いてください。
validations:
required: true
- type: textarea
id: actual
attributes:
label: 実際の動き
description: 実際に起きたこと。エラー画面が出たときは、その内容を省略せずに貼ってください。
validations:
required: true
- type: textarea
id: steps
attributes:
label: 再現の手順
description: |
新しいプロジェクトから不具合が起きるまでの操作を、番号を付けて書いてください。変えた設定の項目と値も書いてください。
プロジェクトファイルや素材は、zip に圧縮して添付できます。添付したファイルは誰でも見られます。プロジェクトファイルには素材を置いたフォルダーのパスが記録されるので、公開できない情報が無いかを確かめてください。
placeholder: |
1. 新しいプロジェクトを作る
2. アイテムを置き、本プラグインを使う
3. 設定を変える
4. 不具合が起きる
validations:
required: true
- type: dropdown
id: frequency
attributes:
label: 起きる頻度
description: ときどき起きるときは、何回試して何回起きたかを、下の「その他」の欄に書いてください。
options:
- 毎回起きる
- ときどき起きる
- 一度だけ起きた
validations:
required: true
- type: textarea
id: context
attributes:
label: その他
description: 一緒に使っているほかのプラグインや、関係すると思われることを書いてください。
- type: checkboxes
id: checks
attributes:
label: 報告の前に
options:
- label: 最新のリリースを使っています。
required: true
- label: 既存の Issue を検索し、同じ報告が無いことを確かめました。
required: true
+5
ファイルの表示
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: YukkuriMovieMaker4 本体の不具合
url: https://manjubox.net/contact/
about: 本体に原因がある不具合は、YukkuriMovieMaker4 の「ヘルプ」の「フィードバックを送信」か、公式サイトのお問い合わせから報告してください。
+63
ファイルの表示
@@ -0,0 +1,63 @@
name: 文書の不備
description: 誤り、書き漏れ、実際の動きとの食い違いがある文書を報告します。
title: "[Docs] "
labels: ["documentation"]
body:
- type: markdown
attributes:
value: |
実際の動きと文書が食い違うときは、ここで報告して構いません。動きのほうが誤りだと考えるときは、不具合の報告を使ってください。
- type: dropdown
id: location
attributes:
label: 文書
options:
- README
- 配布パッケージの Readme.txt
- 設定の項目の名前や説明
- 貢献の手引き、セキュリティポリシー、行動規範
- その他
validations:
required: true
- type: input
id: reference
attributes:
label: 文書の中の位置
description: 見出し、行番号、設定の項目の名前のどれかを書いてください。
placeholder: README の「制限事項」の 2 つ目の項目
validations:
required: true
- type: textarea
id: says
attributes:
label: 今の記述
description: そのまま引用してください。元の文書を開かずに検討できるようにするためです。
validations:
required: true
- type: textarea
id: problem
attributes:
label: どこが問題か
description: |
誤り、書き漏れ、曖昧さのどれに当たるかを書いてください。それによって読む人が何を取り違えるかも書いてください。
実際の動きと食い違っているときは、文書と動きのどちらを直すべきと考えるかも書いてください。
validations:
required: true
- type: textarea
id: suggestion
attributes:
label: 提案する文面
description: 具体的な文面があると、早く直せます。
- type: checkboxes
id: checks
attributes:
label: 報告の前に
options:
- label: 最新のリリースか、既定のブランチの最新の文書で確かめました。
required: true
+42
ファイルの表示
@@ -0,0 +1,42 @@
name: 機能の提案
description: 新しい機能や設定の項目、既存の動きの変更を提案します。
title: "[Proposal] "
labels: ["enhancement"]
body:
- type: textarea
id: problem
attributes:
label: 困っていること
description: 今のプラグインでできないことや、手間がかかることを、利用者の立場で書いてください。
validations:
required: true
- type: textarea
id: workaround
attributes:
label: 今はどうしているか
description: 今の回避策と、それにかかる手間を書いてください。回避策が無ければ、その旨を書いてください。
validations:
required: true
- type: textarea
id: proposal
attributes:
label: 提案する動き
description: どう動いてほしいかを書いてください。設定の項目を増やす提案では、項目の名前、範囲、既定値の案も書いてください。
- type: textarea
id: alternatives
attributes:
label: 検討したほかの方法
description: ほかに考えた方法があれば、それでは足りない理由と一緒に書いてください。
- type: checkboxes
id: checks
attributes:
label: 提案の前に
options:
- label: 既存の Issue を検索し、同じ提案が無いことを確かめました。
required: true
- label: 最新のリリースに同じ機能が無いことを確かめました。
required: true
+49
ファイルの表示
@@ -0,0 +1,49 @@
name: 使い方の質問
description: 使い方や、実際の動きが仕様どおりかを尋ねます。
title: "[Question] "
labels: ["question"]
body:
- type: markdown
attributes:
value: |
プラグインの不具合だと分かっているときは、不具合の報告を使ってください。
- type: textarea
id: question
attributes:
label: 質問
description: 背景を書く前に、質問を 1 文か 2 文で書いてください。
validations:
required: true
- type: textarea
id: goal
attributes:
label: 何をしようとしているか
description: つまずいている操作だけでなく、最終的に何を作りたいかを書いてください。
validations:
required: true
- type: textarea
id: tried
attributes:
label: 試したこと
description: 試した設定と、そのとき実際に起きたことを書いてください。
- type: input
id: plugin-version
attributes:
label: プラグインのバージョン
placeholder: v1.0.0
validations:
required: true
- type: checkboxes
id: checks
attributes:
label: 質問の前に
options:
- label: README の該当する節を読みました。
required: true
- label: 既存の Issue を検索し、同じ質問が無いことを確かめました。
required: true
+1 -1
ファイルの表示
@@ -1,5 +1,5 @@
========================================
墨拡散 for YMM4 v1.1.1
墨拡散 for YMM4 v1.1.2
========================================
YukkuriMovieMaker4上で動作する、素材を墨の付置とみなし、
格子ボルツマン方程式による吸水紙中の浸透流で墨を外へにじませて描画する
+87
ファイルの表示
@@ -0,0 +1,87 @@
<!--
当てはまらない節は消してください。「関連する Issue」と「動きの変更」の節は残し、該当しないときは「なし」と書いてください。
-->
## 概要
<!--
何をどう変えたか。なぜその変更が必要か。
-->
## 関連する Issue
<!--
新しい機能、設定の項目や既定値の変更、大きめの不具合の修正、意図して出力を変える変更、互換性を損なう変更、コードの構成を大きく変える変更は、先に Issue で合意してください。
Issue が無い変更では、下の行を「なし」に書き換えてください。
-->
Closes #
## 変更の種類
<!-- 当てはまるものを残してください。 -->
- 不具合の修正
- 機能の追加
- 動きの変更
- 性能の改善
- テストの追加
- 依存関係の更新
- 文書
- ビルド、リリース
## 動きの変更
<!--
利用者から見て何が変わるか。設定の項目、既定値、出力の結果、エラーの出方の変化も含みます。
保存済みのプロジェクトの結果が変わるなら、必ず書いてください。
-->
## 検証
<!--
手元で実際に確かめた結果を書いてください。
- ビルドの結果と、テストのプロジェクトがあればテストの結果
- YukkuriMovieMaker4 で実際に動かして確かめたこと
- 実行できなかったテストと、その理由
実際に動かして観察したこと、コードを読んで判断したこと、推測したことを分けて書いてください。
-->
使った YukkuriMovieMaker4 のバージョン:
GPU に関わる変更では、使った GPU とドライバー:
## 確認
<!-- テストのプロジェクトが無いリポジトリでは、実装とテストを分ける項目を消してください。 -->
- [ ] 1 つの目的の変更だけを含み、関係の無い整理や整形を含めていない。
- [ ] どのコミットも、それ単独でビルドが通る。
- [ ] 実装の変更と、それを確かめるテストを、別のコミットに分けた。
- [ ] コミットの件名は日本語で書き、50 文字以内に収め、「〜する」の形で終えた。日本語で書けない場合は、その旨を「レビューで見てほしい点」に書いた。
- [ ] コミットの本文は、リリースノートでの変更の分類を指定する行を求められたときだけ書いた。
- [ ] 変更する箇所で既に使われている実装のパターンに従った。
- [ ] 新しく書いたコードにコメントを入れず、コメントアウトしたコードも残していない。既存のコメントとドキュメントコメントは残した。
- [ ] 自分の変更で増えたビルドの警告を直した。
- [ ] 出力を変えるつもりの無い変更では、変更前と変更後で出力が一致することを確かめた。
- [ ] この変更と関係の無い依存関係の更新を含めていない。
- [ ] 動きを変えた場合、README を直した。`.github/Plugin_Readme.txt` があるリポジトリでは、それも直した。
- [ ] バージョンを上げる変更を含めていない。
## 性能の改善を主張する場合
<!-- それ以外の場合は、この節ごと消してください。 -->
- [ ] 同じ機材、ドライバー、設定、電源の条件で、変更前と変更後のビルドを交互に繰り返し測った。
- [ ] 測定の間を空け、ほかのプロセスが GPU を使っていない状態で測った。
- [ ] 正しさの確認と性能の測定を、別々に実行した。
<!--
測定の条件と、測定値。
-->
## レビューで見てほしい点
<!--
判断に迷った点、意見を聞きたい点、意図して外した部分とその理由。
-->
+3 -1
ファイルの表示
@@ -362,4 +362,6 @@ MigrationBackup/
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd
# Stryker.NET
StrykerOutput/
+81
ファイルの表示
@@ -0,0 +1,81 @@
# Contributor Covenant 行動規範
## 私たちの約束
メンバー、貢献者、リーダーである私たちは、年齢、体格、目に見える障害と目に見えない障害、民族、性的特徴、性自認と性表現、経験の程度、教育、社会経済的地位、国籍、外見、人種、宗教、性的アイデンティティと性的指向を問わず、コミュニティへの参加を誰にとっても嫌がらせの無いものにすることを誓います。
私たちは、開かれていて誰もが歓迎される、多様で包摂的な、健全なコミュニティを作るように行動し、交流することを誓います。
## 私たちの基準
コミュニティのよい環境を作る行動の例は、次のとおりです。
- ほかの人に共感と思いやりを示す
- 異なる意見、視点、経験を尊重する
- 建設的な意見を伝え、また快く受け入れる
- 自分たちの誤りに責任を持ち、影響を受けた人に謝り、その経験から学ぶ
- 自分個人にとってだけでなく、コミュニティ全体にとって最善のことを考える
受け入れられない行動の例は、次のとおりです。
- 性的な言葉や画像を使うこと、どのような形であれ、相手に性的な関心を向けることや言い寄ること
- 荒らし、侮辱的または軽蔑的な発言、個人攻撃や政治的な攻撃
- 公の場か私的な場かを問わない嫌がらせ
- 住所やメールアドレスなど、ほかの人の個人情報を明示の許可なく公開すること
- 仕事の場で不適切と合理的に考えられるその他の行為
## 執行の責任
コミュニティリーダーは、受け入れられる行動の基準を明確にし、それを守らせる責任を負います。不適切、脅迫的、攻撃的、または有害と判断した行動には、適切で公正な是正措置をとります。
コミュニティリーダーは、この行動規範に沿わないコメント、コミット、コード、Wiki の編集、Issue、その他の貢献を削除、編集、または却下する権利と責任を持ちます。モデレーションの判断については、適切な場合に理由を伝えます。
## 適用範囲
この行動規範は、コミュニティのあらゆる場で適用されます。個人が公の場でコミュニティを公式に代表しているときにも適用されます。コミュニティを代表しているときとは、たとえば、公式のメールアドレスを使うとき、公式のソーシャルメディアのアカウントから投稿するとき、オンラインやオフラインのイベントで任命された代表として行動するときです。
## 執行
虐待的な言動、嫌がらせ、その他の受け入れられない行動は、執行を担当するコミュニティリーダーへ github.routersys@gmail.com で報告できます。コミュニティリーダーは、すべての苦情を速やかかつ公正に確認し、調査します。
すべてのコミュニティリーダーは、事案を報告した人のプライバシーと安全を尊重する義務を負います。
## 執行のガイドライン
コミュニティリーダーは、この行動規範に違反すると判断した行動への処置を決めるとき、次に示すコミュニティへの影響に応じたガイドラインに従います。
### 1. 是正
コミュニティへの影響: 不適切な言葉づかいや、コミュニティの中で、仕事の場にふさわしくない、または歓迎されないと判断されるその他の行動。
処置: コミュニティリーダーが、非公開の書面による警告を送ります。違反の内容を明らかにし、その行動がなぜ不適切だったかを説明します。公の場での謝罪を求めることがあります。
### 2. 警告
コミュニティへの影響: 1 回の出来事、または一連の行動による違反。
処置: 行動が続いた場合の処置を示した警告を送ります。警告を受けた人は、定められた期間、関係する人々とやり取りしてはいけません。行動規範を執行する人々へ、求められていないのに接触することも、これに含まれます。コミュニティの場だけでなく、ソーシャルメディアなど外部の場でのやり取りも避けなければなりません。これらの条件に違反すると、一時的または永久的な参加禁止につながることがあります。
### 3. 一時的な参加禁止
コミュニティへの影響: 不適切な行動を続けることを含む、コミュニティの基準への重大な違反。
処置: 定められた期間、コミュニティとのあらゆるやり取りと、コミュニティに向けた公の発信を禁止します。この期間中は、公の場か私的な場かを問わず、関係する人々とのやり取りを認めません。行動規範を執行する人々へ、求められていないのに接触することも、これに含まれます。これらの条件に違反すると、永久的な参加禁止につながることがあります。
### 4. 永久的な参加禁止
コミュニティへの影響: コミュニティの基準に繰り返し違反すること。不適切な行動を続けること、個人への嫌がらせ、特定の属性を持つ人々への攻撃や中傷も、これに当たります。
処置: コミュニティの中でのあらゆる公のやり取りを、永久に禁止します。
## 出典
この行動規範は、[Contributor Covenant][homepage] のバージョン 2.0 を基にしています。原文は https://www.contributor-covenant.org/version/2/0/code_of_conduct.html にあります。日本語の文は、公式の日本語訳 https://www.contributor-covenant.org/ja/version/2/0/code_of_conduct/ を基に、原文と照らし合わせて改めたものです。
Contributor Covenant は、[クリエイティブ・コモンズ 表示 4.0 国際 ライセンス](https://creativecommons.org/licenses/by/4.0/deed.ja)のもとで提供されています。
コミュニティへの影響に応じたガイドラインは、[Mozilla の行動規範の執行の段階](https://github.com/mozilla/diversity)に着想を得ています。
[homepage]: https://www.contributor-covenant.org
この行動規範についてのよくある質問と回答は、https://www.contributor-covenant.org/faq にあります。ほかの言語の訳は、https://www.contributor-covenant.org/translations にあります。
+168
ファイルの表示
@@ -0,0 +1,168 @@
# 貢献の手引き
本プラグインへの貢献に関心を持っていただき、ありがとうございます。この手引きは、Issue の立て方、プルリクエストの作り方、変更の確かめ方、コードとコミットの書き方を定めます。
本プラグインでできることとできないことは、[README](README.md) に書いてあります。まず README を読んでください。
---
## 目次
1. [貢献の進め方](#貢献の進め方)
2. [開発環境](#開発環境)
3. [Issue](#issue)
4. [プルリクエスト](#プルリクエスト)
5. [検証](#検証)
6. [コードの規約](#コードの規約)
7. [コミットの規約](#コミットの規約)
8. [行動規範](#行動規範)
---
## 貢献の進め方
誤字の修正、文書の修正、軽微な不具合の修正は、そのままプルリクエストを送ってください。
新しい機能、設定の項目や既定値の変更、大きめの不具合の修正、意図して出力を変える変更、互換性を損なう変更、コードの構成を大きく変える変更は、先に Issue を立ててください。実装を始める前に、意図する動きと変更の範囲について合意するためです。どちらに当たるか迷ったときも、Issue を立ててください。
脆弱性は Issue に書かず、[セキュリティポリシー](SECURITY.md)に従って非公開で報告してください。
Issue とプルリクエストは、日本語か英語で書いてください。
---
## 開発環境
| 項目 | 要件 |
|---|---|
| OS | Windows 10 バージョン 2004 以降の 64bit 版 |
| SDK | .NET 10 |
| YukkuriMovieMaker4 | ビルドがインストール先の DLL を参照するため、手元に入れておく |
| シェーダーのビルド | HLSL をビルドのときにコンパイルするリポジトリでは Windows SDK が要る。シェーダーを `.vcxproj` でビルドするリポジトリでは、Visual Studio 2026 の「C++ によるデスクトップ開発」も要る |
### 取得
リポジトリをフォークし、自分のフォークをクローンしてください。リポジトリはサブモジュールを含むことがあるので、`--recursive` を付けます。
```console
git clone --recursive https://github.com/<自分のアカウント>/<リポジトリ名>.git
```
`--recursive` を付けずにクローンしたときは、後から次のコマンドでサブモジュールを取得できます。
```console
git submodule update --init --recursive
```
作業は `main` から切ったブランチで行ってください。
### YukkuriMovieMaker4 の場所
YukkuriMovieMaker4 のインストール先は、MSBuild のプロパティ `YMM4DirPath` で渡します。値の末尾には `\` を付けてください。
- コマンドラインでは、`-p:YMM4DirPath="<インストール先>\"` を付けてビルドします。PowerShell 7 以降で実行してください。Windows PowerShell 5.1 と cmd では、末尾の `\"` が正しく渡らないため、末尾を `\\"` と書いてください。
- Visual Studio でビルドするときは、プラグインのプロジェクトのフォルダーか、その上のフォルダーに `Directory.Build.props` があれば、その `YMM4DirPath` を手元で書き換えます。無ければ、環境変数 `YMM4DirPath` を設定します。書き換えた `Directory.Build.props` はコミットに含めないでください。サブモジュールの中にある `Directory.Build.props` は書き換えないでください。
### ビルド
ソリューションを開き、Release でビルドしてください。
シェーダーを `.vcxproj` でビルドするリポジトリでは、コマンドラインのビルドに Visual Studio の MSBuild を使ってください。.NET SDK の `dotnet` コマンドは `.vcxproj` を扱えません。テストは、`dotnet test <名前>.Tests\<名前>.Tests.csproj` のようにテストのプロジェクトのファイルを指定して実行してください。ビルドの手順は、`.github/workflows/release.yml` があればそこに書いてあります。
多くのリポジトリでは、ビルドの後にプラグインが YukkuriMovieMaker4 の `user\plugin` フォルダーへ自動でコピーされます。
- YukkuriMovieMaker4 を起動したままだと、コピーの段階で失敗します。ビルドの前に終了してください。
- 配布版のプラグインを入れているときは、同じ名前のファイルが上書きされます。
- コマンドラインでソリューションをビルドしたときはコピーしないリポジトリがあります。その場合は、プラグインのプロジェクトを指定してビルドしてください。
- `.csproj` に `SkipPluginDeploy` の条件があるリポジトリでは、`-p:SkipPluginDeploy=true` を付けるとコピーせずにビルドできます。
---
## Issue
Issue はテンプレートから立ててください。不具合の報告、文書の不備、機能の提案、使い方の質問の 4 つがあります。
不具合の報告には、次の内容を書いてください。
- 期待した動きと、実際の動き
- 再現の手順。できれば、問題が起きる最小のプロジェクトファイルや素材
- プラグインのバージョン、YukkuriMovieMaker4 のバージョン、Windows のバージョン
- 描画や GPU に関わる不具合では、GPU の名前とドライバーのバージョン
- エラー画面に出た内容。省略せずに貼ってください
ときどきしか起きない不具合も、確実な再現の手順が無いまま報告して構いません。何回試して何回起きたかと、どの操作の後に起きたかを書いてください。
コードを読んで見つけた不具合を報告するときは、実際に再現を確かめたかどうかも書いてください。
Issue に添付したファイルは、誰でも見られます。プロジェクトファイルには、素材を置いたフォルダーのパスが記録されています。パスにユーザー名が含まれることがあるので、公開できない情報が無いかを確かめてから添付してください。
不具合の情報を自動で送信するプラグインでも、Issue での報告には意味があります。自動で送られるのは、例外の内容と実行環境の一部です。そこに至った操作、YukkuriMovieMaker4 のバージョン、GPU、例外を伴わない描画の乱れは届きません。
---
## プルリクエスト
1 つのプルリクエストには、1 つの目的の変更だけを含めてください。関係の無い整理、整形、依存関係の更新を含めないでください。依存関係を更新するのは、必要な機能を使うため、不具合やセキュリティの問題を直すため、互換性を保つためなど、具体的な理由があるときだけにしてください。
特に注意が要るのは、次の箇所です。
- 設定の項目と、その既定値と範囲。保存済みのプロジェクトの結果が変わるおそれがある
- 出力の結果。変えるつもりの無い変更で、映像や音が変わっていないか
- GPU のリソース、ファイル、ハンドルの寿命
- 破棄の処理と、失敗したときの処理
- YukkuriMovieMaker4 の内部に手を入れるプラグインでは、YukkuriMovieMaker4 のバージョンによる違い
動きを変えたときは、同じプルリクエストで README を直してください。`.github/Plugin_Readme.txt` があるリポジトリでは、それも直してください。`Plugin_Readme.txt` は配布パッケージに `Readme.txt` として入り、利用者の手元に残ります。
バージョンを上げる変更は、プルリクエストに含めないでください。バージョンの更新とリリースは、開発者が行います。
レビューを受けて直すときは、コミットを目的ごとのまとまりに保つため、ブランチの履歴を組み直して強制プッシュして構いません。
プルリクエストを送った時点で、その貢献をリポジトリと同じライセンスで提供することに同意したものとみなします。リポジトリのライセンスは、リポジトリの直下にあるライセンスのファイルに書いてあります。
---
## 検証
プルリクエストには、手元で実際に確かめた結果を書いてください。
- ビルドの結果と、テストのプロジェクトがあればテストの結果
- YukkuriMovieMaker4 で実際に動かして確かめたこと。使った YukkuriMovieMaker4 のバージョンを添え、GPU に関わる変更では GPU の名前とドライバーのバージョンも添えてください
- 実行できなかったテストと、その理由
実際に動かして観察したこと、コードを読んで判断したこと、推測したことを分けて書いてください。
出力を変えるつもりの無い変更では、変更前と変更後で出力が一致することを確かめてください。`--golden` と `--verify` を持つハーネスのプロジェクトがあるリポジトリでは、それで描画を比べられます。基準値は、手元の環境で変更前のコミットから作り直し、作り直した基準値はコミットに含めないでください。そのようなハーネスが無いリポジトリでは、変更前と変更後の出力を比べてください。サブモジュールの中にあるハーネスは、この確認には使いません。
性能の改善を主張するときは、1 回の測定で判断しないでください。
- 同じ機材、ドライバー、設定、電源の条件で、変更前と変更後のビルドを交互に繰り返し測ってください。
- GPU と CPU の温度で値が変わるため、測定の間を空けてください。
- ほかのプロセスが GPU を使っていない状態で測ってください。
- 正しさの確認と性能の測定は、別々に実行してください。確認のための処理が、測定値を変えるためです。
---
## コードの規約
変更する箇所で既に使われている実装のパターンと書き方に従ってください。既存の実装どうしが食い違っているときは、どちらかを機械的にまねず、README とテストに照らして意図された動きを確かめ、それに合うほうへ揃えてください。
自分の変更で増えたビルドの警告は、放置せず原因を直してください。
新しく書くコードには、コメントを入れず、コメントアウトしたコードも残さないでください。既存のコードにあるコメントとドキュメントコメントは残してください。
---
## コミットの規約
- 1 つのコミットは、目的ごとのまとまりを保てる範囲で、できるだけ小さくしてください。どのコミットも、それ単独でビルドが通るようにしてください。
- 実装の変更と、それを確かめるテストは、別のコミットに分けてください。
- 件名は日本語で書き、50 文字以内に収め、「〜する」の形で終えてください。「〜を追加する」「〜を直す」はよい例です。「〜の追加」「〜を修正」のように名詞で終える形は使いません。
- 件名を日本語で書けないときは、プルリクエストにその旨を書いてください。
- 本文は書かないでください。例外は、リリースノートでの変更の分類を指定する行だけです。この行が要るときは、書き方をレビューで伝えます。
---
## 行動規範
貢献するすべての人に、[行動規範](CODE_OF_CONDUCT.md)に従うことを求めます。
+12
ファイルの表示
@@ -0,0 +1,12 @@
namespace InkDispersion.Tests;
internal readonly record struct Bgra(byte Blue, byte Green, byte Red, byte Alpha)
{
public static Bgra Transparent => default;
public static Bgra Opaque(byte blue, byte green, byte red) => new(blue, green, red, byte.MaxValue);
public Bgra Premultiplied() => new(Premultiply(Blue), Premultiply(Green), Premultiply(Red), Alpha);
byte Premultiply(byte value) => (byte)Math.Round(value * (double)Alpha / byte.MaxValue, MidpointRounding.AwayFromZero);
}
+28
ファイルの表示
@@ -0,0 +1,28 @@
using System.Drawing;
using System.Numerics;
using Vortice.Direct2D1;
using YukkuriMovieMaker.Player.Video;
namespace InkDispersion.Tests;
internal static class EffectDescriptions
{
public const int Fps = 30;
static readonly Size ScreenSize = new(1920, 1080);
public static EffectDescription At(int frame, int length)
{
var timeline = new TimelineSourceDescription(
ScreenSize,
new FrameTime(frame, Fps),
new FrameTime(length, Fps),
Fps,
TimelineSourceUsage.Playing,
Guid.Empty,
[]);
var item = new TimelineItemSourceDescription(timeline, frame, length, 0);
var draw = new DrawDescription(Vector3.Zero, Vector2.Zero, Vector2.One, Vector3.Zero, Matrix4x4.Identity, InterpolationMode.Linear, 1d, false, []);
return new EffectDescription(item, draw, 0, 1, 0, 1);
}
}
+37
ファイルの表示
@@ -0,0 +1,37 @@
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace InkDispersion.Tests;
internal static class HostAssemblyResolver
{
const string MetadataKey = "HostDirectory";
const string AssemblyExtension = ".dll";
public static string Directory { get; } = ReadDirectory();
public static bool IsConfigured => Directory.Length != 0 && System.IO.Directory.Exists(Directory);
[ModuleInitializer]
internal static void Initialize()
{
if (!IsConfigured)
return;
AppDomain.CurrentDomain.AssemblyResolve += (_, arguments) =>
{
var name = new AssemblyName(arguments.Name).Name;
if (name is null)
return null;
var candidate = Path.Combine(Directory, name + AssemblyExtension);
return File.Exists(candidate) ? Assembly.LoadFrom(candidate) : null;
};
}
static string ReadDirectory() => typeof(HostAssemblyResolver).Assembly
.GetCustomAttributes<AssemblyMetadataAttribute>()
.FirstOrDefault(attribute => string.Equals(attribute.Key, MetadataKey, StringComparison.Ordinal))
?.Value ?? string.Empty;
}
+30
ファイルの表示
@@ -0,0 +1,30 @@
using System.Windows;
using Telemetry;
namespace InkDispersion.Tests;
public sealed class HostIntegrationTests
{
[Fact]
public void OutsideAWpfApplicationNoTelemetryIsStartedOrSent()
{
Assert.Null(Application.Current);
InkDispersionTelemetry.EnsureStartedOnce();
InkDispersionTelemetry.Report(new InvalidOperationException());
Assert.Null(ProcessState.Read("DrainClaimed"));
Assert.Null(ProcessState.Read("SentCount"));
}
[Fact]
public void OutsideAWpfApplicationTheEffectCanStillBeCreated()
{
Assert.Null(Application.Current);
var effect = new InkDispersionEffect();
Assert.Equal(Texts.InkDispersion, effect.Label);
Assert.Null(ProcessState.Read("DrainClaimed"));
}
}
+28 -10
ファイルの表示
@@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
@@ -12,50 +13,67 @@
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="10.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.v3" Version="3.2.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.10.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.v3" Version="4.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\InkDispersion\InkDispersion.csproj" SetConfiguration="Configuration=$(Configuration)" SetPlatform="Platform=x64">
<ProjectReference Include="..\InkDispersion\InkDispersion.csproj" SetConfiguration="Configuration=$(Configuration)">
<AdditionalProperties Condition="'$(BuildingSolutionFile)' != 'true'">SkipPluginDeploy=true</AdditionalProperties>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<AssemblyMetadata Include="HostDirectory" Value="$(YMM4DirPath)" />
</ItemGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>$(YMM4DirPath)Newtonsoft.Json.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="SharpGen.Runtime">
<HintPath>$(YMM4DirPath)SharpGen.Runtime.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="SharpGen.Runtime.COM">
<HintPath>$(YMM4DirPath)SharpGen.Runtime.COM.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Vortice.Direct2D1">
<HintPath>$(YMM4DirPath)Vortice.Direct2D1.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Vortice.Direct3D11">
<HintPath>$(YMM4DirPath)Vortice.Direct3D11.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Vortice.DirectX">
<HintPath>$(YMM4DirPath)Vortice.DirectX.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Vortice.DXGI">
<HintPath>$(YMM4DirPath)Vortice.DXGI.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Vortice.Mathematics">
<HintPath>$(YMM4DirPath)Vortice.Mathematics.dll</HintPath>
</Reference>
<Reference Include="YukkuriMovieMaker.Plugin">
<HintPath>$(YMM4DirPath)YukkuriMovieMaker.Plugin.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="YukkuriMovieMaker.Controls">
<HintPath>$(YMM4DirPath)YukkuriMovieMaker.Controls.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="YukkuriMovieMaker.Plugin">
<HintPath>$(YMM4DirPath)YukkuriMovieMaker.Plugin.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
+160
ファイルの表示
@@ -0,0 +1,160 @@
using System.Numerics;
using Vortice.Direct2D1;
using Vortice.Direct2D1.Effects;
using YukkuriMovieMaker.Commons;
namespace InkDispersion.Tests;
[Collection("Direct2D")]
public sealed class InkDispersionCustomEffectTests
{
const int AmountIndex = 0;
const int Width = 40;
const int Height = 24;
static readonly Bgra Blue = Bgra.Opaque(255, 0, 0);
static readonly Bgra HalfInk = new(0, 0, 0, 128);
static Rendering Render(IGraphicsDevicesAndContext devices, ID2D1Image source, ID2D1Image ink, float amount)
{
using var effect = new InkDispersionCustomEffect(devices);
effect.SetInput(0, source, true);
effect.SetInput(1, ink, true);
effect.Amount = amount;
using var output = effect.Output;
return Rendering.Capture(devices, output);
}
static AffineTransform2D Translate(IGraphicsDevicesAndContext devices, ID2D1Image image, float dx, float dy)
{
var transform = new AffineTransform2D(devices.DeviceContext)
{
InterPolationMode = AffineTransform2DInterpolationMode.NearestNeighbor,
BorderMode = BorderMode.Hard,
TransformMatrix = Matrix3x2.CreateTranslation(dx, dy),
};
transform.SetInput(0, image, true);
return transform;
}
static bool WithinRounding(Bgra expected, Bgra actual)
=> Math.Abs(expected.Blue - actual.Blue) <= 1 && Math.Abs(expected.Green - actual.Green) <= 1 && Math.Abs(expected.Red - actual.Red) <= 1 && Math.Abs(expected.Alpha - actual.Alpha) <= 1;
static Bgra Over(Bgra ink, Bgra source, float amount)
{
var inkAlpha = ink.Alpha * amount;
var keep = 1d - inkAlpha / byte.MaxValue;
byte Channel(byte inkValue, byte sourceValue) => (byte)Math.Round(inkValue * amount + sourceValue * keep, MidpointRounding.AwayFromZero);
return new Bgra(Channel(ink.Blue, source.Blue), Channel(ink.Green, source.Green), Channel(ink.Red, source.Red), Channel(ink.Alpha, source.Alpha));
}
[Fact]
public void TheEffectIsEnabledOnceCreated()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
using var effect = new InkDispersionCustomEffect(context);
Assert.True(effect.IsEnabled);
}
[Fact]
public void TheAmountStartsFromZero()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
using var effect = new InkDispersionCustomEffect(context);
Assert.Equal(0f, effect.GetFloatValue(AmountIndex));
}
[Theory]
[InlineData(-0.5f, 0f)]
[InlineData(0f, 0f)]
[InlineData(0.4f, 0.4f)]
[InlineData(1f, 1f)]
[InlineData(1.5f, 1f)]
[InlineData(float.MaxValue, 1f)]
public void TheAmountIsClampedToTheUnitRange(float value, float expected)
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
using var effect = new InkDispersionCustomEffect(context);
effect.Amount = value;
Assert.Equal(expected, effect.GetFloatValue(AmountIndex));
}
[Fact]
public void TheOutputBoundsCoverTheSourceAndTheInk()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
using var source = SourceImage.Solid(context, Width, Height, Blue);
using var ink = SourceImage.Solid(context, 8, 8, HalfInk);
using var moved = Translate(context, ink.Bitmap, 50f, -6f);
using var movedOutput = moved.Output;
using var effect = new InkDispersionCustomEffect(context);
effect.SetInput(0, source.Bitmap, true);
effect.SetInput(1, movedOutput, true);
using var output = effect.Output;
var bounds = context.DeviceContext.GetImageLocalBounds(output);
Assert.Equal(0f, bounds.Left);
Assert.Equal(-6f, bounds.Top);
Assert.Equal(58f, bounds.Right);
Assert.Equal((float)Height, bounds.Bottom);
}
[Theory]
[InlineData(0f)]
[InlineData(-1f)]
public void WithoutAmountTheSourcePassesThroughUntouched(float amount)
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
using var source = SourceImage.Solid(context, Width, Height, Blue);
using var ink = SourceImage.Solid(context, Width, Height, HalfInk);
var rendering = Render(context, source.Bitmap, ink.Bitmap, amount);
Assert.All(rendering.Coordinates(), point => Assert.Equal(source[point.X, point.Y], rendering[point.X, point.Y]));
}
[Theory]
[InlineData(1f)]
[InlineData(0.5f)]
[InlineData(0.25f)]
public void TheInkIsLaidOverTheSourceScaledByTheAmount(float amount)
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
using var source = SourceImage.Solid(context, Width, Height, Blue);
using var ink = SourceImage.Solid(context, Width, Height, HalfInk);
var expected = Over(HalfInk.Premultiplied(), Blue.Premultiplied(), amount);
var rendering = Render(context, source.Bitmap, ink.Bitmap, amount);
Assert.All(rendering.Coordinates(), point => Assert.True(WithinRounding(expected, rendering[point.X, point.Y]), $"({point.X}, {point.Y}) {rendering[point.X, point.Y]}"));
}
[Fact]
public void InkOutsideTheSourceIsDrawnOnItsOwn()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
using var source = SourceImage.Solid(context, Width, Height, Blue);
using var ink = SourceImage.Solid(context, 8, 8, HalfInk);
using var moved = Translate(context, ink.Bitmap, 50f, 4f);
using var movedOutput = moved.Output;
var expected = Over(HalfInk.Premultiplied(), Bgra.Transparent, 1f);
var rendering = Render(context, source.Bitmap, movedOutput, 1f);
Assert.True(WithinRounding(expected, rendering[53, 7]), $"{rendering[53, 7]}");
Assert.Equal(Blue.Premultiplied(), rendering[10, 10]);
Assert.Equal(Bgra.Transparent, rendering[45, 10]);
}
}
+394
ファイルの表示
@@ -0,0 +1,394 @@
using System.Globalization;
using System.Numerics;
using System.Windows.Media;
using ComputeWeave;
using Vortice.Direct2D1;
using Vortice.Direct2D1.Effects;
using YukkuriMovieMaker.Commons;
using YukkuriMovieMaker.Json;
using YukkuriMovieMaker.Player.Video;
namespace InkDispersion.Tests;
[Collection("Direct2D")]
public sealed class InkDispersionEffectProcessorTests
{
const int Size = 64;
const int Length = 30;
static readonly Bgra Gray = Bgra.Opaque(192, 192, 192);
static Bgra CenteredSquare(int x, int y) => x is >= 16 and < 48 && y is >= 16 and < 48 ? Gray : Bgra.Transparent;
static void RequireInterop(IGraphicsDevicesAndContext devices)
{
using var scheduler = ComputeExternalQueueScheduler.Create();
using var provider = InkDispersionInteropProvider.TryCreate(devices, scheduler, out var device);
if (provider is null || device is null)
Assert.Skip("Direct3D 11 and Direct3D 12 sharing is unavailable.");
}
static Animation Linear(double from, double to)
=> Json.LoadFromText<Animation>(string.Create(CultureInfo.InvariantCulture, $$"""{"AnimationType":"直線移動","Values":[{"Value":{{from}}},{"Value":{{to}}}]}"""))!;
static Rendering RenderFrame(IGraphicsDevicesAndContext devices, IVideoEffectProcessor processor, int frame)
{
processor.Update(EffectDescriptions.At(frame, Length));
return Rendering.Capture(devices, processor.Output);
}
static void AssertSameAsSource(Rendering rendering, SourceImage source)
{
Assert.Equal((0, 0, source.Width, source.Height), (rendering.Left, rendering.Top, rendering.Width, rendering.Height));
Assert.All(rendering.Coordinates(), point => Assert.Equal(source[point.X, point.Y], rendering[point.X, point.Y]));
}
static bool HasInkOutside(Rendering rendering, SourceImage source)
=> rendering.Coordinates().Any(point => (!source.Contains(point.X, point.Y) || source[point.X, point.Y].Alpha == 0) && rendering[point.X, point.Y].Alpha > 0);
static bool Tinted(byte channel, byte alpha, byte color) => Math.Abs(channel - color * alpha / 255d) <= 2d;
static double DistanceFrom(SourceImage source, int x, int y)
{
var dx = Math.Max(Math.Max(-x, x - (source.Width - 1)), 0);
var dy = Math.Max(Math.Max(-y, y - (source.Height - 1)), 0);
return Math.Sqrt(dx * dx + dy * dy);
}
[Fact]
public void TheProcessorHandsTheDrawDescriptionBackUnchanged()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
using var source = new SourceImage(context, Size, Size, CenteredSquare);
using var processor = new InkDispersionEffect().CreateVideoEffect(context);
processor.SetInput(source.Bitmap);
var description = EffectDescriptions.At(0, Length);
var draw = processor.Update(description);
Assert.Same(description.DrawDescription, draw);
}
[Fact]
public void TheInkSpreadsOutOfTheSource()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
RequireInterop(context);
using var source = new SourceImage(context, Size, Size, CenteredSquare);
using var processor = new InkDispersionEffect().CreateVideoEffect(context);
processor.SetInput(source.Bitmap);
var rendering = RenderFrame(context, processor, 0);
Assert.True(HasInkOutside(rendering, source));
Assert.All(rendering.Coordinates(), point =>
{
var pixel = rendering[point.X, point.Y];
Assert.InRange(pixel.Blue, 0, pixel.Alpha);
Assert.InRange(pixel.Green, 0, pixel.Alpha);
Assert.InRange(pixel.Red, 0, pixel.Alpha);
});
}
[Fact]
public void TheInkTakesTheChosenColor()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
RequireInterop(context);
using var source = new SourceImage(context, Size, Size, CenteredSquare);
using var processor = new InkDispersionEffect { InkColor = Color.FromRgb(32, 96, 160) }.CreateVideoEffect(context);
processor.SetInput(source.Bitmap);
var rendering = RenderFrame(context, processor, 0);
Assert.True(HasInkOutside(rendering, source));
Assert.All(rendering.Coordinates().Where(point => !source.Contains(point.X, point.Y) || source[point.X, point.Y].Alpha == 0), point =>
{
var pixel = rendering[point.X, point.Y];
Assert.True(Tinted(pixel.Red, pixel.Alpha, 32) && Tinted(pixel.Green, pixel.Alpha, 96) && Tinted(pixel.Blue, pixel.Alpha, 160), $"({point.X}, {point.Y}) {pixel}");
});
}
[Theory]
[InlineData(100, 50)]
[InlineData(-37, 21)]
public void TheInkTravelsWithTheImage(int dx, int dy)
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
RequireInterop(context);
using var source = new SourceImage(context, Size, Size, CenteredSquare);
using var moved = new AffineTransform2D(context.DeviceContext)
{
InterPolationMode = AffineTransform2DInterpolationMode.NearestNeighbor,
BorderMode = BorderMode.Hard,
TransformMatrix = Matrix3x2.CreateTranslation(dx, dy),
};
moved.SetInput(0, source.Bitmap, true);
using var movedOutput = moved.Output;
using var inPlaceProcessor = new InkDispersionEffect().CreateVideoEffect(context);
inPlaceProcessor.SetInput(source.Bitmap);
var inPlace = RenderFrame(context, inPlaceProcessor, 0);
using var travelledProcessor = new InkDispersionEffect().CreateVideoEffect(context);
travelledProcessor.SetInput(movedOutput);
var travelled = RenderFrame(context, travelledProcessor, 0);
Assert.Equal((inPlace.Left + dx, inPlace.Top + dy, inPlace.Width, inPlace.Height), (travelled.Left, travelled.Top, travelled.Width, travelled.Height));
Assert.All(inPlace.Coordinates(), point => Assert.True(inPlace[point.X, point.Y] == travelled[point.X + dx, point.Y + dy], $"({point.X}, {point.Y})"));
}
[Fact]
public void TheReachIsMeasuredAgainstTheLongSideOfTheImage()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
RequireInterop(context);
using var source = SourceImage.Solid(context, 96, 24, Gray);
var effect = new InkDispersionEffect();
effect.Water.Values[0].Value = 100d;
effect.Reach.Values[0].Value = 25d;
using var processor = effect.CreateVideoEffect(context);
processor.SetInput(source.Bitmap);
var rendering = RenderFrame(context, processor, 0);
var distances = rendering.Coordinates()
.Where(point => !source.Contains(point.X, point.Y) && rendering[point.X, point.Y].Alpha > 0)
.Select(point => DistanceFrom(source, point.X, point.Y))
.ToArray();
Assert.Contains(distances, distance => distance > 12d);
Assert.All(distances, distance => Assert.True(distance <= 30d, $"{distance}"));
}
public static readonly TheoryData<string, Action<InkDispersionEffect>> PassThroughSettings = new()
{
{ nameof(InkDispersionEffect.Amount), effect => effect.Amount.Values[0].Value = 0d },
{ nameof(InkDispersionEffect.Spread), effect => effect.Spread.Values[0].Value = 0d },
};
[Theory]
[MemberData(nameof(PassThroughSettings))]
public void AZeroAmountOrSpreadPassesTheImageThrough(string setting, Action<InkDispersionEffect> configure)
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
using var source = new SourceImage(context, Size, Size, CenteredSquare);
var effect = new InkDispersionEffect();
configure(effect);
using var processor = effect.CreateVideoEffect(context);
processor.SetInput(source.Bitmap);
var rendering = RenderFrame(context, processor, 0);
Assert.Equal((0, 0, Size, Size), (rendering.Left, rendering.Top, rendering.Width, rendering.Height));
Assert.All(rendering.Coordinates(), point => Assert.True(source[point.X, point.Y] == rendering[point.X, point.Y], $"{setting} ({point.X}, {point.Y})"));
}
[Fact]
public void AnImageThatLeavesNoRoomForTheInkPassesThroughUntouched()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
using var source = SourceImage.Solid(context, InkDispersionSettings.MaximumCanvasSize - 16, 8, Gray);
using var processor = new InkDispersionEffect().CreateVideoEffect(context);
processor.SetInput(source.Bitmap);
var rendering = RenderFrame(context, processor, 0);
AssertSameAsSource(rendering, source);
}
[Fact]
public void ReturningToAFrameReproducesItExactly()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
RequireInterop(context);
using var source = new SourceImage(context, Size, Size, CenteredSquare);
using var processor = new InkDispersionEffect().CreateVideoEffect(context);
processor.SetInput(source.Bitmap);
var first = RenderFrame(context, processor, 4);
RenderFrame(context, processor, 9);
var again = RenderFrame(context, processor, 4);
Assert.True(first.SamePixelsAs(again));
}
[Fact]
public void ANewProcessorDrawsTheSameInk()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
RequireInterop(context);
using var source = new SourceImage(context, Size, Size, CenteredSquare);
var effect = new InkDispersionEffect { Seed = 9 };
using var firstProcessor = effect.CreateVideoEffect(context);
firstProcessor.SetInput(source.Bitmap);
var first = RenderFrame(context, firstProcessor, 0);
using var secondProcessor = effect.CreateVideoEffect(context);
secondProcessor.SetInput(source.Bitmap);
var second = RenderFrame(context, secondProcessor, 0);
Assert.True(first.SamePixelsAs(second));
}
[Fact]
public void AnimatedSpreadIsReadAtEachFrame()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
RequireInterop(context);
using var source = new SourceImage(context, Size, Size, CenteredSquare);
var effect = new InkDispersionEffect();
effect.Spread.CopyFrom(Linear(0d, 100d));
using var processor = effect.CreateVideoEffect(context);
processor.SetInput(source.Bitmap);
var start = RenderFrame(context, processor, 0);
var end = RenderFrame(context, processor, Length - 1);
AssertSameAsSource(start, source);
Assert.True(HasInkOutside(end, source));
}
[Theory]
[InlineData(100d, 30d)]
[InlineData(30d, 100d)]
public void AProcessorThatDrewAnotherSpreadDrawsLikeAFreshOne(double firstSpread, double secondSpread)
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
RequireInterop(context);
using var source = new SourceImage(context, Size, Size, CenteredSquare);
var effect = new InkDispersionEffect();
effect.Spread.Values[0].Value = firstSpread;
using var processor = effect.CreateVideoEffect(context);
processor.SetInput(source.Bitmap);
RenderFrame(context, processor, 0);
effect.Spread.Values[0].Value = secondSpread;
using var fresh = effect.CreateVideoEffect(context);
fresh.SetInput(source.Bitmap);
var expected = RenderFrame(context, fresh, 0);
var reused = RenderFrame(context, processor, 0);
Assert.True(reused.SamePixelsAs(expected));
}
public static readonly TheoryData<string, Action<InkDispersionEffect>> LaterChanges = new()
{
{ nameof(InkDispersionEffect.Amount), effect => effect.Amount.Values[0].Value = 50d },
{ nameof(InkDispersionEffect.Spread), effect => effect.Spread.Values[0].Value = 30d },
{ nameof(InkDispersionEffect.Quality), effect => effect.Quality = InkDispersionQuality.Balanced },
{ nameof(InkDispersionEffect.Water), effect => effect.Water.Values[0].Value = 100d },
{ nameof(InkDispersionEffect.Reach), effect => effect.Reach.Values[0].Value = 10d },
{ nameof(InkDispersionEffect.Fiber), effect => effect.Fiber.Values[0].Value = 100d },
{ nameof(InkDispersionEffect.Sizing), effect => effect.Sizing.Values[0].Value = 100d },
{ nameof(InkDispersionEffect.Viscosity), effect => effect.Viscosity.Values[0].Value = 100d },
{ nameof(InkDispersionEffect.Drying), effect => effect.Drying.Values[0].Value = 100d },
{ nameof(InkDispersionEffect.Seed), effect => effect.Seed = 1 },
{ nameof(InkDispersionEffect.Density), effect => effect.Density.Values[0].Value = 20d },
{ nameof(InkDispersionEffect.Grain), effect => effect.Grain.Values[0].Value = 100d },
{ nameof(InkDispersionEffect.InkColor), effect => effect.InkColor = Colors.Crimson },
};
[Theory]
[MemberData(nameof(LaterChanges))]
public void EverySettingChangedAfterTheFirstFrameReachesTheEffect(string setting, Action<InkDispersionEffect> change)
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
RequireInterop(context);
using var source = new SourceImage(context, Size, Size, CenteredSquare);
var effect = new InkDispersionEffect();
using var processor = effect.CreateVideoEffect(context);
processor.SetInput(source.Bitmap);
var before = RenderFrame(context, processor, 0);
change(effect);
var after = RenderFrame(context, processor, 0);
Assert.False(before.SamePixelsAs(after), setting);
}
[Theory]
[InlineData(32, 128)]
[InlineData(128, 32)]
public void AResizedSourceKeepsProducingInk(int firstSize, int secondSize)
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
RequireInterop(context);
using var first = new SourceImage(context, firstSize, firstSize, (x, y) => Gray);
using var second = new SourceImage(context, secondSize, secondSize, (x, y) => Gray);
using var processor = new InkDispersionEffect().CreateVideoEffect(context);
processor.SetInput(first.Bitmap);
var before = RenderFrame(context, processor, 0);
processor.SetInput(second.Bitmap);
var after = RenderFrame(context, processor, 0);
Assert.True(HasInkOutside(before, first));
Assert.True(HasInkOutside(after, second));
Assert.Equal(secondSize > firstSize, after.Width > before.Width);
}
[Fact]
public void InkAppearsOnceATransparentSourceTakesShape()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
RequireInterop(context);
using var empty = SourceImage.Solid(context, Size, Size, Bgra.Transparent);
using var source = new SourceImage(context, Size, Size, CenteredSquare);
using var processor = new InkDispersionEffect().CreateVideoEffect(context);
processor.SetInput(empty.Bitmap);
var before = RenderFrame(context, processor, 0);
processor.SetInput(source.Bitmap);
var after = RenderFrame(context, processor, 0);
Assert.False(HasInkOutside(before, empty));
Assert.True(HasInkOutside(after, source));
}
[Fact(Timeout = 60000)]
public async Task AProcessorDrawsLikeAFreshOneAfterTheDeviceReclaimsIdleMemory()
{
await Task.Run(() =>
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
RequireInterop(context);
using var source = new SourceImage(context, Size, Size, (x, y) => x is >= 16 and < 48 && y is >= 16 and < 48 ? Bgra.Opaque(80, 200, 255) : Bgra.Transparent);
var effect = new InkDispersionEffect();
using var processor = effect.CreateVideoEffect(context);
processor.SetInput(source.Bitmap);
RenderFrame(context, processor, 0);
GraphicsDevice.GetDefault().TrimMemory();
var reclaimed = RenderFrame(context, processor, 0);
using var fresh = effect.CreateVideoEffect(context);
fresh.SetInput(source.Bitmap);
var expected = RenderFrame(context, fresh, 0);
Assert.True(reclaimed.SamePixelsAs(expected));
}, TestContext.Current.CancellationToken);
}
[Fact]
public void AFailureWhileUpdatingIsNotSwallowed()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
using var processor = new InkDispersionEffect().CreateVideoEffect(context);
Assert.ThrowsAny<Exception>(() => processor.Update(null!));
}
}
+185 -689
ファイルの表示
@@ -1,51 +1,58 @@
using System.Runtime.InteropServices;
using ComputeWeave;
using ComputeWeave.Interop;
using Vortice;
using Vortice.Direct2D1;
using Vortice.DXGI;
using Vortice.Mathematics;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
using System.Windows.Media;
using YukkuriMovieMaker.Commons;
using PixelFormat = Vortice.DCommon.PixelFormat;
using YukkuriMovieMaker.Controls;
using YukkuriMovieMaker.Exo;
using YukkuriMovieMaker.Json;
using YukkuriMovieMaker.Plugin.Effects;
using YukkuriMovieMaker.Project;
namespace InkDispersion.Tests;
public sealed class InkDispersionEffectTests
{
private static double ValueAt(YukkuriMovieMaker.Commons.Animation animation) => animation.GetValue(0, 1, 30);
static readonly Color DefaultInkColor = Color.FromArgb(255, 30, 26, 24);
private static InkDispersionPipeline.Parameters CreateParameters(
InkDispersionQuality quality = InkDispersionQuality.Balanced,
float spread = 1f,
float water = 0.6f,
float fiber = 0.5f,
float sizing = 0.3f,
float viscosity = 0.3f,
float drying = 0.4f,
float reachPixels = 40f,
float density = 0.8f,
float grain = 0.4f,
int seed = 0)
=> new(quality, spread, water, fiber, sizing, viscosity, drying, reachPixels, density, grain, 0.12f, 0.1f, 0.09f, seed);
static PropertyInfo Property(string name) => typeof(InkDispersionEffect).GetProperty(name)!;
static T Attribute<T>(string property) where T : Attribute => Property(property).GetCustomAttribute<T>()!;
static Animation[] Animations(InkDispersionEffect effect)
=> [effect.Amount, effect.Spread, effect.Water, effect.Reach, effect.Fiber, effect.Sizing, effect.Viscosity, effect.Drying, effect.Density, effect.Grain];
[Theory]
[InlineData(nameof(InkDispersionEffect.Amount), 100d, 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Spread), 100d, 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Water), 60d, 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Reach), 25d, 1d, 400d)]
[InlineData(nameof(InkDispersionEffect.Fiber), 50d, 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Sizing), 30d, 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Viscosity), 30d, 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Drying), 40d, 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Density), 80d, 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Grain), 40d, 0d, 100d)]
public void AnimatedParametersStartFromTheirDefaultsWithinTheirRange(string name, double defaultValue, double minimum, double maximum)
{
var effect = new InkDispersionEffect();
var animation = (Animation)Property(name).GetValue(effect)!;
Assert.Equal(defaultValue, animation.DefaultValue);
Assert.Equal(minimum, animation.MinValue);
Assert.Equal(maximum, animation.MaxValue);
Assert.Equal(defaultValue, animation.GetValue(0, 1, EffectDescriptions.Fps));
}
[Fact]
public void DefaultParameterValuesMatchSpecification()
public void QualitySeedAndInkColorStartFromTheirDefaults()
{
var effect = new InkDispersionEffect();
Assert.Equal(100d, ValueAt(effect.Amount), 6);
Assert.Equal(100d, ValueAt(effect.Spread), 6);
Assert.Equal(60d, ValueAt(effect.Water), 6);
Assert.Equal(25d, ValueAt(effect.Reach), 6);
Assert.Equal(50d, ValueAt(effect.Fiber), 6);
Assert.Equal(30d, ValueAt(effect.Sizing), 6);
Assert.Equal(30d, ValueAt(effect.Viscosity), 6);
Assert.Equal(40d, ValueAt(effect.Drying), 6);
Assert.Equal(80d, ValueAt(effect.Density), 6);
Assert.Equal(40d, ValueAt(effect.Grain), 6);
Assert.Equal(InkDispersionQuality.High, effect.Quality);
Assert.Equal(0, effect.Seed);
Assert.Equal(System.Windows.Media.Color.FromArgb(255, 30, 26, 24), effect.InkColor);
Assert.Equal(DefaultInkColor, effect.InkColor);
}
[Theory]
@@ -53,704 +60,193 @@ public sealed class InkDispersionEffectTests
[InlineData(-1, 0)]
[InlineData(0, 0)]
[InlineData(1234, 1234)]
public void SeedClampsNegativeInputToZero(int input, int expected)
[InlineData(10000, 10000)]
[InlineData(int.MaxValue, int.MaxValue)]
public void SeedNeverDropsBelowZero(int value, int expected)
{
var effect = new InkDispersionEffect { Seed = input };
var effect = new InkDispersionEffect { Seed = 5 };
effect.Seed = value;
Assert.Equal(expected, effect.Seed);
Assert.False(effect.HasErrors);
}
[Fact]
public void CreateExoVideoFiltersReturnsEmpty()
public void ChangingQualitySeedOrInkColorNotifiesTheEditor()
{
var effect = new InkDispersionEffect();
var changed = new List<string?>();
effect.PropertyChanged += (_, e) => changed.Add(e.PropertyName);
effect.Quality = InkDispersionQuality.Ultra;
effect.Seed = 7;
effect.InkColor = Colors.Crimson;
Assert.Equal([nameof(InkDispersionEffect.Quality), nameof(InkDispersionEffect.Seed), nameof(InkDispersionEffect.InkColor)], changed);
}
[Fact]
public void AssigningAnUnchangedOrClampedValueDoesNotNotify()
{
var effect = new InkDispersionEffect();
var changed = new List<string?>();
effect.PropertyChanged += (_, e) => changed.Add(e.PropertyName);
effect.Quality = InkDispersionQuality.High;
effect.Seed = 0;
effect.Seed = -1;
effect.InkColor = DefaultInkColor;
Assert.Empty(changed);
}
[Fact]
public void TheLabelIsTheLocalizedEffectName()
{
var effect = new InkDispersionEffect();
Assert.Empty(effect.CreateExoVideoFilters(0, null!));
Assert.Equal(Texts.InkDispersion, effect.Label);
}
[Fact]
public void TheTenNumericParametersReceiveTheAnimationParameters()
{
var effect = new InkDispersionEffect();
effect.SetAnimationParameters(120, EffectDescriptions.Fps);
Assert.All(Animations(effect), animation => Assert.Equal(120, animation.Length));
}
[Theory]
[InlineData(InkDispersionQuality.Balanced, 160, 720)]
[InlineData(InkDispersionQuality.High, 224, 1080)]
[InlineData(InkDispersionQuality.Ultra, 288, 1440)]
public void QualitySettingsMatchSpecification(InkDispersionQuality quality, int resolution, int maxSteps)
[InlineData(0)]
[InlineData(1)]
[InlineData(int.MaxValue)]
public void NoExoFilterIsWrittenForAviUtl(int keyFrameIndex)
{
var settings = InkDispersionSettings.GetQuality(quality);
var effect = new InkDispersionEffect();
Assert.Equal(resolution, settings.GridResolution);
Assert.Equal(maxSteps, settings.MaxSteps);
var description = new ExoOutputDescription(new VideoInfo(), string.Empty, new AviUtlDirectories(string.Empty, string.Empty));
Assert.Empty(effect.CreateExoVideoFilters(keyFrameIndex, description));
}
[Fact]
public void TheEffectIsRegisteredForDecorationAndAnimationWithoutAviUtlSupport()
{
var attribute = typeof(InkDispersionEffect).GetCustomAttribute<VideoEffectAttribute>()!;
Assert.Equal(nameof(Texts.InkDispersion), attribute.Name);
Assert.Equal([VideoEffectCategories.Decoration, VideoEffectCategories.Animation], attribute.Categories);
Assert.Equal([nameof(Texts.TagInk), nameof(Texts.TagBlot), nameof(Texts.TagJapanese)], attribute.Keywords);
Assert.False(attribute.IsAviUtlSupported);
Assert.True(attribute.IsEffectItemSupported);
Assert.Equal(typeof(Texts), attribute.ResourceType);
Assert.Equal(Texts.InkDispersion, attribute.GetName());
}
[Theory]
[InlineData(1920, 1080, 224)]
[InlineData(1080, 1920, 224)]
[InlineData(8, 8, 224)]
[InlineData(4096, 16, 160)]
[InlineData(100, 100, 288)]
public void GridSizeCoversCanvas(int width, int height, int resolution)
[InlineData(nameof(InkDispersionEffect.Amount), nameof(Texts.BasicGroup), nameof(Texts.Amount), nameof(Texts.AmountDescription), 0)]
[InlineData(nameof(InkDispersionEffect.Spread), nameof(Texts.BasicGroup), nameof(Texts.Spread), nameof(Texts.SpreadDescription), 1)]
[InlineData(nameof(InkDispersionEffect.Quality), nameof(Texts.BasicGroup), nameof(Texts.Quality), nameof(Texts.QualityDescription), 2)]
[InlineData(nameof(InkDispersionEffect.Water), nameof(Texts.FlowGroup), nameof(Texts.Water), nameof(Texts.WaterDescription), 10)]
[InlineData(nameof(InkDispersionEffect.Reach), nameof(Texts.FlowGroup), nameof(Texts.Reach), nameof(Texts.ReachDescription), 11)]
[InlineData(nameof(InkDispersionEffect.Fiber), nameof(Texts.FlowGroup), nameof(Texts.Fiber), nameof(Texts.FiberDescription), 12)]
[InlineData(nameof(InkDispersionEffect.Sizing), nameof(Texts.FlowGroup), nameof(Texts.Sizing), nameof(Texts.SizingDescription), 13)]
[InlineData(nameof(InkDispersionEffect.Viscosity), nameof(Texts.FlowGroup), nameof(Texts.Viscosity), nameof(Texts.ViscosityDescription), 14)]
[InlineData(nameof(InkDispersionEffect.Drying), nameof(Texts.FlowGroup), nameof(Texts.Drying), nameof(Texts.DryingDescription), 15)]
[InlineData(nameof(InkDispersionEffect.Seed), nameof(Texts.FlowGroup), nameof(Texts.Seed), nameof(Texts.SeedDescription), 16)]
[InlineData(nameof(InkDispersionEffect.Density), nameof(Texts.AppearanceGroup), nameof(Texts.Density), nameof(Texts.DensityDescription), 20)]
[InlineData(nameof(InkDispersionEffect.Grain), nameof(Texts.AppearanceGroup), nameof(Texts.Grain), nameof(Texts.GrainDescription), 21)]
[InlineData(nameof(InkDispersionEffect.InkColor), nameof(Texts.AppearanceGroup), nameof(Texts.InkColor), nameof(Texts.InkColorDescription), 22)]
public void EveryParameterIsDisplayedInItsGroupInOrder(string property, string group, string name, string description, int order)
{
var (gridWidth, gridHeight, cellSize) = InkDispersionSettings.GetGridSize(width, height, resolution);
var display = Attribute<DisplayAttribute>(property);
Assert.True(gridWidth >= InkDispersionSettings.MinimumGridSize);
Assert.True(gridHeight >= InkDispersionSettings.MinimumGridSize);
Assert.True(cellSize > 0f);
Assert.True(gridWidth * cellSize >= width);
Assert.True(gridHeight * cellSize >= height);
Assert.Equal(group, display.GroupName);
Assert.Equal(name, display.Name);
Assert.Equal(description, display.Description);
Assert.Equal(order, display.Order);
Assert.Equal(typeof(Texts), display.ResourceType);
}
[Theory]
[InlineData(0f, 720, 192)]
[InlineData(10f, 720, 228)]
[InlineData(60f, 1080, 728)]
[InlineData(500f, 1080, 1080)]
[InlineData(500f, 720, 720)]
public void StepCountScalesWithReachAndRespectsCap(float reachCells, int maxSteps, int expected)
[InlineData(nameof(InkDispersionEffect.Amount), 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Spread), 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Water), 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Reach), 5d, 100d)]
[InlineData(nameof(InkDispersionEffect.Fiber), 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Sizing), 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Viscosity), 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Drying), 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Density), 0d, 100d)]
[InlineData(nameof(InkDispersionEffect.Grain), 0d, 100d)]
public void AnimatedParametersAreEditedAsPercentagesWithAnimationSliders(string property, double minimum, double maximum)
{
Assert.Equal(expected, InkDispersionSettings.GetStepCount(reachCells, maxSteps));
var slider = Attribute<AnimationSliderAttribute>(property);
Assert.Equal("F1", slider.StringFormat);
Assert.Equal("%", slider.UnitText);
Assert.Equal(minimum, slider.DefaultMin);
Assert.Equal(maximum, slider.DefaultMax);
}
[Fact]
public void ParameterMappingsAreMonotonicAndBounded()
public void TheQualityIsChosenFromACombo()
{
Assert.Equal(InkDispersionSettings.MinimumDeposit, InkDispersionSettings.GetDeposit(0f), 5);
Assert.Equal(InkDispersionSettings.MaximumDeposit, InkDispersionSettings.GetDeposit(1f), 5);
Assert.Equal(InkDispersionSettings.MinimumDeposit, InkDispersionSettings.GetDeposit(-5f), 5);
Assert.Equal(InkDispersionSettings.MaximumDeposit, InkDispersionSettings.GetDeposit(5f), 5);
Assert.True(InkDispersionSettings.GetDeposit(0.75f) > InkDispersionSettings.GetDeposit(0.25f));
Assert.Equal(InkDispersionSettings.MaximumOmega, InkDispersionSettings.GetOmega(0f), 5);
Assert.Equal(InkDispersionSettings.MinimumOmega, InkDispersionSettings.GetOmega(1f), 5);
Assert.True(InkDispersionSettings.GetOmega(0.25f) > InkDispersionSettings.GetOmega(0.75f));
Assert.Equal(InkDispersionSettings.SigmaFloor, InkDispersionSettings.GetPinningSigma(0f), 6);
Assert.Equal(InkDispersionSettings.SigmaFloor + InkDispersionSettings.MaximumSigma, InkDispersionSettings.GetPinningSigma(1f), 6);
Assert.True(InkDispersionSettings.GetPinningSigma(0.75f) > InkDispersionSettings.GetPinningSigma(0.25f));
Assert.Equal(0f, InkDispersionSettings.GetSurfaceEvaporation(0f), 7);
Assert.Equal(InkDispersionSettings.MaximumSurfaceEvaporation, InkDispersionSettings.GetSurfaceEvaporation(1f), 7);
Assert.Equal(0f, InkDispersionSettings.GetSurfaceEvaporation(-1f), 7);
Assert.Equal(InkDispersionSettings.MaximumSurfaceEvaporation, InkDispersionSettings.GetSurfaceEvaporation(2f), 7);
Assert.NotNull(Attribute<EnumComboBoxAttribute>(nameof(InkDispersionEffect.Quality)));
Assert.Equal([InkDispersionQuality.Balanced, InkDispersionQuality.High, InkDispersionQuality.Ultra], Enum.GetValues<InkDispersionQuality>());
}
[Theory]
[InlineData(0, 0)]
[InlineData(1, 3)]
[InlineData(2, 4)]
[InlineData(3, 1)]
[InlineData(4, 2)]
[InlineData(5, 7)]
[InlineData(6, 8)]
[InlineData(7, 5)]
[InlineData(8, 6)]
public void LatticeOppositeDirectionsAreInvolutions(int direction, int expected)
[InlineData(InkDispersionQuality.Balanced, nameof(Texts.QualityBalanced), nameof(Texts.QualityBalancedDescription))]
[InlineData(InkDispersionQuality.High, nameof(Texts.QualityHigh), nameof(Texts.QualityHighDescription))]
[InlineData(InkDispersionQuality.Ultra, nameof(Texts.QualityUltra), nameof(Texts.QualityUltraDescription))]
public void EveryQualityIsDisplayedWithItsLocalizedName(InkDispersionQuality quality, string name, string description)
{
Assert.Equal(expected, InkDispersionShaderMath.Opposite(direction));
Assert.Equal(direction, InkDispersionShaderMath.Opposite(expected));
Assert.Equal(-InkDispersionShaderMath.Ex(direction), InkDispersionShaderMath.Ex(expected));
Assert.Equal(-InkDispersionShaderMath.Ey(direction), InkDispersionShaderMath.Ey(expected));
var display = typeof(InkDispersionQuality).GetField(quality.ToString())!.GetCustomAttribute<DisplayAttribute>()!;
Assert.Equal(name, display.Name);
Assert.Equal(description, display.Description);
Assert.Equal(typeof(Texts), display.ResourceType);
}
[Fact]
public void LatticeWeightsSumToOne()
public void TheSeedIsEditedWithoutAUnitFromZero()
{
var sum = 0f;
for (var i = 0; i < 9; i++)
sum += InkDispersionShaderMath.Weight(i);
var slider = Attribute<TextBoxSliderAttribute>(nameof(InkDispersionEffect.Seed));
var range = Attribute<RangeAttribute>(nameof(InkDispersionEffect.Seed));
Assert.Equal(1f, sum, 6);
Assert.Equal("F0", slider.StringFormat);
Assert.Equal(string.Empty, slider.UnitText);
Assert.Equal(0d, slider.DefaultMin);
Assert.Equal(10000d, slider.DefaultMax);
Assert.Equal(0, range.Minimum);
Assert.Equal(int.MaxValue, range.Maximum);
Assert.Equal(0, Attribute<DefaultValueAttribute>(nameof(InkDispersionEffect.Seed)).Value);
}
[Fact]
public void TransparentInputYieldsTransparentOutput()
public void TheInkColorIsPickedWithAColorPicker()
{
using var pipeline = InkDispersionPipeline.TryCreate();
if (pipeline is null)
{
Assert.Skip("Direct3D 12 is unavailable.");
return;
}
const int width = 64;
const int height = 64;
var source = new int[width * height];
var destination = new int[source.Length];
Array.Fill(destination, -1);
var parameters = CreateParameters();
pipeline.Process(source, destination, width, height, in parameters);
Assert.All(destination, pixel => Assert.Equal(0, pixel));
Assert.NotNull(Attribute<ColorPickerAttribute>(nameof(InkDispersionEffect.InkColor)));
}
[Fact]
public void SpreadZeroYieldsTransparentOutput()
public void EverySettingSurvivesAProjectRoundTrip()
{
using var pipeline = InkDispersionPipeline.TryCreate();
if (pipeline is null)
{
Assert.Skip("Direct3D 12 is unavailable.");
return;
}
const int width = 96;
const int height = 96;
var source = CreateSquareSource(width, height, 32, 32, 32, 32);
var destination = new int[source.Length];
Array.Fill(destination, -1);
var parameters = CreateParameters(spread: 0f);
pipeline.Process(source, destination, width, height, in parameters);
Assert.All(destination, pixel => Assert.Equal(0, pixel));
}
[Fact]
public void FullSpreadProducesInk()
{
using var pipeline = InkDispersionPipeline.TryCreate();
if (pipeline is null)
{
Assert.Skip("Direct3D 12 is unavailable.");
return;
}
const int width = 128;
const int height = 128;
var source = CreateSquareSource(width, height, 48, 48, 32, 32);
var destination = new int[source.Length];
var parameters = CreateParameters();
pipeline.Process(source, destination, width, height, in parameters);
Assert.True(CountLitPixels(destination) > 0);
}
[Fact]
public void GpuPipelineIsDeterministic()
{
using var pipeline = InkDispersionPipeline.TryCreate();
if (pipeline is null)
{
Assert.Skip("Direct3D 12 is unavailable.");
return;
}
const int width = 128;
const int height = 128;
var source = CreateSquareSource(width, height, 48, 48, 32, 32);
var first = new int[source.Length];
var second = new int[source.Length];
var parameters = CreateParameters(fiber: 0.8f, seed: 42);
pipeline.Process(source, first, width, height, in parameters);
pipeline.Process(source, second, width, height, in parameters);
Assert.Equal(first, second);
}
[Fact]
public void DifferentSeedsProduceDifferentInkMarks()
{
using var pipeline = InkDispersionPipeline.TryCreate();
if (pipeline is null)
{
Assert.Skip("Direct3D 12 is unavailable.");
return;
}
const int width = 128;
const int height = 128;
var source = CreateSquareSource(width, height, 48, 48, 32, 32);
var first = new int[source.Length];
var second = new int[source.Length];
var parametersA = CreateParameters(fiber: 0.8f, seed: 1);
var parametersB = CreateParameters(fiber: 0.8f, seed: 2);
pipeline.Process(source, first, width, height, in parametersA);
pipeline.Process(source, second, width, height, in parametersB);
Assert.NotEqual(first, second);
}
[Fact]
public void OutputAlphaStaysPremultipliedAndBounded()
{
using var pipeline = InkDispersionPipeline.TryCreate();
if (pipeline is null)
{
Assert.Skip("Direct3D 12 is unavailable.");
return;
}
const int width = 128;
const int height = 128;
var source = CreateSquareSource(width, height, 48, 48, 32, 32);
var destination = new int[source.Length];
var parameters = CreateParameters(water: 1f, density: 1f, grain: 1f);
pipeline.Process(source, destination, width, height, in parameters);
foreach (var pixel in destination)
{
var alpha = (pixel >> 24) & 255;
Assert.InRange((pixel >> 16) & 255, 0, alpha);
Assert.InRange((pixel >> 8) & 255, 0, alpha);
Assert.InRange(pixel & 255, 0, alpha);
}
}
[Fact]
public void SpreadIncreasesLitArea()
{
using var pipeline = InkDispersionPipeline.TryCreate();
if (pipeline is null)
{
Assert.Skip("Direct3D 12 is unavailable.");
return;
}
const int width = 128;
const int height = 128;
var source = CreateSquareSource(width, height, 48, 48, 32, 32);
var partial = new int[source.Length];
var full = new int[source.Length];
var partialParameters = CreateParameters(spread: 0.1f);
var fullParameters = CreateParameters(spread: 1f);
pipeline.Process(source, partial, width, height, in partialParameters);
pipeline.Process(source, full, width, height, in fullParameters);
Assert.True(CountLitPixels(full) > CountLitPixels(partial));
}
[Fact]
public void ReachLimitsInkExtent()
{
using var pipeline = InkDispersionPipeline.TryCreate();
if (pipeline is null)
{
Assert.Skip("Direct3D 12 is unavailable.");
return;
}
const int width = 192;
const int height = 192;
var source = CreateSquareSource(width, height, 80, 80, 32, 32);
var shortReach = new int[source.Length];
var longReach = new int[source.Length];
var shortParameters = CreateParameters(reachPixels: 12f, water: 1f);
var longParameters = CreateParameters(reachPixels: 48f, water: 1f);
pipeline.Process(source, shortReach, width, height, in shortParameters);
pipeline.Process(source, longReach, width, height, in longParameters);
var shortMaxY = MaxLitY(shortReach, width, height);
var longMaxY = MaxLitY(longReach, width, height);
Assert.True(shortMaxY > 0);
Assert.True(longMaxY >= shortMaxY);
Assert.True(shortMaxY <= 80 + 32 + 12 + 8);
}
[Fact]
public void GpuPipelineDoesNotAllocateManagedMemoryAfterWarmup()
{
using var pipeline = InkDispersionPipeline.TryCreate();
if (pipeline is null)
{
Assert.Skip("Direct3D 12 is unavailable.");
return;
}
const int width = 64;
const int height = 64;
var source = CreateSquareSource(width, height, 24, 24, 16, 16);
var destination = new int[source.Length];
var parameters = CreateParameters();
pipeline.Process(source, destination, width, height, in parameters);
pipeline.Process(source, destination, width, height, in parameters);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
var before = GC.GetAllocatedBytesForCurrentThread();
pipeline.Process(source, destination, width, height, in parameters);
var allocated = GC.GetAllocatedBytesForCurrentThread() - before;
Assert.Equal(0, allocated);
}
[Fact]
public void SharedTexturePipelineMatchesPackedBufferPipeline()
{
using var pipeline = InkDispersionPipeline.TryCreate();
if (pipeline is null)
{
Assert.Skip("Direct3D 12 is unavailable.");
return;
}
const int width = 96;
const int height = 96;
var source = CreateSquareSource(width, height, 32, 32, 32, 32);
var expected = new int[source.Length];
var parameters = CreateParameters(fiber: 0.7f, seed: 11);
pipeline.Process(source, expected, width, height, in parameters);
var device = GraphicsDevice.GetDefault();
using var sourceTexture = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, width, height);
using var outputTexture = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, width, height);
var sourcePixels = new Bgra32[source.Length];
for (var index = 0; index < source.Length; index++)
sourcePixels[index].PackedValue = unchecked((uint)source[index]);
sourceTexture.CopyFrom(sourcePixels);
pipeline.ProcessSharedAndWait(sourceTexture, outputTexture, width, height, in parameters);
var result = new Bgra32[source.Length];
outputTexture.CopyTo(result);
for (var index = 0; index < expected.Length; index++)
Assert.Equal(unchecked((uint)expected[index]), result[index].PackedValue);
}
[Fact]
public void SubmittedSharedTexturePipelineAllocationsAmortizeToZero()
{
using var pipeline = InkDispersionPipeline.TryCreate();
if (pipeline is null)
{
Assert.Skip("Direct3D 12 is unavailable.");
return;
}
const int width = 64;
const int height = 64;
var device = GraphicsDevice.GetDefault();
using var source = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, width, height);
using var destination = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, width, height);
var parameters = CreateParameters();
for (var iteration = 0; iteration < 4; iteration++)
pipeline.Process(source, destination, width, height, in parameters);
pipeline.WaitForCompletion();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
var minimum = long.MaxValue;
for (var iteration = 0; iteration < 16; iteration++)
{
var before = GC.GetAllocatedBytesForCurrentThread();
pipeline.Process(source, destination, width, height, in parameters);
minimum = Math.Min(minimum, GC.GetAllocatedBytesForCurrentThread() - before);
}
pipeline.WaitForCompletion();
Assert.Equal(0, minimum);
}
[Theory]
[InlineData(0.3f)]
[InlineData(1f)]
public void VisibleBoundsCoverAllLitPixelsAndMatchFullRender(float spread)
{
using var pipeline = InkDispersionPipeline.TryCreate();
if (pipeline is null)
{
Assert.Skip("Direct3D 12 is unavailable.");
return;
}
const int width = 192;
const int height = 192;
var source = CreateSquareSource(width, height, 80, 80, 32, 24);
var full = new int[source.Length];
var parameters = CreateParameters(spread: spread, reachPixels: 32f, seed: 5);
pipeline.Process(source, full, width, height, in parameters);
var device = GraphicsDevice.GetDefault();
using var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(width, height);
var sourcePixels = new Bgra32[source.Length];
for (var index = 0; index < source.Length; index++)
sourcePixels[index].PackedValue = unchecked((uint)source[index]);
sourceTexture.CopyFrom(sourcePixels);
pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in parameters);
Assert.True(pipeline.TryGetVisibleBounds(width, height, in parameters, out var rect));
Assert.True(rect.Width > 0 && rect.Height > 0);
Assert.True(rect.X >= 0 && rect.Y >= 0);
Assert.True(rect.X + rect.Width <= width && rect.Y + rect.Height <= height);
for (var y = 0; y < height; y++)
{
for (var x = 0; x < width; x++)
{
if (full[y * width + x] == 0)
continue;
Assert.InRange(x, rect.X, rect.X + rect.Width - 1);
Assert.InRange(y, rect.Y, rect.Y + rect.Height - 1);
}
}
using var outputTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(rect.Width, rect.Height);
pipeline.RenderVisible(outputTexture, width, height, rect, in parameters);
var result = new Bgra32[rect.Width * rect.Height];
outputTexture.CopyTo(result);
for (var y = 0; y < rect.Height; y++)
{
for (var x = 0; x < rect.Width; x++)
{
var expected = unchecked((uint)full[(rect.Y + y) * width + rect.X + x]);
Assert.Equal(expected, result[y * rect.Width + x].PackedValue);
}
}
}
[Fact]
public void SimulateCachesStructureUntilInputsChange()
{
using var pipeline = InkDispersionPipeline.TryCreate();
if (pipeline is null)
{
Assert.Skip("Direct3D 12 is unavailable.");
return;
}
const int width = 128;
const int height = 128;
var source = CreateSquareSource(width, height, 48, 48, 32, 32);
var device = GraphicsDevice.GetDefault();
using var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(width, height);
var sourcePixels = new Bgra32[source.Length];
for (var index = 0; index < source.Length; index++)
sourcePixels[index].PackedValue = unchecked((uint)source[index]);
sourceTexture.CopyFrom(sourcePixels);
var parameters = CreateParameters(seed: 3);
Assert.True(pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in parameters));
Assert.False(pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in parameters));
var spreadChanged = parameters with { Spread = 0.5f };
Assert.False(pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in spreadChanged));
var densityChanged = parameters with { Density = 0.5f };
Assert.False(pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in densityChanged));
var seedChanged = parameters with { Seed = 4 };
Assert.True(pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in seedChanged));
var movedSource = CreateSquareSource(width, height, 32, 32, 32, 32);
for (var index = 0; index < movedSource.Length; index++)
sourcePixels[index].PackedValue = unchecked((uint)movedSource[index]);
sourceTexture.CopyFrom(sourcePixels);
Assert.True(pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in seedChanged));
}
[Fact]
public void Direct2DInteropProducesInkAfterGrowingFullHdOutput()
{
using var devices = new GraphicsDevices();
using var graphicsContext = devices.CreateContext();
using var scheduler = ComputeExternalQueueScheduler.Create();
using var provider = InkDispersionInteropProvider.TryCreate(graphicsContext, scheduler, out var interopDevice);
if (provider is null || interopDevice is null)
{
Assert.Skip("Direct3D 11 and Direct3D 12 sharing is unavailable.");
return;
}
using var domain = interopDevice.RegisterExternalDomain(provider);
using var resourceSet = InkDispersionResourceSet.Create(interopDevice, domain);
using var pipeline = InkDispersionPipeline.TryCreate(interopDevice);
Assert.NotNull(pipeline);
const int width = 96;
const int height = 96;
const int fullHdWidth = 1920;
const int fullHdHeight = 1080;
using var inputBitmap = CreateInputBitmap(graphicsContext.DeviceContext, CreateSquareSource(width, height, 32, 32, 32, 32), width, height);
Assert.True(resourceSet.TryEnsureSource(width, height, out _));
var parameters = CreateParameters();
InkDispersionPipeline.PixelRect visible = default;
for (var iteration = 0; iteration < 2; iteration++)
{
DrawSource(resourceSet, provider.RenderContext, inputBitmap);
pipeline!.Simulate(
resourceSet.GetSourceComputeBinding(), width, height, 0, 0, width, height, in parameters);
Assert.True(pipeline.TryGetVisibleBounds(width, height, in parameters, out visible));
Assert.True(resourceSet.TryEnsureOutput(
iteration == 0 ? visible.Width : fullHdWidth,
iteration == 0 ? visible.Height : fullHdHeight,
out _));
pipeline.RenderVisible(
resourceSet.GetOutputComputeBinding(), width, height, visible, in parameters);
if (iteration == 0)
{
using var retiredLease = resourceSet.AcquireOutputExternalViewLease();
Assert.Equal(visible.Width, retiredLease.Width);
Assert.Equal(visible.Height, retiredLease.Height);
}
}
using var outputLease = resourceSet.AcquireOutputExternalViewLease();
Assert.Equal(fullHdWidth, outputLease.Width);
Assert.Equal(fullHdHeight, outputLease.Height);
Assert.True(CountLitOutput(graphicsContext.DeviceContext, outputLease, visible) > 0);
}
[Fact]
public void Direct2DInteropProducesInkAfterReplacingSource()
{
using var devices = new GraphicsDevices();
using var graphicsContext = devices.CreateContext();
using var scheduler = ComputeExternalQueueScheduler.Create();
using var provider = InkDispersionInteropProvider.TryCreate(graphicsContext, scheduler, out var interopDevice);
if (provider is null || interopDevice is null)
{
Assert.Skip("Direct3D 11 and Direct3D 12 sharing is unavailable.");
return;
}
using var domain = interopDevice.RegisterExternalDomain(provider);
using var resourceSet = InkDispersionResourceSet.Create(interopDevice, domain);
using var pipeline = InkDispersionPipeline.TryCreate(interopDevice);
Assert.NotNull(pipeline);
var parameters = CreateParameters();
var previousVisible = default(InkDispersionPipeline.PixelRect);
foreach (var (size, square) in new[] { (96, 32), (128, 64) })
{
using var inputBitmap = CreateInputBitmap(graphicsContext.DeviceContext, CreateSquareSource(size, size, (size - square) / 2, (size - square) / 2, square, square), size, size);
Assert.True(resourceSet.TryEnsureSource(size, size, out var sourceChanged));
Assert.True(sourceChanged);
DrawSource(resourceSet, provider.RenderContext, inputBitmap);
Assert.True(pipeline!.Simulate(
resourceSet.GetSourceComputeBinding(), size, size, 0, 0, size, size, in parameters));
Assert.True(pipeline.TryGetVisibleBounds(size, size, in parameters, out var visible));
Assert.True(visible.Width > previousVisible.Width && visible.Height > previousVisible.Height);
Assert.True(resourceSet.TryEnsureOutput(visible.Width, visible.Height, out _));
pipeline.RenderVisible(
resourceSet.GetOutputComputeBinding(), size, size, visible, in parameters);
using var outputLease = resourceSet.AcquireOutputExternalViewLease();
Assert.Equal(visible.Width, outputLease.Width);
Assert.Equal(visible.Height, outputLease.Height);
Assert.True(CountLitOutput(graphicsContext.DeviceContext, outputLease, visible) > square * square);
previousVisible = visible;
}
}
private static ID2D1Bitmap1 CreateInputBitmap(ID2D1DeviceContext6 deviceContext, int[] pixels, int width, int height)
{
var handle = GCHandle.Alloc(pixels, GCHandleType.Pinned);
var inputBitmap = deviceContext.CreateBitmap(
new SizeI(width, height),
new BitmapProperties1(
new PixelFormat(Format.B8G8R8A8_UNorm, Vortice.DCommon.AlphaMode.Premultiplied),
96f,
96f,
BitmapOptions.None));
try
{
inputBitmap.CopyFromMemory(handle.AddrOfPinnedObject(), width * sizeof(int));
}
finally
{
handle.Free();
}
return inputBitmap;
}
private static void DrawSource(InkDispersionResourceSet resourceSet, ID2D1DeviceContext6 renderContext, ID2D1Bitmap1 inputBitmap)
{
using var borrow = resourceSet.BeginSourceExternalOperation();
var previousTarget = renderContext.Target;
using var sourceBitmap = new ID2D1Bitmap1(borrow.DangerousGetView().AddRefBitmap());
renderContext.Target = sourceBitmap;
renderContext.BeginDraw();
renderContext.Clear(null);
renderContext.DrawImage(
inputBitmap,
new System.Numerics.Vector2(0f, 0f),
null,
InterpolationMode.NearestNeighbor,
CompositeMode.SourceCopy);
renderContext.EndDraw();
renderContext.Target = previousTarget;
}
private static int CountLitOutput(ID2D1DeviceContext6 deviceContext, ExternalTextureLease<ExternalDirect3D11TextureView> outputLease, InkDispersionPipeline.PixelRect visible)
{
using var staging = deviceContext.CreateBitmap(
new SizeI(visible.Width, visible.Height),
new BitmapProperties1(
new PixelFormat(Format.B8G8R8A8_UNorm, Vortice.DCommon.AlphaMode.Premultiplied),
96f,
96f,
BitmapOptions.CpuRead | BitmapOptions.CannotDraw));
using var outputBitmap = new ID2D1Bitmap1(outputLease.DangerousGetView().AddRefBitmap());
staging.CopyFromBitmap(Vortice.Mathematics.Int2.Zero, outputBitmap, new RectI(0, 0, visible.Width, visible.Height));
var mapped = staging.Map(MapOptions.Read);
try
{
var lit = 0;
for (var y = 0; y < visible.Height; y++)
{
for (var x = 0; x < visible.Width; x++)
{
var actual = Marshal.ReadInt32(mapped.Bits + (nint)(y * mapped.Pitch + x * sizeof(int)));
var alpha = (actual >> 24) & 255;
Assert.InRange((actual >> 16) & 255, 0, alpha);
Assert.InRange((actual >> 8) & 255, 0, alpha);
Assert.InRange(actual & 255, 0, alpha);
if (alpha > 0)
lit++;
}
}
return lit;
}
finally
{
staging.Unmap();
}
}
private static int[] CreateSquareSource(int width, int height, int left, int top, int squareWidth, int squareHeight)
{
var source = new int[width * height];
for (var y = top; y < top + squareHeight; y++)
{
for (var x = left; x < left + squareWidth; x++)
{
if (x < 0 || x >= width || y < 0 || y >= height)
continue;
source[y * width + x] = unchecked((int)0xFFC0C0C0);
}
}
return source;
}
private static int CountLitPixels(int[] pixels)
{
var count = 0;
foreach (var pixel in pixels)
{
if (((pixel >> 24) & 255) > 8)
count++;
}
return count;
}
private static int MaxLitY(int[] pixels, int width, int height)
{
for (var y = height - 1; y >= 0; y--)
{
for (var x = 0; x < width; x++)
{
if (((pixels[y * width + x] >> 24) & 255) >= 32)
return y;
}
}
return 0;
var effect = new InkDispersionEffect { Quality = InkDispersionQuality.Ultra, Seed = 42, InkColor = Colors.Crimson };
var values = new[] { 55d, 45d, 70d, 120d, 20d, 65d, 15d, 85d, 35d, 90d };
foreach (var (animation, value) in Animations(effect).Zip(values))
animation.Values[0].Value = value;
var clone = Json.GetClone(effect)!;
Assert.NotSame(effect, clone);
Assert.Equal(InkDispersionQuality.Ultra, clone.Quality);
Assert.Equal(42, clone.Seed);
Assert.Equal(Colors.Crimson, clone.InkColor);
Assert.Equal(values, Animations(clone).Select(animation => animation.GetValue(0, 1, EffectDescriptions.Fps)));
}
}
+165
ファイルの表示
@@ -0,0 +1,165 @@
using System.Numerics;
using ComputeWeave;
using Vortice.Direct2D1;
using YukkuriMovieMaker.Commons;
namespace InkDispersion.Tests;
[Collection("Direct2D")]
public sealed class InkDispersionInteropTests
{
static readonly Bgra Gray = Bgra.Opaque(192, 192, 192);
static InkDispersionPipeline.Parameters Parameters()
=> new(InkDispersionQuality.Balanced, 1f, 0.6f, 0.5f, 0.3f, 0.3f, 0.4f, 40f, 0.8f, 0.4f, 0.12f, 0.1f, 0.09f, 0);
static Func<int, int, Bgra> CenteredSquare(int size, int square)
{
var start = (size - square) / 2;
return (x, y) => x >= start && x < start + square && y >= start && y < start + square ? Gray : Bgra.Transparent;
}
sealed class Interop : IDisposable
{
readonly ComputeExternalQueueScheduler scheduler;
readonly InkDispersionInteropProvider provider;
readonly ComputeInteropDomain domain;
public InkDispersionResourceSet Resources { get; }
public InkDispersionPipeline Pipeline { get; }
Interop(ComputeExternalQueueScheduler scheduler, InkDispersionInteropProvider provider, GraphicsDevice device)
{
this.scheduler = scheduler;
this.provider = provider;
domain = device.RegisterExternalDomain(provider);
Resources = InkDispersionResourceSet.Create(device, domain);
Pipeline = InkDispersionPipeline.TryCreate(device)!;
}
public static Interop Create(IGraphicsDevicesAndContext devices)
{
var scheduler = ComputeExternalQueueScheduler.Create();
var provider = InkDispersionInteropProvider.TryCreate(devices, scheduler, out var device);
if (provider is null || device is null)
{
scheduler.Dispose();
Assert.Skip("Direct3D 11 and Direct3D 12 sharing is unavailable.");
}
return new Interop(scheduler, provider, device);
}
public void Draw(ID2D1Image image)
{
var context = provider.RenderContext;
using var borrow = Resources.BeginSourceExternalOperation();
var previousTarget = context.Target;
using var target = new ID2D1Bitmap1(borrow.DangerousGetView().AddRefBitmap());
context.Target = target;
context.BeginDraw();
context.Clear(null);
context.DrawImage(image, Vector2.Zero, null, InterpolationMode.NearestNeighbor, CompositeMode.SourceCopy);
context.EndDraw();
context.Target = previousTarget;
}
public Rendering CaptureOutput(IGraphicsDevicesAndContext devices, out int width, out int height)
{
using var lease = Resources.AcquireOutputExternalViewLease();
width = lease.Width;
height = lease.Height;
using var bitmap = new ID2D1Bitmap1(lease.DangerousGetView().AddRefBitmap());
return Rendering.Capture(devices, bitmap);
}
public void Dispose()
{
Pipeline.Dispose();
Resources.Dispose();
Resources.WaitForDisposal();
domain.Dispose();
domain.WaitForDisposal();
provider.Dispose();
scheduler.Dispose();
}
}
static int LitPixels(Rendering rendering, InkDispersionPipeline.PixelRect visible)
{
var lit = 0;
for (var y = 0; y < visible.Height; y++)
{
for (var x = 0; x < visible.Width; x++)
{
var pixel = rendering[x, y];
Assert.InRange(pixel.Blue, 0, pixel.Alpha);
Assert.InRange(pixel.Green, 0, pixel.Alpha);
Assert.InRange(pixel.Red, 0, pixel.Alpha);
if (pixel.Alpha > 0)
lit++;
}
}
return lit;
}
[Fact]
public void InkIsDrawnAfterTheOutputGrowsToFullHd()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
using var interop = Interop.Create(context);
using var source = new SourceImage(context, 96, 96, CenteredSquare(96, 32));
var parameters = Parameters();
Assert.True(interop.Resources.TryEnsureSource(96, 96, out _));
InkDispersionPipeline.PixelRect RenderInto(Func<InkDispersionPipeline.PixelRect, (int Width, int Height)> outputSize)
{
interop.Draw(source.Bitmap);
interop.Pipeline.Simulate(interop.Resources.GetSourceComputeBinding(), 96, 96, 0, 0, 96, 96, in parameters);
Assert.True(interop.Pipeline.TryGetVisibleBounds(96, 96, in parameters, out var visible));
var (width, height) = outputSize(visible);
Assert.True(interop.Resources.TryEnsureOutput(width, height, out _));
interop.Pipeline.RenderVisible(interop.Resources.GetOutputComputeBinding(), 96, 96, visible, in parameters);
return visible;
}
var first = RenderInto(visible => (visible.Width, visible.Height));
interop.CaptureOutput(context, out var firstWidth, out var firstHeight);
var second = RenderInto(_ => (1920, 1080));
var output = interop.CaptureOutput(context, out var secondWidth, out var secondHeight);
Assert.Equal((first.Width, first.Height), (firstWidth, firstHeight));
Assert.Equal((1920, 1080), (secondWidth, secondHeight));
Assert.True(LitPixels(output, second) > 0);
}
[Fact]
public void InkIsDrawnAfterTheSourceIsReplacedByALargerOne()
{
using var devices = new GraphicsDevices();
using var context = devices.CreateContext();
using var interop = Interop.Create(context);
var parameters = Parameters();
var previous = default(InkDispersionPipeline.PixelRect);
foreach (var (size, square) in new[] { (96, 32), (128, 64) })
{
using var source = new SourceImage(context, size, size, CenteredSquare(size, square));
Assert.True(interop.Resources.TryEnsureSource(size, size, out var sourceChanged));
interop.Draw(source.Bitmap);
Assert.True(interop.Pipeline.Simulate(interop.Resources.GetSourceComputeBinding(), size, size, 0, 0, size, size, in parameters));
Assert.True(interop.Pipeline.TryGetVisibleBounds(size, size, in parameters, out var visible));
Assert.True(interop.Resources.TryEnsureOutput(visible.Width, visible.Height, out _));
interop.Pipeline.RenderVisible(interop.Resources.GetOutputComputeBinding(), size, size, visible, in parameters);
var output = interop.CaptureOutput(context, out var width, out var height);
Assert.True(sourceChanged);
Assert.True(visible.Width > previous.Width && visible.Height > previous.Height);
Assert.Equal((visible.Width, visible.Height), (width, height));
Assert.True(LitPixels(output, visible) > square * square);
previous = visible;
}
}
}
+425
ファイルの表示
@@ -0,0 +1,425 @@
using ComputeWeave;
using ComputeWeave.Interop;
namespace InkDispersion.Tests;
[Collection("Direct3D12")]
public sealed class InkDispersionPipelineTests
{
const int Opaque = unchecked((int)0xFFC0C0C0);
static readonly bool Direct3D12IsAvailable = GraphicsDevice.EnumerateDevices().Any();
static InkDispersionPipeline CreatePipeline()
{
if (!Direct3D12IsAvailable)
Assert.Skip("Direct3D 12 is unavailable.");
var pipeline = InkDispersionPipeline.TryCreate();
Assert.NotNull(pipeline);
return pipeline;
}
static InkDispersionPipeline.Parameters Parameters(
InkDispersionQuality quality = InkDispersionQuality.Balanced,
float spread = 1f,
float water = 0.6f,
float fiber = 0.5f,
float sizing = 0.3f,
float viscosity = 0.3f,
float drying = 0.4f,
float reachPixels = 40f,
float density = 0.8f,
float grain = 0.4f,
int seed = 0)
=> new(quality, spread, water, fiber, sizing, viscosity, drying, reachPixels, density, grain, 0.12f, 0.1f, 0.09f, seed);
static int[] Square(int width, int height, int left, int top, int squareWidth, int squareHeight)
{
var pixels = new int[width * height];
for (var y = Math.Max(top, 0); y < Math.Min(top + squareHeight, height); y++)
{
for (var x = Math.Max(left, 0); x < Math.Min(left + squareWidth, width); x++)
pixels[y * width + x] = Opaque;
}
return pixels;
}
static int Alpha(int pixel) => (pixel >> 24) & 255;
static int LitPixels(int[] pixels) => pixels.Count(pixel => Alpha(pixel) > 8);
static (int Left, int Top, int Right, int Bottom) InkBounds(int[] pixels, int width)
{
var (left, top, right, bottom) = (int.MaxValue, int.MaxValue, int.MinValue, int.MinValue);
for (var index = 0; index < pixels.Length; index++)
{
if (Alpha(pixels[index]) == 0)
continue;
left = Math.Min(left, index % width);
top = Math.Min(top, index / width);
right = Math.Max(right, index % width + 1);
bottom = Math.Max(bottom, index / width + 1);
}
return (left, top, right, bottom);
}
static int LowestLitRow(int[] pixels, int width)
{
for (var index = pixels.Length - 1; index >= 0; index--)
{
if (Alpha(pixels[index]) >= 32)
return index / width;
}
return 0;
}
static void Upload(ReadWriteTexture2D<Bgra32, Float4> texture, int[] pixels)
=> texture.CopyFrom(pixels.Select(pixel => new Bgra32 { PackedValue = unchecked((uint)pixel) }).ToArray());
static int[] Render(InkDispersionPipeline pipeline, int[] source, int width, int height, InkDispersionPipeline.Parameters parameters)
{
var destination = new int[source.Length];
pipeline.Process(source, destination, width, height, in parameters);
return destination;
}
[Fact]
public void ATransparentSourceProducesNoInk()
{
using var pipeline = CreatePipeline();
var destination = Enumerable.Repeat(-1, 64 * 64).ToArray();
var parameters = Parameters();
pipeline.Process(new int[64 * 64], destination, 64, 64, in parameters);
Assert.All(destination, pixel => Assert.Equal(0, pixel));
}
[Fact]
public void AZeroSpreadProducesNoInk()
{
using var pipeline = CreatePipeline();
var source = Square(96, 96, 32, 32, 32, 32);
var destination = Enumerable.Repeat(-1, source.Length).ToArray();
var parameters = Parameters(spread: 0f);
pipeline.Process(source, destination, 96, 96, in parameters);
Assert.All(destination, pixel => Assert.Equal(0, pixel));
}
[Fact]
public void AFullSpreadProducesInk()
{
using var pipeline = CreatePipeline();
var rendering = Render(pipeline, Square(128, 128, 48, 48, 32, 32), 128, 128, Parameters());
Assert.True(LitPixels(rendering) > 0);
}
[Fact]
public void TheSameSettingsAlwaysProduceTheSameInk()
{
using var pipeline = CreatePipeline();
var source = Square(128, 128, 48, 48, 32, 32);
var first = Render(pipeline, source, 128, 128, Parameters(fiber: 0.8f, seed: 42));
var second = Render(pipeline, source, 128, 128, Parameters(fiber: 0.8f, seed: 42));
Assert.Equal(first, second);
}
[Fact]
public void ADifferentSeedSpreadsTheInkDifferently()
{
using var pipeline = CreatePipeline();
var source = Square(128, 128, 48, 48, 32, 32);
var first = Render(pipeline, source, 128, 128, Parameters(fiber: 0.8f, seed: 1));
var second = Render(pipeline, source, 128, 128, Parameters(fiber: 0.8f, seed: 2));
Assert.NotEqual(first, second);
}
[Fact]
public void TheInkStaysPremultiplied()
{
using var pipeline = CreatePipeline();
var rendering = Render(pipeline, Square(128, 128, 48, 48, 32, 32), 128, 128, Parameters(water: 1f, density: 1f, grain: 1f));
Assert.All(rendering, pixel =>
{
Assert.InRange((pixel >> 16) & 255, 0, Alpha(pixel));
Assert.InRange((pixel >> 8) & 255, 0, Alpha(pixel));
Assert.InRange(pixel & 255, 0, Alpha(pixel));
});
}
[Fact]
public void AWiderSpreadCoversMorePixels()
{
using var pipeline = CreatePipeline();
var source = Square(128, 128, 48, 48, 32, 32);
var partial = Render(pipeline, source, 128, 128, Parameters(spread: 0.1f));
var full = Render(pipeline, source, 128, 128, Parameters(spread: 1f));
Assert.True(LitPixels(full) > LitPixels(partial));
}
[Fact]
public void TheReachLimitsHowFarTheInkTravels()
{
using var pipeline = CreatePipeline();
var source = Square(192, 192, 80, 80, 32, 32);
var shortReach = LowestLitRow(Render(pipeline, source, 192, 192, Parameters(reachPixels: 12f, water: 1f)), 192);
var longReach = LowestLitRow(Render(pipeline, source, 192, 192, Parameters(reachPixels: 48f, water: 1f)), 192);
Assert.True(shortReach > 0);
Assert.True(longReach >= shortReach);
Assert.True(shortReach <= 80 + 32 + 12 + 8);
}
[Fact]
public void APipelineWhoseGridWasReclaimedDrawsLikeAFreshOne()
{
using var pipeline = CreatePipeline();
using var fresh = CreatePipeline();
var source = Square(64, 64, 16, 16, 32, 32);
var parameters = Parameters();
Render(pipeline, source, 64, 64, parameters);
GraphicsDevice.GetDefault().TrimMemory();
var reused = Render(pipeline, source, 64, 64, parameters);
var expected = Render(fresh, source, 64, 64, parameters);
Assert.Equal(expected, reused);
}
[Fact]
public void AReclaimedGridIsSimulatedAgain()
{
using var pipeline = CreatePipeline();
var parameters = Parameters();
var device = GraphicsDevice.GetDefault();
using var texture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(64, 64);
Upload(texture, Square(64, 64, 16, 16, 32, 32));
var first = pipeline.Simulate(texture, 64, 64, 0, 0, 64, 64, in parameters);
var repeated = pipeline.Simulate(texture, 64, 64, 0, 0, 64, 64, in parameters);
device.TrimMemory();
var reclaimed = pipeline.Simulate(texture, 64, 64, 0, 0, 64, 64, in parameters);
Assert.True(first);
Assert.False(repeated);
Assert.True(reclaimed);
}
[Fact]
public void AWarmPipelineAllocatesNoManagedMemory()
{
using var pipeline = CreatePipeline();
var source = Square(64, 64, 24, 24, 16, 16);
var destination = new int[source.Length];
var parameters = Parameters();
for (var iteration = 0; iteration < 4; iteration++)
pipeline.Process(source, destination, 64, 64, in parameters);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
var minimum = long.MaxValue;
for (var iteration = 0; iteration < 16; iteration++)
{
var before = GC.GetAllocatedBytesForCurrentThread();
pipeline.Process(source, destination, 64, 64, in parameters);
minimum = Math.Min(minimum, GC.GetAllocatedBytesForCurrentThread() - before);
}
Assert.Equal(0, minimum);
}
[Fact]
public void SharedTexturesProduceTheSameInkAsPackedBuffers()
{
using var pipeline = CreatePipeline();
var source = Square(96, 96, 32, 32, 32, 32);
var parameters = Parameters(fiber: 0.7f, seed: 11);
var expected = Render(pipeline, source, 96, 96, parameters);
var device = GraphicsDevice.GetDefault();
using var sourceTexture = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, 96, 96);
using var outputTexture = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, 96, 96);
Upload(sourceTexture, source);
pipeline.ProcessSharedAndWait(sourceTexture, outputTexture, 96, 96, in parameters);
var result = new Bgra32[source.Length];
outputTexture.CopyTo(result);
Assert.Equal(expected.Select(pixel => unchecked((uint)pixel)), result.Select(pixel => pixel.PackedValue));
}
[Fact]
public void RepeatedSharedTextureSubmissionsAllocateNoManagedMemory()
{
using var pipeline = CreatePipeline();
var device = GraphicsDevice.GetDefault();
using var source = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, 64, 64);
using var destination = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, 64, 64);
var parameters = Parameters();
for (var iteration = 0; iteration < 4; iteration++)
pipeline.Process(source, destination, 64, 64, in parameters);
pipeline.WaitForCompletion();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
var minimum = long.MaxValue;
for (var iteration = 0; iteration < 16; iteration++)
{
var before = GC.GetAllocatedBytesForCurrentThread();
pipeline.Process(source, destination, 64, 64, in parameters);
minimum = Math.Min(minimum, GC.GetAllocatedBytesForCurrentThread() - before);
}
pipeline.WaitForCompletion();
Assert.Equal(0, minimum);
}
[Theory]
[InlineData(0.3f, 0.6f, 32f)]
[InlineData(1f, 0.6f, 32f)]
[InlineData(1f, 1f, 12f)]
public void TheVisibleBoundsHoldEveryInkedPixelAndRenderTheSameInk(float spread, float water, float reachPixels)
{
using var pipeline = CreatePipeline();
var source = Square(192, 192, 80, 80, 32, 24);
var parameters = Parameters(spread: spread, water: water, reachPixels: reachPixels, seed: 5);
var full = Render(pipeline, source, 192, 192, parameters);
var device = GraphicsDevice.GetDefault();
using var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(192, 192);
Upload(sourceTexture, source);
pipeline.Simulate(sourceTexture, 192, 192, 0, 0, 192, 192, in parameters);
Assert.True(pipeline.TryGetVisibleBounds(192, 192, in parameters, out var rect));
using var outputTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(rect.Width, rect.Height);
pipeline.RenderVisible(outputTexture, 192, 192, rect, in parameters);
var visible = new Bgra32[rect.Width * rect.Height];
outputTexture.CopyTo(visible);
Assert.True(rect is { Width: > 0, Height: > 0, X: >= 0, Y: >= 0 });
Assert.True(rect.X + rect.Width <= 192 && rect.Y + rect.Height <= 192);
for (var y = 0; y < 192; y++)
{
for (var x = 0; x < 192; x++)
{
var inside = x >= rect.X && x < rect.X + rect.Width && y >= rect.Y && y < rect.Y + rect.Height;
if (!inside)
Assert.Equal(0, full[y * 192 + x]);
else
Assert.Equal(unchecked((uint)full[y * 192 + x]), visible[(y - rect.Y) * rect.Width + x - rect.X].PackedValue);
}
}
}
[Fact]
public void TheVisibleBoundsHugTheInkOnAFourPixelGrid()
{
using var pipeline = CreatePipeline();
var source = Square(480, 480, 192, 192, 96, 96);
var parameters = Parameters(reachPixels: 48f, seed: 5);
var ink = InkBounds(Render(pipeline, source, 480, 480, parameters), 480);
var device = GraphicsDevice.GetDefault();
using var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(480, 480);
Upload(sourceTexture, source);
pipeline.Simulate(sourceTexture, 480, 480, 0, 0, 480, 480, in parameters);
Assert.True(pipeline.TryGetVisibleBounds(480, 480, in parameters, out var rect));
Assert.Equal((0, 0), (rect.X % 4, rect.Y % 4));
Assert.InRange(ink.Left - rect.X, 0, 24);
Assert.InRange(ink.Top - rect.Y, 0, 24);
Assert.InRange(rect.X + rect.Width - ink.Right, 0, 24);
Assert.InRange(rect.Y + rect.Height - ink.Bottom, 0, 24);
}
[Fact]
public void ASmallerSpreadNarrowsTheVisibleBounds()
{
using var pipeline = CreatePipeline();
var device = GraphicsDevice.GetDefault();
using var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(192, 192);
Upload(sourceTexture, Square(192, 192, 80, 80, 32, 32));
var full = Parameters(reachPixels: 48f, seed: 5);
var partial = full with { Spread = 0.3f };
pipeline.Simulate(sourceTexture, 192, 192, 0, 0, 192, 192, in full);
Assert.True(pipeline.TryGetVisibleBounds(192, 192, in full, out var wide));
Assert.True(pipeline.TryGetVisibleBounds(192, 192, in partial, out var narrow));
Assert.True(narrow.X >= wide.X && narrow.Y >= wide.Y);
Assert.True(narrow.X + narrow.Width <= wide.X + wide.Width && narrow.Y + narrow.Height <= wide.Y + wide.Height);
Assert.True(narrow.Width * narrow.Height < wide.Width * wide.Height);
}
[Theory]
[InlineData(false, 1f)]
[InlineData(true, 0f)]
public void NothingIsVisibleWithoutInkOrSpread(bool shaped, float spread)
{
using var pipeline = CreatePipeline();
var device = GraphicsDevice.GetDefault();
using var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(128, 128);
Upload(sourceTexture, shaped ? Square(128, 128, 48, 48, 32, 32) : new int[128 * 128]);
var parameters = Parameters(spread: spread);
pipeline.Simulate(sourceTexture, 128, 128, 0, 0, 128, 128, in parameters);
Assert.False(pipeline.TryGetVisibleBounds(128, 128, in parameters, out _));
}
[Fact]
public void APipelineUsedAtAnotherSizeDrawsLikeAFreshOne()
{
using var pipeline = CreatePipeline();
using var fresh = CreatePipeline();
var parameters = Parameters(seed: 7);
Render(pipeline, Square(128, 64, 48, 16, 32, 32), 128, 64, parameters);
var source = Square(64, 64, 16, 16, 32, 32);
var reused = Render(pipeline, source, 64, 64, parameters);
var expected = Render(fresh, source, 64, 64, parameters);
Assert.Equal(expected, reused);
}
[Fact]
public void TheFlowIsSimulatedAgainOnlyWhenTheShapeOrTheFlowSettingsChange()
{
using var pipeline = CreatePipeline();
var device = GraphicsDevice.GetDefault();
using var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(128, 128);
Upload(sourceTexture, Square(128, 128, 48, 48, 32, 32));
var parameters = Parameters(seed: 3);
Assert.True(pipeline.Simulate(sourceTexture, 128, 128, 0, 0, 128, 128, in parameters));
Assert.False(pipeline.Simulate(sourceTexture, 128, 128, 0, 0, 128, 128, in parameters));
var spreadChanged = parameters with { Spread = 0.5f };
Assert.False(pipeline.Simulate(sourceTexture, 128, 128, 0, 0, 128, 128, in spreadChanged));
var densityChanged = parameters with { Density = 0.5f };
Assert.False(pipeline.Simulate(sourceTexture, 128, 128, 0, 0, 128, 128, in densityChanged));
var seedChanged = parameters with { Seed = 4 };
Assert.True(pipeline.Simulate(sourceTexture, 128, 128, 0, 0, 128, 128, in seedChanged));
Upload(sourceTexture, Square(128, 128, 32, 32, 32, 32));
Assert.True(pipeline.Simulate(sourceTexture, 128, 128, 0, 0, 128, 128, in seedChanged));
}
}
+95
ファイルの表示
@@ -0,0 +1,95 @@
namespace InkDispersion.Tests;
public sealed class InkDispersionSettingsTests
{
[Theory]
[InlineData(InkDispersionQuality.Balanced, 160, 720)]
[InlineData(InkDispersionQuality.High, 224, 1080)]
[InlineData(InkDispersionQuality.Ultra, 288, 1440)]
public void EveryQualityChoosesItsGridResolutionAndStepLimit(InkDispersionQuality quality, int resolution, int maxSteps)
{
var settings = InkDispersionSettings.GetQuality(quality);
Assert.Equal(resolution, settings.GridResolution);
Assert.Equal(maxSteps, settings.MaxSteps);
}
[Theory]
[InlineData(1920, 1080, 224)]
[InlineData(1080, 1920, 224)]
[InlineData(8, 8, 224)]
[InlineData(4096, 16, 160)]
[InlineData(100, 100, 288)]
public void TheGridCoversTheWholeCanvas(int width, int height, int resolution)
{
var (gridWidth, gridHeight, cellSize) = InkDispersionSettings.GetGridSize(width, height, resolution);
Assert.True(gridWidth >= InkDispersionSettings.MinimumGridSize);
Assert.True(gridHeight >= InkDispersionSettings.MinimumGridSize);
Assert.True(cellSize > 0f);
Assert.True(gridWidth * cellSize >= width);
Assert.True(gridHeight * cellSize >= height);
}
[Theory]
[InlineData(1920, 1080, 224, 224)]
[InlineData(1080, 1920, 224, 224)]
[InlineData(8, 8, 224, 8)]
[InlineData(4096, 16, 160, 160)]
[InlineData(100, 100, 288, 100)]
public void TheLongSideIsSplitIntoTheResolutionOrIntoSinglePixels(int width, int height, int resolution, int cells)
{
var (gridWidth, gridHeight, _) = InkDispersionSettings.GetGridSize(width, height, resolution);
Assert.InRange(Math.Max(gridWidth, gridHeight), cells + 1, cells + 2);
}
[Theory]
[InlineData(0f, 720, 192)]
[InlineData(10f, 720, 228)]
[InlineData(60f, 1080, 728)]
[InlineData(500f, 1080, 1080)]
[InlineData(500f, 720, 720)]
public void TheStepCountGrowsWithTheReachWithinItsLimits(float reachCells, int maxSteps, int expected)
=> Assert.Equal(expected, InkDispersionSettings.GetStepCount(reachCells, maxSteps));
[Theory]
[InlineData(-5f, InkDispersionSettings.MinimumDeposit)]
[InlineData(0f, InkDispersionSettings.MinimumDeposit)]
[InlineData(1f, InkDispersionSettings.MaximumDeposit)]
[InlineData(5f, InkDispersionSettings.MaximumDeposit)]
public void TheWaterDepositStaysWithinItsRange(float water, float expected)
=> Assert.Equal(expected, InkDispersionSettings.GetDeposit(water), 5);
[Fact]
public void MoreWaterDepositsMore()
=> Assert.True(InkDispersionSettings.GetDeposit(0.75f) > InkDispersionSettings.GetDeposit(0.25f));
[Theory]
[InlineData(0f, InkDispersionSettings.MaximumOmega)]
[InlineData(1f, InkDispersionSettings.MinimumOmega)]
public void TheRelaxationSpansItsRangeOverTheViscosity(float viscosity, float expected)
=> Assert.Equal(expected, InkDispersionSettings.GetOmega(viscosity), 5);
[Fact]
public void AHigherViscosityRelaxesMoreSlowly()
=> Assert.True(InkDispersionSettings.GetOmega(0.25f) > InkDispersionSettings.GetOmega(0.75f));
[Theory]
[InlineData(0f, InkDispersionSettings.SigmaFloor)]
[InlineData(1f, InkDispersionSettings.SigmaFloor + InkDispersionSettings.MaximumSigma)]
public void ThePinningThresholdSpansItsRangeOverTheSizing(float sizing, float expected)
=> Assert.Equal(expected, InkDispersionSettings.GetPinningSigma(sizing), 6);
[Fact]
public void MoreSizingPinsTheFrontHarder()
=> Assert.True(InkDispersionSettings.GetPinningSigma(0.75f) > InkDispersionSettings.GetPinningSigma(0.25f));
[Theory]
[InlineData(-1f, 0f)]
[InlineData(0f, 0f)]
[InlineData(1f, InkDispersionSettings.MaximumSurfaceEvaporation)]
[InlineData(2f, InkDispersionSettings.MaximumSurfaceEvaporation)]
public void TheEvaporationStaysWithinItsRange(float drying, float expected)
=> Assert.Equal(expected, InkDispersionSettings.GetSurfaceEvaporation(drying), 7);
}
+26
ファイルの表示
@@ -0,0 +1,26 @@
namespace InkDispersion.Tests;
public sealed class InkDispersionShaderMathTests
{
[Theory]
[InlineData(0, 0)]
[InlineData(1, 3)]
[InlineData(2, 4)]
[InlineData(3, 1)]
[InlineData(4, 2)]
[InlineData(5, 7)]
[InlineData(6, 8)]
[InlineData(7, 5)]
[InlineData(8, 6)]
public void EveryLatticeDirectionHasAnOppositeThatPointsBack(int direction, int expected)
{
Assert.Equal(expected, InkDispersionShaderMath.Opposite(direction));
Assert.Equal(direction, InkDispersionShaderMath.Opposite(expected));
Assert.Equal(-InkDispersionShaderMath.Ex(direction), InkDispersionShaderMath.Ex(expected));
Assert.Equal(-InkDispersionShaderMath.Ey(direction), InkDispersionShaderMath.Ey(expected));
}
[Fact]
public void TheLatticeWeightsSumToOne()
=> Assert.Equal(1f, Enumerable.Range(0, 9).Sum(InkDispersionShaderMath.Weight), 6);
}
+10
ファイルの表示
@@ -0,0 +1,10 @@
using System.IO.Packaging;
using System.Runtime.CompilerServices;
namespace InkDispersion.Tests;
internal static class PackUriScheme
{
[ModuleInitializer]
internal static void Register() => _ = PackUriHelper.UriSchemePack;
}
+95
ファイルの表示
@@ -0,0 +1,95 @@
using System.Numerics;
using System.Runtime.InteropServices;
using Vortice.Direct2D1;
using Vortice.Mathematics;
using YukkuriMovieMaker.Commons;
namespace InkDispersion.Tests;
internal sealed class Rendering
{
readonly byte[] pixels;
public int Left { get; }
public int Top { get; }
public int Width { get; }
public int Height { get; }
public int Right => Left + Width;
public int Bottom => Top + Height;
Rendering(int left, int top, int width, int height, byte[] pixels)
{
Left = left;
Top = top;
Width = width;
Height = height;
this.pixels = pixels;
}
public static Rendering Capture(IGraphicsDevicesAndContext devices, ID2D1Image image)
{
var context = devices.DeviceContext;
var bounds = context.GetImageLocalBounds(image);
var left = (int)Math.Floor(bounds.Left);
var top = (int)Math.Floor(bounds.Top);
var width = (int)Math.Ceiling(bounds.Right) - left;
var height = (int)Math.Ceiling(bounds.Bottom) - top;
var stride = width * SourceImage.BytesPerPixel;
var size = new SizeI(width, height);
using var target = context.CreateBitmap(size, nint.Zero, stride,
new BitmapProperties1(SourceImage.PixelFormat, SourceImage.Dpi, SourceImage.Dpi, BitmapOptions.Target));
using var readback = context.CreateBitmap(size, nint.Zero, stride,
new BitmapProperties1(SourceImage.PixelFormat, SourceImage.Dpi, SourceImage.Dpi, BitmapOptions.CpuRead | BitmapOptions.CannotDraw));
context.Target = target;
context.BeginDraw();
context.Clear(new Color4(0f, 0f, 0f, 0f));
context.DrawImage(image, new Vector2(-left, -top), null, InterpolationMode.NearestNeighbor, CompositeMode.SourceCopy);
context.EndDraw();
context.Target = null;
readback.CopyFromBitmap(target);
var pixels = new byte[stride * height];
var mapped = readback.Map(MapOptions.Read);
try
{
for (var y = 0; y < height; y++)
Marshal.Copy(mapped.Bits + y * (int)mapped.Pitch, pixels, y * stride, stride);
}
finally
{
readback.Unmap();
}
return new Rendering(left, top, width, height, pixels);
}
public Bgra this[int x, int y]
{
get
{
var offset = ((y - Top) * Width + (x - Left)) * SourceImage.BytesPerPixel;
return new Bgra(pixels[offset], pixels[offset + 1], pixels[offset + 2], pixels[offset + 3]);
}
}
public bool Contains(int x, int y) => x >= Left && y >= Top && x < Right && y < Bottom;
public bool SamePixelsAs(Rendering other)
=> Left == other.Left && Top == other.Top && Width == other.Width && Height == other.Height && pixels.AsSpan().SequenceEqual(other.pixels);
public IEnumerable<(int X, int Y)> Coordinates()
{
for (var y = Top; y < Bottom; y++)
{
for (var x = Left; x < Right; x++)
yield return (x, y);
}
}
}
+59
ファイルの表示
@@ -0,0 +1,59 @@
using Vortice.DCommon;
using Vortice.Direct2D1;
using Vortice.DXGI;
using Vortice.Mathematics;
using YukkuriMovieMaker.Commons;
namespace InkDispersion.Tests;
internal sealed class SourceImage : IDisposable
{
public const float Dpi = 96f;
public const int BytesPerPixel = 4;
public static readonly PixelFormat PixelFormat = new(Format.B8G8R8A8_UNorm, Vortice.DCommon.AlphaMode.Premultiplied);
readonly Func<int, int, Bgra> pixelOf;
public int Width { get; }
public int Height { get; }
public ID2D1Bitmap1 Bitmap { get; }
public SourceImage(IGraphicsDevicesAndContext devices, int width, int height, Func<int, int, Bgra> pixelOf)
{
this.pixelOf = pixelOf;
Width = width;
Height = height;
var stride = width * BytesPerPixel;
var pixels = new byte[stride * height];
for (var y = 0; y < height; y++)
{
for (var x = 0; x < width; x++)
{
var (blue, green, red, alpha) = pixelOf(x, y).Premultiplied();
var offset = y * stride + x * BytesPerPixel;
pixels[offset] = blue;
pixels[offset + 1] = green;
pixels[offset + 2] = red;
pixels[offset + 3] = alpha;
}
}
Bitmap = devices.DeviceContext.CreateBitmap(
new SizeI(width, height), nint.Zero, stride,
new BitmapProperties1(PixelFormat, Dpi, Dpi, BitmapOptions.None));
Bitmap.CopyFromMemory(pixels, stride);
}
public static SourceImage Solid(IGraphicsDevicesAndContext devices, int width, int height, Bgra color)
=> new(devices, width, height, (_, _) => color);
public Bgra this[int x, int y] => pixelOf(x, y).Premultiplied();
public bool Contains(int x, int y) => x >= 0 && y >= 0 && x < Width && y < Height;
public void Dispose() => Bitmap.Dispose();
}
+60
ファイルの表示
@@ -0,0 +1,60 @@
using System.Collections;
using System.Globalization;
using System.Reflection;
namespace InkDispersion.Tests;
public sealed class TextsTests
{
public static readonly TheoryData<string> Cultures = ["ja-JP", "en-US", "zh-CN", "zh-TW", "ko-KR", "es-ES", "ar-SA", "id-ID"];
static readonly string[] Keys = typeof(Texts)
.GetProperties(BindingFlags.Public | BindingFlags.Static)
.Where(property => property.PropertyType == typeof(string) && property.Name != nameof(Texts.CurrentCulture))
.Select(property => property.Name)
.ToArray();
[Fact]
public void EveryLocalizedKeyHasAProperty()
{
var resources = Texts.ResourceManager.GetResourceSet(CultureInfo.InvariantCulture, true, false)!;
var keys = resources.Cast<DictionaryEntry>().Select(entry => (string)entry.Key).Where(key => key != nameof(Texts.CurrentCulture));
Assert.Equal(keys.Order(), Keys.Order());
}
[Theory]
[MemberData(nameof(Cultures))]
public void EveryKeyIsTranslated(string culture)
{
var cultureInfo = CultureInfo.GetCultureInfo(culture);
Assert.All(Keys, key => Assert.False(string.IsNullOrWhiteSpace(Texts.ResourceManager.GetString(key, cultureInfo)), key));
}
[Theory]
[MemberData(nameof(Cultures))]
public void EveryCultureCarriesItsOwnTranslations(string culture)
{
var cultureInfo = CultureInfo.GetCultureInfo(culture);
Assert.Equal(culture.ToLowerInvariant(), Texts.ResourceManager.GetString(nameof(Texts.CurrentCulture), cultureInfo));
}
[Fact]
public void JapaneseIsTheNeutralLanguage()
{
var neutral = Texts.ResourceManager.GetString(nameof(Texts.InkDispersion), CultureInfo.InvariantCulture);
Assert.Equal("墨拡散", neutral);
Assert.Equal(neutral, Texts.ResourceManager.GetString(nameof(Texts.InkDispersion), CultureInfo.GetCultureInfo("ja-JP")));
}
[Fact]
public void TheUpdateMessageEmbedsTheVersion()
{
var message = string.Format(CultureInfo.InvariantCulture, Texts.ResourceManager.GetString(nameof(Texts.UpdateAvailableMessage), CultureInfo.InvariantCulture)!, "v1.2.3");
Assert.Contains("v1.2.3", message);
}
}
+26
ファイルの表示
@@ -0,0 +1,26 @@
{
"stryker-config": {
"project": "InkDispersion.csproj",
"test-runner": "mtp",
"coverage-analysis": "off",
"concurrency": 4,
"additional-timeout": 30000,
"mutate": [
"**/*.cs",
"!**/YMM4-GitHubUpdateNotifier/**",
"!**/YMM4-Telemetry/**",
"!**/InkDispersionTelemetry.cs",
"!**/InkDispersionUpdateNotifier.cs"
],
"reporters": [
"progress",
"cleartext",
"html"
],
"thresholds": {
"high": 80,
"low": 60,
"break": 55
}
}
}
+1 -1
ファイルの表示
@@ -5,7 +5,7 @@
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>1.1.1</Version>
<Version>1.1.2</Version>
<Platforms>AnyCPU;x64</Platforms>
<PlatformTarget>x64</PlatformTarget>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
+1
ファイルの表示
@@ -1,3 +1,4 @@
// Stryker disable all
using ComputeWeave;
namespace InkDispersion;
+12 -4
ファイルの表示
@@ -340,10 +340,10 @@ internal sealed class InkDispersionPipeline : IDisposable
private void EnsureGrid(int gridWidth, int gridHeight)
{
if (_gridWidth == gridWidth && _gridHeight == gridHeight)
return;
var resized = _gridWidth != gridWidth || _gridHeight != gridHeight;
if (resized)
DisposeGridBuffers();
DisposeGridBuffers();
var gridLength = gridWidth * gridHeight;
var distributionLength = gridLength * 9;
if (!_host.TryEnsureGrid(
@@ -366,8 +366,16 @@ internal sealed class InkDispersionPipeline : IDisposable
surfaceLength: gridLength,
velocityLength: gridLength,
wetnessLength: gridLength),
out _))
out var changed))
throw new InvalidOperationException();
if (!resized)
{
if (changed)
_structureKey = null;
return;
}
_inkStep = _device.AllocateReadWriteBuffer<int>(gridLength);
_inkStepReadBack = _device.AllocateReadBackBuffer<int>(gridLength);
_cachedInkStep = new int[gridLength];
+46
ファイルの表示
@@ -0,0 +1,46 @@
# セキュリティポリシー
## サポートするバージョン
セキュリティの修正は、最新のリリースだけを対象にします。
| バージョン | サポート |
|---|---|
| 最新のリリース | 対象 |
| それより前のリリース | 対象外 |
修正は、最新のリリースの次のバージョンとして公開します。報告する前に、最新のリリースでも問題が起きるかを確かめてください。
## 対象とする問題
本プラグインのコードと配布パッケージに原因がある問題を対象にします。たとえば次のようなものです。
- 細工したプロジェクトファイルや素材を開くと、意図しない処理が実行される
- 更新の確認などで行う通信の内容を、第三者が書き換えられる
- 不具合の情報を自動で送信するプラグインで、個人を特定できる情報が伏せられないまま送信される
配布パッケージに同梱したライブラリの脆弱性は、本プラグインを通じて悪用できる場合に対象にします。
YukkuriMovieMaker4 本体や、ほかのプラグインに原因がある問題は対象外です。それぞれの開発者へ報告してください。
## 報告の方法
脆弱性は、公開の Issue に書かないでください。修正を公開する前に悪用されるおそれがあります。
1. リポジトリの URL の末尾に `/security` を付けたページを開き、「Report a vulnerability」から非公開で報告してください。報告の内容を見られるのは、開発者と報告した人、開発者が招いた人だけです。
2. この方法が使えないときは、github.routersys@gmail.com へメールで報告してください。
報告には、次の内容を書いてください。分からない項目は書かなくて構いません。
| 項目 | 内容 |
|---|---|
| バージョン | 問題を確かめたプラグインのバージョンと、YukkuriMovieMaker4 のバージョン |
| 再現の手順 | 問題を起こす操作と、使ったプロジェクトファイルや素材 |
| 影響 | 問題によって何ができてしまうか |
| 回避策 | 分かっていれば、修正までの間に被害を避ける方法 |
## 報告の後
開発者は、報告を受け取ったら内容を確かめ、修正の見込みを返信します。
報告した人は、修正を含むバージョンが出るまで、報告の内容を明かさないでください。問題の詳細は、修正版の公開後に開発者が公表します。
バイナリ
ファイルの表示
バイナリファイルは表示されません。

変更前

幅:  |  高さ:  |  サイズ: 658 KiB

変更後

幅:  |  高さ:  |  サイズ: 1005 KiB

+5
ファイルの表示
@@ -0,0 +1,5 @@
{
"test": {
"runner": "Microsoft.Testing.Platform"
}
}