View: Proof Setup › Customize… opens a dialog for the device to simulate

View › Proof Setup › Customize… opened the Separations Preview panel.
It now opens a Proof Setup dialog: Device to Simulate (the working CMYK
space or any CMYK or RGB profile), Preserve CMYK Numbers or Preserve RGB
Numbers, Rendering intent (off while the numbers are preserved),
Simulate Paper Color, Simulate Black Ink and Preview. OK sets the proof
setup and turns Proof Colors on; Cancel puts the earlier proof back.

view.proofSetup takes an "rgb:<profile>" target, preserveNumbers and
simulateBlack, and its reply carries both. Simulate Black Ink shows the
device's black without black-point compensation. With Preserve Numbers
the renderer proofs each color from its own numbers as it paints it,
placed CMYK images from their own inks, and the inks a CMYK document
blends; the paper under the art takes Simulate Paper Color's tint.
This commit is contained in:
dotCooCoo
2026-11-14 13:29:29 -08:00
parent 67f6d3a50f
commit 06bf6397c7
49 changed files with 1007 additions and 39 deletions
+27
View File
@@ -321,6 +321,33 @@ mod tests {
}
}
/// A proof that preserves the colors' numbers proofs an art brush's own colors, as it proofs
/// the document's: the brush's blue shows as the simulated device shows that color's numbers.
#[test]
fn a_proof_that_preserves_numbers_proofs_brush_art() {
use vectorcraft_brush::{ArtBrush, ArtScale, Brush, BrushKind, Colorization};
use vectorcraft_color::cms;
let mut d = doc_with_line(Some("Blue art"), 1.0);
let blue = Color::rgb(0.0, 0.0, 1.0);
let art =
Node::path(d.alloc_id(), shapes::rectangle(Rect::new(0.0, -10.0, 10.0, 10.0)), Appearance::basic(Paint::solid(blue), Paint::None, 0.0));
let brush = Brush {
name: "Blue art".into(),
kind: BrushKind::Art(ArtBrush { art, scale: ArtScale::Stretch, colorization: Colorization::None, ..Default::default() }),
};
vectorcraft_brush::store(&mut d, &[brush]);
let proof = cms::ProofSetup { target: cms::ProofTarget::Cmyk(cms::DEVICE_CMYK.into()), preserve_numbers: true, ..Default::default() };
let want = cms::active().proof_color(&blue, &proof).map(|v| (v * 255.0).round() as i32);
let opts = RenderOptions { proof: Some(proof), background: Some([255, 255, 255, 255]), ..Default::default() };
let mut r = Renderer::new();
for _ in 0..2 {
let px = r.render(&d, 200, 100, Affine::IDENTITY, &opts).pixel(100, 50);
assert!(want != [0, 0, 255], "{want:?}");
assert!(px.iter().zip(want).all(|(p, w)| (i32::from(*p) - w).abs() <= 2), "{px:?} vs {want:?}");
}
}
/// Object opacity fades a brushed stroke's art as a whole, with or without a dash and a fill:
/// the same as the object at full opacity inside a group at that opacity.
#[test]
+118 -8
View File
@@ -12,6 +12,9 @@
//! colours; RGB colours and placed images are separated into the working CMYK space first.
//!
//! RGB documents, and CMYK documents without transparency, draw screen colours ([`Ink::Display`]).
//! A proof that preserves the colors' numbers draws each screen colour as the proof shows it
//! ([`Ink::Proofed`]); a CMYK document that blends in CMYK keeps its ink planes, and [`compose`]
//! shows their inks through the proof.
use std::cell::RefCell;
use std::collections::HashMap;
@@ -44,6 +47,10 @@ pub(crate) enum Ink {
RichBlack,
/// Source-color adjustment before the display/ink conversion. Float bits keep cache keys exact.
Darkened(InkSpace, u32, bool),
/// Screen colours as a proof that preserves the colors' numbers shows them
/// ([`crate::proof::preserves`], [`Cms::proof_color`]): the proof [`proofed_ink`] registered
/// under this number, so the caches keep what each proof draws apart.
Proofed(u32),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@@ -52,6 +59,68 @@ pub(crate) enum InkSpace {
Cmy,
K,
RichBlack,
Proofed(u32),
}
/// What [`Ink::Proofed`] paints with: its number, the color settings and the proof setup.
type Proof = (u32, Arc<Cms>, vectorcraft_color::cms::ProofSetup, u64);
/// The proofs [`proofed_ink`] registered last, the newest last: a few, for renderers drawing with
/// different ones.
static PROOFS: Mutex<Vec<Arc<Proof>>> = Mutex::new(Vec::new());
/// The last number [`proofed_ink`] gave out.
static PROOF_NUMBER: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
thread_local! {
/// The proof [`Ink::rgb`] used last on this thread, so a frame does not look it up for each
/// color it paints.
static LAST_PROOF: RefCell<Option<Arc<Proof>>> = const { RefCell::new(None) };
}
/// Keeps the proof [`proofed_ink`] registered for a frame while the frame is drawn: a proof that
/// something holds stays registered.
pub(crate) struct ProofHold(#[allow(dead_code)] Arc<Proof>);
/// The ink a frame drawn with a proof that preserves the colors' numbers paints screen colours
/// with: the same [`Ink::Proofed`] number for the same proof setup, active color settings and
/// loaded profiles ([`cms::profiles_generation`]), and a new one when any of them changes. The
/// proof stays registered while the hold returned with it is kept.
pub(crate) fn proofed_ink(proof: &vectorcraft_color::cms::ProofSetup) -> (Ink, ProofHold) {
let (c, profiles) = (cms::active(), cms::profiles_generation());
let mut proofs = PROOFS.lock().unwrap_or_else(|e| e.into_inner());
if let Some(p) = proofs.iter().find(|p| Arc::ptr_eq(&p.1, &c) && p.2 == *proof && p.3 == profiles) {
return (Ink::Proofed(p.0), ProofHold(p.clone()));
}
let number = PROOF_NUMBER.fetch_add(1, Ordering::Relaxed).wrapping_add(1);
// Past a few, the oldest proof nothing holds (no frame, no thread's last proof) goes.
if proofs.len() >= 8
&& let Some(i) = proofs.iter().position(|p| Arc::strong_count(p) == 1)
{
proofs.remove(i);
}
let p = Arc::new((number, c, proof.clone(), profiles));
proofs.push(p.clone());
(Ink::Proofed(number), ProofHold(p))
}
/// The proof setup `ink` proofs with ([`Ink::Proofed`], darkened or not), while it is registered.
pub(crate) fn proof_of(ink: Ink) -> Option<vectorcraft_color::cms::ProofSetup> {
let Ink::Proofed(number) = ink.base() else { return None };
PROOFS.lock().unwrap_or_else(|e| e.into_inner()).iter().find(|p| p.0 == number).map(|p| p.2.clone())
}
/// Display sRGB of `c` as the proof [`proofed_ink`] registered under `number` shows it; a proof
/// no longer registered shows the colour as it is.
fn proofed_rgb(number: u32, c: &Color) -> [f32; 3] {
let proof = LAST_PROOF.with(|l| l.borrow().clone().filter(|p| p.0 == number)).or_else(|| {
let p = PROOFS.lock().unwrap_or_else(|e| e.into_inner()).iter().find(|p| p.0 == number).cloned();
LAST_PROOF.with(|l| l.borrow_mut().clone_from(&p));
p
});
match proof {
Some(p) => p.1.proof_color(c, &p.2),
None => c.to_rgb(),
}
}
impl Ink {
@@ -61,6 +130,7 @@ impl Ink {
Self::Darkened(InkSpace::Cmy, _, _) => Self::Cmy,
Self::Darkened(InkSpace::K, _, _) => Self::K,
Self::Darkened(InkSpace::RichBlack, _, _) => Self::RichBlack,
Self::Darkened(InkSpace::Proofed(n), _, _) => Self::Proofed(n),
other => other,
}
}
@@ -74,6 +144,11 @@ impl Ink {
}
}
/// Whether this ink adjusts the source colors first ([`Ink::Darkened`]).
pub(crate) fn is_darkened(self) -> bool {
matches!(self, Self::Darkened(..))
}
fn darkness(self) -> Option<f32> {
match self {
Self::Darkened(_, bits, _) => Some(f32::from_bits(bits)),
@@ -96,6 +171,7 @@ impl Ink {
Self::Cmy => InkSpace::Cmy,
Self::K => InkSpace::K,
Self::RichBlack => InkSpace::RichBlack,
Self::Proofed(n) => InkSpace::Proofed(n),
_ => InkSpace::Display,
};
Self::Darkened(space, amount.to_bits(), black)
@@ -151,6 +227,7 @@ impl Ink {
match (self, *c) {
(Ink::RichBlack, Color::Cmyk { c, m, y, k }) if is_pure_black([c, m, y, k]) => [0.0; 3],
(Ink::Display | Ink::RichBlack, _) => c.to_rgb(),
(Ink::Proofed(n), _) => proofed_rgb(n, c),
_ => self.plane(inks(c)),
}
}
@@ -178,7 +255,7 @@ impl Ink {
pub(crate) fn fixed8(self, [r, g, b, a]: [u8; 4]) -> [u8; 4] {
match self.base() {
Ink::Display | Ink::RichBlack => [r, g, b, a],
Ink::Display | Ink::RichBlack | Ink::Proofed(_) => [r, g, b, a],
_ => {
let lab = lab::srgb_to_lab([r, g, b].map(|v| v as f32 / 255.0));
let [r, g, b] = self.plane(inks(&Color::Lab { l: lab.l, a: lab.a, b: lab.b })).map(q);
@@ -319,6 +396,32 @@ fn cached<T>(slot: &Cached<T>, build: impl FnOnce(&Cms) -> T) -> (Arc<T>, u64) {
(t, g)
}
/// A table [`proofed_lut`] made, with the color settings, proof setup and profiles generation it
/// was made for.
type ProofedLut = (Arc<Cms>, vectorcraft_color::cms::ProofSetup, u64, Arc<InkLut>);
/// The tables [`proofed_lut`] made last, the newest last.
static PROOFED: Mutex<Vec<ProofedLut>> = Mutex::new(Vec::new());
/// Ink amounts → their display sRGB as `proof` shows a CMYK color of those inks
/// ([`Cms::proof_color`]), for the active color settings and loaded profiles. Cached.
fn proofed_lut(proof: &vectorcraft_color::cms::ProofSetup) -> Arc<InkLut> {
let (c, profiles) = (cms::active(), cms::profiles_generation());
let mut kept = PROOFED.lock().unwrap_or_else(|e| e.into_inner());
if let Some((.., t)) = kept.iter().find(|(o, p, g, _)| Arc::ptr_eq(o, &c) && p == proof && *g == profiles) {
return t.clone();
}
let t = Arc::new(InkLut(CmykLut::build(|[cy, m, y, k]| {
let [px, py, pz] = lab::srgb_to_xyz(c.proof_color(&Color::Cmyk { c: cy, m, y, k }, proof));
[px, py, pz, 0.0]
})));
if kept.len() >= KEPT_TABLES {
kept.remove(0);
}
kept.push((c, proof.clone(), profiles, t.clone()));
t
}
/// [`compose`] puts at least this many pixels in each band but the last.
const BAND_PIXELS: usize = 1 << 16;
@@ -331,12 +434,19 @@ const BAND_PIXELS: usize = 1 << 16;
/// each other band (this thread does when that one can't start). Returns the picture and the number
/// of threads that composed it.
pub(crate) fn compose(cmy: &[u8], k: &[u8], opts: &RenderOptions, threads: u16) -> (Vec<u8>, usize) {
let (lut, _) = cached(&DISPLAY, InkLut::build);
let bg = opts.background.map(|b| (Ink::Cmy.fixed8(b), Ink::K.fixed8(b), b));
// With a proof that preserves the numbers, the inks show as the proof's device shows them,
// and the background as it shows white paper.
let lut = match crate::proof::preserving(opts) {
Some(p) => proofed_lut(p),
None => cached(&DISPLAY, InkLut::build).0,
};
let bg = opts.background.map(|b| (Ink::Cmy.fixed8(b), Ink::K.fixed8(b), crate::proof::under_art(opts, b)));
let mut out = vec![0; cmy.len().min(k.len()) / 4 * 4];
let pixels = out.len() / 4;
let bands = (pixels / BAND_PIXELS).clamp(1, usize::from(threads).max(1));
let band = |o: &mut [u8], p: &[u8], q: &[u8]| compose_band(o, p, q, &lut, bg, opts.rich_black);
// A proof shows its device's black, not Appearance of Black's rich black.
let rich_black = opts.rich_black && crate::proof::preserving(opts).is_none();
let band = |o: &mut [u8], p: &[u8], q: &[u8]| compose_band(o, p, q, &lut, bg, rich_black);
if bands == 1 {
band(&mut out, cmy, k);
return (out, 1);
@@ -469,9 +579,9 @@ fn plane_key(key: &ImageKey, plane: Ink, generation: u64) -> ImageKey {
/// The key [`ink_image`] gives image pixels `key` painted with `ink`.
pub(crate) fn ink_key(key: &ImageKey, ink: Ink) -> ImageKey {
if ink.darkness().is_some() {
let generation = if matches!(ink.base(), Ink::Display | Ink::RichBlack) { 0 } else { separation().1 };
let generation = if matches!(ink.base(), Ink::Display | Ink::RichBlack | Ink::Proofed(_)) { 0 } else { separation().1 };
plane_key(key, ink, generation)
} else if matches!(ink, Ink::Display | Ink::RichBlack) {
} else if matches!(ink, Ink::Display | Ink::RichBlack | Ink::Proofed(_)) {
key.clone()
} else {
plane_key(key, ink, separation().1)
@@ -489,7 +599,7 @@ fn darkened_image(key: &ImageKey, pm: &Arc<Pixmap>, ink: Ink, amount: f32, blob:
return (want, p);
}
let base = ink.base();
let display = matches!(base, Ink::Display | Ink::RichBlack);
let display = matches!(base, Ink::Display | Ink::RichBlack | Ink::Proofed(_));
let raw_cmyk = key_inks(key, blob).filter(|i| (i.width, i.height) == (u32::from(pm.width()), u32::from(pm.height())));
let sep = (!display).then(separation);
let shown = (display && raw_cmyk.is_some()).then(display_lut);
@@ -527,7 +637,7 @@ pub(crate) fn ink_image(key: &ImageKey, pm: &Arc<Pixmap>, ink: Ink, blob: Option
if let Some(amount) = ink.darkness() {
return darkened_image(key, pm, ink, amount, blob, touch);
}
if matches!(ink, Ink::Display | Ink::RichBlack) {
if matches!(ink, Ink::Display | Ink::RichBlack | Ink::Proofed(_)) {
return (key.clone(), pm.clone());
}
let (luts, generation) = separation();
+4 -1
View File
@@ -191,6 +191,9 @@ fn rasterize(
let symbols = doc.symbol_boxes().quick();
r.stamp += 1;
let px_rect = Rect::new(0.0, 0.0, w as f64, h as f64);
// A tile drawn for a proof that preserves the colors' numbers shows its images through that
// proof too.
let plates = crate::proof::ink_plate_lut(ink, doc);
for o in def.offsets_covering(region) {
let v = view * def.instance_xf(o);
let frame = Frame {
@@ -203,7 +206,7 @@ fn rasterize(
opts: &opts,
ink,
output: v,
plates: None,
plates: plates.as_deref(),
};
for a in &def.art {
r.draw_arc(&mut ctx, &frame, a);
+67 -9
View File
@@ -2,6 +2,9 @@
//!
//! * **Proof Colors** post-processes the rendered frame: every pixel goes display sRGB → proof
//! space (CMYK press or RGB/colour-blindness simulation) → display, through a cached 17³ LUT.
//! With Preserve CMYK or RGB Numbers ([`preserves`]) each color is proofed from its own numbers
//! as it is painted instead ([`crate::ink::Ink::Proofed`]), and placed images from their own
//! inks or pixels ([`plate_image`]).
//! * **Separations Preview** recolours the *document* before rendering: each paint colour is split
//! into process inks (colour-managed), or a spot ink at the colour's tint when it's linked to a
//! spot swatch (solid colours and gradient stops alike), with the process plates a gradient stop
@@ -45,6 +48,21 @@ pub(crate) fn overprints(opts: &RenderOptions) -> bool {
opts.overprint_preview || opts.proof.as_ref().is_some_and(|p| p.separations.is_some())
}
/// Whether Proof Colors sends the colors' own numbers to the device it simulates (Preserve CMYK
/// or RGB Numbers on a CMYK or RGB device, outside Separations Preview): each color is proofed as
/// it is painted ([`crate::ink::Ink::Proofed`]) and placed images from their own inks or pixels
/// ([`plate_image`]), and the drawn frame is not proofed again ([`post`]).
pub(crate) fn preserves(proof: &ProofSetup) -> bool {
proof.preserve_numbers
&& proof.separations.is_none()
&& matches!(proof.target, ProofTarget::WorkingCmyk | ProofTarget::Cmyk(_) | ProofTarget::Rgb(_))
}
/// The proof of [`RenderOptions::proof`] when it [`preserves`] the colors' numbers.
pub(crate) fn preserving(opts: &RenderOptions) -> Option<&ProofSetup> {
opts.proof.as_ref().filter(|p| preserves(p))
}
/// What the `visible` plates print of `ink`, as display sRGB, without the spot inks over several
/// plates: with one plate visible its ink as a grey (black = 100%), else the visible process inks
/// through the proof profile.
@@ -101,10 +119,26 @@ pub(crate) struct PlateLut {
}
impl PlateLut {
/// What the visible plates show of process inks `cmyk`, as display sRGB.
/// What the visible plates show of process inks `cmyk`, as display sRGB; with Preserve
/// Numbers outside Separations Preview, the inks as the proof's device shows them.
fn shown(&self, cmyk: [f32; 4]) -> [f32; 3] {
let visible = self.proof.separations.as_deref().unwrap_or_default();
plate_rgb(&self.cms, &self.proof, visible, &Inks { cmyk, spot: None, registration: false })
match self.proof.separations.as_deref() {
Some(visible) => plate_rgb(&self.cms, &self.proof, visible, &Inks { cmyk, spot: None, registration: false }),
None => {
let [c, m, y, k] = cmyk;
self.cms.proof_color(&Color::Cmyk { c, m, y, k }, &self.proof)
}
}
}
/// What display pixel `rgb` shows as: its inks separated with the proof's intent through the
/// visible plates, or with Preserve Numbers outside Separations Preview, its numbers as the
/// proof's device shows them.
fn shown_rgb(&self, rgb: [f32; 3]) -> [f32; 3] {
match self.proof.separations {
Some(_) => self.shown(self.cms.srgb_to_cmyk(rgb, self.proof.intent)),
None => self.cms.proof_srgb(rgb, &self.proof),
}
}
}
@@ -114,10 +148,19 @@ static PLATE_LUTS: Mutex<Vec<Arc<PlateLut>>> = Mutex::new(Vec::new());
/// The last [`PlateLut::generation`] handed out.
static PLATE_GENERATION: AtomicU64 = AtomicU64::new(0);
/// The tables the placed images of `doc` show through in art drawn with `ink` apart from a frame's
/// options (a pattern's tiles): with a proof that preserves the colors' numbers
/// ([`crate::ink::Ink::Proofed`]), that proof's ([`plate_lut`]); else `None`.
pub(crate) fn ink_plate_lut(ink: crate::ink::Ink, doc: &Document) -> Option<Arc<PlateLut>> {
let proof = crate::ink::proof_of(ink)?;
plate_lut(&RenderOptions { proof: Some(proof), ..Default::default() }, doc)
}
/// The tables the placed images of `doc` show Separations Preview's visible plates through with
/// `opts`, or `None` when it is off.
/// `opts`, or their colors as a proof that [`preserves`] the numbers shows them; `None` when
/// neither is on.
pub(crate) fn plate_lut(opts: &RenderOptions, doc: &Document) -> Option<Arc<PlateLut>> {
let proof = opts.proof.as_ref().filter(|p| p.separations.is_some())?;
let proof = opts.proof.as_ref().filter(|p| p.separations.is_some() || preserves(p))?;
let (c, profiles) = (cms::active(), cms::profiles_generation());
// The spot ones are the spot plates of `vectorcraft_doc::inks::plates`; their colors are part
// of the tables' identity, so a swatch edit shows.
@@ -151,12 +194,17 @@ pub(crate) fn plate_image(lut: &PlateLut, key: &ImageKey, pm: &Pixmap, blob: Opt
return (want, p);
}
// An image placed from a DCS file shows its own plates, spot plates included.
if let Some(s) = blob.filter(|b| crate::ink::shows_own_inks(key) && b.is_separated()).and_then(ImageBlob::separated) {
if let Some(s) =
blob.filter(|b| lut.proof.separations.is_some() && crate::ink::shows_own_inks(key) && b.is_separated()).and_then(ImageBlob::separated)
{
let out = images::store().insert(want.clone(), Arc::new(plates_shown(lut, &s, pm)));
return (want, out);
}
let size = (u32::from(pm.width()), u32::from(pm.height()));
let raw = crate::ink::key_inks(key, blob).filter(|i| (i.width, i.height) == size);
// A proof that preserves the numbers shows darkened pixels (a shadow's) as they are drawn,
// not the image's own inks.
let darkened = lut.proof.separations.is_none() && key.ink.is_darkened();
let raw = crate::ink::key_inks(key, blob).filter(|i| !darkened && (i.width, i.height) == size);
let mut out = pm.clone();
match raw {
Some(inks) => {
@@ -173,7 +221,7 @@ pub(crate) fn plate_image(lut: &PlateLut, key: &ImageKey, pm: &Pixmap, blob: Opt
}
}
None => {
let t = lut.rgb.get_or_init(|| ProofLut::build(|rgb| lut.shown(lut.cms.srgb_to_cmyk(rgb, lut.proof.intent))));
let t = lut.rgb.get_or_init(|| ProofLut::build(|rgb| lut.shown_rgb(rgb)));
for px in out.data_mut().iter_mut().filter(|p| p.a > 0) {
let a = f32::from(px.a);
let un = |v: u8| (f32::from(v) / a).min(1.0);
@@ -460,7 +508,7 @@ fn prepare_node(n: &Arc<Node>, earlier: Option<(&Arc<Node>, &Arc<Node>)>, how: &
/// Soft-proof the rendered (premultiplied RGBA8) pixels in place.
pub(crate) fn post(pixels: &mut [u8], opts: &RenderOptions) {
let Some(proof) = opts.proof.as_ref() else { return };
if proof.separations.is_some() || matches!(proof.target, ProofTarget::MonitorRgb | ProofTarget::Srgb) {
if proof.separations.is_some() || preserves(proof) || matches!(proof.target, ProofTarget::MonitorRgb | ProofTarget::Srgb) {
return;
}
let lut = cms::active().proof_lut(proof);
@@ -485,6 +533,16 @@ pub(crate) fn post(pixels: &mut [u8], opts: &RenderOptions) {
}
}
/// Solid color `[r, g, b, a]` (straight alpha) under the art of a frame drawn with `opts`: with a
/// proof that [`preserves`] the numbers, whose art [`prepare`] proofs before drawing, as the
/// proof's device shows it (white paper takes Simulate Paper Color's tint), so the art's
/// transparency and edges mix with it as they print; else as it is.
pub(crate) fn under_art(opts: &RenderOptions, [r, g, b, a]: [u8; 4]) -> [u8; 4] {
let Some(proof) = preserving(opts) else { return [r, g, b, a] };
let [r, g, b] = cms::active().proof_srgb([r, g, b].map(|v| f32::from(v) / 255.0), proof).map(|v| (v.clamp(0.0, 1.0) * 255.0).round() as u8);
[r, g, b, a]
}
/// View-level proof state (View → Proof Setup / Proof Colors / Overprint Preview, Separations
/// Preview panel). Process-wide: the app has one proof state for all windows.
#[derive(Clone, Debug, Default, PartialEq)]
+33 -7
View File
@@ -147,7 +147,16 @@ impl Renderer {
let inv = view.inverse();
let visible = inv.transform_rect_bbox(Rect::new(0.0, 0.0, w as f64, h as f64));
let px = 1.0 / view.determinant().abs().sqrt().max(1e-12);
let screen = if opts.rich_black { Ink::RichBlack } else { Ink::Display };
// A proof that preserves the colors' numbers proofs each colour as it is painted; the hold
// keeps that proof registered until the frame is drawn.
let (screen, _proof) = match proof::preserving(opts) {
Some(p) => {
let (ink, hold) = ink::proofed_ink(p);
(ink, Some(hold))
}
None if opts.rich_black => (Ink::RichBlack, None),
None => (Ink::Display, None),
};
let symbols = doc.symbol_boxes().quick();
let output = Affine::scale(1.0 / f64::from(cell.max(1))) * view;
let plates = proof::plate_lut(opts, doc);
@@ -167,10 +176,13 @@ impl Renderer {
return Rendered { width: w as u32, height: h as u32, pixels };
}
let mut pixels = if inks || self.blends_in_cmyk(doc, opts) {
// Blending in CMYK: one frame per ink plane, then their inks shown on screen.
let cmy = self.draw_frame(&Frame { ink: Ink::Cmy, ..frame }, w, h);
// Blending in CMYK: one frame per ink plane, then their inks shown on screen (through a
// proof that preserves the numbers, when one is on: the planes hold the inks as they
// are, images included).
let planes = if proof::preserving(opts).is_some() { None } else { frame.plates };
let cmy = self.draw_frame(&Frame { ink: Ink::Cmy, plates: planes, ..frame }, w, h);
let stats = self.stats;
let k = self.draw_frame(&Frame { ink: Ink::K, ..frame }, w, h);
let k = self.draw_frame(&Frame { ink: Ink::K, plates: planes, ..frame }, w, h);
self.stats = stats;
if inks {
ink::amounts(&cmy, &k)
@@ -263,9 +275,16 @@ impl Renderer {
ctx.set_aliasing_threshold(opts.anti_alias.threshold());
self.raster = raster_settings(opts);
if opts.artboards && !opts.outline {
// Paper: white on screen, no ink on the ink planes.
// Paper: white on screen, no ink on the ink planes; with a proof that preserves the
// colors' numbers, the device's paper.
ctx.set_transform(f.view);
ctx.set_paint(peniko::Color::WHITE);
match screen_under_art(f, [255; 4]) {
[255, 255, 255, _] => ctx.set_paint(peniko::Color::WHITE),
paper => {
let [r, g, b, a] = f.ink.fixed8(paper);
ctx.set_paint(peniko::Color::from_rgba8(r, g, b, a));
}
}
for ab in &f.doc.artboards {
ctx.fill_rect(&ab.rect);
}
@@ -290,7 +309,7 @@ impl Renderer {
}
let mut pixels = pm.data_as_u8_slice().to_vec();
if let Some(bg) = opts.background {
over_background(&mut pixels, f.ink.fixed8(bg));
over_background(&mut pixels, f.ink.fixed8(screen_under_art(f, bg)));
}
pixels
}
@@ -460,6 +479,13 @@ fn raster_settings(opts: &RenderOptions) -> vello_cpu::RasterizerSettings {
vello_cpu::RasterizerSettings { render_mode, ..Default::default() }
}
/// Solid color `rgba` (straight alpha) under the art of frame `f`: on screen as
/// [`proof::under_art`] gives it; the ink planes paint it as it is, and [`ink::compose`] shows it
/// through the proof.
fn screen_under_art(f: &Frame, rgba: [u8; 4]) -> [u8; 4] {
if matches!(f.ink.base(), Ink::Cmy | Ink::K) { rgba } else { proof::under_art(f.opts, rgba) }
}
/// Premultiplied RGBA `pixels` drawn over the solid color `background` (`[r, g, b, a]`, straight).
pub(crate) fn over_background(pixels: &mut [u8], [r, g, b, a]: [u8; 4]) {
let alpha = u32::from(a);
+4 -1
View File
@@ -307,7 +307,10 @@ impl Renderer {
let image_left_out = self.image_left_out.replace(false);
let failures = crate::paint::decode_failures();
let pattern_images_left_out = crate::pattern::images_left_out();
self.draw_kept_node(&mut mctx, &Frame { mt: false, ink: Ink::Display, ..*f }, &m.art);
// A proof that preserves the colors' numbers leaves the mask's images as they are, as it
// leaves its colors.
let plates = if crate::proof::preserving(f.opts).is_some() { None } else { f.plates };
self.draw_kept_node(&mut mctx, &Frame { mt: false, ink: Ink::Display, plates, ..*f }, &m.art);
let incomplete = self.image_left_out.unwrap_or(false)
|| crate::pattern::images_left_out() > pattern_images_left_out
|| (!f.opts.mark_undecoded_images && crate::paint::decode_failures() > failures);