fast image operations
-rw-r--r--Cargo.toml5
-rw-r--r--src/dyn/mod.rs2
-rw-r--r--src/lib.rs6
-rw-r--r--src/overlay.rs2
-rw-r--r--src/term/b64.rs16
5 files changed, 14 insertions, 17 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 4c3e2bc..a649510 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@ categories = ["multimedia::images", "graphics"]
[dependencies]
mattr = "0.0.2"
-png = { version = "0.17", features = ["unstable"], optional = true }
+png = { version = "0.18", features = ["unstable"], optional = true }
fontdue = { version = "0.7.3", optional = true }
vecto = "0.1.1"
umath = "0.0.7"
@@ -83,3 +83,6 @@ incremental = true
[package.metadata.docs.rs]
all-features = true
+
+[patch.crates-io]
+png = { git = "https://github.com/bend-n/image-png" }
diff --git a/src/dyn/mod.rs b/src/dyn/mod.rs
index a760813..c36a7c1 100644
--- a/src/dyn/mod.rs
+++ b/src/dyn/mod.rs
@@ -161,7 +161,7 @@ impl DynImage<Box<[u8]>> {
let mut dec = png::Decoder::new(r);
dec.set_transformations(T::STRIP_16 | T::EXPAND);
let mut reader = dec.read_info().unwrap();
- let mut buf = vec![0; reader.output_buffer_size()].into_boxed_slice();
+ let mut buf = vec![0; reader.output_buffer_size().unwrap()].into_boxed_slice();
let info = reader.next_frame(&mut buf).unwrap();
use png::ColorType::*;
match info.color_type {
diff --git a/src/lib.rs b/src/lib.rs
index c4dccc8..447aea0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -869,7 +869,7 @@ where
Self: Sized,
{
/// Read a png into an image.
- fn read(f: &mut impl std::io::Read) -> std::io::Result<Self>;
+ fn read<T: std::io::BufRead + std::io::Seek>(f: &mut T) -> std::io::Result<Self>;
}
/// helper macro for defining the save() method.
@@ -916,7 +916,7 @@ macro_rules! read {
#[cfg(feature = "save")]
impl ReadPng for Image<Box<[u8]>, $n> {
/// Open a PNG image
- fn read(f: &mut impl std::io::Read) -> std::io::Result<Self> {
+ fn read<T: std::io::BufRead + std::io::Seek>(f: &mut T) -> std::io::Result<Self> {
use png::Transformations as T;
let mut dec = png::Decoder::new(f);
match $n {
@@ -925,7 +925,7 @@ macro_rules! read {
_ => (),
}
let mut reader = dec.read_info()?;
- let mut buf = vec![0; reader.output_buffer_size()].into_boxed_slice();
+ let mut buf = vec![0; reader.output_buffer_size().unwrap()].into_boxed_slice();
let info = reader.next_frame(&mut buf)?;
use png::ColorType::*;
macro_rules! n {
diff --git a/src/overlay.rs b/src/overlay.rs
index 79fc4b7..6a0bfdb 100644
--- a/src/overlay.rs
+++ b/src/overlay.rs
@@ -92,7 +92,7 @@ unsafe fn blit(mut rgb: &mut [u8], mut rgba: &[u8]) {
let old = Simd::from_slice(dst);
let new: u8x16 = Simd::from_slice(src);
- let threshold = new.simd_ge(Simd::splat(128)).to_int().cast::<u8>();
+ let threshold = new.simd_ge(Simd::splat(128)).to_simd().cast::<u8>();
let mut mask = simd_swizzle!(
threshold,
// [r, g, b, a (3)] [r, g, b, a(7)]
diff --git a/src/term/b64.rs b/src/term/b64.rs
index 2b0ae44..b91cdfd 100644
--- a/src/term/b64.rs
+++ b/src/term/b64.rs
@@ -4,7 +4,7 @@ use core::intrinsics::simd::simd_cast;
use std::arch::x86_64::*;
use std::{
intrinsics::transmute_unchecked,
- simd::{prelude::*, LaneCount, MaskElement, SimdElement, SupportedLaneCount},
+ simd::{MaskElement, SimdElement, prelude::*},
};
#[test]
@@ -31,22 +31,16 @@ trait Cast<T, const N: usize> {
fn cas<U: SimdT>(self) -> U;
}
trait SimdT {}
-impl<T: SimdElement, const N: usize> SimdT for Simd<T, N> where LaneCount<N>: SupportedLaneCount {}
-impl<T: MaskElement, const N: usize> SimdT for Mask<T, N> where LaneCount<N>: SupportedLaneCount {}
-impl<T: SimdElement, const N: usize> Cast<T, N> for Simd<T, N>
-where
- LaneCount<N>: SupportedLaneCount,
-{
+impl<T: SimdElement, const N: usize> SimdT for Simd<T, N> {}
+impl<T: MaskElement, const N: usize> SimdT for Mask<T, N> {}
+impl<T: SimdElement, const N: usize> Cast<T, N> for Simd<T, N> {
fn cas<U>(self) -> U {
assert!(std::mem::size_of::<U>() == std::mem::size_of::<Self>());
unsafe { transmute_unchecked(self) }
}
}
-impl<T: MaskElement, const N: usize> Cast<T, N> for Mask<T, N>
-where
- LaneCount<N>: SupportedLaneCount,
-{
+impl<T: MaskElement, const N: usize> Cast<T, N> for Mask<T, N> {
fn cas<U>(self) -> U {
assert!(std::mem::size_of::<U>() == std::mem::size_of::<Self>());
unsafe { transmute_unchecked(self) }