1 extern crate nihav_core;
3 use nihav_core::frame::*;
4 use std::io::prelude::*;
8 pub fn write_pgmyuv(pfx: &str, strno: usize, num: u64, frm: Ref<NAFrame>) {
9 if let NABufferType::None = frm.get_buffer() { return; }
10 let name = format!("{}out{:02}_{:08}.pgm", pfx, strno, num);
11 let mut ofile = File::create(name).unwrap();
12 let buf = frm.get_buffer().get_vbuf().unwrap();
13 let (w, h) = buf.get_dimensions(0);
14 let (w2, h2) = buf.get_dimensions(1);
16 let hdr = format!("P5\n{} {}\n255\n", w, tot_h);
17 ofile.write_all(hdr.as_bytes()).unwrap();
18 let dta = buf.get_data();
19 let ls = buf.get_stride(0);
22 let mut pad: Vec<u8> = Vec::with_capacity((w - w2 * 2) / 2);
23 pad.resize((w - w2 * 2) / 2, 0xFF);
25 let line = &dta[idx..idx2];
26 ofile.write_all(line).unwrap();
30 let mut base1 = buf.get_offset(1);
31 let stride1 = buf.get_stride(1);
32 let mut base2 = buf.get_offset(2);
33 let stride2 = buf.get_stride(2);
35 let bend1 = base1 + w2;
36 let line = &dta[base1..bend1];
37 ofile.write_all(line).unwrap();
38 ofile.write_all(pad.as_slice()).unwrap();
40 let bend2 = base2 + w2;
41 let line = &dta[base2..bend2];
42 ofile.write_all(line).unwrap();
43 ofile.write_all(pad.as_slice()).unwrap();
50 pub fn write_palppm(pfx: &str, strno: usize, num: u64, frm: Ref<NAFrame>) {
51 let name = format!("{}out{:02}_{:08}.ppm", pfx, strno, num);
52 let mut ofile = File::create(name).unwrap();
53 let buf = frm.get_buffer().get_vbuf().unwrap();
54 let (w, h) = buf.get_dimensions(0);
55 let paloff = buf.get_offset(1);
56 let hdr = format!("P6\n{} {}\n255\n", w, h);
57 ofile.write_all(hdr.as_bytes()).unwrap();
58 let dta = buf.get_data();
59 let ls = buf.get_stride(0);
61 let mut line: Vec<u8> = Vec::with_capacity(w * 3);
62 line.resize(w * 3, 0);
64 let src = &dta[idx..(idx+w)];
66 let pix = src[x] as usize;
67 line[x * 3 + 0] = dta[paloff + pix * 3 + 2];
68 line[x * 3 + 1] = dta[paloff + pix * 3 + 1];
69 line[x * 3 + 2] = dta[paloff + pix * 3 + 0];
71 ofile.write_all(line.as_slice()).unwrap();