main.rs 910 B

123456789101112131415161718192021222324252627282930313233343536
  1. mod opts;
  2. use crate::opts::Options;
  3. use clap::Parser;
  4. use std::path::Path;
  5. use thyme::{data::Mapping, file::ThymeFile, image::Image};
  6. fn main() -> Result<(), Box<dyn std::error::Error>> {
  7. // read the command-line options
  8. let opts = Options::parse();
  9. let image_path = Path::new(&opts.image);
  10. // load the PNG image for the pattern
  11. let image = Image::load(image_path)?;
  12. // load the color map file
  13. let mapping = Mapping::load(opts.mapping, &image)?;
  14. let thyme = ThymeFile::from_image_and_config(&image, &mapping);
  15. let output_filename = match opts.output {
  16. Some(s) => Path::new(&s).to_path_buf(),
  17. None => {
  18. let mut path = image_path.to_path_buf();
  19. path.set_extension("thyme");
  20. path
  21. }
  22. };
  23. {
  24. let mut f = std::fs::File::create(output_filename)?;
  25. thyme.to_stream(&mut f)?;
  26. }
  27. Ok(())
  28. }