Files
effectcraft/crates/host/tests/it/tga_import.rs
T
aiongg 0173abde8c CI: dev-profile gate, one test binary per crate, nextest, line tables only (#2235)
* Dev profile: line tables only for workspace crates, no debug info for dependencies

* xtask ci: dev-profile gate, nextest, tests without examples, wasm --keep-going

* One integration-test binary per crate

* xtask ci: run effectcraft-gpu's shared-device tests in one cargo test process

* xtask ci: run every stage and report all failures

* xtask ci: name the stage type (clippy type_complexity)

* xtask ci: run every test pass and report all failures

* cargo fmt
2026-10-23 12:59:51 -04:00

49 lines
2.4 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! Targa import through the same host and commands used by the desktop and CLI.
use effectcraft_engine::render::RenderOpts;
use effectcraft_project::{FootageKind, ItemId, ItemKind};
use effectcraft_time::{FrameRate, Tick};
use serde_json::json;
#[test]
fn tga_stills_and_numbered_sequences_import_and_render() {
let dir = std::env::temp_dir().join(format!("effectcraft-tga-import-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
// A generated 4×4, 24-bit, top-origin TGA. No binary fixtures are retained.
let write = |name: &str, bgr: [u8; 3]| {
let mut bytes = vec![0; 18];
bytes[2] = 2;
bytes[12] = 4;
bytes[14] = 4;
bytes[16] = 24;
bytes[17] = 0x20;
bytes.extend_from_slice(&bgr.repeat(16));
let path = dir.join(name);
std::fs::write(&path, bytes).unwrap();
path.to_string_lossy().to_string()
};
let still = write("still.TGA", [0, 0, 255]);
let first = write("shot_0001.tga", [0, 0, 255]);
write("shot_0002.tga", [255, 0, 0]);
for (path, sequence) in [(still, false), (first, true)] {
let mut session = effectcraft_host::session();
let imported = session.execute_checked("file.import", json!({"paths": [path], "sequence": sequence})).unwrap();
assert_eq!(imported["errors"], json!([]), "{imported}");
assert_eq!(imported["items"].as_array().unwrap().len(), 1);
let item = ItemId(imported["items"][0].as_u64().unwrap());
let ItemKind::Footage(footage) = &session.project.item(item).unwrap().kind else { panic!("not footage") };
assert_eq!(footage.kind, if sequence { FootageKind::Sequence } else { FootageKind::Still });
assert_eq!(footage.sequence.len(), if sequence { 2 } else { 0 });
session.execute_checked("comp.new", json!({"name": "TGA", "width": 4, "height": 4, "frameRate": 30, "duration": 1})).unwrap();
session.execute_checked("layer.addItem", json!({"item": item.0})).unwrap();
let comp = session.active_comp_id().unwrap();
let image = session.render(comp, Tick::ZERO, RenderOpts::default());
assert_eq!(image.get(2, 2), [1.0, 0.0, 0.0, 1.0]);
if sequence {
let image = session.render(comp, FrameRate::FPS_30.tick_of(1), RenderOpts::default());
assert_eq!(image.get(2, 2), [0.0, 0.0, 1.0, 1.0]);
}
}
std::fs::remove_dir_all(dir).unwrap();
}