lottie/vector: move pixman code to separate pixman folder.
[platform/core/uifw/lottie-player.git] / src / vector / vcompositionfunctions.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Flora License, Version 1.1 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "vdrawhelper.h"
18
19 /*
20   result = s
21   dest = s * ca + d * cia
22 */
23 void comp_func_solid_Source(uint32_t *dest, int length, uint32_t color,
24                             uint32_t const_alpha)
25 {
26     int ialpha, i;
27
28     if (const_alpha == 255) {
29         memfill32(dest, color, length);
30     } else {
31         ialpha = 255 - const_alpha;
32         color = BYTE_MUL(color, const_alpha);
33         for (i = 0; i < length; ++i)
34             dest[i] = color + BYTE_MUL(dest[i], ialpha);
35     }
36 }
37
38 /*
39   r = s + d * sia
40   dest = r * ca + d * cia
41        =  (s + d * sia) * ca + d * cia
42        = s * ca + d * (sia * ca + cia)
43        = s * ca + d * (1 - sa*ca)
44        = s' + d ( 1 - s'a)
45 */
46 void comp_func_solid_SourceOver(uint32_t *dest, int length, uint32_t color,
47                                 uint32_t const_alpha)
48 {
49     int ialpha, i;
50
51     if (const_alpha != 255) color = BYTE_MUL(color, const_alpha);
52     ialpha = 255 - vAlpha(color);
53     for (i = 0; i < length; ++i) dest[i] = color + BYTE_MUL(dest[i], ialpha);
54 }
55
56 void comp_func_Source(uint32_t *dest, const uint32_t *src, int length,
57                       uint32_t const_alpha)
58 {
59     if (const_alpha == 255) {
60         memcpy(dest, src, size_t(length) * sizeof(uint));
61     } else {
62         uint ialpha = 255 - const_alpha;
63         for (int i = 0; i < length; ++i) {
64             dest[i] =
65                 INTERPOLATE_PIXEL_255(src[i], const_alpha, dest[i], ialpha);
66         }
67     }
68 }
69
70 /* s' = s * ca
71  * d' = s' + d (1 - s'a)
72  */
73 void comp_func_SourceOver(uint32_t *dest, const uint32_t *src, int length,
74                           uint32_t const_alpha)
75 {
76     uint s, sia;
77
78     if (const_alpha == 255) {
79         for (int i = 0; i < length; ++i) {
80             s = src[i];
81             if (s >= 0xff000000)
82                 dest[i] = s;
83             else if (s != 0) {
84                 sia = vAlpha(~s);
85                 dest[i] = s + BYTE_MUL(dest[i], sia);
86             }
87         }
88     } else {
89         /* source' = source * const_alpha
90          * dest = source' + dest ( 1- source'a)
91          */
92         for (int i = 0; i < length; ++i) {
93             uint s = BYTE_MUL(src[i], const_alpha);
94             sia = vAlpha(~s);
95             dest[i] = s + BYTE_MUL(dest[i], sia);
96         }
97     }
98 }
99
100 CompositionFunctionSolid COMP_functionForModeSolid_C[] = {
101     comp_func_solid_Source, comp_func_solid_SourceOver};
102
103 CompositionFunction COMP_functionForMode_C[] = {comp_func_Source,
104                                                 comp_func_SourceOver};
105
106 void vInitBlendFunctions() {}