private static void Service_TeletextPageCleared(object sender, EventArgs e) { var ttxE = (TeletextPageClearedEventArgs)e; if (_decodedSubtitlePage?.PageNum == ttxE.PageNumber) { _decodedSubtitlePage = null; } }
public static void InitializeStaticFields(int packetId, int pageNumberBcd) { _config = new Config { Page = pageNumberBcd, Tid = packetId }; _primaryCharset = new PrimaryCharset(); _transmissionMode = TransmissionMode.TransmissionModeSerial; _receivingData = false; _states = new States(); _pageBuffer = new TeletextPage(); }
private static void Service_TeletextPageReady(object sender, EventArgs e) { var ttxE = (TeletextPageReadyEventArgs)e; if (ttxE == null) { return; } _decodedSubtitlePage = ttxE.Page; }
/// <summary> /// Retrieve the new page from the server /// </summary> protected void GetNewPage() { int sub = currentSubPageNumber; int maxSubs = _receivedTeletextPage == null ? 1 : _receivedTeletextPage.SubPageCount; // Check if the page is available if (maxSubs <= 0) { if (_receivedTeletextPage != null && _receivedTeletextPage.Content != null && !_waiting) { bmpTeletextPage = _renderer.RenderPage(_receivedTeletextPage.Content, receivedPageNumber, receivedSubPageNumber); Log.Info("dvb-teletext: received page {0:X} / subpage {1:X}", receivedPageNumber, receivedSubPageNumber); } Redraw(); return; } if (sub >= maxSubs) { sub = maxSubs - 1; } // Get the page TeletextPage teletextPage = PluginMain.Navigator.GetTeletextPage(currentPageNumber, sub); // Was the page available, then render it. Otherwise render the last page again and update the header line, if // it was for the first time if (teletextPage != null) { _receivedTeletextPage = teletextPage; receivedPageNumber = currentPageNumber; receivedSubPageNumber = currentSubPageNumber; bmpTeletextPage = _renderer.RenderPage(_receivedTeletextPage.Content, _receivedTeletextPage.PageNumber, sub); _waiting = false; Log.Info("dvb-teletext: select page {0:X} / subpage {1:X}", currentPageNumber, currentSubPageNumber); } else { if (_receivedTeletextPage != null && _receivedTeletextPage.Content != null && !_waiting) { bmpTeletextPage = _renderer.RenderPage(_receivedTeletextPage.Content, receivedPageNumber, receivedSubPageNumber); Log.Info("dvb-teletext: received page {0:X} / subpage {1:X}", receivedPageNumber, receivedSubPageNumber); } _waiting = true; } Redraw(); }
/// <summary> /// Loads the logo page from the assembly /// </summary> protected void LoadLogoPage() { Assembly assm = Assembly.GetExecutingAssembly(); Stream stream = assm.GetManifestResourceStream("ArgusTV.UI.MediaPortal.TeletextLogoPage"); if (stream != null) { using (BinaryReader reader = new BinaryReader(stream)) { _receivedTeletextPage = new TeletextPage(); byte[] teletextPageBytes = new byte[stream.Length]; reader.Read(teletextPageBytes, 0, (int)stream.Length); _receivedTeletextPage.Content = teletextPageBytes; _receivedTeletextPage.PageNumber = 0; _receivedTeletextPage.SubPageNumber = 0; } } }
static void ProcessPage(TeletextPage page, TeletextRunSettings teletextRunSettings, int pageNumber) { #if DEBUG for (int row = 1; row < 25; row++) { _config.LogInfoNoNewLine($"# DEBUG[{row}]: "); for (int col = 0; col < 40; col++) { _config.LogInfo($"{(page.Text[row, col]):X2} "); } _config.LogInfo(string.Empty); } _config.LogInfo(string.Empty); #endif // optimization: slicing column by column -- higher probability we could find boxed area start mark sooner bool pageIsEmpty = true; for (var col = 0; col < 40; col++) { for (var row = 1; row < 25; row++) { if (page.Text[row, col] == 0x0b) { pageIsEmpty = false; break; } } } if (pageIsEmpty) { return; } var paragraph = new Paragraph(); var usedLines = new List <int>(); var sb = new StringBuilder(); if (page.ShowTimestamp > page.HideTimestamp) { page.HideTimestamp = page.ShowTimestamp; } paragraph.StartTime = new TimeCode(page.ShowTimestamp); paragraph.EndTime = new TimeCode(page.HideTimestamp); // process data for (var row = 1; row < 25; row++) { // anchors for string trimming purpose var colStart = 40; var colStop = 40; bool boxOpen = false; for (var col = 0; col < 40; col++) { // replace all 0/B and 0/A characters with 0/20, as specified in ETS 300 706: // Unless operating in "Hold Mosaics" mode, each character space occupied by a // spacing attribute is displayed as a SPACE if (page.Text[row, col] == 0xb) // open the box { if (colStart == 40) { colStart = col; } else { page.Text[row, col] = 0x20; } boxOpen = true; } else if (page.Text[row, col] == 0xa) // close the box { page.Text[row, col] = 0x20; boxOpen = false; } // characters between 0xA and 0xB shouldn't be displayed // page->text[row][col] > 0x20 added to preserve color information else if (!boxOpen && colStart < 40 && page.Text[row, col] > 0x20) { page.Text[row, col] = 0x20; } } // line is empty if (colStart > 39) { continue; } for (var col = colStart + 1; col <= 39; col++) { if (page.Text[row, col] > 0x20) { if (colStop > 39) { colStart = col; } colStop = col; } if (page.Text[row, col] == 0xa) { break; } } // line is empty if (colStop > 39) { continue; } // ETS 300 706, chapter 12.2: Alpha White ("Set-After") - Start-of-row default condition. // used for color changes _before_ start box mark // white is default as stated in ETS 300 706, chapter 12.2 // black(0), red(1), green(2), yellow(3), blue(4), magenta(5), cyan(6), white(7) var foregroundColor = 0x7; bool fontTagOpened = false; for (var col = 0; col <= colStop; col++) { // v is just a shortcut var v = page.Text[row, col]; if (col < colStart) { if (v <= 0x7) { foregroundColor = v; } } if (col == colStart) { if (foregroundColor != 0x7 && _config.Colors) { sb.Append($"<font color=\"{TeletextColors[foregroundColor]}\">"); fontTagOpened = true; } } if (col >= colStart) { if (v <= 0x7) { // ETS 300 706, chapter 12.2: Unless operating in "Hold Mosaics" mode, // each character space occupied by a spacing attribute is displayed as a SPACE. if (_config.Colors) { if (fontTagOpened) { sb.Append("</font> "); fontTagOpened = false; } // black is considered as white for telxcc purpose // telxcc writes <font/> tags only when needed if (v > 0x0 && v < 0x7) { sb.Append($"<font color=\"{TeletextColors[v]}\">"); fontTagOpened = true; } } else { v = 0x20; } } if (v >= 0x20) { sb.Append(Ucs2ToUtf8(v)); } } } // no tag will left opened! if (_config.Colors && fontTagOpened) { sb.Append("</font>"); } // line delimiter sb.Append(Environment.NewLine); usedLines.Add(row); } sb.AppendLine(); var topAlign = usedLines.Count > 0 && usedLines.All(p => p < 6); paragraph.Text = (topAlign ? "{\\an8}" : "") + sb.ToString().TrimEnd(); if (!teletextRunSettings.PageNumberAndParagraph.ContainsKey(pageNumber)) { teletextRunSettings.PageNumberAndParagraph.Add(pageNumber, paragraph); } else { _config.LogError("New pageId in page: " + pageNumber); } }
/// <summary> /// Loads the logo page from the assembly /// </summary> protected void LoadLogoPage() { Assembly assm = Assembly.GetExecutingAssembly(); Stream stream = assm.GetManifestResourceStream("ForTheRecord.UI.MediaPortal.TeletextLogoPage"); if (stream != null) { using (BinaryReader reader = new BinaryReader(stream)) { _receivedTeletextPage = new TeletextPage(); byte[] teletextPageBytes = new byte[stream.Length]; reader.Read(teletextPageBytes, 0, (int)stream.Length); _receivedTeletextPage.Content = teletextPageBytes; _receivedTeletextPage.PageNumber = 0; _receivedTeletextPage.SubPageNumber = 0; } } }
/// <summary> /// Retrieve the new page from the server /// </summary> protected void GetNewPage() { int sub = currentSubPageNumber; int maxSubs = _receivedTeletextPage == null ? 1 : _receivedTeletextPage.SubPageCount; // Check if the page is available if (maxSubs <= 0) { if (_receivedTeletextPage != null && _receivedTeletextPage.Content != null && !_waiting) { bmpTeletextPage = _renderer.RenderPage(_receivedTeletextPage.Content, receivedPageNumber, receivedSubPageNumber); Log.Info("dvb-teletext: received page {0:X} / subpage {1:X}", receivedPageNumber, receivedSubPageNumber); } Redraw(); return; } if (sub >= maxSubs) { sub = maxSubs - 1; } // Get the page TeletextPage teletextPage = ForTheRecordMain.Navigator.GetTeletextPage(currentPageNumber, sub); // Was the page available, then render it. Otherwise render the last page again and update the header line, if // it was for the first time if (teletextPage != null) { _receivedTeletextPage = teletextPage; receivedPageNumber = currentPageNumber; receivedSubPageNumber = currentSubPageNumber; bmpTeletextPage = _renderer.RenderPage(_receivedTeletextPage.Content, _receivedTeletextPage.PageNumber, sub); _waiting = false; Log.Info("dvb-teletext: select page {0:X} / subpage {1:X}", currentPageNumber, currentSubPageNumber); } else { if (_receivedTeletextPage != null && _receivedTeletextPage.Content != null && !_waiting) { bmpTeletextPage = _renderer.RenderPage(_receivedTeletextPage.Content, receivedPageNumber, receivedSubPageNumber); Log.Info("dvb-teletext: received page {0:X} / subpage {1:X}", receivedPageNumber, receivedSubPageNumber); } _waiting = true; } Redraw(); }