refactor dct and quality

This commit is contained in:
2024-05-08 10:12:53 +02:00
parent 31351ea91d
commit 1aa32a3788
3 changed files with 68 additions and 62 deletions
+8 -5
View File
@@ -13,22 +13,25 @@ pub trait Descriptor {
/// Interprets a 64-element array as an 8x8 matrix
/// returns a nicely printable string
fn print_matrix<T: ToString>(array: [T; 64]) -> String {
fn print_matrix<T: ToString + std::fmt::Display>(array: [T; 64]) -> String {
let mut output = String::new();
for x in 0..8 {
for y in 0..8 {
output.push_str(&array[x*8+y].to_string());
output.push_str(",\t");
let element = format!("{:.2}", &array[x*8+y]);
let element = format!("{:8}\t", element);
output.push_str(&element);
}
output.push('\n');
}
output
}
/// A struct representing a Discrete Cosine Transform descriptor
/// Transforms an image into an 8x8 grayscale version, and transforms it
/// into the frequency domain
pub struct DCT {
quantization_matrix: [u8; 64],
quantization_matrix: [u8; 64]
}
pub mod dct;
// fn median64<T: Ord + Copy>(values: &[T]) -> T {