/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
END_TEST;
}
+int UtcDaliAnimationKeyFramesOptimizeKeyFramesLinearP(void)
+{
+ TestApplication application;
+
+ KeyFrames keyFrames = KeyFrames::New();
+
+ float firstExpectTime = 0.0f;
+ float firstExpectValue = 0.0f;
+ float secondExpectTime = 0.4f;
+ float secondExpectValue = 1.2f;
+ float thirdExpectTime = 0.8f;
+ float thirdExpectValue = 0.4f;
+ float fourthExpectTime = 1.0f;
+ float fourthExpectValue = 0.7f;
+
+ float interpolateLate = 0.5f;
+
+ tet_printf("first - second phase test\n");
+
+ DALI_TEST_EQUALS(false, DevelKeyFrames::OptimizeKeyFramesLinear(keyFrames), TEST_LOCATION);
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 0, TEST_LOCATION);
+
+ keyFrames.Add(firstExpectTime, firstExpectValue);
+ DALI_TEST_EQUALS(false, DevelKeyFrames::OptimizeKeyFramesLinear(keyFrames), TEST_LOCATION);
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 1, TEST_LOCATION);
+
+ keyFrames.Add(firstExpectTime * (1.0f - interpolateLate) + secondExpectTime * interpolateLate, firstExpectValue * (1.0f - interpolateLate) + secondExpectValue * interpolateLate);
+ DALI_TEST_EQUALS(false, DevelKeyFrames::OptimizeKeyFramesLinear(keyFrames), TEST_LOCATION);
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 2, TEST_LOCATION);
+
+ keyFrames.Add(secondExpectTime, secondExpectValue);
+
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 3, TEST_LOCATION);
+ DALI_TEST_EQUALS(true, DevelKeyFrames::OptimizeKeyFramesLinear(keyFrames), TEST_LOCATION);
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 2, TEST_LOCATION);
+
+ float outputTime;
+ Property::Value outputValue;
+
+ DevelKeyFrames::GetKeyFrame(keyFrames, 0, outputTime, outputValue);
+
+ DALI_TEST_EQUALS(outputTime, firstExpectTime, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::FLOAT, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.Get<float>(), firstExpectValue, TEST_LOCATION);
+
+ DevelKeyFrames::GetKeyFrame(keyFrames, 1, outputTime, outputValue);
+
+ DALI_TEST_EQUALS(outputTime, secondExpectTime, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::FLOAT, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.Get<float>(), secondExpectValue, TEST_LOCATION);
+
+ tet_printf("second - third phase test\n");
+
+ interpolateLate = 0.3f;
+ keyFrames.Add(secondExpectTime * (1.0f - interpolateLate) + thirdExpectTime * interpolateLate, secondExpectValue * (1.0f - interpolateLate) + thirdExpectValue * interpolateLate);
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 3, TEST_LOCATION);
+
+ interpolateLate = 0.4f;
+ keyFrames.Add(secondExpectTime * (1.0f - interpolateLate) + thirdExpectTime * interpolateLate, secondExpectValue * (1.0f - interpolateLate) + thirdExpectValue * interpolateLate);
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 4, TEST_LOCATION);
+
+ interpolateLate = 0.5f;
+ keyFrames.Add(secondExpectTime * (1.0f - interpolateLate) + thirdExpectTime * interpolateLate, secondExpectValue * (1.0f - interpolateLate) + thirdExpectValue * interpolateLate);
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 5, TEST_LOCATION);
+
+ interpolateLate = 0.8f;
+ keyFrames.Add(secondExpectTime * (1.0f - interpolateLate) + thirdExpectTime * interpolateLate, secondExpectValue * (1.0f - interpolateLate) + thirdExpectValue * interpolateLate);
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 6, TEST_LOCATION);
+
+ keyFrames.Add(thirdExpectTime, thirdExpectValue);
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 7, TEST_LOCATION);
+
+ DALI_TEST_EQUALS(true, DevelKeyFrames::OptimizeKeyFramesLinear(keyFrames), TEST_LOCATION);
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 3, TEST_LOCATION);
+
+ DevelKeyFrames::GetKeyFrame(keyFrames, 0, outputTime, outputValue);
+
+ DALI_TEST_EQUALS(outputTime, firstExpectTime, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::FLOAT, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.Get<float>(), firstExpectValue, TEST_LOCATION);
+
+ DevelKeyFrames::GetKeyFrame(keyFrames, 1, outputTime, outputValue);
+
+ DALI_TEST_EQUALS(outputTime, secondExpectTime, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::FLOAT, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.Get<float>(), secondExpectValue, TEST_LOCATION);
+
+ DevelKeyFrames::GetKeyFrame(keyFrames, 2, outputTime, outputValue);
+
+ DALI_TEST_EQUALS(outputTime, thirdExpectTime, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::FLOAT, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.Get<float>(), thirdExpectValue, TEST_LOCATION);
+
+ tet_printf("third - fourth phase test. Test what we skip same progress.\n");
+
+ interpolateLate = 0.3f;
+ keyFrames.Add(thirdExpectTime * (1.0f - interpolateLate) + fourthExpectTime * interpolateLate, thirdExpectValue * (1.0f - interpolateLate) + fourthExpectValue * interpolateLate);
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 4, TEST_LOCATION);
+
+ interpolateLate = 0.5f;
+ keyFrames.Add(thirdExpectTime * (1.0f - interpolateLate) + fourthExpectTime * interpolateLate, thirdExpectValue * (1.0f - interpolateLate) + fourthExpectValue * interpolateLate);
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 5, TEST_LOCATION);
+
+ interpolateLate = 0.8f;
+ keyFrames.Add(thirdExpectTime * (1.0f - interpolateLate) + fourthExpectTime * interpolateLate, thirdExpectValue * (1.0f - interpolateLate) + fourthExpectValue * interpolateLate);
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 6, TEST_LOCATION);
+
+ keyFrames.Add(fourthExpectTime, fourthExpectValue);
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 7, TEST_LOCATION);
+
+ DALI_TEST_EQUALS(true, DevelKeyFrames::OptimizeKeyFramesLinear(keyFrames), TEST_LOCATION);
+ DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 4, TEST_LOCATION);
+
+ DevelKeyFrames::GetKeyFrame(keyFrames, 0, outputTime, outputValue);
+
+ DALI_TEST_EQUALS(outputTime, firstExpectTime, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::FLOAT, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.Get<float>(), firstExpectValue, TEST_LOCATION);
+
+ DevelKeyFrames::GetKeyFrame(keyFrames, 1, outputTime, outputValue);
+
+ DALI_TEST_EQUALS(outputTime, secondExpectTime, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::FLOAT, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.Get<float>(), secondExpectValue, TEST_LOCATION);
+
+ DevelKeyFrames::GetKeyFrame(keyFrames, 2, outputTime, outputValue);
+
+ DALI_TEST_EQUALS(outputTime, thirdExpectTime, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::FLOAT, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.Get<float>(), thirdExpectValue, TEST_LOCATION);
+
+ DevelKeyFrames::GetKeyFrame(keyFrames, 3, outputTime, outputValue);
+
+ DALI_TEST_EQUALS(outputTime, fourthExpectTime, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::FLOAT, TEST_LOCATION);
+ DALI_TEST_EQUALS(outputValue.Get<float>(), fourthExpectValue, TEST_LOCATION);
+
+ END_TEST;
+}
+
int UtcDaliAnimationAnimateBetweenActorColorAlphaP(void)
{
TestApplication application;
#define DALI_INTERNAL_KEY_FRAME_CHANNEL_H
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
return interpolatedV;
}
+ bool OptimizeValuesLinear()
+ {
+ ProgressValues optimizedValues;
+ bool optimized = false;
+
+ // Optimize works only if value has more or equal than 3 values.
+ if(mValues.size() < 3u)
+ {
+ return optimized;
+ }
+
+ auto iter = mValues.begin();
+ for(; iter + 1 != mValues.end();)
+ {
+ // Insert iter, which is the first value, or jter what we fail to ignore previous loops.
+ optimizedValues.push_back(*iter);
+ const float iterProgress = iter->GetProgress();
+
+ auto jter = iter + 1;
+
+ for(; jter + 1 != mValues.end();)
+ {
+ // Check whether we can ignore jter now.
+ const auto kter = jter + 1;
+ const float jterProgress = jter->GetProgress();
+ const float kterProgress = kter->GetProgress();
+
+ float frameProgress = (jterProgress - iterProgress) / (kterProgress - iterProgress);
+
+ // Interpolate with iter and kter.
+ // Check value between interpolatedV and jter->GetValue().
+ // If two values are similar, we can skip jter!
+ V interpolatedV{};
+ Interpolate(interpolatedV, iter->GetValue(), kter->GetValue(), frameProgress);
+
+ // TODO : We might need to find more good way to compare two values
+ if(Property::Value(interpolatedV) != Property::Value(jter->GetValue()))
+ {
+ break;
+ }
+
+ optimized = true;
+
+ // Keep checking for the next jter
+ ++jter;
+ }
+ iter = jter;
+ }
+
+ // Insert last value.
+ optimizedValues.push_back(*iter);
+
+ if(optimized)
+ {
+ mValues = std::move(optimizedValues);
+ }
+ return optimized;
+ }
+
ProgressValues mValues;
};