From 25af373b34e489c6a081b3a5d2e6a4695e6199a1 Mon Sep 17 00:00:00 2001 From: Julian Wiesler Date: Tue, 2 Apr 2024 20:30:11 +0200 Subject: [PATCH 1/3] Duplicate imports --- src/animation_encoder.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/animation_encoder.rs b/src/animation_encoder.rs index 6547c8c..2f398fc 100644 --- a/src/animation_encoder.rs +++ b/src/animation_encoder.rs @@ -1,12 +1,9 @@ use std::ffi::CString; #[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> { From 2215ee685a678baa0cdd216cdf28d74fe7684637 Mon Sep 17 00:00:00 2001 From: Julian Wiesler Date: Tue, 2 Apr 2024 20:43:53 +0200 Subject: [PATCH 2/3] Upgrade edition --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 56cce62..3f6a446 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "webp" version = "0.2.6" authors = ["Jared Forth "] -edition = "2018" +edition = "2021" description = "WebP conversion library." From d416fddcbad78d59e64e94067bb0efc8c1f1f95a Mon Sep 17 00:00:00 2001 From: Julian Wiesler Date: Tue, 2 Apr 2024 20:43:59 +0200 Subject: [PATCH 3/3] Clippy --- src/animation_decoder.rs | 2 +- src/animation_encoder.rs | 14 +++++++------- src/encoder.rs | 5 ++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/animation_decoder.rs b/src/animation_decoder.rs index 86e4afc..6d822bc 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 2f398fc..5f0a6f3 100644 --- a/src/animation_encoder.rs +++ b/src/animation_encoder.rs @@ -61,7 +61,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 @@ -82,16 +82,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) } @@ -134,7 +134,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 ee1f915..fc59a7e 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 {