Optimize mcc loading a bit

This commit is contained in:
niksedk 2022-04-30 09:44:01 +02:00
parent 10564a4e47
commit bb19964fba
2 changed files with 40 additions and 15 deletions

View File

@ -274,23 +274,25 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
.Replace("00", "Z");
}
private static byte[] HexStringToByteArray(string hex)
private static byte[] HexStringToByteArray(string hexString)
{
try
{
var numberChars = hex.Length;
var bytes = new byte[numberChars / 2];
for (var i = 0; i < numberChars - 1; i += 2)
{
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
}
return bytes;
}
catch
if (hexString.Length % 2 != 0)
{
return new byte[] { };
}
var ret = new byte[hexString.Length / 2];
for (var i = 0; i < ret.Length; i++)
{
int high = hexString[i * 2];
int low = hexString[i * 2 + 1];
high = (high & 0xf) + ((high & 0x40) >> 6) * 9;
low = (low & 0xf) + ((low & 0x40) >> 6) * 9;
ret[i] = (byte)((high << 4) | low);
}
return ret;
}
}
}

View File

@ -19,11 +19,13 @@ using Nikse.SubtitleEdit.Forms.FormatProperties;
using Nikse.SubtitleEdit.Forms.Networking;
using Nikse.SubtitleEdit.Forms.Ocr;
using Nikse.SubtitleEdit.Forms.Options;
using Nikse.SubtitleEdit.Forms.SeJobs;
using Nikse.SubtitleEdit.Forms.Styles;
using Nikse.SubtitleEdit.Forms.Translate;
using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.CommandLineConvert;
using Nikse.SubtitleEdit.Logic.Networking;
using Nikse.SubtitleEdit.Logic.SeJob;
using Nikse.SubtitleEdit.Logic.VideoPlayers;
using System;
using System.Collections.Generic;
@ -39,8 +41,6 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Forms.SeJobs;
using Nikse.SubtitleEdit.Logic.SeJob;
namespace Nikse.SubtitleEdit.Forms
{
@ -3075,6 +3075,29 @@ namespace Nikse.SubtitleEdit.Forms
}
}
if (ext == ".mcc")
{
var lines = FileUtil.ReadAllTextShared(fileName, Encoding.ASCII).SplitToLines();
var f = new MacCaption10();
if (f.IsMine(lines, fileName))
{
f.LoadSubtitle(_subtitle, lines, fileName);
_oldSubtitleFormat = f;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
SubtitleListview1.Fill(_subtitle);
_subtitleListViewIndex = -1;
SubtitleListview1.FirstVisibleIndex = -1;
SubtitleListview1.SelectIndexAndEnsureVisible(0, true);
_fileName = Utilities.GetPathAndFileNameWithoutExtension(fileName) + GetCurrentSubtitleFormat().Extension;
SetTitle();
ShowStatus(string.Format(_language.LoadedSubtitleX, _fileName));
_converted = true;
return;
}
}
if (file.Length > Subtitle.MaxFileSize)
{
// retry Blu-ray sup (file with wrong extension)