30 lines
645 B
Rust
30 lines
645 B
Rust
use crate::{Histogram, Pixel, PixelTransform, RawImage, CHANNELS_IN_RGB};
|
|
|
|
impl RawImage {
|
|
pub fn record_histogram_fn(&self) -> RecordHistogram {
|
|
RecordHistogram::new()
|
|
}
|
|
}
|
|
|
|
pub struct RecordHistogram {
|
|
pub histogram: Histogram,
|
|
}
|
|
|
|
impl RecordHistogram {
|
|
fn new() -> RecordHistogram {
|
|
RecordHistogram {
|
|
histogram: [[0; 0x2000]; CHANNELS_IN_RGB],
|
|
}
|
|
}
|
|
}
|
|
|
|
impl PixelTransform for &mut RecordHistogram {
|
|
fn apply(&mut self, pixel: Pixel) -> [u16; CHANNELS_IN_RGB] {
|
|
self.histogram
|
|
.iter_mut()
|
|
.zip(pixel.values.iter())
|
|
.for_each(|(histogram, &value)| histogram[value as usize >> CHANNELS_IN_RGB] += 1);
|
|
pixel.values
|
|
}
|
|
}
|