summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2023-04-07 20:41:22 -0600
committerSam Atkins <atkinssj@gmail.com>2023-05-05 15:20:44 +0100
commite7921cfe14c1c2d23c97c8f85a198c0df04ec14f (patch)
treee98a32e1803f492c4c2bdcf817455263972fb587 /Userland/Libraries/LibGUI
parent5a4c61838f6089cebe34d98732435787272fe50d (diff)
downloadserenity-e7921cfe14c1c2d23c97c8f85a198c0df04ec14f.zip
LibGfx: Add first_animated_frame_index method to ImageDecoder
Some image formats such as APNG may not use the first frame for animations.
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r--Userland/Libraries/LibGUI/ImageWidget.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/Userland/Libraries/LibGUI/ImageWidget.cpp b/Userland/Libraries/LibGUI/ImageWidget.cpp
index 4b422b0f76..d262a9b981 100644
--- a/Userland/Libraries/LibGUI/ImageWidget.cpp
+++ b/Userland/Libraries/LibGUI/ImageWidget.cpp
@@ -52,18 +52,20 @@ void ImageWidget::set_auto_resize(bool value)
// Same as ImageViewer::ViewWidget::animate(), you probably want to keep any changes in sync
void ImageWidget::animate()
{
- m_current_frame_index = (m_current_frame_index + 1) % m_image_decoder->frame_count();
+ auto first_animated_frame_index = m_image_decoder->first_animated_frame_index();
+ auto total_animated_frames = m_image_decoder->frame_count() - first_animated_frame_index;
+ m_current_frame_index = (m_current_frame_index + 1) % total_animated_frames;
- auto current_frame = m_image_decoder->frame(m_current_frame_index).release_value_but_fixme_should_propagate_errors();
+ auto current_frame = m_image_decoder->frame(first_animated_frame_index + m_current_frame_index).release_value_but_fixme_should_propagate_errors();
set_bitmap(current_frame.image);
if (current_frame.duration != m_timer->interval()) {
m_timer->restart(current_frame.duration);
}
- if (m_current_frame_index == m_image_decoder->frame_count() - 1) {
+ if (m_current_frame_index == total_animated_frames - 1) {
++m_loops_completed;
- if (m_loops_completed > 0 && m_loops_completed == m_image_decoder->loop_count()) {
+ if (m_image_decoder->loop_count() > 0 && m_loops_completed == m_image_decoder->loop_count()) {
m_timer->stop();
}
}