Skip to content

Commit

Permalink
Marginal Filmic Chroma speedup with new techniques
Browse files Browse the repository at this point in the history
yeah I didn't realize you could just cast an array of bytes into an
array of multi-byte primitives my bad. Code smaller and like 30% faster.
  • Loading branch information
Beinsezii committed Jan 12, 2021
1 parent 8eded0d commit c5037b2
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions bsz-filmic-chroma/filmic-chroma.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::convert::TryInto;
use std::os::raw;

#[no_mangle]
Expand All @@ -9,19 +8,12 @@ pub extern "C" fn filmic_chroma(
bytes: *mut raw::c_char,
len: usize) {
let pixels = unsafe {
std::slice::from_raw_parts_mut(bytes.cast::<u8>(), len)
std::slice::from_raw_parts_mut(bytes.cast::<f64>(), len/8)
};
for chunk in pixels.chunks_exact_mut(32) {
let l = f64::from_le_bytes(chunk[0..8].try_into().expect("bytefail"));
let c = f64::from_le_bytes(chunk[8..16].try_into().expect("bytefail2"));

let c = match invert {
false => c * (offset - l / scale),
true => c * (offset - (100.0 - l) / scale)
}.to_le_bytes();

for x in 0..8 {
chunk[x+8] = c[x];
for pixel in pixels.chunks_exact_mut(4) {
pixel[1] = match invert {
false => pixel[1] * (offset - pixel[0] / scale),
true => pixel[1] * (offset - (100.0 - pixel[0]) / scale)
};
}
};
}

0 comments on commit c5037b2

Please sign in to comment.