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
83
84
85
86
use std::{array, fmt, mem, ops::IndexMut};
use num_traits::Num;
pub trait StorageType: Num + Copy + Send + Sync {}
impl<T: Num + Copy + Send + Sync> StorageType for T {}
pub trait Pixel: Sized + Copy + Send + Sync + IndexMut<usize> {
type T: StorageType;
fn at(&self, index: usize) -> Self::T;
fn try_from(raw: &[Self::T]) -> Result<Self, array::TryFromSliceError>;
fn channels() -> u8;
fn len() -> usize {
Self::channels() as usize * mem::size_of::<Self::T>()
}
fn subpixels() -> u8;
}
pub trait Macropixel: Pixel {
type Subpixel: Pixel;
fn from_subpixels(pixels: &[Self::Subpixel]) -> Self;
fn to_subpixels(&self) -> [Self::Subpixel];
}
pub trait GenericImageView<'a> {
type T: Pixel;
type SubImage;
fn width(&self) -> u32;
fn height(&self) -> u32;
fn pixel(&self, x: u32, y: u32) -> Option<Self::T>;
fn view(&'a self, x: u32, y: u32, width: u32, height: u32) -> Option<Self::SubImage>;
}
pub trait GenericImage<'a>: GenericImageView<'a> {
fn set_pixel(&mut self, x: u32, y: u32, pix: &Self::T) -> Result<(), ()>;
}
pub trait TryConvert<B> {
type Error: fmt::Debug;
fn try_convert(&self, output: &mut B) -> Result<(), Self::Error>;
}
pub trait TryConvertSlice<DP: Pixel>: Sized {
type Error: fmt::Debug;
fn try_convert(input: &[Self], output: &mut [DP]) -> Result<(), Self::Error>;
}