From e89dd7456c1d4491374aac68414a43627a861d83 Mon Sep 17 00:00:00 2001 From: Prateek Sunal Date: Mon, 19 Aug 2024 22:50:31 +0530 Subject: [PATCH] fix: reference to TeletextConfig --- src/rust/lib_ccxr/src/common/mod.rs | 2 - src/rust/lib_ccxr/src/common/teletext.rs | 87 ------------------------ src/rust/lib_ccxr/src/teletext.rs | 51 ++++++++++---- src/rust/src/common.rs | 2 +- src/rust/src/lib.rs | 5 +- src/rust/src/parser.rs | 1 + 6 files changed, 39 insertions(+), 109 deletions(-) delete mode 100644 src/rust/lib_ccxr/src/common/teletext.rs diff --git a/src/rust/lib_ccxr/src/common/mod.rs b/src/rust/lib_ccxr/src/common/mod.rs index 61a0a8b59..4aaf4bb62 100644 --- a/src/rust/lib_ccxr/src/common/mod.rs +++ b/src/rust/lib_ccxr/src/common/mod.rs @@ -18,8 +18,6 @@ mod constants; mod options; -mod teletext; pub use constants::*; pub use options::*; -pub use teletext::*; diff --git a/src/rust/lib_ccxr/src/common/teletext.rs b/src/rust/lib_ccxr/src/common/teletext.rs deleted file mode 100644 index 54bac7889..000000000 --- a/src/rust/lib_ccxr/src/common/teletext.rs +++ /dev/null @@ -1,87 +0,0 @@ -use crate::time::units::{Timestamp, TimestampFormat}; -use std::{cell::Cell, fmt}; - -use super::OutputFormat; - -#[derive(Debug)] -pub struct TeletextConfig { - /// should telxcc logging be verbose? - pub verbose: bool, - /// teletext page containing cc we want to filter - pub page: Cell, - /// Page selected by user, which MIGHT be different to `page` depending on autodetection stuff - pub user_page: u16, - /// false = Don't attempt to correct errors - pub dolevdist: bool, - /// Means 2 fails or less is "the same" - pub levdistmincnt: u8, - /// Means 10% or less is also "the same" - pub levdistmaxpct: u8, - /// Segment we actually process - pub extraction_start: Option, - /// Segment we actually process - pub extraction_end: Option, - pub write_format: OutputFormat, - pub date_format: TimestampFormat, - /// Do NOT set time automatically? - pub noautotimeref: bool, - pub nofontcolor: bool, - pub nohtmlescape: bool, - pub latrusmap: bool, -} - -impl Default for TeletextConfig { - fn default() -> Self { - Self { - verbose: true, - page: TeletextPageNumber(0).into(), - user_page: 0, - dolevdist: false, - levdistmincnt: 0, - levdistmaxpct: 0, - extraction_start: None, - extraction_end: None, - write_format: OutputFormat::default(), - date_format: TimestampFormat::default(), - noautotimeref: false, - nofontcolor: false, - nohtmlescape: false, - latrusmap: false, - } - } -} - -/// Represents a Teletext Page Number in its bitcode representation. -/// -/// It can be easily contructed from a [`u16`]. -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub struct TeletextPageNumber(u16); - -impl From for TeletextPageNumber { - fn from(value: u16) -> TeletextPageNumber { - TeletextPageNumber(value) - } -} - -impl fmt::Display for TeletextPageNumber { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{:03x}", self.0) - } -} - -impl TeletextPageNumber { - /// Return the magazine and packet bits. - pub fn magazine(&self) -> u8 { - ((self.0 >> 8) & 0x0f) as u8 - } - - /// Return the page bits. - pub fn page(&self) -> u8 { - (self.0 & 0xff) as u8 - } - - /// Return the page number after converting the page bits in bcd format to normal integer. - pub fn bcd_page_to_u16(&self) -> u16 { - ((self.0 & 0xf00) >> 8) * 100 + ((self.0 & 0xf0) >> 4) * 10 + (self.0 & 0xf) - } -} diff --git a/src/rust/lib_ccxr/src/teletext.rs b/src/rust/lib_ccxr/src/teletext.rs index 2b3a75699..c7289e586 100644 --- a/src/rust/lib_ccxr/src/teletext.rs +++ b/src/rust/lib_ccxr/src/teletext.rs @@ -724,31 +724,52 @@ pub struct TeletextPage { } /// Settings required to contruct a [`TeletextContext`]. -#[allow(dead_code)] +#[derive(Debug)] pub struct TeletextConfig { /// should telxcc logging be verbose? - verbose: bool, + pub verbose: bool, /// teletext page containing cc we want to filter - page: Cell, + pub page: Cell, /// Page selected by user, which MIGHT be different to `page` depending on autodetection stuff - user_page: u16, + pub user_page: u16, /// false = Don't attempt to correct errors - dolevdist: bool, + pub dolevdist: bool, /// Means 2 fails or less is "the same" - levdistmincnt: u8, + pub levdistmincnt: u8, /// Means 10% or less is also "the same" - levdistmaxpct: u8, + pub levdistmaxpct: u8, /// Segment we actually process - extraction_start: Option, + pub extraction_start: Option, /// Segment we actually process - extraction_end: Option, - write_format: OutputFormat, - date_format: TimestampFormat, + pub extraction_end: Option, + pub write_format: OutputFormat, + pub date_format: TimestampFormat, /// Do NOT set time automatically? - noautotimeref: bool, - nofontcolor: bool, - nohtmlescape: bool, - latrusmap: bool, + pub noautotimeref: bool, + pub nofontcolor: bool, + pub nohtmlescape: bool, + pub latrusmap: bool, +} + +impl Default for TeletextConfig { + fn default() -> Self { + Self { + verbose: true, + page: TeletextPageNumber(0).into(), + user_page: 0, + dolevdist: false, + levdistmincnt: 0, + levdistmaxpct: 0, + extraction_start: None, + extraction_end: None, + write_format: OutputFormat::default(), + date_format: TimestampFormat::default(), + noautotimeref: false, + nofontcolor: false, + nohtmlescape: false, + latrusmap: false, + } + } } /// Represents the possible states that [`TeletextContext`] can be in. diff --git a/src/rust/src/common.rs b/src/rust/src/common.rs index ee4adea4c..608761696 100644 --- a/src/rust/src/common.rs +++ b/src/rust/src/common.rs @@ -14,9 +14,9 @@ use lib_ccxr::common::OutputFormat; use lib_ccxr::common::SelectCodec; use lib_ccxr::common::StreamMode; use lib_ccxr::common::StreamType; -use lib_ccxr::common::TeletextConfig; use lib_ccxr::hardsubx::ColorHue; use lib_ccxr::hardsubx::OcrMode; +use lib_ccxr::teletext::TeletextConfig; use lib_ccxr::time::units::Timestamp; use lib_ccxr::time::units::TimestampFormat; use lib_ccxr::util::encoding::Encoding; diff --git a/src/rust/src/lib.rs b/src/rust/src/lib.rs index 87a2f24fa..bd94fd526 100644 --- a/src/rust/src/lib.rs +++ b/src/rust/src/lib.rs @@ -32,10 +32,7 @@ use bindings::*; use clap::{error::ErrorKind, Parser}; use common::{CType2, FromRust}; use decoder::Dtvcc; -use lib_ccxr::{ - common::{Options, TeletextConfig}, - util::log::ExitCause, -}; +use lib_ccxr::{common::Options, teletext::TeletextConfig, util::log::ExitCause}; use parser::OptionsExt; use utils::is_true; diff --git a/src/rust/src/parser.rs b/src/rust/src/parser.rs index 47341ec84..1c381bf88 100644 --- a/src/rust/src/parser.rs +++ b/src/rust/src/parser.rs @@ -1,4 +1,5 @@ use args::{Args, OutFormat}; +use lib_ccxr::teletext::{TeletextConfig, TeletextPageNumber}; use lib_ccxr::time::units::{Timestamp, TimestampFormat}; use lib_ccxr::util::encoding::Encoding; use lib_ccxr::util::log::{DebugMessageFlag, DebugMessageMask, ExitCause, OutputTarget};