forked from etemesi254/zune-image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvert.rs
46 lines (38 loc) · 815 Bytes
/
invert.rs
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::ops::Sub;
use crate::traits::NumOps;
///Invert a pixel
///
/// The formula for inverting a 8 bit pixel
/// is `pixel[x,y] = 255-pixel[x,y]`
pub fn invert<T>(in_image: &mut [T])
where
T: NumOps<T> + Sub<Output = T> + Copy
{
for pixel in in_image.iter_mut()
{
*pixel = T::max_val() - *pixel;
}
}
#[cfg(all(feature = "benchmarks"))]
#[cfg(test)]
mod benchmarks
{
extern crate test;
use crate::invert::invert;
#[bench]
fn invert_u8(b: &mut test::Bencher)
{
let mut in_out = vec![0_u8; 800 * 800];
b.iter(|| {
invert(&mut in_out);
});
}
#[bench]
fn invert_u16(b: &mut test::Bencher)
{
let mut in_out = vec![0_u8; 800 * 800];
b.iter(|| {
invert(&mut in_out);
});
}
}