開口に光の通る標本が無いときは効果を適用しない

・開口をほとんどふさぐ設定で例外が起きる不具合を修正-F
このコミットが含まれているのは:
routersys committed 2026-09-30 19:17:13 +09:00
1 親 cdbfc60672
コミット 2bec5d056b
3ファイル変更
+36 -10

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

+1 -1
ファイルの表示
@@ -138,7 +138,7 @@ internal sealed class WaveOpticsEffectProcessor : VideoEffectProcessorBase
itemHeight,
in parameters);
if (!_pipeline.TryGetVisibleBounds(canvasWidth, canvasHeight, in parameters, out var rect))
if (!_pipeline.HasKernel || !_pipeline.TryGetVisibleBounds(canvasWidth, canvasHeight, in parameters, out var rect))
{
_effect.Amount = 0f;
_amount = amount;
+14 -4
ファイルの表示
@@ -1,4 +1,5 @@
using System.Buffers;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -21,9 +22,17 @@ public sealed class FraunhoferPsfGenerator : IPsfGenerator
| OpticalCapabilities.DirectConvolution;
public PsfGenerationResult Generate(PsfDescriptor descriptor)
{
if (!TryGenerate(descriptor, out var result))
throw new InvalidOperationException();
return result;
}
public bool TryGenerate(PsfDescriptor descriptor, [NotNullWhen(true)] out PsfGenerationResult? result)
{
ArgumentNullException.ThrowIfNull(descriptor);
result = null;
var gridSize = descriptor.PupilGridSize;
var area = gridSize * gridSize;
var real = ArrayPool<double>.Shared.Rent(area);
@@ -33,13 +42,13 @@ public sealed class FraunhoferPsfGenerator : IPsfGenerator
{
var openSampleCount = BuildPupil(descriptor, real, imaginary);
if (openSampleCount == 0)
throw new InvalidOperationException();
return false;
FastFourierTransform.Forward2D(real, imaginary, gridSize, gridSize);
var fullEnergy = ComputeShiftedIntensity(real, imaginary, intensity, gridSize);
if (!double.IsFinite(fullEnergy) || fullEnergy <= 0)
throw new InvalidOperationException();
return false;
var wavelengthMicrometers = descriptor.WavelengthNanometers / 1000d;
var focalPlaneSamplePitch = wavelengthMicrometers * descriptor.FNumber * descriptor.PupilDiameterSamples / gridSize;
@@ -62,7 +71,7 @@ public sealed class FraunhoferPsfGenerator : IPsfGenerator
}
if (!double.IsFinite(rawKernelEnergy) || rawKernelEnergy <= 0)
throw new InvalidOperationException();
return false;
var psfKernel = new PsfKernel(kernelSize, kernel);
var diagnostics = new PsfDiagnostics(
@@ -70,7 +79,8 @@ public sealed class FraunhoferPsfGenerator : IPsfGenerator
focalPlaneSamplePitch,
rawKernelEnergy / fullEnergy,
Peak(psfKernel.Values.Span));
return new PsfGenerationResult(psfKernel, diagnostics);
result = new PsfGenerationResult(psfKernel, diagnostics);
return true;
}
finally
{
+21 -5
ファイルの表示
@@ -176,11 +176,19 @@ internal sealed class WaveOpticsPipeline : IDisposable
return false;
}
EnsureKernel(parameters.Psf);
if (!TryEnsureKernel(parameters.Psf))
{
_convolutionKey = null;
rect = default;
return false;
}
_convolutionKey = key;
return true;
}
internal bool HasKernel => _kernel.Rank > 0;
internal bool TryGetVisibleBounds(int canvasWidth, int canvasHeight, in Parameters parameters, out PixelRect rect)
{
rect = default;
@@ -219,16 +227,17 @@ internal sealed class WaveOpticsPipeline : IDisposable
in Parameters parameters)
{
EnsureCanvas(width, height);
EnsureKernel(parameters.Psf);
if (!TryEnsureKernel(parameters.Psf))
throw new InvalidOperationException();
_convolutionKey = null;
var sourceRect = new PixelRect(0, 0, width, height);
return _host.RecordFullPipeline(source, output, _weights, in sourceRect, in _kernel, parameters.Gain);
}
private void EnsureKernel(in PsfParameters psf)
private bool TryEnsureKernel(in PsfParameters psf)
{
if (_kernelPsf == psf)
return;
return HasKernel;
var pupilGridSize = WaveOpticsSettings.GetPupilGridSize(psf.Quality);
var aberration = new WavefrontAberration(
@@ -250,7 +259,13 @@ internal sealed class WaveOpticsPipeline : IDisposable
psf.BladeRotation,
psf.Obstruction,
aberration);
var result = _generator.Generate(descriptor);
if (!_generator.TryGenerate(descriptor, out var result))
{
_kernel = default;
_kernelPsf = psf;
return false;
}
var separable = SeparableKernel.Decompose(result.Kernel.Values.Span, result.Kernel.Size, WaveOpticsSettings.SeparableResidualRatio, WaveOpticsSettings.MaximumRank);
var size = separable.Size;
@@ -265,6 +280,7 @@ internal sealed class WaveOpticsPipeline : IDisposable
_weights.CopyFrom(_weightValues);
_kernel = new Kernel(separable.Rank, size / 2);
_kernelPsf = psf;
return true;
}
private void EnsureCanvas(int canvasWidth, int canvasHeight)