Skip to content

Commit 4410676

Browse files
committed
style fixes
1 parent 1cb7606 commit 4410676

File tree

7 files changed

+33
-70
lines changed

7 files changed

+33
-70
lines changed

src/rust/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn main() {
2525
"init_encoder",
2626
"dinit_encoder",
2727
"encode_sub",
28-
"add_cc_sub_text"
28+
"add_cc_sub_text",
2929
]);
3030

3131
let mut allowlist_types = vec![
@@ -36,7 +36,7 @@ fn main() {
3636
"ccx_output_format",
3737
"ccx_s_options",
3838
"lib_ccx_ctx",
39-
"encoder_ctx"
39+
"encoder_ctx",
4040
];
4141

4242
#[cfg(feature = "hardsubx_ocr")]

src/rust/src/hardsubx/classifier.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub type subdatatype = ::std::os::raw::c_uint;
1212
pub type subtype = ::std::os::raw::c_uint;
1313
pub type ccx_encoding_type = ::std::os::raw::c_uint;
1414

15-
1615
use std::os::raw::c_char;
1716

1817
use log::warn;
@@ -58,8 +57,6 @@ pub unsafe fn get_ocr_text_simple_threshold(
5857
}
5958
}
6059

61-
62-
6360
/// Function extracts string from tess iterator object
6461
/// frees memory associated with tesseract string
6562
/// takes and gives ownership of the string
@@ -178,8 +175,6 @@ pub unsafe fn get_ocr_text_wordwise_threshold(
178175
text_out
179176
}
180177

181-
182-
183178
/// # Safety
184179
/// The function dereferences a raw pointer
185180
/// The function also calls other functions whose safety is not guaranteed
@@ -240,5 +235,3 @@ pub unsafe fn get_ocr_text_letterwise_threshold(
240235

241236
text_out
242237
}
243-
244-

src/rust/src/hardsubx/decoder.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ use crate::ccx_encoding_type::*;
2727

2828
use std::cmp;
2929

30-
31-
32-
3330
/// # Safety
3431
/// dereferences a raw pointer
3532
/// calls functions that are not necessarily safe
@@ -47,7 +44,6 @@ pub unsafe fn dispatch_classifier_functions(ctx: &mut HardsubxContext, im: *mut
4744
hardsubx_ocr_mode::HARDSUBX_OCRMODE_FRAME => {
4845
get_ocr_text_simple_threshold(ctx, im, (*ctx).conf_thresh)
4946
}
50-
5147
}
5248
}
5349

@@ -548,7 +544,6 @@ pub unsafe fn hardsubx_process_frames_linear(ctx: &mut HardsubxContext, enc_ctx:
548544
);
549545
}
550546

551-
552547
/// # Safety
553548
/// dereferences a raw pointer
554549
/// calls potentially unsafe C functions

src/rust/src/hardsubx/main.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use super::decoder::hardsubx_process_frames_linear;
2+
use super::HardsubxContext;
13
#[cfg(feature = "hardsubx_ocr")]
24
use crate::bindings::{
35
ccx_s_options, dinit_encoder, encoder_cfg, encoder_ctx, init_encoder, lib_ccx_ctx,
@@ -18,19 +20,16 @@ use std::process;
1820
use std::ptr::null;
1921
#[cfg(feature = "hardsubx_ocr")]
2022
use tesseract_sys::*;
21-
use super::HardsubxContext;
22-
use super::decoder::hardsubx_process_frames_linear;
2323
extern "C" {
2424
pub static mut ccx_options: ccx_s_options;
2525
}
2626

27-
28-
2927
/// # Safety
3028
/// Dereferences a raw pointer (datamember of the object ctx)
3129
/// calls potentially unsafe C functions
3230
pub unsafe fn hardsubx_process_data(ctx: &mut HardsubxContext, _ctx_normal: *mut lib_ccx_ctx) {
33-
let mut format_ctx_tmp: *mut AVFormatContext = null::<AVFormatContext>() as *mut AVFormatContext;
31+
let mut format_ctx_tmp: *mut AVFormatContext =
32+
null::<AVFormatContext>() as *mut AVFormatContext;
3433
let file_name = string_to_c_char(&ctx.inputfile[0]);
3534
if avformat_open_input(
3635
&mut format_ctx_tmp as *mut *mut AVFormatContext,
@@ -56,23 +55,14 @@ pub unsafe fn hardsubx_process_data(ctx: &mut HardsubxContext, _ctx_normal: *mut
5655
process::exit(EXIT_READ_ERROR);
5756
}
5857

59-
av_dump_format(
60-
format_ctx_tmp as *mut AVFormatContext,
61-
0,
62-
file_name,
63-
0,
64-
);
58+
av_dump_format(format_ctx_tmp as *mut AVFormatContext, 0, file_name, 0);
6559

6660
ffi::CString::from_raw(file_name); //deallocation
6761

6862
ctx.video_stream_id = -1;
6963

7064
for i in 0..format_ctx_ref.nb_streams {
71-
if (*(**format_ctx_ref
72-
.streams
73-
.offset(i.try_into().unwrap()))
74-
.codecpar)
75-
.codec_type
65+
if (*(**format_ctx_ref.streams.offset(i.try_into().unwrap())).codecpar).codec_type
7666
== AVMEDIA_TYPE_VIDEO
7767
{
7868
ctx.video_stream_id = i as i32;
@@ -88,12 +78,10 @@ pub unsafe fn hardsubx_process_data(ctx: &mut HardsubxContext, _ctx_normal: *mut
8878

8979
let mut codec_ctx: *mut AVCodecContext = avcodec_alloc_context3(null::<AVCodec>());
9080

91-
let codec_par_ptr: *mut AVCodecParameters = (*(*format_ctx_ref.streams)
92-
.offset(ctx.video_stream_id.try_into().unwrap()))
93-
.codecpar;
81+
let codec_par_ptr: *mut AVCodecParameters =
82+
(*(*format_ctx_ref.streams).offset(ctx.video_stream_id.try_into().unwrap())).codecpar;
9483
let codec_par_ref: &mut AVCodecParameters = &mut (*codec_par_ptr);
9584

96-
9785
let status =
9886
avcodec_parameters_to_context(codec_ctx, codec_par_ref as *const AVCodecParameters);
9987

@@ -114,8 +102,7 @@ pub unsafe fn hardsubx_process_data(ctx: &mut HardsubxContext, _ctx_normal: *mut
114102
ctx.codec = codec_ptr;
115103
}
116104

117-
if avcodec_open2(ctx.codec_ctx, ctx.codec, &mut ctx.options_dict) < 0
118-
{
105+
if avcodec_open2(ctx.codec_ctx, ctx.codec, &mut ctx.options_dict) < 0 {
119106
eprintln!("Error opening input codec!\n");
120107
process::exit(EXIT_READ_ERROR);
121108
}
@@ -198,9 +185,7 @@ pub unsafe fn hardsubx_process_data(ctx: &mut HardsubxContext, _ctx_normal: *mut
198185

199186
/// # Safety
200187
/// calls potentially unsafe C functions
201-
pub unsafe fn _dinit_hardsubx(ctx: &mut HardsubxContext)
202-
{
203-
188+
pub unsafe fn _dinit_hardsubx(ctx: &mut HardsubxContext) {
204189
// Free OCR related stuff
205190
TessBaseAPIEnd(ctx.tess_handle);
206191
TessBaseAPIDelete(ctx.tess_handle);

src/rust/src/hardsubx/mod.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,38 @@ use leptonica_sys::*;
1515

1616
use crate::bindings;
1717
use crate::bindings::{
18-
cc_subtitle, ccx_output_format, ccx_s_options, get_file_extension, probe_tessdata_location
18+
cc_subtitle, ccx_output_format, ccx_s_options, get_file_extension, probe_tessdata_location,
1919
};
2020
use crate::utils::string_to_c_char;
2121
use std::boxed::Box;
2222
use std::convert::TryInto;
2323
use std::ffi;
2424
use std::matches;
2525
use std::os::raw::c_char;
26+
use std::os::raw::c_void;
2627
use std::process;
2728
use std::ptr::null;
2829
use std::vec::Vec;
29-
use std::os::raw::c_void;
30-
3130

3231
// definitions taken from ccx_common_common.h
3332
static EXIT_NOT_ENOUGH_MEMORY: i32 = 500;
3433
static EXIT_READ_ERROR: i32 = 8;
3534

36-
3735
static EXIT_MALFORMED_PARAMETER: i32 = 7;
3836

3937
extern "C" {
4038
pub static mut ccx_options: ccx_s_options;
4139
}
4240

43-
pub enum hardsubx_color_type
44-
{
45-
HARDSUBX_COLOR_WHITE,
46-
HARDSUBX_COLOR_YELLOW,
47-
HARDSUBX_COLOR_GREEN,
48-
HARDSUBX_COLOR_CYAN,
49-
HARDSUBX_COLOR_BLUE,
50-
HARDSUBX_COLOR_MAGENTA,
51-
HARDSUBX_COLOR_RED,
52-
HARDSUBX_COLOR_CUSTOM,
41+
pub enum hardsubx_color_type {
42+
HARDSUBX_COLOR_WHITE,
43+
HARDSUBX_COLOR_YELLOW,
44+
HARDSUBX_COLOR_GREEN,
45+
HARDSUBX_COLOR_CYAN,
46+
HARDSUBX_COLOR_BLUE,
47+
HARDSUBX_COLOR_MAGENTA,
48+
HARDSUBX_COLOR_RED,
49+
HARDSUBX_COLOR_CUSTOM,
5350
}
5451

5552
pub enum hardsubx_ocr_mode {
@@ -58,7 +55,6 @@ pub enum hardsubx_ocr_mode {
5855
HARDSUBX_OCRMODE_LETTER,
5956
}
6057

61-
6258
impl Default for cc_subtitle {
6359
fn default() -> Self {
6460
Self {
@@ -188,7 +184,7 @@ impl Default for HardsubxContext {
188184
codec: null::<AVCodec>() as *mut AVCodec,
189185
frame: null::<AVFrame>() as *mut AVFrame,
190186
rgb_frame: null::<AVFrame>() as *mut AVFrame,
191-
packet: AVPacket{
187+
packet: AVPacket {
192188
buf: null::<AVBufferRef>() as *mut AVBufferRef,
193189
pts: 0,
194190
dts: 0,
@@ -364,15 +360,15 @@ impl HardsubxContext {
364360
hardsubx_ocr_mode::HARDSUBX_OCRMODE_FRAME
365361
} else if (*options).hardsubx_ocr_mode == 1 {
366362
hardsubx_ocr_mode::HARDSUBX_OCRMODE_WORD
367-
} else if (*options).hardsubx_ocr_mode == 2{
363+
} else if (*options).hardsubx_ocr_mode == 2 {
368364
hardsubx_ocr_mode::HARDSUBX_OCRMODE_LETTER
369365
} else {
370366
eprintln!("Invalid OCR Mode");
371367
process::exit(EXIT_MALFORMED_PARAMETER);
372368
}
373369
},
374370

375-
subcolor: match (*options).hardsubx_subcolor{
371+
subcolor: match (*options).hardsubx_subcolor {
376372
0 => hardsubx_color_type::HARDSUBX_COLOR_WHITE,
377373
1 => hardsubx_color_type::HARDSUBX_COLOR_YELLOW,
378374
2 => hardsubx_color_type::HARDSUBX_COLOR_GREEN,
@@ -381,7 +377,7 @@ impl HardsubxContext {
381377
5 => hardsubx_color_type::HARDSUBX_COLOR_MAGENTA,
382378
6 => hardsubx_color_type::HARDSUBX_COLOR_RED,
383379
7 => hardsubx_color_type::HARDSUBX_COLOR_CUSTOM,
384-
_ => hardsubx_color_type::HARDSUBX_COLOR_WHITE // white is default
380+
_ => hardsubx_color_type::HARDSUBX_COLOR_WHITE, // white is default
385381
},
386382

387383
min_sub_duration: (*options).hardsubx_min_sub_duration,

src/rust/src/hardsubx/utility.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ pub unsafe extern "C" fn edit_distance(
8787
) as c_int
8888
}
8989

90-
pub fn edit_distance_string(
91-
word1: &str,
92-
word2: &str,
93-
) -> i32 {
94-
90+
pub fn edit_distance_string(word1: &str, word2: &str) -> i32 {
9591
let len1 = word1.chars().count();
9692
let len2 = word2.chars().count();
9793

src/rust/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ use utils::is_true;
2828
use env_logger::{builder, Target};
2929
use log::{warn, LevelFilter};
3030

31-
pub enum ccx_encoding_type
32-
{
33-
CCX_ENC_UNICODE = 0,
34-
CCX_ENC_LATIN_1 = 1,
35-
CCX_ENC_UTF_8 = 2,
36-
CCX_ENC_ASCII = 3
31+
pub enum ccx_encoding_type {
32+
CCX_ENC_UNICODE = 0,
33+
CCX_ENC_LATIN_1 = 1,
34+
CCX_ENC_UTF_8 = 2,
35+
CCX_ENC_ASCII = 3,
3736
}
3837

39-
4038
extern "C" {
4139
static mut cb_708: c_int;
4240
static mut cb_field1: c_int;

0 commit comments

Comments
 (0)