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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use crate::;
// ───────────────────────────────────────────────────────────────────
// ImageView / ImageViewMut — random pixel access (universal)
// ───────────────────────────────────────────────────────────────────
/// The `ImageView` trait is a non-mutable representation of a part of
/// an image. This trait should be like a 2D slice for an image.
/// The `ImageViewMut` trait is a mutable representation of a part of
/// an image. This trait should be like a 2D mut slice for an image
// ───────────────────────────────────────────────────────────────────
// RasterImage / RasterImageMut — row-level slice access (memory-backed)
// ───────────────────────────────────────────────────────────────────
/// A memory-backed image where each row is a contiguous slice of pixels.
///
/// `RasterImage` sits between [`ImageView`] (random pixel access) and
/// [`ContiguousImage`](crate::image::ContiguousImage) (entire buffer is
/// flat). Every row is a dense `&[Self::Pixel]` slice of exactly
/// `width()` elements, but rows may be separated by a stride (e.g. for
/// strided ROIs produced by [`SubView::roi`](crate::image::SubView::roi)).
///
/// This trait is the foundation for SIMD-friendly iteration: transforms
/// can process one row slice at a time instead of calling `pixel_at` per
/// pixel, enabling both auto-vectorization and explicit SIMD kernels.
///
/// # Who implements this
///
/// | Type | `RasterImage` | `ContiguousImage` |
/// |--------------------------|---------------|-------------------|
/// | `Image<T>` | ✅ | ✅ |
/// | `ImageArray<T, W, H>` | ✅ | ✅ |
/// | `ImageRef` (any) | ✅ | ❌ |
/// | `ImageRefMut` (any) | ✅ | — |
/// | Function image (future) | ❌ | ❌ |
///
/// # Example
/// ```
/// # use fovea::image::{Image, ImageView, RasterImage};
/// let img = Image::generate(4, 3, |x, y| (y * 4 + x) as u8);
/// let row1 = img.row(1);
/// assert_eq!(row1, &[4, 5, 6, 7]);
/// ```
/// A memory-backed image with mutable row-level slice access.
///
/// Extends [`RasterImage`] with `row_mut`, enabling in-place
/// modification of an entire row at a time.
///
/// # Example
/// ```
/// # use fovea::image::{Image, RasterImage, RasterImageMut};
/// let mut img = Image::generate(3, 2, |x, y| (y * 3 + x) as u8);
/// img.row_mut(0).fill(42);
/// assert_eq!(img.row(0), &[42, 42, 42]);
/// assert_eq!(img.row(1), &[3, 4, 5]);
/// ```