mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 21:27:00 +00:00
Merge pull request #8157 from dotCooCoo/fix/hfp-full-tone
Image Trace: High Fidelity Photo traces in Full Tone with abutting shapes
This commit is contained in:
@@ -144,7 +144,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Make",
|
||||
["Object", "Image Trace"],
|
||||
None,
|
||||
"{id?: image or Image Trace group (default: selection), preset?: name (imageTrace.presets), savedPreset?: {settings} (a saved preset's settings, which the journal records so a replay traces with them after the preset is changed, renamed or deleted; used in place of the saved preset `preset` names), enhanced?: false (the preset's enhanced version: with Auto Grouping, and with Shapes in all but High Fidelity Photo; Flat Logo has none and is traced as it is), params?: {mode: \"blackAndWhite\"|\"grayscale\"|\"color\"|\"logo\", threshold: 0-255, palette: \"limited\"|\"fullTone\"|\"automatic\"|\"documentLibrary\" (color mode; limited: the `colors` best colours, fullTone: as many as the tones need, more with colorDetail, automatic: flat art with its own colours, else fullTone, documentLibrary: at most `colors` of the library's colours, as they are), colors: 2-256, colorDetail: 0-100 (fullTone, automatic), library: \"document\" (the document's swatches) or a swatch library id or name (swatch.library.list; documentLibrary), colorGroup?: name (color mode, documentLibrary with library \"document\": the colors of that document color group instead of every swatch; \"\" is every swatch), paths: 0-100, corners: 0-100, noise: px (an area smaller than this joins the color it shares the longest border with; when that color is far from its own and the area is 2 px or more, or a single pixel whose longest border is not tied between colors, it joins the neighboring color nearest its pixels among those sharing at least a tenth of that border), method: \"abutting\"|\"overlapping\" (abutting with fills, not mode logo: a \"Seam Fills\" clip group under the paths holds strokes along the edges two filled paths share, 1.5 image pixels wide (VectorCraft's own width), in the color of the lower path (on an image stretched more one way than another, each stroke's outline in image pixels as a filled path), clipped to the image's box within the traced paths' box; paths that became live shapes get none; the paths are not changed), ignoreWhite (leave out white areas), ignoreColor?: \"#rrggbb\" (with ignoreWhite: the colour left out instead of white), ignoreBackground: false (with ignoreWhite: only the areas of the ignored color that reach the image's edge are left out), keepColors?: [\"#rrggbb\"…] (not mode logo: only the palette colors within about 30 levels of a listed color are traced; empty: every color), snapCurvesToLines, shapes: false (filled outlines that are a circle, an ellipse, a rectangle or a regular polygon come out as that live shape), autoGrouping: false (each path that has others inside it is grouped with them), gradients: false (grayscale and color: an area whose colour changes evenly along one direction is one path with a linear gradient fill), fills: true, strokes: false (Create: lines up to strokeWidth wide become stroked centre lines; without fills, wider areas become stroked outlines), strokeWidth: px (10), logoColors?: [\"#rrggbb\"…] (mode logo: flat-colour logos only; colours found automatically or named here, at most ten; white is its own color, and a named color with every channel 245 or more is taken as that white, except with logoColors named, logoWhite false and no ignoreWhite; noise = areas under noise/10 px ignored; edges to a fraction of a pixel, sharp corners restored, lines and circles snapped; enclosed transparent areas are painted white while white is its own color, and stay holes with ignoreWhite or without a white of its own; fills/strokes are ignored; gradients and photos are refused, judged by the image's own colors also when logoColors are named), logoWhite: true (mode logo with logoColors named; false traces the named colors only: white areas take the nearest of them, a named white is kept and enclosed transparent areas stay holes; with ignoreWhite, white areas are left out either way)}, view?: as imageTrace.setView (default: the traced object's own, else tracingResult), ids?: [id…] (instead of id)} → {id, paths, anchors, colors, warnings: [text…] (the image is over 1500 px on a side, so it traces more slowly; or it was traced scaled down; Flat Logo names only the size it traced a larger image at; or a keepColors color matches none the trace found, or nothing was traced)}",
|
||||
"{id?: image or Image Trace group (default: selection), preset?: name (imageTrace.presets), savedPreset?: {settings} (a saved preset's settings, which the journal records so a replay traces with them after the preset is changed, renamed or deleted; used in place of the saved preset `preset` names), enhanced?: false (the preset's enhanced version: with Auto Grouping, and with Shapes in all but High Fidelity Photo; Flat Logo has none and is traced as it is), params?: {mode: \"blackAndWhite\"|\"grayscale\"|\"color\"|\"logo\", threshold: 0-255, palette: \"limited\"|\"fullTone\"|\"automatic\"|\"documentLibrary\" (color mode; limited: the `colors` best colours, fullTone: as many as the tones need, more with colorDetail, split into at least colorDetail colors where the image has that many before colors that look alike merge (less than 5 apart in Oklab × 100 and thoroughly mixed, or less than 1.5 and mixed in patches), automatic: flat art with its own colours, else as many as the tones need without fullTone's least count, merging close RGB colors, documentLibrary: at most `colors` of the library's colours, as they are), colors: 2-256, colorDetail: 0-100 (fullTone, automatic), library: \"document\" (the document's swatches) or a swatch library id or name (swatch.library.list; documentLibrary), colorGroup?: name (color mode, documentLibrary with library \"document\": the colors of that document color group instead of every swatch; \"\" is every swatch), paths: 0-100, corners: 0-100, noise: px (an area smaller than this joins the color it shares the longest border with; when that color is far from its own and the area is 2 px or more, or a single pixel whose longest border is not tied between colors, it joins the neighboring color nearest its pixels among those sharing at least a tenth of that border), method: \"abutting\"|\"overlapping\" (abutting with fills, not mode logo: a \"Seam Fills\" clip group under the paths holds strokes along the edges two filled paths share, 1.5 image pixels wide (VectorCraft's own width), in the color of the lower path (on an image stretched more one way than another, each stroke's outline in image pixels as a filled path), clipped to the image's box within the traced paths' box; paths that became live shapes get none; the paths are not changed), ignoreWhite (leave out white areas), ignoreColor?: \"#rrggbb\" (with ignoreWhite: the colour left out instead of white), ignoreBackground: false (with ignoreWhite: only the areas of the ignored color that reach the image's edge are left out), keepColors?: [\"#rrggbb\"…] (not mode logo: only the palette colors within about 30 levels of a listed color are traced; empty: every color), snapCurvesToLines, shapes: false (filled outlines that are a circle, an ellipse, a rectangle or a regular polygon come out as that live shape), autoGrouping: false (each path that has others inside it is grouped with them), gradients: false (grayscale and color: an area whose colour changes evenly along one direction is one path with a linear gradient fill), fills: true, strokes: false (Create: lines up to strokeWidth wide become stroked centre lines; without fills, wider areas become stroked outlines), strokeWidth: px (10), logoColors?: [\"#rrggbb\"…] (mode logo: flat-colour logos only; colours found automatically or named here, at most ten; white is its own color, and a named color with every channel 245 or more is taken as that white, except with logoColors named, logoWhite false and no ignoreWhite; noise = areas under noise/10 px ignored; edges to a fraction of a pixel, sharp corners restored, lines and circles snapped; enclosed transparent areas are painted white while white is its own color, and stay holes with ignoreWhite or without a white of its own; fills/strokes are ignored; gradients and photos are refused, judged by the image's own colors also when logoColors are named), logoWhite: true (mode logo with logoColors named; false traces the named colors only: white areas take the nearest of them, a named white is kept and enclosed transparent areas stay holes; with ignoreWhite, white areas are left out either way)}, view?: as imageTrace.setView (default: the traced object's own, else tracingResult), ids?: [id…] (instead of id)} → {id, paths, anchors, colors, warnings: [text…] (the image is over 1500 px on a side, so it traces more slowly; or it was traced scaled down; Flat Logo names only the size it traced a larger image at; or a keepColors color matches none the trace found, or nothing was traced)}",
|
||||
has_selection_or_ids,
|
||||
|s, p| trace_make(s, p, false)
|
||||
),
|
||||
|
||||
@@ -38,11 +38,12 @@ pub enum Palette {
|
||||
#[serde(alias = "Limited")]
|
||||
Limited,
|
||||
/// As many colours as the image's tones need, up to [`FULL_TONE_MAX`] (photos, gradients):
|
||||
/// `color_detail` sets how close two colours may be and stay apart.
|
||||
/// `color_detail` sets how close two colours may be and stay apart. Before merging colors that
|
||||
/// look alike, it splits to at least one color per step of `color_detail` where the image has that many.
|
||||
#[serde(alias = "Full Tone")]
|
||||
FullTone,
|
||||
/// Flat art (a few colours cover nearly all of it) traces with exactly those colours, anything
|
||||
/// else as Full Tone.
|
||||
/// else with as many as its tones need, without Full Tone's least count and merging close RGB colors.
|
||||
#[serde(alias = "Automatic")]
|
||||
Automatic,
|
||||
/// The most used colours of a swatch library ([`TraceParams::swatches`]), at most `colors` of
|
||||
@@ -243,7 +244,10 @@ pub fn preset(name: &str) -> Option<TraceParams> {
|
||||
// many as its tones need where it is not.
|
||||
// (Color detail 85: a colour on a hundredth of the picture is still one of its colours.)
|
||||
"auto color" => TraceParams { palette: Palette::Automatic, color_detail: 85.0, ..color(6, 65.0, 60.0, 16, Method::Abutting) },
|
||||
"high fidelity photo" => color(64, 50.0, 50.0, 5, Method::Overlapping),
|
||||
// A photo's tones: as many colors as they need (Full Tone), split until no color spans more
|
||||
// than about 21 levels of a channel and into at least 85 (Color detail 85) before colors that
|
||||
// look alike merge, as abutting shapes. VectorCraft's own values.
|
||||
"high fidelity photo" => TraceParams { palette: Palette::FullTone, color_detail: 85.0, ..color(64, 50.0, 50.0, 5, Method::Abutting) },
|
||||
"low fidelity photo" => color(20, 50.0, 50.0, 10, Method::Overlapping),
|
||||
"3 colors" => color(3, 50.0, 50.0, 15, Method::Abutting),
|
||||
"6 colors" => color(6, 50.0, 50.0, 8, Method::Abutting),
|
||||
|
||||
@@ -93,7 +93,7 @@ pub(crate) fn quantize_keeping(img: &Raster, params: &TraceParams) -> (Quantized
|
||||
let g = l.round().clamp(0.0, 255.0) as u8;
|
||||
[g, g, g]
|
||||
});
|
||||
let q = merge_mixed(compact(labels, palette.collect()), img.width as usize, img.height as usize, &[]);
|
||||
let q = merge_mixed(compact(labels, palette.collect()), img.width as usize, img.height as usize, &[], Alike::Rgb);
|
||||
(if settles_wide(params) { settled_wide(q, img, &own, true) } else { settled(q, img, &own) }, vec![])
|
||||
}
|
||||
// Logo mode traces without quantising; asked directly, it quantises like Color.
|
||||
@@ -175,12 +175,14 @@ pub(crate) fn quantize_keeping(img: &Raster, params: &TraceParams) -> (Quantized
|
||||
img.rgba.as_chunks::<4>().0.iter().map(|p| if p[3] < 128 { TRANSPARENT } else { lut[hk.key(p[0], p[1], p[2])] }).collect();
|
||||
let palette = centers.iter().map(|c| [c[0].round() as u8, c[1].round() as u8, c[2].round() as u8]).collect();
|
||||
let q = compact(labels, palette);
|
||||
// A swatch library's colours are used as they are.
|
||||
// A swatch library's colours are used as they are. Full Tone's colors merge only when
|
||||
// they look alike (see `Alike`).
|
||||
if library {
|
||||
return (q, false);
|
||||
}
|
||||
let alike = if params.palette == Palette::FullTone { Alike::Seen } else { Alike::Rgb };
|
||||
let before = q.palette.len();
|
||||
let q = merge_mixed(q, img.width as usize, img.height as usize, &rare);
|
||||
let q = merge_mixed(q, img.width as usize, img.height as usize, &rare, alike);
|
||||
let merged = q.palette.len() < before;
|
||||
(q, merged)
|
||||
};
|
||||
@@ -309,16 +311,38 @@ pub(crate) fn tests_oklab(c: [u8; 3]) -> [f64; 3] {
|
||||
oklab(c.map(f64::from))
|
||||
}
|
||||
|
||||
/// Which colors [`merge_mixed`] takes for one color that noise split.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
enum Alike {
|
||||
/// Close in RGB: under 30 levels apart and thoroughly mixed, or under 12 and mixed in patches.
|
||||
/// Used for Grayscale and for every Color palette but Full Tone (Automatic included).
|
||||
Rgb,
|
||||
/// Close to the eye: under [`FULL_TONE_ALIKE`] apart in Oklab and thoroughly mixed, or under
|
||||
/// [`FULL_TONE_PATCHES`] and mixed in patches (compression blocks). Full Tone's neighboring tones
|
||||
/// of a smooth photo are about as close in RGB as noise makes one color, and mixed along their
|
||||
/// soft border, so the RGB test would take most of them for one color.
|
||||
Seen,
|
||||
}
|
||||
|
||||
/// How far apart (Oklab × 100) two thoroughly mixed Full Tone colors may lie and still be merged
|
||||
/// as one color that noise split: a little more than the least difference one sees (see [`oklab`]).
|
||||
const FULL_TONE_ALIKE: f64 = 5.0;
|
||||
|
||||
/// How far apart (Oklab × 100) two Full Tone colors mixed in patches may lie and still be merged:
|
||||
/// the blocks of one flat color that compression shifted by a few levels each.
|
||||
const FULL_TONE_PATCHES: f64 = 1.5;
|
||||
|
||||
/// `q` with the colours that noise made of one colour merged, largest mix first.
|
||||
///
|
||||
/// Asked for more colours than a picture has, k-means splits a flat colour along its noise, and
|
||||
/// the two halves would trace as specks of one all over the other. Such halves are close (under 30
|
||||
/// levels apart: noise is about as strong in a dark colour as in a light one, so the distance is
|
||||
/// taken in RGB) and thoroughly mixed: the pixels of the lesser one have, on average, more than
|
||||
/// half a neighbour of the other each; or they are closer still (under 12 levels) and mixed in
|
||||
/// patches (compression blocks). The bands of a gradient are close too, but each keeps to itself
|
||||
/// and they stay apart. The colours in `keep` merge with none.
|
||||
fn merge_mixed(q: Quantized, w: usize, h: usize, keep: &[[u8; 3]]) -> Quantized {
|
||||
/// the two halves would trace as specks of one all over the other. Such halves are close and
|
||||
/// thoroughly mixed: the pixels of the lesser one have, on average, more than half a neighbour of
|
||||
/// the other each; or they are closer still and mixed in patches (compression blocks). The bands
|
||||
/// of a gradient are close too, but each keeps to itself and they stay apart. The colours in
|
||||
/// `keep` merge with none. Close is under 30 RGB levels apart for thoroughly mixed colours and
|
||||
/// under 12 for patches with [`Alike::Rgb`], and in Oklab under [`FULL_TONE_ALIKE`] and
|
||||
/// [`FULL_TONE_PATCHES`] with [`Alike::Seen`].
|
||||
fn merge_mixed(q: Quantized, w: usize, h: usize, keep: &[[u8; 3]], alike: Alike) -> Quantized {
|
||||
let k = q.palette.len();
|
||||
// A rare colour kept on purpose (see `rare_colours`) is distinct by choice: it merges with none.
|
||||
let kept: Vec<bool> = q.palette.iter().map(|c| keep.contains(c)).collect();
|
||||
@@ -340,6 +364,13 @@ fn merge_mixed(q: Quantized, w: usize, h: usize, keep: &[[u8; 3]]) -> Quantized
|
||||
}
|
||||
}
|
||||
let mut color: Vec<[f64; 3]> = q.palette.iter().map(|c| c.map(f64::from)).collect();
|
||||
// Each colour in Oklab, for `Alike::Seen`, worked out once and again only for a colour that
|
||||
// takes in another.
|
||||
let mut lab: Vec<[f64; 3]> = if alike == Alike::Seen { color.iter().map(|&c| oklab(c)).collect() } else { vec![] };
|
||||
let seen_apart = |lab: &[[f64; 3]], a: usize, b: usize| match (lab.get(a), lab.get(b)) {
|
||||
(Some(la), Some(lb)) => (0..3).map(|c| (la[c] - lb[c]).powi(2)).sum::<f64>().sqrt(),
|
||||
_ => f64::INFINITY,
|
||||
};
|
||||
// Which colour each has merged into (itself when none).
|
||||
let mut into: Vec<usize> = (0..k).collect();
|
||||
loop {
|
||||
@@ -350,14 +381,30 @@ fn merge_mixed(q: Quantized, w: usize, h: usize, keep: &[[u8; 3]]) -> Quantized
|
||||
continue;
|
||||
}
|
||||
let mixed = touch[a * k + b] / count[a].min(count[b]);
|
||||
let apart = (0..3).map(|c| (color[a][c] - color[b][c]).powi(2)).sum::<f64>().sqrt();
|
||||
if (mixed > 0.5 && apart < 30.0 || mixed > 0.15 && apart < 12.0) && best.is_none_or(|x| mixed > x.0) {
|
||||
// Two colours this little mixed merge under neither test.
|
||||
if mixed <= 0.15 {
|
||||
continue;
|
||||
}
|
||||
let merges = match alike {
|
||||
Alike::Rgb => {
|
||||
let apart = (0..3).map(|c| (color[a][c] - color[b][c]).powi(2)).sum::<f64>().sqrt();
|
||||
mixed > 0.5 && apart < 30.0 || apart < 12.0
|
||||
}
|
||||
Alike::Seen => {
|
||||
let apart = seen_apart(&lab, a, b);
|
||||
mixed > 0.5 && apart < FULL_TONE_ALIKE || apart < FULL_TONE_PATCHES
|
||||
}
|
||||
};
|
||||
if merges && best.is_none_or(|x| mixed > x.0) {
|
||||
best = Some((mixed, a, b));
|
||||
}
|
||||
}
|
||||
}
|
||||
let Some((_, a, b)) = best else { break };
|
||||
color[a] = [0, 1, 2].map(|c| (color[a][c] * count[a] + color[b][c] * count[b]) / (count[a] + count[b]));
|
||||
if let Some(l) = lab.get_mut(a) {
|
||||
*l = oklab(color[a]);
|
||||
}
|
||||
count[a] += count[b];
|
||||
count[b] = 0.0;
|
||||
into[b] = a;
|
||||
@@ -410,6 +457,33 @@ mod tests {
|
||||
assert!(own.iter().all(|o| *o == own[0]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn full_tone_merges_only_mixed_colors_that_look_alike() {
|
||||
// Two colors in a checkerboard: every pixel has four neighbors of the other color.
|
||||
let mixed =
|
||||
|a: [u8; 3], b: [u8; 3]| Quantized { labels: (0..16 * 16).map(|i| ((i % 16 + i / 16) % 2) as u16).collect(), palette: vec![a, b] };
|
||||
let colors = |q: Quantized, alike: Alike| merge_mixed(q, 16, 16, &[], alike).palette.len();
|
||||
// Gray and a greener gray, 22 levels apart (about 6.4 in Oklab): one color in RGB, two that look different.
|
||||
let (gray, green) = ([128, 128, 128], [128, 150, 128]);
|
||||
assert_eq!(colors(mixed(gray, green), Alike::Rgb), 1);
|
||||
assert_eq!(colors(mixed(gray, green), Alike::Seen), 2);
|
||||
// Two grays 3 levels apart (about 1 in Oklab): one color either way.
|
||||
assert_eq!(colors(mixed(gray, [131; 3]), Alike::Rgb), 1);
|
||||
assert_eq!(colors(mixed(gray, [131; 3]), Alike::Seen), 1);
|
||||
// Side by side, not mixed: two colors either way.
|
||||
let halves = Quantized { labels: (0..16 * 16).map(|i| u16::from(i % 16 >= 8)).collect(), palette: vec![[128; 3], [131; 3]] };
|
||||
assert_eq!(colors(halves.clone(), Alike::Rgb), 2);
|
||||
assert_eq!(colors(halves, Alike::Seen), 2);
|
||||
// In 8 × 8 blocks, mixed in patches: grays 3 levels apart merge either way; grays 6 levels
|
||||
// apart (about 10 in RGB, more than 1.5 in Oklab) merge only in RGB.
|
||||
let blocks =
|
||||
|b: [u8; 3]| Quantized { labels: (0..16 * 16).map(|i| ((i % 16 / 8 + i / 16 / 8) % 2) as u16).collect(), palette: vec![gray, b] };
|
||||
assert_eq!(colors(blocks([131; 3]), Alike::Rgb), 1);
|
||||
assert_eq!(colors(blocks([131; 3]), Alike::Seen), 1);
|
||||
assert_eq!(colors(blocks([134; 3]), Alike::Rgb), 1);
|
||||
assert_eq!(colors(blocks([134; 3]), Alike::Seen), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_picture_with_no_pixels_is_not_shared_out() {
|
||||
// No band for each of the rows of a picture with no columns, however many rows it has.
|
||||
|
||||
@@ -138,6 +138,12 @@ pub(super) fn labs(colors: &[[f64; 3]]) -> Vec<[f64; 3]> {
|
||||
/// The most colours Full Tone (and Automatic on continuous-tone images) makes.
|
||||
pub const FULL_TONE_MAX: usize = 256;
|
||||
|
||||
/// The fewest colors Palette › Full Tone splits into, before merging, at Color detail `detail`
|
||||
/// (0–1): one per step of Color detail, 85 at 85. Automatic does not use it.
|
||||
pub(super) fn full_tone_least(detail: f64) -> usize {
|
||||
(detail.clamp(0.0, 1.0) * 100.0).round() as usize
|
||||
}
|
||||
|
||||
/// A histogram bin in use: its index, mean colour and pixel count.
|
||||
pub(super) type Used = (usize, [f64; 3], f64);
|
||||
|
||||
@@ -152,11 +158,14 @@ pub(super) fn color_palette(used: &[Used], params: &TraceParams) -> Vec<[f64; 3]
|
||||
// Full Tone: split until no colour box is wider than 96 (few colours) … 8 (many) levels per
|
||||
// channel, which is one histogram bin.
|
||||
let full_tone = || refine(used, centers(&median_cut(used, FULL_TONE_MAX, 96.0 - 88.0 * detail)));
|
||||
// Palette › Full Tone also splits into at least one color per step of Color detail, where the
|
||||
// picture has that many (see [`full_tone_least`]).
|
||||
let full_tone_palette = || refine(used, centers(&median_cut_least(used, FULL_TONE_MAX, 96.0 - 88.0 * detail, full_tone_least(detail))));
|
||||
// A Limited palette of 9 to 16 colors keeps a nearly flat dark ground in one color (see [`kmeans_rgb`]).
|
||||
let limited = || kmeans_rgb(used, k, if FEW_COLORS.contains(&k) { LEAST_APART } else { 0.0 });
|
||||
match params.palette {
|
||||
Palette::Limited => limited(),
|
||||
Palette::FullTone => full_tone(),
|
||||
Palette::FullTone => full_tone_palette(),
|
||||
Palette::Automatic => match flat_colors(used, detail) {
|
||||
Some(n) => flat_palette(used, n),
|
||||
None => full_tone(),
|
||||
@@ -285,7 +294,7 @@ const GRAY: f64 = 3.0;
|
||||
/// (see [`median_cut_apart`]). A large, nearly flat dark ground then keeps one color, and the
|
||||
/// color it would have taken goes to another cut.
|
||||
fn kmeans_rgb(used: &[Used], k: usize, apart: f64) -> Vec<[f64; 3]> {
|
||||
refine(used, centers(&median_cut_apart(used, k, 0.0, apart)))
|
||||
refine(used, centers(&median_cut_apart(used, k, 0.0, apart, 0)))
|
||||
}
|
||||
|
||||
/// Divisive clustering in the manner of median cut, but each box is cut where that leaves its two
|
||||
@@ -295,21 +304,34 @@ fn kmeans_rgb(used: &[Used], k: usize, apart: f64) -> Vec<[f64; 3]> {
|
||||
/// and leaves two smaller colours in one box. Boxes are cut while there are fewer than `k` and
|
||||
/// some box spans more than `spread` levels of a channel.
|
||||
pub(super) fn median_cut(used: &[Used], k: usize, spread: f64) -> Vec<ColorBox> {
|
||||
median_cut_apart(used, k, spread, 0.0)
|
||||
median_cut_apart(used, k, spread, 0.0, 0)
|
||||
}
|
||||
|
||||
/// [`median_cut`], except when both sides of a cut have a dark gray mean color (see [`DARK`] and
|
||||
/// [`GRAY`]) and the two means lie `d` (Oklab × 100) apart with `d` < `apart`: then the cut's gain
|
||||
/// is scaled by (`d` / `apart`)². With `apart` 0 it is [`median_cut`].
|
||||
fn median_cut_apart(used: &[Used], k: usize, spread: f64, apart: f64) -> Vec<ColorBox> {
|
||||
/// [`median_cut`], then, while there are fewer than `least` boxes, cutting the boxes no wider than
|
||||
/// `spread` too, the one whose cut gains most first.
|
||||
fn median_cut_least(used: &[Used], k: usize, spread: f64, least: usize) -> Vec<ColorBox> {
|
||||
median_cut_apart(used, k, spread, 0.0, least)
|
||||
}
|
||||
|
||||
/// [`median_cut`] with at least `least` boxes where the bins allow (see [`median_cut_least`]),
|
||||
/// except when both sides of a cut have a dark gray mean color (see [`DARK`] and [`GRAY`]) and the
|
||||
/// two means lie `d` (Oklab × 100) apart with `d` < `apart`: then the cut's gain is scaled by
|
||||
/// (`d` / `apart`)². With `apart` 0 and `least` 0 it is [`median_cut`].
|
||||
fn median_cut_apart(used: &[Used], k: usize, spread: f64, apart: f64, least: usize) -> Vec<ColorBox> {
|
||||
if used.is_empty() {
|
||||
return vec![ColorBox { mean: [255.0; 3], weight: 0.0, peak: 0.0 }];
|
||||
}
|
||||
/// A box's bins and its best cut: (gain, bins sorted along the cut's channel, bins on the first side).
|
||||
/// A box's bins, its widest span over the channels, and its best cut: (gain, bins sorted along
|
||||
/// the cut's channel, bins on the first side).
|
||||
struct Cut {
|
||||
bins: Vec<usize>,
|
||||
widest: f64,
|
||||
best: Option<(f64, Vec<usize>, usize)>,
|
||||
}
|
||||
// Boxes no wider than `spread` are cut only while there are fewer than `least` boxes. A box made
|
||||
// when there are already `least` boxes or more is never cut unless it is wider, so its cut is
|
||||
// not planned.
|
||||
let narrowest = |boxes_after: usize| if boxes_after < least { 0.0 } else { spread.max(0.0) };
|
||||
// How much of a cut's gain counts when its sides' mean colors are `a` and `b`: all of it when
|
||||
// they look different or either is not a dark gray, less as two dark grays look more alike.
|
||||
let dark_gray = |c: [f64; 3]| c[0] < DARK && c[1].hypot(c[2]) < GRAY;
|
||||
@@ -320,7 +342,8 @@ fn median_cut_apart(used: &[Used], k: usize, spread: f64, apart: f64) -> Vec<Col
|
||||
}
|
||||
((0..3).map(|q| (a[q] - b[q]).powi(2)).sum::<f64>() / (apart * apart)).min(1.0)
|
||||
};
|
||||
let plan = |bins: Vec<usize>| {
|
||||
let plan = |bins: Vec<usize>, boxes_after: usize| {
|
||||
let narrowest = narrowest(boxes_after);
|
||||
let mut best: Option<(f64, Vec<usize>, usize)> = None;
|
||||
let widest = (0..3)
|
||||
.map(|ch| {
|
||||
@@ -328,7 +351,7 @@ fn median_cut_apart(used: &[Used], k: usize, spread: f64, apart: f64) -> Vec<Col
|
||||
v.clone().fold(f64::NEG_INFINITY, f64::max) - v.fold(f64::INFINITY, f64::min)
|
||||
})
|
||||
.fold(0.0, f64::max);
|
||||
if bins.len() >= 2 && widest > spread.max(0.0) {
|
||||
if bins.len() >= 2 && widest > narrowest {
|
||||
for ch in 0..3 {
|
||||
let mut sorted = bins.clone();
|
||||
sorted.sort_by(|x, y| used[*x].1[ch].total_cmp(&used[*y].1[ch]));
|
||||
@@ -366,18 +389,26 @@ fn median_cut_apart(used: &[Used], k: usize, spread: f64, apart: f64) -> Vec<Col
|
||||
}
|
||||
}
|
||||
}
|
||||
Cut { bins, best }
|
||||
Cut { bins, widest, best }
|
||||
};
|
||||
let mut boxes = vec![plan((0..used.len()).collect())];
|
||||
let mut boxes = vec![plan((0..used.len()).collect(), 1)];
|
||||
while boxes.len() < k {
|
||||
let gain = |c: &Cut| c.best.as_ref().map_or(f64::NEG_INFINITY, |b| b.0);
|
||||
let Some(bi) = (0..boxes.len()).filter(|&i| boxes[i].best.is_some()).max_by(|&a, &b| gain(&boxes[a]).total_cmp(&gain(&boxes[b]))) else {
|
||||
// The boxes wider than `spread` first; when none is left and there are fewer than `least`,
|
||||
// any box with a cut.
|
||||
let most = |wide: bool| {
|
||||
(0..boxes.len())
|
||||
.filter(|&i| boxes[i].best.is_some() && (!wide || boxes[i].widest > spread.max(0.0)))
|
||||
.max_by(|&a, &b| gain(&boxes[a]).total_cmp(&gain(&boxes[b])))
|
||||
};
|
||||
let Some(bi) = most(true).or_else(|| if boxes.len() < least { most(false) } else { None }) else {
|
||||
break;
|
||||
};
|
||||
let Some((_, mut sorted, at)) = boxes.swap_remove(bi).best else { break };
|
||||
let tail = sorted.split_off(at);
|
||||
boxes.push(plan(sorted));
|
||||
boxes.push(plan(tail));
|
||||
let after = boxes.len() + 2;
|
||||
boxes.push(plan(sorted, after));
|
||||
boxes.push(plan(tail, after));
|
||||
}
|
||||
boxes
|
||||
.iter()
|
||||
@@ -467,7 +498,9 @@ mod tests {
|
||||
assert_eq!(palette(Palette::DocumentLibrary, colors), plain(colors as usize), "{colors} colors");
|
||||
}
|
||||
let detail = (TraceParams::default().color_detail / 100.0).clamp(0.0, 1.0);
|
||||
assert_eq!(palette(Palette::FullTone, 16), refine(&used, centers(&median_cut(&used, FULL_TONE_MAX, 96.0 - 88.0 * detail))));
|
||||
// Full Tone's median cut makes at least one color per step of Color detail.
|
||||
let full_tone = refine(&used, centers(&median_cut_least(&used, FULL_TONE_MAX, 96.0 - 88.0 * detail, full_tone_least(detail))));
|
||||
assert_eq!(palette(Palette::FullTone, 16), full_tone);
|
||||
let automatic = match flat_colors(&used, detail) {
|
||||
Some(n) => plain(n),
|
||||
None => refine(&used, centers(&median_cut(&used, FULL_TONE_MAX, 96.0 - 88.0 * detail))),
|
||||
@@ -475,6 +508,32 @@ mod tests {
|
||||
assert_eq!(palette(Palette::Automatic, 16), automatic);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn full_tone_makes_one_color_per_step_of_color_detail() {
|
||||
// 256 grays, 1,200 pixels each: the width limit alone gives fewer colors than Color detail.
|
||||
let ramp = bins((0..256).map(|g| ([f64::from(g); 3], 1200.0)));
|
||||
let colors = |used: &[Used], color_detail: f64| {
|
||||
color_palette(used, &TraceParams { palette: Palette::FullTone, color_detail, ..TraceParams::default() }).len()
|
||||
};
|
||||
assert!(median_cut(&ramp, FULL_TONE_MAX, 96.0 - 88.0 * 0.85).len() < 85);
|
||||
assert_eq!(colors(&ramp, 85.0), 85);
|
||||
assert_eq!(colors(&ramp, 40.0), 40);
|
||||
// A picture of three colors keeps three.
|
||||
let three = bins([([0.0; 3], 100.0), ([128.0; 3], 100.0), ([255.0; 3], 100.0)]);
|
||||
assert_eq!(colors(&three, 85.0), 3);
|
||||
// A large, finely shaded area does not take the count from a small pair of reds 40 levels
|
||||
// apart, wider than one color may be at Color detail 85: the pair keeps two colors.
|
||||
let shaded = bins((0..128).map(|g| ([f64::from(g); 3], 10_000.0)).chain([([200.0, 0.0, 0.0], 1.0), ([240.0, 0.0, 0.0], 1.0)]));
|
||||
let reds = color_palette(&shaded, &TraceParams { palette: Palette::FullTone, color_detail: 85.0, ..TraceParams::default() });
|
||||
assert!(reds.len() >= 85, "{} colors", reds.len());
|
||||
for red in [200.0, 240.0] {
|
||||
assert!(reds.iter().any(|c| (c[0] - red).abs() < 1.0 && c[1] < 1.0), "no color for red {red}: {reds:?}");
|
||||
}
|
||||
// Automatic's continuous-tone colors are not raised to the count.
|
||||
let automatic = color_palette(&ramp, &TraceParams { palette: Palette::Automatic, color_detail: 85.0, ..TraceParams::default() });
|
||||
assert!(automatic.len() < 85, "{} colors with Automatic", automatic.len());
|
||||
}
|
||||
|
||||
/// `colors`, each with `n` pixels, as histogram bins.
|
||||
fn bins(colors: impl IntoIterator<Item = ([f64; 3], f64)>) -> Vec<Used> {
|
||||
colors.into_iter().enumerate().map(|(i, (c, n))| (i, c, n)).collect()
|
||||
|
||||
@@ -944,6 +944,16 @@ fn presets_have_their_paths_corners_and_noise() {
|
||||
assert_eq!(colors, [64, 20, 3, 6, 16, 8]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn high_fidelity_photo_traces_in_full_tone() {
|
||||
// As many colors as the tones need, split until no color spans more than about 21 levels, as
|
||||
// abutting shapes.
|
||||
let p = preset("High Fidelity Photo").unwrap();
|
||||
assert_eq!((p.palette, p.color_detail, p.method), (Palette::FullTone, 85.0, Method::Abutting));
|
||||
// Low Fidelity Photo keeps its 20 colors.
|
||||
assert_eq!(preset("Low Fidelity Photo").unwrap().palette, Palette::Limited);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn params_json_roundtrip_and_partial() {
|
||||
let p = preset("6 Colors").unwrap();
|
||||
@@ -1213,12 +1223,14 @@ fn full_tone_follows_the_tones_the_image_has() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn automatic_traces_flat_art_with_its_colours_and_photos_in_full_tone() {
|
||||
fn automatic_traces_flat_art_with_its_colours_and_photos_in_continuous_tone() {
|
||||
let flat = palette(&flat_quads(), Palette::Automatic, 2, 50.0);
|
||||
assert_eq!(flat.len(), 4, "the four flat colours, whatever `colors` says: {flat:?}");
|
||||
assert!(flat.iter().any(|c| c[0] > 200 && c[1] < 60 && c[2] < 60), "red is one of them: {flat:?}");
|
||||
let tone = palette(&gradient(), Palette::Automatic, 2, 50.0);
|
||||
assert_eq!(tone.len(), palette(&gradient(), Palette::FullTone, 2, 50.0).len(), "continuous tone: as Full Tone");
|
||||
// Continuous tone: as many colors as the tones need, without Full Tone's least count.
|
||||
let full = palette(&gradient(), Palette::FullTone, 2, 50.0);
|
||||
assert!(tone.len() > 4 && tone.len() <= full.len(), "{} colors, {} in Full Tone", tone.len(), full.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1713,6 +1725,56 @@ fn jitter(x: u32, y: u32, salt: u32) -> f64 {
|
||||
f64::from(v & 0xFFFF) / 32768.0 - 1.0
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn full_tone_keeps_more_of_a_noisy_ramps_tones() {
|
||||
// Gray to green with grain: Full Tone's neighboring tones are close in RGB and mixed along
|
||||
// their borders, and still look different.
|
||||
let img = Raster::from_fn(256, 96, |x, y| {
|
||||
let v = |k: u32, base: f64, slope: f64| (base + slope * f64::from(x) + 8.0 * jitter(x, y, k)).round().clamp(0.0, 255.0) as u8;
|
||||
[v(0, 100.0, 0.0), v(1, 40.0, 0.7), v(2, 100.0, 0.0), 255]
|
||||
});
|
||||
let params = TraceParams { mode: Mode::Color, palette: Palette::FullTone, color_detail: 85.0, ..TraceParams::default() };
|
||||
// Median cut gives at least 85 (one per step of Color detail). Merging the ones that look alike
|
||||
// leaves 6 (one per 30 or so levels of the ramp); merging close RGB colors would leave 4.
|
||||
let n = quantize(&img, ¶ms).palette.len();
|
||||
assert!(n >= 6, "{n} tones");
|
||||
// Automatic traces continuous tone without Full Tone's least count and keeps merging close RGB colors.
|
||||
let automatic = quantize(&img, &TraceParams { palette: Palette::Automatic, ..params }).palette.len();
|
||||
assert!(automatic < n, "{automatic} tones with Automatic, {n} with Full Tone");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn full_tone_traces_a_noisy_dark_ground_like_a_light_one() {
|
||||
// A gray ground with up to 8 levels of grain a channel. The same grain lies farther apart in
|
||||
// Oklab in a dark gray than in a light one; the dark ground still takes about as many colors
|
||||
// and shapes as the light one (32 and 53 against 31 and 52 when measured).
|
||||
let ground = |gray: f64| {
|
||||
let img = Raster::from_fn(192, 128, |x, y| {
|
||||
let c = |k: u32| (gray + 8.0 * jitter(x, y, k)).round().clamp(0.0, 255.0) as u8;
|
||||
[c(0), c(1), c(2), 255]
|
||||
});
|
||||
trace(&img, &preset("High Fidelity Photo").unwrap())
|
||||
};
|
||||
let (dark, light) = (ground(28.0), ground(200.0));
|
||||
assert!(dark.palette.len() <= light.palette.len() + 2, "{} colors dark, {} light", dark.palette.len(), light.palette.len());
|
||||
assert!(dark.paths.len() <= light.paths.len() + 6, "{} shapes dark, {} light", dark.paths.len(), light.paths.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn full_tone_merges_a_flat_colors_compression_blocks() {
|
||||
// Three flat colors stored in 8 × 8 blocks, each block off by up to 8 levels a channel, with a
|
||||
// little grain: the blocks of one color look alike and are mixed in patches, so each flat
|
||||
// color traces as one shape in Full Tone too, not as squares of near colors.
|
||||
let bases = [[200.0, 150.0, 120.0], [70.0, 120.0, 190.0], [40.0, 90.0, 40.0]];
|
||||
let img = Raster::from_fn(192, 128, |x, y| {
|
||||
let base: [f64; 3] = bases[(x / 64) as usize];
|
||||
let c = |k: u32| (base[k as usize] + 8.0 * jitter(x / 8, y / 8, k) + 1.5 * jitter(x, y, k + 7)).round().clamp(0.0, 255.0) as u8;
|
||||
[c(0), c(1), c(2), 255]
|
||||
});
|
||||
let res = trace(&img, &preset("High Fidelity Photo").unwrap());
|
||||
assert_eq!((res.palette.len(), res.paths.len()), (3, 3), "{:?}", res.palette);
|
||||
}
|
||||
|
||||
/// Three flat colours (a navy field, a yellow disc, a green bar) drawn anti-aliased, with `noise`
|
||||
/// levels of noise per channel.
|
||||
fn three_colour_art(noise: f64) -> Raster {
|
||||
@@ -2013,7 +2075,7 @@ fn a_nearly_flat_dark_ground_keeps_one_color() {
|
||||
|
||||
#[test]
|
||||
fn a_noisy_gradient_keeps_its_tones_without_specks() {
|
||||
// Tones 0–255 across with noise larger than High Fidelity Photo's 64 steps are apart.
|
||||
// Tones 0–255 across with up to 5 levels of noise a channel.
|
||||
let img = Raster::from_fn(256, 96, |x, y| {
|
||||
let c = |k: u32| (f64::from(x) + 5.0 * jitter(x, y, k)).round().clamp(0.0, 255.0) as u8;
|
||||
[c(0), c(1), c(2), 255]
|
||||
|
||||
@@ -23,7 +23,10 @@ versions. Among those presets, Corners is 100 in Technical Drawing, 75 in Defaul
|
||||
Logo, Line Art and Outline, and 50 in the other eight. Noise is 1 px in Technical Drawing, 5 in High Fidelity Photo and Black and White Logo, 8 in 6 Colors
|
||||
and 16 Colors, 10 in Low Fidelity Photo, 15 in 3 Colors and Shades of Gray, 20 in Sketched Art, Line
|
||||
Art and Outline, 25 in Default, and 90 in Silhouettes (see
|
||||
[image-trace-quality.md](image-trace-quality.md#preset-paths-corners-and-noise)).
|
||||
[image-trace-quality.md](image-trace-quality.md#preset-paths-corners-and-noise)). High Fidelity Photo
|
||||
traces with Palette › Full Tone at Color detail 85 and Method › Abutting (VectorCraft's own values; see
|
||||
[image-trace-quality.md](image-trace-quality.md#high-fidelity-photo-in-full-tone)); Low Fidelity Photo
|
||||
traces with a Limited palette of 20 colors, Overlapping.
|
||||
|
||||
Sliders apply on release, and their numeric fields can be edited directly. Each committed
|
||||
adjustment re-traces the selected object as one undo step and changes the preset to Custom.
|
||||
@@ -83,9 +86,9 @@ leaves out every white area whatever `ignoreBackground` is.
|
||||
color nearest to it in lightness and hue, with a difference in hue or chroma counted three times
|
||||
as much as one in lightness, so a gray or a muted brown takes a black, white or other neutral
|
||||
library color rather than a saturated color of the same lightness.
|
||||
**Abutting and Overlapping.** Abutting is the default Method, and the Default, Auto Color, 3 Colors,
|
||||
6 Colors and 16 Colors presets use it. With Abutting, two neighboring colors share one exact edge. The
|
||||
canvas smooths the edges of each path on its own, so each of the two paths covers only part of the
|
||||
**Abutting and Overlapping.** Abutting is the default Method, and the Default, Auto Color, High Fidelity
|
||||
Photo, 3 Colors, 6 Colors and 16 Colors presets use it. With Abutting, two neighboring colors share one
|
||||
exact edge. The canvas smooths the edges of each path on its own, so each of the two paths covers only part of the
|
||||
pixels along that edge, and a thin line of the background can show between the colors. Web browsers
|
||||
and PDF viewers usually draw an exported SVG or PDF file the same way and show the same line. Raster
|
||||
exports (PNG, JPEG, TIFF and the other bitmap formats) with None anti-aliasing do not show it at any
|
||||
|
||||
@@ -83,8 +83,9 @@ gradient, texture, sensor noise):
|
||||
Photo trace was 86,000 anchors under the old limit; a noisier scan of the same size would have been
|
||||
refused. At 8,000,000 anchors a trace keeps about 0.7 GB, with a peak of about 0.9 GB while tracing.
|
||||
The preset rows were measured with the earlier preset values: High Fidelity Photo at Paths 90, Corners 25
|
||||
and Noise 4, Low Fidelity Photo at Paths 60, Noise 12 and 16 Colors at Paths 70, Corners 55 and Noise 10
|
||||
(see [Preset Paths, Corners and Noise](#preset-paths-corners-and-noise)).
|
||||
and Noise 4 with a Limited palette of 64 colors and Overlapping, Low Fidelity Photo at Paths 60, Noise 12
|
||||
and 16 Colors at Paths 70, Corners 55 and Noise 10 (see [Preset Paths, Corners and
|
||||
Noise](#preset-paths-corners-and-noise) and [High Fidelity Photo in Full Tone](#high-fidelity-photo-in-full-tone)).
|
||||
## Collapsed loops keep few segments
|
||||
A small closed loop (or a piece that returns to its own junction) whose fit collapsed to a single
|
||||
cubic cannot stay as one, so it kept every positioned point as a straight segment. A looser Paths
|
||||
@@ -250,7 +251,8 @@ Every built-in preset other than Auto Color and Flat Logo traces at Paths 50. Co
|
||||
The palettes, color counts, thresholds and other options of the presets did not change. The enhanced
|
||||
versions of these presets use the same Paths, Corners and Noise. 6 Colors and 16 Colors were at Noise 15
|
||||
and Black and White Logo at 25 until [Noise joins the nearest color](#noise-joins-the-nearest-color);
|
||||
the measurements below were made at those values.
|
||||
the measurements below were made at those values. High Fidelity Photo's palette and Method changed
|
||||
later (see [High Fidelity Photo in Full Tone](#high-fidelity-photo-in-full-tone)).
|
||||
|
||||
Measured with the harness below (section 1, each preset on the inputs it is meant for), before and after:
|
||||
anchors fall in 10 of the 12 changed presets, for example 5,494 to 3,136 (High Fidelity Photo), 33 to 27
|
||||
@@ -271,6 +273,47 @@ the other sections of this file, and in the Image Trace entries of
|
||||
[target-app-parity.md](target-app-parity.md), were measured at the earlier values.
|
||||
Test: `presets_have_their_paths_corners_and_noise` in `crates/trace/src/tests.rs`.
|
||||
|
||||
## High Fidelity Photo in Full Tone
|
||||
High Fidelity Photo traces with Palette › Full Tone at Color detail 85 and Method › Abutting. It traced
|
||||
with a Limited palette of 64 colors, Overlapping, before. Paths, Corners and Noise stay 50, 50 and 5.
|
||||
These are VectorCraft's own values. Low Fidelity Photo keeps its Limited palette of 20 colors.
|
||||
|
||||
Palette › Full Tone splits its colors until none spans more than its width limit. Then, while it has
|
||||
fewer colors than Color detail's value (85 at 85), it splits the narrower ones too, where the image has
|
||||
that many colors. The colors that look alike merge after that, and a merged color can merge again, so a
|
||||
trace can end with far fewer colors than that count: a gray-to-green ramp 256 px wide with up to 8 levels
|
||||
of grain a channel ends with 6 colors at Color detail 85, where the RGB test leaves 4. Full Tone's colors
|
||||
merge when they are thoroughly mixed and less than 5 apart in Oklab × 100, or mixed in patches
|
||||
(compression blocks) and less than 1.5 apart. The other palettes, Automatic included, keep the RGB test
|
||||
(under 30 levels and thoroughly mixed, or under 12 and mixed in patches), and Automatic's continuous-tone
|
||||
colors do not take the least count. These rules apply to every trace with Palette › Full Tone, so an
|
||||
existing Full Tone trace or saved preset traces differently when it is traced again.
|
||||
|
||||
On 19 photos, cartoons and synthetic shapes of 400 to 4,000 px, the mean pixel difference summed over the
|
||||
inputs fell from 80.5 to 65.6 levels. It fell by more than 1% on 14 inputs (2.88 to 2.19 and 2.59 to 2.48
|
||||
on two photos, the second a JPEG at quality 40; 1.88 to 1.45 on a 4000 × 3000 photo; 12.40 to 7.44 on an
|
||||
upscaled cartoon) and changed by less than 1% on the other 5. Anchors rose 1.66 times (1.98 million to
|
||||
3.29 million) and the SVG size 1.31 times. The trace time rose 1.7 times (18.9 to 31.5 s for all 19, with
|
||||
both builds tracing 3 images at a time in the same run). Flat synthetic art costs the most: 12 to 400
|
||||
anchors on a 4000 × 3000 image of two flat colors, and about 3 times the anchors on two images of
|
||||
synthetic shapes (400 × 300 and 1600 × 1200), with the same pixel difference. A flat gray 192 × 128 with
|
||||
up to 3 levels of grain a channel traces as 25 colors and 244 anchors, where the Limited palette of 64
|
||||
traced 1 color and 4 anchors; with up to 5 or 8 levels both trace it as 25 to 37 colors, on each of the
|
||||
grays tested (28, 60, 128 and 200).
|
||||
|
||||
In the same run, peak memory fell on 16 of the 19 inputs, for example 906 to 625 MiB on a 1536 × 2048
|
||||
cartoon, and rose on 3 small ones (by 5 to 11 MiB). Abutting accounts for the fall: the earlier preset
|
||||
with Method › Abutting peaked at 523 MiB on the same cartoon, against 924 MiB with Overlapping, in another
|
||||
run. Low Fidelity Photo, 16 Colors, 6 Colors, Black and White Logo and Auto Color give byte-identical
|
||||
SVGs. On three flat colors stored in 8 × 8 blocks, each block off by up to 8 levels a channel, High
|
||||
Fidelity Photo traces 3 colors as 3 paths; without the patch rule it traced 7 colors as 74 paths.
|
||||
|
||||
Tests: `high_fidelity_photo_traces_in_full_tone`, `full_tone_keeps_more_of_a_noisy_ramps_tones`,
|
||||
`full_tone_traces_a_noisy_dark_ground_like_a_light_one` and
|
||||
`full_tone_merges_a_flat_colors_compression_blocks` in `crates/trace/src/tests.rs`,
|
||||
`full_tone_merges_only_mixed_colors_that_look_alike` in `crates/trace/src/quantize.rs`, and
|
||||
`full_tone_makes_one_color_per_step_of_color_detail` in `crates/trace/src/quantize/palette.rs`.
|
||||
|
||||
## A simpler contour walk
|
||||
`contour::trace_mask` follows each region's outline along the pixel cracks with the inside on the
|
||||
right. It used to build a table of outgoing directions for every pixel corner in a raster pass and
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user