Skip to content

Commit

Permalink
Fix issues when drawing frames with crop fit. (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
r12f authored Jul 30, 2022
1 parent 2aaec5d commit 69acfe3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
17 changes: 16 additions & 1 deletion divoom/src/animation/animation_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,29 @@ mod tests {
);
}

#[test]
fn divoom_animation_builder_can_crop_animation() {
let frames = DivoomAnimationResourceLoader::from_gif_file(
"test_data/animation_builder_tests/input/logo.gif",
)
.unwrap();

let builder = DivoomAnimationBuilder::new(32, Duration::from_millis(100)).unwrap();
let animation = builder.draw_frames(&frames, 0).build();
test_utils::assert_animation_equal_with_baseline(
&animation,
"test_data/animation_builder_tests/expected_cropped_animation.gif",
);
}

#[test]
fn divoom_animation_builder_can_downscale_animation() {
let frames = DivoomAnimationResourceLoader::from_gif_file(
"test_data/animation_builder_tests/input/logo.gif",
)
.unwrap();

let builder = DivoomAnimationBuilder::new(64, Duration::from_millis(100)).unwrap();
let builder = DivoomAnimationBuilder::new(32, Duration::from_millis(100)).unwrap();
let animation = builder
.draw_frames_fit(
&frames,
Expand Down
6 changes: 3 additions & 3 deletions divoom/src/animation/animation_frame_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ impl DivoomAnimationFrameBuilder<'_> {

match fit {
DivoomDrawFitMode::Center => {
x = ((self.frame.width() - draw_width) / 2) as i32;
y = ((self.frame.height() - draw_height) / 2) as i32;
x = (self.frame.width() as i32 - draw_width as i32) / 2;
y = (self.frame.height() as i32 - draw_height as i32) / 2;
}

DivoomDrawFitMode::FitX => {
Expand All @@ -81,7 +81,7 @@ impl DivoomAnimationFrameBuilder<'_> {
DivoomDrawFitMode::FitY => {
draw_height = self.frame.height();
draw_width = (draw_height as f32 * frame_ratio).round() as u32;
x = ((self.frame.width() - draw_width) / 2) as i32;
x = (self.frame.width() as i32 - draw_width as i32) / 2;
}

DivoomDrawFitMode::Stretch => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 69acfe3

Please sign in to comment.