mirror of
https://github.com/bend-n/fimg.git
synced 2024-12-22 18:38:21 -06:00
must_use all cloner functions
This commit is contained in:
parent
89b1596db2
commit
4eb9c336b0
|
@ -18,6 +18,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
|
||||||
/// let a = Image::<_, 1>::build(2,2).buf(vec![21,42,90,01]);
|
/// let a = Image::<_, 1>::build(2,2).buf(vec![21,42,90,01]);
|
||||||
/// assert_eq!(a.cloner().flip_v().take_buffer(), [90,01,21,42]);
|
/// assert_eq!(a.cloner().flip_v().take_buffer(), [90,01,21,42]);
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use = "function does not modify the original image"]
|
||||||
pub fn flip_v(&self) -> Image<Vec<u8>, CHANNELS> {
|
pub fn flip_v(&self) -> Image<Vec<u8>, CHANNELS> {
|
||||||
let mut out = self.alloc();
|
let mut out = self.alloc();
|
||||||
for y in 0..self.height() {
|
for y in 0..self.height() {
|
||||||
|
@ -37,6 +38,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
|
||||||
/// let a = Image::<_,1>::build(2,2).buf(vec![90,01,21,42]);
|
/// let a = Image::<_,1>::build(2,2).buf(vec![90,01,21,42]);
|
||||||
/// assert_eq!(a.cloner().flip_h().take_buffer(), [01,90,42,21]);
|
/// assert_eq!(a.cloner().flip_h().take_buffer(), [01,90,42,21]);
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use = "function does not modify the original image"]
|
||||||
pub fn flip_h(&self) -> Image<Vec<u8>, CHANNELS> {
|
pub fn flip_h(&self) -> Image<Vec<u8>, CHANNELS> {
|
||||||
let mut out = self.alloc();
|
let mut out = self.alloc();
|
||||||
for y in 0..self.height() {
|
for y in 0..self.height() {
|
||||||
|
@ -120,6 +122,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
|
||||||
/// let a = Image::<_,1>::build(2,2).buf(vec![00,01,02,10]);
|
/// let a = Image::<_,1>::build(2,2).buf(vec![00,01,02,10]);
|
||||||
/// assert_eq!(a.cloner().rot_180().take_buffer(), vec![10,02,01,00]);
|
/// assert_eq!(a.cloner().rot_180().take_buffer(), vec![10,02,01,00]);
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use = "function does not modify the original image"]
|
||||||
pub fn rot_180(&self) -> Image<Vec<u8>, CHANNELS> {
|
pub fn rot_180(&self) -> Image<Vec<u8>, CHANNELS> {
|
||||||
let s = (self.width() * self.height()) as usize;
|
let s = (self.width() * self.height()) as usize;
|
||||||
let mut v: Vec<[u8; CHANNELS]> = Vec::with_capacity(s);
|
let mut v: Vec<[u8; CHANNELS]> = Vec::with_capacity(s);
|
||||||
|
@ -140,6 +143,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// UB if the image is not square
|
/// UB if the image is not square
|
||||||
|
#[must_use = "function does not modify the original image"]
|
||||||
pub unsafe fn rot_90(&self) -> Image<Vec<u8>, CHANNELS> {
|
pub unsafe fn rot_90(&self) -> Image<Vec<u8>, CHANNELS> {
|
||||||
let mut out = self.flip_v();
|
let mut out = self.flip_v();
|
||||||
// SAFETY: sqar
|
// SAFETY: sqar
|
||||||
|
@ -151,6 +155,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// UB if the image is not square
|
/// UB if the image is not square
|
||||||
|
#[must_use = "function does not modify the original image"]
|
||||||
pub unsafe fn rot_270(&self) -> Image<Vec<u8>, CHANNELS> {
|
pub unsafe fn rot_270(&self) -> Image<Vec<u8>, CHANNELS> {
|
||||||
let mut out = self.flip_h();
|
let mut out = self.flip_h();
|
||||||
// SAFETY: sqar
|
// SAFETY: sqar
|
||||||
|
|
|
@ -246,6 +246,7 @@ impl<T: std::ops::Deref<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Procure a [`ImageCloner`].
|
/// Procure a [`ImageCloner`].
|
||||||
|
#[must_use = "function does not modify the original image"]
|
||||||
pub fn cloner(&self) -> ImageCloner<'_, CHANNELS> {
|
pub fn cloner(&self) -> ImageCloner<'_, CHANNELS> {
|
||||||
ImageCloner::from(self.as_ref())
|
ImageCloner::from(self.as_ref())
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,6 +119,7 @@ impl Overlay<Image<&[u8], 4>> for Image<&mut [u8], 4> {
|
||||||
|
|
||||||
impl ClonerOverlay<4, 4> for ImageCloner<'_, 4> {
|
impl ClonerOverlay<4, 4> for ImageCloner<'_, 4> {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use = "function does not modify the original image"]
|
||||||
unsafe fn overlay(&self, with: &Image<&[u8], 4>) -> Image<Vec<u8>, 4> {
|
unsafe fn overlay(&self, with: &Image<&[u8], 4>) -> Image<Vec<u8>, 4> {
|
||||||
let mut out = self.dup();
|
let mut out = self.dup();
|
||||||
// SAFETY: same
|
// SAFETY: same
|
||||||
|
@ -153,6 +154,8 @@ impl OverlayAt<Image<&[u8], 4>> for Image<&mut [u8], 3> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClonerOverlayAt<4, 3> for ImageCloner<'_, 3> {
|
impl ClonerOverlayAt<4, 3> for ImageCloner<'_, 3> {
|
||||||
|
#[inline]
|
||||||
|
#[must_use = "function does not modify the original image"]
|
||||||
unsafe fn overlay_at(&self, with: &Image<&[u8], 4>, x: u32, y: u32) -> Image<Vec<u8>, 3> {
|
unsafe fn overlay_at(&self, with: &Image<&[u8], 4>, x: u32, y: u32) -> Image<Vec<u8>, 3> {
|
||||||
let mut new = self.dup();
|
let mut new = self.dup();
|
||||||
// SAFETY: same
|
// SAFETY: same
|
||||||
|
@ -225,6 +228,7 @@ impl Overlay<Image<&[u8], 4>> for Image<&mut [u8], 3> {
|
||||||
|
|
||||||
impl ClonerOverlay<4, 3> for ImageCloner<'_, 3> {
|
impl ClonerOverlay<4, 3> for ImageCloner<'_, 3> {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use = "function does not modify the original image"]
|
||||||
unsafe fn overlay(&self, with: &Image<&[u8], 4>) -> Image<Vec<u8>, 3> {
|
unsafe fn overlay(&self, with: &Image<&[u8], 4>) -> Image<Vec<u8>, 3> {
|
||||||
let mut out = self.dup();
|
let mut out = self.dup();
|
||||||
// SAFETY: same
|
// SAFETY: same
|
||||||
|
@ -271,6 +275,7 @@ impl OverlayAt<Image<&[u8], 4>> for Image<&mut [u8], 4> {
|
||||||
|
|
||||||
impl ClonerOverlayAt<4, 4> for ImageCloner<'_, 4> {
|
impl ClonerOverlayAt<4, 4> for ImageCloner<'_, 4> {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use = "function does not modify the original image"]
|
||||||
/// Overlay with => self at coordinates x, y, without blending, returning a new Image
|
/// Overlay with => self at coordinates x, y, without blending, returning a new Image
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
|
|
Loading…
Reference in a new issue