mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-16 15:22:43 +00:00
Merge remote-tracking branch 'upstream/main' into onee/i786-psd-writer-craft-psd
This commit is contained in:
commit
5d5be53bef
4 files changed
+13
-38
No files matched your search
Generated
+1
-1
@@ -1131,7 +1131,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-cms"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=9fd926dc93be7d4723e6eb4f484c7233d91d3e94#9fd926dc93be7d4723e6eb4f484c7233d91d3e94"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=58964adec11197594d9b6b79a94ae6232221211a#58964adec11197594d9b6b79a94ae6232221211a"
|
||||
dependencies = [
|
||||
"md-5",
|
||||
"rayon",
|
||||
|
||||
@@ -10,7 +10,7 @@ rust-version.workspace = true
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
craft-cms = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "9fd926dc93be7d4723e6eb4f484c7233d91d3e94" }
|
||||
craft-cms = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "58964adec11197594d9b6b79a94ae6232221211a" }
|
||||
effectcraft-geom = { workspace = true }
|
||||
effectcraft-color = { workspace = true }
|
||||
effectcraft-keyframe = { workspace = true }
|
||||
|
||||
@@ -18,18 +18,8 @@ pub enum FileXform {
|
||||
/// Parse a Sony Imageworks `.spimtx` matrix: three rows of four numbers, three matrix columns
|
||||
/// and an offset in 16-bit code values (÷ 65535).
|
||||
pub fn parse_spimtx(text: &str) -> Option<FileXform> {
|
||||
let v: Vec<f64> = text.split_whitespace().map(|t| t.parse().ok()).collect::<Option<_>>()?;
|
||||
if v.len() != 12 || v.iter().any(|x| !x.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
let mut m = [0.0; 16];
|
||||
let mut offset = [0.0; 4];
|
||||
for (r, row) in v.as_chunks::<4>().0.iter().enumerate() {
|
||||
m[r * 4..r * 4 + 3].copy_from_slice(&row[..3]);
|
||||
offset[r] = row[3] / 65535.0;
|
||||
}
|
||||
m[15] = 1.0;
|
||||
Some(FileXform::Matrix { m, offset })
|
||||
let value = craft_cms::sony_lut::parse_spimtx(text)?;
|
||||
Some(FileXform::Matrix { m: value.matrix, offset: value.offset })
|
||||
}
|
||||
|
||||
/// Parse a Sony Imageworks `.spi1d` 1D LUT: `From <min> <max>`, `Length <n>`, `Components
|
||||
@@ -42,30 +32,8 @@ pub fn parse_spi1d(text: &str) -> Option<Lut> {
|
||||
/// Parse a Sony Imageworks `.spi3d` lattice: `SPILUT 1.0`, `3 3`, the sizes, then one
|
||||
/// `r g b R G B` line per lattice point (indices, then the colour).
|
||||
pub fn parse_spi3d(text: &str) -> Option<Lut> {
|
||||
let mut lines = text.lines().map(str::trim).filter(|l| !l.is_empty());
|
||||
if !lines.next()?.starts_with("SPILUT") {
|
||||
return None;
|
||||
}
|
||||
lines.next()?;
|
||||
let size: Vec<usize> = lines.next()?.split_whitespace().map(|t| t.parse().ok()).collect::<Option<_>>()?;
|
||||
let n = *size.first()?;
|
||||
if size.len() != 3 || size.iter().any(|s| *s != n) || !(2..=MAX_LATTICE).contains(&n) {
|
||||
return None;
|
||||
}
|
||||
let mut d3 = vec![[0.0f32; 3]; n * n * n];
|
||||
let mut seen = 0usize;
|
||||
for line in lines {
|
||||
let v: Vec<&str> = line.split_whitespace().collect();
|
||||
let [r, g, b, cr, cg, cb] = v.as_slice() else { return None };
|
||||
let (r, g, b): (usize, usize, usize) = (r.parse().ok()?, g.parse().ok()?, b.parse().ok()?);
|
||||
if r >= n || g >= n || b >= n {
|
||||
return None;
|
||||
}
|
||||
// Our lattice is red fastest.
|
||||
*d3.get_mut(r + g * n + b * n * n)? = [cr.parse().ok()?, cg.parse().ok()?, cb.parse().ok()?];
|
||||
seen += 1;
|
||||
}
|
||||
(seen == n * n * n).then_some(Lut { n1: 0, d1: vec![], n3: n, d3, dmin: [0.0; 3], dmax: [1.0; 3] })
|
||||
let value = craft_cms::sony_lut::parse_spi3d(text)?;
|
||||
Some(Lut { n1: 0, d1: vec![], n3: value.size, d3: value.values, dmin: [0.0; 3], dmax: [1.0; 3] })
|
||||
}
|
||||
|
||||
/// Parse an Autodesk `.3dl` lattice (integers, blue fastest; an optional input-mesh line).
|
||||
|
||||
@@ -127,6 +127,13 @@ fn spi_files_parse() {
|
||||
for (r, g, b) in (0..8).map(|i| (i & 1, (i >> 1) & 1, i >> 2)) {
|
||||
spi3d += &format!("{r} {g} {b} {} {} {}\n", r as f32 * 0.5, g, b);
|
||||
}
|
||||
let lattice = parse_spi3d(&spi3d).unwrap();
|
||||
assert_eq!(lattice.n1, 0);
|
||||
assert!(lattice.d1.is_empty());
|
||||
assert_eq!(lattice.n3, 2);
|
||||
assert_eq!(lattice.dmin, [0.0; 3]);
|
||||
assert_eq!(lattice.dmax, [1.0; 3]);
|
||||
assert!(parse_spimtx("1 0 0 0 0 1 0 0 0 0 1 0 extra").is_none());
|
||||
let x = parse_file(&spi3d, "spi3d").unwrap();
|
||||
let o = x.apply([1.0, 0.5, 0.25], 1, false, "");
|
||||
assert!((o[0] - 0.5).abs() < 1e-6 && (o[1] - 0.5).abs() < 1e-6 && (o[2] - 0.25).abs() < 1e-6, "{o:?}");
|
||||
|
||||
Reference in new issue
Block a user