Revert "Experiment with idealizing small circles"

This reverts commit c3012c6aef.
This commit is contained in:
Chris Tsang
2024-03-29 18:58:06 +00:00
parent 177797108d
commit ddb47e1ad4
2 changed files with 11 additions and 28 deletions

View File

@@ -13,7 +13,7 @@ keywords = ["svg", "computer-graphics"]
[dependencies] [dependencies]
clap = "2.33.3" clap = "2.33.3"
image = "0.23.10" image = "0.23.10"
visioncortex = { version = "0.8.4" } visioncortex = { version = "0.8.1" }
fastrand = "1.8" fastrand = "1.8"
pyo3 = { version = "0.19.0", optional = true } pyo3 = { version = "0.19.0", optional = true }

View File

@@ -5,17 +5,13 @@ use super::config::{ColorMode, Config, ConverterConfig, Hierarchical};
use super::svg::SvgFile; use super::svg::SvgFile;
use fastrand::Rng; use fastrand::Rng;
use visioncortex::color_clusters::{KeyingAction, Runner, RunnerConfig, HIERARCHICAL_MAX}; use visioncortex::color_clusters::{KeyingAction, Runner, RunnerConfig, HIERARCHICAL_MAX};
use visioncortex::{ use visioncortex::{Color, ColorImage, ColorName};
approximate_circle_with_spline, Color, ColorImage, ColorName, CompoundPath, PathSimplifyMode,
};
const NUM_UNUSED_COLOR_ITERATIONS: usize = 6; const NUM_UNUSED_COLOR_ITERATIONS: usize = 6;
/// The fraction of pixels in the top/bottom rows of the image that need to be transparent before /// The fraction of pixels in the top/bottom rows of the image that need to be transparent before
/// the entire image will be keyed. /// the entire image will be keyed.
const KEYING_THRESHOLD: f32 = 0.2; const KEYING_THRESHOLD: f32 = 0.2;
const SMALL_CIRCLE: i32 = 12;
/// Convert an in-memory image into an in-memory SVG /// Convert an in-memory image into an in-memory SVG
pub fn convert(img: ColorImage, config: Config) -> Result<SvgFile, String> { pub fn convert(img: ColorImage, config: Config) -> Result<SvgFile, String> {
let config = config.into_converter_config(); let config = config.into_converter_config();
@@ -171,28 +167,15 @@ fn color_image_to_svg(mut img: ColorImage, config: ConverterConfig) -> Result<Sv
let mut svg = SvgFile::new(width, height, config.path_precision); let mut svg = SvgFile::new(width, height, config.path_precision);
for &cluster_index in view.clusters_output.iter().rev() { for &cluster_index in view.clusters_output.iter().rev() {
let cluster = view.get_cluster(cluster_index); let cluster = view.get_cluster(cluster_index);
let paths = if matches!(config.mode, PathSimplifyMode::Spline) let paths = cluster.to_compound_path(
&& cluster.rect.width() < SMALL_CIRCLE &view,
&& cluster.rect.height() < SMALL_CIRCLE false,
&& cluster.to_shape(&view).is_circle() config.mode,
{ config.corner_threshold,
let mut paths = CompoundPath::new(); config.length_threshold,
paths.add_spline(approximate_circle_with_spline( config.max_iterations,
cluster.rect.left_top(), config.splice_threshold,
cluster.rect.width(), );
));
paths
} else {
cluster.to_compound_path(
&view,
false,
config.mode,
config.corner_threshold,
config.length_threshold,
config.max_iterations,
config.splice_threshold,
)
};
svg.add_path(paths, cluster.residue_color()); svg.add_path(paths, cluster.residue_color());
} }