Mutator updates, linting
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit is contained in:
2024-07-08 10:38:42 +02:00
parent ead1cf9931
commit 8c4bb53608
2 changed files with 37 additions and 8 deletions
+3 -4
View File
@@ -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 {
@@ -69,9 +68,9 @@ impl DCT {
}
}
dct_values
}
}
fn idct(&self, dct_values: [f64; 64]) -> [u8; 64] {
fn idct(&self, dct_values: [f64; 64]) -> [u8; 64] {
let mut reconstructed: [u8; 64] = [0; 64];
//for k in 0..64 {
for (k, item) in reconstructed.iter_mut().enumerate() {
@@ -216,4 +215,4 @@ impl Descriptor for DCT {
// TODO: Do something with these last 8 bits.
mask
}
}
}
+34 -4
View File
@@ -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![