1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] include!("ffi.rs"); #[cfg(test)] mod tests { use super::*; use std::io::prelude::*; use std::fs::File; use std::slice; #[test] fn test_webp() { let mut width = 0; let mut height = 0; let mut buf = Vec::new(); let len = File::open("./tests/test1.webp").unwrap().read_to_end(&mut buf).unwrap(); unsafe { WebPGetInfo(buf.as_ptr(), len, &mut width, &mut height); } assert!(width == 1000); assert!(height == 1000); } #[test] fn test_webp_encode_lossless() { let mut buf = Vec::new(); let len = File::open("./tests/test1_1000x1000.bif").unwrap().read_to_end(&mut buf).unwrap(); let mut out_buf = Box::into_raw(Box::new(0u8)) as *mut _; unsafe { let l = WebPEncodeLosslessRGBA(buf.as_ptr(), 1000, 1000, 1000 * 4, &mut out_buf as *mut _); let mut file = File::create("./tests/test1.webp").unwrap(); let out = slice::from_raw_parts(out_buf, l); file.write_all(out).unwrap(); } assert!(4000000 == len); } #[test] fn test_webp_encode() { println!("{:?}", env!("OUT_DIR")); let mut buf = Vec::new(); let len = File::open("./tests/test1_1000x1000.bif").unwrap().read_to_end(&mut buf).unwrap(); let mut out_buf = Box::into_raw(Box::new(0u8)) as *mut _; unsafe { let l = WebPEncodeRGBA(buf.as_ptr(), 1000, 1000, 1000 * 4, 90 as f32, &mut out_buf as *mut _); println!("{:?}", l); let mut file = File::create("./tests/test1_q90.webp").unwrap(); let out = slice::from_raw_parts(out_buf, l); println!("{:?}", out.len()); file.write_all(out).unwrap(); } assert!(4000000 == len); } }