diff --git a/src/lib_ccx/ccx_encoders_helpers.c b/src/lib_ccx/ccx_encoders_helpers.c index fb7d25396..00f96b45b 100644 --- a/src/lib_ccx/ccx_encoders_helpers.c +++ b/src/lib_ccx/ccx_encoders_helpers.c @@ -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, diff --git a/src/lib_ccx/ccx_encoders_helpers.h b/src/lib_ccx/ccx_encoders_helpers.h index dae1f4c48..2b1f24cb6 100644 --- a/src/lib_ccx/ccx_encoders_helpers.h +++ b/src/lib_ccx/ccx_encoders_helpers.h @@ -6,7 +6,6 @@ #include "ccx_decoders_structs.h" #include "ccx_decoders_608.h" #include "ccx_encoders_common.h" -#include extern struct word_list capitalization_list; extern struct word_list profane; @@ -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; @@ -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 diff --git a/src/lib_ccx/ccx_encoders_spupng.c b/src/lib_ccx/ccx_encoders_spupng.c index de5151c11..815c521ed 100644 --- a/src/lib_ccx/ccx_encoders_spupng.c +++ b/src/lib_ccx/ccx_encoders_spupng.c @@ -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 #include #include @@ -704,7 +704,7 @@ uint32_t *utf8_to_utf32(char *src) } // Convert big-endian and little-endian -#define BigtoLittle32(A) ((((uint32_t)(A)&0xff000000) >> 24) | (((uint32_t)(A)&0x00ff0000) >> 8) | (((uint32_t)(A)&0x0000ff00) << 8) | (((uint32_t)(A)&0x000000ff) << 24)) +#define BigtoLittle32(A) ((((uint32_t)(A) & 0xff000000) >> 24) | (((uint32_t)(A) & 0x00ff0000) >> 8) | (((uint32_t)(A) & 0x0000ff00) << 8) | (((uint32_t)(A) & 0x000000ff) << 24)) // Generate PNG file from an UTF-8 string (str) // PNG file will be stored at output diff --git a/src/lib_ccx/ccx_encoders_spupng.h b/src/lib_ccx/ccx_encoders_spupng.h new file mode 100644 index 000000000..25277df3c --- /dev/null +++ b/src/lib_ccx/ccx_encoders_spupng.h @@ -0,0 +1,4 @@ +#include +#include "ccx_encoders_common.h" + +int mapclut_paletee(png_color *palette, png_byte *alpha, uint32_t *clut, uint8_t depth); \ No newline at end of file diff --git a/src/rust/build.rs b/src/rust/build.rs index 7341eeebb..9429cdb12 100644 --- a/src/rust/build.rs +++ b/src/rust/build.rs @@ -33,15 +33,12 @@ fn main() { "gop_time_code", "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")] diff --git a/src/rust/src/common.rs b/src/rust/src/common.rs index e1ad15cbb..c9be2dcea 100644 --- a/src/rust/src/common.rs +++ b/src/rust/src/common.rs @@ -625,3 +625,13 @@ impl CType for EncoderConfig { } } } + +impl CType for Vec { + unsafe fn to_ctype(&self) -> word_list { + return word_list { + words: string_to_c_chars(self.clone()), + len: self.len(), + capacity: self.capacity(), + }; + } +} diff --git a/src/rust/src/lib.rs b/src/rust/src/lib.rs index b88493605..a65eec8a6 100644 --- a/src/rust/src/lib.rs +++ b/src/rust/src/lib.rs @@ -29,7 +29,7 @@ use std::{io::Write, os::raw::c_char, os::raw::c_int}; 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; @@ -60,6 +60,8 @@ extern "C" { static mut MPEG_CLOCK_FREQ: c_int; static mut tlt_config: ccx_s_teletext_config; static mut ccx_options: ccx_s_options; + static mut capitalization_list: word_list; + static mut profane: word_list; } /// Initialize env logger with custom format, using stdout as target @@ -253,8 +255,8 @@ pub unsafe extern "C" fn ccxr_parse_parameters(argc: c_int, argv: *mut *mut c_ch } }; - let mut capitalization_list: Vec = Vec::new(); - let mut profane: Vec = Vec::new(); + let mut _capitalization_list: Vec = Vec::new(); + let mut _profane: Vec = Vec::new(); let mut opt = Options::default(); let mut _tlt_config = TeletextConfig::default(); @@ -262,13 +264,21 @@ pub unsafe extern "C" fn ccxr_parse_parameters(argc: c_int, argv: *mut *mut c_ch 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() } diff --git a/src/rust/wrapper.h b/src/rust/wrapper.h index 7205fac4a..a7297478f 100644 --- a/src/rust/wrapper.h +++ b/src/rust/wrapper.h @@ -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"