Skip to content

Commit

Permalink
fix: reassign back profane and capitalization lists to c
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekmedia committed Aug 28, 2024
1 parent f2bbcdb commit 7e01acd
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 21 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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -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
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 @@ -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")]
Expand Down
10 changes: 10 additions & 0 deletions src/rust/src/common.rs
Original file line number Diff line number Diff line change
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 {
return 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 @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -253,22 +255,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
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 7e01acd

Please sign in to comment.