mod.rs 1.1 KB

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