mod.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. use kahlo::{
  2. Bitmap, BitmapAccess
  3. };
  4. pub fn load_test_resource(name: &'static str) -> Bitmap<kahlo::formats::Rgba32> {
  5. let mut path = std::path::PathBuf::new();
  6. path.push(env!("CARGO_MANIFEST_DIR"));
  7. path.push("test_resources");
  8. path.push(name);
  9. let file_reader =
  10. std::io::BufReader::new(std::fs::File::open(path).expect("couldn't open test resource"));
  11. let img = image::load(file_reader, image::ImageFormat::from_path(name).unwrap())
  12. .expect("couldn't parse test resource")
  13. .into_rgba8();
  14. let (w, h) = (img.width(), img.height());
  15. Bitmap::new_from_vec(img.into_vec(), w as usize, h as usize, w as usize * 4)
  16. }
  17. pub fn save_test_result_rgba32(name: &'static str, bitmap: &impl BitmapAccess<kahlo::formats::Rgba32>) {
  18. let mut path = std::path::PathBuf::new();
  19. path.push(env!("CARGO_TARGET_TMPDIR"));
  20. path.push(name);
  21. assert_eq!(bitmap.row_stride(), bitmap.width() * 4);
  22. image::save_buffer(
  23. path,
  24. bitmap.data(),
  25. bitmap.width() as u32,
  26. bitmap.height() as u32,
  27. image::ExtendedColorType::Rgba8,
  28. )
  29. .expect("couldn't save test result");
  30. }