Skip to content

Commit 31b2bc0

Browse files
committed
fix: hardsubx garbage output
1 parent b32fb44 commit 31b2bc0

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/rust/src/hardsubx/decoder.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ pub unsafe fn dispatch_classifier_functions(ctx: *mut lib_hardsubx_ctx, im: *mut
4040
// function that calls the classifier functions
4141
match (*ctx).ocr_mode {
4242
0 => {
43+
let ret_char_arr = get_ocr_text_simple_threshold(ctx, im, (*ctx).conf_thresh);
44+
let text_out_result = ffi::CString::from_raw(ret_char_arr).into_string();
45+
match text_out_result {
46+
Ok(T) => T,
47+
Err(_E) => "".to_string(),
48+
}
49+
}
50+
1 => {
4351
let ret_char_arr = get_ocr_text_wordwise_threshold(ctx, im, (*ctx).conf_thresh);
4452
if ret_char_arr.is_null() {
4553
"".to_string()
@@ -49,17 +57,8 @@ pub unsafe fn dispatch_classifier_functions(ctx: *mut lib_hardsubx_ctx, im: *mut
4957
.into_owned()
5058
}
5159
}
52-
1 => {
53-
let ret_char_arr = get_ocr_text_letterwise_threshold(ctx, im, (*ctx).conf_thresh);
54-
let text_out_result = ffi::CString::from_raw(ret_char_arr).into_string();
55-
match text_out_result {
56-
Ok(T) => T,
57-
Err(_E) => "".to_string(),
58-
}
59-
}
60-
6160
2 => {
62-
let ret_char_arr = get_ocr_text_simple_threshold(ctx, im, (*ctx).conf_thresh);
61+
let ret_char_arr = get_ocr_text_letterwise_threshold(ctx, im, (*ctx).conf_thresh);
6362
let text_out_result = ffi::CString::from_raw(ret_char_arr).into_string();
6463
match text_out_result {
6564
Ok(T) => T,
@@ -70,7 +69,6 @@ pub unsafe fn dispatch_classifier_functions(ctx: *mut lib_hardsubx_ctx, im: *mut
7069
_ => {
7170
eprintln!("Invalid OCR Mode");
7271
exit(EXIT_MALFORMED_PARAMETER);
73-
// "".to_string()
7472
}
7573
}
7674
}
@@ -117,7 +115,7 @@ pub unsafe extern "C" fn _process_frame_white_basic(
117115
let mut gray_im: *mut Pix = pixConvertRGBToGray(im, 0.0, 0.0, 0.0);
118116
let mut sobel_edge_im: *mut Pix =
119117
pixSobelEdgeFilter(gray_im, L_VERTICAL_EDGES.try_into().unwrap());
120-
let mut dilate_gray_im: *mut Pix = pixDilateGray(sobel_edge_im, 21, 1);
118+
let mut dilate_gray_im: *mut Pix = pixDilateGray(sobel_edge_im, 21, 11);
121119
let mut edge_im: *mut Pix = pixThresholdToBinary(dilate_gray_im, 50);
122120

123121
let mut feat_im: *mut Pix = pixCreate(width, height, 32);

src/rust/src/hardsubx/imgops.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ pub extern "C" fn rgb_to_hsv(R: f32, G: f32, B: f32, H: &mut f32, S: &mut f32, V
1313

1414
#[no_mangle]
1515
pub extern "C" fn rgb_to_lab(R: f32, G: f32, B: f32, L: &mut f32, a: &mut f32, b: &mut f32) {
16-
let rgb = Srgb::new(R, G, B);
16+
// Normalize input RGB from 0-255 to 0.0-1.0
17+
let rgb = Srgb::new(R / 255.0, G / 255.0, B / 255.0);
1718

18-
// This declaration sets the white-point as per the D65 standard
19-
let lab_rep = Lab::<palette::white_point::D65, f32>::from_color(rgb);
19+
// Convert from sRGB to Lab (D65 white point is default)
20+
let lab_rep = Lab::from_color(rgb);
2021

2122
*L = lab_rep.l;
2223
*a = lab_rep.a;

0 commit comments

Comments
 (0)