Skip to content
Open
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
14 changes: 7 additions & 7 deletions src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::cmp::Ordering;
use std::time::Duration;

use crate::error::ImageResult;
use crate::RgbaImage;
use crate::DynamicImage;

/// An implementation dependent iterator, reading the frames as requested
pub struct Frames<'a> {
Expand Down Expand Up @@ -43,7 +43,7 @@ pub struct Frame {
left: u32,
/// y offset
top: u32,
buffer: RgbaImage,
buffer: DynamicImage,
}

/// The delay of a frame relative to the previous one.
Expand All @@ -68,7 +68,7 @@ pub struct Delay {
impl Frame {
/// Constructs a new frame without any delay.
#[must_use]
pub fn new(buffer: RgbaImage) -> Frame {
pub fn new(buffer: DynamicImage) -> Frame {
Frame {
delay: Delay::from_ratio(Ratio { numer: 0, denom: 1 }),
left: 0,
Expand All @@ -79,7 +79,7 @@ impl Frame {

/// Constructs a new frame
#[must_use]
pub fn from_parts(buffer: RgbaImage, left: u32, top: u32, delay: Delay) -> Frame {
pub fn from_parts(buffer: DynamicImage, left: u32, top: u32, delay: Delay) -> Frame {
Frame {
delay,
left,
Expand All @@ -96,18 +96,18 @@ impl Frame {

/// Returns the image buffer
#[must_use]
pub fn buffer(&self) -> &RgbaImage {
pub fn buffer(&self) -> &DynamicImage {
&self.buffer
}

/// Returns a mutable image buffer
pub fn buffer_mut(&mut self) -> &mut RgbaImage {
pub fn buffer_mut(&mut self) -> &mut DynamicImage {
&mut self.buffer
}

/// Returns the image buffer
#[must_use]
pub fn into_buffer(self) -> RgbaImage {
pub fn into_buffer(self) -> DynamicImage {
self.buffer
}

Expand Down
2 changes: 1 addition & 1 deletion src/codecs/gif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ impl<W: Write> GifEncoder<W> {
// get the delay before converting img_frame
let frame_delay = img_frame.delay().into_ratio().to_integer();
// convert img_frame into RgbaImage
let mut rbga_frame = img_frame.into_buffer();
let mut rbga_frame = img_frame.into_buffer().to_rgba8();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is odd. While consistent with automatically converting for other encoding of DynamicImage, this can only happen here since it is DynamicImage and can not be another input that we'd reject automatically converting.

This feels like a right change but I do find it remarkable regardless.

let (width, height) = self.gif_dimensions(rbga_frame.width(), rbga_frame.height())?;

// Create the gif::Frame from the animation::Frame
Expand Down
1 change: 0 additions & 1 deletion src/io/image_reader_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,6 @@ impl<'stream> ImageReader<'stream> {
let x = frame_decoded.attributes().x;
let y = frame_decoded.attributes().y;
let delay = frame_decoded.attributes().delay.unwrap_or(no_delay);
let frame = frame.into_rgba8();

let frame = Frame::from_parts(frame, x, y, delay);
Some(Ok(frame))
Expand Down
6 changes: 2 additions & 4 deletions tests/reference_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ fn main() -> std::process::ExitCode {
// Select a single frame
let frame = frames.drain(frame_num..).next().unwrap();

// Convert the frame to a`RgbaImage`
DynamicImage::from(frame.into_buffer())
frame.into_buffer()
}

#[cfg(feature = "png")]
Expand All @@ -121,8 +120,7 @@ fn main() -> std::process::ExitCode {
// Select a single frame
let frame = frames.drain(frame_num..).next().unwrap();

// Convert the frame to a`RgbaImage`
DynamicImage::from(frame.into_buffer())
frame.into_buffer()
}
_ => unreachable!(
"Format is unspported or disabled. Should have been detected earlier"
Expand Down
Loading