Only reconstruct on debug

This commit is contained in:
2024-05-12 10:44:15 +02:00
parent 3c657404f2
commit a0c1a650b0
+19 -17
View File
@@ -1,7 +1,7 @@
use image::{save_buffer, GenericImageView}; use image::{save_buffer, GenericImageView};
use std::f64::consts::{PI, SQRT_2}; use std::f64::consts::{PI, SQRT_2};
use crate::descriptors::{Descriptor, DCT, print_matrix}; use crate::descriptors::{Descriptor, DCT, print_matrix};
use log::debug; use log::{debug, log_enabled, Level};
impl DCT { impl DCT {
@@ -114,23 +114,25 @@ impl Descriptor for DCT {
} }
debug!("DCT-coefficients, quantized:\n {}", print_matrix(dct_values)); debug!("DCT-coefficients, quantized:\n {}", print_matrix(dct_values));
// De-quantization: if log_enabled!(Level::Debug) {
for i in 0..64 { // De-quantization:
dct_values[i] = dct_values[i] * self.quantization_matrix[i] as f64; for i in 0..64 {
dct_values[i] = dct_values[i] * self.quantization_matrix[i] as f64;
}
debug!("DCT-coefficients, de-quantized:\n {}", print_matrix(dct_values));
// Reconstruction original pixel values:
let reconstructed = self.idct(dct_values);
debug!("Reconstructed pixel values:\n{}", print_matrix(reconstructed));
save_buffer(
"reconstructed.png",
&reconstructed,
8,
8,
image::ColorType::L8
).expect("Error saving buffer");
} }
debug!("DCT-coefficients, de-quantized:\n {}", print_matrix(dct_values));
// Reconstruction original pixel values:
let reconstructed = self.idct(dct_values);
debug!("Reconstructed pixel values:\n{}", print_matrix(reconstructed));
save_buffer(
"reconstructed.png",
&reconstructed,
8,
8,
image::ColorType::L8
).expect("Error saving buffer");
// Calculating descriptor from dct values: // Calculating descriptor from dct values:
let mut mask: u64 = 0; let mut mask: u64 = 0;