From f3687b5e0ef0b355798e654374d4062236b610e7 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Mon, 4 Nov 2019 20:15:37 +0100 Subject: [PATCH] Trying to fix a few codacy issues --- libse/TransportStream/Teletext.cs | 43 ++++++++++++------- libse/TransportStream/TeletextHamming.cs | 9 ++-- .../TransportStream/TransportStreamParser.cs | 1 - 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/libse/TransportStream/Teletext.cs b/libse/TransportStream/Teletext.cs index 71f88f991..8fa88cdd8 100644 --- a/libse/TransportStream/Teletext.cs +++ b/libse/TransportStream/Teletext.cs @@ -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 { diff --git a/libse/TransportStream/TeletextHamming.cs b/libse/TransportStream/TeletextHamming.cs index 36bb587c5..163adc742 100644 --- a/libse/TransportStream/TeletextHamming.cs +++ b/libse/TransportStream/TeletextHamming.cs @@ -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; diff --git a/libse/TransportStream/TransportStreamParser.cs b/libse/TransportStream/TransportStreamParser.cs index 7787be1ea..7acff8a51 100644 --- a/libse/TransportStream/TransportStreamParser.cs +++ b/libse/TransportStream/TransportStreamParser.cs @@ -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();