using Chronos.Core.Export;
using Chronos.Core.Project;
using Chronos.Core.Video;
namespace Chronos.Core.Render;
///
/// What a render needs of the program that runs it (owner review 1, phase 4): the settings format a render node or server
/// must read to render a job as this Chronos would. Computed for routing and gating only, never written into the settings.
///
public static class RenderRules
{
///
/// The settings format a still job needs (owner review 1, R8, "Save frame"): an older program reads the job as a render
/// of the whole video, so it must never claim one.
///
public const int StillFormat = 3;
/// The codecs a still frame is saved with, in the order "Save frame" offers them: PNG, JPEG and TIFF 16-bit.
public static IReadOnlyList StillCodecs { get; } = [VideoCodec.PngSequence, VideoCodec.JpegSequence, VideoCodec.Tiff16Sequence];
///
/// , and at least for a
/// still job (: one frame saved as an image).
///
public static int RequiredFormat(ProjectSettings settings, ResolvedExport export, int sourceWidth, int sourceHeight, bool still)
{
var format = RequiredFormat(settings, export, sourceWidth, sourceHeight);
return still ? int.Max(format, StillFormat) : format;
}
///
/// The settings format a render of needs:
/// for its export, a still when is set.
///
public static int RequiredFormat(ProjectSettings settings, RenderTarget target, int sourceWidth, int sourceHeight)
{
ArgumentNullException.ThrowIfNull(target);
return RequiredFormat(settings, target.Export, sourceWidth, sourceHeight, target.IsStill);
}
///
/// The settings format a render of with on a source of the given
/// (Exif-oriented) size needs: the format the settings are written in (, 3 when
/// plays other than forward once, so the settings must carry the export the job
/// renders), and at least 2 when the chosen proportions change a fixed-size preset's size (), which
/// a format-1 program would render at the preset's own ratio.
///
public static int RequiredFormat(ProjectSettings settings, ResolvedExport export, int sourceWidth, int sourceHeight)
{
ArgumentNullException.ThrowIfNull(settings);
ArgumentNullException.ThrowIfNull(export);
var format = settings.WrittenFormat;
if (export.Width > 0 && export.Height > 0 && sourceWidth > 0 && sourceHeight > 0 && !RenderSize.IsSource(settings.Camera)
&& RenderSize.Of(settings.Camera, export, sourceWidth, sourceHeight) != PresetSize(export))
format = int.Max(format, 2);
return format;
}
/// A fixed-size preset's size as a format-1 program renders it (even for codecs that are not managed).
private static (int Width, int Height) PresetSize(ResolvedExport export) =>
RenderSize.Of(new CameraSettings(), export, 1, 1);
}