Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gif repeat bug #3

Open
Nickesm opened this issue Feb 2, 2014 · 8 comments
Open

Gif repeat bug #3

Nickesm opened this issue Feb 2, 2014 · 8 comments

Comments

@Nickesm
Copy link

Nickesm commented Feb 2, 2014

The Repeat property of the gif encoder class works with the values:
-1 = No repeat.
0 = Repeat forever.
n = +Iterations. (if n set to 3, the frames will be displayed 4 times)

The problem is, if i set n to 1, iterates 3 times. But not 2 times as expected!

@cdonges
Copy link

cdonges commented Feb 19, 2014

If I set it to one I am getting two iterations. I can't work out how to make it go through the frames once only.

@Nickesm
Copy link
Author

Nickesm commented Feb 21, 2014

Yep, same with me, maybe removing the "NETSCAPE 2.0" tag will fix that.

@Nickesm Nickesm closed this as completed Feb 21, 2014
@Nickesm Nickesm reopened this Feb 21, 2014
@DataDink
Copy link
Owner

Just posting to say I've seen this issue, but will not be able to attack it right now. I am hopeful time will be available soon for this library.

@Nickesm
Copy link
Author

Nickesm commented Feb 21, 2014

Alright, I'm gonna try removing the ApplicationIdentification tag or changing the FileVersion to the first GIF specification.

@cdonges
Copy link

cdonges commented Feb 24, 2014

Looks like different browsers implement the standard differently:
https://bugzilla.mozilla.org/show_bug.cgi?id=222176

@Nickesm
Copy link
Author

Nickesm commented Feb 24, 2014

oh, no!

@JimBobSquarePants
Copy link
Contributor

If I read the property item 0x5101 of a gif that only plays once without repeating I get the value {1, 0} which translates to 1 which if we set in the encoder will cause it to play once then loop once.

This, to me means that the signature of the gif encoder is incorrect as Microsoft are interpreting the loopcount value as the number of times to play the animation not the number of times to loop the animation. (Does that make sense?)

GifEncoder(stream, null, null, n)

Should make the animation play n times rather than play n+1 times.

Anyhow.. to stop the animation playing again if the signature worked that way you would edit the InitHeader method as follows: It's trickier to work out otherwise since you will never get -1 by reading the property item.

private void InitHeader(Stream sourceGif, int w, int h)
{
    // File Header
    WriteString(FileType);
    WriteString(FileVersion);
    WriteShort(_width.GetValueOrDefault(w)); // Initial Logical Width
    WriteShort(_height.GetValueOrDefault(h)); // Initial Logical Height
    sourceGif.Position = SourceGlobalColorInfoPosition;
    WriteByte(sourceGif.ReadByte()); // Global Color Table Info
    WriteByte(0); // Background Color Index
    WriteByte(0); // Pixel aspect ratio
    WriteColorTable(sourceGif);

    // App Extension Header
    int count = _repeatCount.GetValueOrDefault(0);
    if (count != 1){
        count = Math.Max(0, count - 1); // 0 means loop infinitely.
        WriteShort(ApplicationExtensionBlockIdentifier);
        WriteByte(ApplicationBlockSize);
        WriteString(ApplicationIdentification);
        WriteByte(3); // Application block length
        WriteByte(1);
        WriteShort(_repeatCount.GetValueOrDefault(0)); // Repeat count for images.
        WriteByte(0); // terminator
   }
}

I'd have submitted a pull request but I don't want to change the signature of the method.

@DataDink
Copy link
Owner

DataDink commented Apr 5, 2017

Hey guys,

Changing the signature should probably be avoided, but adding overloads - etc should be fine.
As I am noting on other requests here: I am not actively maintaining this project. Please feel free to make pull requests.

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

No branches or pull requests

4 participants