Trying to fix a few codacy issues

This commit is contained in:
Nikolaj Olsson 2019-11-04 20:15:37 +01:00
parent d7ac94d33f
commit f3687b5e0e
3 changed files with 33 additions and 20 deletions

View File

@ -104,7 +104,7 @@ namespace Nikse.SubtitleEdit.Core.TransportStream
};
// subtitle type pages bitmap, 2048 bits = 2048 possible pages in teletext (excl. subpages)
public static byte[] CcMap = new byte[256];
private static byte[] _ccMap = new byte[256];
public static readonly StringBuilder Fout = new StringBuilder();
@ -411,7 +411,10 @@ namespace Nikse.SubtitleEdit.Core.TransportStream
{
var address = (TeletextHamming.UnHamming84(packet.Address[1]) << 4) | TeletextHamming.UnHamming84(packet.Address[0]);
var m = address & 0x7;
if (m == 0) m = 8;
if (m == 0)
{
m = 8;
}
var y = (address >> 3) & 0x1f;
if (y == 0)
{
@ -465,13 +468,7 @@ namespace Nikse.SubtitleEdit.Core.TransportStream
var i = (TeletextHamming.UnHamming84(packet.Data[1]) << 4) | TeletextHamming.UnHamming84(packet.Data[0]);
var flagSubtitle = (TeletextHamming.UnHamming84(packet.Data[5]) & 0x08) >> 3;
CcMap[i] |= (byte)(flagSubtitle << (m - 1));
//if (config.Page == 0 && flagSubtitle == (int)BoolT.Yes && i < 0xff)
//{
// config.Page = (m << 8) | (TeletextHamming.UnHamming84(packet.Data[1]) << 4) | TeletextHamming.UnHamming84(packet.Data[0]);
// Console.WriteLine($"- No teletext page specified, first received suitable page is {config.Page}, not guaranteed");
//}
_ccMap[i] |= (byte)(flagSubtitle << (m - 1));
// Page number and control bits
var pageNumber = (m << 8) | (TeletextHamming.UnHamming84(packet.Data[1]) << 4) | TeletextHamming.UnHamming84(packet.Data[0]);
@ -520,7 +517,7 @@ namespace Nikse.SubtitleEdit.Core.TransportStream
PageBuffer.ShowTimestamp = timestamp;
PageBuffer.HideTimestamp = 0;
PageBuffer.Text = new int[25, 40]; //memset(page_buffer.text, 0x00, sizeof(page_buffer.text));
PageBuffer.Text = new int[25, 40];
PageBuffer.Tainted = false;
ReceivingData = true;
PrimaryCharset.G0X28 = (int)BoolT.Undef;
@ -588,18 +585,26 @@ namespace Nikse.SubtitleEdit.Core.TransportStream
if (mode == 0x04 && rowAddressGroup)
{
x26Row = (int)(address2 - 40);
if (x26Row == 0) x26Row = 24;
x26Col = 0;
if (x26Row == 0)
{
x26Row = 24;
}
}
// ETS 300 706, chapter 12.3.1, table 27: termination marker
if (mode >= 0x11 && mode <= 0x1f && rowAddressGroup) break;
if (mode >= 0x11 && mode <= 0x1f && rowAddressGroup)
{
break;
}
// ETS 300 706, chapter 12.3.1, table 27: character from G2 set
if (mode == 0x0f && !rowAddressGroup)
{
x26Col = (int)address2;
if (data > 31) PageBuffer.Text[x26Row, x26Col] = TeletextTables.G2[0, data - 0x20];
if (data > 31)
{
PageBuffer.Text[x26Row, x26Col] = TeletextTables.G2[0, data - 0x20];
}
}
// ETS 300 706, chapter 12.3.1, table 27: G0 character with diacritical mark
@ -635,7 +640,10 @@ namespace Nikse.SubtitleEdit.Core.TransportStream
if (triplet0 == 0xffffffff)
{
// invalid data (HAM24/18 uncorrectable error detected), skip group
if (Config.Verbose) Console.WriteLine($"! Unrecoverable data error; UNHAM24/18()={triplet0}");
if (Config.Verbose)
{
Console.WriteLine($"! Unrecoverable data error; UNHAM24/18()={triplet0}");
}
}
else
{
@ -662,7 +670,10 @@ namespace Nikse.SubtitleEdit.Core.TransportStream
if (triplet0 == 0xffffffff)
{
// invalid data (HAM24/18 uncorrectable error detected), skip group
if (Config.Verbose) Console.WriteLine($"! Unrecoverable data error; UNHAM24/18()={triplet0}");
if (Config.Verbose)
{
Console.WriteLine($"! Unrecoverable data error; UNHAM24/18()={triplet0}");
}
}
else
{

View File

@ -2,7 +2,7 @@
{
public static class TeletextHamming
{
public static byte[] Parity8 =
public static readonly byte[] Parity8 =
{
0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00,
0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
@ -22,7 +22,7 @@
0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00
};
public static byte[] Reverse8 =
public static readonly byte[] Reverse8 =
{
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
@ -42,7 +42,7 @@
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
};
public static byte[] Unham84 =
public static readonly byte[] Unham84 =
{
0x01, 0xff, 0x01, 0x01, 0xff, 0x00, 0x01, 0xff, 0xff, 0x02, 0x01, 0xff, 0x0a, 0xff, 0xff, 0x07,
0xff, 0x00, 0x01, 0xff, 0x00, 0x00, 0xff, 0x00, 0x06, 0xff, 0xff, 0x0b, 0xff, 0x00, 0x03, 0xff,
@ -85,7 +85,10 @@
// Tests A-F correspond to bits 0-6 respectively in 'test'.
for (int i = 0; i < 23; i++)
{
test ^= ((a >> i) & 0x01) * (i + 33);
}
// Only parity bit is tested for bit 24
test ^= ((a >> 23) & 0x01) * 32;

View File

@ -170,7 +170,6 @@ namespace Nikse.SubtitleEdit.Core.TransportStream
Teletext.TransMode = Teletext.TransmissionMode.TransmissionModeSerial;
Teletext.ReceivingData = false;
Teletext.States = new Teletext.TeletextStates();
Teletext.CcMap = new byte[256];
Teletext.PageBuffer = new Teletext.TeletextPage();
var pageBcd = Teletext.DecToBec(page);
var teletextRunSettings = new TeletextRunSettings();