mirror of
https://github.com/bend-n/fimg.git
synced 2024-12-22 10:28: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]);
|
||||
/// 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> {
|
||||
let mut out = self.alloc();
|
||||
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]);
|
||||
/// 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> {
|
||||
let mut out = self.alloc();
|
||||
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]);
|
||||
/// 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> {
|
||||
let s = (self.width() * self.height()) as usize;
|
||||
let mut v: Vec<[u8; CHANNELS]> = Vec::with_capacity(s);
|
||||
|
@ -140,6 +143,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
|
|||
/// # Safety
|
||||
///
|
||||
/// 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> {
|
||||
let mut out = self.flip_v();
|
||||
// SAFETY: sqar
|
||||
|
@ -151,6 +155,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
|
|||
/// # Safety
|
||||
///
|
||||
/// 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> {
|
||||
let mut out = self.flip_h();
|
||||
// SAFETY: sqar
|
||||
|
|
|
@ -246,6 +246,7 @@ impl<T: std::ops::Deref<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS
|
|||
}
|
||||
|
||||
/// Procure a [`ImageCloner`].
|
||||
#[must_use = "function does not modify the original image"]
|
||||
pub fn cloner(&self) -> ImageCloner<'_, CHANNELS> {
|
||||
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> {
|
||||
#[inline]
|
||||
#[must_use = "function does not modify the original image"]
|
||||
unsafe fn overlay(&self, with: &Image<&[u8], 4>) -> Image<Vec<u8>, 4> {
|
||||
let mut out = self.dup();
|
||||
// SAFETY: same
|
||||
|
@ -153,6 +154,8 @@ impl OverlayAt<Image<&[u8], 4>> for Image<&mut [u8], 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> {
|
||||
let mut new = self.dup();
|
||||
// SAFETY: same
|
||||
|
@ -225,6 +228,7 @@ impl Overlay<Image<&[u8], 4>> for Image<&mut [u8], 3> {
|
|||
|
||||
impl ClonerOverlay<4, 3> for ImageCloner<'_, 3> {
|
||||
#[inline]
|
||||
#[must_use = "function does not modify the original image"]
|
||||
unsafe fn overlay(&self, with: &Image<&[u8], 4>) -> Image<Vec<u8>, 3> {
|
||||
let mut out = self.dup();
|
||||
// SAFETY: same
|
||||
|
@ -271,6 +275,7 @@ impl OverlayAt<Image<&[u8], 4>> for Image<&mut [u8], 4> {
|
|||
|
||||
impl ClonerOverlayAt<4, 4> for ImageCloner<'_, 4> {
|
||||
#[inline]
|
||||
#[must_use = "function does not modify the original image"]
|
||||
/// Overlay with => self at coordinates x, y, without blending, returning a new Image
|
||||
///
|
||||
/// # Safety
|
||||
|
|
Loading…
Reference in a new issue