This commit is contained in:
bendn 2024-01-23 07:21:17 +07:00
parent 698f8d468a
commit 9210b2500f
No known key found for this signature in database
GPG key ID: 0D9D3A2A3B2A93D6
5 changed files with 11 additions and 16 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "fimg" name = "fimg"
version = "0.4.32" version = "0.4.33"
authors = ["bend-n <bend.n@outlook.com>"] authors = ["bend-n <bend.n@outlook.com>"]
license = "MIT" license = "MIT"
edition = "2021" edition = "2021"

View file

@ -207,10 +207,10 @@ unsafe fn transpose<const CHANNELS: usize, T: AsMut<[u8]> + AsRef<[u8]>>(
) { ) {
debug_assert_eq!(img.width(), img.height()); debug_assert_eq!(img.width(), img.height());
if img.width().is_power_of_two() { if img.width().is_power_of_two() {
// SAFETY: caller gurantees // SAFETY: caller guarantees
unsafe { transpose_diag(img, 0, img.width() as usize) }; unsafe { transpose_diag(img, 0, img.width() as usize) };
} else { } else {
// SAFETY: caller gurantees // SAFETY: caller guarantees
unsafe { transpose_non_power_of_two(img) }; unsafe { transpose_non_power_of_two(img) };
} }
} }

View file

@ -8,7 +8,8 @@
//! //!
//! - [`Image`]: the main image type. //! - [`Image`]: the main image type.
//! - [`DynImage`]: This is the image type you use when, say, loading a png. You should immediately convert this into a //! - [`DynImage`]: This is the image type you use when, say, loading a png. You should immediately convert this into a
//! - [`ImageCloner`]: this is... a [`Image`], but about to be cloned. It just allows some simple out-of-place optimizations, that `.clone().op()` dont allow. (produce with [`Image::cloner`]) //! - [`ImageCloner`]: This is... a [`Image`], but about to be cloned. It just allows some simple out-of-place optimizations, that `.clone().op()` dont allow. (produce with [`Image::cloner`])
//! - [`uninit::Image`]: A uninitialized image. Used for performance optimization.
//! //!
//! ### Operations //! ### Operations
//! //!
@ -283,7 +284,7 @@ impl<T, const CHANNELS: usize> Image<T, CHANNELS> {
/// # Safety /// # Safety
/// ///
/// the output index is not guranteed to be in bounds /// the output index is not guaranteed to be in bounds
#[inline] #[inline]
fn at(&self, x: u32, y: u32) -> usize { fn at(&self, x: u32, y: u32) -> usize {
(self.width(), self.height()).at::<CHANNELS>(x, y) (self.width(), self.height()).at::<CHANNELS>(x, y)
@ -418,7 +419,7 @@ impl<T, const CHANNELS: usize> Image<T, CHANNELS> {
/// # Safety /// # Safety
/// ///
/// the output index is not guranteed to be in bounds /// the output index is not guaranteed to be in bounds
#[inline] #[inline]
fn slice<U>(&self, x: u32, y: u32) -> Range<usize> fn slice<U>(&self, x: u32, y: u32) -> Range<usize>
where where

View file

@ -76,7 +76,7 @@ unsafe fn blit(rgb: &mut [u8], rgba: &[u8]) {
while dsti + 16 <= rgb.len() { while dsti + 16 <= rgb.len() {
// SAFETY: i think it ok // SAFETY: i think it ok
let old: Simd<u8, 16> = Simd::from_slice(unsafe { rgb.get_unchecked(dsti..dsti + 16) }); let old: Simd<u8, 16> = Simd::from_slice(unsafe { rgb.get_unchecked(dsti..dsti + 16) });
// SAFETY: definetly ok // SAFETY: definitly ok
let new: Simd<u8, 16> = Simd::from_slice(unsafe { rgba.get_unchecked(srci..srci + 16) }); let new: Simd<u8, 16> = Simd::from_slice(unsafe { rgba.get_unchecked(srci..srci + 16) });
let threshold = new.simd_ge(Simd::splat(128)).to_int().cast::<u8>(); let threshold = new.simd_ge(Simd::splat(128)).to_int().cast::<u8>();
@ -98,7 +98,7 @@ unsafe fn blit(rgb: &mut [u8], rgba: &[u8]) {
} }
while dsti + 3 <= rgb.len() { while dsti + 3 <= rgb.len() {
// SAFETY: caller gurantees slice is big enough // SAFETY: caller guarantees slice is big enough
if unsafe { *rgba.get_unchecked(srci + 3) } >= 128 { if unsafe { *rgba.get_unchecked(srci + 3) } >= 128 {
// SAFETY: slice is big enough! // SAFETY: slice is big enough!
let src = unsafe { rgba.get_unchecked(srci..=srci + 2) }; let src = unsafe { rgba.get_unchecked(srci..=srci + 2) };

View file

@ -1,14 +1,8 @@
//! the houser of uninitialized memory. €$@!0В𴬔!℡ //! the houser of uninitialized memory. €$@!0В𴬔!℡
//! //!
//! contains [`Image`], an uninitialized image. //! contains [`Image`], an uninitialized image.
use std::{
hint::assert_unchecked,
mem::MaybeUninit,
num::NonZeroU32,
ops::{Index, IndexMut},
};
use crate::{span::Span, CopyWithinUnchecked}; use crate::{span::Span, CopyWithinUnchecked};
use std::{hint::assert_unchecked, mem::MaybeUninit, num::NonZeroU32, ops::Index};
/// A uninitialized image. Be sure to initialize it! /// A uninitialized image. Be sure to initialize it!
pub struct Image<T: Copy, const CHANNELS: usize> { pub struct Image<T: Copy, const CHANNELS: usize> {
@ -72,7 +66,7 @@ impl<T: Copy, const CHANNELS: usize> Image<T, CHANNELS> {
/// # Safety /// # Safety
/// ///
/// the output index is not guranteed to be in bounds /// the output index is not guaranteed to be in bounds
#[inline] #[inline]
pub fn at(&self, x: u32, y: u32) -> usize { pub fn at(&self, x: u32, y: u32) -> usize {
crate::At::at::<CHANNELS>((self.width(), self.height()), x, y) crate::At::at::<CHANNELS>((self.width(), self.height()), x, y)