Mutator updates, linting
This commit is contained in:
@@ -29,7 +29,6 @@ impl DCT {
|
||||
50..=100 => 200.0 - 2.0*quality as f32,
|
||||
_ => 100.0 // Invalid input: set to base quality
|
||||
};
|
||||
//for i in 0..64 {
|
||||
for (_, cell) in quantization_matrix.iter_mut().enumerate() {
|
||||
*cell = ((scalar * *cell as f32 + 50.0) / 100.0).floor() as u8;
|
||||
if *cell == 0 {
|
||||
|
||||
+34
-4
@@ -1,5 +1,8 @@
|
||||
//! Mutators that can be used to mutate an image.
|
||||
//! These mutated images can be used as a "near copy"
|
||||
use image::{Rgb, Rgba};
|
||||
use imageproc::definitions::Image;
|
||||
use imageproc::geometric_transformations::*;
|
||||
|
||||
pub trait Mutator {
|
||||
/// Name/description of the mutator
|
||||
@@ -15,7 +18,7 @@ pub trait Mutator {
|
||||
fn mutate(&self, img: &image::DynamicImage) -> image::DynamicImage;
|
||||
}
|
||||
|
||||
/// Horizontal flip/mirror
|
||||
/// Horizontal mirror
|
||||
pub struct Flip;
|
||||
impl Mutator for Flip {
|
||||
fn info(&self) -> String {
|
||||
@@ -29,7 +32,7 @@ impl Mutator for Flip {
|
||||
}
|
||||
}
|
||||
|
||||
/// Slight hue-shift
|
||||
/// Hue shift
|
||||
pub struct Hue;
|
||||
impl Mutator for Hue {
|
||||
fn info(&self) -> String {
|
||||
@@ -43,7 +46,7 @@ impl Mutator for Hue {
|
||||
}
|
||||
}
|
||||
|
||||
/// Slight sharpen (unsharp mask)
|
||||
/// Unsharp mask
|
||||
pub struct Sharp;
|
||||
impl Mutator for Sharp {
|
||||
fn info(&self) -> String {
|
||||
@@ -57,7 +60,6 @@ impl Mutator for Sharp {
|
||||
}
|
||||
}
|
||||
|
||||
/// Slight blur
|
||||
pub struct Blur;
|
||||
impl Mutator for Blur {
|
||||
fn info(&self) -> String {
|
||||
@@ -71,6 +73,34 @@ impl Mutator for Blur {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BlurSharp;
|
||||
impl Mutator for BlurSharp {
|
||||
fn info(&self) -> String {
|
||||
"Blur and sharpen".to_string()
|
||||
}
|
||||
fn tag(&self) -> String {
|
||||
".blsh.".to_string()
|
||||
}
|
||||
fn mutate(&self, img: &image::DynamicImage) -> image::DynamicImage {
|
||||
img.blur(1.5).unsharpen(1.5, 20)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RotateCrop;
|
||||
impl Mutator for RotateCrop {
|
||||
fn info(&self) -> String {
|
||||
"Rotate and crop".to_string()
|
||||
}
|
||||
fn tag(&self) -> String {
|
||||
".rcrop.".to_string()
|
||||
}
|
||||
fn mutate(&self, img: &image::DynamicImage) -> image::DynamicImage {
|
||||
let img: Image<Rgb<u8>> = img.to_rgb8();
|
||||
let default = *img.get_pixel(0, 0);
|
||||
image::DynamicImage::ImageRgb8(rotate_about_center(&img, 0.1, Interpolation::Bicubic, default))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_all_mutators() -> Vec<Box<dyn Mutator>> {
|
||||
let mutators: Vec<Box<dyn Mutator>> = //Vec::with_capacity(4);
|
||||
vec![
|
||||
|
||||
Reference in New Issue
Block a user