diff --git a/Cargo.toml b/Cargo.toml index 0f87db6..6b0fcab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "webp" version = "0.3.0" authors = ["Jared Forth "] -edition = "2018" +edition = "2021" description = "WebP conversion library." diff --git a/src/animation_decoder.rs b/src/animation_decoder.rs index 6cc8601..7f18c22 100644 --- a/src/animation_decoder.rs +++ b/src/animation_decoder.rs @@ -52,8 +52,8 @@ impl<'a> AnimDecoder<'a> { if ok != 0 { let len = (if has_alpha { 4 } else { 3 } * width * height) as usize; let mut img = Vec::with_capacity(len); + buf.copy_to(img.spare_capacity_mut().as_mut_ptr().cast(), len); img.set_len(len); - buf.copy_to(img.as_mut_ptr(), len); let layout = if has_alpha { PixelLayout::Rgba } else { diff --git a/src/animation_encoder.rs b/src/animation_encoder.rs index 049eccb..c4e9f9f 100644 --- a/src/animation_encoder.rs +++ b/src/animation_encoder.rs @@ -1,10 +1,7 @@ #[cfg(feature = "img")] -use image::DynamicImage; +use image::{DynamicImage, ImageBuffer}; use libwebp_sys::*; -#[cfg(feature = "img")] -use image::*; - use crate::{shared::*, Encoder}; pub struct AnimFrame<'a> { @@ -62,7 +59,7 @@ impl<'a> AnimFrame<'a> { Self::new(image, PixelLayout::Rgba, width, height, timestamp, None) } pub fn get_image(&self) -> &[u8] { - &self.image + self.image } pub fn get_layout(&self) -> PixelLayout { self.layout @@ -83,16 +80,16 @@ impl<'a> From<&'a AnimFrame<'a>> for Encoder<'a> { } } #[cfg(feature = "img")] -impl Into for &AnimFrame<'_> { - fn into(self) -> DynamicImage { - if self.layout.is_alpha() { +impl From<&AnimFrame<'_>> for DynamicImage { + fn from(value: &AnimFrame<'_>) -> DynamicImage { + if value.layout.is_alpha() { let image = - ImageBuffer::from_raw(self.width(), self.height(), self.get_image().to_owned()) + ImageBuffer::from_raw(value.width(), value.height(), value.get_image().to_owned()) .expect("ImageBuffer couldn't be created"); DynamicImage::ImageRgba8(image) } else { let image = - ImageBuffer::from_raw(self.width(), self.height(), self.get_image().to_owned()) + ImageBuffer::from_raw(value.width(), value.height(), value.get_image().to_owned()) .expect("ImageBuffer couldn't be created"); DynamicImage::ImageRgb8(image) } @@ -135,7 +132,7 @@ impl<'a> AnimEncoder<'a> { self.try_encode().unwrap() } pub fn try_encode(&self) -> Result { - unsafe { anim_encode(&self) } + unsafe { anim_encode(self) } } } diff --git a/src/encoder.rs b/src/encoder.rs index d44bee5..4590061 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -90,8 +90,7 @@ impl<'a> Encoder<'a> { pub fn encode_advanced(&self, config: &WebPConfig) -> Result { unsafe { let mut picture = new_picture(self.image, self.layout, self.width, self.height); - let res = encode(&mut *picture, config); - res + encode(&mut picture, config) } } } @@ -129,7 +128,7 @@ unsafe fn encode( picture.custom_ptr = ww.as_mut_ptr() as *mut std::ffi::c_void; let status = libwebp_sys::WebPEncode(config, picture); let ww = ww.assume_init(); - let mem = WebPMemory(ww.mem, ww.size as usize); + let mem = WebPMemory(ww.mem, ww.size); if status != VP8StatusCode::VP8_STATUS_OK as i32 { Ok(mem) } else {