diff --git a/crates/cms/src/builtin.rs b/crates/cms/src/builtin.rs index ca7034286..e62faa907 100644 --- a/crates/cms/src/builtin.rs +++ b/crates/cms/src/builtin.rs @@ -450,3 +450,15 @@ mod tests { assert!(cicp_rgb(u16::MAX, u16::MAX, true).is_none()); } } + +/// Generates the compact ICC v2.1 sRGB matrix/TRC profile used by PDFCraft. +/// +/// Unlike [`Builtin::Srgb`]'s v4 profile, this uses a 1024-sample tone curve and +/// v2 `desc`/`text` tags for consumers that require a v2 output intent. The legacy +/// description `sRGB (PdfCraft)` is retained to preserve existing document bytes. +/// The generated profile contains no external assets; callers choose where it is +/// appropriate (including their own PDF/A conformance policy). +/// All sizes are fixed; no input-controlled allocation or recursion is involved. +pub fn srgb_v2() -> Vec { + crate::builtin_v2::srgb() +} diff --git a/crates/cms/src/builtin_v2.rs b/crates/cms/src/builtin_v2.rs index 935dd105c..4a9e2e25b 100644 --- a/crates/cms/src/builtin_v2.rs +++ b/crates/cms/src/builtin_v2.rs @@ -44,7 +44,7 @@ fn curve() -> Vec { t } -/// The profile's bytes. +/// Fixed-size profile bytes; all tag sizes and loop counts are constants. pub fn srgb() -> Vec { // sRGB primaries, Bradford-adapted to the D50 profile connection space. let tags: Vec<(&[u8; 4], Vec)> = vec![ @@ -110,6 +110,21 @@ pub fn srgb() -> Vec { #[cfg(test)] mod tests { + #[test] + fn parses_as_v2_with_shared_rgb_curves() { + let bytes = super::srgb(); + let p = crate::Profile::parse(&bytes).unwrap(); + assert_eq!(p.version, (2, 0x10)); + assert_eq!(p.color_space, crate::ColorSpace::Rgb); + assert_eq!(p.pcs, crate::Pcs::Xyz); + assert_eq!(p.description, "sRGB (PdfCraft)"); + let curves = p.trc.unwrap(); + assert_eq!(curves[0], curves[1]); + assert_eq!(curves[1], curves[2]); + assert!(matches!(&curves[0], crate::Curve::Table(v) if v.len() == 1024 && v[0] == 0.0 && v[1023] == 1.0)); + assert_eq!(bytes, super::srgb()); + } + #[test] fn profile_is_well_formed() { let p = super::srgb(); diff --git a/crates/cms/src/lib.rs b/crates/cms/src/lib.rs index 8d4f99f49..5e8a1e268 100644 --- a/crates/cms/src/lib.rs +++ b/crates/cms/src/lib.rs @@ -20,6 +20,7 @@ #![forbid(unsafe_code)] pub mod builtin; +mod builtin_v2; pub mod clut; pub mod curve; pub mod gamut;