The embedded ICC profile

The ICC profile the library embeds in a PDF/A file.

Rust write_icc.rs 28 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//! Writes the ICC profile the library embeds in a PDF/A file.
//!
//! Our own tests can only say the bytes look right to us. Whether they are an
//! ICC profile — and whether that profile is really sRGB rather than something
//! wearing its name — is a question for a colour engine, which is what
//! `scripts/check_icc_profile.py` uses this for.
//!
//! Usage: `cargo run --example write_icc -- tmp/srgb.icc`

use std::env;
use std::fs;
use std::path::Path;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let out = env::args()
        .nth(1)
        .unwrap_or_else(|| "tmp/srgb.icc".to_owned());

    let profile = hqf_pdf::color::icc::srgb();

    if let Some(parent) = Path::new(&out).parent() {
        fs::create_dir_all(parent)?;
    }
    fs::write(&out, &profile)?;

    println!("wrote {out}: {} bytes", profile.len());
    Ok(())
}