feat(editor): visual crop, rotate/mirror/flip/straighten, colour looks (owner review 1 phase 4) (#26)
CI / Build and test (push) Successful in 8m19s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 12m9s
CI / PostgreSQL 16 integration (push) Successful in 7m49s
CI / PostgreSQL 17 integration (push) Successful in 7m19s
CI / Docker image (push) Successful in 46s
Release / Server image (push) Successful in 1m14s

Owner review 1 R5 + R6. Camera rotation, mirror, flip, straighten and crop handles locked to the output; an Exposure Look group; Export output size ("proportions win"); settings format 2 with older-node gates. Also fixes project text and hashes differing between Windows and Linux.

Closes #19
Closes #20

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #26.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-11-05 01:09:09 +01:00
1 parent db389a54f2
commit 188b2c2e55
355 files changed
+10549 -1061

No files matched your search

@@ -77,7 +77,7 @@ public sealed class ProjectSettingsTests
Assert.Equal("{date} {title} - {preset}", partial.Export.NameTemplate);
Assert.SequenceEqual(new[] { 0.0, 1.0 }, partial.Timing.RemapCurve.Select(p => p.X));
Assert.Equal(9, partial.Stack.Length);
Assert.Equal(ProjectSettings.CurrentVersion, partial.Version);
Assert.Equal(ProjectSettings.BaseVersion, partial.Version);
// An explicit null clears a nullable value; arrays are replaced, not merged.
var cleared = ProjectSettings.FromJson("""{ "exposure": { "highlightKnee": null }, "timing": { "remapCurve": [ { "x": 0, "y": 0.5 } ] } }""");
@@ -470,4 +470,171 @@ public sealed class ProjectSettingsTests
Assert.Equal(24, s.GopLength);
Assert.Equal(10, s.BitDepth);
}
/// <summary>
/// SHA-256 of the default project's canonical text, as format-1 builds write it: none of phase 4's members, version 1.
/// Builds before wrote it indented with the OS's line ends (CRLF on Windows, LF on Linux); this pin is of the CRLF text,
/// the hash such a Windows build stored.
/// </summary>
private const string DefaultProjectHash = "df0b0f50b113475ece3753a80df0be05cc281cdaa1fa08a73a438ea9161358e0";
/// <summary>SHA-256 of the same text with LF, as every build writes it now on every OS.</summary>
private const string DefaultProjectLfHash = "24e4c2d0379bfda6e42533d4687d69cca95bab72f2a49bd70e2fba267b66a3d1";
[Test]
public void ProjectsWithoutTheNewMembersKeepTheirTextAndHash()
{
var defaults = new ProjectSettings().ToJson();
Assert.False(defaults.Contains('\r', StringComparison.Ordinal), "line ends");
Assert.Equal(DefaultProjectLfHash, ProjectContent.Hash(ProjectContent.Canonical(defaults)));
// A version a Windows build stored before still names this text.
Assert.True(ProjectContent.MatchesHash(ProjectContent.Canonical(defaults), DefaultProjectHash));
Assert.Equal(DefaultProjectHash, ProjectContent.Hash(ProjectContent.Canonical(defaults).Replace("\n", "\r\n", StringComparison.Ordinal)));
// The old build wrote the OS's line ends (OldJson leaves NewLine unset): the same text but for those.
Assert.Equal(OldBuild.Write(new OldProject()).ReplaceLineEndings("\n"), defaults);
Assert.Contains("\"version\": 1", defaults);
foreach (var member in new[] { "rotate", "mirror", "flip", "straighten", "\"look\"" })
Assert.False(defaults.Contains(member, StringComparison.Ordinal), member);
// A project written by a format-1 build reads and writes back the same, byte for byte but for line ends.
var older = new ProjectSettings
{
Camera = new CameraSettings { Crop = [0.1, 0.2, 0.5, 0.6], Aspect = new Auto<string>().WithManual("9:16"), Keyframes = [new CameraKey(3, 0.4, 0.5, 1.5, 2)] },
Exposure = new ExposureSettings { ExposureOffsetEv = 0.3 },
}.ToJson();
Assert.Equal(older, ProjectContent.Canonical(older));
Assert.Equal(older, OldBuild.Write(OldBuild.Read(older)).ReplaceLineEndings("\n"));
Assert.Equal(older, ProjectContent.Canonical(older.Replace("\n", "\r\n", StringComparison.Ordinal)));
Assert.Equal(ProjectSettings.BaseVersion, ProjectContent.FormatOf(older));
}
[Test]
public void TheNewMembersRoundTripAndRaiseTheFormatOnlyWhileUsed()
{
var plain = new ProjectSettings { Exposure = new ExposureSettings { ExposureOffsetEv = 0.5 } };
Assert.Equal(ProjectSettings.BaseVersion, plain.RequiredFormat);
var turned = plain with { Camera = plain.Camera with { Rotate = 90, Mirror = true, Flip = true, Straighten = -3.5 } };
var looked = plain with { Look = new LookSettings { Filter = "sepia", Strength = 0.6 } };
foreach (var settings in new[] { turned, looked, plain with { Camera = new CameraSettings { Straighten = 1 } }, plain with { Camera = new CameraSettings { Flip = true } } })
{
Assert.Equal(2, settings.RequiredFormat);
var json = settings.ToJson();
Assert.Contains("\"version\": 2", json);
var back = ProjectSettings.FromJson(json);
Assert.Equal(2, back.Version);
Assert.False(back.IsNewerFormat);
Assert.Equal(json, back.ToJson());
}
var read = ProjectSettings.FromJson(turned.ToJson());
Assert.Equal((90, true, true, -3.5), (read.Camera.Rotate, read.Camera.Mirror, read.Camera.Flip, read.Camera.Straighten));
Assert.Equal((1, true), (read.Camera.Turns, read.Camera.IsOriented));
var look = Assert.NotNull(ProjectSettings.FromJson(looked.ToJson()).Look);
Assert.Equal(("sepia", (double?)0.6), (look.Filter, look.Strength));
// Taken away again, the project is format 1 with the text it had before.
var undone = ProjectSettings.FromJson(turned.ToJson()) with { Camera = plain.Camera };
Assert.Equal(ProjectSettings.BaseVersion, undone.RequiredFormat);
Assert.Equal(plain.ToJson(), undone.ToJson());
Assert.Equal(plain.ToJson(), (ProjectSettings.FromJson(looked.ToJson()) with { Look = null }).ToJson());
// An identity look and a whole turn need nothing newer; an unknown look does (it is a newer Chronos's).
Assert.Equal(1, (plain with { Look = new LookSettings { Filter = "none" } }).RequiredFormat);
Assert.Equal(1, (plain with { Look = new LookSettings { Filter = "mono", Strength = 0 } }).RequiredFormat);
Assert.Equal(1, (plain with { Camera = new CameraSettings { Rotate = 360 } }).RequiredFormat);
Assert.Equal(2, (plain with { Look = new LookSettings { Filter = "film" } }).RequiredFormat);
Assert.Equal(3, new CameraSettings { Rotate = -90 }.Turns);
}
[Test]
public void TheNewMembersComeAfterTheOldOnesSoAnOlderBuildWritesThemBackInPlace()
{
var settings = new ProjectSettings
{
Camera = new CameraSettings { Crop = [0.2, 0, 0.6, 1], Keyframes = [new CameraKey(1, 0.5, 0.5, 2, 0)], Rotate = 270, Straighten = 2.25 },
HeroFrame = 4,
Look = new LookSettings { Filter = "warm" },
};
var canonical = ProjectContent.Canonical(settings.ToJson());
// A format-1 build keeps them as members it does not know, and writes them where they were.
var old = OldBuild.Read(canonical);
Assert.True(old.Camera.Extra!.ContainsKey("rotate") && old.Extra!.ContainsKey("look"));
// In the OS's line ends (CRLF on Windows): the same text and content hash but for those.
Assert.Equal(canonical, OldBuild.Write(old).ReplaceLineEndings("\n"));
Assert.True(ProjectContent.MatchesHash(OldBuild.Write(old), ProjectContent.Hash(canonical)));
Assert.True(ProjectContent.SameChoices(OldBuild.Write(old), canonical, new FramePhotos([])));
var camera = System.Text.Json.Nodes.JsonNode.Parse(canonical)!["camera"]!.AsObject().Select(p => p.Key).ToList();
Assert.SequenceEqual(["crop", "aspect", "offsetX", "offsetY", "keyframes", "rotate", "straighten"], camera);
}
[Test]
public void ANewerFormatStaysReadOnlyAndKeepsItsNumber()
{
const string newer = """{ "version": 3, "camera": { "rotate": 90 }, "look": { "filter": "film", "grain": 0.2 } }""";
Assert.Throws<InvalidDataException>(() => ProjectSettings.FromJson(newer));
var read = ProjectSettings.FromJson(newer, allowNewer: true);
Assert.True(read.IsNewerFormat);
Assert.Equal(3, read.WrittenFormat);
var canonical = ProjectContent.Canonical(newer);
Assert.Equal(3, ProjectContent.FormatOf(canonical));
Assert.Contains("\"grain\": 0.2", canonical);
Assert.Equal(canonical, ProjectContent.Canonical(canonical));
// A format-2 project is this Chronos's own (written as the format it needs); text without a version is format 1.
Assert.False(ProjectSettings.FromJson("""{ "version": 2 }""").IsNewerFormat);
Assert.Equal(1, ProjectSettings.FromJson("""{ "version": 2 }""").WrittenFormat);
Assert.Equal(1, ProjectContent.FormatOf("""{ "camera": {} }"""));
Assert.Equal(1, ProjectContent.FormatOf(null));
}
/// <summary>
/// The settings as a format-1 build reads and writes them: its camera without phase 4's members and its project without
/// the look, with the same serialiser options. What it does not know lands in <c>Extra</c>.
/// </summary>
private static class OldBuild
{
public static OldProject Read(string json) => System.Text.Json.JsonSerializer.Deserialize(json, OldJson.Default.OldProject)!;
public static string Write(OldProject project) => System.Text.Json.JsonSerializer.Serialize(project, OldJson.Default.OldProject);
}
}
/// <summary>A format-1 build's camera (before owner review 1, phase 4).</summary>
internal sealed record OldCamera
{
public double[]? Crop { get; init; }
public Auto<string> Aspect { get; init; } = new();
public double OffsetX { get; init; }
public double OffsetY { get; init; }
public IReadOnlyList<CameraKey> Keyframes { get; init; } = [];
[System.Text.Json.Serialization.JsonExtensionData]
public Dictionary<string, System.Text.Json.JsonElement>? Extra { get; set; }
}
/// <summary>A format-1 build's project (before owner review 1, phase 4).</summary>
internal sealed record OldProject
{
public int Version { get; init; } = 1;
public TimingSettings Timing { get; init; } = new();
public ExposureSettings Exposure { get; init; } = new();
public MotionSettings Motion { get; init; } = new();
public OldCamera Camera { get; init; } = new();
public StackSettings Stack { get; init; } = new();
public ExportSettings Export { get; init; } = new();
public IReadOnlyList<int> ExcludedFrames { get; init; } = [];
public int? HeroFrame { get; init; }
public IReadOnlyList<PendingFrame>? PendingFrames { get; init; }
[System.Text.Json.Serialization.JsonExtensionData]
public Dictionary<string, System.Text.Json.JsonElement>? Extra { get; set; }
}
[System.Text.Json.Serialization.JsonSourceGenerationOptions(
WriteIndented = true,
PropertyNamingPolicy = System.Text.Json.Serialization.JsonKnownNamingPolicy.CamelCase,
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull,
UseStringEnumConverter = true,
PropertyNameCaseInsensitive = true)]
[System.Text.Json.Serialization.JsonSerializable(typeof(OldProject))]
internal sealed partial class OldJson : System.Text.Json.Serialization.JsonSerializerContext;