TMP
This commit is contained in:
@ -43,6 +43,7 @@ pub enum Format {
|
||||
Gray8,
|
||||
Gray8Simd,
|
||||
Gray16be,
|
||||
Pal4,
|
||||
}
|
||||
|
||||
impl Format {
|
||||
@ -98,6 +99,16 @@ impl Format {
|
||||
tgt.write_all(&buf[0..OUT])?;
|
||||
}
|
||||
}
|
||||
|
||||
Self::Pal4 => {
|
||||
const OUT: usize = reduce::pal4::out_size(IN_SIZE);
|
||||
let mut buf = [0u8; IN_SIZE];
|
||||
loop {
|
||||
src.read_exact(&mut buf)?;
|
||||
reduce::pal4::run(&mut buf);
|
||||
tgt.write_all(&buf[0..OUT])?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,3 +2,4 @@ pub mod gray8;
|
||||
pub mod gray8_simd;
|
||||
pub mod mono;
|
||||
pub mod mono_simd;
|
||||
pub mod pal4;
|
||||
|
37
server/src/reduce/pal4.rs
Normal file
37
server/src/reduce/pal4.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use std::convert::TryInto;
|
||||
|
||||
const GROUP_BY: usize = 8;
|
||||
pub const fn out_size(in_size: usize) -> usize {
|
||||
in_size / 8
|
||||
}
|
||||
|
||||
pub fn run(buf: &mut [u8]) {
|
||||
let n_raw = buf.len();
|
||||
let mut in_cursor = 0;
|
||||
let mut out_cursor = 0;
|
||||
|
||||
while in_cursor + GROUP_BY <= n_raw {
|
||||
let a: &[u8; 8] = buf[in_cursor..in_cursor + 8].try_into().unwrap();
|
||||
|
||||
let pix = [a[0], a[2], a[4], a[6]];
|
||||
|
||||
let mut out = 0u8;
|
||||
|
||||
for i in 0..pix.len() {
|
||||
let p = pix[i] & 0b1110;
|
||||
if p >= 0x0E {
|
||||
out |= 0b11 >> (2 * i);
|
||||
} else if p >= 0x04 {
|
||||
out |= 0b10 >> (2 * i);
|
||||
} else if p >= 0x01 {
|
||||
out |= 0b01 >> (2 * i);
|
||||
} else {
|
||||
out |= 0b00 >> (2 * i);
|
||||
}
|
||||
}
|
||||
|
||||
buf[out_cursor] = out;
|
||||
out_cursor += 1;
|
||||
in_cursor += GROUP_BY;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user