Skip to content

Commit

Permalink
[NUI] Support FrameSpeedFactor for AnimatedImage relative classes
Browse files Browse the repository at this point in the history
Let we make some property to control the speed of animated image.

If we want to play animation 2x speed, Set this value as 2.0f.

If we want to play animation 0.5x speed, Set this value as 0.5f.

Note : For the platform safety reason, let we constraint the input value as
0.01f to 100.0f

Relative dali patch :

https://review.tizen.org/gerrit/c/platform/core/uifw/dali-toolkit/+/316847

Signed-off-by: Eunki, Hong <[email protected]>
  • Loading branch information
Eunki, Hong authored and hinohie committed Sep 2, 2024
1 parent 90c2f36 commit 4953367
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 1 deletion.
45 changes: 45 additions & 0 deletions src/Tizen.NUI/src/public/BaseComponents/AnimatedImageView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public partial class AnimatedImageView : ImageView
ImageVisualProperty.FrameDelay,
ImageVisualProperty.LoopCount,
ImageVisualProperty.StopBehavior,
ImageVisualProperty.FrameSpeedFactor,
};
private List<string> resourceURLs = new List<string>();
#endregion Private
Expand Down Expand Up @@ -284,6 +285,50 @@ private StopBehaviorType InternalStopBehavior
}
}

/// <summary>
/// Specifies a speed factor for the animated image frame.
/// </summary>
/// <remarks>
/// The speed factor is a multiplier of the normal velocity of the animation. Values between [0,1] will
/// slow down the animation and values above one will speed up the animation.
///
/// The range of this value is clamped between [0.01f ~ 100.0f].
///
/// Inhouse API.
/// The default is 1.0f.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public float FrameSpeedFactor
{
get
{
return InternalFrameSpeedFactor;
}
set
{
InternalFrameSpeedFactor = value;
NotifyPropertyChanged();
}
}

private float InternalFrameSpeedFactor
{
get
{
float ret = 1.0f;

using PropertyValue frameSpeedFactor = GetCachedImageVisualProperty(ImageVisualProperty.FrameSpeedFactor);
frameSpeedFactor?.Get(out ret);

return ret;
}
set
{
using PropertyValue setValue = new PropertyValue(value);
UpdateImage(ImageVisualProperty.FrameSpeedFactor, setValue);
}
}

/// <summary>
/// Get the number of total frames
/// </summary>
Expand Down
55 changes: 54 additions & 1 deletion src/Tizen.NUI/src/public/BaseComponents/LottieAnimationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public LottieAnimationView(float scale = 1.0f, bool shown = true) : base()
currentStates.loopCount = 1;
currentStates.loopMode = LoopingModeType.Restart;
currentStates.stopEndAction = StopBehaviorType.CurrentFrame;
currentStates.frameSpeedFactor = 1.0f;
currentStates.framePlayRangeMin = -1;
currentStates.framePlayRangeMax = -1;
currentStates.totalFrame = -1;
Expand Down Expand Up @@ -216,6 +217,7 @@ private string InternalURL
using PropertyValue synchronousLoading = new PropertyValue(currentStates.synchronousLoading);
using PropertyValue enableFrameCache = new PropertyValue(currentStates.enableFrameCache);
using PropertyValue notifyAfterRasterization = new PropertyValue(currentStates.notifyAfterRasterization);
using PropertyValue frameSpeedFactor = new PropertyValue(currentStates.frameSpeedFactor);

map.Add(Visual.Property.Type, type)
.Add(ImageVisualProperty.URL, url)
Expand All @@ -225,7 +227,8 @@ private string InternalURL
.Add(ImageVisualProperty.RedrawInScalingDown, redrawInScalingDown)
.Add(ImageVisualProperty.SynchronousLoading, synchronousLoading)
.Add(ImageVisualProperty.EnableFrameCache, enableFrameCache)
.Add(ImageVisualProperty.NotifyAfterRasterization, notifyAfterRasterization);
.Add(ImageVisualProperty.NotifyAfterRasterization, notifyAfterRasterization)
.Add(ImageVisualProperty.FrameSpeedFactor, frameSpeedFactor);

if (currentStates.desiredWidth > 0)
{
Expand Down Expand Up @@ -779,6 +782,53 @@ private bool InternalNotifyAfterRasterization
return currentStates.notifyAfterRasterization;
}
}

/// <summary>
/// Specifies a speed factor for the animated image frame.
/// </summary>
/// <remarks>
/// The speed factor is a multiplier of the normal velocity of the animation. Values between [0,1] will
/// slow down the animation and values above one will speed up the animation.
///
/// The range of this value is clamped between [0.01f ~ 100.0f].
///
/// Inhouse API.
/// The default is 1.0f.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public float FrameSpeedFactor
{
get
{
return InternalFrameSpeedFactor;
}
set
{
InternalFrameSpeedFactor = value;
NotifyPropertyChanged();
}
}

private float InternalFrameSpeedFactor
{
set
{
if (currentStates.frameSpeedFactor != value)
{
currentStates.changed = true;
currentStates.frameSpeedFactor = value;

NUILog.Debug($"<[{GetId()}]SET currentStates.FrameSpeedFactor={currentStates.frameSpeedFactor}>");

Interop.View.InternalUpdateVisualPropertyFloat(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.FrameSpeedFactor, currentStates.frameSpeedFactor);
}
}
get
{
NUILog.Debug($"FrameSpeedFactor get! {currentStates.frameSpeedFactor}");
return currentStates.frameSpeedFactor;
}
}
#endregion Property


Expand Down Expand Up @@ -1103,6 +1153,7 @@ protected override void UpdateImage()
UpdateImage(ImageVisualProperty.SynchronousLoading, new PropertyValue(currentStates.synchronousLoading), false);
UpdateImage(ImageVisualProperty.EnableFrameCache, new PropertyValue(currentStates.enableFrameCache), false);
UpdateImage(ImageVisualProperty.NotifyAfterRasterization, new PropertyValue(currentStates.notifyAfterRasterization), false);
UpdateImage(ImageVisualProperty.FrameSpeedFactor, new PropertyValue(currentStates.frameSpeedFactor), false);

// Do not cache PlayRange and TotalFrameNumber into cachedImagePropertyMap.
// (To keep legacy implements behaviour)
Expand Down Expand Up @@ -1495,6 +1546,7 @@ internal void FlushLottieMessages()
ImageVisualProperty.RedrawInScalingDown,
ImageVisualProperty.EnableFrameCache,
ImageVisualProperty.NotifyAfterRasterization,
ImageVisualProperty.FrameSpeedFactor,
};

private struct states
Expand All @@ -1503,6 +1555,7 @@ private struct states
internal int loopCount;
internal LoopingModeType loopMode;
internal StopBehaviorType stopEndAction;
internal float frameSpeedFactor;
internal int framePlayRangeMin;
internal int framePlayRangeMax;
internal int totalFrame;
Expand Down
14 changes: 14 additions & 0 deletions src/Tizen.NUI/src/public/Visuals/VisualConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,20 @@ public struct ImageVisualProperty
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly int SynchronousSizing = NDalic.ImageVisualOrientationCorrection + 18;

/// <summary>
/// @brief Specifies a speed factor for the animated image frame.
/// @details Name "frameSpeedFactor", type Property::FLOAT.
///
/// The speed factor is a multiplier of the normal velocity of the animation. Values between [0,1] will
/// slow down the animation and values above one will speed up the animation.
///
/// @note The range of this value is clamped between [0.01f ~ 100.0f].
/// It might be supported out of bound, and negative value in future.
/// @note Used by the ImageVisual and AnimatedVectorImageVisual. The default is 1.0f.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly int FrameSpeedFactor = NDalic.ImageVisualOrientationCorrection + 19;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,28 @@ public Tizen.NUI.BaseComponents.AnimatedImageView.StopBehaviorType StopBehavior
}
}

/// <summary>
/// Gets and sets the speed factor for the AnimatedImageVisual frame rendering.
/// The default is 1.0f. If the number is less than 1.0f then it will play slower than normal case.
/// If the number is greater than 1.0f then it will play faster than normal case.
/// We will clamp the value between [0.01f 100.0f] internally.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public float FrameSpeedFactor
{
set
{
UpdateVisualProperty((int)Tizen.NUI.ImageVisualProperty.FrameSpeedFactor, new PropertyValue(value));
}
get
{
float ret = 1.0f;
var propertyValue = GetCachedVisualProperty((int)Tizen.NUI.ImageVisualProperty.FrameSpeedFactor);
propertyValue?.Get(out ret);
return ret;
}
}

/// <summary>
/// Get the number of total frames.
/// Or -1 if image is invalid, or not loaded yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,34 @@ public void URLs_SET_GET_VALUE()

testView.Dispose();
}

[Test]
[Category("P1")]
[Description("internal API test in Ubuntu, AnimatedImageView.FrameSpeedFactor")]
[Property("SPEC", "Tizen.NUI.BaseComponents.AnimatedImageView.FrameSpeedFactor")]
[Property("SPEC_URL", "-")]
[Property("CRITERIA", "PRO")]
[Property("AUTHOR", "[email protected]")]
public void FrameSpeedFactor_SET_GET_VALUE()
{
/* TEST CODE */
AnimatedImageView testView = new AnimatedImageView();

Assert.AreEqual(1.0f, testView.FrameSpeedFactor, "FrameSpeedFactor should be 1.0f when ResourceUrl is not setup");

testView.ResourceUrl = animated_image_path;

Assert.AreEqual(1.0f, testView.FrameSpeedFactor, "FrameSpeedFactor should be 1.0f even ResourceUrl is setup");

float expectSpeedFactor = 3.0f;
testView.FrameSpeedFactor = expectSpeedFactor;
Assert.AreEqual(expectSpeedFactor, testView.FrameSpeedFactor, "FrameSpeedFactor doesn't matched!");

expectSpeedFactor = 0.5f;
testView.FrameSpeedFactor = expectSpeedFactor;
Assert.AreEqual(expectSpeedFactor, testView.FrameSpeedFactor, "FrameSpeedFactor doesn't matched!");

testView.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public void Activate()
lav.NotifyAfterRasterization = true;
lav.URL = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "a.json";
lav.LoopCount = -1;
lav.FrameSpeedFactor = 2.0f; // 2x speed
lav.BackgroundColor = Color.White;
NUIApplication.GetDefaultWindow().GetDefaultLayer().Add(lav);
Tizen.Log.Error("NUI", $"Total frame before resource ready : {lav.TotalFrame} / might be 0 if still load images. or, might be valid value if load finished during above logic running.\n");
Expand Down

0 comments on commit 4953367

Please sign in to comment.