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
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:
1 parent
db389a54f2
commit
188b2c2e55
355 files changed
+10549
-1061
No files matched your search
@@ -1,6 +1,7 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Jobs;
|
||||
@@ -102,20 +103,20 @@ public static class JobEndpoints
|
||||
// A render of a project version (owner review 2, R8): of the sequence's projects, a project alone pinned to its head.
|
||||
var (render, missing) = await ProjectRenderAsync(db, archives, targets[0], parsed, ct);
|
||||
if (missing is not null) return ApiErrors.NotFound(context, missing);
|
||||
var parametersJson = render == parsed ? request.ParametersJson : JsonSerializer.Serialize(render, ProtocolJson.Default.RenderJobParameters);
|
||||
// A batch becomes one job per preset: a render node uploads one file per job (BRIEF §14.7).
|
||||
// A batch becomes one job per preset: a render node uploads one file per job (BRIEF §14.7). Each gets the size and the
|
||||
// settings format of the settings it renders (owner review 1, phase 4), so it goes only to a node that renders it as asked.
|
||||
IReadOnlyList<RenderJobParameters> each;
|
||||
try
|
||||
{
|
||||
var (width, height) = await SourceSizeAsync(db, targets[0], render, ct);
|
||||
each = ProcessingJobs.Split(render, width, height);
|
||||
each = ProcessingJobs.Split(render, width, height, await RenderedSettingsAsync(db, targets[0], render, ct));
|
||||
}
|
||||
catch (InvalidDataException)
|
||||
{
|
||||
return ApiErrors.BadRequest(context, "invalid_parameters", "parametersJson");
|
||||
}
|
||||
queue = each.Count == 1
|
||||
? [(ProcessingJobs.RenderLabel(label, render.PresetName), parametersJson)]
|
||||
queue = each is [var one] && one == parsed
|
||||
? [(ProcessingJobs.RenderLabel(label, render.PresetName), request.ParametersJson)]
|
||||
: [.. each.Select(p => (ProcessingJobs.RenderLabel(label, p.PresetName), (string?)JsonSerializer.Serialize(p, ProtocolJson.Default.RenderJobParameters)))];
|
||||
}
|
||||
else if (request.ParametersJson is not null && !IsJsonObject(request.ParametersJson))
|
||||
@@ -186,8 +187,22 @@ public static class JobEndpoints
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The settings a render job renders, for its size and settings format: those it embeds, else the project version's it
|
||||
/// names, else the sequence's own; a newer Chronos's too (their format stands). Null when they cannot be read (or the
|
||||
/// version is not there): the job keeps the size it was posted with, and its render says why it cannot read them.
|
||||
/// </summary>
|
||||
internal static async Task<ProjectSettings?> RenderedSettingsAsync(ChronosDatabase db, Guid sequenceId, RenderJobParameters render, CancellationToken ct)
|
||||
{
|
||||
if (render.SettingsJson is { } embedded) return ProcessingJobs.ReadSettings(embedded);
|
||||
if (render.ProjectVersionId is { } versionId)
|
||||
return await db.Projects.GetVersionAsync(versionId, ct) is { } version ? ProcessingJobs.ReadSettings(version.SettingsJson) : null;
|
||||
if (await db.Sequences.GetAsync(sequenceId, ct) is not { } sequence) return null;
|
||||
return sequence.SettingsJson is null ? new ProjectSettings() : ProcessingJobs.ReadSettings(sequence.SettingsJson);
|
||||
}
|
||||
|
||||
/// <summary>The oriented size of the sequence's first frame (what a preset without a fixed size renders at), else the job's size.</summary>
|
||||
private static async Task<(int Width, int Height)> SourceSizeAsync(ChronosDatabase db, Guid sequenceId, RenderJobParameters render, CancellationToken ct) =>
|
||||
internal static async Task<(int Width, int Height)> SourceSizeAsync(ChronosDatabase db, Guid sequenceId, RenderJobParameters render, CancellationToken ct) =>
|
||||
(await db.Frames.ListBySequenceAsync(sequenceId, limit: 1, cancellationToken: ct)).FirstOrDefault() is { Width: > 0, Height: > 0 } frame
|
||||
? frame.Orientation is >= 5 and <= 8 ? (frame.Height, frame.Width) : (frame.Width, frame.Height)
|
||||
: (render.Width, render.Height);
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Globalization;
|
||||
using System.Reflection;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Server.Configuration;
|
||||
@@ -47,7 +48,8 @@ public static class SystemEndpoints
|
||||
state.TlsFingerprint,
|
||||
["jpeg", "png", "tiff", "dng", "cr2", "cr3", "nef", "arw", "raf", "orf", "rw2", "pef", "heic", "webp"],
|
||||
new ServerLimits(options.MaxUploadBytes, options.ChunkSizeBytes, PasswordHasher.MinimumLength),
|
||||
PhotoExtensions), ProtocolJson.Default.ServerInfo)).AllowAnonymousCaller();
|
||||
PhotoExtensions,
|
||||
ProjectSettings.CurrentVersion), ProtocolJson.Default.ServerInfo)).AllowAnonymousCaller();
|
||||
|
||||
api.MapGet("/i18n/{culture}", (string culture) =>
|
||||
{
|
||||
|
||||
@@ -11,8 +11,10 @@ namespace Chronos.Server.Jobs;
|
||||
/// Whether a queued render job that needs a platform encoder still waits for a render node (BRIEF §14.7); once it does
|
||||
/// not, the server's own engine renders it in a managed format. A job waits at least as long as a node may stay silent
|
||||
/// (<see cref="ServerOptions.NodeTimeoutSeconds"/>), so a node that is restarting or reconnecting takes it back, and
|
||||
/// then as long as an online node can encode its codec at its size. The server's render handler asks for every queued
|
||||
/// job it examines, so the online nodes are read at most once a second.
|
||||
/// then as long as an online node reads the settings format it needs (<see cref="RenderJobParameters.RequiredSettingsFormat"/>)
|
||||
/// and can encode its codec at its size, both as the job was queued and as its settings route it now (what the claim
|
||||
/// checks). The server's render handler asks for every queued job it examines, so the online
|
||||
/// nodes are read at most once a second.
|
||||
/// </summary>
|
||||
public sealed class RenderNodeAvailability(ChronosDatabase db, ServerOptions options, TimeProvider time)
|
||||
{
|
||||
@@ -34,7 +36,13 @@ public sealed class RenderNodeAvailability(ChronosDatabase db, ServerOptions opt
|
||||
snapshot = new Snapshot(Stopwatch.GetTimestamp(), [.. online.Select(Dto.Capabilities).OfType<RegisterNodeRequest>()]);
|
||||
Volatile.Write(ref _snapshot, snapshot);
|
||||
}
|
||||
return snapshot.Nodes.Any(node => RenderNodeService.CanEncode(node, parameters));
|
||||
var candidates = snapshot.Nodes.Where(node => RenderNodeService.Renders(node, parameters)).ToList();
|
||||
if (candidates.Count == 0) return false;
|
||||
// The claim also skips a node that cannot render what the job renders now (the sequence's settings may have changed
|
||||
// since it was queued, a job of an older server carries no settings format): the wait asks the same, or a node that
|
||||
// never claims the job would hold it here for good.
|
||||
return await RenderNodeService.RoutedAsync(db, job, parameters, cancellationToken) is not { } routed
|
||||
|| candidates.Any(node => RenderNodeService.Renders(node, routed));
|
||||
}
|
||||
|
||||
/// <summary>What the online nodes announced, and when it was read (a <see cref="Stopwatch"/> timestamp).</summary>
|
||||
|
||||
@@ -6,6 +6,7 @@ using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Data.Processing;
|
||||
using Chronos.Data.Projects;
|
||||
using Chronos.Data.Repositories;
|
||||
using Chronos.Protocol;
|
||||
@@ -86,7 +87,10 @@ public sealed class RenderNodeService(
|
||||
// A render the server's own engine started (it left a checkpoint) resumes there: only it knows that attempt's
|
||||
// leftovers and the batch entries it recorded.
|
||||
if (queued.Checkpoint is not null) continue;
|
||||
if (JobEndpoints.ParseRender(queued.ParametersJson) is not { } parameters || capabilities is null || !CanEncode(capabilities, parameters)) continue;
|
||||
if (JobEndpoints.ParseRender(queued.ParametersJson) is not { } parameters || capabilities is null || !Renders(capabilities, parameters)) continue;
|
||||
// What the job renders now decides too (owner review 1, phase 4): the sequence's own settings may have changed
|
||||
// since it was queued, and a job of an older server carries no settings format.
|
||||
if (await RoutedAsync(db, queued, parameters, cancellationToken) is { } routed && !Renders(capabilities, routed)) continue;
|
||||
if (await db.Jobs.TryClaimAsync(queued.Id, NodeKey(node), cancellationToken) is not { } job) continue;
|
||||
jobs.Publish(job);
|
||||
if (job.TargetIds.Count != 1 || await db.Sequences.GetAsync(job.TargetIds[0], cancellationToken) is not { } sequence)
|
||||
@@ -95,7 +99,7 @@ public sealed class RenderNodeService(
|
||||
continue;
|
||||
}
|
||||
await TouchAsync(node, cancellationToken);
|
||||
if (await SettingsAsync(parameters, sequence, cancellationToken) is not { } settings)
|
||||
if (await SettingsAsync(db, parameters, sequence, cancellationToken) is not { } settings)
|
||||
{
|
||||
await FinishAsync(node, job, JobState.Failed, Loc.L("Errors.Render.ProjectVersion"), cancellationToken);
|
||||
continue;
|
||||
@@ -124,7 +128,7 @@ public sealed class RenderNodeService(
|
||||
/// the frames the node gets), else those of the project version the job names (owner review 2, R8), else the sequence's.
|
||||
/// Null when the job names a version that is not one of the sequence's projects'.
|
||||
/// </summary>
|
||||
private async Task<(string Json, bool Portable)?> SettingsAsync(RenderJobParameters parameters, Sequence sequence, CancellationToken cancellationToken)
|
||||
private static async Task<(string Json, bool Portable)?> SettingsAsync(ChronosDatabase db, RenderJobParameters parameters, Sequence sequence, CancellationToken cancellationToken)
|
||||
{
|
||||
if (parameters.SettingsJson is { } embedded) return (embedded, Waits(embedded));
|
||||
if (parameters.ProjectVersionId is not { } versionId) return (sequence.SettingsJson ?? "{}", false);
|
||||
@@ -134,6 +138,28 @@ public sealed class RenderNodeService(
|
||||
: null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The job's parameters with the output size and settings format of the settings a node would render now
|
||||
/// (<see cref="ProcessingJobs.Routed"/>); null when they cannot be told (no sequence, settings that cannot be read, a
|
||||
/// version that is not the sequence's), which the claim reports as it does today. The claim and the server's wait for
|
||||
/// a node (<see cref="RenderNodeAvailability"/>) both read it, so a node counted as able to take a job does take it.
|
||||
/// </summary>
|
||||
internal static async Task<RenderJobParameters?> RoutedAsync(ChronosDatabase db, Job queued, RenderJobParameters parameters, CancellationToken cancellationToken)
|
||||
{
|
||||
if (queued.TargetIds is not [var sequenceId] || await db.Sequences.GetAsync(sequenceId, cancellationToken) is not { } sequence) return null;
|
||||
if (await SettingsAsync(db, parameters, sequence, cancellationToken) is not { } settings || ProcessingJobs.ReadSettings(settings.Json) is not { } read) return null;
|
||||
try
|
||||
{
|
||||
var (width, height) = await JobEndpoints.SourceSizeAsync(db, sequence.Id, parameters, cancellationToken);
|
||||
return ProcessingJobs.Routed(parameters, read, width, height);
|
||||
}
|
||||
catch (InvalidDataException)
|
||||
{
|
||||
// Not an export section: the render says so.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Settings with positions that wait for their photos (a project version's portable form, settings synced from another copy).</summary>
|
||||
private static bool Waits(string settingsJson) => settingsJson.Contains("pendingFrames", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
@@ -311,14 +337,25 @@ public sealed class RenderNodeService(
|
||||
if (state != node.State) events.Publish(new NodeStateEvent(node.Id, node.ClientName, state));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The node renders the job as asked: it reads the settings format the job needs (<see cref="RegisterNodeRequest.SettingsFormat"/>,
|
||||
/// 1 for an older node) and can encode it (<see cref="CanEncode"/>).
|
||||
/// </summary>
|
||||
internal static bool Renders(RegisterNodeRequest node, RenderJobParameters job) => job.RequiredSettingsFormat <= node.SettingsFormat && CanEncode(node, job);
|
||||
|
||||
/// <summary>
|
||||
/// The node has an encoder for the job's codec that handles its resolution: the encoder's own limit, else the node's
|
||||
/// (0 = no announced limit).
|
||||
/// (0 = no announced limit). A node of settings format 2 or more takes the limit as a long edge × short edge, as its
|
||||
/// encoders do (<see cref="Core.Export.EncoderSelector.Takes"/>: portrait UHD on a 4096×2304 encoder); an older node
|
||||
/// would shrink a portrait frame to the limit as announced, so it is held to it.
|
||||
/// </summary>
|
||||
internal static bool CanEncode(RegisterNodeRequest node, RenderJobParameters job) =>
|
||||
node.Encoders.Any(e => string.Equals(e.Codec, job.Codec, StringComparison.OrdinalIgnoreCase)
|
||||
&& Fits(job.Width, e.MaxWidth > 0 ? e.MaxWidth : node.MaxWidth)
|
||||
&& Fits(job.Height, e.MaxHeight > 0 ? e.MaxHeight : node.MaxHeight));
|
||||
&& Fits(job.Width, job.Height, e.MaxWidth > 0 ? e.MaxWidth : node.MaxWidth, e.MaxHeight > 0 ? e.MaxHeight : node.MaxHeight,
|
||||
eitherWay: node.SettingsFormat >= 2));
|
||||
|
||||
private static bool Fits(int width, int height, int maxWidth, int maxHeight, bool eitherWay) =>
|
||||
(Fits(width, maxWidth) && Fits(height, maxHeight)) || (eitherWay && Fits(height, maxWidth) && Fits(width, maxHeight));
|
||||
|
||||
private static bool Fits(int size, int limit) => limit <= 0 || size <= limit;
|
||||
|
||||
|
||||
Reference in new issue
Block a user