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
81
82
use crate::*;
/// Filter input
#[derive(Clone)]
pub struct Input<'a, T: 'a + Type, C: 'a + Color> {
/// Input images
pub images: Vec<&'a Image<T, C>>,
/// Input pixel
pub pixel: Option<(Point, Pixel<C>)>,
}
impl<'a, T: 'a + Type, C: 'a + Color> Input<'a, T, C> {
/// Create new `Input`
pub fn new(images: &'a [&'a Image<T, C>]) -> Self {
Input {
images: images.to_vec(),
pixel: None,
}
}
/// Add chained pixel data
pub fn with_pixel(mut self, point: Point, pixel: Pixel<C>) -> Self {
self.pixel = Some((point, pixel));
self
}
/// Remove chained pixel data
pub fn without_pixel(mut self) -> Self {
self.pixel = None;
self
}
/// Returns optional pixel value
pub fn pixel(&self) -> Option<&(Point, Pixel<C>)> {
self.pixel.as_ref()
}
/// Get number of images
pub fn len(&self) -> usize {
self.images.len()
}
/// Returns true when there are no inputs
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// Get input images
pub fn images(&self) -> &[&Image<T, C>] {
&self.images
}
/// Get input pixel at `pt` - if `pt` matches the stored pixel from a preview computation then
/// that pixel will be returned instead of the actual input pixel. If `image_index` is not
/// `None` then input from the image with that index will be used.
pub fn get_pixel(&self, pt: impl Into<Point>, image_index: Option<usize>) -> Pixel<C> {
let pt = pt.into();
match (image_index, &self.pixel) {
(None, Some((point, data))) if point.eq(&pt) => data.clone(),
_ => self.images[image_index.unwrap_or_default()].get_pixel(pt),
}
}
/// Get input float value - if `pt` matches the stored pixel from a preview computation then
/// that pixel will be returned instead of the actual input pixel. If `image_index` is not
/// `None` then input from the image with that index will be used.
pub fn get_f(&self, pt: impl Into<Point>, c: Channel, image_index: Option<usize>) -> f64 {
let pt = pt.into();
match (image_index, &self.pixel) {
(None, Some((point, data))) if point.eq(&pt) => data[c],
_ => self.images[image_index.unwrap_or_default()].get_f(pt, c),
}
}
/// Create a new pixel
pub fn new_pixel(&self) -> Pixel<C> {
Pixel::new()
}
}