Skip to content

Commit d523893

Browse files
jwieslerjaredforth
andauthored
Chores: Clippy, edition upgrade (#36)
* Duplicate imports * Upgrade edition * Clippy --------- Co-authored-by: Jared Forth <[email protected]>
1 parent 4442747 commit d523893

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "webp"
33
version = "0.3.0"
44
authors = ["Jared Forth <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66

77
description = "WebP conversion library."
88

src/animation_decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ impl<'a> AnimDecoder<'a> {
5252
if ok != 0 {
5353
let len = (if has_alpha { 4 } else { 3 } * width * height) as usize;
5454
let mut img = Vec::with_capacity(len);
55+
buf.copy_to(img.spare_capacity_mut().as_mut_ptr().cast(), len);
5556
img.set_len(len);
56-
buf.copy_to(img.as_mut_ptr(), len);
5757
let layout = if has_alpha {
5858
PixelLayout::Rgba
5959
} else {

src/animation_encoder.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#[cfg(feature = "img")]
2-
use image::DynamicImage;
2+
use image::{DynamicImage, ImageBuffer};
33
use libwebp_sys::*;
44

5-
#[cfg(feature = "img")]
6-
use image::*;
7-
85
use crate::{shared::*, Encoder};
96

107
pub struct AnimFrame<'a> {
@@ -62,7 +59,7 @@ impl<'a> AnimFrame<'a> {
6259
Self::new(image, PixelLayout::Rgba, width, height, timestamp, None)
6360
}
6461
pub fn get_image(&self) -> &[u8] {
65-
&self.image
62+
self.image
6663
}
6764
pub fn get_layout(&self) -> PixelLayout {
6865
self.layout
@@ -83,16 +80,16 @@ impl<'a> From<&'a AnimFrame<'a>> for Encoder<'a> {
8380
}
8481
}
8582
#[cfg(feature = "img")]
86-
impl Into<DynamicImage> for &AnimFrame<'_> {
87-
fn into(self) -> DynamicImage {
88-
if self.layout.is_alpha() {
83+
impl From<&AnimFrame<'_>> for DynamicImage {
84+
fn from(value: &AnimFrame<'_>) -> DynamicImage {
85+
if value.layout.is_alpha() {
8986
let image =
90-
ImageBuffer::from_raw(self.width(), self.height(), self.get_image().to_owned())
87+
ImageBuffer::from_raw(value.width(), value.height(), value.get_image().to_owned())
9188
.expect("ImageBuffer couldn't be created");
9289
DynamicImage::ImageRgba8(image)
9390
} else {
9491
let image =
95-
ImageBuffer::from_raw(self.width(), self.height(), self.get_image().to_owned())
92+
ImageBuffer::from_raw(value.width(), value.height(), value.get_image().to_owned())
9693
.expect("ImageBuffer couldn't be created");
9794
DynamicImage::ImageRgb8(image)
9895
}
@@ -135,7 +132,7 @@ impl<'a> AnimEncoder<'a> {
135132
self.try_encode().unwrap()
136133
}
137134
pub fn try_encode(&self) -> Result<WebPMemory, AnimEncodeError> {
138-
unsafe { anim_encode(&self) }
135+
unsafe { anim_encode(self) }
139136
}
140137
}
141138

src/encoder.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ impl<'a> Encoder<'a> {
9090
pub fn encode_advanced(&self, config: &WebPConfig) -> Result<WebPMemory, WebPEncodingError> {
9191
unsafe {
9292
let mut picture = new_picture(self.image, self.layout, self.width, self.height);
93-
let res = encode(&mut *picture, config);
94-
res
93+
encode(&mut picture, config)
9594
}
9695
}
9796
}
@@ -129,7 +128,7 @@ unsafe fn encode(
129128
picture.custom_ptr = ww.as_mut_ptr() as *mut std::ffi::c_void;
130129
let status = libwebp_sys::WebPEncode(config, picture);
131130
let ww = ww.assume_init();
132-
let mem = WebPMemory(ww.mem, ww.size as usize);
131+
let mem = WebPMemory(ww.mem, ww.size);
133132
if status != VP8StatusCode::VP8_STATUS_OK as i32 {
134133
Ok(mem)
135134
} else {

0 commit comments

Comments
 (0)