This commit is contained in:
Nikolaj Olsson 2019-01-19 12:29:38 +01:00
parent 5de6cf6df6
commit 1468fa7642
28 changed files with 532 additions and 566 deletions

View File

@ -21,23 +21,23 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
public class BluRaySupPalette
{
/** Number of palette entries */
private int size;
private readonly int _size;
/** Byte buffer for RED info */
private byte[] r;
private readonly byte[] _r;
/** Byte buffer for GREEN info */
private byte[] g;
private readonly byte[] _g;
/** Byte buffer for BLUE info */
private byte[] b;
private readonly byte[] _b;
/** Byte buffer for alpha info */
private byte[] a;
private readonly byte[] _a;
/** Byte buffer for Y (luminance) info */
private byte[] y;
private readonly byte[] _y;
/** Byte buffer for Cb (chrominance blue) info */
private byte[] cb;
private readonly byte[] _cb;
/** Byte buffer for Cr (chrominance red) info */
private byte[] cr;
private readonly byte[] _cr;
/** Use BT.601 color model instead of BT.709 */
private bool useBT601;
private readonly bool _useBt601;
/**
* Convert YCBCr color info to RGB
@ -48,7 +48,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public static int[] YCbCr2Rgb(int y, int cb, int cr, bool useBt601)
{
int[] rgb = new int[3];
var rgb = new int[3];
double r, g, b;
y -= 16;
@ -76,9 +76,13 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
for (int i = 0; i < 3; i++)
{
if (rgb[i] < 0)
{
rgb[i] = 0;
}
else if (rgb[i] > 255)
{
rgb[i] = 255;
}
}
return rgb;
}
@ -92,7 +96,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
private static int[] Rgb2YCbCr(int r, int g, int b, bool useBt601)
{
int[] yCbCr = new int[3];
var yCbCr = new int[3];
double y, cb, cr;
if (useBt601)
@ -115,18 +119,24 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
for (int i = 0; i < 3; i++)
{
if (yCbCr[i] < 16)
{
yCbCr[i] = 16;
}
else
{
if (i == 0)
{
if (yCbCr[i] > 235)
{
yCbCr[i] = 235;
}
}
else
{
if (yCbCr[i] > 240)
{
yCbCr[i] = 240;
}
}
}
}
@ -140,27 +150,27 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public BluRaySupPalette(int palSize, bool use601)
{
size = palSize;
useBT601 = use601;
r = new byte[size];
g = new byte[size];
b = new byte[size];
a = new byte[size];
y = new byte[size];
cb = new byte[size];
cr = new byte[size];
_size = palSize;
_useBt601 = use601;
_r = new byte[_size];
_g = new byte[_size];
_b = new byte[_size];
_a = new byte[_size];
_y = new byte[_size];
_cb = new byte[_size];
_cr = new byte[_size];
// set at least all alpha values to invisible
int[] yCbCr = Rgb2YCbCr(0, 0, 0, useBT601);
var yCbCr = Rgb2YCbCr(0, 0, 0, _useBt601);
for (int i = 0; i < palSize; i++)
{
a[i] = 0;
r[i] = 0;
g[i] = 0;
b[i] = 0;
y[i] = (byte)yCbCr[0];
cb[i] = (byte)yCbCr[1];
cr[i] = (byte)yCbCr[2];
_a[i] = 0;
_r[i] = 0;
_g[i] = 0;
_b[i] = 0;
_y[i] = (byte)yCbCr[0];
_cb[i] = (byte)yCbCr[1];
_cr[i] = (byte)yCbCr[2];
}
}
@ -183,66 +193,54 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public BluRaySupPalette(byte[] red, byte[] green, byte[] blue, byte[] alpha, bool use601)
{
size = red.Length;
useBT601 = use601;
r = new byte[size];
g = new byte[size];
b = new byte[size];
a = new byte[size];
y = new byte[size];
cb = new byte[size];
cr = new byte[size];
_size = red.Length;
_useBt601 = use601;
_r = new byte[_size];
_g = new byte[_size];
_b = new byte[_size];
_a = new byte[_size];
_y = new byte[_size];
_cb = new byte[_size];
_cr = new byte[_size];
for (int i = 0; i < size; i++)
for (int i = 0; i < _size; i++)
{
a[i] = alpha[i];
r[i] = red[i];
g[i] = green[i];
b[i] = blue[i];
var yCbCr = Rgb2YCbCr(r[i] & 0xff, g[i] & 0xff, b[i] & 0xff, useBT601);
y[i] = (byte)yCbCr[0];
cb[i] = (byte)yCbCr[1];
cr[i] = (byte)yCbCr[2];
_a[i] = alpha[i];
_r[i] = red[i];
_g[i] = green[i];
_b[i] = blue[i];
var yCbCr = Rgb2YCbCr(_r[i] & 0xff, _g[i] & 0xff, _b[i] & 0xff, _useBt601);
_y[i] = (byte)yCbCr[0];
_cb[i] = (byte)yCbCr[1];
_cr[i] = (byte)yCbCr[2];
}
}
/**
* Ctor - construct palette from red, green blue and alpha buffers
* @param red Byte buffer containing the red components
* @param green Byte buffer containing the green components
* @param blue Byte buffer containing the blue components
* @param alpha Byte buffer containing the alpha components
*/
public BluRaySupPalette(byte[] red, byte[] green, byte[] blue, byte[] alpha)
: this(red, green, blue, alpha, false)
{
}
/**
* Ctor - construct new (independent) palette from existing one
* @param p Palette to copy values from
*/
public BluRaySupPalette(BluRaySupPalette p)
{
size = p.GetSize();
useBT601 = p.UsesBt601();
r = new byte[size];
g = new byte[size];
b = new byte[size];
a = new byte[size];
y = new byte[size];
cb = new byte[size];
cr = new byte[size];
_size = p.GetSize();
_useBt601 = p.UsesBt601();
_r = new byte[_size];
_g = new byte[_size];
_b = new byte[_size];
_a = new byte[_size];
_y = new byte[_size];
_cb = new byte[_size];
_cr = new byte[_size];
for (int i = 0; i < size; i++)
for (int i = 0; i < _size; i++)
{
a[i] = p.a[i];
r[i] = p.r[i];
g[i] = p.g[i];
b[i] = p.b[i];
y[i] = p.y[i];
cb[i] = p.cb[i];
cr[i] = p.cr[i];
_a[i] = p._a[i];
_r[i] = p._r[i];
_g[i] = p._g[i];
_b[i] = p._b[i];
_y[i] = p._y[i];
_cb[i] = p._cb[i];
_cr[i] = p._cr[i];
}
}
@ -268,7 +266,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public int GetArgb(int index)
{
return ((a[index] & 0xff) << 24) | ((r[index] & 0xff) << 16) | ((g[index] & 0xff) << 8) | (b[index] & 0xff);
return ((_a[index] & 0xff) << 24) | ((_r[index] & 0xff) << 16) | ((_g[index] & 0xff) << 8) | (_b[index] & 0xff);
}
internal void SetColor(int index, System.Drawing.Color color)
@ -286,14 +284,14 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public void SetRgb(int index, int red, int green, int blue)
{
r[index] = (byte)red;
g[index] = (byte)green;
b[index] = (byte)blue;
_r[index] = (byte)red;
_g[index] = (byte)green;
_b[index] = (byte)blue;
// create yCbCr
int[] yCbCr = Rgb2YCbCr(red, green, blue, useBT601);
y[index] = (byte)yCbCr[0];
cb[index] = (byte)yCbCr[1];
cr[index] = (byte)yCbCr[2];
var yCbCr = Rgb2YCbCr(red, green, blue, _useBt601);
_y[index] = (byte)yCbCr[0];
_cb[index] = (byte)yCbCr[1];
_cr[index] = (byte)yCbCr[2];
}
/**
@ -305,14 +303,14 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public void SetYCbCr(int index, int yn, int cbn, int crn)
{
y[index] = (byte)yn;
cb[index] = (byte)cbn;
cr[index] = (byte)crn;
_y[index] = (byte)yn;
_cb[index] = (byte)cbn;
_cr[index] = (byte)crn;
// create RGB
int[] rgb = YCbCr2Rgb(yn, cbn, crn, useBT601);
r[index] = (byte)rgb[0];
g[index] = (byte)rgb[1];
b[index] = (byte)rgb[2];
var rgb = YCbCr2Rgb(yn, cbn, crn, _useBt601);
_r[index] = (byte)rgb[0];
_g[index] = (byte)rgb[1];
_b[index] = (byte)rgb[2];
}
/**
@ -322,7 +320,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public void SetAlpha(int index, int alpha)
{
a[index] = (byte)alpha;
_a[index] = (byte)alpha;
}
/**
@ -332,7 +330,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public int GetAlpha(int index)
{
return a[index] & 0xff;
return _a[index] & 0xff;
}
/**
@ -341,7 +339,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public byte[] GetAlpha()
{
return a;
return _a;
}
/**
@ -351,10 +349,10 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public int[] GetRgb(int index)
{
int[] rgb = new int[3];
rgb[0] = r[index] & 0xff;
rgb[1] = g[index] & 0xff;
rgb[2] = b[index] & 0xff;
var rgb = new int[3];
rgb[0] = _r[index] & 0xff;
rgb[1] = _g[index] & 0xff;
rgb[2] = _b[index] & 0xff;
return rgb;
}
@ -365,10 +363,10 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public int[] GetYCbCr(int index)
{
int[] yCbCr = new int[3];
yCbCr[0] = y[index] & 0xff;
yCbCr[1] = cb[index] & 0xff;
yCbCr[2] = cr[index] & 0xff;
var yCbCr = new int[3];
yCbCr[0] = _y[index] & 0xff;
yCbCr[1] = _cb[index] & 0xff;
yCbCr[2] = _cr[index] & 0xff;
return yCbCr;
}
@ -378,7 +376,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public byte[] GetR()
{
return r;
return _r;
}
/**
@ -387,7 +385,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public byte[] GetG()
{
return g;
return _g;
}
/**
@ -396,7 +394,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public byte[] GetB()
{
return b;
return _b;
}
/**
@ -405,7 +403,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public byte[] GetY()
{
return y;
return _y;
}
/**
@ -414,7 +412,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public byte[] GetCb()
{
return cb;
return _cb;
}
/**
@ -423,7 +421,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public byte[] GetCr()
{
return cr;
return _cr;
}
/**
@ -432,7 +430,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public int GetSize()
{
return size;
return _size;
}
/**
@ -444,14 +442,16 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
// find (most) transparent index in palette
int transpIdx = 0;
int minAlpha = 0x100;
for (int i = 0; i < size; i++)
for (int i = 0; i < _size; i++)
{
if ((a[i] & 0xff) < minAlpha)
if ((_a[i] & 0xff) < minAlpha)
{
minAlpha = a[i] & 0xff;
minAlpha = _a[i] & 0xff;
transpIdx = i;
if (minAlpha == 0)
{
break;
}
}
}
return transpIdx;
@ -463,7 +463,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
*/
public bool UsesBt601()
{
return useBT601;
return _useBt601;
}
}

View File

@ -181,7 +181,7 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.Mp4
if (Name == "mdat")
{
var before = (long)fs.Position;
var before = fs.Position;
var readLength = ((long)Position) - before;
if (readLength > 10)
{

View File

@ -20,8 +20,7 @@ namespace Nikse.SubtitleEdit.Core
public DvdSubtitleLanguage GetValueOrNull(string code)
{
DvdSubtitleLanguage language;
Dictionary.TryGetValue(code, out language);
Dictionary.TryGetValue(code, out var language);
return language;
}
@ -31,16 +30,15 @@ namespace Nikse.SubtitleEdit.Core
}
}
private static readonly Dictionary<string, string> _isoToDvd = new Dictionary<string, string>
private static readonly Dictionary<string, string> IsoToDvd = new Dictionary<string, string>
{
{ "yi", "ji" }, { "jv", "jw" }, { "id", "in" }, { "he", "iw" } // { "bs", "sh" }, { "nb", "no" }, { "nn", "no" } ???
};
private static readonly Dictionary<string, string> _dvdToIso = new Dictionary<string, string>
private static readonly Dictionary<string, string> DvdToIso = new Dictionary<string, string>
{
{ "ji", "yi" }, { "jw", "jv" }, { "in", "id" }, { "iw", "he" }
};
private static readonly string[] _compliantDescriptions = new[]
{ // DVD code + native name
private static readonly string[] CompliantDescriptions = { // DVD code + native name
"aa:Qafár af", "ab:аҧсуа бызшәа", "af:Afrikaans", "am:አማርኛ", "ar:العربية", "as:অসমীয়া", "ay:Aymar aru", "az:azərbaycan dili", "ba:башҡорт теле", "be:беларуская",
"bg:български", "bh:भोजपुरी", "bi:Bislama", "bn:বাংলা", "bo:བོད་སྐད་", "br:brezhoneg", "ca:català", "co:corsu", "cs:čeština", "cy:Cymraeg", "da:dansk", "de:Deutsch", "dz:རྫོང་ཁ",
"el:Ελληνικά", "en:English", "eo:esperanto", "es:español", "et:eesti", "eu:euskara", "fa:فارسی", "fi:suomi", "fj:Vosa Vakaviti", "fo:føroyskt", "fr:français",
@ -56,11 +54,11 @@ namespace Nikse.SubtitleEdit.Core
};
private static LanguagesByCode _compliantLanguagesByCode;
public string Code { get; private set; }
public string LocalName { get; private set; }
public string NativeName { get; private set; }
public string Code { get; }
public string LocalName { get; }
public string NativeName { get; }
private DvdSubtitleLanguage(string code, string localName, string nativeName)
public DvdSubtitleLanguage(string code, string localName, string nativeName)
{
Code = code;
LocalName = localName;
@ -73,7 +71,7 @@ namespace Nikse.SubtitleEdit.Core
var code = description.Remove(2);
Code = code;
var names = Configuration.Settings.Language.LanguageNames;
LocalName = (string)names.GetType().GetProperty(DvdToIso(code) + "Name").GetValue(names, null);
LocalName = (string)names.GetType().GetProperty(ConvertDvdToIso(code) + "Name")?.GetValue(names, null);
}
public override string ToString()
@ -81,21 +79,9 @@ namespace Nikse.SubtitleEdit.Core
return LocalName;
}
public static DvdSubtitleLanguage English
{
get
{
return CompliantLanguagesByCode["en"];
}
}
public static DvdSubtitleLanguage English => CompliantLanguagesByCode["en"];
public static IEnumerable<DvdSubtitleLanguage> CompliantLanguages
{
get
{
return CompliantLanguagesByCode;
}
}
public static IEnumerable<DvdSubtitleLanguage> CompliantLanguages => CompliantLanguagesByCode;
private static LanguagesByCode CompliantLanguagesByCode
{
@ -103,8 +89,8 @@ namespace Nikse.SubtitleEdit.Core
{
if (_compliantLanguagesByCode == null)
{
var cl = _compliantDescriptions.Select(s => new DvdSubtitleLanguage(s)).OrderBy(dsl => dsl.LocalName, StringComparer.CurrentCultureIgnoreCase).ThenBy(dsl => dsl.LocalName, StringComparer.Ordinal);
var ns = new DvdSubtitleLanguage[] { new DvdSubtitleLanguage(" ", Configuration.Settings.Language.LanguageNames.NotSpecified, "Not Specified") };
var cl = CompliantDescriptions.Select(s => new DvdSubtitleLanguage(s)).OrderBy(dsl => dsl.LocalName, StringComparer.CurrentCultureIgnoreCase).ThenBy(dsl => dsl.LocalName, StringComparer.Ordinal);
var ns = new[] { new DvdSubtitleLanguage(" ", Configuration.Settings.Language.LanguageNames.NotSpecified, "Not Specified") };
_compliantLanguagesByCode = new LanguagesByCode(ns.Concat(cl));
}
return _compliantLanguagesByCode;
@ -130,7 +116,7 @@ namespace Nikse.SubtitleEdit.Core
public static DvdSubtitleLanguage GetLanguageOrNull(string code)
{
code = IsoToDvd(code.ToLowerInvariant());
code = ConvertIsoToDvd(code.ToLowerInvariant());
return CompliantLanguagesByCode.GetValueOrNull(code);
}
@ -149,7 +135,9 @@ namespace Nikse.SubtitleEdit.Core
}
catch
{
// ignored
}
return codeCulture.EnglishName; // SE culture != UI culture
}
catch
@ -170,18 +158,16 @@ namespace Nikse.SubtitleEdit.Core
}
}
private static string DvdToIso(string dvdCode)
private static string ConvertDvdToIso(string dvdCode)
{
string isoCode;
if (!_dvdToIso.TryGetValue(dvdCode, out isoCode))
if (!DvdToIso.TryGetValue(dvdCode, out var isoCode))
isoCode = dvdCode;
return isoCode;
}
private static string IsoToDvd(string isoCode)
private static string ConvertIsoToDvd(string isoCode)
{
string dvdCode;
if (!_isoToDvd.TryGetValue(isoCode, out dvdCode))
if (!IsoToDvd.TryGetValue(isoCode, out var dvdCode))
dvdCode = isoCode;
return dvdCode;
}

View File

@ -308,14 +308,14 @@ namespace Nikse.SubtitleEdit.Core
return RichTextToPlainText.ConvertToText(value);
}
public static string RemoveChar(this string value, char removeChar)
public static string RemoveChar(this string value, char charToRemove)
{
char[] array = new char[value.Length];
int arrayIndex = 0;
for (int i = 0; i < value.Length; i++)
{
char ch = value[i];
if (ch != removeChar)
if (ch != charToRemove)
array[arrayIndex++] = ch;
}
return new string(array, 0, arrayIndex);

View File

@ -466,13 +466,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
subtitle.Renumber();
}
public override List<string> AlternateExtensions
{
get
{
return new List<string>() { ".2HD", ".1SD", ".2SD" }; // 1HD = first HD subtitle, 2SD = second SD subtitle
}
}
// 1HD = first HD subtitle, 2SD = second SD subtitle
public override List<string> AlternateExtensions => new List<string> { ".2HD", ".1SD", ".2SD" };
}
}

View File

@ -524,120 +524,118 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
string lastVPosition = string.Empty;
foreach (XmlNode innerNode in node.ChildNodes)
{
switch (innerNode.Name)
if (innerNode.Name == "Text")
{
case "Text":
if (innerNode.Attributes["VPosition"] != null)
if (innerNode.Attributes["VPosition"] != null)
{
string vPosition = innerNode.Attributes["VPosition"].InnerText;
var vAlignmentNode = innerNode.Attributes["VAlign"];
if (vAlignmentNode != null)
vAlignment = vAlignmentNode.InnerText;
if (vPosition != lastVPosition)
{
string vPosition = innerNode.Attributes["VPosition"].InnerText;
var vAlignmentNode = innerNode.Attributes["VAlign"];
if (vAlignmentNode != null)
vAlignment = vAlignmentNode.InnerText;
if (vPosition != lastVPosition)
if (pText.Length > 0 && lastVPosition.Length > 0)
{
if (pText.Length > 0 && lastVPosition.Length > 0)
{
textLines.Add(new SubtitleLine(pText.ToString(), lastVPosition, vAlignment));
pText.Clear();
}
lastVPosition = vPosition;
}
}
bool alignLeft = false;
bool alignRight = false;
bool alignVTop = false;
bool alignVCenter = false;
if (innerNode.Attributes["HAlign"] != null)
{
string hAlign = innerNode.Attributes["HAlign"].InnerText;
if (hAlign == "left")
alignLeft = true;
else if (hAlign == "right")
alignRight = true;
}
if (innerNode.Attributes["VAlign"] != null)
{
string hAlign = innerNode.Attributes["VAlign"].InnerText;
if (hAlign == "top")
alignVTop = true;
else if (hAlign == "center")
alignVCenter = true;
}
if (alignLeft || alignRight || alignVCenter || alignVTop)
{
if (!pText.ToString().StartsWith("{\\an", StringComparison.Ordinal))
{
string pre = string.Empty;
if (alignVTop)
{
if (alignLeft)
pre = "{\\an7}";
else if (alignRight)
pre = "{\\an9}";
else
pre = "{\\an8}";
}
else if (alignVCenter)
{
if (alignLeft)
pre = "{\\an4}";
else if (alignRight)
pre = "{\\an6}";
else
pre = "{\\an5}";
}
else
{
if (alignLeft)
pre = "{\\an1}";
else if (alignRight)
pre = "{\\an3}";
}
string temp = pre + pText;
textLines.Add(new SubtitleLine(pText.ToString(), lastVPosition, vAlignment));
pText.Clear();
pText.Append(temp);
}
}
if (innerNode.ChildNodes.Count == 0)
{
pText.Append(innerNode.InnerText);
lastVPosition = vPosition;
}
else
}
bool alignLeft = false;
bool alignRight = false;
bool alignVTop = false;
bool alignVCenter = false;
if (innerNode.Attributes["HAlign"] != null)
{
string hAlign = innerNode.Attributes["HAlign"].InnerText;
if (hAlign == "left")
alignLeft = true;
else if (hAlign == "right")
alignRight = true;
}
if (innerNode.Attributes["VAlign"] != null)
{
string hAlign = innerNode.Attributes["VAlign"].InnerText;
if (hAlign == "top")
alignVTop = true;
else if (hAlign == "center")
alignVCenter = true;
}
if (alignLeft || alignRight || alignVCenter || alignVTop)
{
if (!pText.ToString().StartsWith("{\\an", StringComparison.Ordinal))
{
foreach (XmlNode innerInnerNode in innerNode)
string pre = string.Empty;
if (alignVTop)
{
if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Italic"] != null &&
innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase))
{
if (innerInnerNode.Attributes["Color"] != null)
pText.Append("<i><font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
else
pText.Append("<i>" + innerInnerNode.InnerText + "</i>");
}
else if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Color"] != null)
{
if (innerInnerNode.Attributes["Italic"] != null && innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase))
pText.Append("<i><font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
else
pText.Append("<font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font>");
}
if (alignLeft)
pre = "{\\an7}";
else if (alignRight)
pre = "{\\an9}";
else
{
pText.Append(innerInnerNode.InnerText);
}
pre = "{\\an8}";
}
else if (alignVCenter)
{
if (alignLeft)
pre = "{\\an4}";
else if (alignRight)
pre = "{\\an6}";
else
pre = "{\\an5}";
}
else
{
if (alignLeft)
pre = "{\\an1}";
else if (alignRight)
pre = "{\\an3}";
}
string temp = pre + pText;
pText.Clear();
pText.Append(temp);
}
}
if (innerNode.ChildNodes.Count == 0)
{
pText.Append(innerNode.InnerText);
}
else
{
foreach (XmlNode innerInnerNode in innerNode)
{
if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Italic"] != null &&
innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase))
{
if (innerInnerNode.Attributes["Color"] != null)
pText.Append("<i><font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
else
pText.Append("<i>" + innerInnerNode.InnerText + "</i>");
}
else if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Color"] != null)
{
if (innerInnerNode.Attributes["Italic"] != null && innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase))
pText.Append("<i><font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
else
pText.Append("<font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font>");
}
else
{
pText.Append(innerInnerNode.InnerText);
}
}
break;
default:
pText.Append(innerNode.InnerText);
break;
}
}
else
{
pText.Append(innerNode.InnerText);
}
}

View File

@ -616,143 +616,146 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
string lastVPosition = string.Empty;
foreach (XmlNode innerNode in node.ChildNodes)
{
switch (innerNode.Name)
if (innerNode.Name == "Text")
{
case "Text":
if (innerNode.Attributes["Vposition"] != null)
if (innerNode.Attributes["Vposition"] != null)
{
string vPosition = innerNode.Attributes["Vposition"].InnerText;
if (vPosition != lastVPosition)
{
string vPosition = innerNode.Attributes["Vposition"].InnerText;
if (vPosition != lastVPosition)
if (pText.Length > 0 && lastVPosition.Length > 0)
{
if (pText.Length > 0 && lastVPosition.Length > 0)
{
pText.AppendLine();
}
pText.AppendLine();
}
lastVPosition = vPosition;
}
lastVPosition = vPosition;
}
bool alignLeft = false;
bool alignRight = false;
bool alignVTop = false;
bool alignVCenter = false;
if (innerNode.Attributes["Halign"] != null)
}
bool alignLeft = false;
bool alignRight = false;
bool alignVTop = false;
bool alignVCenter = false;
if (innerNode.Attributes["Halign"] != null)
{
string hAlign = innerNode.Attributes["Halign"].InnerText;
if (hAlign == "left")
{
string hAlign = innerNode.Attributes["Halign"].InnerText;
if (hAlign == "left")
{
alignLeft = true;
}
else if (hAlign == "right")
{
alignRight = true;
}
alignLeft = true;
}
if (innerNode.Attributes["Valign"] != null)
else if (hAlign == "right")
{
string hAlign = innerNode.Attributes["Valign"].InnerText;
if (hAlign == "top")
{
alignVTop = true;
}
else if (hAlign == "center")
{
alignVCenter = true;
}
alignRight = true;
}
if (alignLeft || alignRight || alignVCenter || alignVTop)
}
if (innerNode.Attributes["Valign"] != null)
{
string hAlign = innerNode.Attributes["Valign"].InnerText;
if (hAlign == "top")
{
if (!pText.ToString().StartsWith("{\\an"))
alignVTop = true;
}
else if (hAlign == "center")
{
alignVCenter = true;
}
}
if (alignLeft || alignRight || alignVCenter || alignVTop)
{
if (!pText.ToString().StartsWith("{\\an"))
{
string pre = string.Empty;
if (alignVTop)
{
string pre = string.Empty;
if (alignVTop)
if (alignLeft)
{
if (alignLeft)
{
pre = "{\\an7}";
}
else if (alignRight)
{
pre = "{\\an9}";
}
else
{
pre = "{\\an8}";
}
pre = "{\\an7}";
}
else if (alignVCenter)
else if (alignRight)
{
if (alignLeft)
{
pre = "{\\an4}";
}
else if (alignRight)
{
pre = "{\\an6}";
}
else
{
pre = "{\\an5}";
}
pre = "{\\an9}";
}
else
{
if (alignLeft)
{
pre = "{\\an1}";
}
else if (alignRight)
{
pre = "{\\an3}";
}
pre = "{\\an8}";
}
string temp = pre + pText;
pText.Clear();
pText.Append(temp);
}
}
if (innerNode.ChildNodes.Count == 0)
{
pText.Append(innerNode.InnerText);
}
else
{
foreach (XmlNode innerInnerNode in innerNode)
else if (alignVCenter)
{
if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Italic"] != null &&
innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase))
if (alignLeft)
{
if (innerInnerNode.Attributes["Color"] != null)
{
pText.Append("<i><font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
}
else
{
pText.Append("<i>" + innerInnerNode.InnerText + "</i>");
}
pre = "{\\an4}";
}
else if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Color"] != null)
else if (alignRight)
{
if (innerInnerNode.Attributes["Italic"] != null && innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase))
{
pText.Append("<i><font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
}
else
{
pText.Append("<font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font>");
}
pre = "{\\an6}";
}
else
{
pText.Append(innerInnerNode.InnerText);
pre = "{\\an5}";
}
}
else
{
if (alignLeft)
{
pre = "{\\an1}";
}
else if (alignRight)
{
pre = "{\\an3}";
}
}
string temp = pre + pText;
pText.Clear();
pText.Append(temp);
}
break;
default:
}
if (innerNode.ChildNodes.Count == 0)
{
pText.Append(innerNode.InnerText);
break;
}
else
{
foreach (XmlNode innerInnerNode in innerNode)
{
if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Italic"] != null &&
innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase))
{
if (innerInnerNode.Attributes["Color"] != null)
{
pText.Append("<i><font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
}
else
{
pText.Append("<i>" + innerInnerNode.InnerText + "</i>");
}
}
else if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Color"] != null)
{
if (innerInnerNode.Attributes["Italic"] != null && innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase))
{
pText.Append("<i><font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
}
else
{
pText.Append("<font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font>");
}
}
else
{
pText.Append(innerInnerNode.InnerText);
}
}
}
}
else
{
pText.Append(innerNode.InnerText);
}
}
string start = node.Attributes["TimeIn"].InnerText;

View File

@ -184,7 +184,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
subNode.Attributes.Append(id);
XmlAttribute fadeUpTime = xml.CreateAttribute("FadeUpTime");
fadeUpTime.InnerText = new TimeCode(FramesToMilliseconds(Configuration.Settings.SubtitleSettings.DCinemaFadeUpTime)).ToHHMMSSFF();
fadeUpTime.InnerText = new TimeCode(FramesToMilliseconds(Configuration.Settings.SubtitleSettings.DCinemaFadeUpTime)).ToHHMMSSFF();
subNode.Attributes.Append(fadeUpTime);
XmlAttribute fadeDownTime = xml.CreateAttribute("FadeDownTime");
@ -647,143 +647,146 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
string lastVPosition = string.Empty;
foreach (XmlNode innerNode in node.ChildNodes)
{
switch (innerNode.Name)
if (innerNode.Name == "Text")
{
case "Text":
if (innerNode.Attributes["Vposition"] != null)
if (innerNode.Attributes["Vposition"] != null)
{
string vPosition = innerNode.Attributes["Vposition"].InnerText;
if (vPosition != lastVPosition)
{
string vPosition = innerNode.Attributes["Vposition"].InnerText;
if (vPosition != lastVPosition)
if (pText.Length > 0 && lastVPosition.Length > 0)
{
if (pText.Length > 0 && lastVPosition.Length > 0)
{
pText.AppendLine();
}
pText.AppendLine();
}
lastVPosition = vPosition;
}
lastVPosition = vPosition;
}
bool alignLeft = false;
bool alignRight = false;
bool alignVTop = false;
bool alignVCenter = false;
if (innerNode.Attributes["Halign"] != null)
}
bool alignLeft = false;
bool alignRight = false;
bool alignVTop = false;
bool alignVCenter = false;
if (innerNode.Attributes["Halign"] != null)
{
string hAlign = innerNode.Attributes["Halign"].InnerText;
if (hAlign == "left")
{
string hAlign = innerNode.Attributes["Halign"].InnerText;
if (hAlign == "left")
{
alignLeft = true;
}
else if (hAlign == "right")
{
alignRight = true;
}
alignLeft = true;
}
if (innerNode.Attributes["Valign"] != null)
else if (hAlign == "right")
{
string hAlign = innerNode.Attributes["Valign"].InnerText;
if (hAlign == "top")
{
alignVTop = true;
}
else if (hAlign == "center")
{
alignVCenter = true;
}
alignRight = true;
}
if (alignLeft || alignRight || alignVCenter || alignVTop)
}
if (innerNode.Attributes["Valign"] != null)
{
string hAlign = innerNode.Attributes["Valign"].InnerText;
if (hAlign == "top")
{
if (!pText.ToString().StartsWith("{\\an", StringComparison.Ordinal))
alignVTop = true;
}
else if (hAlign == "center")
{
alignVCenter = true;
}
}
if (alignLeft || alignRight || alignVCenter || alignVTop)
{
if (!pText.ToString().StartsWith("{\\an", StringComparison.Ordinal))
{
string pre = string.Empty;
if (alignVTop)
{
string pre = string.Empty;
if (alignVTop)
if (alignLeft)
{
if (alignLeft)
{
pre = "{\\an7}";
}
else if (alignRight)
{
pre = "{\\an9}";
}
else
{
pre = "{\\an8}";
}
pre = "{\\an7}";
}
else if (alignVCenter)
else if (alignRight)
{
if (alignLeft)
{
pre = "{\\an4}";
}
else if (alignRight)
{
pre = "{\\an6}";
}
else
{
pre = "{\\an5}";
}
pre = "{\\an9}";
}
else
{
if (alignLeft)
{
pre = "{\\an1}";
}
else if (alignRight)
{
pre = "{\\an3}";
}
pre = "{\\an8}";
}
string temp = pre + pText;
pText.Clear();
pText.Append(temp);
}
}
if (innerNode.ChildNodes.Count == 0)
{
pText.Append(innerNode.InnerText);
}
else
{
foreach (XmlNode innerInnerNode in innerNode)
else if (alignVCenter)
{
if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Italic"] != null &&
innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase))
if (alignLeft)
{
if (innerInnerNode.Attributes["Color"] != null)
{
pText.Append("<i><font color=\"" + DCinemaInterop.GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
}
else
{
pText.Append("<i>" + innerInnerNode.InnerText + "</i>");
}
pre = "{\\an4}";
}
else if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Color"] != null)
else if (alignRight)
{
if (innerInnerNode.Attributes["Italic"] != null && innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase))
{
pText.Append("<i><font color=\"" + DCinemaInterop.GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
}
else
{
pText.Append("<font color=\"" + DCinemaInterop.GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font>");
}
pre = "{\\an6}";
}
else
{
pText.Append(innerInnerNode.InnerText);
pre = "{\\an5}";
}
}
else
{
if (alignLeft)
{
pre = "{\\an1}";
}
else if (alignRight)
{
pre = "{\\an3}";
}
}
string temp = pre + pText;
pText.Clear();
pText.Append(temp);
}
break;
default:
}
if (innerNode.ChildNodes.Count == 0)
{
pText.Append(innerNode.InnerText);
break;
}
else
{
foreach (XmlNode innerInnerNode in innerNode)
{
if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Italic"] != null &&
innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase))
{
if (innerInnerNode.Attributes["Color"] != null)
{
pText.Append("<i><font color=\"" + DCinemaInterop.GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
}
else
{
pText.Append("<i>" + innerInnerNode.InnerText + "</i>");
}
}
else if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Color"] != null)
{
if (innerInnerNode.Attributes["Italic"] != null && innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase))
{
pText.Append("<i><font color=\"" + DCinemaInterop.GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
}
else
{
pText.Append("<font color=\"" + DCinemaInterop.GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font>");
}
}
else
{
pText.Append(innerInnerNode.InnerText);
}
}
}
}
else
{
pText.Append(innerNode.InnerText);
}
}
string start = node.Attributes["TimeIn"].InnerText;

View File

@ -197,19 +197,13 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
if (text.Substring(i).StartsWith("^I", StringComparison.Ordinal))
{
if (!italicOn)
sb.Append("<i>");
else
sb.Append("</i>");
sb.Append(!italicOn ? "<i>" : "</i>");
italicOn = !italicOn;
skipNext = true;
}
else if (text.Substring(i).StartsWith("^B", StringComparison.Ordinal))
{
if (!boldOn)
sb.Append("<b>");
else
sb.Append("</b>");
sb.Append(!boldOn ? "<b>" : "</b>");
boldOn = !boldOn;
skipNext = true;
}

View File

@ -303,10 +303,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
sbTwoChar.Append(ReplaceSpecialCharactersWithTwoByteEncoding(ch, encoding.GetString(new byte[] { 0xc6 }), "ĂĞŬăğŭ", "AGUagu"));
}
else if ("ĂĞŬăğŭ".Contains(ch))
{
sbTwoChar.Append(ReplaceSpecialCharactersWithTwoByteEncoding(ch, encoding.GetString(new byte[] { 0xc6 }), "ĂĞŬăğŭ", "AGUagu"));
}
else if ("ĊĖĠİŻċėġıż".Contains(ch))
{
sbTwoChar.Append(ReplaceSpecialCharactersWithTwoByteEncoding(ch, encoding.GetString(new byte[] { 0xc7 }), "ĊĖĠİŻċėġıż", "CEGIZcegiz"));

View File

@ -197,7 +197,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
}
var styles = new List<FcpXmlStyle>() { DefaultStyle };
var styles = new List<FcpXmlStyle> { DefaultStyle };
var text = Utilities.RemoveSsaTags(p.Text).Trim();
var italicIndexesBefore = new Stack<int>();
var boldIndexesBefore = new Stack<int>();

View File

@ -99,14 +99,13 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
foreach (XmlNode innerNode in node.ChildNodes)
{
switch (innerNode.Name)
if (innerNode.Name == "br")
{
case "br":
pText.AppendLine();
break;
default:
pText.Append(innerNode.InnerText.Trim());
break;
pText.AppendLine();
}
else
{
pText.Append(innerNode.InnerText.Trim());
}
}

View File

@ -60,7 +60,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
text = DecodeText(text.TrimEnd('\\').Trim());
if (!string.IsNullOrEmpty(text))
{
subtitle.Paragraphs.Add(new Paragraph()
subtitle.Paragraphs.Add(new Paragraph
{
StartTime = DecodeTime(match.Groups[1].Value, timeSplitChar),
EndTime = DecodeTime(match.Groups[2].Value, timeSplitChar),

View File

@ -126,9 +126,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
double startSeconds = double.Parse(frames[0]) / 10;
double endSeconds = double.Parse(frames[1]) / 10;
if (startSeconds == 0 && subtitle.Paragraphs.Count > 0)
if (Math.Abs(startSeconds) < 0.01 && subtitle.Paragraphs.Count > 0)
startSeconds = (subtitle.Paragraphs[subtitle.Paragraphs.Count - 1].EndTime.TotalMilliseconds / 1000) + 0.1;
if (endSeconds == 0)
if (Math.Abs(endSeconds) < 0.01)
endSeconds = startSeconds;
subtitle.Paragraphs.Add(new Paragraph(text, startSeconds * 1000, endSeconds * 1000));

View File

@ -145,14 +145,13 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
sb.Clear();
foreach (XmlNode innerNode in text.ChildNodes)
{
switch (innerNode.Name)
if (innerNode.Name == "br")
{
case "br":
sb.AppendLine();
break;
default:
sb.Append(innerNode.InnerText);
break;
sb.AppendLine();
}
else
{
sb.Append(innerNode.InnerText);
}
}
p.Text = sb.ToString();

View File

@ -122,19 +122,24 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var pText = new StringBuilder();
foreach (XmlNode innerNode in node.ChildNodes)
{
switch (innerNode.Name)
if (innerNode.Name == "key")
{
case "key":
lastKey = innerNode.InnerText;
break;
default:
if (lastKey == "in")
p.StartTime.TotalSeconds = double.Parse(innerNode.InnerText);
else if (lastKey == "out")
p.EndTime.TotalSeconds = double.Parse(innerNode.InnerText);
else if (lastKey.StartsWith("text"))
pText.AppendLine(innerNode.InnerText);
break;
lastKey = innerNode.InnerText;
}
else
{
if (lastKey == "in")
{
p.StartTime.TotalSeconds = double.Parse(innerNode.InnerText);
}
else if (lastKey == "out")
{
p.EndTime.TotalSeconds = double.Parse(innerNode.InnerText);
}
else if (lastKey.StartsWith("text"))
{
pText.AppendLine(innerNode.InnerText);
}
}
}
p.Text = pText.ToString().Trim();

View File

@ -200,7 +200,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
// paragraphs
var sub = new Subtitle(subtitle);
sub.Paragraphs.Insert(0, new Paragraph() { Text = "-" });
sub.Paragraphs.Insert(0, new Paragraph { Text = "-" });
int number = 0;
foreach (Paragraph p in sub.Paragraphs)

View File

@ -286,14 +286,13 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var pText = new StringBuilder();
foreach (XmlNode innerNode in node.SelectSingleNode("Text").ChildNodes)
{
switch (innerNode.Name)
if (innerNode.Name == "br")
{
case "br":
pText.AppendLine();
break;
default:
pText.Append(innerNode.InnerText.Trim());
break;
pText.AppendLine();
}
else
{
pText.Append(innerNode.InnerText.Trim());
}
}

View File

@ -456,7 +456,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
subtitle.Renumber();
}
public override List<string> AlternateExtensions => new List<string>() { ".uld" }; // Ultech drop frame
public override List<string> AlternateExtensions => new List<string> { ".uld" }; // Ultech drop frame
}
}

View File

@ -104,7 +104,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
case "span":
ReadSpan(pText, innerNode);
break;
default:
pText.Append(innerNode.InnerText);
break;

View File

@ -1046,7 +1046,11 @@ namespace Nikse.SubtitleEdit.Core
// Less optimized but readable version of the above
public static int Map(double magnitude, double decibelRange, int indexMax)
{
if (magnitude == 0) return 0;
if (Math.Abs(magnitude) < 0.01)
{
return 0;
}
double decibelLevel = 20.0 * Math.Log10(magnitude);
return decibelLevel >= -decibelRange ? (int)(indexMax * (decibelLevel + decibelRange) / decibelRange) : 0;
}

View File

@ -301,12 +301,9 @@ namespace Nikse.SubtitleEdit.Controls
}
}
public SpectrogramData Spectrogram
public void SetSpectrogram(SpectrogramData spectrogramData)
{
set
{
InitializeSpectrogram(value);
}
InitializeSpectrogram(spectrogramData);
}
public void ClearSelection()

View File

@ -131,6 +131,7 @@ namespace Nikse.SubtitleEdit.Forms
if (cavena890.IsMine(null, openFileDialog1.FileName))
{
cavena890.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName);
format = cavena890;
}
}
if (format == null)
@ -139,6 +140,7 @@ namespace Nikse.SubtitleEdit.Forms
if (spt.IsMine(null, openFileDialog1.FileName))
{
spt.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName);
format = spt;
}
}
if (format == null)
@ -147,6 +149,7 @@ namespace Nikse.SubtitleEdit.Forms
if (cheetahCaption.IsMine(null, openFileDialog1.FileName))
{
cheetahCaption.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName);
format = cheetahCaption;
}
}
if (format == null)
@ -155,6 +158,7 @@ namespace Nikse.SubtitleEdit.Forms
if (chk.IsMine(null, openFileDialog1.FileName))
{
chk.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName);
format = chk;
}
}
if (format == null)
@ -163,6 +167,7 @@ namespace Nikse.SubtitleEdit.Forms
if (asc.IsMine(null, openFileDialog1.FileName))
{
asc.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName);
format = asc;
}
}
if (format == null)
@ -1039,7 +1044,7 @@ namespace Nikse.SubtitleEdit.Forms
if (saveFile.ShowDialog() == DialogResult.OK)
{
string fileName = saveFile.FileName;
var sb = new StringBuilder();
var sb = new StringBuilder();
sb.AppendLine("<!DOCTYPE html>");
sb.AppendLine("<html>");
sb.AppendLine(" <head>");

View File

@ -3338,7 +3338,7 @@ namespace Nikse.SubtitleEdit.Forms
_videoAudioTrackNumber = -1;
labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
audioVisualizer.WavePeaks = null;
audioVisualizer.Spectrogram = null;
audioVisualizer.SetSpectrogram(null);
audioVisualizer.SceneChanges = new List<double>();
}
@ -3462,7 +3462,7 @@ namespace Nikse.SubtitleEdit.Forms
_videoAudioTrackNumber = -1;
labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
audioVisualizer.WavePeaks = null;
audioVisualizer.Spectrogram = null;
audioVisualizer.SetSpectrogram(null);
audioVisualizer.SceneChanges = new List<double>();
Configuration.Settings.RecentFiles.Add(fileName, FirstVisibleIndex, FirstSelectedIndex, _videoFileName, _subtitleAlternateFileName, Configuration.Settings.General.CurrentVideoOffsetInMs);
@ -4225,7 +4225,7 @@ namespace Nikse.SubtitleEdit.Forms
_videoAudioTrackNumber = -1;
labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
audioVisualizer.WavePeaks = null;
audioVisualizer.Spectrogram = null;
audioVisualizer.SetSpectrogram(null);
audioVisualizer.SceneChanges = new List<double>();
if (mediaPlayer.VideoPlayer != null)
{
@ -16163,7 +16163,7 @@ namespace Nikse.SubtitleEdit.Forms
if (File.Exists(peakWaveFileName))
{
audioVisualizer.WavePeaks = WavePeakData.FromDisk(peakWaveFileName);
audioVisualizer.Spectrogram = SpectrogramData.FromDisk(spectrogramFolder);
audioVisualizer.SetSpectrogram(SpectrogramData.FromDisk(spectrogramFolder));
audioVisualizer.SceneChanges = SceneChangeHelper.FromDisk(_videoFileName);
toolStripComboBoxWaveform_SelectedIndexChanged(null, null);
SetWaveformPosition(0, 0, 0);
@ -16995,7 +16995,7 @@ namespace Nikse.SubtitleEdit.Forms
if (audioVisualizer.WavePeaks != null)
{
audioVisualizer.WavePeaks = null;
audioVisualizer.Spectrogram = null;
audioVisualizer.SetSpectrogram(null);
audioVisualizer.SceneChanges = new List<double>();
}
openFileDialog1.InitialDirectory = Path.GetDirectoryName(openFileDialog1.FileName);
@ -17664,19 +17664,12 @@ namespace Nikse.SubtitleEdit.Forms
if (index + 1 < _subtitle.Paragraphs.Count)
{
SubtitleListview1.Items[index].Selected = false;
SubtitleListview1.Items[index + 1].Selected = true;
if (!_subtitle.Paragraphs[index + 1].StartTime.IsMaxTime)
_subtitle.Paragraphs[index + 1].StartTime = TimeCode.FromSeconds(videoPosition + 0.001);
if (IsFramesRelevant && CurrentFrameRate > 0)
{
_subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(CurrentFrameRate);
if (tabControlSubtitle.SelectedIndex == TabControlSourceView)
ShowSource();
}
if (!_subtitle.Paragraphs[index + 1].StartTime.IsMaxTime)
SubtitleListview1.SetStartTimeAndDuration(index + 1, _subtitle.Paragraphs[index + 1], _subtitle.GetParagraphOrDefault(index + 1), _subtitle.GetParagraphOrDefault(index - 1));
SubtitleListview1.SelectIndexAndEnsureVisible(index + 1, true);
}
_makeHistoryPaused = false;
@ -18776,7 +18769,7 @@ namespace Nikse.SubtitleEdit.Forms
if (addWaveform.ShowDialog() == DialogResult.OK)
{
audioVisualizer.WavePeaks = addWaveform.Peaks;
audioVisualizer.Spectrogram = addWaveform.Spectrogram;
audioVisualizer.SetSpectrogram(addWaveform.Spectrogram);
timerWaveform.Start();
}
}
@ -19149,7 +19142,7 @@ namespace Nikse.SubtitleEdit.Forms
if (addWaveform.ShowDialog() == DialogResult.OK)
{
audioVisualizer.WavePeaks = addWaveform.Peaks;
audioVisualizer.Spectrogram = addWaveform.Spectrogram;
audioVisualizer.SetSpectrogram(addWaveform.Spectrogram);
timerWaveform.Start();
}
}
@ -20394,7 +20387,7 @@ namespace Nikse.SubtitleEdit.Forms
_videoAudioTrackNumber = -1;
labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
audioVisualizer.WavePeaks = null;
audioVisualizer.Spectrogram = null;
audioVisualizer.SetSpectrogram(null);
audioVisualizer.SceneChanges = new List<double>();
mediaPlayer.CurrentPosition = 0;
}
@ -23838,7 +23831,7 @@ namespace Nikse.SubtitleEdit.Forms
if (audioVisualizer.WavePeaks != null)
{
audioVisualizer.WavePeaks = null;
audioVisualizer.Spectrogram = null;
audioVisualizer.SetSpectrogram(null);
audioVisualizer.SceneChanges = new List<double>();
}
if (!panelVideoPlayer.Visible)

View File

@ -78,7 +78,7 @@
//
// pictureBoxSubtitleImage
//
this.pictureBoxSubtitleImage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.pictureBoxSubtitleImage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBoxSubtitleImage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBoxSubtitleImage.Location = new System.Drawing.Point(12, 247);
@ -86,7 +86,6 @@
this.pictureBoxSubtitleImage.Size = new System.Drawing.Size(804, 135);
this.pictureBoxSubtitleImage.TabIndex = 14;
this.pictureBoxSubtitleImage.TabStop = false;
this.pictureBoxSubtitleImage.Click += new System.EventHandler(this.pictureBoxSubtitleImage_Click);
//
// buttonCancel
//
@ -114,8 +113,8 @@
//
// pictureBox1
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Location = new System.Drawing.Point(12, 412);
@ -144,7 +143,7 @@
//
// groupBoxBinaryImageCompareThresshold
//
this.groupBoxBinaryImageCompareThresshold.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.groupBoxBinaryImageCompareThresshold.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBoxBinaryImageCompareThresshold.Controls.Add(this.numericUpDownThreshold);
this.groupBoxBinaryImageCompareThresshold.Controls.Add(this.labelDescription);

View File

@ -61,13 +61,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
DialogResult = DialogResult.Cancel;
}
private void pictureBoxSubtitleImage_Click(object sender, EventArgs e)
{
var bmp = pictureBoxSubtitleImage.Image as Bitmap;
if (bmp == null)
return;
}
private void SetForeColorThreshold_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)

View File

@ -66,7 +66,7 @@ namespace Nikse.SubtitleEdit.Logic.ColorChooser
var s = (double)HSV.Saturation / 255;
var v = (double)HSV.Value / 255;
if (s == 0)
if (Math.Abs(s) < 0.01)
{
// If s is 0, all colors are the same.
// This is some flavor of gray.
@ -159,7 +159,7 @@ namespace Nikse.SubtitleEdit.Logic.ColorChooser
var v = max;
double delta = max - min;
if (max == 0 || delta == 0)
if (Math.Abs(max) < 0.01 || Math.Abs(delta) < 0.01)
{
// R, G, and B must be 0, or all the same.
// In this case, S is 0, and H is undefined.
@ -170,12 +170,12 @@ namespace Nikse.SubtitleEdit.Logic.ColorChooser
else
{
s = delta / max;
if (r == max)
if (Math.Abs(r - max) < 0.01)
{
// Between Yellow and Magenta
h = (g - b) / delta;
}
else if (g == max)
else if (Math.Abs(g - max) < 0.01)
{
// Between Cyan and Yellow
h = 2 + (b - r) / delta;

View File

@ -194,7 +194,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
_mplayer.StandardInput.WriteLine("pausing_keep_force get_property time_pos");
_mplayer.StandardInput.WriteLine("pausing_keep_force get_property pause");
if (!_ended && OnVideoEnded != null && _lengthInSeconds.TotalSeconds == Duration)
if (!_ended && OnVideoEnded != null && Math.Abs(_lengthInSeconds.TotalSeconds - Duration) < 0.01)
{
// _ended = true;
// OnVideoEnded.Invoke(this, null);