Commit dd763d01 authored by Monty's avatar Monty
Browse files

Read 10-bit y4m input. #107

Note this cannot yet encode high bitdepth; it reads it and then shifts
to 8 before encode.
parent 893f2aac
......@@ -12,7 +12,7 @@ clap = "2"
libc = "0.2"
rand = "0.4"
rustyline = "1"
y4m = "0.1"
y4m = "0.2"
enum-iterator-derive = "0.1.1"
backtrace = "0.3"
......
......@@ -757,6 +757,8 @@ pub fn process_frame(sequence: &Sequence, fi: &FrameInvariants,
}
let width = fi.width;
let height = fi.height;
let y4m_bits = y4m_dec.get_bit_depth();
let y4m_bytes = y4m_dec.get_bytes_per_sample();
match y4m_dec.read_frame() {
Ok(y4m_frame) => {
let y4m_y = y4m_frame.get_y_plane();
......@@ -764,9 +766,23 @@ pub fn process_frame(sequence: &Sequence, fi: &FrameInvariants,
let y4m_v = y4m_frame.get_v_plane();
eprintln!("{}", fi);
let mut fs = FrameState::new(&fi);
fs.input.planes[0].copy_from_raw_u8(&y4m_y, width);
fs.input.planes[1].copy_from_raw_u8(&y4m_u, width/2);
fs.input.planes[2].copy_from_raw_u8(&y4m_v, width/2);
fs.input.planes[0].copy_from_raw_u8(&y4m_y, width*y4m_bytes, y4m_bytes);
fs.input.planes[1].copy_from_raw_u8(&y4m_u, width*y4m_bytes/2, y4m_bytes);
fs.input.planes[2].copy_from_raw_u8(&y4m_v, width*y4m_bytes/2, y4m_bytes);
// We cannot currently encode > 8 bit input!
match y4m_bits {
8 => {},
10 | 12 => {
for plane in 0..3 {
for row in fs.input.planes[plane].data.chunks_mut(fs.rec.planes[plane].cfg.stride) {
for col in row.iter_mut() { *col >>= y4m_bits-8 }
}
}
},
_ => panic! ("unknown input bit depth!"),
}
let packet = encode_frame(&sequence, &fi, &mut fs, &last_rec);
write_ivf_frame(output_file, fi.number, packet.as_ref());
match y4m_enc {
......
......@@ -57,11 +57,24 @@ impl Plane {
self.data[y*self.cfg.stride + x]
}
pub fn copy_from_raw_u8(&mut self, source: &[u8], source_stride: usize) {
pub fn copy_from_raw_u8(&mut self,
source: &[u8],
source_stride: usize,
source_bytewidth: usize) {
let stride = self.cfg.stride;
for (self_row, source_row) in self.data.chunks_mut(stride).zip(source.chunks(source_stride)) {
for (self_pixel, source_pixel) in self_row.iter_mut().zip(source_row.iter()) {
*self_pixel = *source_pixel as u16;
match source_bytewidth {
1 =>
for (self_pixel, source_pixel) in self_row.iter_mut().zip(source_row.iter()) {
*self_pixel = *source_pixel as u16;
},
2 => {
for (self_pixel, bytes) in self_row.iter_mut().zip(source_row.chunks(2)) {
*self_pixel = (bytes[1] as u16) << 8 | (bytes[0] as u16);
}
},
_ => {}
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment