Opened 3 months ago

Closed 3 months ago

Last modified 3 months ago

#16392 closed defect (fixed)

Animated Gifs saved with wxGIFHandler always have the same delay

Reported by: elvissteinjr Owned by: VZ
Priority: low Milestone:
Component: GUI-generic Version: dev-latest
Keywords: wxGIFHandler simple Cc:
Blocked By: Blocking:
Patch: yes

Description

wxGifHandler::SaveAnimation() has a delayMilliSecs argument, but it's being not used correctly.

The delay itself is applied in this piece of code:

bool wxGIFHandler_WriteControl(wxOutputStream *stream,
    int maskIndex, int delayMilliSecs)
{
    wxUint8 buf[8];

    buf[0] = GIF_MARKER_EXT;    // extension marker
    buf[1] = GIF_MARKER_EXT_GRAPHICS_CONTROL;
    buf[2] = 4;     // length of block
    buf[3] = (maskIndex != wxNOT_FOUND) ? 1 : 0;   // has transparency
    buf[4] = delayMilliSecs / 10; // delay time
    buf[5] = 0;
    buf[6] = (maskIndex != wxNOT_FOUND) ? (wxUint8) maskIndex : 0;
    buf[7] = 0;
    return wxGIFHandler_Write(stream, buf, sizeof(buf));
}

(common/imaggif.cpp, line 720+)

However, while the delay time in a gif file is a 2 bytes value, the second byte just gets set to 0 in the code.

The resulting files had a delay of 0x00 0x00 in my tests (using GCC, if that matters), regardless of the delay value supplied to the function.
Most image viewers play these files with a slow animation speed, probably defaulting to it.

Attachments (1)

gifdelayfix.patch download (863 bytes) - added by elvissteinjr 3 months ago.
Fixes the animation delay being wrongly written to the gif file

Download all attachments as: .zip

Change History (5)

comment:1 Changed 3 months ago by vadz

  • Keywords simple added
  • Priority changed from normal to low
  • Status changed from new to confirmed

This seems simple to fix, if you can please do it and test that the fix works, please don't hesitate to submit a patch with your fixes.

BTW, we should probably give an error and return false from here if delayMilliSecs is greater than 10*USHRT_MAX as it wouldn't be representable as a single word in this case.

Changed 3 months ago by elvissteinjr

Fixes the animation delay being wrongly written to the gif file

comment:2 Changed 3 months ago by elvissteinjr

  • Patch set

comment:3 Changed 3 months ago by VZ

  • Owner set to VZ
  • Resolution set to fixed
  • Status changed from confirmed to closed

In 76951:

Write delay between frames correctly when saving GIF files.

Deal with delays greater than ~2.5s correctly, their most significant byte was
previously lost resulting in 0 delay being written to the file.

Closes #16392.

comment:4 Changed 3 months ago by VZ

In 76952:

Write delay between frames correctly when saving GIF files.

Deal with delays greater than ~2.5s correctly, their most significant byte was
previously lost resulting in 0 delay being written to the file.

Closes #16392.

Note: See TracTickets for help on using tickets.