1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 #include "libavutil/intreadwrite.h"
23 #include "pixels.h"
24 #include "rnd_avg.h"
25 
26 #include "bit_depth_template.c"
27 
28 #define DEF_PEL(OPNAME, OP)                                             \
29 static inline void FUNCC(OPNAME ## _pixels2)(uint8_t *block,            \
30                                              const uint8_t *pixels,     \
31                                              ptrdiff_t line_size,       \
32                                              int h)                     \
33 {                                                                       \
34     int i;                                                              \
35     for (i = 0; i < h; i++) {                                           \
36         OP(*((pixel2 *) block), AV_RN2P(pixels));                       \
37         pixels += line_size;                                            \
38         block  += line_size;                                            \
39     }                                                                   \
40 }                                                                       \
41                                                                         \
42 static inline void FUNCC(OPNAME ## _pixels4)(uint8_t *block,            \
43                                              const uint8_t *pixels,     \
44                                              ptrdiff_t line_size,       \
45                                              int h)                     \
46 {                                                                       \
47     int i;                                                              \
48     for (i = 0; i < h; i++) {                                           \
49         OP(*((pixel4 *) block), AV_RN4P(pixels));                       \
50         pixels += line_size;                                            \
51         block  += line_size;                                            \
52     }                                                                   \
53 }                                                                       \
54                                                                         \
55 static inline void FUNCC(OPNAME ## _pixels8)(uint8_t *block,            \
56                                              const uint8_t *pixels,     \
57                                              ptrdiff_t line_size,       \
58                                              int h)                     \
59 {                                                                       \
60     int i;                                                              \
61     for (i = 0; i < h; i++) {                                           \
62         OP(*((pixel4 *) block), AV_RN4P(pixels));                       \
63         OP(*((pixel4 *) (block + 4 * sizeof(pixel))),                   \
64            AV_RN4P(pixels + 4 * sizeof(pixel)));                        \
65         pixels += line_size;                                            \
66         block  += line_size;                                            \
67     }                                                                   \
68 }                                                                       \
69                                                                         \
70 CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16),                              \
71                FUNCC(OPNAME ## _pixels8),                               \
72                8 * sizeof(pixel))
73 
74 #define op_avg(a, b) a = rnd_avg_pixel4(a, b)
75 #define op_put(a, b) a = b
76 
77 DEF_PEL(avg, op_avg)
78 DEF_PEL(put, op_put)
79 #undef op_avg
80 #undef op_put
81