Merge pull request #1709

This commit is contained in:
Brandon Thomas
2026-10-18 09:35:35 -04:00
2 changed files with 16 additions and 2 deletions
+3 -2
View File
@@ -140,9 +140,10 @@ fn srgb_to_linear(c: f32) -> f32 {
if c <= 0.04045 { c / 12.92 } else { ((c + 0.055) / 1.055).powf(2.4) }
}
/// A unique EXR layer name (no dots: they separate the layer from the channel).
/// A unique EXR layer name (no dots: they separate the layer from the channel). Printable ASCII only:
/// the `exr` crate panics on characters it cannot store in a channel name (#1702).
fn exr_name(name: &str, used: &mut Vec<String>) -> String {
let base: String = name.chars().map(|c| if c == '.' || c.is_control() { '_' } else { c }).collect();
let base: String = name.chars().map(|c| if c == '.' || !(c == ' ' || c.is_ascii_graphic()) { '_' } else { c }).collect();
let base = if base.trim().is_empty() { "Layer".to_string() } else { base };
let mut n = base.clone();
let mut k = 2;
+13
View File
@@ -77,6 +77,19 @@ fn proexr_writes_layer_prefixed_channels_and_the_composite() {
assert!(at("R", 16, 16) < 0.5, "multiplied by 50% blue (linear)");
}
#[test]
fn proexr_names_a_non_ascii_layer_with_underscores_instead_of_panicking() {
let mut s = Session::default();
s.execute("comp.new", json!({"name": "Frame", "width": 8, "height": 8, "frameRate": 24, "duration": 1})).unwrap();
s.execute("layer.newSolid", json!({"name": "你好", "color": "#ff0000"})).unwrap();
let dir = out_dir("frame-exr-non-ascii");
let path = dir.join("frame.exr").to_string_lossy().to_string();
let r = s.execute("comp.saveFrameAsExr", json!({"path": path})).unwrap();
let names: Vec<&str> = r["channels"].as_array().unwrap().iter().map(|c| c.as_str().unwrap()).collect();
assert!(names.contains(&"__.R") && names.contains(&"__.A"), "{names:?}");
assert!(std::path::Path::new(&path).exists());
}
/// Save a 32×32 comp holding one opaque solid of `color` (an sRGB-encoded triple) as ProEXR and
/// return the centre pixel of the composite and of the solid's own layer: `[R, G, B]` each.
fn proexr_centre(color: [f64; 3], bit_depth: u64) -> ([f32; 3], [f32; 3]) {