1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "core/animation/animatable_data.h"
17 
18 namespace OHOS::Ace {
19 
20 template<>
Blend(const Dimension & start,const Dimension & end,float process)21 Dimension AnimatableData<Dimension>::Blend(
22     const Dimension& start, const Dimension& end, float process)
23 {
24     float scaleA = process;
25     float scaleB = 0.0f;
26     if (!NearEqual(process, 1.0f)) {
27         scaleB = 1.0f - process;
28     }
29     return start * scaleB + end * scaleA;
30 }
31 
32 template<>
Blend(const Color & start,const Color & end,float process)33 Color AnimatableData<Color>::Blend(
34     const Color& start, const Color& end, float process)
35 {
36     float startA = start.GetAlpha();
37     float startR = start.GetRed();
38     float startG = start.GetGreen();
39     float startB = start.GetBlue();
40     uint8_t alpha = static_cast<uint8_t>(startA + (end.GetAlpha() - startA) * process);
41     uint8_t red = static_cast<uint8_t>(startR + (end.GetRed() - startR) * process);
42     uint8_t green = static_cast<uint8_t>(startG + (end.GetGreen() - startG) * process);
43     uint8_t blue = static_cast<uint8_t>(startB + (end.GetBlue() - startB) * process);
44     return Color::FromARGB(alpha, red, green, blue);
45 }
46 
47 template<>
Blend(const BorderStyle & start,const BorderStyle & end,float process)48 BorderStyle AnimatableData<BorderStyle>::Blend(const BorderStyle& start, const BorderStyle& end, float process)
49 {
50     if (process > 0.5f) {
51         return end;
52     }
53     return start;
54 }
55 
56 template<>
Blend(const Shadow & start,const Shadow & end,float process)57 Shadow AnimatableData<Shadow>::Blend(const Shadow& start, const Shadow& end, float process)
58 {
59     return Shadow::Blend(end, start, process);
60 }
61 
62 template<>
Blend(const BackgroundImageSize & start,const BackgroundImageSize & end,float process)63 BackgroundImageSize AnimatableData<BackgroundImageSize>::Blend(
64     const BackgroundImageSize& start, const BackgroundImageSize& end, float process)
65 {
66     float scaleA = process;
67     float tmp = 1.0f;
68     float scaleB = tmp - process;
69     return start * scaleB + end * scaleA;
70 }
71 
72 } // namespace OHOS::Ace