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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
extern crate image;
extern crate rand;
use image::{GenericImage, GenericImageView};
use rand::Rng;
use image::{Pixel};
use crate::{PhotonImage};
use crate::{helpers};
pub fn add_noise_rand(mut photon_image: PhotonImage) -> PhotonImage {
let mut img = helpers::dyn_image_from_raw(&photon_image);
let (width, height) = img.dimensions();
let mut rng = rand::thread_rng();
for x in 0..width {
for y in 0..height {
let offset = rng.gen_range(0, 150);
let px = img.get_pixel(x, y).map(|ch| if ch <= 255 - offset { ch + offset } else { 255});
img.put_pixel(x, y, px);
}
}
photon_image.raw_pixels = img.raw_pixels();
return photon_image;
}
pub fn pink_noise(mut photon_image: &mut PhotonImage) {
let mut img = helpers::dyn_image_from_raw(&photon_image);
let (width, height) = img.dimensions();
let mut rng = rand::thread_rng();
for x in 0..width {
for y in 0..height {
let ran1: f64 = rng.gen();
let ran2: f64 = rng.gen();
let ran3: f64 = rng.gen();
let ran_color1: f64 = 0.6 + ran1 * 0.6;
let ran_color2: f64 = 0.6 + ran2 * 0.1;
let ran_color3: f64 = 0.6 + ran3 * 0.4;
let mut px = img.get_pixel(x, y);
px.data[0] = (px.data[0] as f64 * 0.99 * ran_color1) as u8;
px.data[1] = (px.data[1] as f64 * 0.99 * ran_color2) as u8;
px.data[2] = (px.data[2] as f64 * 0.99 * ran_color3) as u8;
img.put_pixel(x, y, px);
}
}
photon_image.raw_pixels = img.raw_pixels();
}