Skip to content

Commit

Permalink
Merge branch 'master' into migration-timing-module
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekmedia authored Sep 2, 2024
2 parents 414048b + 1a13bbb commit 8e82c1a
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 27 deletions.
7 changes: 0 additions & 7 deletions src/lib_ccx/ccx_encoders_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
// userdefined rgb color
unsigned char usercolor_rgb[8] = "";

struct word_list
{
char **words;
size_t len;
size_t capacity;
};

struct word_list capitalization_list = {
.words = NULL,
.len = 0,
Expand Down
10 changes: 7 additions & 3 deletions src/lib_ccx/ccx_encoders_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "ccx_decoders_structs.h"
#include "ccx_decoders_608.h"
#include "ccx_encoders_common.h"
#include <png.h>

extern struct word_list capitalization_list;
extern struct word_list profane;
Expand All @@ -15,6 +14,13 @@ extern const char *profane_builtin[];

extern unsigned char usercolor_rgb[8];

struct word_list
{
char **words;
size_t len;
size_t capacity;
};

struct ccx_encoders_helpers_settings_t
{
int trim_subs;
Expand Down Expand Up @@ -43,6 +49,4 @@ void shell_sort(void *base, int nb, size_t size, int (*compar)(const void *p1, c

void ccx_encoders_helpers_perform_shellsort_words(void);
void ccx_encoders_helpers_setup(enum ccx_encoding_type encoding, int no_font_color, int no_type_setting, int trim_subs);

int mapclut_paletee(png_color *palette, png_byte *alpha, uint32_t *clut, uint8_t depth);
#endif
2 changes: 1 addition & 1 deletion src/lib_ccx/ccx_encoders_spupng.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "ccfont2.xbm" // CC font from libzvbi
#include "ccx_common_common.h"
#include "ccx_encoders_common.h"
#include "ccx_encoders_spupng.h"
#include <png.h>
#include <ft2build.h>
#include <math.h>
Expand Down
4 changes: 4 additions & 0 deletions src/lib_ccx/ccx_encoders_spupng.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <png.h>
#include "ccx_encoders_common.h"

int mapclut_paletee(png_color *palette, png_byte *alpha, uint32_t *clut, uint8_t depth);
5 changes: 1 addition & 4 deletions src/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,12 @@ fn main() {
"ccx_common_timing_settings_t",
"ccx_s_options",
"ccx_s_teletext_config",
"ccx_output_format",
"ccx_boundary_time",
"ccx_output_date_format",
"ccx_encoding_type",
"ccx_output_date_format",
"ccx_decoder_608_settings",
"ccx_decoder_608_report",
"ccx_output_format",
"uint8_t",
"word_list",
]);

#[cfg(feature = "hardsubx_ocr")]
Expand Down
20 changes: 20 additions & 0 deletions src/rust/lib_ccxr/src/common/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,3 +639,23 @@ impl Default for Options {
}
}
}

impl Options {
pub fn millis_separator(&self) -> char {
if self.ucla {
'.'
} else {
self.date_format.millis_separator()
}
}
}

impl EncoderConfig {
pub fn millis_separator(&self) -> char {
if self.ucla {
'.'
} else {
self.date_format.millis_separator()
}
}
}
16 changes: 13 additions & 3 deletions src/rust/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl FromRust<Options> for ccx_s_options {
self.settings_dtvcc = options.settings_dtvcc.to_ctype();
self.is_608_enabled = options.is_608_enabled as _;
self.is_708_enabled = options.is_708_enabled as _;
self.millis_separator = options.date_format.millis_separator() as _;
self.millis_separator = options.millis_separator() as _;
self.binary_concat = options.binary_concat as _;
self.use_gop_as_pts = if let Some(usegops) = options.use_gop_as_pts {
if usegops {
Expand Down Expand Up @@ -257,7 +257,7 @@ impl CType2<ccx_s_teletext_config, &Options> for TeletextConfig {
encoding: value.enc_cfg.encoding.to_ctype() as _,
nofontcolor: self.nofontcolor.into(),
nohtmlescape: self.nohtmlescape.into(),
millis_separator: self.date_format.millis_separator() as _,
millis_separator: value.millis_separator() as _,
latrusmap: self.latrusmap.into(),
};
config.set_verbose(self.verbose.into());
Expand Down Expand Up @@ -571,7 +571,7 @@ impl CType<encoder_cfg> for EncoderConfig {
ucla: self.ucla as _,
encoding: self.encoding as _,
date_format: self.date_format.to_ctype(),
millis_separator: self.date_format.millis_separator() as _,
millis_separator: self.millis_separator() as _,
autodash: self.autodash as _,
trim_subs: self.trim_subs as _,
sentence_cap: self.sentence_cap as _,
Expand Down Expand Up @@ -625,3 +625,13 @@ impl CType<encoder_cfg> for EncoderConfig {
}
}
}

impl CType<word_list> for Vec<String> {
unsafe fn to_ctype(&self) -> word_list {
word_list {
words: string_to_c_chars(self.clone()),
len: self.len(),
capacity: self.capacity(),
}
}
}
20 changes: 15 additions & 5 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::os::windows::io::{FromRawHandle, RawHandle};
use args::Args;
use bindings::*;
use clap::{error::ErrorKind, Parser};
use common::{CType2, FromRust};
use common::{CType, CType2, FromRust};
use decoder::Dtvcc;
use lib_ccxr::{common::Options, teletext::TeletextConfig, util::log::ExitCause};
use parser::OptionsExt;
Expand Down Expand Up @@ -72,6 +72,8 @@ extern "C" {
static mut fts_at_gop_start: c_long;
static mut gop_rollover: c_int;
static mut ccx_common_timing_settings: ccx_common_timing_settings_t;
static mut capitalization_list: word_list;
static mut profane: word_list;
}

/// Initialize env logger with custom format, using stdout as target
Expand Down Expand Up @@ -265,22 +267,30 @@ pub unsafe extern "C" fn ccxr_parse_parameters(argc: c_int, argv: *mut *mut c_ch
}
};

let mut capitalization_list: Vec<String> = Vec::new();
let mut profane: Vec<String> = Vec::new();
let mut _capitalization_list: Vec<String> = Vec::new();
let mut _profane: Vec<String> = Vec::new();

let mut opt = Options::default();
let mut _tlt_config = TeletextConfig::default();

opt.parse_parameters(
&args,
&mut _tlt_config,
&mut capitalization_list,
&mut profane,
&mut _capitalization_list,
&mut _profane,
);
tlt_config = _tlt_config.to_ctype(&opt);

// Convert the rust struct (CcxOptions) to C struct (ccx_s_options), so that it can be used by the C code
ccx_options.copy_from_rust(opt);

if !_capitalization_list.is_empty() {
capitalization_list = _capitalization_list.to_ctype();
}
if !_profane.is_empty() {
profane = _profane.to_ctype();
}

ExitCause::Ok.exit_code()
}

Expand Down
10 changes: 6 additions & 4 deletions src/rust/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,11 +1222,9 @@ impl OptionsExt for Options {
tlt_config.page = Cell::new(TeletextPageNumber::from(tlt_config.user_page));
}

let mut millis_separator = ',';
// Red Hen/ UCLA Specific stuff
if args.ucla {
self.ucla = true;
millis_separator = '.';
self.enc_cfg.no_bom = true;

if !self.transcript_settings.is_final {
Expand Down Expand Up @@ -1291,11 +1289,15 @@ impl OptionsExt for Options {
}

if args.sects {
self.date_format = TimestampFormat::Seconds { millis_separator };
self.date_format = TimestampFormat::Seconds {
millis_separator: ',',
};
}

if args.datets {
self.date_format = TimestampFormat::Date { millis_separator };
self.date_format = TimestampFormat::Date {
millis_separator: ',',
};
}

if args.teletext {
Expand Down
1 change: 1 addition & 0 deletions src/rust/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
#include "../lib_ccx/lib_ccx.h"
#include "../lib_ccx/hardsubx.h"
#include "../lib_ccx/utility.h"
#include "../lib_ccx/ccx_encoders_helpers.h"

0 comments on commit 8e82c1a

Please sign in to comment.