mirror of
https://github.com/bend-n/fimg.git
synced 2024-12-22 18:38:21 -06:00
remove redundant bounds (Deref is supertrait of DerefMut)
This commit is contained in:
parent
eed6423cba
commit
7c800b700e
|
@ -1,5 +1,5 @@
|
||||||
//! Manages the affine image transformations.
|
//! Manages the affine image transformations.
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::DerefMut;
|
||||||
|
|
||||||
use crate::{cloner::ImageCloner, Image};
|
use crate::{cloner::ImageCloner, Image};
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const CHANNELS: usize, T: Deref<Target = [u8]> + DerefMut<Target = [u8]>> Image<T, CHANNELS> {
|
impl<const CHANNELS: usize, T: DerefMut<Target = [u8]>> Image<T, CHANNELS> {
|
||||||
/// Flip an image vertically.
|
/// Flip an image vertically.
|
||||||
pub fn flip_v(&mut self) {
|
pub fn flip_v(&mut self) {
|
||||||
for y in 0..self.height() / 2 {
|
for y in 0..self.height() / 2 {
|
||||||
|
@ -131,7 +131,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const CHANNELS: usize, T: Deref<Target = [u8]> + DerefMut<Target = [u8]>> Image<T, CHANNELS> {
|
impl<const CHANNELS: usize, T: DerefMut<Target = [u8]>> Image<T, CHANNELS> {
|
||||||
/// Rotate an image 180 degrees clockwise.
|
/// Rotate an image 180 degrees clockwise.
|
||||||
pub fn rot_180(&mut self) {
|
pub fn rot_180(&mut self) {
|
||||||
self.flatten_mut().reverse();
|
self.flatten_mut().reverse();
|
||||||
|
@ -166,7 +166,7 @@ impl<const CHANNELS: usize, T: Deref<Target = [u8]> + DerefMut<Target = [u8]>> I
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// UB if supplied image rectangular
|
/// UB if supplied image rectangular
|
||||||
unsafe fn transpose<const CHANNELS: usize, T: Deref<Target = [u8]> + DerefMut<Target = [u8]>>(
|
unsafe fn transpose<const CHANNELS: usize, T: DerefMut<Target = [u8]>>(
|
||||||
img: &mut Image<T, CHANNELS>,
|
img: &mut Image<T, CHANNELS>,
|
||||||
) {
|
) {
|
||||||
debug_assert_eq!(img.width(), img.height());
|
debug_assert_eq!(img.width(), img.height());
|
||||||
|
@ -184,10 +184,7 @@ unsafe fn transpose<const CHANNELS: usize, T: Deref<Target = [u8]> + DerefMut<Ta
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// UB if image not square
|
/// UB if image not square
|
||||||
unsafe fn transpose_non_power_of_two<
|
unsafe fn transpose_non_power_of_two<const CHANNELS: usize, T: DerefMut<Target = [u8]>>(
|
||||||
const CHANNELS: usize,
|
|
||||||
T: Deref<Target = [u8]> + DerefMut<Target = [u8]>,
|
|
||||||
>(
|
|
||||||
img: &mut Image<T, CHANNELS>,
|
img: &mut Image<T, CHANNELS>,
|
||||||
) {
|
) {
|
||||||
debug_assert_eq!(img.width(), img.height());
|
debug_assert_eq!(img.width(), img.height());
|
||||||
|
@ -208,10 +205,7 @@ const TILE: usize = 4;
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// be careful
|
/// be careful
|
||||||
unsafe fn transpose_tile<
|
unsafe fn transpose_tile<const CHANNELS: usize, T: DerefMut<Target = [u8]>>(
|
||||||
const CHANNELS: usize,
|
|
||||||
T: Deref<Target = [u8]> + DerefMut<Target = [u8]>,
|
|
||||||
>(
|
|
||||||
img: &mut Image<T, CHANNELS>,
|
img: &mut Image<T, CHANNELS>,
|
||||||
row: usize,
|
row: usize,
|
||||||
col: usize,
|
col: usize,
|
||||||
|
@ -247,10 +241,7 @@ unsafe fn transpose_tile<
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// be careful
|
/// be careful
|
||||||
unsafe fn transpose_diag<
|
unsafe fn transpose_diag<const CHANNELS: usize, T: DerefMut<Target = [u8]>>(
|
||||||
const CHANNELS: usize,
|
|
||||||
T: Deref<Target = [u8]> + DerefMut<Target = [u8]>,
|
|
||||||
>(
|
|
||||||
img: &mut Image<T, CHANNELS>,
|
img: &mut Image<T, CHANNELS>,
|
||||||
pos: usize,
|
pos: usize,
|
||||||
size: usize,
|
size: usize,
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
//! `Box<cat>`
|
//! `Box<cat>`
|
||||||
use std::ops::{Deref, DerefMut, Range};
|
use std::ops::{DerefMut, Range};
|
||||||
|
|
||||||
use crate::Image;
|
use crate::Image;
|
||||||
|
|
||||||
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
impl<T: DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
||||||
/// Draw a bordered box
|
/// Draw a bordered box
|
||||||
/// ```
|
/// ```
|
||||||
/// # use fimg::Image;
|
/// # use fimg::Image;
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
//! adds a `line` function to Image
|
//! adds a `line` function to Image
|
||||||
#![allow(clippy::missing_docs_in_private_items)]
|
#![allow(clippy::missing_docs_in_private_items)]
|
||||||
use crate::Image;
|
use crate::Image;
|
||||||
use std::{
|
use std::{iter::Iterator, ops::DerefMut};
|
||||||
iter::Iterator,
|
|
||||||
ops::{Deref, DerefMut},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// taken from [bresenham-rs](https://github.com/mbr/bresenham-rs)
|
/// taken from [bresenham-rs](https://github.com/mbr/bresenham-rs)
|
||||||
pub struct Bresenham {
|
pub struct Bresenham {
|
||||||
|
@ -130,7 +127,7 @@ impl Iterator for Bresenham {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
impl<T: DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
||||||
/// Draw a line from point a to point b.
|
/// Draw a line from point a to point b.
|
||||||
///
|
///
|
||||||
/// Points not in bounds will not be included.
|
/// Points not in bounds will not be included.
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
//! draw polygons
|
//! draw polygons
|
||||||
use std::{
|
use std::{
|
||||||
cmp::{max, min},
|
cmp::{max, min},
|
||||||
ops::{Deref, DerefMut},
|
ops::DerefMut,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::Image;
|
use crate::Image;
|
||||||
|
|
||||||
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
impl<T: DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
||||||
/// Draws a filled polygon from a slice of points. Please close your poly. (first == last)
|
/// Draws a filled polygon from a slice of points. Please close your poly. (first == last)
|
||||||
///
|
///
|
||||||
/// Borrowed from [imageproc](https://docs.rs/imageproc/latest/src/imageproc/drawing/polygon.rs.html#31), modified for less allocations.
|
/// Borrowed from [imageproc](https://docs.rs/imageproc/latest/src/imageproc/drawing/polygon.rs.html#31), modified for less allocations.
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
//! trongle drawing
|
//! trongle drawing
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::DerefMut;
|
||||||
|
|
||||||
use crate::Image;
|
use crate::Image;
|
||||||
|
|
||||||
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
impl<T: DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
||||||
/// Draw a (filled) triangle
|
/// Draw a (filled) triangle
|
||||||
/// ```
|
/// ```
|
||||||
/// # use fimg::*;
|
/// # use fimg::*;
|
||||||
|
|
|
@ -100,9 +100,7 @@ unsafe fn blit(rgb: &mut [u8], rgba: &[u8]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, U: Deref<Target = [u8]>>
|
impl<T: DerefMut<Target = [u8]>, U: Deref<Target = [u8]>> Overlay<Image<U, 4>> for Image<T, 4> {
|
||||||
Overlay<Image<U, 4>> for Image<T, 4>
|
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn overlay(&mut self, with: &Image<U, 4>) -> &mut Self {
|
unsafe fn overlay(&mut self, with: &Image<U, 4>) -> &mut Self {
|
||||||
debug_assert!(self.width() == with.width());
|
debug_assert!(self.width() == with.width());
|
||||||
|
@ -129,9 +127,7 @@ impl ClonerOverlay<4, 4> for ImageCloner<'_, 4> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, U: Deref<Target = [u8]>>
|
impl<T: DerefMut<Target = [u8]>, U: Deref<Target = [u8]>> OverlayAt<Image<U, 4>> for Image<T, 3> {
|
||||||
OverlayAt<Image<U, 4>> for Image<T, 3>
|
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn overlay_at(&mut self, with: &Image<U, 4>, x: u32, y: u32) -> &mut Self {
|
unsafe fn overlay_at(&mut self, with: &Image<U, 4>, x: u32, y: u32) -> &mut Self {
|
||||||
// SAFETY: caller upholds this
|
// SAFETY: caller upholds this
|
||||||
|
@ -167,9 +163,7 @@ impl ClonerOverlayAt<4, 3> for ImageCloner<'_, 3> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, U: Deref<Target = [u8]>>
|
impl<T: DerefMut<Target = [u8]>, U: Deref<Target = [u8]>> OverlayAt<Image<U, 3>> for Image<T, 3> {
|
||||||
OverlayAt<Image<U, 3>> for Image<T, 3>
|
|
||||||
{
|
|
||||||
/// Overlay a RGB image(with) => self at coordinates x, y.
|
/// Overlay a RGB image(with) => self at coordinates x, y.
|
||||||
/// As this is a `RGBxRGB` operation, blending is unnecessary,
|
/// As this is a `RGBxRGB` operation, blending is unnecessary,
|
||||||
/// and this is simply a copy.
|
/// and this is simply a copy.
|
||||||
|
@ -208,9 +202,7 @@ impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, U: Deref<Target = [u8]>>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, U: Deref<Target = [u8]>>
|
impl<T: DerefMut<Target = [u8]>, U: Deref<Target = [u8]>> Overlay<Image<U, 4>> for Image<T, 3> {
|
||||||
Overlay<Image<U, 4>> for Image<T, 3>
|
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn overlay(&mut self, with: &Image<U, 4>) -> &mut Self {
|
unsafe fn overlay(&mut self, with: &Image<U, 4>) -> &mut Self {
|
||||||
debug_assert!(self.width() == with.width());
|
debug_assert!(self.width() == with.width());
|
||||||
|
@ -244,9 +236,7 @@ impl ClonerOverlay<4, 3> for ImageCloner<'_, 3> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, U: Deref<Target = [u8]>>
|
impl<T: DerefMut<Target = [u8]>, U: Deref<Target = [u8]>> OverlayAt<Image<U, 4>> for Image<T, 4> {
|
||||||
OverlayAt<Image<U, 4>> for Image<T, 4>
|
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Overlay with => self at coordinates x, y, without blending
|
/// Overlay with => self at coordinates x, y, without blending
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in a new issue