Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "webp"
version = "0.3.0"
authors = ["Jared Forth <jaredforthdev@gmail.com>"]
edition = "2018"
edition = "2021"

description = "WebP conversion library."

Expand Down
2 changes: 1 addition & 1 deletion src/animation_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 8 additions & 11 deletions src/animation_encoder.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down Expand Up @@ -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
Expand All @@ -83,16 +80,16 @@ impl<'a> From<&'a AnimFrame<'a>> for Encoder<'a> {
}
}
#[cfg(feature = "img")]
impl Into<DynamicImage> 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)
}
Expand Down Expand Up @@ -135,7 +132,7 @@ impl<'a> AnimEncoder<'a> {
self.try_encode().unwrap()
}
pub fn try_encode(&self) -> Result<WebPMemory, AnimEncodeError> {
unsafe { anim_encode(&self) }
unsafe { anim_encode(self) }
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ impl<'a> Encoder<'a> {
pub fn encode_advanced(&self, config: &WebPConfig) -> Result<WebPMemory, WebPEncodingError> {
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)
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down