Skip to content

Commit

Permalink
gifski addition fixed
Browse files Browse the repository at this point in the history
1. fixed the order of settings (according to gifski's code)
pub struct GifskiSettings {
    pub width: u32,
    pub height: u32,
    pub quality: u8,
    pub fast: bool,
    pub repeat: i16,
}
2. Since version 1.4.0 had been pubulished, set it to be default.(dll files'length built by different persons can be different, I got 606720bytes by version 1.4.0 x64)
3. No need to set up lastTimestamp when addframe, it can be auto-calc. 
refer to gifski.h
 * Presentation timestamp (PTS) is time in seconds, since start of the file, when this frame is to be displayed.
 * For a 20fps video it could be `frame_number/20.0`. First frame must have PTS=0.
 * Frames with duplicate or out-of-order PTS will be skipped.
  • Loading branch information
soysaucemo committed Aug 8, 2021
1 parent c8abcbe commit 538acb0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions ScreenToGif/Util/GifskiInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ internal class GifskiInterop
[StructLayout(LayoutKind.Sequential)]
internal struct GifskiSettings
{
public GifskiSettings(uint width, uint height, byte quality, bool looped, bool fast)
//fixed the order of settings (according to gifski's code)
public GifskiSettings(uint width, uint height, byte quality, bool fast, bool looped)
{
Width = width;
Height = height;
Quality = quality;
Once = !looped;
Fast = fast;
Once = !looped;
}

/// <summary>
Expand Down Expand Up @@ -165,6 +166,7 @@ public GifskiInterop()
info.Refresh();

//I really need another way to differentiate gifski versions.
//Since version 1.4.0 had been pubulished, set it to be default.(dll files'length built by different persons can be different, I got 606720bytes by version 1.4.0 x64)
switch (info.Length)
{
case 524_752:
Expand All @@ -180,7 +182,7 @@ public GifskiInterop()
break;

default:
Version = new Version(0, 0);
Version = new Version(1, 4, 0);
break;
}

Expand Down Expand Up @@ -216,7 +218,8 @@ public GifskiInterop()

internal IntPtr Start(uint width, uint height, int quality, bool looped = true, bool fast = false)
{
return _new(new GifskiSettings(width, height, (byte)quality, looped, fast));
//fixed the order of settings (according to gifski's code)
return _new(new GifskiSettings(width, height, (byte)quality, fast, looped));
}

internal GifskiError AddFrame(IntPtr handle, uint index, string path, int delay, double lastTimestamp = 0, bool isLast = false)
Expand All @@ -243,7 +246,8 @@ internal GifskiError AddFrame(IntPtr handle, uint index, string path, int delay,
if (Version > new Version(0, 10, 4))
{
//First frame receives the delay set of the last frame.
result = AddFrame2Pixels(handle, index, (uint)util.Width, (uint)bytesPerRow, (uint)util.Height, address, index == 0 ? lastTimestamp : _timeStamp);
//No need to set up lastTimestamp, it can be auto-calc.
result = AddFrame2Pixels(handle, index, (uint)util.Width, (uint)bytesPerRow, (uint)util.Height, address, index == 0 ? 0 : _timeStamp);

_timeStamp += (delay / 1000d);
}
Expand Down Expand Up @@ -311,4 +315,4 @@ internal GifskiError End(IntPtr handle, string destination)
return GifskiError.Ok;
}
}
}
}

0 comments on commit 538acb0

Please sign in to comment.