mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-31 09:43:46 +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;
|
var model = Properties as KeyboardPropertiesModel;
|
||||||
if (model != null)
|
if (model != null)
|
||||||
GifImage = new GifImage(model.GifFile);
|
GifImage = new GifImage(model.GifFile, Properties.AnimationSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
|
|||||||
@ -42,9 +42,9 @@ namespace Artemis.Profiles.Layers.Types.KeyboardGif
|
|||||||
|
|
||||||
// Only reconstruct GifImage if the underlying source has changed
|
// Only reconstruct GifImage if the underlying source has changed
|
||||||
if (layerModel.GifImage == null)
|
if (layerModel.GifImage == null)
|
||||||
layerModel.GifImage = new GifImage(props.GifFile);
|
layerModel.GifImage = new GifImage(props.GifFile, props.AnimationSpeed);
|
||||||
if (layerModel.GifImage.Source != props.GifFile)
|
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);
|
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)
|
public void Update(LayerModel layerModel, ModuleDataModel dataModel, bool isPreview = false)
|
||||||
{
|
{
|
||||||
layerModel.ApplyProperties(true);
|
layerModel.ApplyProperties(true);
|
||||||
|
if (layerModel.GifImage != null)
|
||||||
|
layerModel.GifImage.AnimationSpeed = layerModel.Properties.AnimationSpeed;
|
||||||
|
|
||||||
if (isPreview || dataModel == null)
|
if (isPreview || dataModel == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -74,7 +77,8 @@ namespace Artemis.Profiles.Layers.Types.KeyboardGif
|
|||||||
if (layerModel.Properties is KeyboardPropertiesModel)
|
if (layerModel.Properties is KeyboardPropertiesModel)
|
||||||
return;
|
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,
|
public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
|
||||||
|
|||||||
Binary file not shown.
@ -6,23 +6,22 @@ namespace Artemis.Utilities
|
|||||||
{
|
{
|
||||||
public class GifImage
|
public class GifImage
|
||||||
{
|
{
|
||||||
private readonly int _delay;
|
|
||||||
private readonly FrameDimension _dimension;
|
private readonly FrameDimension _dimension;
|
||||||
private readonly Image _gifImage;
|
private readonly Image _gifImage;
|
||||||
|
private readonly PropertyItem _gifProperties;
|
||||||
private DateTime _lastRequest;
|
private DateTime _lastRequest;
|
||||||
private int _step = 1;
|
private int _step = 1;
|
||||||
|
|
||||||
public GifImage(string path)
|
public GifImage(string path, double animationSpeed)
|
||||||
{
|
{
|
||||||
_lastRequest = DateTime.Now;
|
_lastRequest = DateTime.Now;
|
||||||
_gifImage = Image.FromFile(path); //initialize
|
_gifImage = Image.FromFile(path); //initialize
|
||||||
_dimension = new FrameDimension(_gifImage.FrameDimensionsList[0]); //gets the GUID
|
_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;
|
Source = path;
|
||||||
|
AnimationSpeed = animationSpeed;
|
||||||
var item = _gifImage.GetPropertyItem(0x5100); // FrameDelay in libgdiplus
|
FrameCount = _gifImage.GetFrameCount(_dimension); //total frames in the animation
|
||||||
_delay = (item.Value[0] + item.Value[1]*256)*10; // Time is in 1/100th of a second
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -30,6 +29,8 @@ namespace Artemis.Utilities
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Source { get; private set; }
|
public string Source { get; private set; }
|
||||||
|
|
||||||
|
public double AnimationSpeed { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the current frame, set to -1 to reset
|
/// Gets or sets the current frame, set to -1 to reset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -47,8 +48,16 @@ namespace Artemis.Utilities
|
|||||||
|
|
||||||
public Image GetNextFrame()
|
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
|
// 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;
|
CurrentFrame += _step;
|
||||||
_lastRequest = DateTime.Now;
|
_lastRequest = DateTime.Now;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user