mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Added GIF animation speed
This commit is contained in:
parent
99762a5ce2
commit
96eadfecbb
@ -25,7 +25,7 @@ namespace Artemis.Profiles.Layers.Models
|
||||
|
||||
var model = Properties as KeyboardPropertiesModel;
|
||||
if (model != null)
|
||||
GifImage = new GifImage(model.GifFile);
|
||||
GifImage = new GifImage(model.GifFile, Properties.AnimationSpeed);
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
|
||||
@ -42,9 +42,9 @@ namespace Artemis.Profiles.Layers.Types.KeyboardGif
|
||||
|
||||
// Only reconstruct GifImage if the underlying source has changed
|
||||
if (layerModel.GifImage == null)
|
||||
layerModel.GifImage = new GifImage(props.GifFile);
|
||||
layerModel.GifImage = new GifImage(props.GifFile, props.AnimationSpeed);
|
||||
if (layerModel.GifImage.Source != props.GifFile)
|
||||
layerModel.GifImage = new GifImage(props.GifFile);
|
||||
layerModel.GifImage = new GifImage(props.GifFile, props.AnimationSpeed);
|
||||
|
||||
var rect = new Rect(layerModel.X*4, layerModel.Y*4, layerModel.Width*4, layerModel.Height*4);
|
||||
|
||||
@ -61,6 +61,9 @@ namespace Artemis.Profiles.Layers.Types.KeyboardGif
|
||||
public void Update(LayerModel layerModel, ModuleDataModel dataModel, bool isPreview = false)
|
||||
{
|
||||
layerModel.ApplyProperties(true);
|
||||
if (layerModel.GifImage != null)
|
||||
layerModel.GifImage.AnimationSpeed = layerModel.Properties.AnimationSpeed;
|
||||
|
||||
if (isPreview || dataModel == null)
|
||||
return;
|
||||
|
||||
@ -74,7 +77,8 @@ namespace Artemis.Profiles.Layers.Types.KeyboardGif
|
||||
if (layerModel.Properties is KeyboardPropertiesModel)
|
||||
return;
|
||||
|
||||
layerModel.Properties = new KeyboardPropertiesModel(layerModel.Properties);
|
||||
// Set animation speed to 1.5, this translates back to a GIF playback rate of x1
|
||||
layerModel.Properties = new KeyboardPropertiesModel(layerModel.Properties) {AnimationSpeed = 1.5};
|
||||
}
|
||||
|
||||
public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
|
||||
|
||||
Binary file not shown.
@ -6,23 +6,22 @@ namespace Artemis.Utilities
|
||||
{
|
||||
public class GifImage
|
||||
{
|
||||
private readonly int _delay;
|
||||
private readonly FrameDimension _dimension;
|
||||
private readonly Image _gifImage;
|
||||
private readonly PropertyItem _gifProperties;
|
||||
private DateTime _lastRequest;
|
||||
private int _step = 1;
|
||||
|
||||
public GifImage(string path)
|
||||
public GifImage(string path, double animationSpeed)
|
||||
{
|
||||
_lastRequest = DateTime.Now;
|
||||
_gifImage = Image.FromFile(path); //initialize
|
||||
_dimension = new FrameDimension(_gifImage.FrameDimensionsList[0]); //gets the GUID
|
||||
FrameCount = _gifImage.GetFrameCount(_dimension); //total frames in the animation
|
||||
_gifProperties = _gifImage.GetPropertyItem(0x5100); // FrameDelay in libgdiplus
|
||||
|
||||
Source = path;
|
||||
|
||||
var item = _gifImage.GetPropertyItem(0x5100); // FrameDelay in libgdiplus
|
||||
_delay = (item.Value[0] + item.Value[1]*256)*10; // Time is in 1/100th of a second
|
||||
AnimationSpeed = animationSpeed;
|
||||
FrameCount = _gifImage.GetFrameCount(_dimension); //total frames in the animation
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -30,6 +29,8 @@ namespace Artemis.Utilities
|
||||
/// </summary>
|
||||
public string Source { get; private set; }
|
||||
|
||||
public double AnimationSpeed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current frame, set to -1 to reset
|
||||
/// </summary>
|
||||
@ -47,8 +48,16 @@ namespace Artemis.Utilities
|
||||
|
||||
public Image GetNextFrame()
|
||||
{
|
||||
var animationSpeed = 2 - AnimationSpeed/3 * 2;
|
||||
var fileDelay = (_gifProperties.Value[0] + _gifProperties.Value[1] * 256) * 10;
|
||||
// If the file is missing this metadata such as in #319 then default to 100
|
||||
if (fileDelay == 0)
|
||||
fileDelay = 100;
|
||||
// Apply the animation speed to the delay
|
||||
var delay = fileDelay * animationSpeed;
|
||||
|
||||
// Only pass the next frame if the proper amount of time has passed
|
||||
if ((DateTime.Now - _lastRequest).Milliseconds > _delay)
|
||||
if ((DateTime.Now - _lastRequest).Milliseconds > delay)
|
||||
{
|
||||
CurrentFrame += _step;
|
||||
_lastRequest = DateTime.Now;
|
||||
@ -75,4 +84,4 @@ namespace Artemis.Utilities
|
||||
return _gifImage;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user