mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-26 05:02:36 +01:00
Work on mcc
This commit is contained in:
parent
deca2df2d6
commit
c7f23b10e8
@ -160,7 +160,7 @@ namespace Test.Logic.SubtitleFormats
|
||||
[TestMethod]
|
||||
public void CommandTextCommand()
|
||||
{
|
||||
var command = new TextCommand(0, "Hallo!");
|
||||
var command = new SetText(0, "Hallo!");
|
||||
var bytes = command.GetBytes();
|
||||
Assert.AreEqual(bytes.Length, 6);
|
||||
Assert.AreEqual(bytes[0], 72);
|
||||
|
@ -41,6 +41,54 @@ namespace Nikse.SubtitleEdit.Core.Cea708
|
||||
}
|
||||
}
|
||||
|
||||
public CcDataSection(int ccDataCount, byte[] bytes)
|
||||
{
|
||||
DataSection = 0x72;
|
||||
ProcessEmData = true;
|
||||
ProcessEmData = true;
|
||||
ProcessEmData = true;
|
||||
|
||||
CcData = new CcData[ccDataCount];
|
||||
for (int i = 0; i < ccDataCount; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
CcData[i] = new CcData
|
||||
{
|
||||
Valid = true,
|
||||
Type = 0,
|
||||
Data1 = 0x97,
|
||||
Data2 = 0xa2,
|
||||
};
|
||||
}
|
||||
else if (i == 1)
|
||||
{
|
||||
CcData[i] = new CcData
|
||||
{
|
||||
Valid = true,
|
||||
Type = 1,
|
||||
Data1 = 0x80,
|
||||
Data2 = 0x80,
|
||||
};
|
||||
}
|
||||
else if (i == 2)
|
||||
{
|
||||
CcData[i] = new CcData
|
||||
{
|
||||
Valid = true,
|
||||
Type = 3,
|
||||
Data1 = 0x0b,
|
||||
Data2 = 0x33,
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
CcData[i] = new CcData { Type = 2 };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public string GetText(int lineIndex, CommandState state, bool flush)
|
||||
{
|
||||
var hex = new StringBuilder();
|
||||
|
@ -511,7 +511,7 @@ namespace Nikse.SubtitleEdit.Core.Cea708
|
||||
else if (b <= 0x1F)
|
||||
{
|
||||
// CL Group: C0: Subset of ASCII Control Codes
|
||||
var text = new TextCommand(lineIndex, SingleCharLookupTable[b]);
|
||||
var text = new SetText(lineIndex, SingleCharLookupTable[b]);
|
||||
state.Commands.Add(text);
|
||||
debugBuilder.Append(text.Content);
|
||||
|
||||
@ -528,21 +528,21 @@ namespace Nikse.SubtitleEdit.Core.Cea708
|
||||
else if (b >= 0x20 && b <= 0x7F)
|
||||
{
|
||||
// Modified version of ANSI X3.4 Printable Character Set(ASCII)
|
||||
var text = new TextCommand(lineIndex, SingleCharLookupTable[b]);
|
||||
var text = new SetText(lineIndex, SingleCharLookupTable[b]);
|
||||
state.Commands.Add(text);
|
||||
debugBuilder.Append(text.Content);
|
||||
}
|
||||
else if (b >= 0x80 && b <= 0x9f)
|
||||
{
|
||||
// CR Group: C1: Caption Control Codes
|
||||
var text = new TextCommand(lineIndex, SingleCharLookupTable[b]);
|
||||
var text = new SetText(lineIndex, SingleCharLookupTable[b]);
|
||||
state.Commands.Add(text);
|
||||
debugBuilder.Append(text.Content);
|
||||
}
|
||||
else if (b >= 0xA0 && b <= 0xFF)
|
||||
{
|
||||
// ISO 8859 - 1 Latin 1 Characters
|
||||
var text = new TextCommand(lineIndex, SingleCharLookupTable[b]);
|
||||
var text = new SetText(lineIndex, SingleCharLookupTable[b]);
|
||||
state.Commands.Add(text);
|
||||
debugBuilder.Append(text.Content);
|
||||
}
|
||||
@ -565,7 +565,7 @@ namespace Nikse.SubtitleEdit.Core.Cea708
|
||||
var italicOn = false;
|
||||
foreach (var command in state.Commands)
|
||||
{
|
||||
if (command is TextCommand textCommand)
|
||||
if (command is SetText textCommand)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textCommand.Content))
|
||||
{
|
||||
|
@ -8,6 +8,21 @@
|
||||
|
||||
public bool[] Flags { get; set; }
|
||||
|
||||
public DeleteWindows(bool deleteAll)
|
||||
{
|
||||
Flags = new[]
|
||||
{
|
||||
deleteAll,
|
||||
deleteAll,
|
||||
deleteAll,
|
||||
deleteAll,
|
||||
deleteAll,
|
||||
deleteAll,
|
||||
deleteAll,
|
||||
deleteAll,
|
||||
};
|
||||
}
|
||||
|
||||
public DeleteWindows(int lineIndex, byte[] bytes, int index)
|
||||
{
|
||||
LineIndex = lineIndex;
|
||||
|
@ -8,6 +8,21 @@
|
||||
|
||||
public bool[] Flags { get; set; }
|
||||
|
||||
public HideWindows(bool hideAll)
|
||||
{
|
||||
Flags = new[]
|
||||
{
|
||||
hideAll,
|
||||
hideAll,
|
||||
hideAll,
|
||||
hideAll,
|
||||
hideAll,
|
||||
hideAll,
|
||||
hideAll,
|
||||
hideAll,
|
||||
};
|
||||
}
|
||||
|
||||
public HideWindows(int lineIndex, byte[] bytes, int index)
|
||||
{
|
||||
LineIndex = lineIndex;
|
||||
|
@ -14,6 +14,10 @@
|
||||
public bool Underline { get; set; }
|
||||
public bool Italics { get; set; }
|
||||
|
||||
public SetPenAttributes()
|
||||
{
|
||||
}
|
||||
|
||||
public SetPenAttributes(int lineIndex, byte[] bytes, int index)
|
||||
{
|
||||
LineIndex = lineIndex;
|
||||
|
@ -21,6 +21,10 @@
|
||||
public int EdgeColorRed { get; set; }
|
||||
public int EdgeOpacity => ForegroundOpacity;
|
||||
|
||||
public SetPenColor()
|
||||
{
|
||||
}
|
||||
|
||||
public SetPenColor(int lineIndex, byte[] bytes, int index)
|
||||
{
|
||||
LineIndex = lineIndex;
|
||||
|
@ -16,6 +16,10 @@
|
||||
/// </summary>
|
||||
public int Row { get; set; }
|
||||
|
||||
public SetPenLocation()
|
||||
{
|
||||
}
|
||||
|
||||
public SetPenLocation(int lineIndex, byte[] bytes, int index)
|
||||
{
|
||||
LineIndex = lineIndex;
|
||||
|
@ -1,12 +1,17 @@
|
||||
namespace Nikse.SubtitleEdit.Core.Cea708.Commands
|
||||
{
|
||||
public class TextCommand : ICommand
|
||||
public class SetText : ICommand
|
||||
{
|
||||
public int LineIndex { get; set; }
|
||||
|
||||
public string Content { get; set; }
|
||||
|
||||
public TextCommand(int lineIndex, string content)
|
||||
public SetText(string content)
|
||||
{
|
||||
Content = content;
|
||||
}
|
||||
|
||||
public SetText(int lineIndex, string content)
|
||||
{
|
||||
LineIndex = lineIndex;
|
||||
Content = content;
|
@ -32,6 +32,10 @@
|
||||
public int EffectDirection { get; set; }
|
||||
public int EffectSpeed { get; set; }
|
||||
|
||||
public SetWindowAttributes()
|
||||
{
|
||||
}
|
||||
|
||||
public SetWindowAttributes(int lineIndex, byte[] bytes, int index)
|
||||
{
|
||||
LineIndex = lineIndex;
|
||||
|
@ -8,6 +8,21 @@
|
||||
|
||||
public bool[] Flags { get; set; }
|
||||
|
||||
public ToggleWindows(bool toggleAll)
|
||||
{
|
||||
Flags = new[]
|
||||
{
|
||||
toggleAll,
|
||||
toggleAll,
|
||||
toggleAll,
|
||||
toggleAll,
|
||||
toggleAll,
|
||||
toggleAll,
|
||||
toggleAll,
|
||||
toggleAll,
|
||||
};
|
||||
}
|
||||
|
||||
public ToggleWindows(int lineIndex, byte[] bytes, int index)
|
||||
{
|
||||
LineIndex = lineIndex;
|
||||
|
@ -1,4 +1,7 @@
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Nikse.SubtitleEdit.Core.Cea708.Commands;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Core.Cea708
|
||||
{
|
||||
@ -17,6 +20,9 @@ namespace Nikse.SubtitleEdit.Core.Cea708
|
||||
public bool CaptionDistributionPacketServiceInfoChanged { get; set; }
|
||||
public bool CaptionDistributionPacketServiceInfoEnd { get; set; }
|
||||
public bool CaptionDistributionPacketContainsCaptions { get; set; }
|
||||
/// <summary>
|
||||
/// Should start with zero and count one up for each packet.
|
||||
/// </summary>
|
||||
public int CaptionDistributionPacketHeaderSequenceCounter { get; set; }
|
||||
public CcDataSection CcDataSectionCcData { get; set; }
|
||||
public CcServiceInfoSection CcServiceInfoSection { get; set; }
|
||||
@ -41,6 +47,26 @@ namespace Nikse.SubtitleEdit.Core.Cea708
|
||||
}
|
||||
}
|
||||
|
||||
public Smpte291M(int sequenceCount, int ccDataCount, byte[] bytes)
|
||||
{
|
||||
DataId = 0x61;
|
||||
SecondaryDataId = 1;
|
||||
DataCount = 0x59;
|
||||
CaptionDistributionPacketId = 0x9669;
|
||||
CaptionDistributionPacketDataCount = 0x59;
|
||||
CaptionDistributionPacketFramingRate = 4; // 29.97
|
||||
CaptionDistributionPacketTimeCodeAdded = false;
|
||||
CaptionDistributionPacketDataBlockAdded = true;
|
||||
CaptionDistributionPacketServiceInfoAdded = true;
|
||||
CaptionDistributionPacketServiceInfoStart = true;
|
||||
CaptionDistributionPacketServiceInfoChanged = true;
|
||||
CaptionDistributionPacketServiceInfoEnd = true;
|
||||
CaptionDistributionPacketContainsCaptions = true;
|
||||
CaptionDistributionPacketHeaderSequenceCounter = sequenceCount;
|
||||
|
||||
CcDataSectionCcData = new CcDataSection(ccDataCount, bytes);
|
||||
}
|
||||
|
||||
public Smpte291M(byte[] bytes)
|
||||
{
|
||||
DataId = bytes[0];
|
||||
|
72
src/libse/Cea708/VancDataWriter.cs
Normal file
72
src/libse/Cea708/VancDataWriter.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using Nikse.SubtitleEdit.Core.Cea708.Commands;
|
||||
using Nikse.SubtitleEdit.Core.Common;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Core.Cea708
|
||||
{
|
||||
public static class VancDataWriter
|
||||
{
|
||||
public static string GenerateTextInit(int counter)
|
||||
{
|
||||
var commands = new List<ICommand>
|
||||
{
|
||||
new HideWindows(true),
|
||||
new ToggleWindows(true),
|
||||
new HideWindows(true),
|
||||
new DeleteWindows(true),
|
||||
};
|
||||
var bytes = new List<byte>();
|
||||
foreach (var command in commands)
|
||||
{
|
||||
bytes.AddRange(command.GetBytes());
|
||||
}
|
||||
|
||||
var smpte291M = new Smpte291M(counter, 20, bytes.ToArray());
|
||||
var resultBytes = smpte291M.GetBytes();
|
||||
var hex = ByteArrayToHexString(resultBytes);
|
||||
return hex;
|
||||
}
|
||||
|
||||
public static string[] GenerateLinesFromText(string text, int counter)
|
||||
{
|
||||
//TODO: chunk in max 32 bytes chunks (do not split commands)
|
||||
|
||||
var commands = new List<ICommand>
|
||||
{
|
||||
new DefineWindow(),
|
||||
new SetWindowAttributes(),
|
||||
new SetPenAttributes(),
|
||||
new SetPenColor(),
|
||||
};
|
||||
|
||||
foreach (var line in text.SplitToLines())
|
||||
{
|
||||
commands.Add(new SetPenLocation());
|
||||
commands.Add(new SetText(line));
|
||||
}
|
||||
|
||||
var bytes = new List<byte>();
|
||||
foreach (var command in commands)
|
||||
{
|
||||
bytes.AddRange(command.GetBytes());
|
||||
}
|
||||
|
||||
var smpte291M = new Smpte291M(counter, 20, bytes.ToArray());
|
||||
var resultBytes = smpte291M.GetBytes();
|
||||
var hex = ByteArrayToHexString(resultBytes);
|
||||
return new[] { hex };
|
||||
}
|
||||
|
||||
public static string ByteArrayToHexString(byte[] bytes)
|
||||
{
|
||||
var hex = new StringBuilder(bytes.Length * 2);
|
||||
foreach (var b in bytes)
|
||||
{
|
||||
hex.AppendFormat("{0:X2}", b);
|
||||
}
|
||||
|
||||
return hex.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using Nikse.SubtitleEdit.Core.Cea708;
|
||||
using Nikse.SubtitleEdit.Core.Cea708.Commands;
|
||||
using Nikse.SubtitleEdit.Core.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
Loading…
Reference in New Issue
Block a user