Skip to content

Interactive 2D wave optics simulator. Turn any image into a refractive scene, add sources, watch waves refract, diffract and interfere. Probes, intensity maps, video export.

C#

Exported sequences and stills are numbered by timeline frame, never by step

Alexander Graef251fc26845c1
diff --git a/CLAUDE.md b/CLAUDE.md
index 6696bea..56f25fc 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -149,7 +149,8 @@ FrameStore: native memory up to the budget, the rest in a temp file (%LOCALAPPDA
lattice came in disabled and ran black until 2026-10-16).
**Languages**: four string tables, live switch; converter output needs the language as an extra binding input.
- **Export**: field, intensity or both, a still of the shown frame, from the current run when fresh and full,
- else a run is made first; PNG/JPEG sequences, MPEG-1, OpenDML AVI, H.264 MP4 via Media Foundation (the only
+ else a run is made first; PNG/JPEG sequences (the files numbered by timeline frame, a range export from its first
+ frame, and a still padded the same way, `name_0655.png`; never a step number, 2026-10-19), MPEG-1, OpenDML AVI, H.264 MP4 via Media Foundation (the only
Windows-bound library piece besides WIC JPEG, which has an in-house fallback), QuickTime Animation MOV, and
**probe data as CSV** (2026-10-18: a probe's context menu in the tree and on its graph box; semicolons, decimal
point, a header row; a point probe one row per step, a line probe one row per frame; the full run like the
diff --git a/WaveDudeNext.WPF/MainWindow.Export.cs b/WaveDudeNext.WPF/MainWindow.Export.cs
index c07f5a3..66793e0 100644
--- a/WaveDudeNext.WPF/MainWindow.Export.cs
+++ b/WaveDudeNext.WPF/MainWindow.Export.cs
@@ -178,7 +178,9 @@ public partial class MainWindow
string suffix = field && intensity ? "" : field ? "_field" : "_intensity";
if (still)
{
- suffix += "_" + (stillFrame * Math.Max(1, Project.Simulation.VisualizeEvery)).ToString(System.Globalization.CultureInfo.InvariantCulture);
+ // the frame number, padded like a sequence's files, so a still of frame 655 is named as the sequence names it
+ // (2026-10-19, the user's rule; the step number stood here until then)
+ suffix += "_" + stillFrame.ToString("D" + ImageSequenceSink.MinDigits, System.Globalization.CultureInfo.InvariantCulture);
}
string chosen;
// the still's filter lists the sequence formats, which lead the full list in the same order
@@ -317,7 +319,7 @@ public partial class MainWindow
string output = !still && ExportFormats.IsSequence(format) ? ExportFormats.SequenceFolder(path) : path;
Func<IFrameSink> open = still
? () => ExportFormats.OpenStill(format, path, width, height, quality)
- : () => ExportFormats.Open(format, path, width, height, fps, quality, frameCount);
+ : () => ExportFormats.Open(format, path, width, height, fps, quality, frameCount, first);
targets.Add(new ExportTarget(exportLayer, output, open));
if (ExportFormats.IsData(format))
{
diff --git a/WaveDudeNext/Export/ExportFormat.cs b/WaveDudeNext/Export/ExportFormat.cs
index d8f7c09..ac3ace3 100644
--- a/WaveDudeNext/Export/ExportFormat.cs
+++ b/WaveDudeNext/Export/ExportFormat.cs
@@ -187,19 +187,20 @@ public static class ExportFormats
/// <param name="fps">Frame rate of a video.</param>
/// <param name="quality">1..100 for the lossy formats.</param>
/// <param name="plannedFrames">How many frames will come at most (the AVI sizes its indexes by it, a sequence the width of its frame numbers).</param>
+ /// <param name="firstFrame">The timeline frame number of the first frame: a sequence's files are numbered from it (2026-10-19).</param>
/// <exception cref="NotSupportedException">The format cannot carry the size, or MP4 is not available here.</exception>
- public static IFrameSink Open(ExportFormat format, string path, int width, int height, int fps, int quality, int plannedFrames)
+ public static IFrameSink Open(ExportFormat format, string path, int width, int height, int fps, int quality, int plannedFrames, int firstFrame = 0)
{
switch (format)
{
case ExportFormat.Png:
return new ImageSequenceSink(SequenceFolder(path), Path.GetFileNameWithoutExtension(path), ".png", width, height,
- () => (stream, frame) => PngEncoder.Write(stream, frame.Span, width, height), SequenceWorkers(encoderIsParallel: false), plannedFrames);
+ () => (stream, frame) => PngEncoder.Write(stream, frame.Span, width, height), SequenceWorkers(encoderIsParallel: false), plannedFrames, firstFrame);
case ExportFormat.Jpeg:
return new ImageSequenceSink(SequenceFolder(path), Path.GetFileNameWithoutExtension(path), ".jpg", width, height,
- () => JpegWriter(width, height, quality), SequenceWorkers(encoderIsParallel: PreferredJpeg == null), plannedFrames);
+ () => JpegWriter(width, height, quality), SequenceWorkers(encoderIsParallel: PreferredJpeg == null), plannedFrames, firstFrame);
case ExportFormat.Exr:
- return ExrSink.Sequence(SequenceFolder(path), Path.GetFileNameWithoutExtension(path), width, height, plannedFrames);
+ return ExrSink.Sequence(SequenceFolder(path), Path.GetFileNameWithoutExtension(path), width, height, plannedFrames, firstFrame);
case ExportFormat.Mpeg1:
return new Mpeg1Writer(path, width, height, fps, quality);
case ExportFormat.Avi:
diff --git a/WaveDudeNext/Export/ExrWriter.cs b/WaveDudeNext/Export/ExrWriter.cs
index c62861a..0b5179a 100644
--- a/WaveDudeNext/Export/ExrWriter.cs
+++ b/WaveDudeNext/Export/ExrWriter.cs
@@ -163,28 +163,30 @@ public sealed class ExrSink : IFrameSink
private readonly string _folder;
private readonly string _baseName;
private readonly int _digits;
+ private readonly int _firstFrame;
private bool _closed;
- private ExrSink(string? stillPath, string folder, string baseName, int width, int height, int plannedFrames)
+ private ExrSink(string? stillPath, string folder, string baseName, int width, int height, int plannedFrames, int firstFrame)
{
ArgumentOutOfRangeException.ThrowIfLessThan(width, 1);
ArgumentOutOfRangeException.ThrowIfLessThan(height, 1);
_stillPath = stillPath;
_folder = folder;
_baseName = baseName;
- _digits = Math.Max(4, Math.Max(0, plannedFrames - 1).ToString(CultureInfo.InvariantCulture).Length);
+ _firstFrame = Math.Max(0, firstFrame);
+ _digits = Math.Max(4, Math.Max(0, _firstFrame + plannedFrames - 1).ToString(CultureInfo.InvariantCulture).Length);
Width = width;
Height = height;
Directory.CreateDirectory(folder);
}
- /// <summary>A sequence in <paramref name="folder"/> (created when missing) named <paramref name="baseName"/><c>_0000.exr</c> and on.</summary>
- public static ExrSink Sequence(string folder, string baseName, int width, int height, int plannedFrames) =>
- new(null, folder, baseName, width, height, plannedFrames);
+ /// <summary>A sequence in <paramref name="folder"/> (created when missing) named <paramref name="baseName"/><c>_0000.exr</c> and on, or from <paramref name="firstFrame"/>, the timeline frame number of the first frame (2026-10-19).</summary>
+ public static ExrSink Sequence(string folder, string baseName, int width, int height, int plannedFrames, int firstFrame = 0) =>
+ new(null, folder, baseName, width, height, plannedFrames, firstFrame);
/// <summary>One file at <paramref name="path"/>; a second frame is refused.</summary>
public static ExrSink Still(string path, int width, int height) =>
- new(path, Path.GetDirectoryName(Path.GetFullPath(path)) ?? "", Path.GetFileNameWithoutExtension(path), width, height, 1);
+ new(path, Path.GetDirectoryName(Path.GetFullPath(path)) ?? "", Path.GetFileNameWithoutExtension(path), width, height, 1, 0);
/// <inheritdoc/>
public int Width { get; }
@@ -202,7 +204,7 @@ public sealed class ExrSink : IFrameSink
public bool WantsHalves => true;
/// <summary>The file of frame <paramref name="index"/> of a sequence.</summary>
- public string PathOf(int index) => Path.Combine(_folder, _baseName + "_" + index.ToString("D" + _digits, CultureInfo.InvariantCulture) + ".exr");
+ public string PathOf(int index) => Path.Combine(_folder, _baseName + "_" + (_firstFrame + index).ToString("D" + _digits, CultureInfo.InvariantCulture) + ".exr");
/// <inheritdoc/>
public void Add(ReadOnlySpan<int> pixels) => throw new NotSupportedException("An OpenEXR file holds the store's halves, not rendered pixels.");
diff --git a/WaveDudeNext/Export/ImageSequenceSink.cs b/WaveDudeNext/Export/ImageSequenceSink.cs
index 19e77e0..9453500 100644
--- a/WaveDudeNext/Export/ImageSequenceSink.cs
+++ b/WaveDudeNext/Export/ImageSequenceSink.cs
@@ -52,8 +52,9 @@ public sealed class ImageSequenceSink : IFrameSink
/// <param name="height">Frame height in pixels.</param>
/// <param name="makeEncoder">Makes an encoder that writes one frame (packed BGRA32, width × height) to a stream; called once per worker.</param>
/// <param name="workers">Frames encoded at once; 1 encodes on the caller's thread.</param>
- /// <param name="plannedFrames">How many frames will come at most; decides the width of the frame numbers (<see cref="Digits"/>).</param>
- public ImageSequenceSink(string folder, string baseName, string extension, int width, int height, Func<Action<Stream, ReadOnlyMemory<int>>> makeEncoder, int workers = 1, int plannedFrames = 0)
+ /// <param name="plannedFrames">How many frames will come at most; with <paramref name="firstFrame"/> it decides the width of the frame numbers (<see cref="Digits"/>).</param>
+ /// <param name="firstFrame">The number of the first file: the timeline frame number of the first frame added, so a range export is numbered as the timeline is (2026-10-19, the user's rule: the file number is the frame number, never a step or a count from zero).</param>
+ public ImageSequenceSink(string folder, string baseName, string extension, int width, int height, Func<Action<Stream, ReadOnlyMemory<int>>> makeEncoder, int workers = 1, int plannedFrames = 0, int firstFrame = 0)
{
Folder = folder;
BaseName = baseName;
@@ -61,7 +62,8 @@ public sealed class ImageSequenceSink : IFrameSink
Width = width;
Height = height;
Workers = Math.Max(1, workers);
- Digits = Math.Max(MinDigits, Math.Max(0, plannedFrames - 1).ToString(System.Globalization.CultureInfo.InvariantCulture).Length);
+ FirstFrame = Math.Max(0, firstFrame);
+ Digits = Math.Max(MinDigits, Math.Max(0, FirstFrame + plannedFrames - 1).ToString(System.Globalization.CultureInfo.InvariantCulture).Length);
_makeEncoder = makeEncoder;
Directory.CreateDirectory(folder);
if (Workers == 1)
@@ -96,9 +98,12 @@ public sealed class ImageSequenceSink : IFrameSink
/// <summary>Frames encoded at once.</summary>
public int Workers { get; }
- /// <summary>Digits of the frame number in every file name of this sequence: <see cref="MinDigits"/>, or more when the planned frame count needs them.</summary>
+ /// <summary>Digits of the frame number in every file name of this sequence: <see cref="MinDigits"/>, or more when the last planned frame number needs them.</summary>
public int Digits { get; }
+ /// <summary>The frame number of the first file; the files count on from it.</summary>
+ public int FirstFrame { get; }
+
/// <inheritdoc/>
public int FrameCount { get; private set; }
@@ -106,7 +111,7 @@ public sealed class ImageSequenceSink : IFrameSink
public string Output => Folder;
/// <summary>The path of frame <paramref name="index"/>.</summary>
- public string PathOf(int index) => Path.Combine(Folder, BaseName + "_" + index.ToString("D" + Digits, System.Globalization.CultureInfo.InvariantCulture) + Extension);
+ public string PathOf(int index) => Path.Combine(Folder, BaseName + "_" + (FirstFrame + index).ToString("D" + Digits, System.Globalization.CultureInfo.InvariantCulture) + Extension);
/// <inheritdoc/>
public void Add(ReadOnlySpan<int> pixels)
diff --git a/_tools/library_check/ExportChecks.cs b/_tools/library_check/ExportChecks.cs
index 63ebc96..4bbbf05 100644
--- a/_tools/library_check/ExportChecks.cs
+++ b/_tools/library_check/ExportChecks.cs
@@ -445,11 +445,11 @@ internal static class ExportChecks
string exrPath = Path.Combine(folder, "data.exr");
var targets = new List<ExportTarget>
{
- new(fieldLayer, ExportFormats.SequenceFolder(seqPath), () => ExportFormats.Open(ExportFormat.Png, seqPath, 64, 48, 30, 70, 6)),
+ new(fieldLayer, ExportFormats.SequenceFolder(seqPath), () => ExportFormats.Open(ExportFormat.Png, seqPath, 64, 48, 30, 70, 6, 2)),
new(intensityLayer, aviPath, () => ExportFormats.Open(ExportFormat.Avi, aviPath, 64, 48, 30, 70, 6)),
// a data target beside the pictures: the job hands it the stored halves, nothing rendered or decorated
new(new ExportLayer(FrameLayer.Field, lut, 30f, null, 0, (_, _) => throw new InvalidOperationException("a data target is never decorated")),
- ExportFormats.SequenceFolder(exrPath), () => ExportFormats.Open(ExportFormat.Exr, exrPath, 64, 48, 30, 70, 6)),
+ ExportFormats.SequenceFolder(exrPath), () => ExportFormats.Open(ExportFormat.Exr, exrPath, 64, 48, 30, 70, 6, 2)),
};
var job = new ExportJob(store, 2, 7, targets, null);
var states = new List<ExportState>();
@@ -468,21 +468,22 @@ internal static class ExportChecks
check(states.SequenceEqual([ExportState.Running, ExportState.Completed]) && job.FramesDone == 6 && job.FrameCount == 6, "job: Running then Completed, 6 of 6 frames");
check(decorated.SequenceEqual([2, 3, 4, 5, 6, 7]), "job: the decoration saw frames 2 to 7 in order");
string[] files = Directory.GetFiles(Path.Combine(folder, "field"));
- check(files.Length == 6 && File.Exists(Path.Combine(folder, "field", "field_0005.png")), "job: six PNGs, field_0000 to field_0005");
+ check(files.Length == 6 && File.Exists(Path.Combine(folder, "field", "field_0002.png")) && File.Exists(Path.Combine(folder, "field", "field_0007.png")) && !File.Exists(Path.Combine(folder, "field", "field_0000.png")),
+ "job: six PNGs numbered by timeline frame, field_0002 to field_0007");
// the first file is frame 2 rendered with the same LUT and gain, plus the decoration
var values = new Half[64 * 48];
var expected = new int[64 * 48];
store.CopyLayer(2, FrameLayer.Field, values);
FrameRenderer.RenderField(values, 64, 48, lut, 30f, expected);
expected[0] = unchecked((int)0xFFFF0000);
- int[]? first = DecodePng(File.ReadAllBytes(Path.Combine(folder, "field", "field_0000.png")), 64, 48);
- check(first != null && first.SequenceEqual(expected), "job: field_0000.png is frame 2 as the renderer colours it, with the decoration");
+ int[]? first = DecodePng(File.ReadAllBytes(Path.Combine(folder, "field", "field_0002.png")), 64, 48);
+ check(first != null && first.SequenceEqual(expected), "job: field_0002.png is frame 2 as the renderer colours it, with the decoration");
AviWalk walk = WalkAvi(File.ReadAllBytes(aviPath));
check(walk.Frames == 6 && walk.TotalInDmlh == 6 && walk.EndsAtFileEnd, "job: the intensity AVI holds 6 frames");
- string exrFirst = Path.Combine(folder, "data", "data_0000.exr");
+ string exrFirst = Path.Combine(folder, "data", "data_0002.exr");
Half[]? exrValues = File.Exists(exrFirst) ? ReadExr(File.ReadAllBytes(exrFirst), 64, 48, out _) : null;
check(Directory.GetFiles(Path.Combine(folder, "data")).Length == 6 && exrValues != null && MemoryMarshal.AsBytes(exrValues.AsSpan()).SequenceEqual(MemoryMarshal.AsBytes(values.AsSpan())),
- "job: data_0000.exr holds frame 2's stored halves bit for bit, undecorated, beside the pictures");
+ "job: data_0002.exr holds frame 2's stored halves bit for bit, undecorated, beside the pictures");
// cancelled: a slow decoration lets the cancel land after the first frame
using var started = new ManualResetEventSlim();
diff --git a/_tools/ui_check/ExportCheck.ps1 b/_tools/ui_check/ExportCheck.ps1
index 1066535..b5558cc 100644
--- a/_tools/ui_check/ExportCheck.ps1
+++ b/_tools/ui_check/ExportCheck.ps1
@@ -117,9 +117,9 @@ try {
for ($i = 0; $i -lt 2 -and (PopupFocusedId) -ne "ContextExportFrame"; $i++) { Step "Down" $VK_DOWN 120 }
Check "'Export this frame...' is the context menu's first entry" ((PopupFocusedId) -eq "ContextExportFrame") (PopupFocusedId)
Step "Enter" $VK_RETURN 200
- $still = Join-Path $out "tiny_field_0.png"
- Check "the shown frame lands as tiny_field_0.png" (WaitFor { Test-Path $still } 20000) ((Find "StatusMessage").Current.Name)
- Check "and is a PNG, with the status bar reporting one frame" ((IsPng $still) -and (WaitFor { (Find "StatusMessage").Current.Name -like "Exported 1 frames to *tiny_field_0.png*" } 5000)) ((Find "StatusMessage").Current.Name)
+ $still = Join-Path $out "tiny_field_0000.png"
+ Check "the shown frame lands as tiny_field_0000.png (the frame number, padded like a sequence's files)" (WaitFor { Test-Path $still } 20000) ((Find "StatusMessage").Current.Name)
+ Check "and is a PNG, with the status bar reporting one frame" ((IsPng $still) -and (WaitFor { (Find "StatusMessage").Current.Name -like "Exported 1 frames to *tiny_field_0000.png*" } 5000)) ((Find "StatusMessage").Current.Name)
Check "the app never took the foreground" ((Foreground) -ne "APP") (Foreground)
}
finally {