test(app): editor sample for --capture and a Windows smoke test of every section
SampleData.FillEditorAsync writes a synthetic harbour sunset of real JPEG frames with Exif (flicker, two exposure steps, white-balance drift, a horizon), scans, deep-analyses and advises it, so --capture writes sequence-<tab>-<theme>.png for every editor section. EditorViewModel .WhenIdleAsync lets capture and tests wait for the preview, corrections, plan, estimates and thumbnails in flight. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
7 files changed
+413
-1
No files matched your search
@@ -1,14 +1,23 @@
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using Titano.App.About;
|
||||
using Titano.App.Editor;
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.App.Server;
|
||||
using Titano.App.Settings;
|
||||
using Titano.Core.Advice;
|
||||
using Titano.Core.Analysis;
|
||||
using Titano.Core.Analysis.Deep;
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Codecs.Jpeg;
|
||||
using Titano.Core.Diagnostics.Synthetic;
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Core.Imaging.Decoders;
|
||||
using Titano.Core.Metadata;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Video;
|
||||
using Titano.Data;
|
||||
using Titano.Data.Archiving;
|
||||
using Titano.Protocol;
|
||||
using Titano.Protocol.Client;
|
||||
|
||||
@@ -79,6 +88,149 @@ public sealed class SampleData
|
||||
settings.FirstRunCompleted = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The sequence editor's sample: a second archive holding a synthetic harbour sunset of real JPEG frames with Exif
|
||||
/// (flicker, two received exposure steps, white-balance drift, a horizon), indexed by a scan, analysed (light and
|
||||
/// deep, saved as <c>analysis.json</c>), advised into <c>project.json</c> and given two past renders.
|
||||
/// </summary>
|
||||
/// <returns>The sequence id to open in the editor.</returns>
|
||||
public async Task<Guid> FillEditorAsync()
|
||||
{
|
||||
var db = _db ?? throw new InvalidOperationException("OpenEmptyAsync first.");
|
||||
var archives = _services.Archives ?? throw new InvalidOperationException("The archive engine is not attached.");
|
||||
var root = Path.Combine(_services.Environment.DataDirectory, "editor-archive");
|
||||
var archive = await archives.CreateAsync(root, "Editor sample");
|
||||
var sunset = SyntheticSequence.Create(EditorSunset);
|
||||
var folder = Path.Combine(root, "2026", "2026-09-28 Canon EOS R5");
|
||||
Directory.CreateDirectory(folder);
|
||||
for (var i = 0; i < sunset.Count; i++)
|
||||
{
|
||||
using var image = SunsetFrame(sunset, i);
|
||||
var exif = ExifWriter.BuildJpegApp1(sunset.Metadata[i]);
|
||||
File.WriteAllBytes(Path.Combine(folder, $"IMG_{4211 + i:0000}.JPG"), JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 88, App1Segments = [exif[4..]] }));
|
||||
}
|
||||
await archives.Indexer.ScanAsync(archive, ScanMode.Full, null, _ => ValueTask.CompletedTask, CancellationToken.None);
|
||||
var id = (await db.Sequences.ListLocationsAsync(archive.Id)).Single().Id;
|
||||
await archives.SetSequenceInfoAsync(id, "Harbour sunset", ["sunset", "harbour"], 4, null);
|
||||
|
||||
var source = new LocalSequenceSource(db, id, DecoderFactory.CreateClient(null), null);
|
||||
var content = await source.LoadAsync(CancellationToken.None);
|
||||
var deep = await DeepAnalyzer.AnalyzeAsync(new SunsetFrames(sunset));
|
||||
var sequence = content.Sequence;
|
||||
deep.Save(new ArchivePaths(root).Sequence(sequence.Folder).AnalysisPath);
|
||||
var advice = Advisor.Recommend(content.Light, deep, SequenceContext.FromFrames(content.Frames));
|
||||
await source.SaveProjectAsync(Advisor.Apply(content.Project, advice), content.Project, CancellationToken.None);
|
||||
await db.Sequences.RecordAnalysisAsync(id, SequenceStatus.AnalyzedLight | SequenceStatus.AnalyzedDeep | SequenceStatus.HasWarnings, SequenceStatus.None,
|
||||
advice.Findings.Count(f => f.Severity >= FindingSeverity.Warning), AnalysisSummary.From(deep).ToJson());
|
||||
foreach (var (preset, codec, width, height, daysAgo, bytes) in new[] { ("4K archive", "hevc", 3840, 2160, 7, 2_210_000_000L), ("1080p share", "h264", 1920, 1080, 3, 412_000_000L) })
|
||||
{
|
||||
await db.Renders.InsertAsync(new Render
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
SequenceId = id,
|
||||
PresetName = preset,
|
||||
OutputPath = Path.Combine(folder, "exports", $"2026-09-28 Harbour sunset - {preset}.mp4"),
|
||||
Codec = codec,
|
||||
Width = width,
|
||||
Height = height,
|
||||
Fps = 24,
|
||||
DurationSeconds = 5,
|
||||
Bytes = bytes,
|
||||
Created = DateTimeOffset.UtcNow.AddDays(-daysAgo),
|
||||
ProducedBy = "studio-pc",
|
||||
});
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/// <summary>A two-minute sunset at 2 s intervals: darkening scene, flicker, two shutter steps the pixels received, warming light.</summary>
|
||||
private static readonly SyntheticSequenceOptions EditorSunset = new()
|
||||
{
|
||||
Width = 600,
|
||||
Height = 400,
|
||||
FrameCount = 96,
|
||||
Seed = 28,
|
||||
Start = new DateTime(2026, 9, 28, 18, 2, 11),
|
||||
IntervalSeconds = 2,
|
||||
StartEv = 0.5,
|
||||
EndEv = -2.5,
|
||||
FlickerEv = 0.12,
|
||||
ExposureSteps = [new SyntheticExposureStep(32, -1), new SyntheticExposureStep(64, -1)],
|
||||
HorizonFraction = 0.62,
|
||||
HorizonWave = 0.02,
|
||||
SkyLevel = 0.32,
|
||||
LandLevel = 0.06,
|
||||
StartKelvin = 5600,
|
||||
EndKelvin = 3200,
|
||||
WhiteBalanceJitter = 0.03,
|
||||
NoiseSigma = 0.002,
|
||||
BaseExposureTime = 1.0 / 125,
|
||||
BaseFNumber = 8,
|
||||
BaseIso = 100,
|
||||
CameraMake = "Canon",
|
||||
CameraModel = "Canon EOS R5",
|
||||
Lens = "RF15-35mm F2.8 L IS USM",
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The synthetic frame (its exposure truth: scene, steps, flicker, white balance) coloured as a harbour sunset: a
|
||||
/// blue-to-amber sky gradient normalised to unit luminance, so the measured luminance keeps the truth, and a setting sun.
|
||||
/// </summary>
|
||||
private static ImageBuffer SunsetFrame(SyntheticSequence sequence, int index)
|
||||
{
|
||||
var image = sequence.Render(index);
|
||||
var (w, h) = (image.Width, image.Height);
|
||||
var t = index / (double)(sequence.Count - 1);
|
||||
var horizon = sequence.Options.HorizonFraction * h;
|
||||
var (sunX, sunY) = (w * 0.64, h * (0.28 + 0.3 * t));
|
||||
var gain = Math.Pow(2, sequence.SceneEv[index] + sequence.ExposureOffsetEv[index] + sequence.FlickerEv[index]);
|
||||
double[][] sky = [Linear("#2A2F6B"), Linear("#8E3F57"), Linear("#E07A48"), Linear("#F5B45E")];
|
||||
var land = Linear("#3A3540");
|
||||
for (var y = 0; y < h; y++)
|
||||
{
|
||||
double[] colour;
|
||||
if (y < horizon)
|
||||
{
|
||||
var f = y / horizon * (sky.Length - 1);
|
||||
var k = Math.Min((int)f, sky.Length - 2);
|
||||
colour = [.. Enumerable.Range(0, 3).Select(c => sky[k][c] + (sky[k + 1][c] - sky[k][c]) * (f - k))];
|
||||
}
|
||||
else
|
||||
{
|
||||
colour = land;
|
||||
}
|
||||
var luminance = 0.2126 * colour[0] + 0.7152 * colour[1] + 0.0722 * colour[2];
|
||||
for (var x = 0; x < w; x++)
|
||||
{
|
||||
var d = Math.Sqrt((x - sunX) * (x - sunX) + (y - sunY) * (y - sunY));
|
||||
var sun = y < horizon ? gain * 4 * Math.Exp(-d * d / 220) : 0;
|
||||
for (var c = 0; c < 3; c++)
|
||||
{
|
||||
var plane = image.Plane(c);
|
||||
plane[y * w + x] = (float)(plane[y * w + x] * colour[c] / luminance + sun * (c == 0 ? 1.0 : c == 1 ? 0.75 : 0.45));
|
||||
}
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
private static double[] Linear(string hex)
|
||||
{
|
||||
var rgb = Convert.FromHexString(hex.TrimStart('#'));
|
||||
return [.. rgb.Select(v => ColorSpace.SrgbToLinear(v / 255.0))];
|
||||
}
|
||||
|
||||
/// <summary>The sunset as the deep analysis reads it (the pixels written to the JPEGs, before compression).</summary>
|
||||
private sealed class SunsetFrames(SyntheticSequence sequence) : IFrameSource
|
||||
{
|
||||
public int Count => sequence.Count;
|
||||
|
||||
public LightFrame Metadata(int index) => LightFrame.From(sequence.Metadata[index], index);
|
||||
|
||||
public ValueTask<ImageBuffer?> LoadAsync(int index, int maxLongEdge, CancellationToken cancellationToken) =>
|
||||
ValueTask.FromResult<ImageBuffer?>(SunsetFrame(sequence, index));
|
||||
}
|
||||
|
||||
private IEnumerable<(Sequence Sequence, string[] Colours, bool Raw)> Sequences(Guid archiveId)
|
||||
{
|
||||
var now = new DateTime(2026, 9, 28, 18, 2, 11);
|
||||
|
||||
Reference in new issue
Block a user