mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:42:27 +00:00
cms: expose fixed v2 sRGB profile and verify shared parsing
This commit is contained in:
1 parent
f483f9d6dd
commit
7bc5f2a4c8
3 files changed
+29
-1
No files matched your search
@@ -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<u8> {
|
||||
crate::builtin_v2::srgb()
|
||||
}
|
||||
@@ -44,7 +44,7 @@ fn curve() -> Vec<u8> {
|
||||
t
|
||||
}
|
||||
|
||||
/// The profile's bytes.
|
||||
/// Fixed-size profile bytes; all tag sizes and loop counts are constants.
|
||||
pub fn srgb() -> Vec<u8> {
|
||||
// sRGB primaries, Bradford-adapted to the D50 profile connection space.
|
||||
let tags: Vec<(&[u8; 4], Vec<u8>)> = vec![
|
||||
@@ -110,6 +110,21 @@ pub fn srgb() -> Vec<u8> {
|
||||
|
||||
#[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();
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
pub mod builtin;
|
||||
mod builtin_v2;
|
||||
pub mod clut;
|
||||
pub mod curve;
|
||||
pub mod gamut;
|
||||
|
||||
Reference in new issue
Block a user