Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented May 31, 2023

Resolves #6164

Changes:

  • Removes if statement that caused single frame GIFs to be ignored
  • Adds a single frame test GIF (converted \docs\yuidoc-p5-theme\assets\rockies.jpg -> rockies.gif)
  • Adds a manual test that loads a single frame and animated GIF side by side (animated GIF from same folder)

Screenshots of the change:

Manual test is here: ./test/manual-test-examples/p5.Image/load-gifs.html

  • Gif on left is a single-frame GIF
  • GIF on right was from \docs\yuidoc-p5-theme\assets\arnott-wallace-eye-loop-forever.gif
  • Also tested with external image to confirm (see dog), but didn't include in case of copyright

ezgif com-video-to-gif (3)
image

PR Checklist

Oz Ramos and others added 5 commits May 30, 2023 20:34
@welcome
Copy link

welcome bot commented May 31, 2023

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on! I think this looks good, I just had one idea I left in a comment for some extra optimization. But if it turns out that that doesn't work, your current implementation is good too!

// so we have to reset it to the first frame
pImg.drawingContext.putImageData(frames[0].image, 0, 0);

pImg.gifProperties = {
Copy link
Contributor

Choose a reason for hiding this comment

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

How do you feel about adding the if statement back just on this block here? If there's just one frame in the gif, if we don't set gifProperties, we can maybe save a few cpu cycles by avoiding trying to calculate what frame it should be on by treating it like a normal image from here on out. At least I think so anyway, your new tests will help confirm it 🙂

Copy link
Contributor

@davepagurek davepagurek May 31, 2023

Choose a reason for hiding this comment

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

I think that should fix the test that's currently failing, which has the title "single frame gif should not have gifProperties". But if there are other complications, it's not the end of the world if they do have that, so we can talk about updating the test if we can't get it to work otherwise.

Copy link
Author

Choose a reason for hiding this comment

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

Wow this is great feedback thanks! It's exactly why I was hoping to contribute :)

I totally agree and have submitted the conditional! But I'm kinda new to PRs so I'm not sure if they were added to this one...it looks like they were?

I took some time to look at where else gifProperties is being used but I think this is safe because the first frame is stored into the pImg, which is what eventually gets drawn. One thing to note is that this may prevent the ability add extra frames later (for example, to make use of the automatic GIF features), but that might not be intended anyways

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, I think we don't have any officially documented APIs for adding frames to imported gifs so I think we should be good!

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

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

Great work @ozramos!

@davepagurek davepagurek merged commit e6d1936 into processing:main Jun 2, 2023
@davepagurek
Copy link
Contributor

@all-contributors please add @ozramos for code

@allcontributors
Copy link
Contributor

@davepagurek

I've put up a pull request to add @ozramos! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem with loadImage() from version 0.10.0 onwards

1 participant