mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-13 23:35:10 +00:00
In a gradient or a shaded area the palette colors on either side of a band border differ by more than the image changes across it, so pixel noise decided where the border ran, and it was smoothed over 0.5 px like a real edge: borders wobbled, kept stair steps and took many anchors. Each crack between two colors now records how much of the step between them the image makes next to it and a few pixels further out, how much the image changes there along the line between the two colors and in any direction, and how much it changes within each side (RGB distances, 0 to 255 a channel). A piece of outline is the contour of a smooth area when its cracks show less than half of the step; either more of it further out, a change along the line under 12, or no opaque pixels further out; some change within the sides, at least 1/32 of the change along the line; and a whole change under twice the change along the line, or under 24. Such a piece is smoothed over 4 px (a closed one over at most an eighth of its smaller width or height), keeps no corners, is fitted to at least 0.5 px and is checked against its smoothed points. The values are the same from either side of the crack. Grayscale reads each pixel as its gray, for this rule and for every edge's sub-pixel shift, which compared the pixels' colors with gray palette entries. Color traces of clean flat-color art and Black and White traces are unchanged. Specks rise by up to 0.8 per image on gradient and photo inputs, and Auto Color with Shapes leaves a 0.3 px gap there. Docs: docs/target-app-parity.md, docs/image-trace-quality.md.
33 lines
1.4 KiB
Rust
33 lines
1.4 KiB
Rust
//! Logo mode: flat-colour logos traced to clean, sub-pixel-accurate vector shapes.
|
|
//!
|
|
//! The tracer in the other modes follows hard pixel edges, so an outline can only be as good as
|
|
//! the pixel grid. Here each pixel is read as a *blend* of the logo's flat colours, the blend is
|
|
//! interpolated smoothly, and every outline is placed where two colours are equally present, to a
|
|
//! fraction of a pixel. The outlines are then cleaned the way a person would: corners the blur
|
|
//! rounded are put back, straight runs and circular arcs become exact lines and arcs, and the
|
|
//! rest is fitted with as few Bézier curves as the tolerance allows. Areas of transparency
|
|
//! fully enclosed by artwork (letters knocked out of a badge, the counters of an "o") are painted
|
|
//! white, so the logo reads the same on any background; with Ignore White they stay real holes.
|
|
//! Flat-colour logos only: gradients and photos are refused ([`TraceError::NotFlat`](crate::TraceError)).
|
|
|
|
mod bezier;
|
|
mod field;
|
|
mod geom;
|
|
mod march;
|
|
mod outline;
|
|
mod palette;
|
|
mod pipeline;
|
|
mod restore;
|
|
#[cfg(test)]
|
|
mod tests;
|
|
#[cfg(test)]
|
|
mod testutil;
|
|
mod unmix;
|
|
|
|
pub(crate) use bezier::{fit_cubics, tangent};
|
|
pub(crate) use geom::{Cubic, all_within, resample_closed, resample_open, sample_cubics, smooth_closed, smooth_pinned};
|
|
pub(crate) use outline::{Stats, Style, fit_open, fit_outline};
|
|
pub(crate) use palette::parse_hex;
|
|
pub(crate) use pipeline::trace_logo;
|
|
pub(crate) use restore::RestoreParams;
|