merge: sequence editor with Export tab (preview through the render pipeline, section tabs, autosave with undo/redo)

Keeps the sync captures and sample server next to the editor's sample sunset;
the editor's capture runs last since it leaves an analysis running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-03 10:58:34 +00:00
commit 8feea5da10
53 files changed
+8622 -18

No files matched your search

+186 -2
View File
@@ -1,14 +1,24 @@
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.Project;
using Titano.Core.Video;
using Titano.Data;
using Titano.Data.Archiving;
using Titano.Data.Jobs;
using Titano.Data.Sync;
using Titano.Protocol;
@@ -195,6 +205,180 @@ public sealed class SampleData
"""{"exposure":{"deflickerWindow":{"isAuto":false,"manual":""" + frames.ToString(System.Globalization.CultureInfo.InvariantCulture) + "}}}";
}
/// <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> with one manual value and three camera
/// keyframes, 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));
// As a user leaves it: the advice applied, one value taken over by hand (Sun track) and a slow push-in.
var advised = Advisor.Apply(content.Project, advice);
var project = advised with
{
Exposure = advised.Exposure with { DeflickerStrength = advised.Exposure.DeflickerStrength.WithManual(0.8) },
Camera = advised.Camera with { Keyframes = [new CameraKey(0, 0.5, 0.5, 1, 0), new CameraKey(48, 0.6, 0.46, 1.4, 0), new CameraKey(95, 0.64, 0.4, 1.9, 0)] },
};
await source.SaveProjectAsync(project, 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 deep analysis of <paramref name="sequenceId"/> half way through: the editor's busy state (settings wait, viewing stays live).</summary>
public async Task MarkAnalysingAsync(Guid sequenceId)
{
var db = _db ?? throw new InvalidOperationException("OpenEmptyAsync first.");
var now = DateTimeOffset.UtcNow;
await db.Jobs.EnqueueAsync(new Job
{
Id = Guid.CreateVersion7(),
Kind = JobKind.DeepAnalyse,
TargetIds = [sequenceId],
TargetLabel = "Harbour sunset",
State = JobState.Running,
Priority = JobPriority.User,
ProgressDone = 40,
ProgressTotal = 96,
ItemsPerSecond = 12,
NodeId = Environment.MachineName,
Attempts = 1,
Created = now.AddSeconds(-5),
Started = now.AddSeconds(-4),
});
}
/// <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);
@@ -456,14 +640,14 @@ public sealed class SampleData
lock (_sequences) return Task.FromResult(_sequences[id].Dto);
}
public Task<SequenceManifest> GetManifestAsync(Guid id, CancellationToken cancellationToken)
public Task<Protocol.SequenceManifest> GetManifestAsync(Guid id, CancellationToken cancellationToken)
{
lock (_sequences)
{
var (dto, settings, frames) = _sequences[id];
var hasProxy = (dto.Status & (long)SequenceStatus.ProxiesBuilt) != 0;
var created = new DateTimeOffset(2026, 9, 20, 21, 0, 0, TimeSpan.Zero);
return Task.FromResult(new SequenceManifest(id, dto.FramesVersion, dto.SettingsVersion, settings, dto.Tags,
return Task.FromResult(new Protocol.SequenceManifest(id, dto.FramesVersion, dto.SettingsVersion, settings, dto.Tags,
[.. frames.Select((frame, i) => new ManifestFrame(frame, i, $"IMG_{i + 1:0000}.JPG", 24_000_000,
Convert.ToHexStringLower(System.Security.Cryptography.SHA256.HashData(BitConverter.GetBytes(i))), hasProxy, true))],
[.. Enumerable.Range(0, dto.RenderedCount).Select(i => new RenderDto(Guid.CreateVersion7(), i == 0 ? "4K HEVC" : "1080p H.264", "hevc",