using Titano.Core.Analysis;
using Titano.Core.Export;
using Titano.Core.Imaging;
using Titano.Core.Motion;
using Titano.Core.Project;
namespace Titano.Core.Render;
/// Everything a render of one sequence reads, shared by every preset of a batch.
public sealed record RenderInput
{
public required IRenderFrameSource Source { get; init; }
/// Capture metadata, one entry per source frame.
public required IReadOnlyList Frames { get; init; }
public required ProjectSettings Project { get; init; }
/// Cached deep-analysis results; missing parts are measured by the preparation pass.
public PrecomputedAnalysis? Analysis { get; init; }
}
/// One output of a render: the resolved export values and where the file (or sequence folder) goes.
/// Full path of the file, or of the folder for image sequences (see ).
public sealed record RenderTarget(ResolvedExport Export, string OutputPath);
/// Tuning of a render that is not part of the project.
public sealed record RenderOptions
{
public static RenderOptions Default { get; } = new();
/// Long edge of the frames measured by the preparation pass.
public int AnalysisLongEdge { get; init; } = 512;
/// Upper bound of the decode size (0 = as large as the output geometry needs); previews set a small value.
public int MaxWorkingLongEdge { get; init; }
/// A downscaled copy of every n-th rendered frame is reported for the live preview (0 = never).
public int PreviewInterval { get; init; }
public int PreviewLongEdge { get; init; } = 640;
/// Prepared (exposure-corrected, warped) frames kept for flow and interpolation neighbours (at least 3).
public int CacheFrames { get; init; } = 4;
public RenderPlanOptions Plan { get; init; } = RenderPlanOptions.Default;
}
public enum RenderStage
{
/// Measuring the sequence (luminance, colour, camera path).
Preparing,
/// Rendering and encoding output frames.
Rendering,
/// Flushing and committing the output.
Finishing,
}
/// Progress of a render. (when present) belongs to the receiver, which disposes it.
/// Frames measured (Preparing) or output frames rendered (Rendering).
/// Frames of the current stage.
/// Recent throughput of the current stage.
/// Estimated time to the end of the stage; null until measurable.
public sealed record RenderProgress(RenderStage Stage, int Done, int Total, double FramesPerSecond, TimeSpan Elapsed, TimeSpan? Remaining, ImageBuffer? Preview = null)
{
public double Fraction => Total > 0 ? (double)Done / Total : 0;
}
///
/// Results of the advisor's deep analysis reused by the preparation (all arrays have one entry per source frame).
/// Invalid or mismatched parts are ignored and measured again.
///
public sealed record PrecomputedAnalysis
{
/// Trimmed-mean log2 luminance (NaN = unusable frame).
public double[]? LogLuminance { get; init; }
/// Mean linear red, green and blue (white-balance smoothing).
public double[]? MeanRed { get; init; }
public double[]? MeanGreen { get; init; }
public double[]? MeanBlue { get; init; }
/// Sky/land mask with the region series measured through it.
public RegionMask? Regions { get; init; }
public double[]? SkyLogLuminance { get; init; }
public double[]? LandLogLuminance { get; init; }
/// Stabilisation solved over the sequence, one correction per source frame, in pixels of a frame of
/// ×.
public StabilizationResult? Stabilization { get; init; }
public int StabilizationWidth { get; init; }
public int StabilizationHeight { get; init; }
/// Path smoothing σ the stabilisation was solved with; a different project value triggers a new solve.
public double StabilizationSmoothing { get; init; }
}
/// A localisable remark about a render (key plus invariant-culture arguments).
public sealed record RenderWarning(string Key, IReadOnlyList Args)
{
public RenderWarning(string key, params string[] args) : this(key, (IReadOnlyList)args)
{
}
public override string ToString() => Args.Count == 0 ? Key : $"{Key}({string.Join(", ", Args)})";
}
/// A render that cannot start or continue for a reason the user can act on.
public sealed class RenderException : Exception
{
public RenderException(string reasonKey, string message, IReadOnlyList? args = null, Exception? innerException = null)
: base(message, innerException)
{
ReasonKey = reasonKey;
Args = args ?? [];
}
/// Localisation key of the reason (e.g. ).
public string ReasonKey { get; }
public IReadOnlyList Args { get; }
}