imgref_iter/
traits.rs

1//! Contains the traits that allow obtaining iterators.
2
3use imgref::Img;
4
5use crate::iter::{
6	Iter,
7	IterMut,
8	IterPtr,
9	IterPtrMut,
10	IterWindows,
11	IterWindowsMut,
12	IterWindowsPtr,
13	IterWindowsPtrMut
14};
15
16#[cfg(any(doc, feature = "simd"))]
17use crate::iter::{
18	SimdIter,
19	SimdIterMut,
20	SimdIterPtr,
21	SimdIterPtrMut,
22	SimdIterWindows,
23	SimdIterWindowsMut,
24	SimdIterWindowsPtr,
25	SimdIterWindowsPtrMut,
26};
27
28#[cfg(doc)]
29use crate::iter::{
30	SimdIterWindow,
31	SimdIterWindowMut,
32	SimdIterWindowPtr,
33	SimdIterWindowPtrMut
34};
35
36mod sealed {
37	pub trait SealedAsPtr {}
38
39	pub trait SealedAsMutPtr {}
40
41	pub trait SealedPtr {}
42
43	pub trait SealedPtrMut {}
44
45	pub trait Sealed {}
46
47	pub trait SealedMut {}
48
49	#[cfg(any(doc, feature = "simd"))]
50	pub trait SealedSimdPtr {}
51
52	#[cfg(any(doc, feature = "simd"))]
53	pub trait SealedSimdPtrMut {}
54
55	#[cfg(any(doc, feature = "simd"))]
56	pub trait SealedSimd {}
57
58	#[cfg(any(doc, feature = "simd"))]
59	pub trait SealedSimdMut {}
60}
61
62/// The trait for images whose buffers can be converted to a `*const` pointer.
63pub trait ImgAsPtr: sealed::SealedAsPtr {
64	type Item;
65
66	#[cfg(not(any(doc, feature = "simd")))]
67	type AsPtr: ImgIterPtr<Item = Self::Item>;
68
69	#[cfg(any(doc, feature = "simd"))]
70	type AsPtr: ImgIterPtr<Item = Self::Item> + ImgSimdIterPtr;
71
72	/// Returns an [`Img`] that points to this one's buffer.
73	fn as_ptr(&self) -> Self::AsPtr;
74}
75
76/// The trait for [`Img`]s whose buffers can be converted to a `*mut` pointer
77/// *through a shared borrow*. `Img<&mut [T]>` cannot implement this because a
78/// mutable reference behind a shared reference becomes immutable - but
79/// [`ImgIterMut`] has another [`as_mut_ptr`][ImgIterMut::as_mut_ptr] method.
80pub trait ImgAsMutPtr: sealed::SealedAsMutPtr + ImgAsPtr {
81	#[cfg(not(any(doc, feature = "simd")))]
82	type AsMutPtr: ImgIterPtrMut<Item = Self::Item>;
83
84	#[cfg(any(doc, feature = "simd"))]
85	type AsMutPtr: ImgIterPtrMut<Item = Self::Item> + ImgSimdIterPtrMut;
86
87	/// Returns a [`Img`] that mutably points to this one's buffer.
88	fn as_mut_ptr(&self) -> Self::AsMutPtr;
89}
90
91/// Exposes iterators that return `*const` pointers.
92///
93/// Implemented for buffer pointers, i.e. [`Img<*const [T]>`][Img] and
94/// [`Img<*mut [T]>`][Img].
95pub trait ImgIterPtr: sealed::SealedPtr + ImgAsPtr {
96	/// Returns an iterator over pointers to the pixels of the specified row.
97	/// row.
98	///
99	/// # Safety
100	///
101	/// The caller must ensure that the pointer contained by the [`Img`] is
102	/// valid for reads from all pixels of the specified row, and that the
103	/// pointer remains valid for the lifetime of the iterator.
104	///
105	/// # Panics
106	///
107	/// Panics if the specified row is out of bounds for the [`Img`].
108	#[inline]
109	unsafe fn iter_row_ptr(&self, row: usize) -> IterPtr<Self::Item> {
110		self.as_ptr().iter_row_ptr(row)
111	}
112
113	/// Returns an iterator over [`IterPtr`]s.
114	///
115	/// # Safety
116	///
117	/// The caller must ensure that the pointer contained by the [`Img`] is
118	/// valid for reads from all pixels, and that the pointer remains valid for
119	/// the lifetime of the iterator.
120	#[inline]
121	unsafe fn iter_rows_ptr(&self) -> IterWindowsPtr<Self::Item> {
122		self.as_ptr().iter_rows_ptr()
123	}
124
125	/// Returns an iterator over pointers to the pixels of the specified column.
126	///
127	/// # Safety
128	///
129	/// The caller must ensure that the pointer contained by the [`Img`] is
130	/// valid for reads from all pixels of the specified column, and that the
131	/// pointer remains valid for the lifetime of the iterator.
132	///
133	/// # Panics
134	///
135	/// Panics if the specified column is out of bounds for the [`Img`].
136	#[inline]
137	unsafe fn iter_col_ptr(&self, col: usize) -> IterPtr<Self::Item> {
138		self.as_ptr().iter_col_ptr(col)
139	}
140
141	/// Returns an iterator over [`IterPtr`]s.
142	///
143	/// # Safety
144	///
145	/// The caller must ensure that the pointer contained by the [`Img`] is
146	/// valid for reads from all pixels, and that the pointer remains valid for
147	/// the lifetime of the iterator.
148	#[inline]
149	unsafe fn iter_cols_ptr(&self) -> IterWindowsPtr<Self::Item> {
150		self.as_ptr().iter_cols_ptr()
151	}
152}
153
154/// Exposes iterators that return `*mut` pointers.
155///
156/// Implemented for `mut` buffer pointers, i.e. [`Img<*mut [T]>`][Img].
157pub trait ImgIterPtrMut: sealed::SealedPtrMut + ImgAsMutPtr + ImgIterPtr {
158	/// Returns an iterator over `*mut` pointers to the pixels of the specified
159	/// row.
160	///
161	/// # Safety
162	///
163	/// The caller must ensure that the pointer contained by the [`Img`] is
164	/// valid for reads and writes for all pixels of the specified row, and that
165	/// the pointer remains valid for the lifetime of the iterator.
166	///
167	/// # Panics
168	///
169	/// Panics if the specified row is out of bounds for the [`Img`].
170	#[inline]
171	unsafe fn iter_row_ptr_mut(&self, row: usize) -> IterPtrMut<Self::Item> {
172		self.as_mut_ptr().iter_row_ptr_mut(row)
173	}
174
175	/// Returns an iterator over [`IterPtrMut`]s.
176	///
177	/// # Safety
178	///
179	/// The caller must ensure that the pointer contained by the [`Img`] is
180	/// valid for reads and writes for all pixels, and that the pointer remains
181	/// valid for the lifetime of the iterator.
182	#[inline]
183	unsafe fn iter_rows_ptr_mut(&self) -> IterWindowsPtrMut<Self::Item> {
184		self.as_mut_ptr().iter_rows_ptr_mut()
185	}
186
187	/// Returns an iterator over `*mut` pointers to the pixels of the specified
188	/// column.
189	///
190	/// # Safety
191	///
192	/// The caller must ensure that the pointer contained by the [`Img`] is
193	/// valid for reads and writes for all pixels of the specified column, and
194	/// that the pointer remains valid for the lifetime of the iterator.
195	///
196	/// # Panics
197	///
198	/// Panics if the specified column is out of bounds for the [`Img`].
199	#[inline]
200	unsafe fn iter_col_ptr_mut(&self, col: usize) -> IterPtrMut<Self::Item> {
201		self.as_mut_ptr().iter_col_ptr_mut(col)
202	}
203
204	/// Returns an iterator over [`IterPtrMut`]s.
205	///
206	/// # Safety
207	///
208	/// The caller must ensure that the pointer contained by the [`Img`] is
209	/// valid for reads and writes for all pixels, and that the pointer remains
210	/// valid for the lifetime of the iterator.
211	#[inline]
212	unsafe fn iter_cols_ptr_mut(&self) -> IterWindowsPtrMut<Self::Item> {
213		self.as_mut_ptr().iter_cols_ptr_mut()
214	}
215}
216
217/// Exposes iterators that return `&` references.
218///
219/// Implemented for all ordinary references and owned containers, i.e.
220/// [`Img<&[T]>`][Img].
221pub trait ImgIter: sealed::Sealed + ImgAsPtr {
222	/// Returns an iterator over the pixels of the specified row.
223	///
224	/// # Panics
225	///
226	/// Panics if the specified row is out of bounds for the [`Img`].
227	fn iter_row(&self, row: usize) -> Iter<Self::Item>;
228
229	/// Returns an iterator over rows.
230	fn iter_rows(&self) -> IterWindows<Self::Item>;
231
232	/// Returns an iterator over the pixels of the specified column.
233	///
234	/// # Panics
235	///
236	/// Panics if the specified column is out of bounds for the [`Img`].
237	fn iter_col(&self, col: usize) -> Iter<Self::Item>;
238
239	/// Returns an iterator over columns.
240	fn iter_cols(&self) -> IterWindows<Self::Item>;
241}
242
243/// Exposes iterators that return `&mut` references.
244///
245/// Implemented for all mutable references and owned containers, i.e.
246/// [`Img<&mut [T]>`][Img] or [`Img<Vec<T>>`][Img].
247pub trait ImgIterMut: sealed::SealedMut + ImgIter {
248	type AsMutPtr: ImgIterPtrMut<Item = Self::Item>;
249
250	/// Returns an [`Img`] that mutably points to this one's buffer.
251	fn as_mut_ptr(&mut self) -> Self::AsMutPtr;
252
253	/// Returns an iterator over the pixels of the specified row.
254	///
255	/// # Panics
256	///
257	/// Panics if the specified row is out of bounds for the [`Img`].
258	fn iter_row_mut(&mut self, row: usize) -> IterMut<Self::Item>;
259
260	/// Returns an iterator over [`IterMut`]s.
261	fn iter_rows_mut(&mut self) -> IterWindowsMut<Self::Item>;
262
263	/// Returns an iterator over the pixels of the specified column.
264	///
265	/// # Panics
266	///
267	/// Panics if the specified column is out of bounds for the [`Img`].
268	fn iter_col_mut(&mut self, col: usize) -> IterMut<Self::Item>;
269
270	/// Returns an iterator over [`IterMut`]s.
271	fn iter_cols_mut(&mut self) -> IterWindowsMut<Self::Item>;
272}
273
274/// Exposes iterators that return arrays of `*const` pointers.
275///
276/// Implemented for buffer pointers, i.e. [`Img<*const [T]>`][Img] and
277/// [`Img<*mut [T]>`][Img].
278#[cfg(any(doc, feature = "simd"))]
279pub trait ImgSimdIterPtr: sealed::SealedSimdPtr + ImgIterPtr {
280	/// Returns an iterator over pointers to the pixels of the specified row.
281	/// row.
282	///
283	/// # Safety
284	///
285	/// The caller must ensure that the pointer contained by the [`Img`] is
286	/// valid for reads from all pixels of the specified row, and that the
287	/// pointer remains valid for the lifetime of the iterator.
288	///
289	/// # Panics
290	///
291	/// Panics if the specified row is out of bounds for the [`Img`].
292	#[inline]
293	unsafe fn simd_iter_row_ptr<const LANES: usize>(&self, row: usize) -> SimdIterPtr<Self::Item, LANES> {
294		self.as_ptr().simd_iter_row_ptr::<LANES>(row)
295	}
296
297	/// Returns an iterator over [`SimdIterWindowPtr`]s.
298	///
299	/// # Safety
300	///
301	/// The caller must ensure that the pointer contained by the [`Img`] is
302	/// valid for reads from all pixels, and that the pointer remains valid for
303	/// the lifetime of the iterator.
304	#[inline]
305	unsafe fn simd_iter_rows_ptr<const LANES: usize>(&self) -> SimdIterWindowsPtr<Self::Item, LANES> {
306		self.as_ptr().simd_iter_rows_ptr()
307	}
308
309	/// Returns an iterator over pointers to the pixels of the specified column.
310	///
311	/// # Safety
312	///
313	/// The caller must ensure that the pointer contained by the [`Img`] is
314	/// valid for reads from all pixels of the specified column, and that the
315	/// pointer remains valid for the lifetime of the iterator.
316	///
317	/// # Panics
318	///
319	/// Panics if the specified column is out of bounds for the [`Img`].
320	#[inline]
321	unsafe fn simd_iter_col_ptr<const LANES: usize>(&self, col: usize) -> SimdIterPtr<Self::Item, LANES> {
322		self.as_ptr().simd_iter_col_ptr::<LANES>(col)
323	}
324
325	/// Returns an iterator over [`SimdIterWindowPtr`]s.
326	///
327	/// # Safety
328	///
329	/// The caller must ensure that the pointer contained by the [`Img`] is
330	/// valid for reads from all pixels, and that the pointer remains valid for
331	/// the lifetime of the iterator.
332	#[inline]
333	unsafe fn simd_iter_cols_ptr<const LANES: usize>(&self) -> SimdIterWindowsPtr<Self::Item, LANES> {
334		self.as_ptr().simd_iter_cols_ptr()
335	}
336}
337
338/// Exposes iterators that return arrays of `*mut` pointers.
339///
340/// Implemented for `mut` buffer pointers, i.e. [`Img<*mut [T]>`][Img].
341#[cfg(any(doc, feature = "simd"))]
342pub trait ImgSimdIterPtrMut: sealed::SealedSimdPtrMut + ImgSimdIterPtr + ImgIterPtrMut {
343	/// Returns an iterator over pointers to the pixels of the specified row.
344	/// row.
345	///
346	/// # Safety
347	///
348	/// The caller must ensure that the pointer contained by the [`Img`] is
349	/// valid for reads from all pixels of the specified row, and that the
350	/// pointer remains valid for the lifetime of the iterator.
351	///
352	/// # Panics
353	///
354	/// Panics if the specified row is out of bounds for the [`Img`].
355	#[inline]
356	unsafe fn simd_iter_row_ptr_mut<const LANES: usize>(&self, row: usize) -> SimdIterPtrMut<Self::Item, LANES> {
357		self.as_mut_ptr().simd_iter_row_ptr_mut::<LANES>(row)
358	}
359
360	/// Returns an iterator over [`SimdIterWindowPtrMut`]s.
361	///
362	/// # Safety
363	///
364	/// The caller must ensure that the pointer contained by the [`Img`] is
365	/// valid for reads and writes for all pixels, and that the pointer remains
366	/// valid for the lifetime of the iterator.
367	#[inline]
368	unsafe fn simd_iter_rows_ptr_mut<const LANES: usize>(&self) -> SimdIterWindowsPtrMut<Self::Item, LANES> {
369		self.as_mut_ptr().simd_iter_rows_ptr_mut()
370	}
371
372	/// Returns an iterator over pointers to the pixels of the specified column.
373	///
374	/// # Safety
375	///
376	/// The caller must ensure that the pointer contained by the [`Img`] is
377	/// valid for reads from all pixels of the specified column, and that the
378	/// pointer remains valid for the lifetime of the iterator.
379	///
380	/// # Panics
381	///
382	/// Panics if the specified column is out of bounds for the [`Img`].
383	#[inline]
384	unsafe fn simd_iter_col_ptr_mut<const LANES: usize>(&self, col: usize) -> SimdIterPtrMut<Self::Item, LANES> {
385		self.as_mut_ptr().simd_iter_col_ptr_mut::<LANES>(col)
386	}
387
388	/// Returns an iterator over [`SimdIterWindowPtrMut`]s.
389	///
390	/// # Safety
391	///
392	/// The caller must ensure that the pointer contained by the [`Img`] is
393	/// valid for reads and writes for all pixels, and that the pointer remains
394	/// valid for the lifetime of the iterator.
395	#[inline]
396	unsafe fn simd_iter_cols_ptr_mut<const LANES: usize>(&self) -> SimdIterWindowsPtrMut<Self::Item, LANES> {
397		self.as_mut_ptr().simd_iter_cols_ptr_mut()
398	}
399}
400
401/// Exposes iterators that return arrays of `&` references.
402///
403/// Implemented for all ordinary references and owned containers, i.e.
404/// [`Img<&[T]>`][Img].
405#[cfg(any(doc, feature = "simd"))]
406pub trait ImgSimdIter: sealed::SealedSimd + ImgIter {
407	/// Returns an iterator over the pixels of the specified row.
408	///
409	/// # Panics
410	///
411	/// Panics if the specified row is out of bounds for the [`Img`].
412	fn simd_iter_row<const LANES: usize>(&self, row: usize) -> SimdIter<Self::Item, LANES>;
413
414	/// Returns an iterator over rows.
415	fn simd_iter_rows<const LANES: usize>(&self) -> SimdIterWindows<Self::Item, LANES>;
416
417	/// Returns an iterator over the pixels of the specified column.
418	///
419	/// # Panics
420	///
421	/// Panics if the specified column is out of bounds for the [`Img`].
422	fn simd_iter_col<const LANES: usize>(&self, col: usize) -> SimdIter<Self::Item, LANES>;
423
424	/// Returns an iterator over columns.
425	fn simd_iter_cols<const LANES: usize>(&self) -> SimdIterWindows<Self::Item, LANES>;
426}
427
428/// Exposes iterators that return arrays of `&mut` references.
429///
430/// Implemented for all mutable references and owned containers, i.e.
431/// [`Img<&mut [T]>`][Img] or [`Img<Vec<T>>`][Img].
432#[cfg(any(doc, feature = "simd"))]
433pub trait ImgSimdIterMut: sealed::SealedSimdMut + ImgIterMut {
434	/// Returns an iterator over the pixels of the specified row.
435	///
436	/// # Panics
437	///
438	/// Panics if the specified row is out of bounds for the [`Img`].
439	fn simd_iter_row_mut<const LANES: usize>(&mut self, row: usize) -> SimdIterMut<Self::Item, LANES>;
440
441	/// Returns an iterator over [`SimdIterWindowMut`]s.
442	fn simd_iter_rows_mut<const LANES: usize>(&mut self) -> SimdIterWindowsMut<Self::Item, LANES>;
443
444	/// Returns an iterator over the pixels of the specified column.
445	///
446	/// # Panics
447	///
448	/// Panics if the specified column is out of bounds for the [`Img`].
449	fn simd_iter_col_mut<const LANES: usize>(&mut self, col: usize) -> SimdIterMut<Self::Item, LANES>;
450
451	/// Returns an iterator over [`SimdIterWindowMut`]s.
452	fn simd_iter_cols_mut<const LANES: usize>(&mut self) -> SimdIterWindowsMut<Self::Item, LANES>;
453}
454
455// @formatter:off
456impl<T> sealed::SealedAsPtr for Img<*const [T]> {}
457impl<T> sealed::SealedPtr for Img<*const [T]> {}
458
459impl<T> sealed::SealedAsPtr for Img<*mut [T]> {}
460impl<T> sealed::SealedAsMutPtr for Img<*mut [T]> {}
461impl<T> sealed::SealedPtr for Img<*mut [T]> {}
462impl<T> sealed::SealedPtrMut for Img<*mut [T]> {}
463
464impl<T> sealed::SealedAsPtr for Img<&[T]> {}
465impl<T> sealed::SealedPtr for Img<&[T]> {}
466impl<T> sealed::Sealed for Img<&[T]> {}
467
468impl<T> sealed::SealedAsPtr for Img<&mut [T]> {}
469impl<T> sealed::SealedAsMutPtr for Img<&mut [T]> {}
470impl<T> sealed::SealedPtr for Img<&mut [T]> {}
471impl<T> sealed::Sealed for Img<&mut [T]> {}
472impl<T> sealed::SealedMut for Img<&mut [T]> {}
473
474#[cfg(any(doc, feature = "simd"))] impl<T> sealed::SealedSimdPtr for Img<*const [T]> {}
475
476#[cfg(any(doc, feature = "simd"))] impl<T> sealed::SealedSimdPtr for Img<*mut [T]> {}
477#[cfg(any(doc, feature = "simd"))] impl<T> sealed::SealedSimdPtrMut for Img<*mut [T]> {}
478
479#[cfg(any(doc, feature = "simd"))] impl<T> sealed::SealedSimdPtr for Img<&[T]> {}
480#[cfg(any(doc, feature = "simd"))] impl<T> sealed::SealedSimd for Img<&[T]> {}
481
482#[cfg(any(doc, feature = "simd"))] impl<T> sealed::SealedSimdPtr for Img<&mut [T]> {}
483#[cfg(any(doc, feature = "simd"))] impl<T> sealed::SealedSimd for Img<&mut [T]> {}
484#[cfg(any(doc, feature = "simd"))] impl<T> sealed::SealedSimdMut for Img<&mut [T]> {}
485// @formatter:on
486
487#[inline]
488unsafe fn copy_buf_unchecked<T, U>(img: &Img<T>, map: impl FnOnce(&T) -> U) -> Img<U> {
489	let (width, height, stride) = (img.width(), img.height(), img.stride());
490	Img::new_stride(map(img.buf()), width, height, stride)
491}
492
493#[inline]
494unsafe fn copy_buf_unchecked_mut<T, U>(img: &mut Img<T>, map: impl FnOnce(&mut T) -> U) -> Img<U> {
495	let (width, height, stride) = (img.width(), img.height(), img.stride());
496	Img::new_stride(map(img.buf_mut()), width, height, stride)
497}
498
499impl<T> ImgAsPtr for Img<*const [T]> {
500	type Item = T;
501	type AsPtr = Self;
502
503	#[inline]
504	fn as_ptr(&self) -> Self::AsPtr {
505		*self
506	}
507}
508
509impl<T> ImgAsPtr for Img<*mut [T]> {
510	type Item = T;
511	type AsPtr = Img<*const [T]>;
512
513	#[inline]
514	fn as_ptr(&self) -> Self::AsPtr {
515		unsafe { copy_buf_unchecked(self, |buf| *buf as *const [T]) }
516	}
517}
518
519impl<T> ImgAsPtr for Img<&[T]> {
520	type Item = T;
521	type AsPtr = Img<*const [T]>;
522
523	#[inline]
524	fn as_ptr(&self) -> Self::AsPtr {
525		unsafe { copy_buf_unchecked(self, |buf| *buf as *const [T]) }
526	}
527}
528
529impl<T> ImgAsPtr for Img<&mut [T]> {
530	type Item = T;
531	type AsPtr = Img<*const [T]>;
532
533	#[inline]
534	fn as_ptr(&self) -> Self::AsPtr {
535		unsafe { copy_buf_unchecked(self, |buf| *buf as *const [T]) }
536	}
537}
538
539impl<T> ImgAsMutPtr for Img<*mut [T]> {
540	type AsMutPtr = Img<*mut [T]>;
541
542	#[inline]
543	fn as_mut_ptr(&self) -> Self::AsMutPtr {
544		*self
545	}
546}
547
548impl<T> ImgIterPtr for Img<*const [T]> {
549	#[inline]
550	unsafe fn iter_row_ptr(&self, row: usize) -> IterPtr<Self::Item> {
551		IterPtr::row_ptr(*self, row)
552	}
553
554	#[inline]
555	unsafe fn iter_rows_ptr(&self) -> IterWindowsPtr<Self::Item> {
556		IterWindowsPtr::rows_ptr(*self)
557	}
558
559	#[inline]
560	unsafe fn iter_col_ptr(&self, col: usize) -> IterPtr<Self::Item> {
561		IterPtr::col_ptr(*self, col)
562	}
563
564	#[inline]
565	unsafe fn iter_cols_ptr(&self) -> IterWindowsPtr<Self::Item> {
566		IterWindowsPtr::cols_ptr(*self)
567	}
568}
569
570impl<T> ImgIterPtr for Img<*mut [T]> {}
571
572impl<T> ImgIterPtr for Img<&[T]> {}
573
574impl<T> ImgIterPtr for Img<&mut [T]> {}
575
576impl<T> ImgIterPtrMut for Img<*mut [T]> {
577	#[inline]
578	unsafe fn iter_row_ptr_mut(&self, row: usize) -> IterPtrMut<Self::Item> {
579		IterPtrMut::row_ptr(*self, row)
580	}
581
582	#[inline]
583	unsafe fn iter_rows_ptr_mut(&self) -> IterWindowsPtrMut<Self::Item> {
584		IterWindowsPtrMut::rows_ptr(*self)
585	}
586
587	#[inline]
588	unsafe fn iter_col_ptr_mut(&self, col: usize) -> IterPtrMut<Self::Item> {
589		IterPtrMut::col_ptr(*self, col)
590	}
591
592	#[inline]
593	unsafe fn iter_cols_ptr_mut(&self) -> IterWindowsPtrMut<Self::Item> {
594		IterWindowsPtrMut::cols_ptr(*self)
595	}
596}
597
598impl<T> ImgIter for Img<&[T]> {
599	#[inline]
600	fn iter_row(&self, row: usize) -> Iter<Self::Item> {
601		Iter::row(self, row)
602	}
603
604	#[inline]
605	fn iter_rows(&self) -> IterWindows<Self::Item> {
606		IterWindows::rows(self)
607	}
608
609	#[inline]
610	fn iter_col(&self, col: usize) -> Iter<Self::Item> {
611		Iter::col(self, col)
612	}
613
614	#[inline]
615	fn iter_cols(&self) -> IterWindows<Self::Item> {
616		IterWindows::cols(self)
617	}
618}
619
620impl<T> ImgIter for Img<&mut [T]> {
621	#[inline]
622	fn iter_row(&self, row: usize) -> Iter<Self::Item> {
623		Iter::row(self, row)
624	}
625
626	#[inline]
627	fn iter_rows(&self) -> IterWindows<Self::Item> {
628		IterWindows::rows(self)
629	}
630
631	#[inline]
632	fn iter_col(&self, col: usize) -> Iter<Self::Item> {
633		Iter::col(self, col)
634	}
635
636	#[inline]
637	fn iter_cols(&self) -> IterWindows<Self::Item> {
638		IterWindows::cols(self)
639	}
640}
641
642impl<T> ImgIterMut for Img<&mut [T]> {
643	type AsMutPtr = Img<*mut [T]>;
644
645	#[inline]
646	fn as_mut_ptr(&mut self) -> Self::AsMutPtr {
647		unsafe { copy_buf_unchecked_mut(self, |buf| *buf as *mut [T]) }
648	}
649
650	#[inline]
651	fn iter_row_mut(&mut self, row: usize) -> IterMut<Self::Item> {
652		IterMut::row(self, row)
653	}
654
655	#[inline]
656	fn iter_rows_mut(&mut self) -> IterWindowsMut<Self::Item> {
657		IterWindowsMut::rows(self)
658	}
659
660	#[inline]
661	fn iter_col_mut(&mut self, col: usize) -> IterMut<Self::Item> {
662		IterMut::col(self, col)
663	}
664
665	#[inline]
666	fn iter_cols_mut(&mut self) -> IterWindowsMut<Self::Item> {
667		IterWindowsMut::cols(self)
668	}
669}
670
671#[cfg(any(doc, feature = "simd"))]
672impl<T> ImgSimdIterPtr for Img<*const [T]> {
673	#[inline]
674	unsafe fn simd_iter_row_ptr<const LANES: usize>(&self, row: usize) -> SimdIterPtr<Self::Item, LANES> {
675		SimdIterPtr::rows_ptr(*self, row)
676	}
677
678	#[inline]
679	unsafe fn simd_iter_rows_ptr<const LANES: usize>(&self) -> SimdIterWindowsPtr<Self::Item, LANES> {
680		SimdIterWindowsPtr::rows_ptr(*self)
681	}
682
683	#[inline]
684	unsafe fn simd_iter_col_ptr<const LANES: usize>(&self, col: usize) -> SimdIterPtr<Self::Item, LANES> {
685		SimdIterPtr::cols_ptr(*self, col)
686	}
687
688	#[inline]
689	unsafe fn simd_iter_cols_ptr<const LANES: usize>(&self) -> SimdIterWindowsPtr<Self::Item, LANES> {
690		SimdIterWindowsPtr::cols_ptr(*self)
691	}
692}
693
694#[cfg(any(doc, feature = "simd"))]
695impl<T> ImgSimdIterPtr for Img<*mut [T]> {}
696
697#[cfg(any(doc, feature = "simd"))]
698impl<T> ImgSimdIterPtr for Img<&[T]> {}
699
700#[cfg(any(doc, feature = "simd"))]
701impl<T> ImgSimdIterPtr for Img<&mut [T]> {}
702
703#[cfg(any(doc, feature = "simd"))]
704impl<T> ImgSimdIterPtrMut for Img<*mut [T]> {
705	#[inline]
706	unsafe fn simd_iter_row_ptr_mut<const LANES: usize>(&self, row: usize) -> SimdIterPtrMut<Self::Item, LANES> {
707		SimdIterPtrMut::rows_ptr(*self, row)
708	}
709
710	#[inline]
711	unsafe fn simd_iter_rows_ptr_mut<const LANES: usize>(&self) -> SimdIterWindowsPtrMut<Self::Item, LANES> {
712		SimdIterWindowsPtrMut::rows_ptr(*self)
713	}
714
715	#[inline]
716	unsafe fn simd_iter_col_ptr_mut<const LANES: usize>(&self, col: usize) -> SimdIterPtrMut<Self::Item, LANES> {
717		SimdIterPtrMut::cols_ptr(*self, col)
718	}
719
720	#[inline]
721	unsafe fn simd_iter_cols_ptr_mut<const LANES: usize>(&self) -> SimdIterWindowsPtrMut<Self::Item, LANES> {
722		SimdIterWindowsPtrMut::cols_ptr(*self)
723	}
724}
725
726#[cfg(any(doc, feature = "simd"))]
727impl<T> ImgSimdIter for Img<&[T]> {
728	#[inline]
729	fn simd_iter_row<const LANES: usize>(&self, row: usize) -> SimdIter<Self::Item, LANES> {
730		SimdIter::rows(self, row)
731	}
732
733	#[inline]
734	fn simd_iter_rows<const LANES: usize>(&self) -> SimdIterWindows<Self::Item, LANES> {
735		SimdIterWindows::rows(self)
736	}
737
738	#[inline]
739	fn simd_iter_col<const LANES: usize>(&self, col: usize) -> SimdIter<Self::Item, LANES> {
740		SimdIter::cols(self, col)
741	}
742
743	#[inline]
744	fn simd_iter_cols<const LANES: usize>(&self) -> SimdIterWindows<Self::Item, LANES> {
745		SimdIterWindows::cols(self)
746	}
747}
748
749#[cfg(any(doc, feature = "simd"))]
750impl<T> ImgSimdIter for Img<&mut [T]> {
751	#[inline]
752	fn simd_iter_row<const LANES: usize>(&self, row: usize) -> SimdIter<Self::Item, LANES> {
753		SimdIter::rows(self, row)
754	}
755
756	#[inline]
757	fn simd_iter_rows<const LANES: usize>(&self) -> SimdIterWindows<Self::Item, LANES> {
758		SimdIterWindows::rows(self)
759	}
760
761	#[inline]
762	fn simd_iter_col<const LANES: usize>(&self, col: usize) -> SimdIter<Self::Item, LANES> {
763		SimdIter::cols(self, col)
764	}
765
766	#[inline]
767	fn simd_iter_cols<const LANES: usize>(&self) -> SimdIterWindows<Self::Item, LANES> {
768		SimdIterWindows::cols(self)
769	}
770}
771
772#[cfg(any(doc, feature = "simd"))]
773impl<T> ImgSimdIterMut for Img<&mut [T]> {
774	#[inline]
775	fn simd_iter_row_mut<const LANES: usize>(&mut self, row: usize) -> SimdIterMut<Self::Item, LANES> {
776		SimdIterMut::rows(self, row)
777	}
778
779	#[inline]
780	fn simd_iter_rows_mut<const LANES: usize>(&mut self) -> SimdIterWindowsMut<Self::Item, LANES> {
781		SimdIterWindowsMut::rows(self)
782	}
783
784	#[inline]
785	fn simd_iter_col_mut<const LANES: usize>(&mut self, col: usize) -> SimdIterMut<Self::Item, LANES> {
786		SimdIterMut::cols(self, col)
787	}
788
789	#[inline]
790	fn simd_iter_cols_mut<const LANES: usize>(&mut self) -> SimdIterWindowsMut<Self::Item, LANES> {
791		SimdIterWindowsMut::cols(self)
792	}
793}