mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
Added SON/TIF format + vobsub bitmaps are allways pre-made with Bitmap.MakeTranslarent()
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@538 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
08d0c91c84
commit
4af13aa0d3
@ -1367,6 +1367,23 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
}
|
||||
|
||||
if (format == null || format.Name == new Scenarist().Name)
|
||||
{
|
||||
var son = new Son();
|
||||
string[] arr = File.ReadAllLines(fileName);
|
||||
List<string> list = new List<string>();
|
||||
foreach (string l in arr)
|
||||
list.Add(l);
|
||||
if (son.IsMine(list, fileName))
|
||||
{
|
||||
if (ContinueNewOrExit())
|
||||
{
|
||||
ImportAndOcrSon(fileName, son, list);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_fileDateTime = File.GetLastWriteTime(fileName);
|
||||
|
||||
@ -1557,6 +1574,39 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void ImportAndOcrSon(string fileName, Son format, List<string> list)
|
||||
{
|
||||
Subtitle sub = new Subtitle();
|
||||
format.LoadSubtitle(sub, list, fileName);
|
||||
sub.FileName = fileName;
|
||||
var formSubOcr = new VobSubOcr();
|
||||
formSubOcr.Initialize(sub, Configuration.Settings.VobSubOcr);
|
||||
if (formSubOcr.ShowDialog(this) == DialogResult.OK)
|
||||
{
|
||||
MakeHistoryForUndo(_language.BeforeImportingBdnXml);
|
||||
FileNew();
|
||||
_subtitle.Paragraphs.Clear();
|
||||
SetCurrentFormat(new SubRip().FriendlyName);
|
||||
_subtitle.WasLoadedWithFrameNumbers = false;
|
||||
_subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
|
||||
foreach (Paragraph p in formSubOcr.SubtitleFromOcr.Paragraphs)
|
||||
{
|
||||
_subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
|
||||
ShowSource();
|
||||
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
|
||||
_change = true;
|
||||
_subtitleListViewIndex = -1;
|
||||
SubtitleListview1.FirstVisibleIndex = -1;
|
||||
SubtitleListview1.SelectIndexAndEnsureVisible(0);
|
||||
|
||||
_fileName = Path.ChangeExtension(formSubOcr.FileName, ".srt");
|
||||
SetTitle();
|
||||
_converted = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowUnknownSubtitle()
|
||||
{
|
||||
var unknownSubtitle = new UnknownSubtitle();
|
||||
|
@ -681,7 +681,7 @@
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
|
||||
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
|
||||
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAD2
|
||||
CAAAAk1TRnQBSQFMAgEBAgEAAQgBCQEIAQkBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
|
||||
CAAAAk1TRnQBSQFMAgEBAgEAARABCQEQAQkBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
|
||||
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
|
||||
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
|
||||
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
|
||||
|
@ -674,7 +674,11 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
string fileName = Path.Combine(Path.GetDirectoryName(_bdnFileName), _bdnXmlSubtitle.Paragraphs[index].Text);
|
||||
if (File.Exists(fileName))
|
||||
return new Bitmap(fileName);
|
||||
{
|
||||
Bitmap b = new Bitmap(fileName);
|
||||
b.MakeTransparent();
|
||||
return b;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -711,7 +715,10 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
|
||||
return _vobSubMergedPackist[index].SubPicture.GetBitmap(null, background, pattern, emphasis1, emphasis2);
|
||||
}
|
||||
return _vobSubMergedPackist[index].SubPicture.GetBitmap(_palette, Color.Transparent, Color.Black, Color.White, Color.Black);
|
||||
|
||||
Bitmap bmp = _vobSubMergedPackist[index].SubPicture.GetBitmap(_palette, Color.Transparent, Color.Black, Color.White, Color.Black);
|
||||
bmp.MakeTransparent();
|
||||
return bmp;
|
||||
}
|
||||
|
||||
private long GetSubtitleStartTimeMilliseconds(int index)
|
||||
|
121
src/Logic/SubtitleFormats/son.cs
Normal file
121
src/Logic/SubtitleFormats/son.cs
Normal file
@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
public class Son : SubtitleFormat
|
||||
{
|
||||
public override string Extension
|
||||
{
|
||||
get { return ".son"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "SON"; }
|
||||
}
|
||||
|
||||
public override bool HasLineNumber
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsTimeBased
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsMine(List<string> lines, string fileName)
|
||||
{
|
||||
var subtitle = new Subtitle();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (string line in lines)
|
||||
sb.AppendLine(line);
|
||||
|
||||
LoadSubtitle(subtitle, lines, fileName);
|
||||
return subtitle.Paragraphs.Count > _errorCount;
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int index = 0;
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
//0003 00:00:28:16 00:00:31:04 Jeg vil lære jer frygten for HERREN." (newline is \t)
|
||||
sb.AppendLine(string.Format("{0:0000}\t{1}\t{2}\t{3}", index + 1, EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), Utilities.RemoveHtmlTags(p.Text).Replace(Environment.NewLine, "\t")));
|
||||
index++;
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private string EncodeTimeCode(TimeCode time)
|
||||
{
|
||||
//00:03:15:22 (last is frame)
|
||||
int frames = (int)(time.Milliseconds / (1000.0 / Configuration.Settings.General.CurrentFrameRate));
|
||||
return string.Format("{0:00}:{1:00}:{2:00}:{3:00}", time.Hours, time.Minutes, time.Seconds, frames);
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
//00:03:15:22 00:03:23:10 This is line one.
|
||||
//This is line two.
|
||||
Paragraph p = null;
|
||||
subtitle.Paragraphs.Clear();
|
||||
var regexTimeCodes = new Regex(@"^\d\d\d\d\t\d\d:\d\d:\d\d:\d\d\t\d\d:\d\d:\d\d:\d\d\t[^\s]+\.tif", RegexOptions.Compiled);
|
||||
int index = 0;
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (regexTimeCodes.IsMatch(line))
|
||||
{
|
||||
string temp = line.Substring(0, regexTimeCodes.Match(line).Length);
|
||||
string start = temp.Substring(5, 11);
|
||||
string end = temp.Substring(12 + 5, 11);
|
||||
|
||||
string[] startParts = start.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
int lastIndexOfTab = line.LastIndexOf("\t");
|
||||
string text = line.Remove(0, lastIndexOfTab+1).Trim();
|
||||
if (!text.Contains(Environment.NewLine))
|
||||
text = text.Replace("\t", Environment.NewLine);
|
||||
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), text);
|
||||
subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
}
|
||||
else if (line.Trim().Length == 0 || line.StartsWith("Display_Area") || line.StartsWith("#") || line.StartsWith("Color") || index < 10)
|
||||
{
|
||||
// skip these lines
|
||||
}
|
||||
else if (line.Trim().Length > 0 && p != null)
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
subtitle.Renumber(1);
|
||||
}
|
||||
|
||||
private TimeCode DecodeTimeCode(string[] parts)
|
||||
{
|
||||
//00:00:07:12
|
||||
string hour = parts[0];
|
||||
string minutes = parts[1];
|
||||
string seconds = parts[2];
|
||||
string frames = parts[3];
|
||||
|
||||
int milliseconds = (int)((1000.0 / Configuration.Settings.General.CurrentFrameRate) * int.Parse(frames));
|
||||
if (milliseconds > 999)
|
||||
milliseconds = 999;
|
||||
|
||||
TimeCode tc = new TimeCode(int.Parse(hour), int.Parse(minutes), int.Parse(seconds), milliseconds);
|
||||
return tc;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1054,7 +1054,8 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
sb.Append("*" + new Pac().Extension + ";");
|
||||
sb.Append("*" + new Cavena890().Extension + ";");
|
||||
sb.Append("*" + new Spt().Extension + ";");
|
||||
sb.Append("*.sup");
|
||||
sb.Append("*.sup;"); // blu-ray sup
|
||||
sb.Append("*.son"); // SON text/tif
|
||||
sb.Append("|" + Configuration.Settings.Language.General.AllFiles + "|*.*");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
@ -560,6 +560,7 @@
|
||||
<Compile Include="Logic\SubtitleFormats\QuickTimeText.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\RealTime.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\Scenarist.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\Son.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\SonyDVDArchitectExplicitDuration.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\SonyDVDArchitectTabs.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\SonyDVDArchitectWithLineNumbers.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user