mirror of
https://github.com/bend-n/fimg.git
synced 2024-12-22 02:28:19 -06:00
add row and col iters (#3)
This commit is contained in:
parent
2c9b749230
commit
8649f3c2a2
66
src/lib.rs
66
src/lib.rs
|
@ -552,6 +552,72 @@ impl<T, const CHANNELS: usize> Image<T, CHANNELS> {
|
||||||
// SAFETY: slice should always return a valid index
|
// SAFETY: slice should always return a valid index
|
||||||
unsafe { self.buffer.as_mut().get_unchecked_mut(idx) }
|
unsafe { self.buffer.as_mut().get_unchecked_mut(idx) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// iterator over columns
|
||||||
|
/// returned iterator returns a iterator for each column
|
||||||
|
///
|
||||||
|
/// ```text
|
||||||
|
/// ┌ ┐┌ ┐┌ ┐
|
||||||
|
/// │1││2││3│
|
||||||
|
/// │4││5││6│
|
||||||
|
/// │7││8││9│
|
||||||
|
/// └ ┘└ ┘└ ┘
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use fimg::Image;
|
||||||
|
/// let img: Image<&[u8],1> = Image::build(2, 3).buf(&[
|
||||||
|
/// 1, 5,
|
||||||
|
/// 2, 4,
|
||||||
|
/// 7, 9
|
||||||
|
/// ]);
|
||||||
|
/// assert_eq!(
|
||||||
|
/// img.cols().map(|x| x.collect::<Vec<_>>()).collect::<Vec<_>>(),
|
||||||
|
/// [[[1], [2], [7]], [[5], [4], [9]]]
|
||||||
|
/// );
|
||||||
|
/// ```
|
||||||
|
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||||
|
pub fn cols<U: Copy>(
|
||||||
|
&self,
|
||||||
|
) -> impl DoubleEndedIterator
|
||||||
|
+ ExactSizeIterator<
|
||||||
|
Item = impl ExactSizeIterator + DoubleEndedIterator<Item = [U; CHANNELS]> + '_,
|
||||||
|
>
|
||||||
|
where
|
||||||
|
T: AsRef<[U]>,
|
||||||
|
{
|
||||||
|
(0..self.width()).map(move |x| (0..self.height()).map(move |y| unsafe { self.pixel(x, y) }))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// iterator over rows
|
||||||
|
/// returns a iterator over each row
|
||||||
|
/// ```text
|
||||||
|
/// [ 1 2 3 ]
|
||||||
|
/// [ 4 5 6 ]
|
||||||
|
/// [ 7 8 9 ]
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use fimg::Image;
|
||||||
|
/// let img: Image<&[u8],1> = Image::build(2, 3).buf(&[
|
||||||
|
/// 1, 5,
|
||||||
|
/// 2, 4,
|
||||||
|
/// 7, 9
|
||||||
|
/// ]);
|
||||||
|
/// assert_eq!(
|
||||||
|
/// img.rows().collect::<Vec<_>>(),
|
||||||
|
/// [[[1], [5]], [[2], [4]], [[7], [9]]]
|
||||||
|
/// );
|
||||||
|
/// ```
|
||||||
|
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||||
|
pub fn rows<'a, U: 'a>(
|
||||||
|
&'a self,
|
||||||
|
) -> impl ExactSizeIterator + DoubleEndedIterator<Item = &'a [[U; CHANNELS]]>
|
||||||
|
where
|
||||||
|
T: AsRef<[U]>,
|
||||||
|
{
|
||||||
|
self.flatten().chunks_exact(self.width() as usize)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
impl<T: AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use super::{float, unfloat};
|
use super::{float, unfloat};
|
||||||
use atools::prelude::*;
|
use atools::prelude::*;
|
||||||
use umath::{generic_float::Constructors, FF32};
|
use umath::{generic_float::Constructors, FF32};
|
||||||
|
#[allow(dead_code)]
|
||||||
pub trait Wam {
|
pub trait Wam {
|
||||||
/// this function weighs the sides and combines
|
/// this function weighs the sides and combines
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use super::{b64, Basic};
|
use super::{b64, Basic};
|
||||||
use crate::{Image, WritePng};
|
use crate::{Image, WritePng};
|
||||||
use core::intrinsics::transmute_unchecked as transmute;
|
|
||||||
use std::fmt::{Debug, Display, Formatter, Result, Write};
|
use std::fmt::{Debug, Display, Formatter, Result, Write};
|
||||||
|
|
||||||
/// Outputs [Iterm2 Inline image protocol](https://iterm2.com/documentation-images.html) encoded data.
|
/// Outputs [Iterm2 Inline image protocol](https://iterm2.com/documentation-images.html) encoded data.
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use super::{b64, Basic};
|
use super::{b64, Basic};
|
||||||
use crate::Image;
|
use crate::Image;
|
||||||
use core::intrinsics::transmute_unchecked as transmute;
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::fmt::{Debug, Display, Formatter, Result, Write};
|
use std::fmt::{Debug, Display, Formatter, Result, Write};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue