On Tue, 3 Nov 2026 16:04:43 GMT, Alexey Ivanov <[email protected]> wrote:
> If a GIF image contains one frame and the loop count isn't set to 1, it is > still animated. > > The GIF decoder starts the animation thread that decodes the single frame > over and over again. The image itself looks static, but decoding consumes CPU > and memory. > > The proposed fix stops animating the image if it contains one frame only. > > --------- > - [x] I confirm that I make this contribution in accordance with the [OpenJDK > Interim AI Policy](https://openjdk.org/legal/ai). test/jdk/javax/imageio/plugins/gif/GIFLoopAnimationTest.java line 44: > 42: * @summary One-frame GIF without loop extension doesn't animate > 43: * @build GIFWriter > 44: * @run main GIFLoopAnimationTest one-frame `#one-frame` is a sanity check that no animation starts if the GIF image has one frame and has no looping indicator. In this case, `JLabel.imageUpdate` is never called, so the test relies on timeout. I disabled running this test to avoid wasting the time. test/jdk/javax/imageio/plugins/gif/GIFLoopAnimationTest.java line 74: > 72: > 73: /* > 74: * @test id=five-frames-loop5 While working on this issue, I discovered another bug where GIF image continues animating after displaying all frames the specified amount of times. I submitted [JDK-8396534](https://bugs.openjdk.org/browse/JDK-8396534), and problem-listed `#five-frames-loop5` subtest. test/jdk/javax/imageio/plugins/gif/GIFWriter.java line 48: > 46: * written into the file. > 47: */ > 48: public final class GIFWriter implements AutoCloseable { `GIFWriter` is largely inspired by `AnimationTest`. The test could be updated to re-use the common code from `GIFWriter` to generate the GIF image. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/33701#discussion_r4457253574 PR Review Comment: https://git.openjdk.org/jdk/pull/33701#discussion_r4457318235 PR Review Comment: https://git.openjdk.org/jdk/pull/33701#discussion_r4457289504
