File size: 645 Bytes
2409829
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::{CHANNELS_IN_RGB, Histogram, Pixel, PixelTransform, RawImage};

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
	}
}