mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-27 16:49:22 +01:00
Merge the import-warnings PR's base
This commit is contained in:
commit
4aec5f16fc
2 files changed
+27
-4
No files matched your search
@@ -96,6 +96,25 @@ fn imported_files_go_into_the_comp_where_they_were_dropped() {
|
||||
assert!(s.execute("layer.addItem", json!({"item": "a.png", "position": [1.0]})).is_err(), "position needs x and y");
|
||||
}
|
||||
|
||||
/// What an import left out of a file (a 3D model's textures over the limits) comes back in the
|
||||
/// import's `warnings`.
|
||||
#[test]
|
||||
fn what_an_import_left_out_is_a_warning() {
|
||||
use effectcraft_project::{Footage, FootageKind};
|
||||
struct Probe;
|
||||
impl crate::Importer for Probe {
|
||||
fn probe(&self, path: &str) -> Result<Footage, String> {
|
||||
Ok(Footage { path: path.into(), kind: FootageKind::Model, ..Default::default() })
|
||||
}
|
||||
fn probe_noting(&self, path: &str) -> Result<(Footage, Option<String>), String> {
|
||||
Ok((self.probe(path)?, Some(format!("{path}: texture `a.png` left out"))))
|
||||
}
|
||||
}
|
||||
let mut s = Session { importer: Some(std::sync::Arc::new(Probe)), ..Default::default() };
|
||||
let r = s.execute("file.import", json!({"paths": ["/m/scene.obj"]})).unwrap();
|
||||
assert_eq!(r["warnings"], json!(["/m/scene.obj: texture `a.png` left out"]));
|
||||
}
|
||||
|
||||
/// #270: files dropped or picked in the Import dialog (`file.import {background}`) are probed in
|
||||
/// a background job that says which file it is reading and how many are left; then they arrive
|
||||
/// in one undo step, all selected, with a count. The same file imported again arrives again.
|
||||
|
||||
@@ -74,16 +74,20 @@ impl Texture {
|
||||
pub fn solid(c: [f32; 4]) -> Texture {
|
||||
Texture { width: 1, height: 1, data: vec![c], wrap: [Wrap::Repeat; 2] }
|
||||
}
|
||||
/// Decode a PNG or JPEG of at most [`MAX_TEXTURE_PIXELS`].
|
||||
/// The pixel size an image claims, read from its header without decoding it.
|
||||
pub fn dimensions(bytes: &[u8]) -> Result<(u32, u32)> {
|
||||
let reader = image::ImageReader::new(std::io::Cursor::new(bytes)).with_guessed_format().map_err(|e| perr(format!("image: {e}")))?;
|
||||
reader.into_dimensions().map_err(|e| perr(format!("image: {e}")))
|
||||
}
|
||||
/// Decode a PNG or JPEG.
|
||||
pub fn decode(bytes: &[u8]) -> Result<Texture> {
|
||||
Self::decode_within(bytes, &mut MAX_IMPORT_TEXTURE_PIXELS.clone())
|
||||
}
|
||||
/// [`decode`](Self::decode) taking the pixels from `pixels_left`, an import's remaining
|
||||
/// [`decode`](Self::decode), of at most [`MAX_TEXTURE_PIXELS`], taking the pixels from `pixels_left`, an import's remaining
|
||||
/// texture budget, before the image is decoded.
|
||||
pub fn decode_within(bytes: &[u8], pixels_left: &mut u64) -> Result<Texture> {
|
||||
let err = |e: image::ImageError| perr(format!("image: {e}"));
|
||||
let reader = image::ImageReader::new(std::io::Cursor::new(bytes)).with_guessed_format().map_err(|e| perr(format!("image: {e}")))?;
|
||||
let (w, h) = reader.into_dimensions().map_err(err)?;
|
||||
let (w, h) = Self::dimensions(bytes)?;
|
||||
let pixels = w as u64 * h as u64;
|
||||
if pixels > MAX_TEXTURE_PIXELS {
|
||||
return Err(ModelError::Unsupported(format!("a {w}×{h} texture (at most {MAX_TEXTURE_PIXELS} pixels)")));
|
||||
|
||||
Reference in new issue
Block a user