From 93dd1f59dc5c36db1a552e8bc96e0260de1e0759 Mon Sep 17 00:00:00 2001 From: OmrSi Date: Tue, 23 Nov 2021 19:16:41 +0200 Subject: [PATCH] Improve rounding for NQC --- src/libse/NetflixQualityCheck/NetflixCheckBridgeGaps.cs | 2 +- src/libse/NetflixQualityCheck/NetflixCheckSceneChange.cs | 4 ++-- src/libse/SubtitleFormats/SubtitleFormat.cs | 2 +- src/ui/Forms/NetflixFixErrors.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libse/NetflixQualityCheck/NetflixCheckBridgeGaps.cs b/src/libse/NetflixQualityCheck/NetflixCheckBridgeGaps.cs index abf2b7ef1..b1bacab97 100644 --- a/src/libse/NetflixQualityCheck/NetflixCheckBridgeGaps.cs +++ b/src/libse/NetflixQualityCheck/NetflixCheckBridgeGaps.cs @@ -19,7 +19,7 @@ namespace Nikse.SubtitleEdit.Core.NetflixQualityCheck } double twoFramesGap = 1000.0 / controller.FrameRate * 2.0; - int halfSecGap = (int)Math.Round(controller.FrameRate / 2); + int halfSecGap = (int)Math.Round(controller.FrameRate / 2, MidpointRounding.AwayFromZero); for (int index = 0; index < subtitle.Paragraphs.Count; index++) { diff --git a/src/libse/NetflixQualityCheck/NetflixCheckSceneChange.cs b/src/libse/NetflixQualityCheck/NetflixCheckSceneChange.cs index 92740b77b..87ec8f224 100644 --- a/src/libse/NetflixQualityCheck/NetflixCheckSceneChange.cs +++ b/src/libse/NetflixQualityCheck/NetflixCheckSceneChange.cs @@ -25,7 +25,7 @@ namespace Nikse.SubtitleEdit.Core.NetflixQualityCheck return; } - int halfSecGapInFrames = (int)Math.Round(controller.FrameRate / 2); + int halfSecGapInFrames = (int)Math.Round(controller.FrameRate / 2, MidpointRounding.AwayFromZero); double twoFramesGap = 1000.0 / controller.FrameRate * 2.0; foreach (Paragraph p in subtitle.Paragraphs) @@ -54,7 +54,7 @@ namespace Nikse.SubtitleEdit.Core.NetflixQualityCheck { double nearestStartNextSceneChange = nextStartSceneChanges.Aggregate((x, y) => Math.Abs(x - p.StartTime.TotalSeconds) < Math.Abs(y - p.StartTime.TotalSeconds) ? x : y); var gapToSceneChange = SubtitleFormat.MillisecondsToFrames(nearestStartNextSceneChange * 1000 - p.StartTime.TotalMilliseconds); - var threshold = (int)Math.Round(halfSecGapInFrames * 0.75); + var threshold = (int)Math.Round(halfSecGapInFrames * 0.75, MidpointRounding.AwayFromZero); if (gapToSceneChange < halfSecGapInFrames) { if (gapToSceneChange < threshold) diff --git a/src/libse/SubtitleFormats/SubtitleFormat.cs b/src/libse/SubtitleFormats/SubtitleFormat.cs index 1226fcd50..99c937939 100644 --- a/src/libse/SubtitleFormats/SubtitleFormat.cs +++ b/src/libse/SubtitleFormats/SubtitleFormat.cs @@ -448,7 +448,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats public static int MillisecondsToFramesMaxFrameRate(double milliseconds) { - int frames = (int)Math.Round(milliseconds / (TimeCode.BaseUnit / GetFrameForCalculation(Configuration.Settings.General.CurrentFrameRate))); + int frames = (int)Math.Round(milliseconds / (TimeCode.BaseUnit / GetFrameForCalculation(Configuration.Settings.General.CurrentFrameRate)), MidpointRounding.AwayFromZero); if (frames >= Configuration.Settings.General.CurrentFrameRate) { frames = (int)(Configuration.Settings.General.CurrentFrameRate - 0.01); diff --git a/src/ui/Forms/NetflixFixErrors.cs b/src/ui/Forms/NetflixFixErrors.cs index 1d78470b6..daaa06eb7 100644 --- a/src/ui/Forms/NetflixFixErrors.cs +++ b/src/ui/Forms/NetflixFixErrors.cs @@ -65,7 +65,7 @@ namespace Nikse.SubtitleEdit.Forms checkBoxNoItalics.Checked = !_netflixQualityController.AllowItalics; checkBoxNoItalics.Enabled = !_netflixQualityController.AllowItalics; - int halfSecGapInFrames = (int)Math.Round(_frameRate / 2); + int halfSecGapInFrames = (int)Math.Round(_frameRate / 2, MidpointRounding.AwayFromZero); checkBoxGapBridge.Text = $"Frame gap: 3 to {halfSecGapInFrames - 1} frames => 2 frames"; var sceneChangesExist = false;