From bec59649e2fccb9c42c740c7387a7af0b7ff1c50 Mon Sep 17 00:00:00 2001 From: niksedk Date: Sat, 11 Dec 2021 18:29:17 +0100 Subject: [PATCH] Trying to make nOCR work better with corrupted files - thx k7Up :) --- src/ui/Logic/Ocr/NOcrChar.cs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/ui/Logic/Ocr/NOcrChar.cs b/src/ui/Logic/Ocr/NOcrChar.cs index ccaa55398..fe839bc09 100644 --- a/src/ui/Logic/Ocr/NOcrChar.cs +++ b/src/ui/Logic/Ocr/NOcrChar.cs @@ -97,6 +97,10 @@ namespace Nikse.SubtitleEdit.Logic.Ocr stream.Read(buffer, 0, buffer.Length); Text = System.Text.Encoding.UTF8.GetString(buffer); } + else + { + Text = string.Empty; + } if (isShort) { @@ -109,7 +113,14 @@ namespace Nikse.SubtitleEdit.Logic.Ocr LinesBackground = ReadPoints(stream); } - LoadedOk = true; + if (Width >= 0 && Height >= 0 && Width <= 1920 && Height <= 1080 && Text.IndexOf('\0') < 0) + { + LoadedOk = true; + } + else + { + LoadedOk = false; + } } else { @@ -137,10 +148,22 @@ namespace Nikse.SubtitleEdit.Logic.Ocr stream.Read(buffer, 0, buffer.Length); Text = System.Text.Encoding.UTF8.GetString(buffer); } + else + { + Text = string.Empty; + } + LinesForeground = ReadPoints(stream); LinesBackground = ReadPoints(stream); - LoadedOk = true; + if (Width >= 0 && Height >= 0 && Width <= 1920 && Height <= 1080 && Text.IndexOf('\0') < 0) + { + LoadedOk = true; + } + else + { + LoadedOk = false; + } } } catch