forked from CCExtractor/ccextractor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port hardsubx imgops (CCExtractor#1439)
* add hardsubx rust module and expose it * port rgb_to_hsv to rust * add dependency fast-math and extern it * port rgb_to_lab to rust also make preprocessor to not allow compilation of hardsubx_imgops if WITHOUT_RUST is OFF * improve if-else constructs for readability * unroll macros that were only used once and remove their definition * Improve readability of rgb_to_lab function (and fixes) The function in Rust behaves slightly differently than its C counterpart * remove fast math library, use palette library and rewrite imgops using it * run formatter * replace destructuring assignment statement with normal assignment statements because of build rust compiler issues * run formatter on C code for imgops * remove extern for modules because it is not required * improve comment placement in rust imgops Co-authored-by: Punit Lodha <[email protected]>
- Loading branch information
1 parent
689d92a
commit 0f90afa
Showing
6 changed files
with
228 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use palette::{FromColor, Hsv, Lab, Srgb}; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn rgb_to_hsv(R: f32, G: f32, B: f32, H: &mut f32, S: &mut f32, V: &mut f32) { | ||
let rgb = Srgb::new(R, G, B); | ||
|
||
let hsv_rep = Hsv::from_color(rgb); | ||
|
||
*H = hsv_rep.hue.to_positive_degrees(); | ||
*S = hsv_rep.saturation; | ||
*V = hsv_rep.value; | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn rgb_to_lab(R: f32, G: f32, B: f32, L: &mut f32, a: &mut f32, b: &mut f32) { | ||
let rgb = Srgb::new(R, G, B); | ||
|
||
// This declaration sets the white-point as per the D65 standard | ||
let lab_rep = Lab::<palette::white_point::D65, f32>::from_color(rgb); | ||
|
||
*L = lab_rep.l; | ||
*a = lab_rep.a; | ||
*b = lab_rep.b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod imgops; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters