Skip to content

Commit

Permalink
Add a simplified convert() function
Browse files Browse the repository at this point in the history
This lets the user convert an image from memory, without encoding it to
PNG, writing it to a file, then reopening this file and decoding it
using the image crate.

It also allows the user to not write a SVG directly to a file.
  • Loading branch information
linkmauve committed Oct 29, 2023
1 parent 2b5b574 commit 1361c50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 10 additions & 5 deletions cmdapp/src/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ const NUM_UNUSED_COLOR_ITERATIONS: usize = 6;
/// the entire image will be keyed.
const KEYING_THRESHOLD: f32 = 0.2;

/// Convert an image file into svg file
pub fn convert(img: ColorImage, config: Config) -> Result<SvgFile, String> {
let config = config.into_converter_config();
match config.color_mode {
ColorMode::Color => color_image_to_svg(img, config),
ColorMode::Binary => binary_image_to_svg(img, config),
}
}

/// Convert an image file into svg file
pub fn convert_image_to_svg(input_path: &Path, output_path: &Path, config: Config) -> Result<(), String> {
let img = read_image(input_path)?;
let config = config.into_converter_config();
let svg = match config.color_mode {
ColorMode::Color => color_image_to_svg(img, config)?,
ColorMode::Binary => binary_image_to_svg(img, config)?,
};
let svg = convert(img, config)?;
write_svg(svg, output_path)
}

Expand Down
3 changes: 2 additions & 1 deletion cmdapp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ pub use config::*;
pub use converter::*;
pub use svg::*;
#[cfg(feature = "python-binding")]
pub use python::*;
pub use python::*;
pub use visioncortex::ColorImage;

0 comments on commit 1361c50

Please sign in to comment.