fix(render): ignore excluded frames in cached series and exposure steps
An excluded test shot at another exposure created holy-grail steps, and cached deep-analysis series still fed excluded frames into the fits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
2 files changed
+34
-7
No files matched your search
@@ -114,6 +114,9 @@ public static class RenderPreparation
|
||||
var cached = input.Analysis;
|
||||
var warnings = new List<RenderWarning>();
|
||||
var included = Included(input.Project.ExcludedFrames, n);
|
||||
var excluded = new bool[n];
|
||||
Array.Fill(excluded, true);
|
||||
foreach (var i in included) excluded[i] = false;
|
||||
|
||||
var deflicker = ProjectValues.Get(exposure.Deflicker, false);
|
||||
var holyGrail = ProjectValues.Get(exposure.HolyGrail, false);
|
||||
@@ -122,15 +125,15 @@ public static class RenderPreparation
|
||||
var stabilize = ProjectValues.Get(motion.Stabilize, false);
|
||||
var smoothing = ProjectValues.Get(motion.StabilizeSmoothing, new StabilizerOptions().SmoothingSigma);
|
||||
|
||||
var luminance = deflicker || holyGrail ? Valid(cached?.LogLuminance, n) : null;
|
||||
var luminance = deflicker || holyGrail ? Valid(cached?.LogLuminance, excluded) : null;
|
||||
var measureLuminance = (deflicker || holyGrail) && luminance is null;
|
||||
double[]? red = null, green = null, blue = null;
|
||||
if (whiteBalance && Valid(cached?.MeanRed, n) is { } r && Valid(cached?.MeanGreen, n) is { } g && Valid(cached?.MeanBlue, n) is { } b)
|
||||
if (whiteBalance && Valid(cached?.MeanRed, excluded) is { } r && Valid(cached?.MeanGreen, excluded) is { } g && Valid(cached?.MeanBlue, excluded) is { } b)
|
||||
(red, green, blue) = (r, g, b);
|
||||
var measureColour = whiteBalance && red is null;
|
||||
RegionMask? mask = null;
|
||||
double[]? sky = null, land = null;
|
||||
if (regionMode != RegionMode.Off && cached?.Regions is { } m && Valid(cached.SkyLogLuminance, n) is { } s && Valid(cached.LandLogLuminance, n) is { } l)
|
||||
if (regionMode != RegionMode.Off && cached?.Regions is { } m && Valid(cached.SkyLogLuminance, excluded) is { } s && Valid(cached.LandLogLuminance, excluded) is { } l)
|
||||
(mask, sky, land) = (m, s, l);
|
||||
var stabilization = stabilize ? CachedStabilization(cached, n, smoothing) : null;
|
||||
var measureStabilization = stabilize && stabilization is null;
|
||||
@@ -164,10 +167,10 @@ public static class RenderPreparation
|
||||
}
|
||||
}
|
||||
|
||||
return Combine(input, luminance, red, green, blue, mask, sky, land, stabilization, deflicker, holyGrail, pass.MeasuredFrames, warnings);
|
||||
return Combine(input, excluded, luminance, red, green, blue, mask, sky, land, stabilization, deflicker, holyGrail, pass.MeasuredFrames, warnings);
|
||||
}
|
||||
|
||||
private static RenderCorrections Combine(RenderInput input, double[]? luminance, double[]? red, double[]? green, double[]? blue, RegionMask? mask,
|
||||
private static RenderCorrections Combine(RenderInput input, bool[] excluded, double[]? luminance, double[]? red, double[]? green, double[]? blue, RegionMask? mask,
|
||||
double[]? sky, double[]? land, StabilizationData? stabilization, bool deflicker, bool holyGrail, int measured, List<RenderWarning> warnings)
|
||||
{
|
||||
var n = input.Source.FrameCount;
|
||||
@@ -184,7 +187,8 @@ public static class RenderPreparation
|
||||
Strength = double.Clamp(ProjectValues.Get(exposure.DeflickerStrength, 1.0), 0, 1),
|
||||
};
|
||||
var evs = new double?[n];
|
||||
for (var i = 0; i < n; i++) evs[i] = input.Frames[i].ExposureValue;
|
||||
// Excluded frames (test shots, bumps) must not create exposure steps.
|
||||
for (var i = 0; i < n; i++) evs[i] = excluded[i] ? null : input.Frames[i].ExposureValue;
|
||||
if (holyGrail)
|
||||
{
|
||||
var transition = ProjectValues.Get(exposure.TransitionLength, 0);
|
||||
@@ -287,7 +291,17 @@ public static class RenderPreparation
|
||||
return result;
|
||||
}
|
||||
|
||||
private static double[]? Valid(double[]? values, int n) => values is not null && values.Length == n ? values : null;
|
||||
/// <summary>A copy of a cached series with excluded frames marked unusable, or null when it does not fit the sequence.</summary>
|
||||
private static double[]? Valid(double[]? values, bool[] excluded)
|
||||
{
|
||||
if (values is null || values.Length != excluded.Length) return null;
|
||||
var copy = (double[])values.Clone();
|
||||
for (var i = 0; i < copy.Length; i++)
|
||||
{
|
||||
if (excluded[i]) copy[i] = double.NaN;
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
private static double[] NaNs(int n)
|
||||
{
|
||||
|
||||
@@ -69,6 +69,19 @@ public sealed class RenderProcessingTests
|
||||
Assert.Approximately(-1.0, output[^1] - output[0], 0.1, "the step is kept, only spread out");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ExcludedFramesDoNotCreateExposureSteps()
|
||||
{
|
||||
// Frame 10 is a test shot one stop darker; excluding it must leave no holy-grail step behind.
|
||||
var source = Source(30, configure: o => o with { ExposureSteps = [new SyntheticExposureStep(10, 1.0), new SyntheticExposureStep(11, -1.0)], StartEv = 0, EndEv = 0 });
|
||||
var project = With(new ExposureSettings { HolyGrail = On(true), HighlightKnee = null });
|
||||
var all = await RenderPreparation.PrepareAsync(Input(source, project), cancellationToken: _context.Cancellation);
|
||||
var excluded = await RenderPreparation.PrepareAsync(Input(source, project with { ExcludedFrames = [10] }), cancellationToken: _context.Cancellation);
|
||||
Assert.Count(2, all.Report.Transitions);
|
||||
Assert.Empty(excluded.Report.Transitions);
|
||||
Assert.True(double.IsNaN(excluded.MeasuredLogLuminance[10]));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task WhiteBalanceSmoothingRemovesColourJitter()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user