- if let NABufferType::VideoPacked(ref buf) = frm.get_buffer() {
- let (w, h) = buf.get_dimensions(0);
- let hdr = format!("P6\n{} {}\n255\n", w, h);
- ofile.write_all(hdr.as_bytes()).unwrap();
- let dta = buf.get_data();
- let stride = buf.get_stride(0);
- let offs: [usize; 3] = [
- buf.get_info().get_format().get_chromaton(0).unwrap().get_offset() as usize,
- buf.get_info().get_format().get_chromaton(1).unwrap().get_offset() as usize,
- buf.get_info().get_format().get_chromaton(2).unwrap().get_offset() as usize
- ];
- let step = buf.get_info().get_format().get_elem_size() as usize;
- let mut line: Vec<u8> = Vec::with_capacity(w * 3);
- line.resize(w * 3, 0);
- for src in dta.chunks(stride) {
- for x in 0..w {
- line[x * 3 + 0] = src[x * step + offs[0]];
- line[x * 3 + 1] = src[x * step + offs[1]];
- line[x * 3 + 2] = src[x * step + offs[2]];
- }
- ofile.write_all(line.as_slice()).unwrap();
- }
- } else if let NABufferType::Video16(ref buf) = frm.get_buffer() {
+ let info = frm.get_buffer().get_video_info().unwrap();
+ let mut dpic = alloc_video_buffer(NAVideoInfo::new(info.get_width(), info.get_height(), false, RGB24_FORMAT), 0).unwrap();
+ let ifmt = ScaleInfo { width: info.get_width(), height: info.get_height(), fmt: info.get_format() };
+ let ofmt = ScaleInfo { width: info.get_width(), height: info.get_height(), fmt: RGB24_FORMAT };
+ let mut scaler = NAScale::new(ifmt, ofmt).unwrap();
+ scaler.convert(&frm.get_buffer(), &mut dpic).unwrap();
+ let buf = dpic.get_vbuf().unwrap();