Import: Interpret Footage ▸ Preserve RGB keeps the file's values (#411)
Cause: float footage (OpenEXR, float TIFF) was always sRGB-encoded on
decode, and Interpret Footage could not turn that off, so an OCIO effect
on the layer converted values that were already encoded.
Fix: After Effects' Interpret Footage ▸ Color ▸ Preserve RGB
(Footage::preserve_rgb; file.interpretFootage {"preserveRgb": true}; a
checkbox in the Interpret Footage form; Remember / Apply Interpretation
carry it). The decoder keeps float values linear, and the working-space
conversion from the colour profile and Interpret As Linear Light don't
apply, so the file's values enter the composition unconverted. The media
cache key includes the flag, so both interpretations decode separately.
Tests: pool::preserve_rgb_reads_float_exr_values_unconverted,
tests_color::preserve_rgb_footage_is_not_converted (managed, linearized
and not), tests_proxy::guess_alpha_invert_and_linear_light (command,
render, Apply Interpretation).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
698ade94ac
commit
d6de68b20d
@@ -17,7 +17,7 @@
|
||||
//! pixels to their parent). Without a working space the sRGB curve is used.
|
||||
|
||||
use effectcraft_color::{ColorSpace, Conversion};
|
||||
use effectcraft_project::{HdrMode, ProjectSettings};
|
||||
use effectcraft_project::{Footage, HdrMode, ProjectSettings};
|
||||
use effectcraft_raster::Image;
|
||||
use rayon::prelude::*;
|
||||
|
||||
@@ -57,10 +57,11 @@ impl Pipe {
|
||||
self.space.unwrap_or(ColorSpace::Srgb)
|
||||
}
|
||||
|
||||
/// Footage with colour profile `profile` (`None` = sRGB) → working space.
|
||||
pub fn media_in(&self, profile: Option<ColorSpace>) -> Option<Conversion> {
|
||||
let ws = self.space?;
|
||||
Conversion::new(profile.unwrap_or(ColorSpace::Srgb), false, ws, self.linear)
|
||||
/// Footage `f` from its colour profile (`None` = sRGB) → working space; nothing for
|
||||
/// Preserve RGB, whose values enter the working space as the file stores them.
|
||||
pub fn media_in(&self, f: &Footage) -> Option<Conversion> {
|
||||
let ws = self.space.filter(|_| !f.preserve_rgb)?;
|
||||
Conversion::new(f.color_profile.unwrap_or(ColorSpace::Srgb), false, ws, self.linear)
|
||||
}
|
||||
|
||||
/// Authored colours (solids, text, shapes) → working space: linearised in a linear working
|
||||
|
||||
@@ -1089,7 +1089,7 @@ impl<'a> Renderer<'a> {
|
||||
let k = self.raster_scale(ctx, layer);
|
||||
if let Some(img) = self.footage.vector_frame(*item, f, k) {
|
||||
let mut buf = Buf { img: (*img).clone(), offset: [0.0; 2], scale: k };
|
||||
if let Some(c) = self.pipe.media_in(f.color_profile) {
|
||||
if let Some(c) = self.pipe.media_in(f) {
|
||||
color::convert(&mut buf.img, &c);
|
||||
}
|
||||
return Some(buf);
|
||||
@@ -1127,7 +1127,7 @@ impl<'a> Renderer<'a> {
|
||||
} else {
|
||||
Buf { img: img.clone(), offset: [0.0; 2], scale: 1.0 / k }
|
||||
};
|
||||
if let Some(c) = self.pipe.media_in(f.color_profile) {
|
||||
if let Some(c) = self.pipe.media_in(f) {
|
||||
color::convert(&mut buf.img, &c);
|
||||
}
|
||||
buf
|
||||
@@ -1156,7 +1156,7 @@ impl<'a> Renderer<'a> {
|
||||
return Some(Arc::new(interpret_pixels(&field_frame(&img, parity), f)));
|
||||
}
|
||||
let img = self.footage_frame_raw(ctx, layer, item, f, t)?;
|
||||
if f.invert_alpha || f.linear_light { Some(Arc::new(interpret_pixels(&img, f))) } else { Some(img) }
|
||||
if f.invert_alpha || f.linear_light_applies() { Some(Arc::new(interpret_pixels(&img, f))) } else { Some(img) }
|
||||
}
|
||||
|
||||
fn footage_frame_raw(&self, ctx: &EvalCtx, layer: &Layer, item: ItemId, f: &Footage, t: Tick) -> Option<Arc<Image>> {
|
||||
@@ -2024,7 +2024,8 @@ pub fn field_frame(img: &Image, parity: usize) -> Image {
|
||||
/// Interpret Footage ▸ Invert Alpha and Interpret As Linear Light on decoded (premultiplied)
|
||||
/// pixels.
|
||||
pub fn interpret_pixels(img: &Image, f: &Footage) -> Image {
|
||||
if !f.invert_alpha && !f.linear_light {
|
||||
let linear = f.linear_light_applies();
|
||||
if !f.invert_alpha && !linear {
|
||||
return img.clone();
|
||||
}
|
||||
let space = f.color_profile.unwrap_or(effectcraft_color::ColorSpace::Srgb);
|
||||
@@ -2032,7 +2033,7 @@ pub fn interpret_pixels(img: &Image, f: &Footage) -> Image {
|
||||
for p in out.data.iter_mut() {
|
||||
let a = p[3];
|
||||
let mut c = if a > 1e-6 { [p[0] / a, p[1] / a, p[2] / a] } else { [0.0; 3] };
|
||||
if f.linear_light {
|
||||
if linear {
|
||||
// The file's values are linear light: encode them like the rest of the footage.
|
||||
c = c.map(|v| space.encode(v));
|
||||
}
|
||||
|
||||
@@ -198,6 +198,34 @@ fn footage_profile_is_converted_into_the_working_space() {
|
||||
assert!((o[0] - 1.0).abs() < 2e-3 && o[1].abs() < 2e-3 && o[2].abs() < 2e-3, "{o:?}");
|
||||
}
|
||||
|
||||
/// #411: Interpret Footage ▸ Preserve RGB: the footage's values enter the composition as the file
|
||||
/// stores them, whatever its colour profile, Interpret As Linear Light or the working space.
|
||||
#[test]
|
||||
fn preserve_rgb_footage_is_not_converted() {
|
||||
let render = |linearize: bool, f: Footage| {
|
||||
let (mut p, cid, comp) = setup(BitDepth::Bpc32);
|
||||
p.settings.working_space = Some(ColorSpace::Rec2020);
|
||||
p.settings.linearize = linearize;
|
||||
let fid = p.add_item("F", Label::Aqua, None, ItemKind::Footage(f));
|
||||
let l = build::layer(&mut p, &comp, "F", LayerSource::Footage { item: fid }, (40, 20), None);
|
||||
p.comp_mut(cid).unwrap().layers.push(l);
|
||||
let src = Flat([0.18, 0.5, 0.75]);
|
||||
let out = Renderer::new(&p, &src, RenderOpts::default()).comp_frame(cid, Tick::ZERO).get(5, 5);
|
||||
// Back from the output conversion (working space → sRGB) to the working space's values.
|
||||
let ws = effectcraft_color::Conversion::new(ColorSpace::Srgb, false, ColorSpace::Rec2020, linearize).unwrap();
|
||||
let c = ws.apply([out[0], out[1], out[2]]);
|
||||
[c[0], c[1], c[2], out[3]]
|
||||
};
|
||||
let preserve = Footage { preserve_rgb: true, linear_light: true, ..footage(Some(ColorSpace::DisplayP3)) };
|
||||
for linearize in [false, true] {
|
||||
let o = render(linearize, preserve.clone());
|
||||
assert!((o[0] - 0.18).abs() < 1e-3 && (o[1] - 0.5).abs() < 1e-3 && (o[2] - 0.75).abs() < 1e-3, "linearize {linearize}: {o:?}");
|
||||
// Without Preserve RGB the profile and linear light convert the values.
|
||||
let o = render(linearize, Footage { preserve_rgb: false, ..preserve.clone() });
|
||||
assert!((o[0] - 0.18).abs() > 0.05, "linearize {linearize}: {o:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layer_cache_is_keyed_by_colour_settings() {
|
||||
let (mut p, cid, _) = setup(BitDepth::Bpc8);
|
||||
|
||||
Reference in New Issue
Block a user