コミットを比較
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
27a56f610a
|
||
|
|
dbcd9d84c8
|
||
|
|
6b2842034a
|
||
|
|
b59a1827c2
|
||
|
|
f22c22f5d3
|
||
|
|
1ac6fab372
|
||
|
|
a91597fcdd
|
||
|
|
38d90125ba
|
||
|
|
7ad7ac0f30
|
||
|
|
f6fe8c1dd7
|
||
|
|
97e84ba169
|
||
|
|
cd8005c283
|
||
|
|
2030a19d8d
|
||
|
|
9a8c195d7f
|
||
|
|
c792764441
|
||
|
|
c241dc189d
|
||
|
|
6b6ebff653
|
||
|
|
104355b500
|
||
|
|
087a736e6d
|
||
|
|
d67aacc862
|
||
|
|
5216ebde5b
|
||
|
|
c92d2d50b2
|
||
|
|
e8377f5d83
|
||
|
|
e5acf28d54
|
||
|
|
b3f01cc76f
|
||
|
|
df72237d64
|
||
|
|
60ba4692b9
|
検索条件に一致するファイルはありません
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-stryker": {
|
||||
"version": "5.0.0",
|
||||
"commands": [
|
||||
"dotnet-stryker"
|
||||
],
|
||||
"rollForward": false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,483 @@
|
||||
name: リリース
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: リリースするタグ
|
||||
required: true
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
build-and-release:
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- name: ソースコードのチェックアウト
|
||||
uses: actions/checkout@v7
|
||||
env:
|
||||
GIT_CONFIG_COUNT: "2"
|
||||
GIT_CONFIG_KEY_0: url.https://git.routersys.com/routersys/.insteadOf
|
||||
GIT_CONFIG_VALUE_0: https://github.com/routersys/
|
||||
GIT_CONFIG_KEY_1: url.https://git.routersys.com/manju-summoner/YukkuriMovieMaker.Generator.insteadOf
|
||||
GIT_CONFIG_VALUE_1: https://github.com/manju-summoner/YukkuriMovieMaker.Generator
|
||||
with:
|
||||
ref: ${{ inputs.tag || github.ref_name }}
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: MSBuild のセットアップ
|
||||
uses: microsoft/setup-msbuild@v3
|
||||
|
||||
- name: YMM4 最新リリースの取得と解凍
|
||||
id: ymm4
|
||||
shell: pwsh
|
||||
run: |
|
||||
$list = 'C:\runner\cache\ymm4\releases.json'
|
||||
New-Item -ItemType Directory -Force -Path (Split-Path $list) | Out-Null
|
||||
if (-not (Test-Path $list) -or (Get-Item $list).Length -lt 1000 -or ((Get-Date) - (Get-Item $list).LastWriteTime).TotalHours -gt 6) {
|
||||
$fetched = $null
|
||||
for ($attempt = 1; $attempt -le 6 -and -not $fetched; $attempt++) {
|
||||
try {
|
||||
$fetched = Invoke-RestMethod -Uri "https://api.github.com/repos/manju-summoner/YukkuriMovieMaker4/releases?per_page=100" `
|
||||
-Headers @{ "User-Agent" = "DrawingWobble-CI" } -ErrorAction Stop
|
||||
}
|
||||
catch {
|
||||
$message = $_.Exception.Message
|
||||
Write-Host "リリース一覧の取得に失敗しました($attempt 回目): $($message.Substring(0, [Math]::Min(80, $message.Length)))"
|
||||
Start-Sleep -Seconds (5 * $attempt)
|
||||
}
|
||||
}
|
||||
if (@($fetched).Count -gt 0) {
|
||||
$fetched | Select-Object tag_name, published_at, prerelease, draft, assets |
|
||||
ConvertTo-Json -Depth 6 | Set-Content -Path $list -Encoding UTF8
|
||||
}
|
||||
elseif (-not (Test-Path $list)) { throw 'the list of releases could not be fetched' }
|
||||
else { Write-Host '保存済みのリリース一覧を使います' }
|
||||
}
|
||||
$when = [DateTimeOffset](git log -1 --format=%cI)
|
||||
$releases = @(Get-Content -Raw -Path $list | ConvertFrom-Json | Where-Object { -not $_.draft -and -not $_.prerelease })
|
||||
$release = $releases | Where-Object { [DateTimeOffset]$_.published_at -le $when } | Select-Object -First 1
|
||||
if (-not $release) { $release = $releases | Select-Object -Last 1 }
|
||||
Write-Host "最後のコミット $when に合わせた YMM4: $($release.tag_name)"
|
||||
$asset = $release.assets | Where-Object { $_.name -like "*_Lite.zip" } | Select-Object -First 1
|
||||
if (-not $asset) {
|
||||
$asset = $release.assets | Where-Object { $_.name -like "*.zip" } | Select-Object -First 1
|
||||
}
|
||||
Write-Host "ダウンロード対象: $($asset.name)"
|
||||
$cache = Join-Path 'C:\runner\cache\ymm4' $asset.name
|
||||
$extracted = "$cache.extracted"
|
||||
$lock = New-Object System.Threading.Mutex($false, 'Global\ci-ymm4-cache')
|
||||
[void]$lock.WaitOne()
|
||||
try {
|
||||
if (-not (Test-Path "$extracted\.complete")) {
|
||||
New-Item -ItemType Directory -Force -Path (Split-Path $cache) | Out-Null
|
||||
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $cache
|
||||
Remove-Item -Recurse -Force $extracted -ErrorAction SilentlyContinue
|
||||
Expand-Archive -Path $cache -DestinationPath $extracted -Force
|
||||
New-Item -ItemType File -Path "$extracted\.complete" | Out-Null
|
||||
}
|
||||
else {
|
||||
Write-Host "保存済みの YMM4 を使います: $extracted"
|
||||
}
|
||||
}
|
||||
finally {
|
||||
$lock.ReleaseMutex()
|
||||
}
|
||||
$ymm4Dir = (Get-ChildItem -Path $extracted -Recurse -Filter "YukkuriMovieMaker.dll" |
|
||||
Select-Object -First 1).DirectoryName
|
||||
Write-Host "YMM4 DLL ディレクトリ: $ymm4Dir"
|
||||
echo "YMM4_DIR=$ymm4Dir\" >> $env:GITHUB_OUTPUT
|
||||
|
||||
- name: タグ名からバージョンを取得
|
||||
id: version
|
||||
shell: pwsh
|
||||
run: |
|
||||
$tag = "${{ inputs.tag || github.ref_name }}"
|
||||
echo "TAG=$tag" >> $env:GITHUB_OUTPUT
|
||||
echo "VERSION=$($tag.TrimStart('v'))" >> $env:GITHUB_OUTPUT
|
||||
|
||||
- name: バージョン記載の照合
|
||||
shell: pwsh
|
||||
run: |
|
||||
$tag = "${{ steps.version.outputs.TAG }}"
|
||||
$version = "${{ steps.version.outputs.VERSION }}"
|
||||
$problems = @()
|
||||
|
||||
$csprojPath = "DrawingWobble/DrawingWobble.csproj"
|
||||
$csproj = Get-Content $csprojPath -Raw
|
||||
if (-not $csproj.Contains("<Version>$version</Version>")) {
|
||||
$current = if ($csproj -match '<Version>([^<]*)</Version>') { $Matches[1] } else { "記載なし" }
|
||||
$problems += "$csprojPath の <Version> が $current です。$version にしてください。"
|
||||
}
|
||||
|
||||
$readmePath = ".github/Plugin_Readme.txt"
|
||||
$readme = Get-Content $readmePath -Raw
|
||||
if (-not $readme.Contains(" DrawingWobble for YMM4 $tag")) {
|
||||
$current = if ($readme -match '(?m)^ DrawingWobble for YMM4 (\S+)') { $Matches[1] } else { "記載なし" }
|
||||
$problems += "$readmePath の見出しが $current です。$tag にしてください。"
|
||||
}
|
||||
|
||||
if ($problems.Count -eq 0) {
|
||||
Write-Host "バージョン記載は $tag と一致しています"
|
||||
exit 0
|
||||
}
|
||||
|
||||
foreach ($problem in $problems) {
|
||||
Write-Host "::error::$problem"
|
||||
}
|
||||
Write-Host "::error::リリースの対象は $tag が指すコミットです。タグを付けた後で main へ訂正を積んでも、その訂正はリリースに入りません。タグを削除し、記載を直したコミットを積んでから付け直してください。"
|
||||
exit 1
|
||||
|
||||
- name: シェーダーのビルド
|
||||
shell: pwsh
|
||||
run: |
|
||||
msbuild DrawingWobble.Shader/DrawingWobble.Shader.vcxproj `
|
||||
/p:Configuration=Release `
|
||||
/p:Platform=Win32 `
|
||||
/nologo
|
||||
|
||||
- name: プロジェクトのビルド
|
||||
shell: pwsh
|
||||
run: |
|
||||
$proj = "DrawingWobble/DrawingWobble.csproj"
|
||||
dotnet build "$proj" `
|
||||
-c Release `
|
||||
-p:YMM4DirPath="${{ steps.ymm4.outputs.YMM4_DIR }}" `
|
||||
-p:SkipPluginDeploy=true
|
||||
|
||||
- name: パッケージの作成
|
||||
id: package
|
||||
shell: pwsh
|
||||
run: |
|
||||
$version = "${{ steps.version.outputs.TAG }}"
|
||||
$outDir = "DrawingWobble/bin/Release/net10.0-windows10.0.19041.0"
|
||||
$stageRoot = "stage/DrawingWobble"
|
||||
$pkgName = "DrawingWobble_$version.ymme"
|
||||
|
||||
New-Item -ItemType Directory -Path $stageRoot -Force | Out-Null
|
||||
New-Item -ItemType Directory -Path "$stageRoot/LICENSE" -Force | Out-Null
|
||||
|
||||
$dll = "$outDir/DrawingWobble.dll"
|
||||
if (-not (Test-Path $dll)) {
|
||||
Write-Error "ビルド結果に DrawingWobble.dll が見つかりませんでした: $dll"
|
||||
exit 1
|
||||
}
|
||||
Copy-Item $dll "$stageRoot/"
|
||||
|
||||
foreach ($lang in @("ar-sa", "en-us", "es-es", "id-id", "ko-kr", "zh-cn", "zh-tw")) {
|
||||
$src = "$outDir/$lang"
|
||||
if (Test-Path $src) {
|
||||
New-Item -ItemType Directory -Path "$stageRoot/$lang" -Force | Out-Null
|
||||
Copy-Item "$src/*.dll" "$stageRoot/$lang/"
|
||||
}
|
||||
}
|
||||
|
||||
Copy-Item ".github/LICENSE/*.txt" "$stageRoot/LICENSE/"
|
||||
Copy-Item ".github/Plugin_Readme.txt" "$stageRoot/Readme.txt"
|
||||
|
||||
$readme = Get-Content "$stageRoot/Readme.txt" -Raw
|
||||
if (-not $readme.Contains(" DrawingWobble for YMM4 $version")) {
|
||||
Write-Error "同梱する Readme.txt の見出しが $version と一致しません"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Compress-Archive -Path "stage/*" -DestinationPath $pkgName -CompressionLevel Optimal
|
||||
echo "PKG_NAME=$pkgName" >> $env:GITHUB_OUTPUT
|
||||
|
||||
- name: 変更履歴の作成
|
||||
id: changelog
|
||||
shell: pwsh
|
||||
env:
|
||||
GITEA_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ steps.version.outputs.TAG }}
|
||||
REPOSITORY: ${{ github.repository }}
|
||||
SERVER_URL: ${{ github.server_url }}
|
||||
PACKAGE: ${{ steps.package.outputs.PKG_NAME }}
|
||||
run: |
|
||||
$tag = $env:TAG
|
||||
$repository = $env:REPOSITORY
|
||||
$server = $env:SERVER_URL
|
||||
$code = [char]0x60
|
||||
$fence = [string]::new($code, 3)
|
||||
$unit = [char]0x1f
|
||||
|
||||
$previous = ""
|
||||
$candidates = @(git tag --list "v*" --merged $tag --sort=-creatordate | Where-Object { $_ -ne $tag })
|
||||
if ($candidates.Count -gt 0) {
|
||||
$previous = $candidates[0]
|
||||
}
|
||||
Write-Host "直前のタグ: $previous"
|
||||
|
||||
$range = if ($previous) { "$previous..$tag" } else { $tag }
|
||||
$log = @(git log "--format=%H%x1f%s%x1f%an%x1f%ad" --date=short $range)
|
||||
|
||||
$commits = @()
|
||||
foreach ($line in $log) {
|
||||
if (-not $line) { continue }
|
||||
$fields = $line -split $unit
|
||||
if ($fields.Count -lt 4) { continue }
|
||||
$commits += [pscustomobject]@{
|
||||
Sha = $fields[0]
|
||||
Subject = $fields[1]
|
||||
Name = $fields[2]
|
||||
Date = $fields[3]
|
||||
Login = ""
|
||||
Avatar = ""
|
||||
}
|
||||
}
|
||||
Write-Host "コミット数: $($commits.Count)"
|
||||
|
||||
$pending = [System.Collections.Generic.HashSet[string]]::new()
|
||||
foreach ($commit in $commits) {
|
||||
[void]$pending.Add($commit.Sha)
|
||||
}
|
||||
|
||||
$headers = @{ Authorization = "token $env:GITEA_TOKEN" }
|
||||
|
||||
$accounts = @{}
|
||||
$page = 1
|
||||
while ($pending.Count -gt 0 -and $page -le 20) {
|
||||
$rows = @()
|
||||
try {
|
||||
$rows = @(Invoke-RestMethod -Uri "$server/api/v1/repos/$repository/commits?sha=$tag&limit=50&page=$page&stat=false&verification=false&files=false" -Headers $headers)
|
||||
}
|
||||
catch {
|
||||
Write-Host "コミットの作者を取得できませんでした: $($_.Exception.Message)"
|
||||
break
|
||||
}
|
||||
if ($rows.Count -eq 0) { break }
|
||||
|
||||
foreach ($row in $rows) {
|
||||
if ($pending.Remove($row.sha)) {
|
||||
$login = ""
|
||||
$avatar = ""
|
||||
if ($row.author) {
|
||||
$login = [string]$row.author.login
|
||||
$avatar = [string]$row.author.avatar_url
|
||||
}
|
||||
$accounts[$row.sha] = @{ Login = $login; Avatar = $avatar }
|
||||
}
|
||||
}
|
||||
|
||||
if ($rows.Count -lt 50) { break }
|
||||
$page++
|
||||
}
|
||||
|
||||
foreach ($commit in $commits) {
|
||||
if ($accounts.ContainsKey($commit.Sha)) {
|
||||
$commit.Login = $accounts[$commit.Sha].Login
|
||||
$commit.Avatar = $accounts[$commit.Sha].Avatar
|
||||
}
|
||||
}
|
||||
|
||||
$emptyTree = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
||||
$base = if ($previous) { $previous } else { $emptyTree }
|
||||
$shortstat = (@(git diff --shortstat $base $tag) -join " ")
|
||||
$changedFiles = 0
|
||||
$insertions = 0
|
||||
$deletions = 0
|
||||
if ($shortstat -match "(\d+) file") { $changedFiles = [int]$Matches[1] }
|
||||
if ($shortstat -match "(\d+) insertion") { $insertions = [int]$Matches[1] }
|
||||
if ($shortstat -match "(\d+) deletion") { $deletions = [int]$Matches[1] }
|
||||
$diffStat = @(git diff --stat $base $tag)
|
||||
$tagDate = (git log -1 "--format=%ad" --date=short $tag)
|
||||
|
||||
$contributors = @($commits |
|
||||
Group-Object -Property { if ($_.Login) { $_.Login } else { $_.Name } } |
|
||||
Sort-Object -Property Count -Descending)
|
||||
|
||||
function Get-Icon($avatar, $login, $size) {
|
||||
if (-not $avatar) { return "" }
|
||||
$sized = if ($avatar.Contains("?")) { "$avatar&s=$($size * 2)" } else { "$avatar" + "?s=$($size * 2)" }
|
||||
return "<img src=""$sized"" width=""$size"" height=""$size"" alt=""$login""> "
|
||||
}
|
||||
|
||||
$package = Get-Item $env:PACKAGE
|
||||
$size = [math]::Round($package.Length / 1MB, 2)
|
||||
|
||||
$body = [System.Collections.Generic.List[string]]::new()
|
||||
$body.Add("## 概要")
|
||||
$body.Add("")
|
||||
$body.Add("| 項目 | 内容 |")
|
||||
$body.Add("|---|---|")
|
||||
$body.Add("| タグ | [$tag]($server/$repository/tree/$tag) |")
|
||||
$body.Add("| 公開日 | $tagDate |")
|
||||
if ($previous) {
|
||||
$body.Add("| 直前のリリース | [$previous]($server/$repository/releases/tag/$previous) |")
|
||||
}
|
||||
$body.Add("| コミット数 | $($commits.Count) |")
|
||||
$body.Add("| 貢献者 | $($contributors.Count) 名 |")
|
||||
$body.Add("| 変更されたファイル | $changedFiles |")
|
||||
$body.Add("| 追加された行 | $insertions |")
|
||||
$body.Add("| 削除された行 | $deletions |")
|
||||
|
||||
$body.Add("")
|
||||
$body.Add("## ダウンロード")
|
||||
$body.Add("")
|
||||
$body.Add("| ファイル | サイズ |")
|
||||
$body.Add("|---|---|")
|
||||
$body.Add("| $($package.Name) | $size MB |")
|
||||
|
||||
$body.Add("")
|
||||
$body.Add("## 貢献者")
|
||||
$body.Add("")
|
||||
$body.Add("| 貢献者 | コミット数 |")
|
||||
$body.Add("|---|---|")
|
||||
foreach ($contributor in $contributors) {
|
||||
$first = $contributor.Group[0]
|
||||
if ($first.Login) {
|
||||
$name = (Get-Icon $first.Avatar $first.Login 40) + "[@$($first.Login)]($server/$($first.Login))"
|
||||
}
|
||||
else {
|
||||
$name = $first.Name
|
||||
}
|
||||
$body.Add("| $name | $($contributor.Count) |")
|
||||
}
|
||||
|
||||
$body.Add("")
|
||||
$body.Add("## 変更履歴")
|
||||
$body.Add("")
|
||||
$body.Add("| コミット | 内容 | 貢献者 | 日付 |")
|
||||
$body.Add("|---|---|---|---|")
|
||||
$maximumCommits = 300
|
||||
$listed = 0
|
||||
foreach ($commit in $commits) {
|
||||
if ($listed -ge $maximumCommits) { break }
|
||||
$short = $commit.Sha.Substring(0, 7)
|
||||
$subject = $commit.Subject -replace '\|', '\|'
|
||||
if ($commit.Login) {
|
||||
$author = (Get-Icon $commit.Avatar $commit.Login 20) + "[@$($commit.Login)]($server/$($commit.Login))"
|
||||
}
|
||||
else {
|
||||
$author = $commit.Name
|
||||
}
|
||||
$body.Add("| [$code$short$code]($server/$repository/commit/$($commit.Sha)) | $subject | $author | $($commit.Date) |")
|
||||
$listed++
|
||||
}
|
||||
if ($commits.Count -gt $maximumCommits) {
|
||||
$body.Add("")
|
||||
$body.Add("残り $($commits.Count - $maximumCommits) 件のコミットは省略しました。")
|
||||
}
|
||||
|
||||
if ($diffStat.Count -gt 0) {
|
||||
$body.Add("")
|
||||
$body.Add("## 変更されたファイル")
|
||||
$body.Add("")
|
||||
$body.Add("<details>")
|
||||
$body.Add("<summary>差分の統計</summary>")
|
||||
$body.Add("")
|
||||
$body.Add($fence)
|
||||
$maximumStatLines = 200
|
||||
$shown = 0
|
||||
foreach ($line in $diffStat) {
|
||||
if ($shown -ge $maximumStatLines) { break }
|
||||
$body.Add($line)
|
||||
$shown++
|
||||
}
|
||||
if ($diffStat.Count -gt $maximumStatLines) {
|
||||
$body.Add("... 残り $($diffStat.Count - $maximumStatLines) 行は省略しました。")
|
||||
}
|
||||
$body.Add($fence)
|
||||
$body.Add("")
|
||||
$body.Add("</details>")
|
||||
}
|
||||
|
||||
if ($previous) {
|
||||
$body.Add("")
|
||||
$body.Add("## 全ての変更")
|
||||
$body.Add("")
|
||||
$body.Add("$server/$repository/compare/$previous...$tag")
|
||||
}
|
||||
|
||||
$path = "release-body.md"
|
||||
Set-Content -Path $path -Value ($body -join "`n") -Encoding utf8NoBOM
|
||||
if (-not (Test-Path $path)) {
|
||||
throw "変更履歴を作成できませんでした。"
|
||||
}
|
||||
Write-Host "変更履歴の行数: $($body.Count)"
|
||||
$global:LASTEXITCODE = 0
|
||||
|
||||
- name: Gitea リリースの作成
|
||||
shell: pwsh
|
||||
env:
|
||||
GITEA_TOKEN: ${{ github.token }}
|
||||
REPOSITORY: ${{ github.repository }}
|
||||
SERVER_URL: ${{ github.server_url }}
|
||||
EVENT_NAME: ${{ github.event_name }}
|
||||
WORKFLOW_NAME: ${{ github.workflow }}
|
||||
JOB_NAME: ${{ github.job }}
|
||||
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_number }}
|
||||
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
|
||||
RELEASE_NAME: ${{ steps.version.outputs.TAG }}
|
||||
RELEASE_BODY: ''
|
||||
RELEASE_BODY_PATH: release-body.md
|
||||
RELEASE_DRAFT: false
|
||||
RELEASE_PRERELEASE: false
|
||||
RELEASE_FILES: |
|
||||
${{ steps.package.outputs.PKG_NAME }}
|
||||
run: |
|
||||
$headers = @{ Authorization = "token $env:GITEA_TOKEN" }
|
||||
$api = "$env:SERVER_URL/api/v1/repos/$env:REPOSITORY"
|
||||
$tag = $env:RELEASE_TAG
|
||||
|
||||
$body = $env:RELEASE_BODY
|
||||
if ($env:RELEASE_BODY_PATH -and (Test-Path $env:RELEASE_BODY_PATH)) {
|
||||
$body = Get-Content $env:RELEASE_BODY_PATH -Raw -Encoding utf8
|
||||
}
|
||||
|
||||
$files = @()
|
||||
foreach ($pattern in ($env:RELEASE_FILES -split "[`r`n,]+" | Where-Object { $_.Trim() })) {
|
||||
$found = @(Get-ChildItem -Path $pattern.Trim() -File -ErrorAction SilentlyContinue)
|
||||
if ($found.Count -eq 0) { throw "リリースに付けるファイルが見つかりません: $pattern" }
|
||||
$files += $found
|
||||
}
|
||||
|
||||
$payload = @{
|
||||
tag_name = $tag
|
||||
name = $env:RELEASE_NAME
|
||||
body = [string]$body
|
||||
draft = ($env:RELEASE_DRAFT -eq 'true')
|
||||
prerelease = ($env:RELEASE_PRERELEASE -eq 'true')
|
||||
} | ConvertTo-Json
|
||||
$bytes = [System.Text.Encoding]::UTF8.GetBytes($payload)
|
||||
|
||||
$existing = $null
|
||||
try { $existing = Invoke-RestMethod -Uri "$api/releases/tags/$([System.Uri]::EscapeDataString($tag))" -Headers $headers } catch { }
|
||||
if ($existing) {
|
||||
$release = Invoke-RestMethod -Method Patch -Uri "$api/releases/$($existing.id)" -Headers $headers -ContentType "application/json; charset=utf-8" -Body $bytes
|
||||
foreach ($asset in @($existing.assets)) {
|
||||
Invoke-RestMethod -Method Delete -Uri "$api/releases/$($existing.id)/assets/$($asset.id)" -Headers $headers | Out-Null
|
||||
}
|
||||
} else {
|
||||
$release = Invoke-RestMethod -Method Post -Uri "$api/releases" -Headers $headers -ContentType "application/json; charset=utf-8" -Body $bytes
|
||||
}
|
||||
foreach ($file in $files) {
|
||||
$name = [System.Uri]::EscapeDataString($file.Name)
|
||||
Invoke-RestMethod -Method Post -Uri "$api/releases/$($release.id)/assets?name=$name" -Headers $headers -Form @{ attachment = Get-Item $file.FullName } | Out-Null
|
||||
Write-Host "添付しました: $($file.Name)"
|
||||
}
|
||||
Write-Host "リリースを作成しました: $($release.html_url)"
|
||||
|
||||
if ($env:EVENT_NAME -eq 'workflow_dispatch') {
|
||||
try {
|
||||
$sha = (git rev-parse HEAD).Trim()
|
||||
$status = @{
|
||||
state = 'success'
|
||||
context = "$env:WORKFLOW_NAME / $env:JOB_NAME (workflow_dispatch)"
|
||||
description = "Actions がタグ $tag のコミットから作成しました"
|
||||
target_url = $env:RUN_URL
|
||||
} | ConvertTo-Json
|
||||
Invoke-RestMethod -Method Post -Uri "$api/statuses/$sha" -Headers $headers -ContentType "application/json; charset=utf-8" -Body ([System.Text.Encoding]::UTF8.GetBytes($status)) | Out-Null
|
||||
Write-Host "タグのコミット $sha に成功の状態を付けました"
|
||||
}
|
||||
catch {
|
||||
Write-Warning "タグのコミットに状態を付けられませんでした: $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
|
||||
+14
-4
@@ -73,15 +73,22 @@ YukkuriMovieMaker4(YMM4)上で動作する、映像を手描きアニメの
|
||||
■ 不具合の報告
|
||||
--------------------------------------------------------------------------------
|
||||
本プラグインは、想定していない例外が起きたときに、その内容を開発者へ自動で
|
||||
送信します。同意は求めず、常に送信します。
|
||||
送信します。同意は求めません。止める設定もありません。
|
||||
|
||||
送信する数には上限があります。YMM4 の 1 回の起動で送る報告は、
|
||||
YMM4-Telemetry で報告する別のプラグインと合わせて 20 件までです。
|
||||
例外の型と発生位置が同じ報告は 3 件までです。上限を超えた報告と、
|
||||
送信先から待つよう求められている間に起きた報告は、送信も退避もしません。
|
||||
|
||||
送信する情報は次のとおりです。
|
||||
例外 : 型の完全名、メッセージ、スタックトレース
|
||||
発生位置 : モジュール名、関数名、ファイル名、行番号
|
||||
発生位置 : モジュール名、関数名、ファイル名、行番号、
|
||||
プラグイン自身のコードかどうか
|
||||
プラグイン : アセンブリ名、バージョン
|
||||
実行環境 : OS の名前とバージョン、.NET のバージョン、
|
||||
CPU のアーキテクチャ、論理プロセッサ数
|
||||
識別子 : YMM4 の起動ごとに決まるセッション識別子、報告ごとの識別子
|
||||
時刻 : 報告を作った時刻(UTC)
|
||||
|
||||
映像の中身とプロジェクトの内容は送信しません。継続して個人を追跡する
|
||||
識別子も持ちません。セッション識別子は YMM4 を起動し直すと別の値に
|
||||
@@ -100,8 +107,11 @@ YukkuriMovieMaker4(YMM4)上で動作する、映像を手描きアニメの
|
||||
そのまま通したとき
|
||||
更新の確認の通信の失敗 : GitHub へ接続できない
|
||||
|
||||
送信できなかった報告は YMM4 のユーザーフォルダーへ退避し、次回の起動時に
|
||||
送り直します。送信も再送も非同期に行うため、起動と描画が遅くなることは
|
||||
送信できなかった報告は YMM4 のユーザーフォルダーへ退避します。
|
||||
次に YMM4 を起動したあと、本プラグインのエフェクトを生成するか、
|
||||
同じく YMM4-Telemetry で報告する別のプラグインが動き始めると、
|
||||
退避した報告を 1 回の起動で 10 件まで送り直します。
|
||||
送信も再送も非同期に行うため、起動と描画が遅くなることは
|
||||
ありません。
|
||||
--------------------------------------------------------------------------------
|
||||
■ 免責事項
|
||||
|
||||
+3
-1
@@ -363,4 +363,6 @@ MigrationBackup/
|
||||
FodyWeavers.xsd
|
||||
|
||||
# YukkuriMovieMaker.Generator
|
||||
*.resx
|
||||
*.resx
|
||||
# Stryker.NET
|
||||
StrykerOutput/
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
[submodule "YukkuriMovieMaker.Generator"]
|
||||
path = YukkuriMovieMaker.Generator
|
||||
url = https://github.com/manju-summoner/YukkuriMovieMaker.Generator.git
|
||||
url = https://git.routersys.com/manju-summoner/YukkuriMovieMaker.Generator.git
|
||||
[submodule "YMM4-GitHubUpdateNotifier"]
|
||||
path = YMM4-GitHubUpdateNotifier
|
||||
url = https://github.com/routersys/YMM4-GitHubUpdateNotifier.git
|
||||
url = https://git.routersys.com/routersys/YMM4-GitHubUpdateNotifier.git
|
||||
[submodule "YMM4-Telemetry"]
|
||||
path = YMM4-Telemetry
|
||||
url = https://github.com/routersys/YMM4-Telemetry.git
|
||||
url = https://git.routersys.com/routersys/YMM4-Telemetry.git
|
||||
@@ -0,0 +1,61 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<AssemblyName>DrawingWobble.Harness</AssemblyName>
|
||||
<RootNamespace>DrawingWobble.Harness</RootNamespace>
|
||||
<TieredCompilation>false</TieredCompilation>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DrawingWobble\DrawingWobble.csproj" SetConfiguration="Configuration=$(Configuration)">
|
||||
<AdditionalProperties Condition="'$(BuildingSolutionFile)' != 'true'">SkipPluginDeploy=true</AdditionalProperties>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyMetadata Include="HostDirectory" Value="$(YMM4DirPath)" />
|
||||
<AssemblyMetadata Include="HarnessDirectory" Value="$(MSBuildProjectDirectory)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="SharpGen.Runtime">
|
||||
<HintPath>$(YMM4DirPath)SharpGen.Runtime.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>
|
||||
<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>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,55 @@
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace DrawingWobble.Harness;
|
||||
|
||||
internal sealed record GoldenCase(string Name, IReadOnlyList<int> Frames, string Hash);
|
||||
|
||||
internal sealed record Golden(string Adapter, string Driver, string Input, string Canvas, IReadOnlyList<GoldenCase> Cases)
|
||||
{
|
||||
const string FileName = "golden.json";
|
||||
const string DirectoryKey = "HarnessDirectory";
|
||||
|
||||
static readonly JsonSerializerOptions Options = new()
|
||||
{
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true,
|
||||
NewLine = "\n",
|
||||
};
|
||||
|
||||
public static string PathFor(HarnessImage image)
|
||||
=> Path.Combine(ReadDirectory(), image.Key is null ? FileName : $"golden-{image.Key}.json");
|
||||
|
||||
public static Golden Load(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
throw new HarnessException($"基準値がありません。先に --golden で書いてください。{path}");
|
||||
Golden? golden;
|
||||
try
|
||||
{
|
||||
golden = JsonSerializer.Deserialize<Golden>(File.ReadAllBytes(path), Options);
|
||||
}
|
||||
catch (JsonException exception)
|
||||
{
|
||||
throw new HarnessException($"基準値を読めません。{path} {exception.Message}");
|
||||
}
|
||||
|
||||
if (golden is not { Adapter: not null, Driver: not null, Input: not null, Canvas: not null, Cases: not null }
|
||||
|| golden.Cases.Any(item => item is not { Name: not null, Frames: not null, Hash: not null }))
|
||||
throw new HarnessException($"基準値の項目が足りません。{path}");
|
||||
if (golden.Cases.Select(item => item.Name).Distinct(StringComparer.Ordinal).Count() != golden.Cases.Count)
|
||||
throw new HarnessException($"基準値のケース名が重複しています。{path}");
|
||||
return golden;
|
||||
}
|
||||
|
||||
public void Save(string path) => File.WriteAllBytes(path, JsonSerializer.SerializeToUtf8Bytes(this, Options));
|
||||
|
||||
static string ReadDirectory()
|
||||
=> typeof(Golden).Assembly
|
||||
.GetCustomAttributes<AssemblyMetadataAttribute>()
|
||||
.FirstOrDefault(attribute => string.Equals(attribute.Key, DirectoryKey, StringComparison.Ordinal))
|
||||
?.Value ?? throw new HarnessException($"アセンブリに {DirectoryKey} がありません。");
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System.Diagnostics;
|
||||
using Vortice.Direct3D11;
|
||||
|
||||
namespace DrawingWobble.Harness;
|
||||
|
||||
internal sealed class GpuTimer : IDisposable
|
||||
{
|
||||
static readonly TimeSpan ResolveTimeout = TimeSpan.FromSeconds(5);
|
||||
|
||||
readonly ID3D11DeviceContext context;
|
||||
readonly ID3D11Query disjoint;
|
||||
readonly ID3D11Query start;
|
||||
readonly ID3D11Query stop;
|
||||
|
||||
public GpuTimer(ID3D11Device device, ID3D11DeviceContext context)
|
||||
{
|
||||
this.context = context;
|
||||
disjoint = device.CreateQuery(new QueryDescription(QueryType.TimestampDisjoint, QueryFlags.None));
|
||||
start = device.CreateQuery(new QueryDescription(QueryType.Timestamp, QueryFlags.None));
|
||||
stop = device.CreateQuery(new QueryDescription(QueryType.Timestamp, QueryFlags.None));
|
||||
}
|
||||
|
||||
public void Begin()
|
||||
{
|
||||
context.Begin(disjoint);
|
||||
context.End(start);
|
||||
}
|
||||
|
||||
public void End()
|
||||
{
|
||||
context.End(stop);
|
||||
context.End(disjoint);
|
||||
}
|
||||
|
||||
public TimeSpan? Resolve()
|
||||
{
|
||||
if (!Wait<QueryDataTimestampDisjoint>(disjoint, out var timing) || timing.Disjoint || timing.Frequency == 0UL)
|
||||
return null;
|
||||
if (!Wait<ulong>(start, out var began) || !Wait<ulong>(stop, out var ended) || ended < began)
|
||||
return null;
|
||||
return TimeSpan.FromSeconds((ended - began) / (double)timing.Frequency);
|
||||
}
|
||||
|
||||
bool Wait<T>(ID3D11Query query, out T value) where T : unmanaged
|
||||
{
|
||||
var elapsed = Stopwatch.StartNew();
|
||||
while (!context.GetData(query, out value))
|
||||
{
|
||||
if (elapsed.Elapsed > ResolveTimeout)
|
||||
return false;
|
||||
Thread.Yield();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
stop.Dispose();
|
||||
start.Dispose();
|
||||
disjoint.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
namespace DrawingWobble.Harness;
|
||||
|
||||
internal sealed class HarnessException(string message) : Exception(message);
|
||||
|
||||
internal enum HarnessMode
|
||||
{
|
||||
Render,
|
||||
Golden,
|
||||
Verify,
|
||||
Transition,
|
||||
Compare,
|
||||
Benchmark,
|
||||
}
|
||||
|
||||
internal sealed record HarnessArguments(HarnessMode Mode, string? Input, string? OutputDirectory, string? Before, string? After)
|
||||
{
|
||||
public const string Usage = """
|
||||
使い方:
|
||||
[<出力先>] [--input <画像>] ケースを描き、PNG とハッシュを出します
|
||||
--golden [--input <画像>] 基準値を golden.json に書きます
|
||||
--verify [--input <画像>] 基準値と照合します
|
||||
--transition [<出力先>] [--input <画像>] 設定を変えた後とフレームを進めた後の描画を、作り直した描画と照合します
|
||||
--compare <前> <後> 2 つの出力先の PNG を画素ごとに比べます
|
||||
--benchmark [--input <画像>] 描画を計測します
|
||||
""";
|
||||
|
||||
public static HarnessArguments Parse(string[] arguments)
|
||||
{
|
||||
HarnessMode? mode = null;
|
||||
string? input = null;
|
||||
var positionals = new List<string>();
|
||||
for (var index = 0; index < arguments.Length; index++)
|
||||
{
|
||||
var argument = arguments[index];
|
||||
switch (argument)
|
||||
{
|
||||
case "--golden":
|
||||
mode = Select(mode, HarnessMode.Golden);
|
||||
break;
|
||||
case "--verify":
|
||||
mode = Select(mode, HarnessMode.Verify);
|
||||
break;
|
||||
case "--transition":
|
||||
mode = Select(mode, HarnessMode.Transition);
|
||||
break;
|
||||
case "--compare":
|
||||
mode = Select(mode, HarnessMode.Compare);
|
||||
break;
|
||||
case "--benchmark":
|
||||
mode = Select(mode, HarnessMode.Benchmark);
|
||||
break;
|
||||
case "--input":
|
||||
if (index + 1 >= arguments.Length)
|
||||
throw new HarnessException("--input には画像のパスを続けてください。");
|
||||
input = arguments[++index];
|
||||
break;
|
||||
default:
|
||||
if (argument.StartsWith('-'))
|
||||
throw new HarnessException($"不明なオプションです。{argument}");
|
||||
positionals.Add(argument);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var selected = mode ?? HarnessMode.Render;
|
||||
switch (selected)
|
||||
{
|
||||
case HarnessMode.Compare:
|
||||
if (positionals.Count != 2)
|
||||
throw new HarnessException("--compare には前と後の出力先を続けてください。");
|
||||
if (input is not null)
|
||||
throw new HarnessException("--compare に --input は使えません。");
|
||||
return new HarnessArguments(HarnessMode.Compare, null, null, positionals[0], positionals[1]);
|
||||
case HarnessMode.Render:
|
||||
case HarnessMode.Transition:
|
||||
if (positionals.Count > 1)
|
||||
throw new HarnessException($"余分な引数です。{positionals[1]}");
|
||||
return new HarnessArguments(selected, input, positionals.FirstOrDefault(), null, null);
|
||||
default:
|
||||
if (positionals.Count > 0)
|
||||
throw new HarnessException($"余分な引数です。{positionals[0]}");
|
||||
return new HarnessArguments(selected, input, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
static HarnessMode Select(HarnessMode? current, HarnessMode next)
|
||||
=> current is null ? next : throw new HarnessException("モードは 1 つだけ指定してください。");
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
namespace DrawingWobble.Harness;
|
||||
|
||||
internal static class HarnessCases
|
||||
{
|
||||
public static IEnumerable<(string Name, DrawingWobbleEffect Effect, IReadOnlyList<int> Frames)> All()
|
||||
{
|
||||
yield return ("default", Create(), [0]);
|
||||
yield return ("default-frame-4", Create(), [4]);
|
||||
yield return ("default-frames-0-8", Create(), Enumerable.Range(0, 9).ToArray());
|
||||
yield return ("amplitude-0", Create(effect => effect.Amplitude.Values[0].Value = 0), [0]);
|
||||
yield return ("amplitude-20", Create(effect => effect.Amplitude.Values[0].Value = 20), [0]);
|
||||
yield return ("scale-8", Create(effect => effect.Scale.Values[0].Value = 8), [0]);
|
||||
yield return ("scale-400", Create(effect => effect.Scale.Values[0].Value = 400), [0]);
|
||||
yield return ("hold-1-frame-2", Create(effect => effect.HoldFrames = 1), [2]);
|
||||
yield return ("hold-1-frames-0-3", Create(effect => effect.HoldFrames = 1), [0, 1, 2, 3]);
|
||||
yield return ("seed-42", Create(effect => effect.Seed = 42), [0]);
|
||||
yield return ("edge-radius-64", Create(effect => effect.EdgeRadius.Values[0].Value = 64), [0]);
|
||||
yield return ("edge-focus-0", Create(effect => effect.EdgeFocus.Values[0].Value = 0), [0]);
|
||||
yield return ("edge-focus-50", Create(effect => effect.EdgeFocus.Values[0].Value = 50), [0]);
|
||||
}
|
||||
|
||||
public static IEnumerable<(string Name, Func<DrawingWobbleEffect> Create, Action<DrawingWobbleEffect> Change, int Frame)> Transitions()
|
||||
{
|
||||
yield return ("amplitude-2-to-20", () => Create(), effect => effect.Amplitude.Values[0].Value = 20, 0);
|
||||
yield return ("amplitude-2-to-0", () => Create(), effect => effect.Amplitude.Values[0].Value = 0, 0);
|
||||
yield return ("amplitude-0-to-2", () => Create(effect => effect.Amplitude.Values[0].Value = 0), effect => effect.Amplitude.Values[0].Value = 2, 0);
|
||||
yield return ("scale-60-to-8", () => Create(), effect => effect.Scale.Values[0].Value = 8, 0);
|
||||
yield return ("hold-3-to-1-frame-4", () => Create(), effect => effect.HoldFrames = 1, 4);
|
||||
yield return ("seed-0-to-42", () => Create(), effect => effect.Seed = 42, 0);
|
||||
yield return ("edge-radius-12-to-64", () => Create(), effect => effect.EdgeRadius.Values[0].Value = 64, 0);
|
||||
yield return ("edge-focus-100-to-0", () => Create(), effect => effect.EdgeFocus.Values[0].Value = 0, 0);
|
||||
yield return ("edge-focus-0-to-100", () => Create(effect => effect.EdgeFocus.Values[0].Value = 0), effect => effect.EdgeFocus.Values[0].Value = 100, 0);
|
||||
}
|
||||
|
||||
public static IEnumerable<(string Name, DrawingWobbleEffect Effect)> Benchmarks()
|
||||
{
|
||||
yield return ("default", Create());
|
||||
yield return ("edge-focus-0", Create(effect => effect.EdgeFocus.Values[0].Value = 0));
|
||||
yield return ("edge-radius-64", Create(effect => effect.EdgeRadius.Values[0].Value = 64));
|
||||
yield return ("amplitude-20", Create(effect => effect.Amplitude.Values[0].Value = 20));
|
||||
}
|
||||
|
||||
static DrawingWobbleEffect Create(Action<DrawingWobbleEffect>? configure = null)
|
||||
{
|
||||
var effect = new DrawingWobbleEffect();
|
||||
configure?.Invoke(effect);
|
||||
return effect;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace DrawingWobble.Harness;
|
||||
|
||||
internal sealed record HarnessImage(int Width, int Height, byte[] Pixels, string Identity, string? Key)
|
||||
{
|
||||
public const int BytesPerPixel = 4;
|
||||
const int KeyLength = 16;
|
||||
|
||||
public static HarnessImage Synthetic(int width, int height)
|
||||
{
|
||||
var pixels = SyntheticImage.Create(width, height);
|
||||
return new HarnessImage(width, height, pixels, $"synthetic {width}x{height} {Convert.ToHexString(SHA256.HashData(pixels))[..KeyLength]}", null);
|
||||
}
|
||||
|
||||
public static HarnessImage Load(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
throw new HarnessException($"入力の画像がありません。{path}");
|
||||
|
||||
var bytes = File.ReadAllBytes(path);
|
||||
var (width, height, pixels) = Decode(bytes, path);
|
||||
var hash = Convert.ToHexString(SHA256.HashData(bytes));
|
||||
return new HarnessImage(width, height, pixels, $"{hash} {width}x{height}", hash[..KeyLength]);
|
||||
}
|
||||
|
||||
public static (int Width, int Height, byte[] Pixels) LoadPremultiplied(string path) => Decode(File.ReadAllBytes(path), path);
|
||||
|
||||
public static void Save(string path, byte[] pixels, int width, int height)
|
||||
{
|
||||
var source = BitmapSource.Create(width, height, 96, 96, PixelFormats.Pbgra32, null, pixels, width * BytesPerPixel);
|
||||
var encoder = new PngBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(source));
|
||||
using var stream = File.Create(path);
|
||||
encoder.Save(stream);
|
||||
}
|
||||
|
||||
static (int Width, int Height, byte[] Pixels) Decode(byte[] bytes, string path)
|
||||
{
|
||||
using var stream = new MemoryStream(bytes);
|
||||
BitmapDecoder decoder;
|
||||
try
|
||||
{
|
||||
decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
|
||||
}
|
||||
catch (Exception exception) when (exception is NotSupportedException or FileFormatException)
|
||||
{
|
||||
throw new HarnessException($"画像として読めません。{path}");
|
||||
}
|
||||
|
||||
var converted = new FormatConvertedBitmap(decoder.Frames[0], PixelFormats.Pbgra32, null, 0d);
|
||||
var pixels = new byte[converted.PixelWidth * converted.PixelHeight * BytesPerPixel];
|
||||
converted.CopyPixels(pixels, converted.PixelWidth * BytesPerPixel, 0);
|
||||
return (converted.PixelWidth, converted.PixelHeight, pixels);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
using System.Diagnostics;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using Vortice.DCommon;
|
||||
using Vortice.Direct2D1;
|
||||
using Vortice.Direct2D1.Effects;
|
||||
using Vortice.DXGI;
|
||||
using Vortice.Mathematics;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
using YukkuriMovieMaker.Player.Video;
|
||||
using YukkuriMovieMaker.Plugin.Effects;
|
||||
|
||||
namespace DrawingWobble.Harness;
|
||||
|
||||
internal sealed class HarnessRenderer : IDisposable
|
||||
{
|
||||
const int Fps = 30;
|
||||
const int Length = 300;
|
||||
const int WarmupUpdates = 2000;
|
||||
const int UpdateRepeats = 20;
|
||||
const float Dpi = 96f;
|
||||
|
||||
static readonly PixelFormat PixelFormat = new(Format.B8G8R8A8_UNorm, Vortice.DCommon.AlphaMode.Premultiplied);
|
||||
|
||||
readonly GraphicsDevices devices;
|
||||
readonly IGraphicsDevicesAndContext context;
|
||||
readonly ID2D1Bitmap1 image;
|
||||
readonly ID2D1Bitmap1 target;
|
||||
readonly ID2D1Bitmap1 readback;
|
||||
readonly ID2D1Bitmap1 sync;
|
||||
readonly GpuTimer timer;
|
||||
readonly AffineTransform2D placement;
|
||||
readonly ID2D1Image centered;
|
||||
|
||||
public HarnessRenderer(int canvasWidth, int canvasHeight, HarnessImage source)
|
||||
{
|
||||
CanvasWidth = canvasWidth;
|
||||
CanvasHeight = canvasHeight;
|
||||
|
||||
devices = new GraphicsDevices();
|
||||
context = devices.CreateContext();
|
||||
var deviceContext = context.DeviceContext;
|
||||
var adapter = devices.DXGI.Adapter;
|
||||
Adapter = adapter.Description.Description;
|
||||
Driver = adapter.CheckInterfaceSupport<IDXGIDevice>(out var version) ? FormatDriverVersion(version) : "不明";
|
||||
|
||||
image = CreateBitmap(deviceContext, source.Width, source.Height, BitmapOptions.None);
|
||||
image.CopyFromMemory(source.Pixels, source.Width * HarnessImage.BytesPerPixel);
|
||||
target = CreateBitmap(deviceContext, canvasWidth, canvasHeight, BitmapOptions.Target);
|
||||
readback = CreateBitmap(deviceContext, canvasWidth, canvasHeight, BitmapOptions.CpuRead | BitmapOptions.CannotDraw);
|
||||
sync = CreateBitmap(deviceContext, 1, 1, BitmapOptions.CpuRead | BitmapOptions.CannotDraw);
|
||||
timer = new GpuTimer(devices.D3D.Device, devices.D3D.DeviceContext);
|
||||
|
||||
placement = new AffineTransform2D(deviceContext)
|
||||
{
|
||||
TransformMatrix = Matrix3x2.CreateTranslation(-source.Width * 0.5f, -source.Height * 0.5f),
|
||||
};
|
||||
placement.SetInput(0, image, true);
|
||||
centered = placement.Output;
|
||||
}
|
||||
|
||||
public int CanvasWidth { get; }
|
||||
|
||||
public int CanvasHeight { get; }
|
||||
|
||||
public string Adapter { get; }
|
||||
|
||||
public string Driver { get; }
|
||||
|
||||
public byte[][] Render(IVideoEffect effect, IReadOnlyList<int> frames)
|
||||
{
|
||||
if (frames.Count == 0)
|
||||
throw new ArgumentException("フレームを 1 つ以上指定してください。", nameof(frames));
|
||||
|
||||
using var processor = effect.CreateVideoEffect(context);
|
||||
processor.SetInput(centered);
|
||||
try
|
||||
{
|
||||
var rendered = new byte[frames.Count][];
|
||||
for (var index = 0; index < frames.Count; index++)
|
||||
{
|
||||
processor.Update(Describe(frames[index]));
|
||||
rendered[index] = Capture(processor.Output);
|
||||
}
|
||||
|
||||
return rendered;
|
||||
}
|
||||
finally
|
||||
{
|
||||
processor.ClearInput();
|
||||
}
|
||||
}
|
||||
|
||||
public (byte[] Direct, byte[] Transitioned) RenderTransition<TEffect>(Func<TEffect> create, Action<TEffect> change, int frame)
|
||||
where TEffect : IVideoEffect
|
||||
{
|
||||
var settled = create();
|
||||
change(settled);
|
||||
var direct = Render(settled, [frame])[0];
|
||||
|
||||
var live = create();
|
||||
using var processor = live.CreateVideoEffect(context);
|
||||
processor.SetInput(centered);
|
||||
try
|
||||
{
|
||||
processor.Update(Describe(frame));
|
||||
_ = Capture(processor.Output);
|
||||
change(live);
|
||||
processor.Update(Describe(frame));
|
||||
return (direct, Capture(processor.Output));
|
||||
}
|
||||
finally
|
||||
{
|
||||
processor.ClearInput();
|
||||
}
|
||||
}
|
||||
|
||||
public Measurement Measure(IVideoEffect effect, int frames, bool moving)
|
||||
{
|
||||
var descriptions = new EffectDescription[frames];
|
||||
for (var frame = 0; frame < frames; frame++)
|
||||
descriptions[frame] = Describe(moving ? frame : 0);
|
||||
|
||||
using var processor = effect.CreateVideoEffect(context);
|
||||
processor.SetInput(centered);
|
||||
var output = processor.Output;
|
||||
try
|
||||
{
|
||||
for (var index = 0; index < WarmupUpdates; index++)
|
||||
processor.Update(descriptions[index % frames]);
|
||||
for (var frame = 0; frame < frames; frame++)
|
||||
{
|
||||
processor.Update(descriptions[frame]);
|
||||
Submit(output);
|
||||
}
|
||||
Synchronize();
|
||||
|
||||
var cpu = TimeSpan.MaxValue;
|
||||
for (var frame = 0; frame < frames; frame++)
|
||||
{
|
||||
var elapsed = Stopwatch.StartNew();
|
||||
processor.Update(descriptions[frame]);
|
||||
Submit(output);
|
||||
elapsed.Stop();
|
||||
cpu = elapsed.Elapsed < cpu ? elapsed.Elapsed : cpu;
|
||||
}
|
||||
Synchronize();
|
||||
|
||||
TimeSpan? gpu = null;
|
||||
for (var frame = 0; frame < frames; frame++)
|
||||
{
|
||||
processor.Update(descriptions[frame]);
|
||||
timer.Begin();
|
||||
Submit(output);
|
||||
timer.End();
|
||||
if (timer.Resolve() is { } resolved && (gpu is null || resolved < gpu))
|
||||
gpu = resolved;
|
||||
}
|
||||
Synchronize();
|
||||
|
||||
var repeats = frames * UpdateRepeats;
|
||||
var updates = Stopwatch.StartNew();
|
||||
for (var index = 0; index < repeats; index++)
|
||||
processor.Update(descriptions[index % frames]);
|
||||
updates.Stop();
|
||||
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
var before = GC.GetAllocatedBytesForCurrentThread();
|
||||
var collections = GC.CollectionCount(0);
|
||||
for (var frame = 0; frame < frames; frame++)
|
||||
processor.Update(descriptions[frame]);
|
||||
var allocated = (GC.GetAllocatedBytesForCurrentThread() - before) / frames;
|
||||
var gen0 = GC.CollectionCount(0) - collections;
|
||||
|
||||
return new Measurement(gpu, cpu, updates.Elapsed / repeats, allocated, gen0);
|
||||
}
|
||||
finally
|
||||
{
|
||||
processor.ClearInput();
|
||||
}
|
||||
}
|
||||
|
||||
byte[] Capture(ID2D1Image output)
|
||||
{
|
||||
Submit(output);
|
||||
readback.CopyFromBitmap(target);
|
||||
|
||||
var stride = CanvasWidth * HarnessImage.BytesPerPixel;
|
||||
var pixels = new byte[stride * CanvasHeight];
|
||||
var mapped = readback.Map(MapOptions.Read);
|
||||
try
|
||||
{
|
||||
for (var y = 0; y < CanvasHeight; y++)
|
||||
Marshal.Copy(mapped.Bits + y * (int)mapped.Pitch, pixels, y * stride, stride);
|
||||
}
|
||||
finally
|
||||
{
|
||||
readback.Unmap();
|
||||
}
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
void Submit(ID2D1Image output)
|
||||
{
|
||||
var deviceContext = context.DeviceContext;
|
||||
deviceContext.Target = target;
|
||||
deviceContext.BeginDraw();
|
||||
deviceContext.Clear(new Color4(0f, 0f, 0f, 0f));
|
||||
deviceContext.DrawImage(output, new Vector2(CanvasWidth * 0.5f, CanvasHeight * 0.5f), null, InterpolationMode.NearestNeighbor, CompositeMode.SourceOver);
|
||||
deviceContext.EndDraw();
|
||||
deviceContext.Target = null;
|
||||
}
|
||||
|
||||
void Synchronize()
|
||||
{
|
||||
sync.CopyFromBitmap(Int2.Zero, target, new RectI(0, 0, 1, 1));
|
||||
_ = sync.Map(MapOptions.Read);
|
||||
sync.Unmap();
|
||||
}
|
||||
|
||||
EffectDescription Describe(int frame)
|
||||
{
|
||||
var timeline = new TimelineSourceDescription(
|
||||
new System.Drawing.Size(CanvasWidth, CanvasHeight),
|
||||
new YukkuriMovieMaker.Player.Video.FrameTime(frame, Fps),
|
||||
new YukkuriMovieMaker.Player.Video.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);
|
||||
}
|
||||
|
||||
static ID2D1Bitmap1 CreateBitmap(ID2D1DeviceContext6 deviceContext, int width, int height, BitmapOptions options)
|
||||
=> deviceContext.CreateBitmap(
|
||||
new SizeI(width, height), nint.Zero, width * HarnessImage.BytesPerPixel,
|
||||
new BitmapProperties1(PixelFormat, Dpi, Dpi, options));
|
||||
|
||||
static string FormatDriverVersion(long version)
|
||||
=> $"{(version >> 48) & 0xFFFF}.{(version >> 32) & 0xFFFF}.{(version >> 16) & 0xFFFF}.{version & 0xFFFF}";
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
placement.SetInput(0, null, true);
|
||||
centered.Dispose();
|
||||
placement.Dispose();
|
||||
timer.Dispose();
|
||||
sync.Dispose();
|
||||
readback.Dispose();
|
||||
target.Dispose();
|
||||
image.Dispose();
|
||||
context.Dispose();
|
||||
devices.Dispose();
|
||||
}
|
||||
|
||||
public readonly record struct Measurement(TimeSpan? Gpu, TimeSpan Cpu, TimeSpan Update, long Allocated, int Gen0);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DrawingWobble.Harness;
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
namespace DrawingWobble.Harness;
|
||||
|
||||
internal readonly record struct ImageDifference(int Differing, int MaxDelta, int Left, int Top, int Right, int Bottom)
|
||||
{
|
||||
public bool IsEmpty => Differing == 0;
|
||||
|
||||
public override string ToString()
|
||||
=> IsEmpty ? "一致" : $"differing={Differing} maxDelta={MaxDelta} box=({Left},{Top})-({Right},{Bottom})";
|
||||
}
|
||||
|
||||
internal static class ImageComparison
|
||||
{
|
||||
public static ImageDifference Of(byte[] first, byte[] second, int width, int height)
|
||||
{
|
||||
if (first.Length != second.Length || first.Length != width * height * HarnessImage.BytesPerPixel)
|
||||
throw new ArgumentException("画像の寸法が一致しません。");
|
||||
|
||||
var differing = 0;
|
||||
var maxDelta = 0;
|
||||
var left = width;
|
||||
var top = height;
|
||||
var right = -1;
|
||||
var bottom = -1;
|
||||
for (var y = 0; y < height; y++)
|
||||
{
|
||||
for (var x = 0; x < width; x++)
|
||||
{
|
||||
var offset = (y * width + x) * HarnessImage.BytesPerPixel;
|
||||
var delta = 0;
|
||||
for (var channel = 0; channel < HarnessImage.BytesPerPixel; channel++)
|
||||
delta = Math.Max(delta, Math.Abs(first[offset + channel] - second[offset + channel]));
|
||||
if (delta == 0)
|
||||
continue;
|
||||
|
||||
differing++;
|
||||
maxDelta = Math.Max(maxDelta, delta);
|
||||
left = Math.Min(left, x);
|
||||
top = Math.Min(top, y);
|
||||
right = Math.Max(right, x);
|
||||
bottom = Math.Max(bottom, y);
|
||||
}
|
||||
}
|
||||
|
||||
return differing == 0 ? default : new ImageDifference(differing, maxDelta, left, top, right, bottom);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,328 @@
|
||||
using System.IO;
|
||||
using System.IO.Packaging;
|
||||
using System.Security.Cryptography;
|
||||
using DrawingWobble.Harness;
|
||||
using SharpGen.Runtime;
|
||||
|
||||
const int CanvasWidth = 1280;
|
||||
const int CanvasHeight = 720;
|
||||
const int ImageWidth = 640;
|
||||
const int ImageHeight = 480;
|
||||
const int FullHdWidth = 1920;
|
||||
const int FullHdHeight = 1080;
|
||||
|
||||
_ = PackUriHelper.UriSchemePack;
|
||||
|
||||
HarnessArguments arguments;
|
||||
try
|
||||
{
|
||||
arguments = HarnessArguments.Parse(args);
|
||||
}
|
||||
catch (HarnessException exception)
|
||||
{
|
||||
Console.Error.WriteLine(exception.Message);
|
||||
Console.Error.WriteLine(HarnessArguments.Usage);
|
||||
return 2;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (arguments.Mode == HarnessMode.Compare)
|
||||
return Compare(arguments.Before!, arguments.After!);
|
||||
|
||||
var outputDirectory = arguments.OutputDirectory ?? Path.Combine(AppContext.BaseDirectory, "harness-output");
|
||||
if (arguments.Mode == HarnessMode.Benchmark)
|
||||
{
|
||||
if (arguments.Input is { } benchmarkInput)
|
||||
{
|
||||
Benchmark(HarnessImage.Load(benchmarkInput));
|
||||
}
|
||||
else
|
||||
{
|
||||
Benchmark(HarnessImage.Synthetic(CanvasWidth, CanvasHeight));
|
||||
Benchmark(HarnessImage.Synthetic(FullHdWidth, FullHdHeight));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
var image = arguments.Input is { } input ? HarnessImage.Load(input) : HarnessImage.Synthetic(ImageWidth, ImageHeight);
|
||||
using var renderer = new HarnessRenderer(CanvasWidth, CanvasHeight, image);
|
||||
return arguments.Mode switch
|
||||
{
|
||||
HarnessMode.Golden => WriteGolden(renderer, image),
|
||||
HarnessMode.Verify => Verify(renderer, image),
|
||||
HarnessMode.Transition => Transition(renderer, outputDirectory),
|
||||
_ => Render(renderer, outputDirectory),
|
||||
};
|
||||
}
|
||||
catch (Exception exception) when (exception is HarnessException or SharpGenException)
|
||||
{
|
||||
Console.Error.WriteLine(exception.Message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int Render(HarnessRenderer renderer, string outputDirectory)
|
||||
{
|
||||
Directory.CreateDirectory(outputDirectory);
|
||||
var failures = 0;
|
||||
var cases = Evaluate(renderer, (golden, files, frames) =>
|
||||
{
|
||||
Console.WriteLine($"{golden.Name}: {golden.Hash}");
|
||||
for (var index = 0; index < files.Length; index++)
|
||||
{
|
||||
HarnessImage.Save(Path.Combine(outputDirectory, files[index]), frames[index], renderer.CanvasWidth, renderer.CanvasHeight);
|
||||
var opaque = CountOpaque(frames[index]);
|
||||
Console.WriteLine($" {files[index]} opaque={opaque}");
|
||||
if (opaque == 0)
|
||||
{
|
||||
Console.Error.WriteLine($"{files[index]}: 出力が完全に透明です。");
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
});
|
||||
Console.WriteLine($"-> {outputDirectory}");
|
||||
return failures + CountDuplicates(cases) == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
static int WriteGolden(HarnessRenderer renderer, HarnessImage image)
|
||||
{
|
||||
var cases = Evaluate(renderer, null);
|
||||
if (CountDuplicates(cases) != 0)
|
||||
return 1;
|
||||
if (cases.Count == 0)
|
||||
Console.Error.WriteLine("ケースがありません。HarnessCases に書き足してください。");
|
||||
|
||||
var golden = new Golden(renderer.Adapter, renderer.Driver, image.Identity, $"{renderer.CanvasWidth}x{renderer.CanvasHeight}", cases);
|
||||
var path = Golden.PathFor(image);
|
||||
golden.Save(path);
|
||||
Console.WriteLine($"adapter: {golden.Adapter} (driver {golden.Driver})");
|
||||
Console.WriteLine($"input: {golden.Input}");
|
||||
foreach (var (name, _, hash) in cases)
|
||||
Console.WriteLine($"{name}: {hash}");
|
||||
Console.WriteLine($"-> {path}");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Verify(HarnessRenderer renderer, HarnessImage image)
|
||||
{
|
||||
var golden = Golden.Load(Golden.PathFor(image));
|
||||
var canvas = $"{renderer.CanvasWidth}x{renderer.CanvasHeight}";
|
||||
if (golden.Input != image.Identity || golden.Canvas != canvas)
|
||||
{
|
||||
Console.Error.WriteLine($"基準値は入力 {golden.Input} とキャンバス {golden.Canvas} で書かれています。今回は入力 {image.Identity} とキャンバス {canvas} です。");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (golden.Adapter != renderer.Adapter || golden.Driver != renderer.Driver)
|
||||
Console.Error.WriteLine($"基準値は {golden.Adapter} (driver {golden.Driver}) で書かれています。今回は {renderer.Adapter} (driver {renderer.Driver}) です。画素の差はこの違いから来ることがあります。");
|
||||
|
||||
var failures = 0;
|
||||
var current = Evaluate(renderer, null).ToDictionary(item => item.Name, StringComparer.Ordinal);
|
||||
if (golden.Cases.Count == 0 && current.Count == 0)
|
||||
Console.Error.WriteLine("ケースがありません。HarnessCases に書き足してください。");
|
||||
foreach (var (name, frames, hash) in golden.Cases)
|
||||
{
|
||||
if (!current.Remove(name, out var actual))
|
||||
{
|
||||
Console.Error.WriteLine($"{name}: ケースがありません。基準値を書き直してください。");
|
||||
failures++;
|
||||
}
|
||||
else if (!actual.Frames.SequenceEqual(frames))
|
||||
{
|
||||
Console.Error.WriteLine($"{name}: フレームが違います。基準値 [{string.Join(", ", frames)}]、今回 [{string.Join(", ", actual.Frames)}]。基準値を書き直してください。");
|
||||
failures++;
|
||||
}
|
||||
else if (actual.Hash != hash)
|
||||
{
|
||||
Console.Error.WriteLine($"{name}: 一致しません。基準値 {hash}、今回 {actual.Hash}");
|
||||
failures++;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{name}: 一致");
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var name in current.Keys)
|
||||
{
|
||||
Console.Error.WriteLine($"{name}: 基準値にありません。基準値を書き直してください。");
|
||||
failures++;
|
||||
}
|
||||
|
||||
return failures == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
static int Transition(HarnessRenderer renderer, string outputDirectory)
|
||||
{
|
||||
var failures = 0;
|
||||
foreach (var (name, create, change, frame) in HarnessCases.Transitions())
|
||||
{
|
||||
var (direct, transitioned) = renderer.RenderTransition(create, change, frame);
|
||||
var difference = ImageComparison.Of(direct, transitioned, renderer.CanvasWidth, renderer.CanvasHeight);
|
||||
if (difference.IsEmpty)
|
||||
{
|
||||
Console.WriteLine($"{name}: 一致");
|
||||
continue;
|
||||
}
|
||||
|
||||
failures++;
|
||||
Directory.CreateDirectory(outputDirectory);
|
||||
HarnessImage.Save(Path.Combine(outputDirectory, name + "-direct.png"), direct, renderer.CanvasWidth, renderer.CanvasHeight);
|
||||
HarnessImage.Save(Path.Combine(outputDirectory, name + "-transitioned.png"), transitioned, renderer.CanvasWidth, renderer.CanvasHeight);
|
||||
Console.Error.WriteLine($"{name}: {difference}。設定を変えた後の描画が作り直した場合と違います。-> {outputDirectory}");
|
||||
}
|
||||
|
||||
if (!HarnessCases.Transitions().Any() && !HarnessCases.All().Any(item => item.Frames.Count > 1))
|
||||
Console.Error.WriteLine("ケースがありません。HarnessCases に書き足してください。");
|
||||
|
||||
foreach (var (name, effect, frames) in HarnessCases.All())
|
||||
{
|
||||
if (frames.Count < 2)
|
||||
continue;
|
||||
|
||||
var sequential = renderer.Render(effect, frames);
|
||||
for (var index = 0; index < frames.Count; index++)
|
||||
{
|
||||
var fresh = renderer.Render(effect, [frames[index]])[0];
|
||||
var difference = ImageComparison.Of(fresh, sequential[index], renderer.CanvasWidth, renderer.CanvasHeight);
|
||||
var label = $"{name}-f{frames[index]:D3}";
|
||||
if (difference.IsEmpty)
|
||||
{
|
||||
Console.WriteLine($"{label}: 一致");
|
||||
continue;
|
||||
}
|
||||
|
||||
failures++;
|
||||
Directory.CreateDirectory(outputDirectory);
|
||||
HarnessImage.Save(Path.Combine(outputDirectory, label + "-direct.png"), fresh, renderer.CanvasWidth, renderer.CanvasHeight);
|
||||
HarnessImage.Save(Path.Combine(outputDirectory, label + "-transitioned.png"), sequential[index], renderer.CanvasWidth, renderer.CanvasHeight);
|
||||
Console.Error.WriteLine($"{label}: {difference}。前のフレームから進めた描画が作り直した場合と違います。-> {outputDirectory}");
|
||||
}
|
||||
}
|
||||
|
||||
return failures == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
static int Compare(string beforeDirectory, string afterDirectory)
|
||||
{
|
||||
if (!Directory.Exists(beforeDirectory) || !Directory.Exists(afterDirectory))
|
||||
throw new HarnessException("比べる出力先がありません。");
|
||||
|
||||
var failures = 0;
|
||||
var names = Directory.EnumerateFiles(beforeDirectory, "*.png")
|
||||
.Concat(Directory.EnumerateFiles(afterDirectory, "*.png"))
|
||||
.Select(path => Path.GetFileName(path))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.Order(StringComparer.OrdinalIgnoreCase)
|
||||
.ToArray();
|
||||
if (names.Length == 0)
|
||||
throw new HarnessException("比べる PNG がありません。");
|
||||
|
||||
foreach (var name in names)
|
||||
{
|
||||
var before = Path.Combine(beforeDirectory, name);
|
||||
var after = Path.Combine(afterDirectory, name);
|
||||
if (!File.Exists(before) || !File.Exists(after))
|
||||
{
|
||||
Console.Error.WriteLine($"{name}: {(File.Exists(before) ? "後" : "前")}にありません。");
|
||||
failures++;
|
||||
continue;
|
||||
}
|
||||
|
||||
var (beforeWidth, beforeHeight, beforePixels) = HarnessImage.LoadPremultiplied(before);
|
||||
var (afterWidth, afterHeight, afterPixels) = HarnessImage.LoadPremultiplied(after);
|
||||
if (beforeWidth != afterWidth || beforeHeight != afterHeight)
|
||||
{
|
||||
Console.Error.WriteLine($"{name}: 寸法が違います。前 {beforeWidth}x{beforeHeight}、後 {afterWidth}x{afterHeight}");
|
||||
failures++;
|
||||
continue;
|
||||
}
|
||||
|
||||
var difference = ImageComparison.Of(beforePixels, afterPixels, beforeWidth, beforeHeight);
|
||||
Console.WriteLine($"{name}: {difference}");
|
||||
if (!difference.IsEmpty)
|
||||
failures++;
|
||||
}
|
||||
|
||||
return failures == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
static void Benchmark(HarnessImage image)
|
||||
{
|
||||
const int Frames = 60;
|
||||
|
||||
using var renderer = new HarnessRenderer(image.Width, image.Height, image);
|
||||
Console.WriteLine($"adapter: {renderer.Adapter} (driver {renderer.Driver})");
|
||||
foreach (var (name, effect) in HarnessCases.Benchmarks())
|
||||
{
|
||||
Report(image, name, "still", renderer.Measure(effect, Frames, moving: false));
|
||||
Report(image, name, "moving", renderer.Measure(effect, Frames, moving: true));
|
||||
}
|
||||
}
|
||||
|
||||
static void Report(HarnessImage image, string name, string motion, HarnessRenderer.Measurement measurement)
|
||||
=> Console.WriteLine(
|
||||
$"{image.Width}x{image.Height} {name,-15} {motion,-6} " +
|
||||
$"gpu={(measurement.Gpu is { } gpu ? gpu.TotalMilliseconds.ToString("F3") : "n/a"),7} " +
|
||||
$"cpu={measurement.Cpu.TotalMilliseconds,7:F3} " +
|
||||
$"update={measurement.Update.TotalMilliseconds,6:F3} " +
|
||||
$"alloc={measurement.Allocated,6} gen0={measurement.Gen0}");
|
||||
|
||||
static List<GoldenCase> Evaluate(HarnessRenderer renderer, Action<GoldenCase, string[], byte[][]>? report)
|
||||
{
|
||||
var cases = new List<GoldenCase>();
|
||||
var names = new HashSet<string>(StringComparer.Ordinal);
|
||||
foreach (var (name, effect, frames) in HarnessCases.All())
|
||||
{
|
||||
if (!names.Add(name))
|
||||
throw new HarnessException($"ケース名が重複しています。{name}");
|
||||
|
||||
var rendered = renderer.Render(effect, frames);
|
||||
var files = new string[frames.Count];
|
||||
using var hash = IncrementalHash.CreateHash(HashAlgorithmName.SHA256);
|
||||
for (var index = 0; index < frames.Count; index++)
|
||||
{
|
||||
hash.AppendData(rendered[index]);
|
||||
files[index] = frames.Count == 1 ? name + ".png" : $"{name}-f{frames[index]:D3}.png";
|
||||
}
|
||||
|
||||
var golden = new GoldenCase(name, frames, Convert.ToHexString(hash.GetHashAndReset()));
|
||||
cases.Add(golden);
|
||||
report?.Invoke(golden, files, rendered);
|
||||
}
|
||||
|
||||
return cases;
|
||||
}
|
||||
|
||||
static int CountDuplicates(IReadOnlyList<GoldenCase> cases)
|
||||
{
|
||||
var duplicates = 0;
|
||||
var seen = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
foreach (var (name, _, hash) in cases)
|
||||
{
|
||||
if (seen.TryGetValue(hash, out var first))
|
||||
{
|
||||
Console.Error.WriteLine($"{name}: {first} と出力が一致します。設定がシェーダーへ届いていません。");
|
||||
duplicates++;
|
||||
}
|
||||
else
|
||||
{
|
||||
seen.Add(hash, name);
|
||||
}
|
||||
}
|
||||
|
||||
return duplicates;
|
||||
}
|
||||
|
||||
static int CountOpaque(byte[] pixels)
|
||||
{
|
||||
var count = 0;
|
||||
for (var offset = HarnessImage.BytesPerPixel - 1; offset < pixels.Length; offset += HarnessImage.BytesPerPixel)
|
||||
{
|
||||
if (pixels[offset] != 0)
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
namespace DrawingWobble.Harness;
|
||||
|
||||
internal static class SyntheticImage
|
||||
{
|
||||
const int GridPitch = 32;
|
||||
|
||||
public static byte[] Create(int width, int height)
|
||||
{
|
||||
var pixels = new byte[width * height * HarnessImage.BytesPerPixel];
|
||||
var plateLeft = width * 0.10f;
|
||||
var plateRight = width * 0.56f;
|
||||
var plateTop = height * 0.14f;
|
||||
var plateBottom = height * 0.86f;
|
||||
var discCenterX = width * 0.70f;
|
||||
var discCenterY = height * 0.50f;
|
||||
var discRadius = MathF.Min(width, height) * 0.28f;
|
||||
|
||||
for (var y = 0; y < height; y++)
|
||||
{
|
||||
for (var x = 0; x < width; x++)
|
||||
{
|
||||
var positionX = x + 0.5f;
|
||||
var positionY = y + 0.5f;
|
||||
var plateInset = MathF.Min(MathF.Min(positionX - plateLeft, plateRight - positionX), MathF.Min(positionY - plateTop, plateBottom - positionY));
|
||||
var plateCoverage = Math.Clamp(plateInset + 0.5f, 0f, 1f);
|
||||
var distance = MathF.Sqrt((positionX - discCenterX) * (positionX - discCenterX) + (positionY - discCenterY) * (positionY - discCenterY));
|
||||
var discCoverage = Math.Clamp(discRadius - distance + 0.5f, 0f, 1f);
|
||||
if (plateCoverage == 0f && discCoverage == 0f)
|
||||
continue;
|
||||
|
||||
var onGrid = x % GridPitch == 0 || y % GridPitch == 0;
|
||||
var plateWeight = plateCoverage * (1f - discCoverage);
|
||||
var shade = 1f - distance / discRadius * 0.5f;
|
||||
var red = (onGrid ? 0.25f : 0.82f) * plateWeight + 0.90f * shade * discCoverage;
|
||||
var green = (onGrid ? 0.30f : 0.86f) * plateWeight + 0.45f * shade * discCoverage;
|
||||
var blue = (onGrid ? 0.40f : 0.90f) * plateWeight + 0.30f * shade * discCoverage;
|
||||
var alpha = plateWeight + discCoverage;
|
||||
|
||||
var offset = (y * width + x) * HarnessImage.BytesPerPixel;
|
||||
pixels[offset] = ToByte(blue);
|
||||
pixels[offset + 1] = ToByte(green);
|
||||
pixels[offset + 2] = ToByte(red);
|
||||
pixels[offset + 3] = ToByte(alpha);
|
||||
}
|
||||
}
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
static byte ToByte(float premultiplied) => (byte)MathF.Round(Math.Clamp(premultiplied, 0f, 1f) * byte.MaxValue);
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
{
|
||||
"adapter": "Intel(R) Iris(R) Xe Graphics",
|
||||
"driver": "32.0.101.7085",
|
||||
"input": "synthetic 640x480 89838D8976198E40",
|
||||
"canvas": "1280x720",
|
||||
"cases": [
|
||||
{
|
||||
"name": "default",
|
||||
"frames": [
|
||||
0
|
||||
],
|
||||
"hash": "B114CDA3AAA725A6BFD389A4B6E930A3CA814398A71355134E861E554A9104A3"
|
||||
},
|
||||
{
|
||||
"name": "default-frame-4",
|
||||
"frames": [
|
||||
4
|
||||
],
|
||||
"hash": "55BA14A2931CE4F3539A45687656DAACBFE2F475BC86ABE6FC30B718D47762E8"
|
||||
},
|
||||
{
|
||||
"name": "default-frames-0-8",
|
||||
"frames": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8
|
||||
],
|
||||
"hash": "E130A44C982973ADCA3640F37659B26610AE85CBDFC8C9F344DDE80E99EFC8FB"
|
||||
},
|
||||
{
|
||||
"name": "amplitude-0",
|
||||
"frames": [
|
||||
0
|
||||
],
|
||||
"hash": "0A700F76CEDDBAD7C4B6A2C19D46939C1A93940E86C6EFEF1E5A53DB48D2A020"
|
||||
},
|
||||
{
|
||||
"name": "amplitude-20",
|
||||
"frames": [
|
||||
0
|
||||
],
|
||||
"hash": "7040B3DAEB12E4EEF1AB19A8936D6EB09CBD9A943B497D6A9440DE4E66782BE3"
|
||||
},
|
||||
{
|
||||
"name": "scale-8",
|
||||
"frames": [
|
||||
0
|
||||
],
|
||||
"hash": "BFC5FD0B99BE0E0BC56A846A866E462F90F34A0C05E81B8BD8BCEB304D9FA43E"
|
||||
},
|
||||
{
|
||||
"name": "scale-400",
|
||||
"frames": [
|
||||
0
|
||||
],
|
||||
"hash": "93C4A79D19DB49EF88626FC1110681636DDA3579920D0CA5345FD15B77862D7C"
|
||||
},
|
||||
{
|
||||
"name": "hold-1-frame-2",
|
||||
"frames": [
|
||||
2
|
||||
],
|
||||
"hash": "5E9375ADE4349AAE6AEE7DEEF71FBCD49DBBD923FE06EF0094D75F6E2DDD4086"
|
||||
},
|
||||
{
|
||||
"name": "hold-1-frames-0-3",
|
||||
"frames": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3
|
||||
],
|
||||
"hash": "464A0C1FC4D9B902470B94CA94C008AF0F685D075A2B8FC3C4AA8A359282EBD8"
|
||||
},
|
||||
{
|
||||
"name": "seed-42",
|
||||
"frames": [
|
||||
0
|
||||
],
|
||||
"hash": "D8A147024D3769FF81029CDF05B8FF84D6360EA3C0B5056467DCC72A2F404ADD"
|
||||
},
|
||||
{
|
||||
"name": "edge-radius-64",
|
||||
"frames": [
|
||||
0
|
||||
],
|
||||
"hash": "FD2FB0945F0529DBC99092BFAF94385BCB289274525551B4653345AFF1A9C2DB"
|
||||
},
|
||||
{
|
||||
"name": "edge-focus-0",
|
||||
"frames": [
|
||||
0
|
||||
],
|
||||
"hash": "8A819BAD91F27CADE9CC50BD6C3255E14726FE2EACA0EE2C43715D676C901593"
|
||||
},
|
||||
{
|
||||
"name": "edge-focus-50",
|
||||
"frames": [
|
||||
0
|
||||
],
|
||||
"hash": "F4D065624C17E56CCD095D658912DFE3E52FE1324E58B3441F360D953DDE8686"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace DrawingWobble.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);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<AssemblyName>DrawingWobble.Tests</AssemblyName>
|
||||
<RootNamespace>DrawingWobble.Tests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="10.0.1">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<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="..\DrawingWobble\DrawingWobble.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="Vortice.Direct2D1">
|
||||
<HintPath>$(YMM4DirPath)Vortice.Direct2D1.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>
|
||||
<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>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,229 @@
|
||||
using System.Numerics;
|
||||
using Vortice.Direct2D1;
|
||||
using Vortice.Direct2D1.Effects;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
using static DrawingWobble.DrawingWobbleCustomEffect;
|
||||
|
||||
namespace DrawingWobble.Tests;
|
||||
|
||||
[Collection("Direct2D")]
|
||||
public sealed class DrawingWobbleCustomEffectTests
|
||||
{
|
||||
const float MaxInputPixel = 4096f;
|
||||
|
||||
static float Read(DrawingWobbleCustomEffect effect, PropertyIndex index) => effect.GetFloatValue((int)index);
|
||||
|
||||
[Fact]
|
||||
public void TheEffectIsEnabledOnceCreated()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var effect = new DrawingWobbleCustomEffect(context);
|
||||
|
||||
Assert.True(effect.IsEnabled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ThePropertiesStartFromTheirDefaults()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var effect = new DrawingWobbleCustomEffect(context);
|
||||
|
||||
Assert.Equal(0f, Read(effect, PropertyIndex.Amplitude));
|
||||
Assert.Equal(1f, Read(effect, PropertyIndex.Scale));
|
||||
Assert.Equal(0f, Read(effect, PropertyIndex.EdgeRadius));
|
||||
Assert.Equal(0f, Read(effect, PropertyIndex.EdgeFocus));
|
||||
Assert.Equal(0, effect.GetIntValue((int)PropertyIndex.HoldIndex));
|
||||
Assert.Equal(0, effect.GetIntValue((int)PropertyIndex.Seed));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1f, 0f)]
|
||||
[InlineData(0f, 0f)]
|
||||
[InlineData(2.5f, 2.5f)]
|
||||
[InlineData(MaxInputPixel, MaxInputPixel)]
|
||||
[InlineData(MaxInputPixel + 1f, MaxInputPixel)]
|
||||
[InlineData(float.MaxValue, MaxInputPixel)]
|
||||
public void AmplitudeIsClampedToTheInputPixelRange(float value, float expected)
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var effect = new DrawingWobbleCustomEffect(context);
|
||||
|
||||
effect.Amplitude = value;
|
||||
|
||||
Assert.Equal(expected, Read(effect, PropertyIndex.Amplitude));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1f, 0f)]
|
||||
[InlineData(12f, 12f)]
|
||||
[InlineData(MaxInputPixel + 1f, MaxInputPixel)]
|
||||
public void EdgeRadiusIsClampedToTheInputPixelRange(float value, float expected)
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var effect = new DrawingWobbleCustomEffect(context);
|
||||
|
||||
effect.EdgeRadius = value;
|
||||
|
||||
Assert.Equal(expected, Read(effect, PropertyIndex.EdgeRadius));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-5f, 1f)]
|
||||
[InlineData(0f, 1f)]
|
||||
[InlineData(0.5f, 1f)]
|
||||
[InlineData(1f, 1f)]
|
||||
[InlineData(60f, 60f)]
|
||||
[InlineData(float.MaxValue, float.MaxValue)]
|
||||
public void ScaleNeverDropsBelowOnePixel(float value, float expected)
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var effect = new DrawingWobbleCustomEffect(context);
|
||||
|
||||
effect.Scale = value;
|
||||
|
||||
Assert.Equal(expected, Read(effect, PropertyIndex.Scale));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-0.5f, 0f)]
|
||||
[InlineData(0f, 0f)]
|
||||
[InlineData(0.25f, 0.25f)]
|
||||
[InlineData(1f, 1f)]
|
||||
[InlineData(1.5f, 1f)]
|
||||
public void EdgeFocusIsClampedToTheUnitRange(float value, float expected)
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var effect = new DrawingWobbleCustomEffect(context);
|
||||
|
||||
effect.EdgeFocus = value;
|
||||
|
||||
Assert.Equal(expected, Read(effect, PropertyIndex.EdgeFocus));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(int.MinValue)]
|
||||
[InlineData(-1)]
|
||||
[InlineData(0)]
|
||||
[InlineData(7)]
|
||||
[InlineData(int.MaxValue)]
|
||||
public void HoldIndexAndSeedAreStoredWithoutClamping(int value)
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var effect = new DrawingWobbleCustomEffect(context);
|
||||
|
||||
effect.HoldIndex = value;
|
||||
effect.Seed = value;
|
||||
|
||||
Assert.Equal(value, effect.GetIntValue((int)PropertyIndex.HoldIndex));
|
||||
Assert.Equal(value, effect.GetIntValue((int)PropertyIndex.Seed));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithoutAmplitudeTheOutputBoundsEqualTheInput()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = SourceImage.Solid(context, 40, 24, Bgra.Opaque(10, 20, 30));
|
||||
using var effect = new DrawingWobbleCustomEffect(context);
|
||||
effect.SetInput(0, source.Bitmap, true);
|
||||
effect.EdgeRadius = 64f;
|
||||
effect.EdgeFocus = 1f;
|
||||
using var output = effect.Output;
|
||||
|
||||
var bounds = context.DeviceContext.GetImageLocalBounds(output);
|
||||
|
||||
Assert.Equal(0f, bounds.Left);
|
||||
Assert.Equal(0f, bounds.Top);
|
||||
Assert.Equal(40f, bounds.Right);
|
||||
Assert.Equal(24f, bounds.Bottom);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.5f, 3f)]
|
||||
[InlineData(1f, 3f)]
|
||||
[InlineData(2f, 4f)]
|
||||
[InlineData(2.01f, 5f)]
|
||||
[InlineData(20f, 22f)]
|
||||
public void TheOutputBoundsGrowByTheRoundedUpAmplitudePlusTwoPixels(float amplitude, float margin)
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = SourceImage.Solid(context, 40, 24, Bgra.Opaque(10, 20, 30));
|
||||
using var effect = new DrawingWobbleCustomEffect(context);
|
||||
effect.SetInput(0, source.Bitmap, true);
|
||||
effect.Amplitude = amplitude;
|
||||
using var output = effect.Output;
|
||||
|
||||
var bounds = context.DeviceContext.GetImageLocalBounds(output);
|
||||
|
||||
Assert.Equal(-margin, bounds.Left);
|
||||
Assert.Equal(-margin, bounds.Top);
|
||||
Assert.Equal(40f + margin, bounds.Right);
|
||||
Assert.Equal(24f + margin, bounds.Bottom);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheOutputMarginIgnoresTheEdgeRadius()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = SourceImage.Solid(context, 40, 24, Bgra.Opaque(10, 20, 30));
|
||||
using var effect = new DrawingWobbleCustomEffect(context);
|
||||
effect.SetInput(0, source.Bitmap, true);
|
||||
effect.Amplitude = 2f;
|
||||
effect.EdgeRadius = 64f;
|
||||
effect.EdgeFocus = 1f;
|
||||
using var output = effect.Output;
|
||||
|
||||
var bounds = context.DeviceContext.GetImageLocalBounds(output);
|
||||
|
||||
Assert.Equal(-4f, bounds.Left);
|
||||
Assert.Equal(44f, bounds.Right);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(10f, 5f, 10f, 20f)]
|
||||
[InlineData(10f, 5f, 30f, 5f)]
|
||||
[InlineData(10f, 5f, 10f, 5f)]
|
||||
public void AnEmptyInputStaysEmpty(float left, float top, float right, float bottom)
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = SourceImage.Solid(context, 40, 24, Bgra.Opaque(10, 20, 30));
|
||||
using var crop = new Crop(context.DeviceContext) { Rectangle = new Vector4(left, top, right, bottom) };
|
||||
crop.SetInput(0, source.Bitmap, true);
|
||||
using var cropped = crop.Output;
|
||||
using var effect = new DrawingWobbleCustomEffect(context);
|
||||
effect.SetInput(0, cropped, true);
|
||||
effect.Amplitude = 3f;
|
||||
using var output = effect.Output;
|
||||
|
||||
var bounds = context.DeviceContext.GetImageLocalBounds(output);
|
||||
|
||||
Assert.True(bounds.Right <= bounds.Left || bounds.Bottom <= bounds.Top, $"{bounds}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheOutputMarginIsCappedAtTheInputPixelLimit()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = SourceImage.Solid(context, 8, 8, Bgra.Opaque(10, 20, 30));
|
||||
using var effect = new DrawingWobbleCustomEffect(context);
|
||||
effect.SetInput(0, source.Bitmap, true);
|
||||
effect.Amplitude = MaxInputPixel;
|
||||
using var output = effect.Output;
|
||||
|
||||
var bounds = context.DeviceContext.GetImageLocalBounds(output);
|
||||
|
||||
Assert.Equal(-MaxInputPixel, bounds.Left);
|
||||
Assert.Equal(8f + MaxInputPixel, bounds.Right);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
using System.Globalization;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
using YukkuriMovieMaker.Json;
|
||||
using YukkuriMovieMaker.Player.Video;
|
||||
|
||||
namespace DrawingWobble.Tests;
|
||||
|
||||
[Collection("Direct2D")]
|
||||
public sealed class DrawingWobbleEffectProcessorTests
|
||||
{
|
||||
const int Width = 64;
|
||||
const int Height = 32;
|
||||
const int Length = 30;
|
||||
|
||||
static readonly Bgra Red = Bgra.Opaque(0, 0, 255);
|
||||
static readonly Bgra Blue = Bgra.Opaque(255, 0, 0);
|
||||
|
||||
static Bgra TwoHalves(int x, int y) => x < Width / 2 ? Red : Blue;
|
||||
|
||||
static Bgra Gradient(int x, int y) => Bgra.Opaque((byte)(x * 4), (byte)(x * 4), (byte)(x * 4));
|
||||
|
||||
static DrawingWobbleEffect Uniform(double amplitude, int holdFrames = 3)
|
||||
{
|
||||
var effect = new DrawingWobbleEffect { HoldFrames = holdFrames };
|
||||
effect.Amplitude.Values[0].Value = amplitude;
|
||||
effect.EdgeFocus.Values[0].Value = 0d;
|
||||
return effect;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheProcessorHandsTheDrawDescriptionBackUnchanged()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, TwoHalves);
|
||||
using var processor = Uniform(3d).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 WithoutAmplitudeTheProcessorPassesTheImageThrough()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, TwoHalves);
|
||||
using var processor = Uniform(0d).CreateVideoEffect(context);
|
||||
processor.SetInput(source.Bitmap);
|
||||
|
||||
var rendering = RenderFrame(context, processor, 0);
|
||||
|
||||
Assert.Equal((0, 0, Width, 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]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheWobbleHoldsForTheConfiguredFramesThenMoves()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, TwoHalves);
|
||||
using var processor = Uniform(3d, holdFrames: 3).CreateVideoEffect(context);
|
||||
processor.SetInput(source.Bitmap);
|
||||
|
||||
var frames = Enumerable.Range(0, 7).Select(frame => RenderFrame(context, processor, frame)).ToArray();
|
||||
|
||||
Assert.True(frames[0].SamePixelsAs(frames[1]));
|
||||
Assert.True(frames[1].SamePixelsAs(frames[2]));
|
||||
Assert.False(frames[2].SamePixelsAs(frames[3]));
|
||||
Assert.True(frames[3].SamePixelsAs(frames[4]));
|
||||
Assert.True(frames[4].SamePixelsAs(frames[5]));
|
||||
Assert.False(frames[5].SamePixelsAs(frames[6]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AHoldOfOneFrameMovesEveryFrame()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, TwoHalves);
|
||||
using var processor = Uniform(3d, holdFrames: 1).CreateVideoEffect(context);
|
||||
processor.SetInput(source.Bitmap);
|
||||
|
||||
var first = RenderFrame(context, processor, 0);
|
||||
var second = RenderFrame(context, processor, 1);
|
||||
|
||||
Assert.False(first.SamePixelsAs(second));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReturningToAFrameReproducesItExactly()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, TwoHalves);
|
||||
using var processor = Uniform(3d, holdFrames: 2).CreateVideoEffect(context);
|
||||
processor.SetInput(source.Bitmap);
|
||||
|
||||
var first = RenderFrame(context, processor, 4);
|
||||
RenderFrame(context, processor, 9);
|
||||
var again = RenderFrame(context, processor, 5);
|
||||
|
||||
Assert.True(first.SamePixelsAs(again));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheSeedChangesTheSequence()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, TwoHalves);
|
||||
var effect = Uniform(3d);
|
||||
using var processor = effect.CreateVideoEffect(context);
|
||||
processor.SetInput(source.Bitmap);
|
||||
|
||||
var first = RenderFrame(context, processor, 0);
|
||||
effect.Seed = 1;
|
||||
var second = RenderFrame(context, processor, 0);
|
||||
|
||||
Assert.False(first.SamePixelsAs(second));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnimatedAmplitudeIsReadAtEachFrame()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, TwoHalves);
|
||||
var effect = Uniform(0d);
|
||||
effect.Amplitude.CopyFrom(Linear(0d, 4d));
|
||||
using var processor = effect.CreateVideoEffect(context);
|
||||
processor.SetInput(source.Bitmap);
|
||||
|
||||
var start = RenderFrame(context, processor, 0);
|
||||
var end = RenderFrame(context, processor, Length - 1);
|
||||
|
||||
Assert.Equal((0, 0, Width, Height), (start.Left, start.Top, start.Width, start.Height));
|
||||
Assert.True(end.Left < 0 && end.Top < 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheProcessorFeedsTheEffectExactlyTheParameters()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, Gradient);
|
||||
var effect = new DrawingWobbleEffect { HoldFrames = 4, Seed = 11 };
|
||||
effect.Amplitude.Values[0].Value = 3.5d;
|
||||
effect.Scale.Values[0].Value = 17d;
|
||||
effect.EdgeRadius.Values[0].Value = 5d;
|
||||
effect.EdgeFocus.Values[0].Value = 35d;
|
||||
using var processor = effect.CreateVideoEffect(context);
|
||||
processor.SetInput(source.Bitmap);
|
||||
using var direct = new DrawingWobbleCustomEffect(context);
|
||||
direct.SetInput(0, source.Bitmap, true);
|
||||
direct.Amplitude = 3.5f;
|
||||
direct.Scale = 17f;
|
||||
direct.EdgeRadius = 5f;
|
||||
direct.EdgeFocus = 0.35f;
|
||||
direct.HoldIndex = 2;
|
||||
direct.Seed = 11;
|
||||
using var expected = direct.Output;
|
||||
|
||||
var rendering = RenderFrame(context, processor, 9);
|
||||
|
||||
Assert.True(rendering.SamePixelsAs(Rendering.Capture(context, expected)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ChangedSettingsReachTheNextFrame()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, TwoHalves);
|
||||
var effect = Uniform(3d);
|
||||
using var processor = effect.CreateVideoEffect(context);
|
||||
processor.SetInput(source.Bitmap);
|
||||
|
||||
var wobbling = RenderFrame(context, processor, 0);
|
||||
effect.Amplitude.Values[0].Value = 0d;
|
||||
var still = RenderFrame(context, processor, 0);
|
||||
|
||||
Assert.False(wobbling.SamePixelsAs(still));
|
||||
Assert.All(still.Coordinates(), point => Assert.Equal(source[point.X, point.Y], still[point.X, point.Y]));
|
||||
}
|
||||
|
||||
public static readonly TheoryData<string, Action<DrawingWobbleEffect>> LaterChanges = new()
|
||||
{
|
||||
{ nameof(DrawingWobbleEffect.Scale), effect => effect.Scale.Values[0].Value = 6d },
|
||||
{ nameof(DrawingWobbleEffect.EdgeRadius), effect => effect.EdgeRadius.Values[0].Value = 8d },
|
||||
{ nameof(DrawingWobbleEffect.EdgeFocus), effect => effect.EdgeFocus.Values[0].Value = 0d },
|
||||
{ nameof(DrawingWobbleEffect.HoldFrames), effect => effect.HoldFrames = 1 },
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(LaterChanges))]
|
||||
public void EverySettingChangedAfterTheFirstFrameReachesTheEffect(string setting, Action<DrawingWobbleEffect> change)
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, Gradient);
|
||||
var effect = new DrawingWobbleEffect { HoldFrames = 3 };
|
||||
effect.Amplitude.Values[0].Value = 4d;
|
||||
effect.EdgeRadius.Values[0].Value = 2d;
|
||||
effect.EdgeFocus.Values[0].Value = 100d;
|
||||
using var processor = effect.CreateVideoEffect(context);
|
||||
processor.SetInput(source.Bitmap);
|
||||
|
||||
var before = RenderFrame(context, processor, 5);
|
||||
change(effect);
|
||||
var after = RenderFrame(context, processor, 5);
|
||||
|
||||
Assert.False(before.SamePixelsAs(after), setting);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AFailureWhileUpdatingIsNotSwallowed()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var processor = Uniform(3d).CreateVideoEffect(context);
|
||||
|
||||
Assert.ThrowsAny<Exception>(() => processor.Update(null!));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AFailureWhileCreatingTheProcessorIsNotSwallowed()
|
||||
{
|
||||
var effect = Uniform(3d);
|
||||
|
||||
Assert.ThrowsAny<Exception>(() => effect.CreateVideoEffect(null!));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Reflection;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
using YukkuriMovieMaker.Controls;
|
||||
using YukkuriMovieMaker.Exo;
|
||||
using YukkuriMovieMaker.Json;
|
||||
using YukkuriMovieMaker.Plugin;
|
||||
using YukkuriMovieMaker.Plugin.Effects;
|
||||
using YukkuriMovieMaker.Project;
|
||||
|
||||
namespace DrawingWobble.Tests;
|
||||
|
||||
public sealed class DrawingWobbleEffectTests
|
||||
{
|
||||
static PropertyInfo Property(string name) => typeof(DrawingWobbleEffect).GetProperty(name)!;
|
||||
|
||||
static T Attribute<T>(string property) where T : Attribute => Property(property).GetCustomAttribute<T>()!;
|
||||
|
||||
[Theory]
|
||||
[InlineData(nameof(DrawingWobbleEffect.Amplitude), 2d, 0d, 4096d)]
|
||||
[InlineData(nameof(DrawingWobbleEffect.Scale), 60d, 1d, 4096d)]
|
||||
[InlineData(nameof(DrawingWobbleEffect.EdgeRadius), 12d, 0d, 4096d)]
|
||||
[InlineData(nameof(DrawingWobbleEffect.EdgeFocus), 100d, 0d, 100d)]
|
||||
public void AnimatedParametersStartFromTheirDefaultsWithinTheirRange(string name, double defaultValue, double minimum, double maximum)
|
||||
{
|
||||
var effect = new DrawingWobbleEffect();
|
||||
|
||||
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 HoldFramesAndSeedStartFromTheirDefaults()
|
||||
{
|
||||
var effect = new DrawingWobbleEffect();
|
||||
|
||||
Assert.Equal(3, effect.HoldFrames);
|
||||
Assert.Equal(0, effect.Seed);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(int.MinValue, 1)]
|
||||
[InlineData(-1, 1)]
|
||||
[InlineData(0, 1)]
|
||||
[InlineData(1, 1)]
|
||||
[InlineData(12, 12)]
|
||||
[InlineData(int.MaxValue, int.MaxValue)]
|
||||
public void HoldFramesNeverDropBelowOne(int value, int expected)
|
||||
{
|
||||
var effect = new DrawingWobbleEffect { HoldFrames = 5 };
|
||||
|
||||
effect.HoldFrames = value;
|
||||
|
||||
Assert.Equal(expected, effect.HoldFrames);
|
||||
Assert.False(effect.HasErrors);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(int.MinValue, 0)]
|
||||
[InlineData(-1, 0)]
|
||||
[InlineData(0, 0)]
|
||||
[InlineData(10000, 10000)]
|
||||
[InlineData(int.MaxValue, int.MaxValue)]
|
||||
public void SeedNeverDropsBelowZero(int value, int expected)
|
||||
{
|
||||
var effect = new DrawingWobbleEffect { Seed = 5 };
|
||||
|
||||
effect.Seed = value;
|
||||
|
||||
Assert.Equal(expected, effect.Seed);
|
||||
Assert.False(effect.HasErrors);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ChangingHoldFramesOrSeedNotifiesTheEditor()
|
||||
{
|
||||
var effect = new DrawingWobbleEffect();
|
||||
var changed = new List<string?>();
|
||||
effect.PropertyChanged += (_, e) => changed.Add(e.PropertyName);
|
||||
|
||||
effect.HoldFrames = 2;
|
||||
effect.Seed = 7;
|
||||
|
||||
Assert.Equal([nameof(DrawingWobbleEffect.HoldFrames), nameof(DrawingWobbleEffect.Seed)], changed);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AssigningAnUnchangedOrClampedValueDoesNotNotify()
|
||||
{
|
||||
var effect = new DrawingWobbleEffect { HoldFrames = 1 };
|
||||
var changed = new List<string?>();
|
||||
effect.PropertyChanged += (_, e) => changed.Add(e.PropertyName);
|
||||
|
||||
effect.HoldFrames = 1;
|
||||
effect.HoldFrames = -5;
|
||||
effect.Seed = 0;
|
||||
effect.Seed = -1;
|
||||
|
||||
Assert.Empty(changed);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheLabelIsTheLocalizedEffectName()
|
||||
{
|
||||
var effect = new DrawingWobbleEffect();
|
||||
|
||||
Assert.Equal(Texts.DrawingWobble, effect.Label);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheFourNumericParametersReceiveTheAnimationParameters()
|
||||
{
|
||||
var effect = new DrawingWobbleEffect();
|
||||
|
||||
effect.SetAnimationParameters(120, EffectDescriptions.Fps);
|
||||
|
||||
Assert.All([effect.Amplitude, effect.Scale, effect.EdgeRadius, effect.EdgeFocus], animation => Assert.Equal(120, animation.Length));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
[InlineData(int.MaxValue)]
|
||||
public void NoExoFilterIsWrittenForAviUtl(int keyFrameIndex)
|
||||
{
|
||||
var effect = new DrawingWobbleEffect();
|
||||
|
||||
var description = new ExoOutputDescription(new VideoInfo(), string.Empty, new AviUtlDirectories(string.Empty, string.Empty));
|
||||
|
||||
Assert.Empty(effect.CreateExoVideoFilters(keyFrameIndex, description));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheEffectIsRegisteredForAnimationAndFilteringWithoutAviUtlSupport()
|
||||
{
|
||||
var attribute = typeof(DrawingWobbleEffect).GetCustomAttribute<VideoEffectAttribute>()!;
|
||||
|
||||
Assert.Equal(nameof(Texts.DrawingWobble), attribute.Name);
|
||||
Assert.Equal([VideoEffectCategories.Animation, VideoEffectCategories.Filtering], attribute.Categories);
|
||||
Assert.Equal([nameof(Texts.TagHandDrawn), nameof(Texts.TagWobble), nameof(Texts.TagBoil), nameof(Texts.TagSketch)], attribute.Keywords);
|
||||
Assert.False(attribute.IsAviUtlSupported);
|
||||
Assert.True(attribute.IsEffectItemSupported);
|
||||
Assert.Equal(typeof(Texts), attribute.ResourceType);
|
||||
Assert.Equal(Texts.DrawingWobble, attribute.GetName());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheAuthorIsDeclared()
|
||||
{
|
||||
var details = typeof(DrawingWobbleEffect).GetCustomAttribute<PluginDetailsAttribute>()!;
|
||||
|
||||
Assert.Equal("routersys", details.AuthorName);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(nameof(DrawingWobbleEffect.Amplitude), nameof(Texts.WobbleGroup), nameof(Texts.Amplitude), nameof(Texts.AmplitudeDescription), 0)]
|
||||
[InlineData(nameof(DrawingWobbleEffect.Scale), nameof(Texts.WobbleGroup), nameof(Texts.Scale), nameof(Texts.ScaleDescription), 1)]
|
||||
[InlineData(nameof(DrawingWobbleEffect.HoldFrames), nameof(Texts.WobbleGroup), nameof(Texts.HoldFrames), nameof(Texts.HoldFramesDescription), 2)]
|
||||
[InlineData(nameof(DrawingWobbleEffect.Seed), nameof(Texts.WobbleGroup), nameof(Texts.Seed), nameof(Texts.SeedDescription), 3)]
|
||||
[InlineData(nameof(DrawingWobbleEffect.EdgeRadius), nameof(Texts.EdgeGroup), nameof(Texts.EdgeRadius), nameof(Texts.EdgeRadiusDescription), 10)]
|
||||
[InlineData(nameof(DrawingWobbleEffect.EdgeFocus), nameof(Texts.EdgeGroup), nameof(Texts.EdgeFocus), nameof(Texts.EdgeFocusDescription), 11)]
|
||||
public void EveryParameterIsDisplayedInItsGroupInOrder(string property, string group, string name, string description, int order)
|
||||
{
|
||||
var display = Attribute<DisplayAttribute>(property);
|
||||
|
||||
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(nameof(DrawingWobbleEffect.Amplitude), "F1", "px", 0d, 20d)]
|
||||
[InlineData(nameof(DrawingWobbleEffect.Scale), "F1", "px", 8d, 400d)]
|
||||
[InlineData(nameof(DrawingWobbleEffect.EdgeRadius), "F1", "px", 0d, 64d)]
|
||||
[InlineData(nameof(DrawingWobbleEffect.EdgeFocus), "F1", "%", 0d, 100d)]
|
||||
public void AnimatedParametersAreEditedWithAnimationSliders(string property, string format, string unit, double minimum, double maximum)
|
||||
{
|
||||
var slider = Attribute<AnimationSliderAttribute>(property);
|
||||
|
||||
Assert.Equal(format, slider.StringFormat);
|
||||
Assert.Equal(unit, slider.UnitText);
|
||||
Assert.Equal(minimum, slider.DefaultMin);
|
||||
Assert.Equal(maximum, slider.DefaultMax);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HoldFramesAreEditedInFramesFromOneToTwelve()
|
||||
{
|
||||
var slider = Attribute<TextBoxSliderAttribute>(nameof(DrawingWobbleEffect.HoldFrames));
|
||||
var range = Attribute<RangeAttribute>(nameof(DrawingWobbleEffect.HoldFrames));
|
||||
|
||||
Assert.Equal("F0", slider.StringFormat);
|
||||
Assert.Equal(nameof(Texts.FrameUnit), slider.UnitText);
|
||||
Assert.Equal(typeof(Texts), slider.ResourceType);
|
||||
Assert.Equal(1d, slider.DefaultMin);
|
||||
Assert.Equal(12d, slider.DefaultMax);
|
||||
Assert.Equal(1, range.Minimum);
|
||||
Assert.Equal(int.MaxValue, range.Maximum);
|
||||
Assert.Equal(3, Attribute<DefaultValueAttribute>(nameof(DrawingWobbleEffect.HoldFrames)).Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheSeedIsEditedWithoutAUnitFromZero()
|
||||
{
|
||||
var slider = Attribute<TextBoxSliderAttribute>(nameof(DrawingWobbleEffect.Seed));
|
||||
var range = Attribute<RangeAttribute>(nameof(DrawingWobbleEffect.Seed));
|
||||
|
||||
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(DrawingWobbleEffect.Seed)).Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EverySettingSurvivesAProjectRoundTrip()
|
||||
{
|
||||
var effect = new DrawingWobbleEffect { HoldFrames = 5, Seed = 42 };
|
||||
effect.Amplitude.Values[0].Value = 7.5d;
|
||||
effect.Scale.Values[0].Value = 120d;
|
||||
effect.EdgeRadius.Values[0].Value = 3d;
|
||||
effect.EdgeFocus.Values[0].Value = 40d;
|
||||
|
||||
var clone = Json.GetClone(effect)!;
|
||||
|
||||
Assert.NotSame(effect, clone);
|
||||
Assert.Equal(5, clone.HoldFrames);
|
||||
Assert.Equal(42, clone.Seed);
|
||||
Assert.Equal(7.5d, clone.Amplitude.GetValue(0, 1, EffectDescriptions.Fps));
|
||||
Assert.Equal(120d, clone.Scale.GetValue(0, 1, EffectDescriptions.Fps));
|
||||
Assert.Equal(3d, clone.EdgeRadius.GetValue(0, 1, EffectDescriptions.Fps));
|
||||
Assert.Equal(40d, clone.EdgeFocus.GetValue(0, 1, EffectDescriptions.Fps));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using Vortice;
|
||||
using static DrawingWobble.DrawingWobbleCustomEffect.EffectImpl;
|
||||
|
||||
namespace DrawingWobble.Tests;
|
||||
|
||||
public sealed class DrawingWobbleMarginsTests
|
||||
{
|
||||
const int MaxInputPixel = 4096;
|
||||
|
||||
[Theory]
|
||||
[InlineData(-3f, 0)]
|
||||
[InlineData(0f, 0)]
|
||||
[InlineData(0.01f, 3)]
|
||||
[InlineData(1f, 3)]
|
||||
[InlineData(2f, 4)]
|
||||
[InlineData(2.5f, 5)]
|
||||
[InlineData(MaxInputPixel - 2f, MaxInputPixel)]
|
||||
[InlineData(MaxInputPixel, MaxInputPixel)]
|
||||
[InlineData(float.MaxValue, MaxInputPixel)]
|
||||
public void TheOutputMarginRoundsTheAmplitudeUpAndAddsTwoPixels(float amplitude, int expected)
|
||||
=> Assert.Equal(expected, Margins.Output(amplitude));
|
||||
|
||||
[Theory]
|
||||
[InlineData(3f, 12f, 1f, 14)]
|
||||
[InlineData(12f, 3f, 1f, 14)]
|
||||
[InlineData(3f, 12f, 0.01f, 14)]
|
||||
[InlineData(3f, 12f, 0f, 5)]
|
||||
[InlineData(3f, 0f, 1f, 5)]
|
||||
[InlineData(0f, 12f, 1f, 0)]
|
||||
[InlineData(3f, -1f, 1f, 5)]
|
||||
[InlineData(3f, 12f, -1f, 5)]
|
||||
public void TheInputMarginCoversTheRingOnlyWhileItIsSampled(float amplitude, float edgeRadius, float edgeFocus, int expected)
|
||||
=> Assert.Equal(expected, Margins.Input(amplitude, edgeRadius, edgeFocus));
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(-4)]
|
||||
public void InflatingByNothingReturnsTheSameRectangle(int margin)
|
||||
{
|
||||
var rect = new RawRect(1, 2, 3, 4);
|
||||
|
||||
Assert.Equal(rect, Margins.Inflate(rect, margin));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InflatingGrowsEverySide()
|
||||
{
|
||||
Assert.Equal(new RawRect(-2, 7, 33, 44), Margins.Inflate(new RawRect(1, 10, 30, 41), 3));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InflatingSaturatesAtTheIntegerLimits()
|
||||
{
|
||||
var inflated = Margins.Inflate(new RawRect(int.MinValue + 1, int.MinValue, int.MaxValue - 1, int.MaxValue), 5);
|
||||
|
||||
Assert.Equal(new RawRect(int.MinValue, int.MinValue, int.MaxValue, int.MaxValue), inflated);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
using System.Numerics;
|
||||
using Vortice.Direct2D1;
|
||||
using Vortice.Direct2D1.Effects;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
|
||||
namespace DrawingWobble.Tests;
|
||||
|
||||
[Collection("Direct2D")]
|
||||
public sealed class DrawingWobbleRenderingTests
|
||||
{
|
||||
const int Width = 64;
|
||||
const int Height = 32;
|
||||
|
||||
static readonly Bgra Red = Bgra.Opaque(0, 0, 255);
|
||||
static readonly Bgra Blue = Bgra.Opaque(255, 0, 0);
|
||||
|
||||
static Bgra TwoHalves(int x, int y) => x < Width / 2 ? Red : Blue;
|
||||
|
||||
static Bgra Gradient(int x, int y) => Bgra.Opaque((byte)(x * 4), (byte)(x * 4), (byte)(x * 4));
|
||||
|
||||
static Bgra OpaqueLeftHalf(int x, int y) => x < Width / 2 ? Bgra.Opaque(0, 0, 0) : Bgra.Transparent;
|
||||
|
||||
static Rendering Render(IGraphicsDevicesAndContext devices, SourceImage source, Action<DrawingWobbleCustomEffect> configure)
|
||||
{
|
||||
using var effect = new DrawingWobbleCustomEffect(devices);
|
||||
effect.SetInput(0, source.Bitmap, true);
|
||||
configure(effect);
|
||||
using var output = effect.Output;
|
||||
return Rendering.Capture(devices, 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 double DistanceToBorder(SourceImage source, int x, int y)
|
||||
=> Math.Min(Math.Min(x, source.Width - 1 - x), Math.Min(y, source.Height - 1 - y));
|
||||
|
||||
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 long Difference(Rendering rendering, SourceImage source)
|
||||
{
|
||||
var total = 0L;
|
||||
foreach (var (x, y) in rendering.Coordinates())
|
||||
{
|
||||
var expected = source.Contains(x, y) ? source[x, y] : Bgra.Transparent;
|
||||
var actual = rendering[x, y];
|
||||
total += Math.Abs(expected.Blue - actual.Blue) + Math.Abs(expected.Green - actual.Green) + Math.Abs(expected.Red - actual.Red) + Math.Abs(expected.Alpha - actual.Alpha);
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0f, 0f)]
|
||||
[InlineData(1f, 0f)]
|
||||
[InlineData(1f, 8f)]
|
||||
public void WithoutAmplitudeTheImagePassesThroughUntouched(float edgeFocus, float edgeRadius)
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, Gradient);
|
||||
|
||||
var rendering = Render(context, source, effect =>
|
||||
{
|
||||
effect.EdgeFocus = edgeFocus;
|
||||
effect.EdgeRadius = edgeRadius;
|
||||
effect.HoldIndex = 3;
|
||||
effect.Seed = 9;
|
||||
});
|
||||
|
||||
AssertSameAsSource(rendering, source);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheSameSettingsAlwaysProduceTheSamePixels()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, TwoHalves);
|
||||
void Configure(DrawingWobbleCustomEffect effect)
|
||||
{
|
||||
effect.Amplitude = 3f;
|
||||
effect.Scale = 12f;
|
||||
effect.HoldIndex = 2;
|
||||
effect.Seed = 5;
|
||||
}
|
||||
|
||||
var first = Render(context, source, Configure);
|
||||
var second = Render(context, source, Configure);
|
||||
|
||||
Assert.True(first.SamePixelsAs(second));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ADifferentHoldIndexMovesTheImageDifferently()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, TwoHalves);
|
||||
|
||||
var held = Render(context, source, effect => { effect.Amplitude = 3f; effect.HoldIndex = 0; });
|
||||
var next = Render(context, source, effect => { effect.Amplitude = 3f; effect.HoldIndex = 1; });
|
||||
|
||||
Assert.False(held.SamePixelsAs(next));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ADifferentSeedMovesTheImageDifferently()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, TwoHalves);
|
||||
|
||||
var first = Render(context, source, effect => { effect.Amplitude = 3f; effect.Seed = 0; });
|
||||
var second = Render(context, source, effect => { effect.Amplitude = 3f; effect.Seed = 1; });
|
||||
|
||||
Assert.False(first.SamePixelsAs(second));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ADifferentScaleMovesTheImageDifferently()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, TwoHalves);
|
||||
|
||||
var fine = Render(context, source, effect => { effect.Amplitude = 3f; effect.Scale = 6f; });
|
||||
var coarse = Render(context, source, effect => { effect.Amplitude = 3f; effect.Scale = 60f; });
|
||||
|
||||
Assert.False(fine.SamePixelsAs(coarse));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1f)]
|
||||
[InlineData(2.5f)]
|
||||
[InlineData(6f)]
|
||||
public void NoPixelIsPulledFromFartherThanTheAmplitude(float amplitude)
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, TwoHalves);
|
||||
var reach = amplitude + 1d;
|
||||
|
||||
var rendering = Render(context, source, effect => effect.Amplitude = amplitude);
|
||||
|
||||
foreach (var (x, y) in rendering.Coordinates())
|
||||
{
|
||||
var distanceToSeam = Math.Abs(x + 0.5d - Width / 2d);
|
||||
if (source.Contains(x, y) && distanceToSeam > reach && DistanceToBorder(source, x, y) > reach)
|
||||
Assert.Equal(source[x, y], rendering[x, y]);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheSeamActuallyWobbles()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, TwoHalves);
|
||||
|
||||
var rendering = Render(context, source, effect => effect.Amplitude = 3f);
|
||||
|
||||
Assert.Contains(rendering.Coordinates(), point => source.Contains(point.X, point.Y) && rendering[point.X, point.Y] != source[point.X, point.Y]);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(2f)]
|
||||
[InlineData(5f)]
|
||||
public void PixelsBeyondTheReachOfTheAmplitudeStayTransparent(float amplitude)
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = SourceImage.Solid(context, Width, Height, Blue);
|
||||
var reach = amplitude + 1d;
|
||||
|
||||
var rendering = Render(context, source, effect => effect.Amplitude = amplitude);
|
||||
|
||||
Assert.True(rendering.Left < 0 && rendering.Top < 0);
|
||||
foreach (var (x, y) in rendering.Coordinates())
|
||||
{
|
||||
if (-DistanceToBorder(source, x, y) > reach)
|
||||
Assert.Equal(Bgra.Transparent, rendering[x, y]);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheImageSpillsOverItsOriginalEdges()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = SourceImage.Solid(context, Width, Height, Blue);
|
||||
|
||||
var rendering = Render(context, source, effect => effect.Amplitude = 3f);
|
||||
|
||||
Assert.Contains(rendering.Coordinates(), point => !source.Contains(point.X, point.Y) && rendering[point.X, point.Y].Alpha > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheInteriorOfAFlatImageStaysStillWhenTheWobbleFollowsTheEdges()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = SourceImage.Solid(context, Width, Height, Blue);
|
||||
const float edgeRadius = 6f;
|
||||
|
||||
var rendering = Render(context, source, effect =>
|
||||
{
|
||||
effect.Amplitude = 4f;
|
||||
effect.EdgeRadius = edgeRadius;
|
||||
effect.EdgeFocus = 1f;
|
||||
});
|
||||
|
||||
foreach (var (x, y) in rendering.Coordinates())
|
||||
{
|
||||
if (source.Contains(x, y) && DistanceToBorder(source, x, y) > edgeRadius + 1d)
|
||||
Assert.Equal(Blue.Premultiplied(), rendering[x, y]);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheEdgeFocusScalesDownTheWobbleOfFlatAreas()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, Gradient);
|
||||
Action<DrawingWobbleCustomEffect> With(float focus) => effect =>
|
||||
{
|
||||
effect.Amplitude = 4f;
|
||||
effect.EdgeRadius = 2f;
|
||||
effect.EdgeFocus = focus;
|
||||
};
|
||||
|
||||
var none = Difference(Render(context, source, With(0f)), source);
|
||||
var half = Difference(Render(context, source, With(0.5f)), source);
|
||||
var full = Difference(Render(context, source, With(1f)), source);
|
||||
|
||||
Assert.True(none > half, $"none={none} half={half}");
|
||||
Assert.True(half > full, $"half={half} full={full}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AZeroEdgeRadiusWobblesTheWholeImageEvenlyDespiteTheFocus()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, Gradient);
|
||||
|
||||
var uniform = Render(context, source, effect => { effect.Amplitude = 4f; effect.EdgeFocus = 0f; });
|
||||
var focused = Render(context, source, effect => { effect.Amplitude = 4f; effect.EdgeFocus = 1f; effect.EdgeRadius = 0f; });
|
||||
|
||||
Assert.True(uniform.SamePixelsAs(focused));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnAlphaEdgeCountsAsAContour()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, OpaqueLeftHalf);
|
||||
const float amplitude = 3f;
|
||||
const float edgeRadius = 4f;
|
||||
|
||||
var rendering = Render(context, source, effect =>
|
||||
{
|
||||
effect.Amplitude = amplitude;
|
||||
effect.EdgeRadius = edgeRadius;
|
||||
effect.EdgeFocus = 1f;
|
||||
});
|
||||
|
||||
var nearSeam = rendering.Coordinates().Where(point => Math.Abs(point.X + 0.5d - Width / 2d) <= edgeRadius && DistanceToBorder(source, point.X, point.Y) > edgeRadius + amplitude + 1d);
|
||||
Assert.Contains(nearSeam, point => rendering[point.X, point.Y] != source[point.X, point.Y]);
|
||||
foreach (var (x, y) in rendering.Coordinates())
|
||||
{
|
||||
if (source.Contains(x, y) && Math.Abs(x + 0.5d - Width / 2d) > edgeRadius + amplitude + 1d && DistanceToBorder(source, x, y) > edgeRadius + amplitude + 1d)
|
||||
Assert.Equal(source[x, y], rendering[x, y]);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(100, 50)]
|
||||
[InlineData(-37, 21)]
|
||||
public void TheWobbleTravelsWithTheImage(int dx, int dy)
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var source = new SourceImage(context, Width, Height, TwoHalves);
|
||||
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;
|
||||
void Configure(DrawingWobbleCustomEffect effect)
|
||||
{
|
||||
effect.Amplitude = 3f;
|
||||
effect.EdgeRadius = 4f;
|
||||
effect.EdgeFocus = 0.5f;
|
||||
}
|
||||
|
||||
var inPlace = Render(context, source, Configure);
|
||||
using var effect = new DrawingWobbleCustomEffect(context);
|
||||
effect.SetInput(0, movedOutput, true);
|
||||
Configure(effect);
|
||||
using var output = effect.Output;
|
||||
var travelled = Rendering.Capture(context, output);
|
||||
|
||||
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(WithinRounding(inPlace[point.X, point.Y], travelled[point.X + dx, point.Y + dy]), $"({point.X}, {point.Y})"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SemiTransparentPixelsKeepTheirPremultipliedValues()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
var color = new Bgra(40, 90, 200, 128);
|
||||
using var source = SourceImage.Solid(context, Width, Height, color);
|
||||
const float amplitude = 3f;
|
||||
|
||||
var rendering = Render(context, source, effect => effect.Amplitude = amplitude);
|
||||
|
||||
foreach (var (x, y) in rendering.Coordinates())
|
||||
{
|
||||
if (source.Contains(x, y) && DistanceToBorder(source, x, y) > amplitude + 1d)
|
||||
Assert.Equal(color.Premultiplied(), rendering[x, y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
using Vortice.Direct2D1;
|
||||
using YukkuriMovieMaker.Player.Video;
|
||||
|
||||
namespace DrawingWobble.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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DrawingWobble.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;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Windows;
|
||||
using Telemetry;
|
||||
|
||||
namespace DrawingWobble.Tests;
|
||||
|
||||
public sealed class HostIntegrationTests
|
||||
{
|
||||
[Fact]
|
||||
public void OutsideAWpfApplicationNoTelemetryIsStartedOrSent()
|
||||
{
|
||||
Assert.Null(Application.Current);
|
||||
|
||||
DrawingWobbleTelemetry.EnsureStartedOnce();
|
||||
DrawingWobbleTelemetry.Report(new InvalidOperationException());
|
||||
|
||||
Assert.Null(ProcessState.Read("DrainClaimed"));
|
||||
Assert.Null(ProcessState.Read("SentCount"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OutsideAWpfApplicationTheEffectCanStillBeCreated()
|
||||
{
|
||||
Assert.Null(Application.Current);
|
||||
|
||||
var effect = new DrawingWobbleEffect();
|
||||
|
||||
Assert.Equal(Texts.DrawingWobble, effect.Label);
|
||||
Assert.Null(ProcessState.Read("DrainClaimed"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.IO.Packaging;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DrawingWobble.Tests;
|
||||
|
||||
internal static class PackUriScheme
|
||||
{
|
||||
[ModuleInitializer]
|
||||
internal static void Register() => _ = PackUriHelper.UriSchemePack;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using Vortice.Direct2D1;
|
||||
using Vortice.Mathematics;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
|
||||
namespace DrawingWobble.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using Vortice.DCommon;
|
||||
using Vortice.Direct2D1;
|
||||
using Vortice.DXGI;
|
||||
using Vortice.Mathematics;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
|
||||
namespace DrawingWobble.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();
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
|
||||
namespace DrawingWobble.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.DrawingWobble), CultureInfo.InvariantCulture);
|
||||
|
||||
Assert.Equal("作画ゆれ", neutral);
|
||||
Assert.Equal(neutral, Texts.ResourceManager.GetString(nameof(Texts.DrawingWobble), 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"stryker-config": {
|
||||
"project": "DrawingWobble.csproj",
|
||||
"test-runner": "mtp",
|
||||
"coverage-analysis": "off",
|
||||
"mutate": [
|
||||
"**/*.cs",
|
||||
"!**/YMM4-GitHubUpdateNotifier/**",
|
||||
"!**/YMM4-Telemetry/**",
|
||||
"!**/DrawingWobbleTelemetry.cs",
|
||||
"!**/DrawingWobbleUpdateNotifier.cs"
|
||||
],
|
||||
"reporters": [
|
||||
"progress",
|
||||
"cleartext",
|
||||
"html"
|
||||
],
|
||||
"thresholds": {
|
||||
"high": 80,
|
||||
"low": 60,
|
||||
"break": 60
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@
|
||||
<Project Path="DrawingWobble/DrawingWobble.csproj">
|
||||
<BuildDependency Project="DrawingWobble.Shader/DrawingWobble.Shader.vcxproj" />
|
||||
</Project>
|
||||
<Project Path="DrawingWobble.Tests/DrawingWobble.Tests.csproj" />
|
||||
<Project Path="DrawingWobble.Harness/DrawingWobble.Harness.csproj" />
|
||||
<Project Path="DrawingWobble.Shader/DrawingWobble.Shader.vcxproj">
|
||||
<BuildType Solution="*|*" Project="Release" />
|
||||
<Platform Solution="*|*" Project="Win32" />
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace DrawingWobble
|
||||
{
|
||||
internal sealed class DrawingWobbleCustomEffect(IGraphicsDevicesAndContext devices) : D2D1CustomShaderEffectBase(Create<EffectImpl>(devices))
|
||||
{
|
||||
private enum PropertyIndex
|
||||
internal enum PropertyIndex
|
||||
{
|
||||
Amplitude = 0,
|
||||
Scale,
|
||||
@@ -27,7 +27,7 @@ namespace DrawingWobble
|
||||
public int Seed { set => SetValue((int)PropertyIndex.Seed, value); }
|
||||
|
||||
[CustomEffect(1)]
|
||||
private sealed class EffectImpl : D2D1CustomShaderEffectImplBase<EffectImpl>
|
||||
internal sealed class EffectImpl : D2D1CustomShaderEffectImplBase<EffectImpl>
|
||||
{
|
||||
private ConstantBuffer _cb;
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace DrawingWobble
|
||||
_cb.InputBounds = new Vector4(inputRect.Left, inputRect.Top, inputRect.Right, inputRect.Bottom);
|
||||
UpdateConstants();
|
||||
|
||||
outputRect = Inflate(inputRect, OutputMargin());
|
||||
outputRect = Margins.Inflate(inputRect, Margins.Output(_cb.Amplitude));
|
||||
outputOpaqueSubRect = default;
|
||||
}
|
||||
|
||||
@@ -102,34 +102,36 @@ namespace DrawingWobble
|
||||
return;
|
||||
}
|
||||
|
||||
inputRects[0] = Inflate(outputRect, InputMargin());
|
||||
inputRects[0] = Margins.Inflate(outputRect, Margins.Input(_cb.Amplitude, _cb.EdgeRadius, _cb.EdgeFocus));
|
||||
}
|
||||
|
||||
public override RawRect MapInvalidRect(int inputIndex, RawRect invalidInputRect)
|
||||
=> Inflate(invalidInputRect, InputMargin());
|
||||
=> Margins.Inflate(invalidInputRect, Margins.Input(_cb.Amplitude, _cb.EdgeRadius, _cb.EdgeFocus));
|
||||
|
||||
private int OutputMargin() => Margin(_cb.Amplitude);
|
||||
|
||||
private int InputMargin() => Margin(SamplesRing() ? Math.Max(_cb.Amplitude, _cb.EdgeRadius) : _cb.Amplitude);
|
||||
|
||||
private bool SamplesRing() => _cb.Amplitude > 0f && _cb.EdgeFocus > 0f && _cb.EdgeRadius > 0f;
|
||||
|
||||
private static int Margin(float distance) => distance <= 0f ? 0 : (int)Math.Min(Math.Ceiling(distance) + 2.0, MaxInputPixel);
|
||||
|
||||
private static RawRect Inflate(RawRect rect, int margin)
|
||||
internal static class Margins
|
||||
{
|
||||
if (margin <= 0)
|
||||
return rect;
|
||||
public static int Output(float amplitude) => Of(amplitude);
|
||||
|
||||
return new RawRect(
|
||||
Saturate((long)rect.Left - margin),
|
||||
Saturate((long)rect.Top - margin),
|
||||
Saturate((long)rect.Right + margin),
|
||||
Saturate((long)rect.Bottom + margin));
|
||||
public static int Input(float amplitude, float edgeRadius, float edgeFocus)
|
||||
=> Of(amplitude > 0f && edgeFocus > 0f && edgeRadius > 0f ? Math.Max(amplitude, edgeRadius) : amplitude);
|
||||
|
||||
public static RawRect Inflate(RawRect rect, int margin)
|
||||
{
|
||||
if (margin <= 0)
|
||||
return rect;
|
||||
|
||||
return new RawRect(
|
||||
Saturate((long)rect.Left - margin),
|
||||
Saturate((long)rect.Top - margin),
|
||||
Saturate((long)rect.Right + margin),
|
||||
Saturate((long)rect.Bottom + margin));
|
||||
}
|
||||
|
||||
private static int Of(float distance) => distance <= 0f ? 0 : (int)Math.Min(Math.Ceiling(distance) + 2.0, MaxInputPixel);
|
||||
|
||||
private static int Saturate(long value) => (int)Math.Clamp(value, int.MinValue, int.MaxValue);
|
||||
}
|
||||
|
||||
private static int Saturate(long value) => (int)Math.Clamp(value, int.MinValue, int.MaxValue);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct ConstantBuffer
|
||||
{
|
||||
|
||||
@@ -16,20 +16,22 @@ internal static class DrawingWobbleTelemetry
|
||||
|
||||
public static void EnsureStartedOnce()
|
||||
{
|
||||
if (Interlocked.Exchange(ref _started, 1) != 0)
|
||||
var application = Application.Current;
|
||||
if (application is null || Interlocked.Exchange(ref _started, 1) != 0)
|
||||
return;
|
||||
|
||||
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
|
||||
|
||||
var application = Application.Current;
|
||||
if (application is not null)
|
||||
application.DispatcherUnhandledException += OnDispatcherUnhandledException;
|
||||
application.DispatcherUnhandledException += OnDispatcherUnhandledException;
|
||||
|
||||
TelemetryReporter.Start();
|
||||
}
|
||||
|
||||
public static void Report(Exception exception) => TelemetryReporter.Report(exception);
|
||||
public static void Report(Exception exception)
|
||||
{
|
||||
if (Volatile.Read(ref _started) != 0)
|
||||
TelemetryReporter.Report(exception);
|
||||
}
|
||||
|
||||
private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
=> ReportOwn(e.ExceptionObject as Exception);
|
||||
|
||||
@@ -13,7 +13,7 @@ internal static class DrawingWobbleUpdateNotifier
|
||||
|
||||
public static void EnsureCheckedOnce()
|
||||
{
|
||||
if (Interlocked.Exchange(ref _started, 1) != 0)
|
||||
if (Application.Current is null || Interlocked.Exchange(ref _started, 1) != 0)
|
||||
return;
|
||||
_ = RunAsync();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ YukkuriMovieMaker4(YMM4)上で動作する、映像を手描きアニメの
|
||||
映像の各画素を位置ごとに決めた向きと量だけずらし、同じゆれを数フレーム保ってから次のゆれへ切り替えます。
|
||||
色や不透明度が変わる輪郭の近くだけを揺らすこともできるため、静止画や図形や文字の輪郭を手描きの動画のように動かせます。
|
||||
|
||||

|
||||

|
||||
|
||||
---
|
||||
|
||||
@@ -130,17 +130,20 @@ YukkuriMovieMaker4(YMM4)上で動作する、映像を手描きアニメの
|
||||
|
||||
## 不具合の報告
|
||||
|
||||
本プラグインは、想定していない例外が起きたときに、その内容を開発者へ自動で送信します。同意は求めず、常に送信します。
|
||||
本プラグインは、想定していない例外が起きたときに、その内容を開発者へ自動で送信します。同意は求めません。止める設定もありません。
|
||||
|
||||
送信する数には上限があります。YMM4 の 1 回の起動で送る報告は、YMM4-Telemetry で報告する別のプラグインと合わせて 20 件までです。例外の型と発生位置が同じ報告は 3 件までです。上限を超えた報告と、送信先から待つよう求められている間に起きた報告は、送信も退避もしません。
|
||||
|
||||
送信する情報は次のとおりです。
|
||||
|
||||
| 種類 | 内容 |
|
||||
|---|---|
|
||||
| 例外 | 型の完全名、メッセージ、スタックトレース |
|
||||
| 発生位置 | モジュール名、関数名、ファイル名、行番号 |
|
||||
| 発生位置 | モジュール名、関数名、ファイル名、行番号、プラグイン自身のコードかどうか |
|
||||
| プラグイン | アセンブリ名、バージョン |
|
||||
| 実行環境 | OS の名前とバージョン、.NET のバージョン、CPU のアーキテクチャ、論理プロセッサ数 |
|
||||
| 識別子 | YMM4 の起動ごとに決まるセッション識別子、報告ごとの識別子 |
|
||||
| 時刻 | 報告を作った時刻(UTC) |
|
||||
|
||||
メッセージとファイル名は、送信の前に置き換えを通します。置き換えるのは、Windows のユーザー名、ユーザーフォルダー、AppData のパス、マシン名、ドメイン名、メールアドレス、IPv4 アドレスです。送信元の IP アドレスは受信側へ渡す手前で取り除いています。
|
||||
|
||||
@@ -155,7 +158,7 @@ YukkuriMovieMaker4(YMM4)上で動作する、映像を手描きアニメの
|
||||
| 効果をかけないだけで済ませるもの | Direct2D がエフェクトを作れず、映像をそのまま通したとき |
|
||||
| 更新の確認の通信の失敗 | GitHub へ接続できない |
|
||||
|
||||
送信できなかった報告は YMM4 のユーザーフォルダーへ退避し、次回の起動時に送り直します。送信も再送も非同期に行うため、起動と描画が遅くなることはありません。
|
||||
送信できなかった報告は YMM4 のユーザーフォルダーへ退避します。次に YMM4 を起動したあと、本プラグインのエフェクトを生成するか、同じく YMM4-Telemetry で報告する別のプラグインが動き始めると、退避した報告を 1 回の起動で 10 件まで送り直します。送信も再送も非同期に行うため、起動と描画が遅くなることはありません。
|
||||
|
||||
実装は [YMM4-Telemetry](https://github.com/routersys/YMM4-Telemetry) をサブモジュールとして取り込んでいます。
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"test": {
|
||||
"runner": "Microsoft.Testing.Platform"
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする