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#
Export formats: videos first in the dialog, the filter decides the format, and a QuickTime movie with the PNG codec
Alexander Graef0921f8b40d21
diff --git a/CLAUDE.md b/CLAUDE.mdindex 0db123e..fdac53b 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -153,9 +153,12 @@ FrameStore: native memory up to the budget, the rest in a temp file (%LOCALAPPDAlattice 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 (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+ else a run is made first; in the dialog's order (2026-10-19) H.264 MP4 via Media Foundation (the only+ Windows-bound library piece besides WIC JPEG, which has an in-house fallback), MPEG-1, OpenDML AVI, QuickTime+ MOV with the Animation codec or the PNG codec (2026-10-19, each sample a PNG, for a lossless hand-over to Resolve,+ Premiere and Final Cut; both share `.mov`, so the dialog's filter decides the format and the extension follows it,+ while a scripted path goes by its extension, `.mov` meaning Animation), 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), and**probe data as CSV** (2026-10-18: a probe's context menu in the tree and on its graph box; semicolons, decimalpoint, a header row; a point probe one row per step, a line probe one row per frame; the full run like thepictures, started first when needed),diff --git a/WaveDudeNext.WPF/MainWindow.Export.cs b/WaveDudeNext.WPF/MainWindow.Export.csindex 66793e0..f236c0a 100644--- a/WaveDudeNext.WPF/MainWindow.Export.cs+++ b/WaveDudeNext.WPF/MainWindow.Export.cs@@ -183,8 +183,11 @@ public partial class MainWindowsuffix += "_" + 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- int filterIndex = still ? Math.Clamp(Settings.Default.ExportFilterIndex + 1, 1, ExportFormats.All.Count(ExportFormats.IsSequence)) : Math.Clamp(Settings.Default.ExportFilterIndex + 1, 1, ExportFormats.All.Length);+ // the remembered filter is an index into the full list; the still's filter lists the sequence formats alone, so a+ // remembered video means PNG there+ ExportFormat[] formats = still ? ExportFormats.Stills : ExportFormats.All;+ ExportFormat remembered = ExportFormats.All[Math.Clamp(Settings.Default.ExportFilterIndex, 0, ExportFormats.All.Length - 1)];+ int filterIndex = Math.Max(0, Array.IndexOf(formats, remembered)) + 1;string? scripted = Environment.GetEnvironmentVariable("WAVEDUDE_EXPORT_PATH");if (!string.IsNullOrEmpty(scripted)){@@ -200,7 +203,7 @@ public partial class MainWindowFilter = (string)FindResource(still ? "ExportDialogFilterStill" : "ExportDialogFilter"),FilterIndex = filterIndex,AddExtension = true,- DefaultExt = ExportFormats.Extension(ExportFormat.Png),+ DefaultExt = ExportFormats.Extension(formats[filterIndex - 1]),FileName = ProjectName() + suffix,InitialDirectory = ProjectFolder ?? (Directory.Exists(Settings.Default.LastExportFolder) ? Settings.Default.LastExportFolder : ""),};@@ -217,12 +220,18 @@ public partial class MainWindow}Settings.Default.LastExportFolder = Path.GetDirectoryName(chosen) ?? "";}- ExportFormat format = ExportFormats.FromPath(chosen) ?? ExportFormats.All[Math.Clamp(filterIndex - 1, 0, ExportFormats.All.Length - 1)];+ // the filter the user chose is the format, whatever extension was typed (the two MOV formats share theirs); a+ // scripted path has no filter and says its format by its extension, a .mov meaning the Animation codec+ ExportFormat format = formats[Math.Clamp(filterIndex - 1, 0, formats.Length - 1)];+ if (!string.IsNullOrEmpty(scripted))+ {+ format = ExportFormats.FromPath(chosen) ?? format;+ }if (still && !ExportFormats.IsSequence(format)){format = ExportFormat.Png;}- if (ExportFormats.FromPath(chosen) != format)+ if (!ExportFormats.Accepts(format, chosen)){chosen = Path.ChangeExtension(chosen, ExportFormats.Extension(format));}diff --git a/WaveDudeNext.WPF/Strings/Strings.DE.xaml b/WaveDudeNext.WPF/Strings/Strings.DE.xamlindex 549b962..c7dc351 100644--- a/WaveDudeNext.WPF/Strings/Strings.DE.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.DE.xaml@@ -204,7 +204,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="Ready">Bereit</s:String><!-- export: the Save dialog, the status bar line ({0} frames done, {1} frames) and the questions -->- <s:String x:Key="ExportDialogFilter">PNG-Bildfolge (*.png)|*.png|JPEG-Bildfolge (*.jpg)|*.jpg|OpenEXR-Bildfolge, 16-Bit-Gleitkommadaten (*.exr)|*.exr|MPEG-1-Video (*.mpg)|*.mpg|AVI-Video, unkomprimiert (*.avi)|*.avi|MP4-Video, H.264 (*.mp4)|*.mp4|QuickTime-Film, Animation-Codec, verlustfrei (*.mov)|*.mov</s:String>+ <s:String x:Key="ExportDialogFilter">MP4-Video, H.264 (*.mp4)|*.mp4|MPEG-1-Video (*.mpg)|*.mpg|AVI-Video, unkomprimiert (*.avi)|*.avi|QuickTime-Film, Animation-Codec, verlustfrei (*.mov)|*.mov|QuickTime-Film, PNG-Codec, verlustfrei (*.mov)|*.mov|PNG-Bildfolge (*.png)|*.png|JPEG-Bildfolge (*.jpg)|*.jpg|OpenEXR-Bildfolge, 16-Bit-Gleitkommadaten (*.exr)|*.exr</s:String><s:String x:Key="ExportDialogTitleField">Feld exportieren</s:String><s:String x:Key="ExportDialogTitleIntensity">Intensität exportieren</s:String><s:String x:Key="ExportDialogTitleBoth">Feld und Intensität exportieren</s:String>diff --git a/WaveDudeNext.WPF/Strings/Strings.EN.xaml b/WaveDudeNext.WPF/Strings/Strings.EN.xamlindex 26ff185..5aa348e 100644--- a/WaveDudeNext.WPF/Strings/Strings.EN.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.EN.xaml@@ -206,7 +206,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="Ready">Ready</s:String><!-- export: the Save dialog, the status bar line ({0} frames done, {1} frames) and the questions -->- <s:String x:Key="ExportDialogFilter">PNG image sequence (*.png)|*.png|JPEG image sequence (*.jpg)|*.jpg|OpenEXR image sequence, 16-bit float data (*.exr)|*.exr|MPEG-1 video (*.mpg)|*.mpg|AVI video, uncompressed (*.avi)|*.avi|MP4 video, H.264 (*.mp4)|*.mp4|QuickTime movie, Animation codec, lossless (*.mov)|*.mov</s:String>+ <s:String x:Key="ExportDialogFilter">MP4 video, H.264 (*.mp4)|*.mp4|MPEG-1 video (*.mpg)|*.mpg|AVI video, uncompressed (*.avi)|*.avi|QuickTime movie, Animation codec, lossless (*.mov)|*.mov|QuickTime movie, PNG codec, lossless (*.mov)|*.mov|PNG image sequence (*.png)|*.png|JPEG image sequence (*.jpg)|*.jpg|OpenEXR image sequence, 16-bit float data (*.exr)|*.exr</s:String><s:String x:Key="ExportDialogTitleField">Export the field</s:String><s:String x:Key="ExportDialogTitleIntensity">Export the intensity</s:String><s:String x:Key="ExportDialogTitleBoth">Export the field and the intensity</s:String>diff --git a/WaveDudeNext.WPF/Strings/Strings.FR.xaml b/WaveDudeNext.WPF/Strings/Strings.FR.xamlindex f6562be..413601f 100644--- a/WaveDudeNext.WPF/Strings/Strings.FR.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.FR.xaml@@ -204,7 +204,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="Ready">Prêt</s:String><!-- export: the Save dialog, the status bar line ({0} frames done, {1} frames) and the questions -->- <s:String x:Key="ExportDialogFilter">Séquence d'images PNG (*.png)|*.png|Séquence d'images JPEG (*.jpg)|*.jpg|Séquence d'images OpenEXR, données flottantes 16 bits (*.exr)|*.exr|Vidéo MPEG-1 (*.mpg)|*.mpg|Vidéo AVI non compressée (*.avi)|*.avi|Vidéo MP4, H.264 (*.mp4)|*.mp4|Film QuickTime, codec Animation, sans perte (*.mov)|*.mov</s:String>+ <s:String x:Key="ExportDialogFilter">Vidéo MP4, H.264 (*.mp4)|*.mp4|Vidéo MPEG-1 (*.mpg)|*.mpg|Vidéo AVI non compressée (*.avi)|*.avi|Film QuickTime, codec Animation, sans perte (*.mov)|*.mov|Film QuickTime, codec PNG, sans perte (*.mov)|*.mov|Séquence d'images PNG (*.png)|*.png|Séquence d'images JPEG (*.jpg)|*.jpg|Séquence d'images OpenEXR, données flottantes 16 bits (*.exr)|*.exr</s:String><s:String x:Key="ExportDialogTitleField">Exporter le champ</s:String><s:String x:Key="ExportDialogTitleIntensity">Exporter l'intensité</s:String><s:String x:Key="ExportDialogTitleBoth">Exporter le champ et l'intensité</s:String>diff --git a/WaveDudeNext.WPF/Strings/Strings.NL.xaml b/WaveDudeNext.WPF/Strings/Strings.NL.xamlindex 2ee2b84..a7e2ea7 100644--- a/WaveDudeNext.WPF/Strings/Strings.NL.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.NL.xaml@@ -204,7 +204,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="Ready">Gereed</s:String><!-- export: the Save dialog, the status bar line ({0} frames done, {1} frames) and the questions -->- <s:String x:Key="ExportDialogFilter">PNG-beeldreeks (*.png)|*.png|JPEG-beeldreeks (*.jpg)|*.jpg|OpenEXR-beeldreeks, 16-bits drijvendekommagegevens (*.exr)|*.exr|MPEG-1-video (*.mpg)|*.mpg|AVI-video, ongecomprimeerd (*.avi)|*.avi|MP4-video, H.264 (*.mp4)|*.mp4|QuickTime-film, Animation-codec, verliesvrij (*.mov)|*.mov</s:String>+ <s:String x:Key="ExportDialogFilter">MP4-video, H.264 (*.mp4)|*.mp4|MPEG-1-video (*.mpg)|*.mpg|AVI-video, ongecomprimeerd (*.avi)|*.avi|QuickTime-film, Animation-codec, verliesvrij (*.mov)|*.mov|QuickTime-film, PNG-codec, verliesvrij (*.mov)|*.mov|PNG-beeldreeks (*.png)|*.png|JPEG-beeldreeks (*.jpg)|*.jpg|OpenEXR-beeldreeks, 16-bits drijvendekommagegevens (*.exr)|*.exr</s:String><s:String x:Key="ExportDialogTitleField">Veld exporteren</s:String><s:String x:Key="ExportDialogTitleIntensity">Intensiteit exporteren</s:String><s:String x:Key="ExportDialogTitleBoth">Veld en intensiteit exporteren</s:String>diff --git a/WaveDudeNext/Export/ExportFormat.cs b/WaveDudeNext/Export/ExportFormat.csindex ac3ace3..1d3c862 100644--- a/WaveDudeNext/Export/ExportFormat.cs+++ b/WaveDudeNext/Export/ExportFormat.cs@@ -17,23 +17,25 @@namespace WaveDudeNext.Export;-/// <summary>The export formats, in the order of the Save dialog's filter.</summary>+/// <summary>The export formats, in the order of the Save dialog's filter: the videos first, then the sequences (the user's order, 2026-10-19).</summary>public enum ExportFormat{- /// <summary>A PNG per frame in a folder of its own; lossless.</summary>- Png,- /// <summary>A JPEG per frame in a folder of its own; the quality setting applies.</summary>- Jpeg,- /// <summary>An OpenEXR file per frame in a folder of its own: the stored 16-bit floats themselves, one channel, uncompressed; data, not a rendered picture (2026-10-18).</summary>- Exr,+ /// <summary>An H.264 MP4 through the Media Foundation of Windows; the quality setting applies.</summary>+ Mp4,/// <summary>An MPEG-1 program stream of I-pictures (<c>.mpg</c>); the quality setting and the nearest standard frame rate apply.</summary>Mpeg1,/// <summary>An uncompressed AVI with OpenDML indexes; lossless, large.</summary>Avi,- /// <summary>An H.264 MP4 through the Media Foundation of Windows; the quality setting applies.</summary>- Mp4,/// <summary>A QuickTime movie with the Animation codec: lossless RGB, run-length coded, what the editing suites open natively.</summary>Mov,+ /// <summary>A QuickTime movie with the PNG codec: lossless RGB, each frame a PNG, far smaller than the Animation codec on a wave picture; for Resolve, Premiere and Final Cut (2026-10-19). Shares the extension with <see cref="Mov"/>: the dialog's filter tells them apart.</summary>+ MovPng,+ /// <summary>A PNG per frame in a folder of its own; lossless.</summary>+ Png,+ /// <summary>A JPEG per frame in a folder of its own; the quality setting applies.</summary>+ Jpeg,+ /// <summary>An OpenEXR file per frame in a folder of its own: the stored 16-bit floats themselves, one channel, uncompressed; data, not a rendered picture (2026-10-18).</summary>+ Exr,}/// <summary>What is known about each <see cref="ExportFormat"/>: extensions, whether it is a sequence, how to open its sink.</summary>@@ -114,34 +116,58 @@ public static class ExportFormats};}- /// <summary>The formats in filter order.</summary>- public static readonly ExportFormat[] All = [ExportFormat.Png, ExportFormat.Jpeg, ExportFormat.Exr, ExportFormat.Mpeg1, ExportFormat.Avi, ExportFormat.Mp4, ExportFormat.Mov];+ /// <summary>The formats in filter order: the videos, then the sequences.</summary>+ public static readonly ExportFormat[] All = [ExportFormat.Mp4, ExportFormat.Mpeg1, ExportFormat.Avi, ExportFormat.Mov, ExportFormat.MovPng, ExportFormat.Png, ExportFormat.Jpeg, ExportFormat.Exr];++ /// <summary>The formats a still can take, in the order of the still's filter: the sequence formats.</summary>+ public static readonly ExportFormat[] Stills = [ExportFormat.Png, ExportFormat.Jpeg, ExportFormat.Exr];- /// <summary>The file extension with its dot.</summary>- public static string Extension(ExportFormat format) => format switch+ /// <summary>The file extensions a format accepts, with their dots, the first the one it writes; both MOV formats take <c>.mov</c>.</summary>+ public static string[] Extensions(ExportFormat format) => format switch{- ExportFormat.Png => ".png",- ExportFormat.Jpeg => ".jpg",- ExportFormat.Exr => ".exr",- ExportFormat.Mpeg1 => ".mpg",- ExportFormat.Avi => ".avi",- ExportFormat.Mp4 => ".mp4",- ExportFormat.Mov => ".mov",+ ExportFormat.Png => [".png"],+ ExportFormat.Jpeg => [".jpg", ".jpeg"],+ ExportFormat.Exr => [".exr"],+ ExportFormat.Mpeg1 => [".mpg", ".mpeg", ".m1v"],+ ExportFormat.Avi => [".avi"],+ ExportFormat.Mp4 => [".mp4", ".m4v"],+ ExportFormat.Mov or ExportFormat.MovPng => [".mov", ".qt"],_ => throw new ArgumentOutOfRangeException(nameof(format)),};- /// <summary>The format of a path by its extension (<c>.jpeg</c> and <c>.mpeg</c> count too), or null.</summary>- public static ExportFormat? FromPath(string path) => Path.GetExtension(path).ToLowerInvariant() switch+ /// <summary>The file extension a format writes, with its dot.</summary>+ public static string Extension(ExportFormat format) => Extensions(format)[0];++ /// <summary>Whether the path's extension is one the format accepts (case does not matter).</summary>+ public static bool Accepts(ExportFormat format, string path){- ".png" => ExportFormat.Png,- ".jpg" or ".jpeg" => ExportFormat.Jpeg,- ".exr" => ExportFormat.Exr,- ".mpg" or ".mpeg" or ".m1v" => ExportFormat.Mpeg1,- ".avi" => ExportFormat.Avi,- ".mp4" or ".m4v" => ExportFormat.Mp4,- ".mov" or ".qt" => ExportFormat.Mov,- _ => null,- };+ string extension = Path.GetExtension(path);+ foreach (string known in Extensions(format))+ {+ if (string.Equals(known, extension, StringComparison.OrdinalIgnoreCase))+ {+ return true;+ }+ }+ return false;+ }++ /// <summary>+ /// The first format in filter order that accepts the path's extension, or null. The extension alone cannot tell+ /// the two MOV formats apart (a <c>.mov</c> means the Animation codec here): the dialog's filter decides the+ /// format, this serves a scripted path (2026-10-19).+ /// </summary>+ public static ExportFormat? FromPath(string path)+ {+ foreach (ExportFormat format in All)+ {+ if (Accepts(format, path))+ {+ return format;+ }+ }+ return null;+ }/// <summary>Whether the format writes one file per frame (these are also the formats a still can take).</summary>public static bool IsSequence(ExportFormat format) => format is ExportFormat.Png or ExportFormat.Jpeg or ExportFormat.Exr;@@ -212,7 +238,9 @@ public static class ExportFormats}return new Mp4Writer(path, width, height, fps, quality);case ExportFormat.Mov:- return new MovAnimationWriter(path, width, height, fps, plannedFrames);+ return new MovWriter(path, width, height, fps, plannedFrames);+ case ExportFormat.MovPng:+ return new MovWriter(path, width, height, fps, plannedFrames, MovCodec.Png);default:throw new ArgumentOutOfRangeException(nameof(format));}diff --git a/WaveDudeNext/Export/MovAnimationWriter.cs b/WaveDudeNext/Export/MovWriter.cssimilarity index 86%rename from WaveDudeNext/Export/MovAnimationWriter.csrename to WaveDudeNext/Export/MovWriter.csindex 0f9a2f7..6c4ca49 100644--- a/WaveDudeNext/Export/MovAnimationWriter.cs+++ b/WaveDudeNext/Export/MovWriter.cs@@ -20,12 +20,22 @@ using System.Text;namespace WaveDudeNext.Export;+/// <summary>The video codec of a <see cref="MovWriter"/>.</summary>+public enum MovCodec+{+ /// <summary>The Animation codec (<c>rle </c>): 24-bit RGB, run-length coded, every frame a key frame.</summary>+ Animation,+ /// <summary>The PNG codec (<c>png </c>): every sample a whole PNG file of the frame, deflate-coded, which packs a wave picture far tighter than runs do (2026-10-19, the user's request, for a lossless hand-over to Resolve, Premiere and Final Cut).</summary>+ Png,+}+/// <summary>/// Writes a QuickTime movie (<c>.mov</c>) with the Animation codec (<c>rle </c>, 24-bit RGB, run-length/// coded, mathematically lossless, every frame a key frame), the lossless RGB format Final Cut, Premiere,/// After Effects and Resolve all decode without anything installed (2026-10-15, the user's choice: one/// lossless single-file format per container, this one for the editors, the uncompressed AVI for the-/// Windows tools). In-house, no dependencies. The <c>moov</c> with the sample tables comes first: its size+/// Windows tools), or with the PNG codec (<c>png </c>, <see cref="MovCodec"/>), the same movie with each sample a+/// PNG file from <see cref="PngEncoder"/>. In-house, no dependencies. The <c>moov</c> with the sample tables comes first: its size/// follows from the planned frame count (a fixed part plus 12 bytes a frame), so that much is reserved/// after <c>ftyp</c> as a <c>free</c> atom, the samples go into one <c>mdat</c> behind it as they come, and at/// close the reservation is overwritten with the real <c>moov</c> and a <c>free</c> atom for the rest (the@@ -34,12 +44,12 @@ namespace WaveDudeNext.Export;/// offsets are 64-bit from the start (<c>co64</c>), so the file may grow past 4 GB. One thread at a time./// </summary>/// <remarks>-/// A frame: a 4-byte big-endian length of the whole frame data, a 2-byte header of 0 (a full frame), then+/// An Animation frame: a 4-byte big-endian length of the whole frame data, a 2-byte header of 0 (a full frame), then/// per row a skip code (1 = no skip), run codes (a positive count n: n literal RGB pixels follow; a negative/// count −n: one RGB pixel follows, repeated n times; 0: another skip code follows) and −1 at the row's end./// That is what every <c>rle </c> decoder expects (ffmpeg's <c>qtrle</c>, QuickTime's own)./// </remarks>-public sealed class MovAnimationWriter : IFrameSink+public sealed class MovWriter : IFrameSink{/// <summary>The moov's bytes besides the two per-frame tables (measured on the atoms as written, with slack).</summary>private const int MoovFixedBytes = 1024;@@ -59,10 +69,12 @@ public sealed class MovAnimationWriter : IFrameSink/// <param name="height">Frame height in pixels.</param>/// <param name="framesPerSecond">Playback rate; the movie's time scale.</param>/// <param name="plannedFrames">How many frames will come at most, which sizes the reservation for the leading <c>moov</c>; 0 puts it at the end.</param>- public MovAnimationWriter(string path, int width, int height, int framesPerSecond, int plannedFrames = 0)+ /// <param name="codec">The video codec; the Animation codec by default.</param>+ public MovWriter(string path, int width, int height, int framesPerSecond, int plannedFrames = 0, MovCodec codec = MovCodec.Animation){Width = width;Height = height;+ Codec = codec;FramesPerSecond = Math.Max(1, framesPerSecond);Output = path;PlannedFrames = Math.Max(0, plannedFrames);@@ -103,6 +115,9 @@ public sealed class MovAnimationWriter : IFrameSink/// <summary>Frames per second, the movie's time scale.</summary>public int FramesPerSecond { get; }+ /// <summary>The video codec the samples are coded with.</summary>+ public MovCodec Codec { get; }+/// <summary>The frame count the leading moov was reserved for; 0 for a trailing moov.</summary>public int PlannedFrames { get; }@@ -123,14 +138,26 @@ public sealed class MovAnimationWriter : IFrameSink{throw new ArgumentException("The frame is smaller than the movie.", nameof(pixels));}- int length = Encode(pixels, _frame);_offsets.Add(_stream.Position);+ int length;+ if (Codec == MovCodec.Png)+ {+ // the sample is the PNG file itself, written straight into the mdat+ long start = _stream.Position;+ // unfiltered rows: a few percent larger, but what a player's libpng can decode in time (2026-10-19, VLC)+ PngEncoder.Write(_stream, pixels, Width, Height, PngFilter.None);+ length = (int)(_stream.Position - start);+ }+ else+ {+ length = Encode(pixels, _frame);+ _stream.Write(_frame, 0, length);+ }_sizes.Add(length);- _stream.Write(_frame, 0, length);FrameBytes += length;}- /// <summary>Run-length codes one frame into <paramref name="target"/>; returns the byte count.</summary>+ /// <summary>Run-length codes one frame into <paramref name="target"/> the Animation codec's way; returns the byte count.</summary>public int Encode(ReadOnlySpan<int> pixels, byte[] target){int p = 6; // the length and the header are filled in at the end@@ -284,12 +311,12 @@ public sealed class MovAnimationWriter : IFrameSinkreturn Atom("hdlr", [0, 0, 0, 0, .. Encoding.ASCII.GetBytes(type), .. Encoding.ASCII.GetBytes(subtype), .. "appl"u8, 0, 0, 0, 0, 0, 0, 0, 0, (byte)nameBytes.Length, .. nameBytes]);}- /// <summary>The sample description: one 'rle ' entry, 24-bit, spatial quality lossless, named "Animation".</summary>+ /// <summary>The sample description: one entry, 'rle ' named "Animation" or 'png ' named "PNG", 24-bit, spatial quality lossless.</summary>private byte[] Stsd(){var e = new byte[86];BinaryPrimitives.WriteUInt32BigEndian(e, 86);- "rle "u8.CopyTo(e.AsSpan(4));+ (Codec == MovCodec.Png ? "png "u8 : "rle "u8).CopyTo(e.AsSpan(4));BinaryPrimitives.WriteUInt16BigEndian(e.AsSpan(14), 1); // data reference index"appl"u8.CopyTo(e.AsSpan(20)); // vendorBinaryPrimitives.WriteUInt32BigEndian(e.AsSpan(28), 0x3FF); // spatial quality: lossless@@ -298,7 +325,7 @@ public sealed class MovAnimationWriter : IFrameSinkBinaryPrimitives.WriteUInt32BigEndian(e.AsSpan(36), 0x00480000); // 72 dpiBinaryPrimitives.WriteUInt32BigEndian(e.AsSpan(40), 0x00480000);BinaryPrimitives.WriteUInt16BigEndian(e.AsSpan(48), 1); // frames per sample- byte[] name = Encoding.ASCII.GetBytes("Animation");+ byte[] name = Encoding.ASCII.GetBytes(Codec == MovCodec.Png ? "PNG" : "Animation");e[50] = (byte)name.Length;name.CopyTo(e, 51);BinaryPrimitives.WriteUInt16BigEndian(e.AsSpan(82), 24); // depthdiff --git a/WaveDudeNext/Export/PngEncoder.cs b/WaveDudeNext/Export/PngEncoder.csindex adcc25f..7f09e8f 100644--- a/WaveDudeNext/Export/PngEncoder.cs+++ b/WaveDudeNext/Export/PngEncoder.cs@@ -21,6 +21,15 @@ using System.Text;namespace WaveDudeNext.Export;+/// <summary>The row filter a PNG is written with.</summary>+public enum PngFilter+{+ /// <summary>No filtering: the cheapest to decode, and on a rendered frame, flat runs of a few dozen palette colours, also the smallest (2026-10-19: 306 KB against Paeth's 387 on a Full HD frame of Example 2; ffmpeg's PNG encoder writes this by default).</summary>+ None,+ /// <summary>Paeth on every row: the smallest files for smooth gradients, undone byte by byte by the decoder.</summary>+ Paeth,+}+/// <summary>/// Writes 24-bit RGB PNG files from packed BGRA32 frames, in-house: the signature, IHDR, the zlib stream/// (<see cref="ZLibStream"/>, which writes the zlib header and Adler-32 itself) as IDAT chunks of up to 64 KB@@ -38,7 +47,8 @@ public static class PngEncoder/// <param name="pixels">Packed BGRA32 pixels, row-major, at least <paramref name="width"/> × <paramref name="height"/>.</param>/// <param name="width">Width in pixels.</param>/// <param name="height">Height in pixels.</param>- public static void Write(Stream stream, ReadOnlySpan<int> pixels, int width, int height)+ /// <param name="filter">The row filter; Paeth unless a fast decode matters more than a few percent of size (2026-10-19: VLC's libpng could not undo Paeth on Full HD frames at 30 fps and showed only the first; ffmpeg's unfiltered frames played).</param>+ public static void Write(Stream stream, ReadOnlySpan<int> pixels, int width, int height, PngFilter filter = PngFilter.Paeth){stream.Write(Signature);Span<byte> header = stackalloc byte[13];@@ -52,7 +62,7 @@ public static class PngEncoderWriteChunk(stream, "IHDR", header);using (var idat = new IdatStream(stream)){- Deflate(idat, pixels, width, height);+ Deflate(idat, pixels, width, height, filter);}WriteChunk(stream, "IEND", default);}@@ -66,7 +76,7 @@ public static class PngEncoder}/// <summary>The filtered rows, zlib-compressed into <paramref name="output"/>.</summary>- private static void Deflate(Stream output, ReadOnlySpan<int> pixels, int width, int height)+ private static void Deflate(Stream output, ReadOnlySpan<int> pixels, int width, int height, PngFilter filter){int rowBytes = width * 3;var previous = new byte[rowBytes];@@ -84,13 +94,21 @@ public static class PngEncodercurrent[x * 3 + 1] = (byte)(argb >> 8);current[x * 3 + 2] = (byte)argb;}- filtered[0] = 4; // Paeth- for (int i = 0; i < rowBytes; i++)+ if (filter == PngFilter.None)+ {+ filtered[0] = 0;+ current.CopyTo(filtered, 1);+ }+ else{- int a = i >= 3 ? current[i - 3] : 0;- int b = previous[i];- int c = i >= 3 ? previous[i - 3] : 0;- filtered[i + 1] = (byte)(current[i] - Paeth(a, b, c));+ filtered[0] = 4; // Paeth+ for (int i = 0; i < rowBytes; i++)+ {+ int a = i >= 3 ? current[i - 3] : 0;+ int b = previous[i];+ int c = i >= 3 ? previous[i - 3] : 0;+ filtered[i + 1] = (byte)(current[i] - Paeth(a, b, c));+ }}zlib.Write(filtered, 0, filtered.Length);(previous, current) = (current, previous);diff --git a/_tools/library_check/ExportChecks.cs b/_tools/library_check/ExportChecks.csindex 4bbbf05..96540eb 100644--- a/_tools/library_check/ExportChecks.cs+++ b/_tools/library_check/ExportChecks.cs@@ -53,6 +53,13 @@ internal static class ExportCheckscheck(png.Length > 8 && png[1] == (byte)'P' && png[2] == (byte)'N' && png[3] == (byte)'G', "png: signature");int[]? decoded = DecodePng(png, w, h);check(decoded != null && decoded.SequenceEqual(frames[0]), "png: in-house decode gives the frame back pixel for pixel");+ // the unfiltered variant (the PNG movie's, 2026-10-19): every row's filter byte 0, the same picture back+ using var unfilteredStream = new MemoryStream();+ PngEncoder.Write(unfilteredStream, frames[0], w, h, PngFilter.None);+ byte[] unfiltered = unfilteredStream.ToArray();+ int[]? unfilteredDecoded = DecodePng(unfiltered, w, h);+ check(unfilteredDecoded != null && unfilteredDecoded.SequenceEqual(frames[0]) && FilterBytes(unfiltered, w, h) is { } filters && filters.All(f => f == 0),+ "png unfiltered: every row's filter byte is 0 and the frame comes back pixel for pixel");string pngPath = Path.Combine(folder, "one.png");File.WriteAllBytes(pngPath, png);if (Ffmpeg != null)@@ -188,7 +195,7 @@ internal static class ExportChecks// MOV with the Animation codec: the atoms, ffmpeg's qtrle decoder giving the frames back exactly, a run of one colour compressingstring movPath = Path.Combine(folder, "seven.mov");bool moovFirst;- using (var mov = new MovAnimationWriter(movPath, w, h, 25, 7))+ using (var mov = new MovWriter(movPath, w, h, 25, 7)){foreach (int[] frame in frames){@@ -205,7 +212,7 @@ internal static class ExportChecks&& IndexOf(movBytes, "free"u8, moovAt, mdatAt) > moovAt && IndexOf(movBytes, "rle "u8, 0, movBytes.Length) > 0 && IndexOf(movBytes, "co64"u8, 0, movBytes.Length) > 0,"mov: ftyp qt, the moov before the mdat with a free atom filling the reservation, an rle sample description, 64-bit offsets");// a writer told nothing about the count has no reservation and puts the moov at the end, still a valid file- using (var trailing = new MovAnimationWriter(Path.Combine(folder, "trailing.mov"), w, h, 25))+ using (var trailing = new MovWriter(Path.Combine(folder, "trailing.mov"), w, h, 25)){foreach (int[] frame in frames){@@ -228,11 +235,56 @@ internal static class ExportChecksvar flat = new int[w * h];Array.Fill(flat, unchecked((int)0xFF123456));var scratch = new byte[6 + h * (w * 3 + w / 127 + 4)];- using (var mov = new MovAnimationWriter(Path.Combine(folder, "flat.mov"), w, h, 25))+ using (var mov = new MovWriter(Path.Combine(folder, "flat.mov"), w, h, 25)){int flatBytes = mov.Encode(flat, scratch);check(flatBytes < h * 8 + 6, "mov: a flat frame codes to " + flatBytes + " bytes (under " + (h * 8 + 6) + ")");}+ // MOV with the PNG codec (2026-10-19, for the editing suites): a 'png ' sample description, each sample a whole PNG+ // file that decodes to its frame, smaller than the Animation codec on these frames, ffmpeg giving the frames back exactly+ string pngMovPath = Path.Combine(folder, "png.mov");+ long animationBytes;+ using (var mov = new MovWriter(movPath + ".again.mov", w, h, 25, 7))+ {+ foreach (int[] frame in frames)+ {+ mov.Add(frame);+ }+ animationBytes = mov.FrameBytes;+ }+ using (var mov = new MovWriter(pngMovPath, w, h, 25, 7, MovCodec.Png))+ {+ foreach (int[] frame in frames)+ {+ mov.Add(frame);+ }+ mov.Close();+ check(mov.FrameCount == 7 && mov.MoovFirst && mov.Codec == MovCodec.Png, "mov png: 7 frames taken, the moov leading");+ check(mov.FrameBytes < animationBytes, "mov png: smaller than the Animation codec (" + mov.FrameBytes + " against " + animationBytes + " bytes)");+ }+ byte[] pngMov = File.ReadAllBytes(pngMovPath);+ ReadOnlySpan<byte> signature = [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A];+ int firstSample = IndexOf(pngMov, signature, 0, pngMov.Length);+ int secondSample = firstSample < 0 ? -1 : IndexOf(pngMov, signature, firstSample + 8, pngMov.Length);+ check(IndexOf(pngMov, "png "u8, 0, pngMov.Length) > 0 && IndexOf(pngMov, "rle "u8, 0, pngMov.Length) < 0 && firstSample > 0 && secondSample > firstSample,+ "mov png: a 'png ' sample description and PNG files as samples");+ int[]? firstFrame = secondSample > firstSample ? DecodePng(pngMov[firstSample..secondSample], w, h) : null;+ bool firstExact = firstFrame != null;+ for (int i = 0; firstExact && i < w * h; i++)+ {+ firstExact = (firstFrame![i] & 0xFFFFFF) == (frames[0][i] & 0xFFFFFF);+ }+ check(firstExact, "mov png: the first sample decodes to the first frame exactly");+ if (Ffmpeg != null)+ {+ byte[]? rgb = Decode(pngMovPath, w, h, out int count);+ bool exact = rgb != null && count == 7;+ for (int i = 0; exact && i < 7; i++)+ {+ exact = Psnr(rgb!.AsSpan(i * w * h * 3, w * h * 3), frames[i], w, h) >= 99;+ }+ check(exact, "mov png: ffmpeg decodes 7 frames, identical" + (rgb == null ? "" : ", got " + count));+ }// MP4: Media Foundation, when it is thereif (OperatingSystem.IsWindows() && ExportFormats.IsAvailable(ExportFormat.Mp4)){@@ -722,7 +774,7 @@ internal static class ExportChecksvar clock = Stopwatch.StartNew();job.Start();job.Completion.Wait();- string ratio = job.Targets[0].Sink is MovAnimationWriter movSink ? $", {(double)store.Count * w * h * 3 / Math.Max(1, movSink.FrameBytes):0.00} : 1 on the run's frames" : "";+ string ratio = job.Targets[0].Sink is MovWriter movSink ? $", {(double)store.Count * w * h * 3 / Math.Max(1, movSink.FrameBytes):0.00} : 1 on the run's frames" : "";Console.WriteLine($" job to {name}: {clock.Elapsed.TotalMilliseconds / store.Count:0.0} ms per frame ({job.State}){ratio}");ExportFormats.PreferredJpeg = preferredJpeg;Mp4Writer.Throttle = true;@@ -1002,6 +1054,38 @@ internal static class ExportChecks}/// <summary>Decodes an 8-bit RGB PNG with any of the five filters; null when it is not one.</summary>+ /// <summary>The filter byte of every row of a PNG (the first byte of each inflated row), or null when the file does not inflate.</summary>+ private static byte[]? FilterBytes(byte[] png, int w, int h)+ {+ using var idat = new MemoryStream();+ int p = 8;+ while (p + 8 <= png.Length)+ {+ int length = BinaryPrimitives.ReadInt32BigEndian(png.AsSpan(p));+ string type = Encoding.ASCII.GetString(png, p + 4, 4);+ if (type == "IDAT")+ {+ idat.Write(png, p + 8, length);+ }+ p += 12 + length;+ }+ idat.Position = 0;+ var rows = new byte[(w * 3 + 1) * h];+ using (var zlib = new ZLibStream(idat, CompressionMode.Decompress))+ {+ if (zlib.ReadAtLeast(rows, rows.Length, throwOnEndOfStream: false) != rows.Length)+ {+ return null;+ }+ }+ var filters = new byte[h];+ for (int y = 0; y < h; y++)+ {+ filters[y] = rows[y * (w * 3 + 1)];+ }+ return filters;+ }+private static int[]? DecodePng(byte[] png, int w, int h){int p = 8;