Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / third_party / ffmpeg / libavcodec / dsputil_template.c
1 /*
2  * DSP utils
3  * Copyright (c) 2000, 2001 Fabrice Bellard
4  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
7  *
8  * This file is part of FFmpeg.
9  *
10  * FFmpeg is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * FFmpeg is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with FFmpeg; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24
25 /**
26  * @file
27  * DSP utils
28  */
29
30 #define PIXOP2(OPNAME, OP)                                              \
31 static inline void OPNAME ## _no_rnd_pixels8_l2_8(uint8_t *dst,         \
32                                                   const uint8_t *src1,  \
33                                                   const uint8_t *src2,  \
34                                                   int dst_stride,       \
35                                                   int src_stride1,      \
36                                                   int src_stride2,      \
37                                                   int h)                \
38 {                                                                       \
39     int i;                                                              \
40                                                                         \
41     for (i = 0; i < h; i++) {                                           \
42         uint32_t a, b;                                                  \
43         a = AV_RN32(&src1[i * src_stride1]);                            \
44         b = AV_RN32(&src2[i * src_stride2]);                            \
45         OP(*((uint32_t *) &dst[i * dst_stride]),                        \
46            no_rnd_avg32(a, b));                                         \
47         a = AV_RN32(&src1[i * src_stride1 + 4]);                        \
48         b = AV_RN32(&src2[i * src_stride2 + 4]);                        \
49         OP(*((uint32_t *) &dst[i * dst_stride + 4]),                    \
50            no_rnd_avg32(a, b));                                         \
51     }                                                                   \
52 }                                                                       \
53                                                                         \
54 static inline void OPNAME ## _no_rnd_pixels16_l2_8(uint8_t *dst,        \
55                                                    const uint8_t *src1, \
56                                                    const uint8_t *src2, \
57                                                    int dst_stride,      \
58                                                    int src_stride1,     \
59                                                    int src_stride2,     \
60                                                    int h)               \
61 {                                                                       \
62     OPNAME ## _no_rnd_pixels8_l2_8(dst, src1, src2, dst_stride,         \
63                                    src_stride1, src_stride2, h);        \
64     OPNAME ## _no_rnd_pixels8_l2_8(dst  + 8,                            \
65                                    src1 + 8,                            \
66                                    src2 + 8,                            \
67                                    dst_stride, src_stride1,             \
68                                    src_stride2, h);                     \
69 }                                                                       \
70                                                                         \
71 static inline void OPNAME ## _pixels8_l4_8(uint8_t *dst,                \
72                                            const uint8_t *src1,         \
73                                            const uint8_t *src2,         \
74                                            const uint8_t *src3,         \
75                                            const uint8_t *src4,         \
76                                            int dst_stride,              \
77                                            int src_stride1,             \
78                                            int src_stride2,             \
79                                            int src_stride3,             \
80                                            int src_stride4,             \
81                                            int h)                       \
82 {                                                                       \
83     /* FIXME HIGH BIT DEPTH */                                          \
84     int i;                                                              \
85                                                                         \
86     for (i = 0; i < h; i++) {                                           \
87         uint32_t a, b, c, d, l0, l1, h0, h1;                            \
88         a  = AV_RN32(&src1[i * src_stride1]);                           \
89         b  = AV_RN32(&src2[i * src_stride2]);                           \
90         c  = AV_RN32(&src3[i * src_stride3]);                           \
91         d  = AV_RN32(&src4[i * src_stride4]);                           \
92         l0 = (a & 0x03030303UL) +                                       \
93              (b & 0x03030303UL) +                                       \
94                   0x02020202UL;                                         \
95         h0 = ((a & 0xFCFCFCFCUL) >> 2) +                                \
96              ((b & 0xFCFCFCFCUL) >> 2);                                 \
97         l1 = (c & 0x03030303UL) +                                       \
98              (d & 0x03030303UL);                                        \
99         h1 = ((c & 0xFCFCFCFCUL) >> 2) +                                \
100              ((d & 0xFCFCFCFCUL) >> 2);                                 \
101         OP(*((uint32_t *) &dst[i * dst_stride]),                        \
102            h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL));                \
103         a  = AV_RN32(&src1[i * src_stride1 + 4]);                       \
104         b  = AV_RN32(&src2[i * src_stride2 + 4]);                       \
105         c  = AV_RN32(&src3[i * src_stride3 + 4]);                       \
106         d  = AV_RN32(&src4[i * src_stride4 + 4]);                       \
107         l0 = (a & 0x03030303UL) +                                       \
108              (b & 0x03030303UL) +                                       \
109                   0x02020202UL;                                         \
110         h0 = ((a & 0xFCFCFCFCUL) >> 2) +                                \
111              ((b & 0xFCFCFCFCUL) >> 2);                                 \
112         l1 = (c & 0x03030303UL) +                                       \
113              (d & 0x03030303UL);                                        \
114         h1 = ((c & 0xFCFCFCFCUL) >> 2) +                                \
115              ((d & 0xFCFCFCFCUL) >> 2);                                 \
116         OP(*((uint32_t *) &dst[i * dst_stride + 4]),                    \
117            h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL));                \
118     }                                                                   \
119 }                                                                       \
120                                                                         \
121 static inline void OPNAME ## _no_rnd_pixels8_l4_8(uint8_t *dst,         \
122                                                   const uint8_t *src1,  \
123                                                   const uint8_t *src2,  \
124                                                   const uint8_t *src3,  \
125                                                   const uint8_t *src4,  \
126                                                   int dst_stride,       \
127                                                   int src_stride1,      \
128                                                   int src_stride2,      \
129                                                   int src_stride3,      \
130                                                   int src_stride4,      \
131                                                   int h)                \
132 {                                                                       \
133     /* FIXME HIGH BIT DEPTH */                                          \
134     int i;                                                              \
135                                                                         \
136     for (i = 0; i < h; i++) {                                           \
137         uint32_t a, b, c, d, l0, l1, h0, h1;                            \
138         a  = AV_RN32(&src1[i * src_stride1]);                           \
139         b  = AV_RN32(&src2[i * src_stride2]);                           \
140         c  = AV_RN32(&src3[i * src_stride3]);                           \
141         d  = AV_RN32(&src4[i * src_stride4]);                           \
142         l0 = (a & 0x03030303UL) +                                       \
143              (b & 0x03030303UL) +                                       \
144                   0x01010101UL;                                         \
145         h0 = ((a & 0xFCFCFCFCUL) >> 2) +                                \
146              ((b & 0xFCFCFCFCUL) >> 2);                                 \
147         l1 = (c & 0x03030303UL) +                                       \
148              (d & 0x03030303UL);                                        \
149         h1 = ((c & 0xFCFCFCFCUL) >> 2) +                                \
150              ((d & 0xFCFCFCFCUL) >> 2);                                 \
151         OP(*((uint32_t *) &dst[i * dst_stride]),                        \
152            h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL));                \
153         a  = AV_RN32(&src1[i * src_stride1 + 4]);                       \
154         b  = AV_RN32(&src2[i * src_stride2 + 4]);                       \
155         c  = AV_RN32(&src3[i * src_stride3 + 4]);                       \
156         d  = AV_RN32(&src4[i * src_stride4 + 4]);                       \
157         l0 = (a & 0x03030303UL) +                                       \
158              (b & 0x03030303UL) +                                       \
159                   0x01010101UL;                                         \
160         h0 = ((a & 0xFCFCFCFCUL) >> 2) +                                \
161              ((b & 0xFCFCFCFCUL) >> 2);                                 \
162         l1 = (c & 0x03030303UL) +                                       \
163              (d & 0x03030303UL);                                        \
164         h1 = ((c & 0xFCFCFCFCUL) >> 2) +                                \
165              ((d & 0xFCFCFCFCUL) >> 2);                                 \
166         OP(*((uint32_t *) &dst[i * dst_stride + 4]),                    \
167            h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL));                \
168     }                                                                   \
169 }                                                                       \
170                                                                         \
171 static inline void OPNAME ## _pixels16_l4_8(uint8_t *dst,               \
172                                             const uint8_t *src1,        \
173                                             const uint8_t *src2,        \
174                                             const uint8_t *src3,        \
175                                             const uint8_t *src4,        \
176                                             int dst_stride,             \
177                                             int src_stride1,            \
178                                             int src_stride2,            \
179                                             int src_stride3,            \
180                                             int src_stride4,            \
181                                             int h)                      \
182 {                                                                       \
183     OPNAME ## _pixels8_l4_8(dst, src1, src2, src3, src4, dst_stride,    \
184                             src_stride1, src_stride2, src_stride3,      \
185                             src_stride4, h);                            \
186     OPNAME ## _pixels8_l4_8(dst  + 8,                                   \
187                             src1 + 8, src2 + 8,                         \
188                             src3 + 8, src4 + 8,                         \
189                             dst_stride, src_stride1, src_stride2,       \
190                             src_stride3, src_stride4, h);               \
191 }                                                                       \
192                                                                         \
193 static inline void OPNAME ## _no_rnd_pixels16_l4_8(uint8_t *dst,        \
194                                                    const uint8_t *src1, \
195                                                    const uint8_t *src2, \
196                                                    const uint8_t *src3, \
197                                                    const uint8_t *src4, \
198                                                    int dst_stride,      \
199                                                    int src_stride1,     \
200                                                    int src_stride2,     \
201                                                    int src_stride3,     \
202                                                    int src_stride4,     \
203                                                    int h)               \
204 {                                                                       \
205     OPNAME ## _no_rnd_pixels8_l4_8(dst, src1, src2, src3, src4,         \
206                                    dst_stride, src_stride1,             \
207                                    src_stride2, src_stride3,            \
208                                    src_stride4, h);                     \
209     OPNAME ## _no_rnd_pixels8_l4_8(dst  + 8,                            \
210                                    src1 + 8, src2 + 8,                  \
211                                    src3 + 8, src4 + 8,                  \
212                                    dst_stride, src_stride1,             \
213                                    src_stride2, src_stride3,            \
214                                    src_stride4, h);                     \
215 }                                                                       \
216
217 #define op_avg(a, b) a = rnd_avg32(a, b)
218 #define op_put(a, b) a = b
219 #define put_no_rnd_pixels8_8_c put_pixels8_8_c
220 PIXOP2(avg, op_avg)
221 PIXOP2(put, op_put)
222 #undef op_avg
223 #undef op_put