Skip to content
Snippets Groups Projects
Verified Commit e30bbbb6 authored by Louis's avatar Louis :fire:
Browse files

Apply clippy lints

parent 8b705ed7
No related branches found
No related tags found
No related merge requests found
use clap::{Parser, Subcommand}; use clap::Parser;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
// use crate::commands::{calculate_mapping, execute_pipeline, extrude, flip, palette, remap_image, rescale, rotate, write_palette, FlipDirection, RotateDegree, Rotate}; // use crate::commands::{calculate_mapping, execute_pipeline, extrude, flip, palette, remap_image, rescale, rotate, write_palette, FlipDirection, RotateDegree, Rotate};
use crate::commands::{Extrude, Flip, Palette, Pipeline, Remap, Rotate, Scale}; use crate::commands::{Extrude, Flip, Palette, Pipeline, Remap, Rotate, Scale};
use crate::format::PaletteFormat;
use crate::{load_image, Format}; use crate::load_image;
/// Crunch is a set of utilities for quickly and easily processing a batch of files, either directly /// Crunch is a set of utilities for quickly and easily processing a batch of files, either directly
/// or by defining pipelines /// or by defining pipelines
......
use crate::utils::{OutputFormat, RgbaOutputFormat, SpriteData}; use crate::utils::{RgbaOutputFormat, SpriteData};
use clap::Parser; use clap::Parser;
use image::{GenericImage, GenericImageView, Pixel, Rgba, RgbaImage}; use image::{GenericImage, GenericImageView, Pixel, Rgba, RgbaImage};
use num_traits::cast::ToPrimitive; use num_traits::cast::ToPrimitive;
......
...@@ -2,9 +2,8 @@ use clap::Parser; ...@@ -2,9 +2,8 @@ use clap::Parser;
use std::cmp::{min, Ordering}; use std::cmp::{min, Ordering};
use std::collections::hash_map::RandomState; use std::collections::hash_map::RandomState;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::fmt::{Formatter, LowerHex, UpperHex};
use std::io::Write; use std::io::Write;
use std::path::Path;
use deltae::{Delta, LabValue, DE2000}; use deltae::{Delta, LabValue, DE2000};
use image::{GenericImage, Pixel, Rgba}; use image::{GenericImage, Pixel, Rgba};
......
...@@ -92,86 +92,80 @@ impl Pipeline { ...@@ -92,86 +92,80 @@ impl Pipeline {
log::debug!("Expanding pipeline file into targets"); log::debug!("Expanding pipeline file into targets");
let base_path = PathBuf::from(path.parent().unwrap()); let base_path = PathBuf::from(path.parent().unwrap());
get_targets(base_path.clone(), &pipeline_data).for_each( get_targets(base_path, &pipeline_data).for_each(|(input_path, output_path, actions)| {
|(input_path, output_path, actions)| { match make_paths(&output_path) {
match make_paths(&output_path) { Ok(_) => {}
Err(e) => {
log::error!("Failed to create target directory {}; {}", &output_path, e);
return;
}
}
if actions.is_empty() {
match std::fs::copy(&input_path, &output_path) {
Ok(_) => {} Ok(_) => {}
Err(e) => { Err(e) => {
log::error!("Failed to create target directory {}; {}", &output_path, e); log::error!("Failed to copy {} to {}; {}", input_path, output_path, e);
return;
} }
} };
return;
}
if actions.is_empty() { let mut file = result!(load_image(&input_path, None));
match std::fs::copy(&input_path, &output_path) {
Ok(_) => {}
Err(e) => {
log::error!("Failed to copy {} to {}; {}", input_path, output_path, e);
}
};
return;
}
let mut file = result!(load_image(&input_path, None)); log::debug!(
"Loaded {}, Executing {} actions",
log::debug!( &input_path,
"Loaded {}, Executing {} actions", actions.len()
&input_path, );
actions.len()
); for step in actions {
match step {
let mut count = 1; Args::Rotate(rotate) => {
for step in actions { file = result!(rotate.run(&file));
match step { }
Args::Rotate(rotate) => { Args::Extrude(extrude) => {
file = result!(rotate.run(&file)); file = result!(extrude.run(&file));
}
Args::Extrude(extrude) => {
file = result!(extrude.run(&file));
}
Args::Scale(scale) => {
file = result!(scale.run(&file));
}
Args::Flip(flip) => {
file = result!(flip.run(&file));
}
Args::Remap(remap) => {
let palette = result!(load_image(&remap.palette, None));
let image_palette = result!(Palette::extract_from(&file));
let target_palette = result!(Palette::extract_from(&palette));
let mappings =
Palette::calculate_mapping(&image_palette, &target_palette);
file = result!(Remap::remap_image(file, mappings));
}
_ => {}
} }
Args::Scale(scale) => {
file = result!(scale.run(&file));
}
Args::Flip(flip) => {
file = result!(flip.run(&file));
}
Args::Remap(remap) => {
let palette = result!(load_image(&remap.palette, None));
let image_palette = result!(Palette::extract_from(&file));
let target_palette = result!(Palette::extract_from(&palette));
count += 1; let mappings = Palette::calculate_mapping(&image_palette, &target_palette);
file = result!(Remap::remap_image(file, mappings));
}
_ => {}
} }
}
let mut outer_target_path = PathBuf::from(&output_path); let mut outer_target_path = PathBuf::from(&output_path);
outer_target_path.pop(); outer_target_path.pop();
if let Err(e) = std::fs::create_dir(&outer_target_path) { if let Err(e) = std::fs::create_dir(&outer_target_path) {
match e.kind() { match e.kind() {
std::io::ErrorKind::AlreadyExists => { /* This is fine */ } std::io::ErrorKind::AlreadyExists => { /* This is fine */ }
_ => log::error!( _ => log::error!(
"Failed to create containing directory {}; {}", "Failed to create containing directory {}; {}",
outer_target_path.to_string_lossy(), outer_target_path.to_string_lossy(),
e e
), ),
}
} }
}
match file.save(&output_path) { match file.save(&output_path) {
Ok(_) => {} Ok(_) => {}
Err(e) => { Err(e) => {
log::error!("Failed to save to {}; {}", output_path, e); log::error!("Failed to save to {}; {}", output_path, e);
}
} }
}, }
); });
Ok(()) Ok(())
} }
...@@ -211,7 +205,7 @@ fn get_targets( ...@@ -211,7 +205,7 @@ fn get_targets(
( (
join(&base_path, &input_path), join(&base_path, &input_path),
join(&base_path, &output_path), join(&base_path, &output_path),
(*value).actions.clone(), value.actions.clone(),
) )
}) })
.collect(), .collect(),
...@@ -223,7 +217,7 @@ fn get_targets( ...@@ -223,7 +217,7 @@ fn get_targets(
.refs .refs
.get(reference.as_str()) .get(reference.as_str())
.iter() .iter()
.map(|value| (*value).actions.clone()) .map(|value| value.actions.clone())
.flat_map(|actions| { .flat_map(|actions| {
let mut paths = Vec::new(); let mut paths = Vec::new();
let target_path = join(&base_path, pattern); let target_path = join(&base_path, pattern);
......
...@@ -4,7 +4,7 @@ use image::{GenericImage, Pixel, Rgba}; ...@@ -4,7 +4,7 @@ use image::{GenericImage, Pixel, Rgba};
use num_traits::ToPrimitive; use num_traits::ToPrimitive;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::utils::{new_image, BasicRgba, OutputFormat, TypedOutputFormat}; use crate::utils::{new_image, BasicRgba, OutputFormat};
/// Convert the colour space of an image to that of a given palette file /// Convert the colour space of an image to that of a given palette file
#[derive(Debug, Clone, Parser, Serialize, Deserialize)] #[derive(Debug, Clone, Parser, Serialize, Deserialize)]
......
...@@ -4,10 +4,9 @@ mod format; ...@@ -4,10 +4,9 @@ mod format;
mod utils; mod utils;
use clap::Parser; use clap::Parser;
use image::{GenericImage, Rgba, SubImage};
use crate::cli_args::Args; use crate::cli_args::Args;
use crate::format::{load_image, Format}; use crate::format::load_image;
fn main() -> anyhow::Result<(), anyhow::Error> { fn main() -> anyhow::Result<(), anyhow::Error> {
env_logger::Builder::from_env("LOG_LEVEL").init(); env_logger::Builder::from_env("LOG_LEVEL").init();
......
...@@ -5,7 +5,6 @@ use deltae::LabValue; ...@@ -5,7 +5,6 @@ use deltae::LabValue;
use glam::Vec3; use glam::Vec3;
use image::{GenericImage, GenericImageView, Rgb, Rgba, RgbaImage, SubImage}; use image::{GenericImage, GenericImageView, Rgb, Rgba, RgbaImage, SubImage};
use lab::Lab; use lab::Lab;
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub struct SpriteData<'a, T: GenericImage> { pub struct SpriteData<'a, T: GenericImage> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment